fixed issue 54

This commit is contained in:
elias.bachaalany 2010-08-02 14:13:48 +00:00
parent 686e018bdc
commit 15a72289f7

View File

@ -385,47 +385,74 @@ class Strings(object):
class StringItem(object): class StringItem(object):
""" """
Class representing each string item. Class representing each string item.
The attributes are:
ea - string ea
type - string type (ASCSTR_xxxxx)
str() - returns the actual string
""" """
def __init__(self, si): def __init__(self, si):
self.ea = si.ea self.ea = si.ea
"""String ea"""
self.type = si.type self.type = si.type
"""string type (ASCSTR_xxxxx)"""
self.length = si.length self.length = si.length
"""string length"""
def __str__(self): def __str__(self):
return idc.GetString(self.ea, self.length, self.type) return idc.GetString(self.ea, self.length, self.type)
STR_C = 0x0001 # C-style ASCII string STR_C = 0x0001
STR_PASCAL = 0x0002 # Pascal-style ASCII string (length byte) """C-style ASCII string"""
STR_LEN2 = 0x0004 # Pascal-style, length is 2 bytes STR_PASCAL = 0x0002
STR_UNICODE = 0x0008 # Unicode string """Pascal-style ASCII string (length byte)"""
STR_LEN4 = 0x0010 # Pascal-style, length is 4 bytes STR_LEN2 = 0x0004
STR_ULEN2 = 0x0020 # Pascal-style Unicode, length is 2 bytes """Pascal-style, length is 2 bytes"""
STR_ULEN4 = 0x0040 # Pascal-style Unicode, length is 4 bytes STR_UNICODE = 0x0008
"""Unicode string"""
STR_LEN4 = 0x0010
"""Pascal-style, length is 4 bytes"""
STR_ULEN2 = 0x0020
"""Pascal-style Unicode, length is 2 bytes"""
STR_ULEN4 = 0x0040
"""Pascal-style Unicode, length is 4 bytes"""
def clear_cache(self): def clear_cache(self):
"""Clears the strings list cache""" """Clears the strings list cache"""
self.refresh(0, 0) # when ea1=ea2 the kernel will clear the cache self.refresh(0, 0) # when ea1=ea2 the kernel will clear the cache
def __init__(self, default_setup=True): def __init__(self, default_setup = True):
"""
Initializes the Strings enumeration helper class
@param default_setup: Set to True to use default setup (C strings, min len 5, ...)
"""
self.size = 0
if default_setup: if default_setup:
self.setup() self.setup()
self._si = idaapi.string_info_t() self._si = idaapi.string_info_t()
self.size = 0
def refresh(self, ea1=None, ea2=None): def refresh(self, ea1=None, ea2=None):
"""Refreshes the strings list""" """Refreshes the strings list"""
if not ea1: ea1 = idaapi.cvar.inf.minEA if ea1 is None:
if not ea2: ea2 = idaapi.cvar.inf.maxEA ea1 = idaapi.cvar.inf.minEA
if ea2 is None:
ea2 = idaapi.cvar.inf.maxEA
idaapi.refresh_strlist(ea1, ea2) idaapi.refresh_strlist(ea1, ea2)
self.size = idaapi.get_strlist_qty() self.size = idaapi.get_strlist_qty()
def setup(self, strtypes=STR_C, minlen=5, only_7bit=True, ignore_instructions=False, def setup(self,
ea1=None, ea2=None, display_only_existing_strings=False): strtypes = STR_C,
if not ea1: ea1 = idaapi.cvar.inf.minEA minlen = 5,
if not ea2: ea2 = idaapi.cvar.inf.maxEA only_7bit = True,
ignore_instructions = False,
ea1 = None,
ea2 = None,
display_only_existing_strings = False):
if ea1 is None:
ea1 = idaapi.cvar.inf.minEA
if ea2 is None:
ea2 = idaapi.cvar.inf.maxEA
t = idaapi.strwinsetup_t() t = idaapi.strwinsetup_t()
t.strtypes = strtypes t.strtypes = strtypes
t.minlen = minlen t.minlen = minlen
@ -434,15 +461,18 @@ class Strings(object):
t.ea2 = ea2 t.ea2 = ea2
t.display_only_existing_strings = display_only_existing_strings t.display_only_existing_strings = display_only_existing_strings
idaapi.set_strlist_options(t) idaapi.set_strlist_options(t)
# automatically refreshes
# Automatically refreshes
self.refresh() self.refresh()
def __getitem__(self, index): def __getitem__(self, index):
"""Returns string items""" """Returns a string item or None"""
if index >= self.size: if index >= self.size:
raise StopIteration raise StopIteration
if idaapi.get_strlist_item(index, self._si): if idaapi.get_strlist_item(index, self._si):
return Strings.StringItem(self._si) return Strings.StringItem(self._si)
return None return None
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------