Class DataStringUtil
java.lang.Object
com.pnfsoftware.jeb.core.units.code.asm.items.DataStringUtil
Utility methods to facilitate the creation of string items by the
INativeDataAnalyzer
.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.static String
determineValue
(INativeStringItem item, IVirtualMemory mem, boolean reEncodingValidation) Determine the value of a given string data item.static String
determineValue
(StringEncoding st, byte[] buffer, int offset, int size, boolean reEncodingValidation) Determine the value of a string.static String
determineValue
(StringEncoding st, IVirtualMemory mem, long address, int size, boolean reEncodingValidation) Determine the value of a string.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.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.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.static boolean
heurIsValidString
(String s, int minChars) static boolean
isSafeAsciiStringAt
(IVirtualMemory mem, long address, int minChars, int maxChars) 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).static boolean
isValidStringAt
(IVirtualMemory mem, long address, int minChars, int maxChars) Determine whether the memory bytes at the provided address look like a string.
-
Field Details
-
maxStringItemNameLength
public static final int maxStringItemNameLength- See Also:
-
NAME_PREFIX
- See Also:
-
NAME_DEFAULT_LENGTH
public static final int NAME_DEFAULT_LENGTH- See Also:
-
-
Constructor Details
-
DataStringUtil
public DataStringUtil()
-
-
Method Details
-
isValidStringAt
Determine whether the memory bytes at the provided address look like a string.- Parameters:
mem
- virtual memoryaddress
- start addressminChars
- minimum number of characters allowed for the stringmaxChars
- maximum number of characters allowed for the string- Returns:
- a string or null
-
getStringAt
Attempt to create a string from the memory bytes located at the provided address.- Parameters:
mem
- virtual memoryaddress
- start addressminChars
- minimum number of characters allowed for the stringmaxChars
- 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 memoryaddress
- start addressminChars
- minimum number of characters allowed for the stringmaxChars
- maximum number of characters allowed for the stringatype
- 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 memoryaddress
- start addressaddressMax
- max address (use -1 to specify no-max)minChars
- minimum number of characters allowed for the stringmaxChars
- 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 managermem
- virtual memoryaddress
- mandatory start addressaddressMax
- optional maximum (final) address for the string; use -1 for no limitstringType
- the string type hint; null to let this method determine the best string type heuristicallyminChars
- 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 typemem
- virtual memoryaddress
- address to string in memorysize
- string size in bytes, including the terminator if anyreEncodingValidation
-- 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 typebuffer
- bytesoffset
- offset to string in buffersize
- string size in byte, including the null terminator if anyreEncodingValidation
-- Returns:
-
heurIsValidString
-
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 fromStringEncoding.ASCII_ZERO
: it will still check the ASCII range.- Parameters:
mem
- virtual memoryaddress
- String addressst
- String typeminChars
- minimum number of characters expectedmaxChars
- maximum number of characters to be parsed (withouh the final zero if any)- Returns:
-