Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-6055 golang ASM funcs and abi0 callingconvention

dev747368fbef94d9f987
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/GolangSymbolAnalyzer.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/GolangSymbolAnalyzer.java
index 2d31c9333e..ccfb065cd6 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/GolangSymbolAnalyzer.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/GolangSymbolAnalyzer.java
@@ -276,17 +276,19 @@ public class GolangSymbolAnalyzer extends AbstractAnalyzer {
functionSignatureFromMethod++;
}
- GoFunctionFixup ff = new GoFunctionFixup(func, funcDefResult.funcDef(),
- goBinary.getCallingConventionFor(funcdata), goBinary.newStorageAllocator());
+ if (funcdata.getFlags().isEmpty()) {
+ GoFunctionFixup ff = new GoFunctionFixup(func, funcDefResult.funcDef(),
+ goBinary.getDefaultCallingConventionName(), goBinary.newStorageAllocator());
- try {
- ff.apply();
- }
- catch (DuplicateNameException | InvalidInputException
- | IllegalArgumentException e) {
- MarkupSession.logWarningAt(program, func.getEntryPoint(),
- "Failed to update function signature: " + e.getMessage());
- continue;
+ try {
+ ff.apply();
+ }
+ catch (DuplicateNameException | InvalidInputException
+ | IllegalArgumentException e) {
+ MarkupSession.logWarningAt(program, func.getEntryPoint(),
+ "Failed to update function signature: " + e.getMessage());
+ continue;
+ }
}
if (funcDefResult.symbolName().hasReceiver()) {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/GoFunctionFixup.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/GoFunctionFixup.java
index 2de717fa75..f04a161da4 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/GoFunctionFixup.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/GoFunctionFixup.java
@@ -53,24 +53,36 @@ public class GoFunctionFixup {
this.func = func;
this.storageAllocator = new GoParamStorageAllocator(program, goVersion);
this.newSignature = func.getSignature();
- this.newCallingConv = null;
if (GoRttiMapper.isAbi0Func(func.getEntryPoint(), program)) {
// Some (typically lower level) functions in the binary will be marked with a
// symbol that ends in the string "abi0".
// Throw away all registers and force stack allocation for everything
storageAllocator.setAbi0Mode();
+ this.newCallingConv = GoConstants.GOLANG_ABI0_CALLINGCONVENTION_NAME;
+ }
+ else {
+ this.newCallingConv = null;
}
}
- public GoFunctionFixup(Function func, FunctionSignature newSignature, String newCallingConv,
+ public GoFunctionFixup(Function func, FunctionSignature newSignature, String defaultCCName,
GoParamStorageAllocator storageAllocator) {
this.program = func.getProgram();
this.dtm = program.getDataTypeManager();
this.func = func;
this.storageAllocator = storageAllocator;
this.newSignature = newSignature;
- this.newCallingConv = newCallingConv;
+ if (GoRttiMapper.isAbi0Func(func.getEntryPoint(), program)) {
+ // Some (typically lower level) functions in the binary will be marked with a
+ // symbol that ends in the string "abi0".
+ // Throw away all registers and force stack allocation for everything
+ storageAllocator.setAbi0Mode();
+ this.newCallingConv = GoConstants.GOLANG_ABI0_CALLINGCONVENTION_NAME;
+ }
+ else {
+ this.newCallingConv = defaultCCName;
+ }
}
public static boolean isClosureContext(ParameterDefinition p) {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/rtti/GoRttiMapper.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/rtti/GoRttiMapper.java
index a274200b78..4b7ff336ec 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/rtti/GoRttiMapper.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/rtti/GoRttiMapper.java
@@ -552,14 +552,6 @@ public class GoRttiMapper extends DataTypeMapper implements DataTypeMapperContex
return false;
}
- public String getCallingConventionFor(GoFuncData func) {
- // TODO: this logic needs work. Currently we are not strongly declaring functions
- // as abi0.
- return defaultCCName != null && !isAbi0Func(func.getFuncAddress(), program)
- ? defaultCCName
- : null;
- }
-
/**
* Returns true if the specified calling convention is defined for the program.
* @param ccName calling convention name