feat: add mode field to JSON output, only emit stack_offset in clean mode

This commit is contained in:
x86byte
2026-06-30 09:21:05 +01:00
parent c4739221b7
commit 30862455d9
7 changed files with 264299 additions and 38211 deletions
+1
View File
@@ -704,5 +704,6 @@ void CFGBuilder::clean(CFG& cfg)
jumpThread(cfg); jumpThread(cfg);
pruneDeadBlocks(cfg); pruneDeadBlocks(cfg);
computeStackDeltas(cfg); computeStackDeltas(cfg);
cfg.has_stack_offsets = true;
computeXrefs(cfg); computeXrefs(cfg);
} }
+2 -1
View File
@@ -75,12 +75,13 @@ int main(int argc, char* argv[])
} }
CFGBuilder builder(binary.get(), &dis, subsOnly); CFGBuilder builder(binary.get(), &dis, subsOnly);
if (subsOnly) cout << "mode: subs-only" << endl;
CFG cfg = builder.build(); CFG cfg = builder.build();
cfg.mode_str = subsOnly ? "subs-only" : "full";
if (clean) if (clean)
{ {
CFGBuilder::clean(cfg); CFGBuilder::clean(cfg);
cfg.mode_str += "+clean";
cout << "clean: xrefs=" << cfg.xrefs.size() << " functions=" << cfg.functions.size() << endl; cout << "clean: xrefs=" << cfg.xrefs.size() << " functions=" << cfg.functions.size() << endl;
} }
+19105 -38208
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+9 -2
View File
@@ -65,11 +65,13 @@ struct CFG
string binary_path; string binary_path;
string arch_str; string arch_str;
string format_str; string format_str;
string mode_str;
addr_t entry_point; addr_t entry_point;
vector<Function> functions; vector<Function> functions;
vector<ImportEntry> imports; vector<ImportEntry> imports;
vector<IndirectTarget> indirect_targets; vector<IndirectTarget> indirect_targets;
vector<XrefEntry> xrefs; vector<XrefEntry> xrefs;
bool has_stack_offsets = false;
static string escapeJSON(const string& s) static string escapeJSON(const string& s)
{ {
@@ -94,6 +96,7 @@ struct CFG
ostringstream os; ostringstream os;
os << "{\n"; os << "{\n";
os << " \"binary\": \"" << escapeJSON(binary_path) << "\",\n"; os << " \"binary\": \"" << escapeJSON(binary_path) << "\",\n";
os << " \"mode\": \"" << escapeJSON(mode_str) << "\",\n";
os << " \"arch\": \"" << escapeJSON(arch_str) << "\",\n"; os << " \"arch\": \"" << escapeJSON(arch_str) << "\",\n";
os << " \"format\": \"" << escapeJSON(format_str) << "\",\n"; os << " \"format\": \"" << escapeJSON(format_str) << "\",\n";
os << " \"entry_point\": \"0x" << hex << entry_point << "\",\n"; os << " \"entry_point\": \"0x" << hex << entry_point << "\",\n";
@@ -148,8 +151,12 @@ struct CFG
os << " \"address\": \"0x" << hex << inst.address << "\",\n"; os << " \"address\": \"0x" << hex << inst.address << "\",\n";
os << " \"size\": " << dec << (int)inst.size << ",\n"; os << " \"size\": " << dec << (int)inst.size << ",\n";
os << " \"mnemonic\": \"" << escapeJSON(inst.mnemonic) << "\",\n"; os << " \"mnemonic\": \"" << escapeJSON(inst.mnemonic) << "\",\n";
os << " \"operands\": \"" << escapeJSON(inst.operands) << "\",\n"; os << " \"operands\": \"" << escapeJSON(inst.operands) << "\"";
os << " \"stack_offset\": " << dec << inst.stack_offset << "\n"; if (has_stack_offsets) {
os << ",\n";
os << " \"stack_offset\": " << dec << inst.stack_offset;
}
os << "\n";
os << " }"; os << " }";
if (k < b.instructions.size() - 1) os << ","; if (k < b.instructions.size() - 1) os << ",";
os << "\n"; os << "\n";