Ghidra is a software reverse engineering (SRE) framework
GP-4150 add option to ignore DWARF func param storage info
dev747368de80c63e63c5
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFFunctionImporter.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFFunctionImporter.javaindex beafdc1845..01685aef08 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFFunctionImporter.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFFunctionImporter.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -196,6 +196,14 @@ public class DWARFFunctionImporter {dfunc.runFixups();+ String defaultCC = prog.getImportOptions().getDefaultCC();+ if (defaultCC != null && defaultCC.isBlank()) {+ defaultCC = null;+ }+ if (dfunc.callingConventionName == null && defaultCC != null) {+ dfunc.callingConventionName = defaultCC;+ }+decorateFunctionWithDWARFInfo(dfunc, origFuncDef);if (dfunc.signatureCommitMode != CommitMode.SKIP) {diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFImportOptions.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFImportOptions.javaindex 6d32032fe9..215256cceb 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFImportOptions.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFImportOptions.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -70,6 +70,14 @@ public class DWARFImportOptions {private static final String OPTION_IMPORT_LOCAL_VARS_DESC ="Import local variable information from DWARF and attempt to create Ghidra local variables.";+ private static final String OPTION_IGNORE_PARAM_STORAGE = "Ignore Parameter Storage Info";+ private static final String OPTION_IGNORE_PARAM_STORAGE_DESC =+ "Ignore any function parameter storage info specifed, allow automatic layout.";++ private static final String OPTION_DEFAULT_CC = "Default Calling Convention";+ private static final String OPTION_DEFAULT_CC_DESC =+ "Name of default calling convention to assign to functions (e.g. __cdecl, __stdcall, etc), or leave blank.";+//==================================================================================================// Old Option Names - Should stick around for multiple major versions after 10.2//==================================================================================================@@ -104,6 +112,8 @@ public class DWARFImportOptions {private boolean importLocalVariables = true;private boolean useBookmarks = true;private boolean outputSourceLineInfo = false;+ private boolean ignoreParamStorage = false;+ private String defaultCC = "";/*** Create new instance@@ -374,6 +384,22 @@ public class DWARFImportOptions {this.outputSourceLineInfo = outputSourceLineInfo;}+ public boolean isIgnoreParamStorage() {+ return ignoreParamStorage;+ }++ public void setIgnoreParamStorage(boolean ignoreParamStorage) {+ this.ignoreParamStorage = ignoreParamStorage;+ }++ public String getDefaultCC() {+ return defaultCC;+ }++ public void setDefaultCC(String defaultCC) {+ this.defaultCC = defaultCC;+ }+/*** See {@link Analyzer#registerOptions(Options, ghidra.program.model.listing.Program)}*@@ -409,6 +435,11 @@ public class DWARFImportOptions {options.registerOption(OPTION_SOURCE_LINEINFO, isOutputSourceLineInfo(), null,OPTION_SOURCE_LINEINFO_DESC);++ options.registerOption(OPTION_IGNORE_PARAM_STORAGE, isIgnoreParamStorage(), null,+ OPTION_IGNORE_PARAM_STORAGE_DESC);++ options.registerOption(OPTION_DEFAULT_CC, getDefaultCC(), null, OPTION_DEFAULT_CC_DESC);}/**@@ -433,6 +464,9 @@ public class DWARFImportOptions {options.getBoolean(OPTION_IMPORT_LOCAL_VARS, isImportLocalVariables()));setOutputSourceLineInfo(options.getBoolean(OPTION_SOURCE_LINEINFO, isOutputSourceLineInfo()));+ setIgnoreParamStorage(+ options.getBoolean(OPTION_IGNORE_PARAM_STORAGE, isIgnoreParamStorage()));+ setDefaultCC(options.getString(OPTION_DEFAULT_CC, getDefaultCC()));}}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/StorageVerificationDWARFFunctionFixup.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/StorageVerificationDWARFFunctionFixup.javaindex c364be9782..ec281168fc 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/StorageVerificationDWARFFunctionFixup.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/funcfixup/StorageVerificationDWARFFunctionFixup.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -16,8 +16,8 @@package ghidra.app.util.bin.format.dwarf.funcfixup;import ghidra.app.util.bin.format.dwarf.DWARFFunction;-import ghidra.app.util.bin.format.dwarf.DWARFVariable;import ghidra.app.util.bin.format.dwarf.DWARFFunction.CommitMode;+import ghidra.app.util.bin.format.dwarf.DWARFVariable;import ghidra.util.classfinder.ExtensionPointProperties;/**@@ -32,6 +32,14 @@ public class StorageVerificationDWARFFunctionFixup implements DWARFFunctionFixup@Overridepublic void fixupDWARFFunction(DWARFFunction dfunc) {+ boolean ignoreStorage = dfunc.getProgram().getImportOptions().isIgnoreParamStorage() ||+ dfunc.getProgram().getRegisterMappings().isUseFormalParameterStorage();+ boolean isEmptySignature = dfunc.params.isEmpty() && dfunc.retval.isVoidType();+ if (ignoreStorage || isEmptySignature) {+ dfunc.signatureCommitMode = CommitMode.FORMAL;+ return;+ }+boolean storageIsGood = true;for (DWARFVariable param : dfunc.params) {if (param.isMissingStorage() && !param.isZeroByte()) {diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/GolangDWARFFunctionFixup.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/GolangDWARFFunctionFixup.javaindex d50f254488..b18afde3ff 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/GolangDWARFFunctionFixup.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/GolangDWARFFunctionFixup.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -68,7 +68,7 @@ public class GolangDWARFFunctionFixup implements DWARFFunctionFixup {return false;}// sanity check: gofuncs always have a void return type in dwarf- if (!dfunc.retval.type.isEquivalent(VoidDataType.dataType)) {+ if (!dfunc.retval.isVoidType()) {return false;}return true;diff --git a/Ghidra/Processors/ARM/data/languages/ARM.dwarf b/Ghidra/Processors/ARM/data/languages/ARM.dwarfindex 0444463e93..4d4a18228f 100644--- a/Ghidra/Processors/ARM/data/languages/ARM.dwarf+++ b/Ghidra/Processors/ARM/data/languages/ARM.dwarf@@ -8,5 +8,11 @@<register_mapping dwarf="17" ghidra="cpsr"/></register_mappings><call_frame_cfa value="0"/>- <use_formal_parameter_storage/>+ <!--+ In the past, this flag has been present in this file but was not correctly implemented in+ the DWARF analyzer. The DWARF analyzer now respects this flag, and also has the+ "Ignore Parameter Storage Info" toggle option to enable the same feature.+ This flag is being left disabled to match recent DWARF analyzer behavior.+ <use_formal_parameter_storage/>+ --></dwarf>diff --git a/Ghidra/Processors/ARM/data/languages/ARMneon.dwarf b/Ghidra/Processors/ARM/data/languages/ARMneon.dwarfindex fa2ff76207..a6cd403bff 100644--- a/Ghidra/Processors/ARM/data/languages/ARMneon.dwarf+++ b/Ghidra/Processors/ARM/data/languages/ARMneon.dwarf@@ -10,5 +10,11 @@<register_mapping dwarf="64" ghidra="s0" auto_count="32"/> <!-- s0..s31 --></register_mappings><call_frame_cfa value="0"/>- <use_formal_parameter_storage/>+ <!--+ In the past, this flag has been present in this file but was not correctly implemented in+ the DWARF analyzer. The DWARF analyzer now respects this flag, and also has the+ "Ignore Parameter Storage Info" toggle option to enable the same feature.+ This flag is being left disabled to match recent DWARF analyzer behavior.+ <use_formal_parameter_storage/>+ --></dwarf>