This project is an attempt to implement a general decompiler - or, more precisely, a control-flow graph structure detector - developed with extensive use of AI (Copilot, agents) during its implementation.
The project is still a work in progress...
If this get success, I can later use it as a base for new algorithms in jpexs-decompiler.
import com.jpexs.decompiler.vibe.StructureDetector;
// Create a StructureDetector from Graphviz/DOT format
String dot = "digraph { start->a; a->b; a->c; b->d; c->d; d->end; }";
StructureDetector detector = StructureDetector.fromGraphviz(dot);
// Generate pseudocode
String pseudocode = detector.toPseudocode();
System.out.println(pseudocode);
// Or get the structured statement list for further processing
List<Statement> statements = detector.toStatementList();String dot = "digraph {\n" +
"start->trybody;\n" +
"trybody->end;\n" +
"catchbody->end;\n" +
"}";
StructureDetector detector = StructureDetector.fromGraphviz(dot);
// Define exception ranges: tryNodes => catchNodes
detector.parseExceptions("trybody => catchbody");
String pseudocode = detector.toPseudocode();
// Output:
// start;
// try {
// trybody;
// } catch(0) {
// catchbody;
// }
// end;StructureDetector.fromGraphviz(String dot)- Creates a detector from Graphviz/DOT format
StructureDetector(Node entryNode)- Creates a detector with the given entry node
parseExceptions(String exceptionDef)- Parses exception definitions in format"tryNodes => catchNodes; ..."addException(Set<Node> tryNodes, Set<Node> catchNodes)- Adds a try-catch structure programmaticallyaddLabeledBlock(String label, Node startNode, Node endNode)- Registers a labeled block structure
toPseudocode()- Generates pseudocode string representationtoStatementList()- Returns structuredList<Statement>for further processingtoGraphviz()- Generates Graphviz/DOT format string
analyze()- Prints detected control flow structures to stdoutdetectIfs()- ReturnsList<IfStructure>of detected if statementsdetectLoops()- ReturnsList<LoopStructure>of detected loopsgetTryStructures()- ReturnsList<TryStructure>of registered exception handlersgetLabeledBlocks()- ReturnsList<LabeledBlockStructure>of registered labeled blocks
getEntryNode()- Returns the entry node of the CFG
Node()- creates node with generic labelNode(String label)- creates node with custom labelNode(String label, Object customData)- creates node with custom label and datavoid setCustomData(Object customData)- sets custom node dataObject getCustomData()- gets custom node data
ant runJindra Petřík aka JPEXS giving prompts to agents...