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
createItemNameFromString
(String str, int maxLength) Generate a default name for a String, starting with default prefixNAME_PREFIX
, and replacing non identifier characters by '_'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 String
getValidStringAt
(INativeCodeModel<?> model, IVirtualMemory mem, long address, int minChars, int maxChars) Determine whether the memory bytes at the provided address look like a string and return its value.static boolean
heurIsValidString
(String s, int minChars) static boolean
isSafeAsciiCharArrayAt
(IVirtualMemory mem, long address, int size) Indicate if there is an ascii char array at a given address.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
isValidCharAt
(IVirtualMemory mem, long address, long endAddress, StringEncoding st) Determine of char at a given address is valid.static boolean
isValidStringAt
(INativeCodeModel<?> model, 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
public static boolean isValidStringAt(INativeCodeModel<?> model, IVirtualMemory mem, long address, int minChars, int maxChars) Determine whether the memory bytes at the provided address look like a string. Check named overlapping items.- Parameters:
model
-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
-
getValidStringAt
public static String getValidStringAt(INativeCodeModel<?> model, IVirtualMemory mem, long address, int minChars, int maxChars) Determine whether the memory bytes at the provided address look like a string and return its value. Check named overlapping items.- Parameters:
model
- native model to validate there is no overlap. If null, validation won't be performed.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
-
createItemNameFromString
Generate a default name for a String, starting with default prefixNAME_PREFIX
, and replacing non identifier characters by '_'- Parameters:
str
- stringmaxLength
- max length of generated name. UseNAME_DEFAULT_LENGTH
if unknown.- Returns:
- a legal item name
-
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:
-
isSafeAsciiCharArrayAt
Indicate if there is an ascii char array at a given address. Some extra characters are allowed, implementation is based onCharacters.isAsciiCharOrCommonFormat(int)
- Parameters:
mem
- virtual memoryaddress
- char array addresssize
- array size- Returns:
- true if there is a valid only-ascii char array
-
isValidCharAt
public static boolean isValidCharAt(IVirtualMemory mem, long address, long endAddress, StringEncoding st) Determine of char at a given address is valid. Does not build the full String sequences.- Parameters:
mem
- virtual memoryaddress
- Char addressendAddress
- end addressst
- String type. Must not be null.- Returns:
- true if there is a valid character regarding its encoding.
-