From d26fb9911e99c29436f84e348c35623cf6f9dca0 Mon Sep 17 00:00:00 2001 From: Dan <46821332+nsadeveloper789@users.noreply.github.com> Date: Thu, 3 Aug 2023 11:29:31 -0400 Subject: [PATCH 1/4] GP-3700: Fix indirect branching operand size mismatch. --- .../src/main/java/ghidra/pcode/exec/PcodeExecutor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/exec/PcodeExecutor.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/exec/PcodeExecutor.java index 0e52acdeee..a5ce01bc07 100644 --- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/exec/PcodeExecutor.java +++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/exec/PcodeExecutor.java @@ -411,7 +411,9 @@ public class PcodeExecutor { * @param frame the frame to finish */ protected void branchToOffset(T offset, PcodeFrame frame) { - state.setVar(pc, offset); + T truncOff = arithmetic.unaryOp(PcodeOp.COPY, pc.getMinimumByteSize(), + (int) arithmetic.sizeOf(offset), offset); + state.setVar(pc, truncOff); frame.finishAsBranch(); } From 486a509ee364823b9a3178df974fd703b9b46544 Mon Sep 17 00:00:00 2001 From: Dan <46821332+nsadeveloper789@users.noreply.github.com> Date: Thu, 3 Aug 2023 11:56:02 -0400 Subject: [PATCH 2/4] GP-3661: Fix address hover outside of default address space. --- .../java/ghidra/trace/database/program/DBTraceProgramView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramView.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramView.java index 5ae5ada266..652d9771bd 100644 --- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramView.java +++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramView.java @@ -1227,7 +1227,7 @@ public class DBTraceProgramView implements TraceProgramView { @Override public Address getImageBase() { - return language.getAddressFactory().getAddressSet().getMinAddress(); + return language.getDefaultSpace().getMinAddress(); } @Override From 554f1c87abc40520536cd7b9d1adf29b682cd888 Mon Sep 17 00:00:00 2001 From: ghidra1 Date: Thu, 27 Jul 2023 12:52:28 -0400 Subject: [PATCH 3/4] GP-3675 Removed use of aligned-length and forced alignment when creating data on selected regions --- .../app/cmd/data/CreateDataBackgroundCmd.java | 46 ++++++------------- .../compositeeditor/CompositeEditorModel.java | 6 ++- .../program/model/data/DataTypeInstance.java | 18 ++++++-- 3 files changed, 32 insertions(+), 38 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/data/CreateDataBackgroundCmd.java b/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/data/CreateDataBackgroundCmd.java index bb550afa54..3fc774b768 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/data/CreateDataBackgroundCmd.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/data/CreateDataBackgroundCmd.java @@ -126,38 +126,15 @@ public class CreateDataBackgroundCmd extends BackgroundCommand { return true; } - private static Address alignAddress(Address addr, int alignment) { - if (addr == null) { - return null; - } - long mod = addr.getOffset() % alignment; - if (mod == 0) { - return addr; - } - try { - return addr.addNoWrap(alignment - mod); - } - catch (AddressOverflowException e) { - // ignore - } - return null; - } - private void createData(Address start, Address end, DataType dataType, Program p, TaskMonitor monitor) throws CodeUnitInsertionException { - int alignment = 1; - if (newDataType.getLength() != newDataType.getAlignedLength()) { - // datatypes whose length does not match their aligned-length must - // be properly aligned to account for padding (e.g., x86-32 80-bit floats) - alignment = newDataType.getAlignment(); - } + Address nextAddr = start; + Listing listing = p.getListing(); + listing.clearCodeUnits(start, end, false); int initialProgress = bytesApplied; - Listing listing = p.getListing(); - listing.clearCodeUnits(start, end, false); - Address nextAddr = alignAddress(start, alignment); int length = (int) end.subtract(nextAddr) + 1; while (nextAddr != null && nextAddr.compareTo(end) <= 0) { if (monitor.isCancelled()) { @@ -165,19 +142,22 @@ public class CreateDataBackgroundCmd extends BackgroundCommand { } Data d = listing.createData(nextAddr, dataType, length); - Address maxDataAddr = d.getMaxAddress(); - bytesApplied = initialProgress + (int) maxDataAddr.subtract(start) + 1; - nextAddr = alignAddress(maxDataAddr.next(), alignment); - if (nextAddr != null) { - length = (int) end.subtract(nextAddr) + 1; + int dataLength = d.getLength(); + bytesApplied = initialProgress + dataLength; + + try { + nextAddr = nextAddr.addNoWrap(dataLength); + length -= dataLength; + } + catch (AddressOverflowException e) { + return; } monitor.setProgress(bytesApplied); if (++numDataCreated % 10000 == 0) { monitor.setMessage("Created " + numDataCreated); - // Allow the Swing thread a chance to paint components that may require - // a DB lock. + // Allow the Swing thread a chance to paint components that may require lock Swing.allowSwingToProcessEvents(); } } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorModel.java index 7b08494749..ef54361532 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorModel.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorModel.java @@ -212,7 +212,7 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen } DataType resultDt = DataUtilities.reconcileAppliedDataType(currentDt, dt, true); - int resultLen = resultDt.getAlignedLength(); + int resultLen = resultDt.getLength(); if (resultDt instanceof Dynamic) { resultLen = DataTypeHelper.requestDtSize(getProvider(), resultDt.getDisplayName(), @@ -222,7 +222,9 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen throw new InvalidDataTypeException("Data types of size 0 are not allowed."); } - return DataTypeInstance.getDataTypeInstance(resultDt, resultLen, true); + // TODO: Need to handle proper placement for big-endian within a larger component (i.e., right-justified) + return DataTypeInstance.getDataTypeInstance(resultDt, resultLen, + viewComposite.isPackingEnabled()); } /** diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeInstance.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeInstance.java index 560848301d..c75dca418b 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeInstance.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeInstance.java @@ -77,6 +77,11 @@ public class DataTypeInstance { /** * Generate a data-type instance * Factory and Dynamic data-types are NOT handled. + *
+ * This container does not dictate the placement of a fixed-length type within this + * container. It is suggested that big-endian use should evaulate the datatype + * at the far end of the container. + * * @param dataType data type * @param buf memory buffer * @param useAlignedLength if true a fixed-length primitive data type will use its @@ -95,6 +100,11 @@ public class DataTypeInstance { /** * Attempt to create a fixed-length data-type instance. * Factory and non-sizable Dynamic data-types are NOT handled. + *
+ * This container does not dictate the placement of a fixed-length type within this + * container. It is suggested that big-endian use should evaulate the datatype + * at the far end of the container. + * * @param dataType data type * @param length length for sizable Dynamic data-types, otherwise ignored * @param useAlignedLength if true a fixed-length primitive data type will use its @@ -128,6 +138,7 @@ public class DataTypeInstance { } } else if (useAlignedLength) { + // TODO: big-endian should place type at end of this container length = dataType.getAlignedLength(); } else { @@ -145,10 +156,11 @@ public class DataTypeInstance { * Attempt to create a data-type instance associated with a specific memory location. * Factory and Dynamic data-types are handled. *
- * NOTE: fixed-length primitive datatypes assume {@link DataType#getLength() raw datatype length} - * intended for {@link Data} use. + * This container does not dictate the placement of a fixed-length type within this + * container. It is suggested that big-endian use should evaulate the datatype + * at the far end of the container. * - * @param dataType + * @param dataType the data type * @param buf memory location * @param length length for sizable Dynamic data-types, otherwise ignored * @param useAlignedLength if true a fixed-length primitive data type will use its From f78ab92fc50f29cc701fb073d5ee38a18d81ac11 Mon Sep 17 00:00:00 2001 From: ghidra1 Date: Thu, 3 Aug 2023 14:58:40 -0400 Subject: [PATCH 4/4] GP-0 specify script log file for GhidraServer as server.log --- .../src/main/java/ghidra/server/remote/GhidraServer.java | 3 ++- .../ghidra/server/remote/GhidraServerApplicationLayout.java | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/remote/GhidraServer.java b/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/remote/GhidraServer.java index 0938aec291..bf61b2d010 100644 --- a/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/remote/GhidraServer.java +++ b/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/remote/GhidraServer.java @@ -723,7 +723,8 @@ public class GhidraServer extends UnicastRemoteObject implements GhidraServerHan System.exit(-1); } - Application.initializeLogging(new File(serverRoot, "server.log"), null); + File serverLogFile = new File(serverRoot, "server.log"); + Application.initializeLogging(serverLogFile, serverLogFile); // In the absence of module initialization - we must invoke directly SSLContextInitializer.initialize(); diff --git a/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/remote/GhidraServerApplicationLayout.java b/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/remote/GhidraServerApplicationLayout.java index 45f4594fc4..8f0f1a3ebd 100644 --- a/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/remote/GhidraServerApplicationLayout.java +++ b/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/remote/GhidraServerApplicationLayout.java @@ -57,8 +57,6 @@ public class GhidraServerApplicationLayout extends ApplicationLayout { // User directories (don't let anything use the user home directory...there may not be one) userTempDir = ApplicationUtilities.getDefaultUserTempDir(applicationProperties); - userSettingsDir = ApplicationUtilities.getDefaultUserSettingsDir(applicationProperties, - applicationInstallationDir); // Modules - required to find module data files modules = ModuleUtilities.findModules(applicationRootDirs,