Package ghidra.program.util
Class DiffUtility
java.lang.Object
ghidra.program.util.SimpleDiffUtility
ghidra.program.util.DiffUtility
The
DiffUtility
class provides static methods for getting and
creating an object in one program based on an object from another program.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
Compare any two addresses from two different programs.static ExternalLocation
createExtLocation
(Program program, ExternalLocation extLoc, Program otherProgram) Create equivalent external location in otherProgram.static Namespace
createNamespace
(Program program, Namespace namespace, Program otherProgram) Given a namespace, create the corresponding namespace in the specified otherProgram.static Reference
createReference
(Program program, Reference ref, Program otherProgram) Given a reference for a specified program, create a comparable reference in the specified otherProgram if possible.static Variable
createVariable
(Program program, Variable var, Program otherProgram) Given a variable for a specified program, create a comparable variable in the specified otherProgram if possible.static AddressSet
getCodeUnitSet
(AddressSetView addrSet, Program program) Creates an address set that contains the entire code units within the program's listing that are part of the address set that is passed in.static AddressSet
getCompatibleAddressSet
(AddressRange range, Program otherProgram, boolean exactMatchOnly) Convert an address range from one program to a compatible address set in the specified otherProgram.static AddressSet
getCompatibleAddressSet
(AddressSetView set, Program otherProgram) Convert an address-set from one program to a compatible address-set in the specified otherProgram.static Address
getCompatibleMemoryAddress
(Address memoryAddress, Program otherProgram) Determines the memory address in the other program that is compatible with the specified address.static ProgramLocation
getCompatibleProgramLocation
(Program program, ProgramLocation location, Program otherProgram) static Function
getFunction
(Function function, Program otherProgram) Given a function, get the corresponding function from the specified otherProgram.static Namespace
getNamespace
(Namespace namespace, Program otherProgram) Given a namespace, get the corresponding namespace from the specified otherProgram.static Reference
getReference
(Program program, Reference ref, Program otherProgram) Given a reference for a specified program, get the corresponding reference from the specified otherProgram.static Reference
getReference
(AddressTranslator p2ToP1Translator, Reference p2Ref) Translate reference from program p2 to target program p1static String
getUserToAddressString
(Program program, Address address) Returns a string representation of the specified address.static String
getUserToAddressString
(Program program, Reference ref) Returns the string representation of the specified reference's "to" address.static String
getUserToSymbolString
(Program program, Reference ref) Returns the string representation of the specified reference's "to" symbol.static Variable
getVariable
(Program program, Variable var, Program otherProgram) Given a variable for a specified program, get the corresponding variable from the specified otherProgram.static Variable
getVariable
(Variable var, Function otherFunction) Given a variable, get the corresponding variable from the specified otherFunction.static String
toSignedHexString
(int value) Returns the signed hex string representing the int value.static String
toSignedHexString
(long value) Returns the signed hex string representing the long value.static boolean
variableStorageMatches
(Variable var1, Variable var2) Determine if the specified variables have exactly the same storage.static boolean
variableStorageOverlaps
(Variable var1, Variable var2) Determine if the specified variables have overlapping storage.Methods inherited from class ghidra.program.util.SimpleDiffUtility
expandAddressSetToIncludeFullDelaySlots, getCompatibleAddress, getCompatibleAddressSpace, getCompatibleVariableStorage, getCompatibleVarnode, getEndOfDelaySlots, getMatchingExternalLocation, getMatchingExternalSymbol, getOverlappingVariable, getStartOfDelaySlots, getSymbol, getVariableSymbol, getVariableSymbol, getVariableSymbol, translateMemoryAddress
-
Constructor Details
-
DiffUtility
public DiffUtility()
-
-
Method Details
-
getCompatibleMemoryAddress
Determines the memory address in the other program that is compatible with the specified address.- Parameters:
memoryAddress
- the memory address to be convertedotherProgram
- target program which corresponds to the returned address.- Returns:
- the memory address derived from the other program or null if one cannot be determined.
-
getCompatibleAddressSet
Convert an address-set from one program to a compatible address-set in the specified otherProgram. Those regions which can not be mapped will be eliminated from the new address-set. Only memory addresses will be considered.- Parameters:
set
- address-set corresponding to programotherProgram
- target program which corresponds to the returned address set.- Returns:
- translated address-set
-
getCompatibleAddressSet
public static AddressSet getCompatibleAddressSet(AddressRange range, Program otherProgram, boolean exactMatchOnly) Convert an address range from one program to a compatible address set in the specified otherProgram. Only memory addresses will be considered. If none of the range can be converted then null is returned.- Parameters:
range
- address range to convertotherProgram
- target program which corresponds to the returned address range.exactMatchOnly
- if true and a one-to-one address mapping cannot be identified null will be returned, otherwise a partial set may be returned or null if no valid translation was found.- Returns:
- compatible address set or null
-
compare
Compare any two addresses from two different programs.- Parameters:
program1
-addr1
-program2
-addr2
-- Returns:
-
getNamespace
Given a namespace, get the corresponding namespace from the specified otherProgram. The return namespace body may be different.- Parameters:
namespace
- namespace to look forotherProgram
- other program- Returns:
- corresponding namespace for otherProgram or null if no such namespace exists.
-
createNamespace
public static Namespace createNamespace(Program program, Namespace namespace, Program otherProgram) throws InvalidInputException, DuplicateNameException Given a namespace, create the corresponding namespace in the specified otherProgram. If a corresponding namespace already exists, it is returned. The return namespace body may be different.- Parameters:
program
- program which contains the specified namespace instancenamespace
- namespace to look forotherProgram
- other program- Returns:
- corresponding namespace for otherProgram or null if no such namespace exists.
- Throws:
InvalidInputException
- if the namespace's name or path is not valid.DuplicateNameException
- if the namespace's name or path cannot be created due to a conflict with another namespace or symbol.
-
variableStorageOverlaps
Determine if the specified variables have overlapping storage. Variable storage check includes dynamically mapped storage for parameters. This method should not be used with caution if both arguments are parameters which use dynamically mapped storage.- Parameters:
var1
-var2
-- Returns:
- true if variables overlap, else false
-
variableStorageMatches
Determine if the specified variables have exactly the same storage. This method should not be used with caution if both arguments are parameters which use dynamically mapped storage.- Parameters:
var1
-var2
-- Returns:
- true if variables have matching storage, else false
-
getFunction
Given a function, get the corresponding function from the specified otherProgram. Function matchup is done based upon function entry point only. The function bodies may be different.- Parameters:
function
- function to look forotherProgram
- other program- Returns:
- corresponding function for otherProgram or null if no such function exists.
-
getReference
Given a reference for a specified program, get the corresponding reference from the specified otherProgram. A Non-memory reference is considered a suitable reference for returning if its destination address is from the same address space (i.e., stack, register, etc.)- Parameters:
program
- program which contains the specified reference instanceref
- reference to look forotherProgram
- other program- Returns:
- corresponding reference for otherProgram or null if no such reference exists.
-
getReference
Translate reference from program p2 to target program p1- Parameters:
p2ToP1Translator
- program address translaterp2Ref
- original reference to be copied- Returns:
- translated reference or null
-
createExtLocation
public static ExternalLocation createExtLocation(Program program, ExternalLocation extLoc, Program otherProgram) throws InvalidInputException, DuplicateNameException Create equivalent external location in otherProgram.- Parameters:
program
- program containing extLocextLoc
- existing external location to be copiedotherProgram
- target program- Returns:
- new external location
- Throws:
InvalidInputException
- iflibraryName
is invalid or null, or an invalidextlabel
is specified. Names with spaces or the empty string are not permitted. NeitherextLabel
norextAddr
was specified properly.DuplicateNameException
- if another non-Library namespace has the same name
-
createReference
Given a reference for a specified program, create a comparable reference in the specified otherProgram if possible. An open transaction on otherProgram must exist.- Parameters:
program
- program which contains the specified reference instanceref
- reference to be addedotherProgram
- other program- Returns:
- new reference for otherProgram or null if unable to create reference.
-
getVariable
Given a variable for a specified program, get the corresponding variable from the specified otherProgram.- Parameters:
program
- program which contains the specified variable instancevar
- variable to look forotherProgram
- other program- Returns:
- corresponding variable for otherProgram or null if no such variable exists.
-
getVariable
Given a variable, get the corresponding variable from the specified otherFunction.- Parameters:
var
- variable to look forotherFunction
- other function- Returns:
- corresponding variable for otherFunction or null if no such variable exists.
-
createVariable
public static Variable createVariable(Program program, Variable var, Program otherProgram) throws DuplicateNameException, InvalidInputException Given a variable for a specified program, create a comparable variable in the specified otherProgram if possible. An open transaction on otherProgram must exist.- Parameters:
program
- program which contains the specified variable instancevar
- variable to be added from program to otherProgram.otherProgram
- other program- Returns:
- new variable for otherProgram or null if unable to create variable.
- Throws:
DuplicateNameException
- if another variable already exists with the same name as var in the resulting function.InvalidInputException
- if data type is not a fixed length or variable name is invalid, etc.VariableSizeException
- if data type size is too large based upon storage constraints.
-
getCodeUnitSet
Creates an address set that contains the entire code units within the program's listing that are part of the address set that is passed in.
Note: This method will not remove any addresses from the address set even if they are not part of code units in the program's listing.- Parameters:
addrSet
- The original address set that may contain portions of code units.program
- the program which has the code units.- Returns:
- the address set that contains addresses for whole code units.
-
toSignedHexString
Returns the signed hex string representing the int value. Positive values are represented beginning with 0x. (i.e. value of 12 would be 0xc) Negative values are represented beginning with -0x. (i.e. value of -12 would be -0xc)- Parameters:
value
- the value- Returns:
- the signed hex string
-
toSignedHexString
Returns the signed hex string representing the long value. Positive values are represented beginning with 0x. (i.e. value of 12 would be 0xc) Negative values are represented beginning with -0x. (i.e. value of -12 would be -0xc)- Parameters:
value
- the value- Returns:
- the signed hex string
-
getUserToAddressString
Returns the string representation of the specified reference's "to" address.- Parameters:
program
- the program containing the referenceref
- the reference- Returns:
- the "to" address for the reference as a meaningful address for the user.
-
getUserToAddressString
Returns a string representation of the specified address.- Parameters:
program
- the program containing the addressaddress
- the address- Returns:
- the address as a meaningful string for the user.
-
getUserToSymbolString
Returns the string representation of the specified reference's "to" symbol.- Parameters:
program
- the program containing the referenceref
- the reference- Returns:
- the "to" symbol for the reference as a meaningful string for the user. The empty string, "", is returned if the reference isn't to a symbol.
-
getCompatibleProgramLocation
public static ProgramLocation getCompatibleProgramLocation(Program program, ProgramLocation location, Program otherProgram)
-