Skip to content

Commit 66128cb

Browse files
Lin Chencopybara-github
authored andcommitted
Ghidra: Fix BinExport2Builder's promoteUndefinedFunctions.
PiperOrigin-RevId: 863174575 Change-Id: Ic66b1777df59d279a1809accffa713cf23a7e313
1 parent 8d303f1 commit 66128cb

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

java/src/main/java/com/google/security/binexport/BinExport2Builder.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import com.google.security.zynamics.BinExport.BinExport2;
2424
import com.google.security.zynamics.BinExport.BinExport2.Builder;
2525
import ghidra.app.nav.NavigationUtils;
26-
import ghidra.program.database.function.OverlappingFunctionException;
2726
import ghidra.program.database.symbol.EquateDB;
27+
import ghidra.program.flatapi.FlatProgramAPI;
2828
import ghidra.program.model.address.Address;
2929
import ghidra.program.model.address.AddressSetView;
3030
import ghidra.program.model.block.BasicBlockModel;
@@ -61,7 +61,6 @@
6161
import ghidra.program.util.DefinedDataIterator;
6262
import ghidra.util.UndefinedFunction;
6363
import ghidra.util.exception.CancelledException;
64-
import ghidra.util.exception.InvalidInputException;
6564
import ghidra.util.task.TaskMonitor;
6665
import java.io.File;
6766
import java.util.ArrayList;
@@ -749,6 +748,7 @@ private void buildBasicBlocks(
749748

750749
private void promoteUndefinedFunctions() throws CancelledException {
751750
FunctionManager funcManager = program.getFunctionManager();
751+
FlatProgramAPI flatProgramApi = new FlatProgramAPI(program);
752752

753753
for (var bbIter = bbModel.getCodeBlocks(monitor); bbIter.hasNext(); ) {
754754
CodeBlock bb = bbIter.next();
@@ -761,22 +761,12 @@ private void promoteUndefinedFunctions() throws CancelledException {
761761
UndefinedFunction undefinedFunction =
762762
UndefinedFunction.findFunction(program, bbEntryPoint, monitor);
763763
if (undefinedFunction != null) {
764-
try {
765-
Function newFunc =
766-
funcManager.createFunction(
767-
undefinedFunction.getName(),
768-
undefinedFunction.getEntryPoint(),
769-
undefinedFunction.getBody(),
770-
undefinedFunction.getSignatureSource());
771-
if (newFunc != null) {
772-
monitor.setMessage(
773-
String.format("Created undefined function at %x", getMappedAddress(bbEntryPoint)));
774-
System.out.printf("newUndefinedFunction: %x%n", getMappedAddress(bbEntryPoint));
775-
}
776-
} catch (InvalidInputException | OverlappingFunctionException e) {
764+
Function newFunc =
765+
flatProgramApi.createFunction(
766+
undefinedFunction.getEntryPoint(), undefinedFunction.getName());
767+
if (newFunc != null) {
777768
monitor.setMessage(
778-
String.format(
779-
"Failed to create undefined function at %x", getMappedAddress(bbEntryPoint)));
769+
String.format("Created undefined function at %x", getMappedAddress(bbEntryPoint)));
780770
}
781771
}
782772
}

0 commit comments

Comments
 (0)