mirror of
https://gitlab.com/BinaryHardening/cfgrip
synced 2026-07-26 12:41:08 +00:00
feat: add mode field to JSON output, only emit stack_offset in clean mode
This commit is contained in:
@@ -704,5 +704,6 @@ void CFGBuilder::clean(CFG& cfg)
|
||||
jumpThread(cfg);
|
||||
pruneDeadBlocks(cfg);
|
||||
computeStackDeltas(cfg);
|
||||
cfg.has_stack_offsets = true;
|
||||
computeXrefs(cfg);
|
||||
}
|
||||
|
||||
@@ -75,12 +75,13 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
CFGBuilder builder(binary.get(), &dis, subsOnly);
|
||||
if (subsOnly) cout << "mode: subs-only" << endl;
|
||||
CFG cfg = builder.build();
|
||||
cfg.mode_str = subsOnly ? "subs-only" : "full";
|
||||
|
||||
if (clean)
|
||||
{
|
||||
CFGBuilder::clean(cfg);
|
||||
cfg.mode_str += "+clean";
|
||||
cout << "clean: xrefs=" << cfg.xrefs.size() << " functions=" << cfg.functions.size() << endl;
|
||||
}
|
||||
|
||||
|
||||
+19105
-38208
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
@@ -65,11 +65,13 @@ struct CFG
|
||||
string binary_path;
|
||||
string arch_str;
|
||||
string format_str;
|
||||
string mode_str;
|
||||
addr_t entry_point;
|
||||
vector<Function> functions;
|
||||
vector<ImportEntry> imports;
|
||||
vector<IndirectTarget> indirect_targets;
|
||||
vector<XrefEntry> xrefs;
|
||||
bool has_stack_offsets = false;
|
||||
|
||||
static string escapeJSON(const string& s)
|
||||
{
|
||||
@@ -94,6 +96,7 @@ struct CFG
|
||||
ostringstream os;
|
||||
os << "{\n";
|
||||
os << " \"binary\": \"" << escapeJSON(binary_path) << "\",\n";
|
||||
os << " \"mode\": \"" << escapeJSON(mode_str) << "\",\n";
|
||||
os << " \"arch\": \"" << escapeJSON(arch_str) << "\",\n";
|
||||
os << " \"format\": \"" << escapeJSON(format_str) << "\",\n";
|
||||
os << " \"entry_point\": \"0x" << hex << entry_point << "\",\n";
|
||||
@@ -148,8 +151,12 @@ struct CFG
|
||||
os << " \"address\": \"0x" << hex << inst.address << "\",\n";
|
||||
os << " \"size\": " << dec << (int)inst.size << ",\n";
|
||||
os << " \"mnemonic\": \"" << escapeJSON(inst.mnemonic) << "\",\n";
|
||||
os << " \"operands\": \"" << escapeJSON(inst.operands) << "\",\n";
|
||||
os << " \"stack_offset\": " << dec << inst.stack_offset << "\n";
|
||||
os << " \"operands\": \"" << escapeJSON(inst.operands) << "\"";
|
||||
if (has_stack_offsets) {
|
||||
os << ",\n";
|
||||
os << " \"stack_offset\": " << dec << inst.stack_offset;
|
||||
}
|
||||
os << "\n";
|
||||
os << " }";
|
||||
if (k < b.instructions.size() - 1) os << ",";
|
||||
os << "\n";
|
||||
|
||||
Reference in New Issue
Block a user