From d39a5e836549805c853568ae32b3bf39923e0a75 Mon Sep 17 00:00:00 2001 From: James <49045138+ghidracadabra@users.noreply.github.com> Date: Thu, 14 Dec 2023 20:17:50 +0000 Subject: [PATCH] GP-4149 frame descriptor entry fix and msp430 improvements --- .../ehFrame/FrameDescriptionEntry.java | 33 +++++++++++-------- .../TI_MSP430/certification.manifest | 2 ++ .../TI_MSP430/data/languages/TI_MSP430.cspec | 22 ++++++++++++- .../TI_MSP430/data/languages/TI_MSP430.dwarf | 9 +++++ .../TI_MSP430/data/languages/TI_MSP430.ldefs | 5 ++- .../TI_MSP430/data/languages/TI_MSP430X.cspec | 24 +++++++++++++- .../TI_MSP430/data/languages/TI_MSP430X.dwarf | 9 +++++ 7 files changed, 87 insertions(+), 17 deletions(-) create mode 100644 Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430.dwarf create mode 100644 Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430X.dwarf diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/structures/ehFrame/FrameDescriptionEntry.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/structures/ehFrame/FrameDescriptionEntry.java index f492dad644..cbe33418b0 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/structures/ehFrame/FrameDescriptionEntry.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/structures/ehFrame/FrameDescriptionEntry.java @@ -30,6 +30,7 @@ import ghidra.program.model.listing.*; import ghidra.program.model.mem.*; import ghidra.program.model.symbol.*; import ghidra.program.model.util.CodeUnitInsertionException; +import ghidra.util.DataConverter; import ghidra.util.Msg; import ghidra.util.exception.InvalidInputException; import ghidra.util.task.TaskMonitor; @@ -228,8 +229,8 @@ public class FrameDescriptionEntry extends GccAnalysisClass { curSize += locTypeSize; - program.getReferenceManager().addMemoryReference(addr, cieAddr, RefType.DATA, - SourceType.ANALYSIS, 0); + program.getReferenceManager() + .addMemoryReference(addr, cieAddr, RefType.DATA, SourceType.ANALYSIS, 0); return addr.add(locTypeSize); } @@ -267,8 +268,8 @@ public class FrameDescriptionEntry extends GccAnalysisClass { createAndCommentData(program, addr, encodedDt, comment, CodeUnit.EOL_COMMENT); if (pcBeginAddr.getOffset() != 0x0) { - program.getReferenceManager().addMemoryReference(addr, pcBeginAddr, RefType.DATA, - SourceType.ANALYSIS, 0); + program.getReferenceManager() + .addMemoryReference(addr, pcBeginAddr, RefType.DATA, SourceType.ANALYSIS, 0); } curSize += encodedLen; @@ -293,7 +294,12 @@ public class FrameDescriptionEntry extends GccAnalysisClass { */ String comment = "(FDE) PcRange"; - intPcRange = (int) GccAnalysisUtils.readDWord(program, addr); + DataType dataType = getAddressSizeDataType(); + byte[] range = new byte[dataType.getLength()]; + GccAnalysisUtils.readBytes(program, addr, range); + DataConverter converter = DataConverter.getInstance(program.getMemory().isBigEndian()); + intPcRange = (int) converter.getSignedValue(range, range.length); + if (intPcRange < 0) { return null; } @@ -303,7 +309,6 @@ public class FrameDescriptionEntry extends GccAnalysisClass { } pcEndAddr = pcBeginAddr.add(intPcRange - 1); - DataType dataType = getAddressSizeDataType(); if (dataType.getLength() == 8) { // While this is 64-bit system, this length may be encoded as a 32-bit value, // arguing a length needn't use all 8 bytes. If it *is* encoded in 8 bytes, the @@ -389,8 +394,6 @@ public class FrameDescriptionEntry extends GccAnalysisClass { * @throws MemoryAccessException if the required memory can't be read */ private Address createCallFrameInstructions(Address addr) throws MemoryAccessException { - CreateArrayCmd arrayCmd = null; - // Create initial instructions array with remaining bytes. int instructionLength = intLength - curSize; ArrayDataType adt = new ArrayDataType(ByteDataType.dataType, instructionLength, BYTE_LEN); @@ -589,16 +592,17 @@ public class FrameDescriptionEntry extends GccAnalysisClass { createData(program, augmentationDataAddr, DWordDataType.dataType); - program.getReferenceManager().addMemoryReference(augmentationDataAddr, - augmentationDataExAddr, RefType.DATA, SourceType.ANALYSIS, 0); + program.getReferenceManager() + .addMemoryReference(augmentationDataAddr, augmentationDataExAddr, + RefType.DATA, SourceType.ANALYSIS, 0); try { String label = "eh_augmentation_" + pcBeginAddr + ".." + pcEndAddr + "_" + augmentationDataExAddr; - program.getSymbolTable().createLabel(augmentationDataExAddr, label, - SourceType.ANALYSIS); + program.getSymbolTable() + .createLabel(augmentationDataExAddr, label, SourceType.ANALYSIS); } catch (InvalidInputException e) { // ignored @@ -634,8 +638,9 @@ public class FrameDescriptionEntry extends GccAnalysisClass { return; } - program.getReferenceManager().addMemoryReference(augmentationDataAddr, lsdaAddr, - RefType.DATA, SourceType.ANALYSIS, 0); + program.getReferenceManager() + .addMemoryReference(augmentationDataAddr, lsdaAddr, RefType.DATA, + SourceType.ANALYSIS, 0); if (!program.getMemory().getAllInitializedAddressSet().contains(lsdaAddr)) { diff --git a/Ghidra/Processors/TI_MSP430/certification.manifest b/Ghidra/Processors/TI_MSP430/certification.manifest index 6f3226852c..8fc757c16a 100644 --- a/Ghidra/Processors/TI_MSP430/certification.manifest +++ b/Ghidra/Processors/TI_MSP430/certification.manifest @@ -3,10 +3,12 @@ Module.manifest||GHIDRA||||END| data/languages/TI430Common.sinc||GHIDRA||||END| data/languages/TI430X.sinc||GHIDRA||||END| data/languages/TI_MSP430.cspec||GHIDRA||||END| +data/languages/TI_MSP430.dwarf||GHIDRA||||END| data/languages/TI_MSP430.ldefs||GHIDRA||||END| data/languages/TI_MSP430.pspec||GHIDRA||||END| data/languages/TI_MSP430.slaspec||GHIDRA||||END| data/languages/TI_MSP430X.cspec||GHIDRA||||END| +data/languages/TI_MSP430X.dwarf||GHIDRA||||END| data/languages/TI_MSP430X.slaspec||GHIDRA||||END| data/languages/ti_msp430.opinion||GHIDRA||||END| data/manuals/MSP430.idx||GHIDRA||reviewed||END| diff --git a/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430.cspec b/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430.cspec index 8d909eebbf..5f5bf8fe84 100644 --- a/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430.cspec +++ b/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430.cspec @@ -1,6 +1,26 @@ - + + + + + + + + + + + + + + + + + + + + + diff --git a/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430.dwarf b/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430.dwarf new file mode 100644 index 0000000000..46b3c70446 --- /dev/null +++ b/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430.dwarf @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430.ldefs b/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430.ldefs index e8bfbcbf2b..4f980021f6 100644 --- a/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430.ldefs +++ b/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430.ldefs @@ -12,7 +12,8 @@ id="TI_MSP430:LE:16:default"> TI MSP430 16-Bit MicroController - + + TI MSP430X 20-Bit MicroController + + diff --git a/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430X.cspec b/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430X.cspec index 85cacd4578..edccb2ec9c 100644 --- a/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430X.cspec +++ b/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430X.cspec @@ -1,6 +1,28 @@ - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430X.dwarf b/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430X.dwarf new file mode 100644 index 0000000000..41c550c6d1 --- /dev/null +++ b/Ghidra/Processors/TI_MSP430/data/languages/TI_MSP430X.dwarf @@ -0,0 +1,9 @@ + + + + + + + + +