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];
|
||||
|
||||
Reference in New Issue
Block a user