mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-19 16:40:38 -09:00
GP-4855: Adding new fields and copy specials for various types of address offsets
This commit is contained in:
@@ -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.
|
||||
@@ -130,6 +130,9 @@ public class ToolOptions extends AbstractOptions {
|
||||
WrappedOption wo = (WrappedOption) constructor.newInstance();
|
||||
wo.readState(new SaveState(element));
|
||||
|
||||
if (wo instanceof WrappedCustomOption wrappedCustom && !wrappedCustom.isValid()) {
|
||||
continue;
|
||||
}
|
||||
if (wo instanceof WrappedKeyStroke wrappedKs) {
|
||||
wo = wrappedKs.toWrappedActionTrigger();
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* 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.
|
||||
@@ -21,28 +20,40 @@ import ghidra.util.Msg;
|
||||
public class WrappedCustomOption implements WrappedOption {
|
||||
|
||||
private CustomOption value;
|
||||
private boolean valid;
|
||||
|
||||
public WrappedCustomOption(CustomOption value) {
|
||||
this();
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public WrappedCustomOption() {
|
||||
|
||||
this.valid = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readState(SaveState saveState) {
|
||||
String customOptionClassName = saveState.getString("CUSTOM OPTION CLASS", null);
|
||||
valid = false;
|
||||
try {
|
||||
Class<?> c = Class.forName(customOptionClassName);
|
||||
value = (CustomOption) c.newInstance();
|
||||
value = (CustomOption) c.getConstructor().newInstance();
|
||||
value.readState(saveState);
|
||||
valid = true;
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
Msg.info(this,
|
||||
"Custom option class '%s' does not exist".formatted(customOptionClassName));
|
||||
}
|
||||
catch (Exception e) {
|
||||
Msg.error(this, "Can't create customOption instance for: " + customOptionClassName, e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeState(SaveState saveState) {
|
||||
saveState.putString("CUSTOM OPTION CLASS", value.getClass().getName());
|
||||
|
||||
@@ -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.
|
||||
@@ -19,28 +19,41 @@ import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.listing.Program;
|
||||
|
||||
/**
|
||||
* Provides specific information about a program location within the File Offset field
|
||||
* Provides specific information about a program location within an offset field
|
||||
*/
|
||||
public class FileOffsetFieldLocation extends CodeUnitLocation {
|
||||
public class OffsetFieldLocation extends CodeUnitLocation {
|
||||
|
||||
private OffsetFieldType type;
|
||||
|
||||
/**
|
||||
* Creates a new {@link FileOffsetFieldLocation} for the given address
|
||||
* Creates a new {@link OffsetFieldLocation} for the given address
|
||||
*
|
||||
* @param program the program
|
||||
* @param addr the address of the byte for this location
|
||||
* @param componentPath the path to data, or null
|
||||
* @param charOffset the position into the string representation indicating the exact
|
||||
* position within the field
|
||||
* @param type The {@link OffsetFieldType type} of offset field
|
||||
*/
|
||||
public FileOffsetFieldLocation(Program program, Address addr, int[] componentPath,
|
||||
int charOffset) {
|
||||
public OffsetFieldLocation(Program program, Address addr, int[] componentPath, int charOffset,
|
||||
OffsetFieldType type) {
|
||||
super(program, addr, componentPath, 0, 0, charOffset);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor needed for restoring the field location from XML
|
||||
*
|
||||
* @param type The {@link OffsetFieldType type} of offset field
|
||||
*/
|
||||
public FileOffsetFieldLocation() {
|
||||
public OffsetFieldLocation(OffsetFieldType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the type of offset field}
|
||||
*/
|
||||
public OffsetFieldType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* 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.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ghidra.program.util;
|
||||
|
||||
/**
|
||||
* The type of offset field
|
||||
*
|
||||
* @see OffsetFieldLocation
|
||||
*/
|
||||
public enum OffsetFieldType {
|
||||
FILE,
|
||||
FUNCTION,
|
||||
IMAGEBASE,
|
||||
MEMORYBLOCK
|
||||
}
|
||||
Reference in New Issue
Block a user