mirror of
https://github.com/idapython/src
synced 2026-06-08 14:47:00 +00:00
IDA Pro 6.7 support
This commit is contained in:
+34
-15
@@ -374,8 +374,8 @@ def DecodePreviousInstruction(ea):
|
||||
@param ea: address to decode
|
||||
@return: None or a new insn_t instance
|
||||
"""
|
||||
inslen = idaapi.decode_prev_insn(ea)
|
||||
if inslen == 0:
|
||||
prev_addr = idaapi.decode_prev_insn(ea)
|
||||
if prev_addr == idaapi.BADADDR:
|
||||
return None
|
||||
|
||||
return idaapi.cmd.copy()
|
||||
@@ -462,7 +462,8 @@ def GetInputFileMD5():
|
||||
|
||||
class Strings(object):
|
||||
"""
|
||||
Returns the string list.
|
||||
Allows iterating over the string list. The set of strings will not be modified.
|
||||
, unless asked explicitly at setup()-time..
|
||||
|
||||
Example:
|
||||
s = Strings()
|
||||
@@ -483,8 +484,34 @@ class Strings(object):
|
||||
self.length = si.length
|
||||
"""string length"""
|
||||
|
||||
def is_1_byte_encoding(self):
|
||||
return not self.is_2_bytes_encoding() and not self.is_4_bytes_encoding()
|
||||
|
||||
def is_2_bytes_encoding(self):
|
||||
return (self.type & 7) in [idaapi.ASCSTR_UTF16, idaapi.ASCSTR_ULEN2, idaapi.ASCSTR_ULEN4]
|
||||
|
||||
def is_4_bytes_encoding(self):
|
||||
return (self.type & 7) == idaapi.ASCSTR_UTF32
|
||||
|
||||
def _toseq(self, as_unicode):
|
||||
if self.is_2_bytes_encoding():
|
||||
conv = idaapi.ACFOPT_UTF16
|
||||
pyenc = "utf-16"
|
||||
elif self.is_4_bytes_encoding():
|
||||
conv = idaapi.ACFOPT_UTF8
|
||||
pyenc = "utf-8"
|
||||
else:
|
||||
conv = idaapi.ACFOPT_ASCII
|
||||
pyenc = 'ascii'
|
||||
strbytes = idaapi.get_ascii_contents2(self.ea, self.length, self.type, conv)
|
||||
return unicode(strbytes, pyenc, 'replace') if as_unicode else strbytes
|
||||
|
||||
def __str__(self):
|
||||
return idc.GetString(self.ea, self.length, self.type)
|
||||
return self._toseq(False)
|
||||
|
||||
def __unicode__(self):
|
||||
return self._toseq(True)
|
||||
|
||||
|
||||
STR_C = 0x0001
|
||||
"""C-style ASCII string"""
|
||||
@@ -505,8 +532,7 @@ class Strings(object):
|
||||
"""Clears the strings list 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 = False):
|
||||
"""
|
||||
Initializes the Strings enumeration helper class
|
||||
|
||||
@@ -515,10 +541,11 @@ class Strings(object):
|
||||
self.size = 0
|
||||
if default_setup:
|
||||
self.setup()
|
||||
else:
|
||||
self.refresh()
|
||||
|
||||
self._si = idaapi.string_info_t()
|
||||
|
||||
|
||||
def refresh(self, ea1=None, ea2=None):
|
||||
"""Refreshes the strings list"""
|
||||
if ea1 is None:
|
||||
@@ -750,14 +777,6 @@ def ProcessUiActions(actions, flags=0):
|
||||
helper = __process_ui_actions_helper(actions, flags)
|
||||
return False if len(helper) < 1 else idaapi.execute_ui_requests((helper,))
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
def IsBatchMode():
|
||||
"""
|
||||
Checks if batch mode is enabled
|
||||
|
||||
@return: True if batch mode is enabled and False otherwise
|
||||
"""
|
||||
return idaapi.cvar.batch != 0
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
class peutils_t(object):
|
||||
|
||||
+70
-28
@@ -1450,7 +1450,11 @@ def PatchByte(ea, value):
|
||||
@param ea: linear address
|
||||
@param value: new value of the byte
|
||||
|
||||
@return: 1 if successful, 0 if not
|
||||
@return: 1 if the database has been modified,
|
||||
0 if either the debugger is running and the process' memory
|
||||
has value 'value' at address 'ea',
|
||||
or the debugger is not running, and the IDB
|
||||
has value 'value' at address 'ea already.
|
||||
"""
|
||||
return idaapi.patch_byte(ea, value)
|
||||
|
||||
@@ -1462,7 +1466,11 @@ def PatchWord(ea, value):
|
||||
@param ea: linear address
|
||||
@param value: new value of the word
|
||||
|
||||
@return: 1 if successful, 0 if not
|
||||
@return: 1 if the database has been modified,
|
||||
0 if either the debugger is running and the process' memory
|
||||
has value 'value' at address 'ea',
|
||||
or the debugger is not running, and the IDB
|
||||
has value 'value' at address 'ea already.
|
||||
"""
|
||||
return idaapi.patch_word(ea, value)
|
||||
|
||||
@@ -1474,11 +1482,31 @@ def PatchDword(ea, value):
|
||||
@param ea: linear address
|
||||
@param value: new value of the double word
|
||||
|
||||
@return: 1 if successful, 0 if not
|
||||
@return: 1 if the database has been modified,
|
||||
0 if either the debugger is running and the process' memory
|
||||
has value 'value' at address 'ea',
|
||||
or the debugger is not running, and the IDB
|
||||
has value 'value' at address 'ea already.
|
||||
"""
|
||||
return idaapi.patch_long(ea, value)
|
||||
|
||||
|
||||
def PatchQword(ea, value):
|
||||
"""
|
||||
Change value of a quad word
|
||||
|
||||
@param ea: linear address
|
||||
@param value: new value of the quad word
|
||||
|
||||
@return: 1 if the database has been modified,
|
||||
0 if either the debugger is running and the process' memory
|
||||
has value 'value' at address 'ea',
|
||||
or the debugger is not running, and the IDB
|
||||
has value 'value' at address 'ea already.
|
||||
"""
|
||||
return idaapi.patch_qword(ea, value)
|
||||
|
||||
|
||||
def SetFlags(ea, flags):
|
||||
"""
|
||||
Set new value of flags
|
||||
@@ -1880,7 +1908,7 @@ def GetFloat(ea):
|
||||
Get value of a floating point number (4 bytes)
|
||||
This function assumes number stored using IEEE format
|
||||
and in the same endianness as integers.
|
||||
|
||||
|
||||
@param ea: linear address
|
||||
|
||||
@return: float
|
||||
@@ -2253,7 +2281,7 @@ def GetOpnd(ea, n):
|
||||
|
||||
@return: the current text representation of operand or ""
|
||||
"""
|
||||
|
||||
|
||||
if not isCode(idaapi.get_flags_novalue(ea)):
|
||||
return ""
|
||||
|
||||
@@ -2280,21 +2308,21 @@ def GetOpType(ea, n):
|
||||
return -1 if inslen == 0 else idaapi.cmd.Operands[n].type
|
||||
|
||||
|
||||
o_void = idaapi.o_void # No Operand ----------
|
||||
o_reg = idaapi.o_reg # General Register (al,ax,es,ds...) reg
|
||||
o_mem = idaapi.o_mem # Direct Memory Reference (DATA) addr
|
||||
o_phrase = idaapi.o_phrase # Memory Ref [Base Reg + Index Reg] phrase
|
||||
o_displ = idaapi.o_displ # Memory Reg [Base Reg + Index Reg + Displacement] phrase+addr
|
||||
o_imm = idaapi.o_imm # Immediate Value value
|
||||
o_far = idaapi.o_far # Immediate Far Address (CODE) addr
|
||||
o_near = idaapi.o_near # Immediate Near Address (CODE) addr
|
||||
o_idpspec0 = idaapi.o_idpspec0 # IDP specific type
|
||||
o_idpspec1 = idaapi.o_idpspec1 # IDP specific type
|
||||
o_idpspec2 = idaapi.o_idpspec2 # IDP specific type
|
||||
o_idpspec3 = idaapi.o_idpspec3 # IDP specific type
|
||||
o_idpspec4 = idaapi.o_idpspec4 # IDP specific type
|
||||
o_idpspec5 = idaapi.o_idpspec5 # IDP specific type
|
||||
o_last = idaapi.o_last # first unused type
|
||||
o_void = idaapi.o_void # No Operand ----------
|
||||
o_reg = idaapi.o_reg # General Register (al,ax,es,ds...) reg
|
||||
o_mem = idaapi.o_mem # Direct Memory Reference (DATA) addr
|
||||
o_phrase = idaapi.o_phrase # Memory Ref [Base Reg + Index Reg] phrase
|
||||
o_displ = idaapi.o_displ # Memory Reg [Base Reg + Index Reg + Displacement] phrase+addr
|
||||
o_imm = idaapi.o_imm # Immediate Value value
|
||||
o_far = idaapi.o_far # Immediate Far Address (CODE) addr
|
||||
o_near = idaapi.o_near # Immediate Near Address (CODE) addr
|
||||
o_idpspec0 = idaapi.o_idpspec0 # Processor specific type
|
||||
o_idpspec1 = idaapi.o_idpspec1 # Processor specific type
|
||||
o_idpspec2 = idaapi.o_idpspec2 # Processor specific type
|
||||
o_idpspec3 = idaapi.o_idpspec3 # Processor specific type
|
||||
o_idpspec4 = idaapi.o_idpspec4 # Processor specific type
|
||||
o_idpspec5 = idaapi.o_idpspec5 # Processor specific type
|
||||
# There can be more processor specific types
|
||||
|
||||
# x86
|
||||
o_trreg = idaapi.o_idpspec0 # trace register
|
||||
@@ -2308,7 +2336,7 @@ o_xmmreg = idaapi.o_idpspec5 # xmm register
|
||||
o_reglist = idaapi.o_idpspec1 # Register list (for LDM/STM)
|
||||
o_creglist = idaapi.o_idpspec2 # Coprocessor register list (for CDP)
|
||||
o_creg = idaapi.o_idpspec3 # Coprocessor register (for LDC/STC)
|
||||
o_fpreg = idaapi.o_idpspec4 # Floating point register
|
||||
o_fpreg_arm = idaapi.o_idpspec4 # Floating point register
|
||||
o_fpreglist = idaapi.o_idpspec5 # Floating point register list
|
||||
o_text = (idaapi.o_idpspec5+1) # Arbitrary text stored in the operand
|
||||
|
||||
@@ -3116,6 +3144,20 @@ def Message(msg):
|
||||
idaapi.msg(msg)
|
||||
|
||||
|
||||
def UMessage(msg):
|
||||
"""
|
||||
Display an UTF-8 string in the message window
|
||||
|
||||
The result of the stringification of the arguments
|
||||
will be treated as an UTF-8 string.
|
||||
|
||||
@param msg: message to print (formatting is done in Python)
|
||||
|
||||
This function can be used to debug IDC scripts
|
||||
"""
|
||||
idaapi.umsg(msg)
|
||||
|
||||
|
||||
def Warning(msg):
|
||||
"""
|
||||
Display a message in a message box
|
||||
@@ -6917,16 +6959,16 @@ def ApplyType(ea, py_type, flags = TINFO_DEFINITE):
|
||||
@return: Boolean
|
||||
"""
|
||||
|
||||
if py_type != None:
|
||||
if py_type is None:
|
||||
py_type = ""
|
||||
if isinstance(py_type, basestring) and len(py_type) == 0:
|
||||
pt = ("", "")
|
||||
else:
|
||||
if len(py_type) == 3:
|
||||
pt = py_type[1:] # skip name component
|
||||
else:
|
||||
pt = py_type
|
||||
return idaapi.apply_type(idaapi.cvar.idati, pt[0], pt[1], ea, flags)
|
||||
if idaapi.has_ti(ea):
|
||||
idaapi.del_tinfo(ea)
|
||||
return True
|
||||
return False
|
||||
return idaapi.apply_type(idaapi.cvar.idati, pt[0], pt[1], ea, flags)
|
||||
|
||||
def SetType(ea, newtype):
|
||||
"""
|
||||
@@ -6941,7 +6983,7 @@ def SetType(ea, newtype):
|
||||
@return: 1-ok, 0-failed.
|
||||
"""
|
||||
if newtype is not '':
|
||||
pt = ParseType(newtype, 0)
|
||||
pt = ParseType(newtype, 1) # silent
|
||||
if pt is None:
|
||||
# parsing failed
|
||||
return None
|
||||
|
||||
+2
-3
@@ -28,9 +28,8 @@ class IDAPythonStdOut:
|
||||
Dummy file-like class that receives stout and stderr
|
||||
"""
|
||||
def write(self, text):
|
||||
# Swap out the unprintable characters
|
||||
text = text.decode('ascii', 'replace').encode('ascii', 'replace')
|
||||
# Print to IDA message window
|
||||
# NB: in case 'text' is Unicode, msg() will decode it
|
||||
# and call umsg() to print it
|
||||
_idaapi.msg(text)
|
||||
|
||||
def flush(self):
|
||||
|
||||
Reference in New Issue
Block a user