Class DiffUtility


  • public class DiffUtility
    extends SimpleDiffUtility
    The DiffUtility class provides static methods for getting and creating an object in one program based on an object from another program.
    • Constructor Detail

      • DiffUtility

        public DiffUtility()
    • Method Detail

      • getCompatibleMemoryAddress

        public static Address getCompatibleMemoryAddress​(Address memoryAddress,
                                                         Program otherProgram)
        Determines the memory address in the other program that is compatible with the specified address.
        Parameters:
        memoryAddress - the memory address to be converted
        otherProgram - 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

        public static AddressSet getCompatibleAddressSet​(AddressSetView set,
                                                         Program otherProgram)
        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 program
        otherProgram - target program which corresponds to the returned address set.
        Returns:
        translated address-set
      • getNonCompatibleAddressSet

        public static AddressSet getNonCompatibleAddressSet​(AddressSetView set,
                                                            Program otherProgram)
        Reduce an address-set from one program to the set of addresses that are incompatible with the specified otherProgram.
        Parameters:
        set - address-set corresponding to one program
        otherProgram - the addresses are incompatible with this other program.
        Returns:
        incompatible address-set
      • getCompatibleAddressRange

        public static AddressRange getCompatibleAddressRange​(AddressRange range,
                                                             Program otherProgram)
        Convert an address range from one program to a compatible address range in the specified otherProgram. Only memory addresses will be considered. If the entire range cannot be converted then null is returned.
        Parameters:
        range - address range to convert
        otherProgram - target program which corresponds to the returned address range.
        Returns:
        translated address range or null if a compatible range could not be determined in the other program.
      • compare

        public static int compare​(Program program1,
                                  Address addr1,
                                  Program program2,
                                  Address addr2)
        Compare any two addresses from two different programs.
        Parameters:
        program1 -
        addr1 -
        program2 -
        addr2 -
        Returns:
      • getNamespace

        public static Namespace getNamespace​(Namespace namespace,
                                             Program otherProgram)
        Given a namespace, get the corresponding namespace from the specified otherProgram. The return namespace body may be different.
        Parameters:
        namespace - namespace to look for
        otherProgram - 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 instance
        namespace - namespace to look for
        otherProgram - 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

        public static boolean variableStorageOverlaps​(Variable var1,
                                                      Variable var2)
        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

        public static boolean variableStorageMatches​(Variable var1,
                                                     Variable var2)
        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

        public static Function getFunction​(Function function,
                                           Program otherProgram)
        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 for
        otherProgram - other program
        Returns:
        corresponding function for otherProgram or null if no such function exists.
      • getReference

        public static Reference getReference​(Program program,
                                             Reference ref,
                                             Program otherProgram)
        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 instance
        ref - reference to look for
        otherProgram - other program
        Returns:
        corresponding reference for otherProgram or null if no such reference exists.
      • createReference

        public 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. An open transaction on otherProgram must exist.
        Parameters:
        program - program which contains the specified reference instance
        ref - reference to be added
        otherProgram - other program
        Returns:
        new reference for otherProgram or null if unable to create reference.
      • getVariable

        public static Variable getVariable​(Program program,
                                           Variable var,
                                           Program otherProgram)
        Given a variable for a specified program, get the corresponding variable from the specified otherProgram.
        Parameters:
        program - program which contains the specified variable instance
        var - variable to look for
        otherProgram - other program
        Returns:
        corresponding variable for otherProgram or null if no such variable exists.
      • getVariable

        public static Variable getVariable​(Variable var,
                                           Function otherFunction)
        Given a variable, get the corresponding variable from the specified otherFunction.
        Parameters:
        var - variable to look for
        otherFunction - 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 instance
        var - 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

        public 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.
        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

        public static java.lang.String toSignedHexString​(int value)
        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

        public static java.lang.String toSignedHexString​(long value)
        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

        public static java.lang.String getUserToAddressString​(Program program,
                                                              Reference ref)
        Returns the string representation of the specified reference's "to" address.
        Parameters:
        program - the program containing the reference
        ref - the reference
        Returns:
        the "to" address for the reference as a meaningful address for the user.
      • getUserToAddressString

        public static java.lang.String getUserToAddressString​(Program program,
                                                              Address address)
        Returns a string representation of the specified address.
        Parameters:
        program - the program containing the address
        address - the address
        Returns:
        the address as a meaningful string for the user.
      • getUserToSymbolString

        public static java.lang.String getUserToSymbolString​(Program program,
                                                             Reference ref)
        Returns the string representation of the specified reference's "to" symbol.
        Parameters:
        program - the program containing the reference
        ref - 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.