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 Details

    • DiffUtility

      public DiffUtility()
  • Method Details

    • 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
    • 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 convert
      otherProgram - 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

      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.
    • getReference

      public static Reference getReference(AddressTranslator p2ToP1Translator, Reference p2Ref)
      Translate reference from program p2 to target program p1
      Parameters:
      p2ToP1Translator - program address translater
      p2Ref - 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 extLoc
      extLoc - existing external location to be copied
      otherProgram - target program
      Returns:
      new external location
      Throws:
      InvalidInputException - if libraryName is invalid or null, or an invalid extlabel is specified. Names with spaces or the empty string are not permitted. Neither extLabel nor extAddr was specified properly.
      DuplicateNameException - if another non-Library namespace has the same name
    • 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 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 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 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 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 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.
    • getCompatibleProgramLocation

      public static ProgramLocation getCompatibleProgramLocation(Program program, ProgramLocation location, Program otherProgram)