Class DataStringUtil

java.lang.Object
com.pnfsoftware.jeb.core.units.code.asm.items.DataStringUtil

public class DataStringUtil extends Object
Utility methods to facilitate the creation of string items by the INativeDataAnalyzer.
  • Field Details

  • Constructor Details

    • DataStringUtil

      public DataStringUtil()
  • Method Details

    • isValidStringAt

      public static boolean isValidStringAt(IVirtualMemory mem, long address, int minChars, int maxChars)
      Determine whether the memory bytes at the provided address look like a string.
      Parameters:
      mem - virtual memory
      address - start address
      minChars - minimum number of characters allowed for the string
      maxChars - maximum number of characters allowed for the string
      Returns:
      a string or null
    • getStringAt

      public static String getStringAt(IVirtualMemory mem, long address, int minChars, int maxChars)
      Attempt to create a string from the memory bytes located at the provided address.
      Parameters:
      mem - virtual memory
      address - start address
      minChars - minimum number of characters allowed for the string
      maxChars - maximum number of characters allowed for the string
      Returns:
      a string or null
    • getStringAt

      public static String getStringAt(IVirtualMemory mem, long address, int minChars, int maxChars, StringEncoding[] atype)
      Attempt to create a string from the memory bytes located at the provided address.
      Parameters:
      mem - virtual memory
      address - start address
      minChars - minimum number of characters allowed for the string
      maxChars - maximum number of characters allowed for the string
      atype - optional single-element array to collect the string output type
      Returns:
      a string or null
    • getStringAt

      public static StringEntry getStringAt(IVirtualMemory mem, long address, long addressMax, int minChars, int maxChars)
      Attempt to create a string from the memory bytes located at the provided address.
      Parameters:
      mem - virtual memory
      address - start address
      addressMax - max address (use -1 to specify no-max)
      minChars - minimum number of characters allowed for the string
      maxChars - maximum number of characters allowed for the string
      Returns:
      a string descriptor or null
    • createFromMemory

      public static INativeStringItem createFromMemory(INativeDataAnalyzer dataParser, ILabelManager labelman, IVirtualMemory mem, long address, long addressMax, StringEncoding stringType, int minChars, int maxChars)
      Parse a memory area as a string. If a non-null string item is returned, it must be registered to a memory model or immediately disposed.
      Parameters:
      dataParser -
      labelman - label manager
      mem - virtual memory
      address - mandatory start address
      addressMax - optional maximum (final) address for the string; use -1 for no limit
      stringType - the string type hint; null to let this method determine the best string type heuristically
      minChars - minimum number of characters to be found in the string for it to be considered valid (inclusive); set to -1 for default (currently: 3)
      maxChars - maximum number of characters (not bytes) to be parsed (exclusive); set to -1 for default (currently: 100_000)
      Returns:
      a string item or null
    • determineValue

      public static String determineValue(INativeStringItem item, IVirtualMemory mem, boolean reEncodingValidation)
      Determine the value of a given string data item.
      Parameters:
      item -
      mem -
      reEncodingValidation -
      Returns:
    • determineValue

      public static String determineValue(StringEncoding st, IVirtualMemory mem, long address, int size, boolean reEncodingValidation)
      Determine the value of a string.
      Parameters:
      st - string type
      mem - virtual memory
      address - address to string in memory
      size - string size in bytes, including the terminator if any
      reEncodingValidation -
      Returns:
    • determineValue

      public static String determineValue(StringEncoding st, byte[] buffer, int offset, int size, boolean reEncodingValidation)
      Determine the value of a string.
      Parameters:
      st - string type
      buffer - bytes
      offset - offset to string in buffer
      size - string size in byte, including the null terminator if any
      reEncodingValidation -
      Returns:
    • heurIsValidString

      public static boolean heurIsValidString(String s, int minChars)
    • isSafeAsciiStringAt

      public static boolean isSafeAsciiStringAt(IVirtualMemory mem, long address, int minChars, int maxChars)
    • isSafeAsciiStringAt

      public static boolean isSafeAsciiStringAt(IVirtualMemory mem, long address, StringEncoding st, int minChars, int maxChars)
      Indicate if a data in memory is a safe ASCII (meaning containing only printable character in the ASCII range). Does not consider extended ASCII. Note that String Type can be different from StringEncoding.ASCII_ZERO: it will still check the ASCII range.
      Parameters:
      mem - virtual memory
      address - String address
      st - String type
      minChars - minimum number of characters expected
      maxChars - maximum number of characters to be parsed (withouh the final zero if any)
      Returns: