Class ListingDiff

java.lang.Object
ghidra.program.util.ListingDiff

public class ListingDiff extends Object
Determines where instructions couldn't be matched and where they differ between sets of addresses as provided by a ListingAddressCorrelation. Initially this will be byte differences and instruction operand differences for any instructions that were determined to be matched.
Important: This class is not intended to be used for an entire program. Instead it is for comparing smaller portions such as functions. If the correlation handed to this class associates two large address sets, then the address sets, such as byte differences, that are created by this class could potentially consume large amounts of memory.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a ListingDiff to determine where instructions couldn't be matched and where they differ between sets of addresses as provided by a ListingAddressCorrelation.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds the indicated listener to those that get notified when the ListingDiff's set of differences and unmatched addresses changes.
    boolean
    Determines if the entire set of operands should indicate that it differs.
    Gets the addresses in the first listing where byte differences were found based on the current difference settings.
    Gets the addresses in the first listing where code unit (mnemonic and/or operand) differences were found based on the current difference settings.
    Gets the addresses in the first listing where differences were found based on the current difference settings.
    getMatchingAddress(Address address, boolean isListing1)
    Gets the matching address from the other listing for the specified address from one of the two listings whose differences this class determines.
    Gets the matching code unit from the other side listing given a code unit from a given side of the two listings whose differences this class determines.
    int[]
    getOperandsThatDiffer(CodeUnit codeUnit1, CodeUnit codeUnit2)
    Gets an array containing the operand indices where the two indicated code units differ.
    Gets the address set for unmatched code for the given side second listing.
    boolean
    Determines if this ListingDiff currently has an address correlation to use.
    boolean
    Gets the setting indicating if byte differences are currently being ignored.
    boolean
    Gets the setting indicating if values of operand constants that differ are currently being ignored when determining code unit differences.
    boolean
    Gets the setting indicating if operand registers that differ other than in size are currently being ignored when determining code unit differences.
    void
    Outputs an information message, primarily for debugging, that indicates where code was unmatched with the other listing and where various differences, such as bytes and code units, were found.
    void
    Removes the indicated listener from those that get notified when the ListingDiff's set of differences and unmatched addresses changes.
    void
    Sets the address correlation that is used to determine matching addresses between the two listings.
    void
    setIgnoreByteDiffs(boolean ignore)
    Changes the setting indicating whether or not byte differences should be ignored.
    void
    setIgnoreConstants(boolean ignore)
    Changes the setting indicating if values of operand constants that differ should be ignored when determining code unit differences.
    void
    setIgnoreRegisters(boolean ignore)
    Changes the setting indicating if operand registers that differ other than in size should be ignored when determining code unit differences.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ListingDiff

      public ListingDiff()
      Creates a ListingDiff to determine where instructions couldn't be matched and where they differ between sets of addresses as provided by a ListingAddressCorrelation.
  • Method Details

    • setCorrelation

      public void setCorrelation(ListingAddressCorrelation correlation) throws MemoryAccessException
      Sets the address correlation that is used to determine matching addresses between the two listings. Differences can then be determined where a matching address is found.
      Important: This class is not intended to be used for an entire program. Instead it is for comparing smaller portions such as functions. If the correlation handed to this class associates two large address sets, then the address sets, such as byte differences, that are created by this class could potentially consume large amounts of memory.
      Parameters:
      correlation - the address correlation. Otherwise, null to clear the correlation.
      Throws:
      MemoryAccessException - if memory can't be read.
    • hasCorrelation

      public boolean hasCorrelation()
      Determines if this ListingDiff currently has an address correlation to use.
      Returns:
      true if it has an address correlation currently.
    • getOperandsThatDiffer

      public int[] getOperandsThatDiffer(CodeUnit codeUnit1, CodeUnit codeUnit2)
      Gets an array containing the operand indices where the two indicated code units differ. These differences are determined based on whether constants and registers are being ignored.
      Parameters:
      codeUnit1 - the first code unit
      codeUnit2 - the second code unit
      Returns:
      an array of operand indices where the operands differ between the two code units based on the current settings that indicate what differences can be ignored.
    • doesEntireOperandSetDiffer

      public boolean doesEntireOperandSetDiffer(CodeUnit codeUnit1, CodeUnit codeUnit2)
      Determines if the entire set of operands should indicate that it differs. If the code units aren't the same type then the entire set of operands is considered different. Also if the number of operands differs then as far as we're concerned the entire set differs.
      Parameters:
      codeUnit1 - the first code unit
      codeUnit2 - the second code unit
      Returns:
      true if we should indicate that all operands differ.
    • getUnmatchedCode

      public AddressSetView getUnmatchedCode(Duo.Side side)
      Gets the address set for unmatched code for the given side second listing.
      Parameters:
      side - the LEFT or RIGHT side
      Returns:
      the addresses of the unmatched code in the first listing.
    • getDiffs

      public AddressSetView getDiffs(Duo.Side side)
      Gets the addresses in the first listing where differences were found based on the current difference settings.
      Parameters:
      side - the side (LEFT or RIGHT) to get the listing diffs for
      Returns:
      the addresses with differences in the first listing.
    • getCodeUnitDiffs

      public AddressSetView getCodeUnitDiffs(Duo.Side side)
      Gets the addresses in the first listing where code unit (mnemonic and/or operand) differences were found based on the current difference settings.
      Parameters:
      side - the side (LEFT or RIGHT) to get the code unit diffs for
      Returns:
      the addresses with code unit differences in the first listing.
    • getByteDiffs

      public AddressSetView getByteDiffs(Duo.Side side)
      Gets the addresses in the first listing where byte differences were found based on the current difference settings.
      Parameters:
      side - the side (LEFT or RIGHT) to get the byte diffs for
      Returns:
      the addresses with byte differences in the first listing.
    • getMatchingAddress

      public Address getMatchingAddress(Address address, boolean isListing1)
      Gets the matching address from the other listing for the specified address from one of the two listings whose differences this class determines.
      Parameters:
      address - the address whose matching address this determines.
      isListing1 - true indicates the address is from the first listing. false indicates it is from the second listing.
      Returns:
      the matching address or null
    • printFunctionComparisonDiffs

      public void printFunctionComparisonDiffs()
      Outputs an information message, primarily for debugging, that indicates where code was unmatched with the other listing and where various differences, such as bytes and code units, were found.
    • isIgnoringByteDiffs

      public boolean isIgnoringByteDiffs()
      Gets the setting indicating if byte differences are currently being ignored.
      Returns:
      true if byte differences are being ignored.
    • setIgnoreByteDiffs

      public void setIgnoreByteDiffs(boolean ignore)
      Changes the setting indicating whether or not byte differences should be ignored.
      Parameters:
      ignore - true indicates to ignore byte differences
    • isIgnoringConstants

      public boolean isIgnoringConstants()
      Gets the setting indicating if values of operand constants that differ are currently being ignored when determining code unit differences.
      Returns:
      true if code unit differences are ignoring differences in values of operand constants.
    • setIgnoreConstants

      public void setIgnoreConstants(boolean ignore)
      Changes the setting indicating if values of operand constants that differ should be ignored when determining code unit differences.
      Parameters:
      ignore - true means code unit differences should ignore differences in values of operand constants.
    • isIgnoringRegisters

      public boolean isIgnoringRegisters()
      Gets the setting indicating if operand registers that differ other than in size are currently being ignored when determining code unit differences.
      Returns:
      true if code unit differences are ignoring operand register differences other than in size.
    • setIgnoreRegisters

      public void setIgnoreRegisters(boolean ignore)
      Changes the setting indicating if operand registers that differ other than in size should be ignored when determining code unit differences.
      Parameters:
      ignore - true means code unit differences should ignore operand register differences other than in size.
    • addListingDiffChangeListener

      public void addListingDiffChangeListener(ListingDiffChangeListener listener)
      Adds the indicated listener to those that get notified when the ListingDiff's set of differences and unmatched addresses changes.
      Parameters:
      listener - the listener to be notified
    • removeListingDiffChangeListener

      public void removeListingDiffChangeListener(ListingDiffChangeListener listener)
      Removes the indicated listener from those that get notified when the ListingDiff's set of differences and unmatched addresses changes.
      Parameters:
      listener - the listener to be removed
    • getMatchingCodeUnit

      public CodeUnit getMatchingCodeUnit(CodeUnit codeUnit, Duo.Side side)
      Gets the matching code unit from the other side listing given a code unit from a given side of the two listings whose differences this class determines.
      Parameters:
      codeUnit - the code unit whose match this determines.
      side - the side the code unit came from
      Returns:
      the matching code unit or null