mirror of
https://gitlab.com/BinaryHardening/cfgrip
synced 2026-07-26 12:41:08 +00:00
fix: skip empty functions, relax jump-threading to handle multi-instr jmp stubs
This commit is contained in:
+10
-2
@@ -458,12 +458,19 @@ CFG CFGBuilder::build()
|
||||
set<addr_t> built;
|
||||
queue<addr_t> pending;
|
||||
|
||||
auto isEmpty = [](const Function& f) -> bool {
|
||||
for (const auto& b : f.blocks)
|
||||
if (!b.instructions.empty()) return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
auto process = [&](addr_t addr, const string& name)
|
||||
{
|
||||
if (built.count(addr)) return;
|
||||
built.insert(addr);
|
||||
|
||||
auto func = buildFunction(addr, name);
|
||||
if (isEmpty(func)) return;
|
||||
cfg.functions.push_back(func);
|
||||
|
||||
for (const auto& b : func.blocks)
|
||||
@@ -513,6 +520,7 @@ CFG CFGBuilder::build()
|
||||
|
||||
built.insert(a);
|
||||
auto func = buildFunction(a, name);
|
||||
if (isEmpty(func)) continue;
|
||||
cfg.functions.push_back(func);
|
||||
|
||||
for (const auto& b : func.blocks)
|
||||
@@ -616,8 +624,8 @@ static void jumpThread(CFG& cfg)
|
||||
if (addr_to_func[t] != &func) continue;
|
||||
|
||||
BasicBlock* target = it->second;
|
||||
if (target->instructions.size() == 1 &&
|
||||
target->instructions[0].mnemonic == "jmp" &&
|
||||
if (!target->instructions.empty() &&
|
||||
target->instructions.back().mnemonic == "jmp" &&
|
||||
target->successors.size() == 1)
|
||||
{
|
||||
addr_t redirect = target->successors[0];
|
||||
|
||||
+1
-49
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"binary": "tests\\example1.exe",
|
||||
"binary": "C:\\Dev\\Current\\BinaryHardening\\cfgrip\\tests\\example1.exe",
|
||||
"mode": "full",
|
||||
"arch": "x86-64",
|
||||
"format": "PE",
|
||||
@@ -82571,12 +82571,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"address": "0x14000c9d0",
|
||||
"name": "",
|
||||
"blocks": [
|
||||
]
|
||||
},
|
||||
{
|
||||
"address": "0x140006544",
|
||||
"name": "",
|
||||
@@ -95917,18 +95911,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"address": "0x140015200",
|
||||
"name": "",
|
||||
"blocks": [
|
||||
]
|
||||
},
|
||||
{
|
||||
"address": "0x140011b00",
|
||||
"name": "",
|
||||
"blocks": [
|
||||
]
|
||||
},
|
||||
{
|
||||
"address": "0x140012358",
|
||||
"name": "",
|
||||
@@ -114576,18 +114558,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"address": "0x14000b204",
|
||||
"name": "",
|
||||
"blocks": [
|
||||
]
|
||||
},
|
||||
{
|
||||
"address": "0x14000ca74",
|
||||
"name": "",
|
||||
"blocks": [
|
||||
]
|
||||
},
|
||||
{
|
||||
"address": "0x14000a73c",
|
||||
"name": "",
|
||||
@@ -135887,12 +135857,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"address": "0x1400075e8",
|
||||
"name": "",
|
||||
"blocks": [
|
||||
]
|
||||
},
|
||||
{
|
||||
"address": "0x140009dc4",
|
||||
"name": "",
|
||||
@@ -144893,12 +144857,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"address": "0x140007650",
|
||||
"name": "",
|
||||
"blocks": [
|
||||
]
|
||||
},
|
||||
{
|
||||
"address": "0x140009f50",
|
||||
"name": "",
|
||||
@@ -147615,12 +147573,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"address": "0x140004538",
|
||||
"name": "",
|
||||
"blocks": [
|
||||
]
|
||||
},
|
||||
{
|
||||
"address": "0x14001a95c",
|
||||
"name": "",
|
||||
|
||||
Reference in New Issue
Block a user