Ghidra is a software reverse engineering (SRE) framework
GP-3200 - PDB - Smarter, restricted creation of functions for global labels
ghizard56322bf94ecc
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/symbol/ProcedureFlags.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/symbol/ProcedureFlags.javaindex 8ef515e547..fb5a4123fb 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/symbol/ProcedureFlags.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/symbol/ProcedureFlags.java@@ -25,6 +25,20 @@ import ghidra.app.util.bin.format.pdb2.pdbreader.type.AbstractProcedureMsType;*/public class ProcedureFlags extends AbstractParsableItem {+ private static final int HAS_FRAME_POINTER_PRESENT = 0x0001;+ private static final int HAS_INTERRUPT_RETURN = 0x0002;+ private static final int HAS_FAR_RETURN = 0x0004;+ private static final int DOES_NOT_RETURN = 0x0008;+ private static final int LABEL_NOT_REACHED = 0x0010;+ private static final int HAS_CUSTOM_CALLING_CONVENTION = 0x0020;+ private static final int MARKED_AS_NO_INLINE = 0x0040;+ private static final int HAS_DEBUG_INFORMATION_FOR_OPTIMIZED_CODE = 0x0080;++ private static final int FUNCTION_INDICATION =+ HAS_FRAME_POINTER_PRESENT | HAS_INTERRUPT_RETURN | HAS_FAR_RETURN | DOES_NOT_RETURN |+ LABEL_NOT_REACHED | HAS_CUSTOM_CALLING_CONVENTION | MARKED_AS_NO_INLINE |+ HAS_DEBUG_INFORMATION_FOR_OPTIMIZED_CODE;+private int flagByte;/**@@ -55,7 +69,7 @@ public class ProcedureFlags extends AbstractParsableItem {* @return true if frame pointer is present*/public boolean hasFramePointerPresent() {- return (flagByte & 0x0001) == 0x0001;+ return (flagByte & HAS_FRAME_POINTER_PRESENT) != 0;}/**@@ -63,7 +77,7 @@ public class ProcedureFlags extends AbstractParsableItem {* @return true if has an interrupt return*/public boolean hasInterruptReturn() {- return (flagByte & 0x0002) == 0x0002;+ return (flagByte & HAS_INTERRUPT_RETURN) != 0;}/**@@ -71,7 +85,7 @@ public class ProcedureFlags extends AbstractParsableItem {* @return true if has a far return*/public boolean hasFarReturn() {- return (flagByte & 0x0004) == 0x0004;+ return (flagByte & HAS_FAR_RETURN) != 0;}/**@@ -79,7 +93,7 @@ public class ProcedureFlags extends AbstractParsableItem {* @return true if does not return*/public boolean doesNotReturn() {- return (flagByte & 0x0008) == 0x0008;+ return (flagByte & DOES_NOT_RETURN) != 0;}/**@@ -87,7 +101,7 @@ public class ProcedureFlags extends AbstractParsableItem {* @return true if label is not reached*/public boolean labelNotReached() {- return (flagByte & 0x0010) == 0x0010;+ return (flagByte & LABEL_NOT_REACHED) != 0;}/**@@ -99,7 +113,7 @@ public class ProcedureFlags extends AbstractParsableItem {* @return true if has custom calling convention*/public boolean hasCustomCallingConvention() {- return (flagByte & 0x0020) == 0x0020;+ return (flagByte & HAS_CUSTOM_CALLING_CONVENTION) != 0;}/**@@ -107,7 +121,7 @@ public class ProcedureFlags extends AbstractParsableItem {* @return true if marked as {@code noinline}*/public boolean markedAsNoInline() {- return (flagByte & 0x0040) == 0x0040;+ return (flagByte & MARKED_AS_NO_INLINE) != 0;}/**@@ -115,7 +129,15 @@ public class ProcedureFlags extends AbstractParsableItem {* @return true if has debug information for optimized code*/public boolean hasDebugInformationForOptimizedCode() {- return (flagByte & 0x0080) == 0x0080;+ return (flagByte & HAS_DEBUG_INFORMATION_FOR_OPTIMIZED_CODE) != 0;}+ /**+ * Returns true if seems like a function. Not necessary, but (seems) sufficient, to indicate a+ * function (this is Ghidra functionality not specified in PDB API)+ * @return true if function indicated+ */+ public boolean hasFunctionIndication() {+ return (flagByte & FUNCTION_INDICATION) != 0x0000;+ }}diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/LabelSymbolApplier.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/LabelSymbolApplier.javaindex aaa8e0e0fb..8647fed2aa 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/LabelSymbolApplier.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/LabelSymbolApplier.java@@ -25,7 +25,8 @@ import ghidra.app.util.bin.format.pdb2.pdbreader.symbol.AbstractLabelMsSymbol;import ghidra.app.util.bin.format.pdb2.pdbreader.symbol.AbstractMsSymbol;import ghidra.app.util.pdb.pdbapplicator.SymbolGroup.AbstractMsSymbolIterator;import ghidra.program.model.address.Address;-import ghidra.program.model.listing.*;+import ghidra.program.model.listing.Function;+import ghidra.program.model.listing.Instruction;import ghidra.program.model.symbol.SourceType;import ghidra.util.Msg;import ghidra.util.exception.*;@@ -70,11 +71,20 @@ public class LabelSymbolApplier extends MsSymbolApplier {return;}- // The applyFunction call hierarchy here, was copied and modified from FunctionSymbolApplier.- // We need to re-look at this and create common as possibly in applicator or utility or- // else where. Note that our applyFunction here does not apply a function definition, as- // we have no data type associated with the label.- applyFunction(symbolAddress, label, applicator.getCancelOnlyWrappingMonitor());+ // Create function or label, depending on what is indicated. Note that the indicator is+ // sufficient, but not necessary for a function; thus, we might not create a function+ // where one exists. However, other analyses, such as EntryPointAnalysis might pick+ // this up.+ if (hasFunctionIndication()) {+ // The applyFunction call hierarchy here, was copied and modified from+ // FunctionSymbolApplier. We need to re-look at this and create common as possibly+ // in applicator or utility or else where. Note that our applyFunction here does not+ // apply a function definition, as we have no data type associated with the label.+ applyFunction(symbolAddress, label, applicator.getCancelOnlyWrappingMonitor());+ }+ else {+ applicator.createSymbol(symbolAddress, label, true);+ }}@Override@@ -118,6 +128,15 @@ public class LabelSymbolApplier extends MsSymbolApplier {applicator.createSymbol(symbolAddress, label, false);}+ /**+ * Returns true if seems like a function. Not necessary, but (seems) sufficient, to indicate a+ * function+ * @return true if function indicated+ */+ private boolean hasFunctionIndication() {+ return symbol.getFlags().hasFunctionIndication();+ }+/*** Returns true if there is a specific indication that the function is non-returning.* @return true if positive indication is given