GP-5586 Refactored and fixed function stack frame editor

This commit is contained in:
ghidra1 2025-04-11 10:40:36 -04:00
parent 4a46edc9fe
commit 72a94daa1d
20 changed files with 1920 additions and 1949 deletions

View file

@ -36,8 +36,7 @@ class DataTypeComponentDB implements InternalDataTypeComponent {
private final ComponentDBAdapter adapter;
private final DBRecord record; // null record -> immutable component
private final CompositeDB parent;
private DataType cachedDataType; // required for bit-fields during packing process
private final DataType cachedDataType; // used by immutable defined component (no record)
private int ordinal;
private int offset;
@ -56,9 +55,15 @@ class DataTypeComponentDB implements InternalDataTypeComponent {
*/
DataTypeComponentDB(DataTypeManagerDB dataMgr, CompositeDB parent, int ordinal, int offset,
DataType datatype, int length) {
this(dataMgr, parent, ordinal, offset);
this.dataMgr = dataMgr;
this.parent = parent;
this.cachedDataType = datatype;
this.ordinal = ordinal;
this.offset = offset;
this.length = length;
this.record = null;
this.adapter = null;
}
/**
@ -73,6 +78,8 @@ class DataTypeComponentDB implements InternalDataTypeComponent {
this.dataMgr = dataMgr;
this.parent = parent;
this.ordinal = ordinal;
this.cachedDataType = null;
this.offset = offset;
this.length = 1;
this.record = null;
@ -90,11 +97,13 @@ class DataTypeComponentDB implements InternalDataTypeComponent {
DBRecord record) {
this.dataMgr = dataMgr;
this.adapter = adapter;
this.cachedDataType = null;
this.record = record;
this.parent = parent;
ordinal = record.getIntValue(ComponentDBAdapter.COMPONENT_ORDINAL_COL);
offset = record.getIntValue(ComponentDBAdapter.COMPONENT_OFFSET_COL);
length = record.getIntValue(ComponentDBAdapter.COMPONENT_SIZE_COL);
this.ordinal = record.getIntValue(ComponentDBAdapter.COMPONENT_ORDINAL_COL);
this.offset = record.getIntValue(ComponentDBAdapter.COMPONENT_OFFSET_COL);
this.length = record.getIntValue(ComponentDBAdapter.COMPONENT_SIZE_COL);
if (isZeroBitFieldComponent()) {
length = 0; // previously stored as 1, force to 0
}

View file

@ -1378,11 +1378,13 @@ class StructureDB extends CompositeDB implements StructureInternal {
* @param componentName name of component replacement (may be null)
* @param comment comment for component replacement (may be null)
* @return new/updated component (may be null if replacement is not a defined component)
* @throws IllegalArgumentException if unable to identify/make sufficient space
* @throws IOException if an IO error occurs
*/
private DataTypeComponent doComponentReplacement(
LinkedList<DataTypeComponentDB> replacedComponents, int offset, DataType dataType,
int length, String componentName, String comment) throws IOException {
int length, String componentName, String comment)
throws IllegalArgumentException, IOException {
// Attempt quick update of a single defined component if possible.
// A quick update requires that component characteristics including length, offset,
@ -1416,13 +1418,14 @@ class StructureDB extends CompositeDB implements StructureInternal {
@Override
public final DataTypeComponent replace(int ordinal, DataType dataType, int length)
throws IllegalArgumentException {
throws IllegalArgumentException, IndexOutOfBoundsException {
return replace(ordinal, dataType, length, null, null);
}
@Override
public DataTypeComponent replace(int ordinal, DataType dataType, int length,
String componentName, String comment) {
String componentName, String comment)
throws IllegalArgumentException, IndexOutOfBoundsException {
lock.acquire();
try {
checkDeleted();

View file

@ -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.
@ -277,16 +277,18 @@ class FunctionStackFrame implements StackFrame {
function.setLocalSize(size);
}
/*
* (non-Javadoc)
* @see ghidra.program.model.listing.StackFrame#getParameterSize()
*/
@Override
public int getParameterSize() {
function.manager.lock.acquire();
try {
checkIsValid();
// NOTE: This logic is sensitive to the existance of Local variables at the incorrect
// stack offset placed before parameters. This can occur when adjustments are made to
// the prototype model's stack pentry specification. Unfortunately, the distinction
// between a parameter and a local is locked-in at the time of creation due to the
// use of distinct symbol types.
int baseOffset = 0;
Integer base = VariableUtilities.getBaseStackParamOffset(function);
if (base != null) {

View file

@ -44,7 +44,8 @@ public interface Structure extends Composite {
public DataTypeComponent getComponent(int ordinal) throws IndexOutOfBoundsException;
/**
* Gets the first defined component located at or after the specified offset.
* Gets the first defined component located at or after the specified offset. If a
* component contains the specified offset that component will be returned.
* Note: The returned component may be a zero-length component.
*
* @param offset the byte offset into this structure
@ -436,7 +437,7 @@ public interface Structure extends Composite {
* @throws IllegalArgumentException if amount &lt; 0
*/
public void growStructure(int amount);
/**
* Set the size of the structure to the specified byte-length. If the length is shortened defined
* components will be cleared and removed as required.

View file

@ -107,13 +107,6 @@ public interface StackFrame {
*/
public int getParameterOffset();
// /**
// * Set the offset on the stack of the parameters.
// *
// * @param offset the start offset of parameters on the stack
// */
// public void setParameterOffset(int offset) throws InvalidInputException;
/**
* Returns true if specified offset could correspond to a parameter
* @param offset