Automatically infer function ends in IDA.

The problem with using an end param in IDA is that IDA will quite
stupidly treat the function end as gospel even if it makes no sense
(e.g. a single "function" spanning many MB because there are no symbols
in between). Leaving out end, on the other hand, tells IDA there's a
function at a given starting address but lets IDA figure out the end by
itself, which it usually does correctly.
This commit is contained in:
Robert Xiao
2020-04-18 01:59:09 -07:00
committed by Katy
parent 34f0d4ceef
commit 359b99fded

View File

@@ -72,15 +72,9 @@ def SetName(addr, name):
new_name = name + '_' + str(addr) new_name = name + '_' + str(addr)
ret = idc.set_name(addr, new_name, SN_NOWARN | SN_NOCHECK) ret = idc.set_name(addr, new_name, SN_NOWARN | SN_NOCHECK)
def MakeFunction(start, end): def MakeFunction(start):
next_func = idc.get_next_func(start) ida_funcs.add_func(start)
if next_func < end: ");
end = next_func
current_func = idaapi.get_func(start)
if current_func is not None and current_func.startEA == start:
ida_funcs.del_func(start)
ida_funcs.add_func(start, end)"
);
// Compatibility (in a separate decl block in case these are already defined) // Compatibility (in a separate decl block in case these are already defined)
writeDecls(@" writeDecls(@"
@@ -162,8 +156,7 @@ typedef __int64 int64_t;
private void writeFunctions() { private void writeFunctions() {
foreach (var func in model.Package.FunctionAddresses) foreach (var func in model.Package.FunctionAddresses)
if (func.Key != func.Value) writeLine($"MakeFunction({func.Key.ToAddressString()})");
writeLine($"MakeFunction({func.Key.ToAddressString()}, {func.Value.ToAddressString()})");
} }
private void writeMetadata() { private void writeMetadata() {