mirror of
https://github.com/idapython/src
synced 2026-06-08 14:47:00 +00:00
IDAPython for IDA 7.4
This commit is contained in:
+25
-16
@@ -14,6 +14,7 @@ from __future__ import print_function
|
||||
#
|
||||
#---------------------------------------------------------------------
|
||||
# pylint: disable=C0103, C0111, C0301, C0326, W0511, R0903
|
||||
import sys
|
||||
import ctypes
|
||||
import idaapi
|
||||
import ida_idaapi
|
||||
@@ -41,21 +42,23 @@ def get_struct(str_, off, struct):
|
||||
ctypes.memmove(ctypes.addressof(s), bytebuf, fit)
|
||||
return s
|
||||
|
||||
_byte = ord if sys.version_info.major < 3 else lambda t: t
|
||||
|
||||
# unpack base address
|
||||
def unpack_db(buf, off):
|
||||
x = 0
|
||||
if off < len(buf):
|
||||
x = ord(buf[off])
|
||||
x = _byte(buf[off])
|
||||
off += 1
|
||||
return (x, off)
|
||||
|
||||
def get_dw(buf, off):
|
||||
x = 0
|
||||
if off < len(buf):
|
||||
x = ord(buf[off]) << 8
|
||||
x = _byte(buf[off]) << 8
|
||||
off += 1
|
||||
if off < len(buf):
|
||||
x |= ord(buf[off])
|
||||
x |= _byte(buf[off])
|
||||
off += 1
|
||||
return (x, off)
|
||||
|
||||
@@ -66,7 +69,7 @@ def unpack_dw(buf, off):
|
||||
(x, off) = get_dw(buf, off)
|
||||
else:
|
||||
if off < len(buf):
|
||||
x = ((x & ~0x80) << 8) | ord(buf[off])
|
||||
x = ((x & ~0x80) << 8) | _byte(buf[off])
|
||||
off += 1
|
||||
return (x, off)
|
||||
|
||||
@@ -79,13 +82,13 @@ def unpack_dd(buf, off):
|
||||
else:
|
||||
xh = 0
|
||||
if off < len(buf):
|
||||
xh = ((x & ~0xC0) << 8) | ord(buf[off])
|
||||
xh = ((x & ~0xC0) << 8) | _byte(buf[off])
|
||||
off += 1
|
||||
(xl, off) = get_dw(buf, off)
|
||||
x = (xh << 16) | xl
|
||||
else:
|
||||
if off < len(buf):
|
||||
x = ((x & ~0x80) << 8) | ord(buf[off])
|
||||
x = ((x & ~0x80) << 8) | _byte(buf[off])
|
||||
off += 1
|
||||
return (x, off)
|
||||
|
||||
@@ -184,21 +187,21 @@ class Dex(object):
|
||||
|
||||
# ea-based indexes
|
||||
DEXCMN_STRING_ID = ord('S') # string ea => string_id
|
||||
DEXCMN_METHOD_ID = ord('M') # dex_method::func.start_ea => method_id
|
||||
DEXCMN_TRY_TYPES = ord('E') # ea (handler start) => list of type_id, handled types
|
||||
DEXCMN_TRY_IDS = ord('Y') # ea (handler start) => list of try_item_id
|
||||
DEXCMN_DEBINFO = ord('D') # line start ea => dex_lineinfo_t
|
||||
DEXCMN_METHOD_ID = ord('M') # dex_method::func.start_ea => method_id
|
||||
DEXCMN_TRY_TYPES = ord('E') # ea (handler start) => list of type_id, handled types
|
||||
DEXCMN_TRY_IDS = ord('Y') # ea (handler start) => list of try_item_id
|
||||
DEXCMN_DEBINFO = ord('D') # line start ea => dex_lineinfo_t
|
||||
DEXCMN_DEBSTR = ord('B') # line start ea => human readable debug info string
|
||||
|
||||
# var indexes
|
||||
DEXVAR_STRING_IDS = ord('S') # string_id => ea
|
||||
DEXVAR_TYPE_IDS = ord('T') # type_id => descriptor_idx
|
||||
DEXVAR_TYPE_STR = ord('U') # type_id => type string (possible user redefined), char data
|
||||
DEXVAR_TYPE_STR = ord('U') # type_id => type string (possible user redefined), char data
|
||||
DEXVAR_TYPE_STRO = ord('V') # type_id => type string (original), char data
|
||||
DEXVAR_METHOD = ord('M') # method_id => struct dex_method, supval
|
||||
DEXVAR_METH_STR = ord('N') # method_id => method name, char data
|
||||
DEXVAR_METH_STR = ord('N') # method_id => method name, char data
|
||||
DEXVAR_METH_STRO = ord('O') # method_id => method name fromdex file, char data
|
||||
DEXVAR_FIELD = ord('F') # field_id => struct dex_field
|
||||
DEXVAR_FIELD = ord('F') # field_id => struct dex_field
|
||||
DEXVAR_TRYLIST = ord('Y') # method_id => try_item
|
||||
|
||||
# debug info representation
|
||||
@@ -263,6 +266,11 @@ class Dex(object):
|
||||
res += " " + access_bit
|
||||
return res[1:] if res else ""
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
@staticmethod
|
||||
def as_string(s):
|
||||
return s.decode("UTF-8") if sys.version_info.major >= 3 else s
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
def idx_to_ea(self, from_ea, idx, tag):
|
||||
nn_var = self.get_nn_var(from_ea)
|
||||
@@ -274,7 +282,8 @@ class Dex(object):
|
||||
if addr == ida_idaapi.BADADDR:
|
||||
return None
|
||||
length = ida_bytes.get_max_strlit_length(addr, idc.STRTYPE_C, ida_bytes.ALOPT_IGNHEADS|ida_bytes.ALOPT_IGNPRINT)
|
||||
return ida_bytes.get_strlit_contents(addr, length, idc.STRTYPE_C)
|
||||
raw = ida_bytes.get_strlit_contents(addr, length, idc.STRTYPE_C)
|
||||
return Dex.as_string(raw)
|
||||
|
||||
def get_method_idx(self, ea):
|
||||
return self.nn_cmn.altval(ea, Dex.DEXCMN_METHOD_ID)
|
||||
@@ -299,9 +308,9 @@ class Dex(object):
|
||||
longname_director = get_struct(val, 0, longname_director_t)
|
||||
if longname_director.zero == 0:
|
||||
nn = idaapi.netnode(longname_director.node)
|
||||
return nn.getblob(0, tag)[:-1]
|
||||
return Dex.as_string(nn.getblob(0, tag)[:-1])
|
||||
if len(val) > 0:
|
||||
return val[:-1]
|
||||
return Dex.as_string(val[:-1])
|
||||
return ""
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
+25
-24
@@ -32,7 +32,7 @@ import ida_xref
|
||||
import idc
|
||||
import types
|
||||
import os
|
||||
|
||||
import sys
|
||||
|
||||
def refs(ea, funcfirst, funcnext):
|
||||
"""
|
||||
@@ -57,7 +57,7 @@ def CodeRefsTo(ea, flow):
|
||||
Example::
|
||||
|
||||
for ref in CodeRefsTo(get_screen_ea(), 1):
|
||||
print ref
|
||||
print(ref)
|
||||
"""
|
||||
if flow == 1:
|
||||
return refs(ea, ida_xref.get_first_cref_to, ida_xref.get_next_cref_to)
|
||||
@@ -78,7 +78,7 @@ def CodeRefsFrom(ea, flow):
|
||||
Example::
|
||||
|
||||
for ref in CodeRefsFrom(get_screen_ea(), 1):
|
||||
print ref
|
||||
print(ref)
|
||||
"""
|
||||
if flow == 1:
|
||||
return refs(ea, ida_xref.get_first_cref_from, ida_xref.get_next_cref_from)
|
||||
@@ -97,7 +97,7 @@ def DataRefsTo(ea):
|
||||
Example::
|
||||
|
||||
for ref in DataRefsTo(get_screen_ea()):
|
||||
print ref
|
||||
print(ref)
|
||||
"""
|
||||
return refs(ea, ida_xref.get_first_dref_to, ida_xref.get_next_dref_to)
|
||||
|
||||
@@ -113,7 +113,7 @@ def DataRefsFrom(ea):
|
||||
Example::
|
||||
|
||||
for ref in DataRefsFrom(get_screen_ea()):
|
||||
print ref
|
||||
print(ref)
|
||||
"""
|
||||
return refs(ea, ida_xref.get_first_dref_from, ida_xref.get_next_dref_from)
|
||||
|
||||
@@ -159,12 +159,12 @@ def XrefsFrom(ea, flags=0):
|
||||
Return all references from address 'ea'
|
||||
|
||||
@param ea: Reference address
|
||||
@param flags: any of ida_xref.XREF_* flags
|
||||
@param flags: one of ida_xref.XREF_ALL (default), ida_xref.XREF_FAR, ida_xref.XREF_DATA
|
||||
|
||||
Example::
|
||||
for xref in XrefsFrom(here(), 0):
|
||||
print xref.type, XrefTypeName(xref.type), \
|
||||
'from', hex(xref.frm), 'to', hex(xref.to)
|
||||
print(xref.type, XrefTypeName(xref.type), \
|
||||
'from', hex(xref.frm), 'to', hex(xref.to))
|
||||
"""
|
||||
xref = ida_xref.xrefblk_t()
|
||||
if xref.first_from(ea, flags):
|
||||
@@ -178,12 +178,12 @@ def XrefsTo(ea, flags=0):
|
||||
Return all references to address 'ea'
|
||||
|
||||
@param ea: Reference address
|
||||
@param flags: any of ida_xref.XREF_* flags
|
||||
@param flags: one of ida_xref.XREF_ALL (default), ida_xref.XREF_FAR, ida_xref.XREF_DATA
|
||||
|
||||
Example::
|
||||
for xref in XrefsTo(here(), 0):
|
||||
print xref.type, XrefTypeName(xref.type), \
|
||||
'from', hex(xref.frm), 'to', hex(xref.to)
|
||||
print(xref.type, XrefTypeName(xref.type), \
|
||||
'from', hex(xref.frm), 'to', hex(xref.to))
|
||||
"""
|
||||
xref = ida_xref.xrefblk_t()
|
||||
if xref.first_to(ea, flags):
|
||||
@@ -194,7 +194,7 @@ def XrefsTo(ea, flags=0):
|
||||
|
||||
def Threads():
|
||||
"""Returns all thread IDs for the current debugee"""
|
||||
for i in xrange(0, idc.get_thread_qty()):
|
||||
for i in range(0, idc.get_thread_qty()):
|
||||
yield idc.getn_thread(i)
|
||||
|
||||
|
||||
@@ -283,7 +283,7 @@ def Names():
|
||||
|
||||
@return: List of tuples (ea, name)
|
||||
"""
|
||||
for i in xrange(ida_name.get_nlist_size()):
|
||||
for i in range(ida_name.get_nlist_size()):
|
||||
ea = ida_name.get_nlist_ea(i)
|
||||
name = ida_name.get_nlist_name(i)
|
||||
yield (ea, name)
|
||||
@@ -295,7 +295,7 @@ def Segments():
|
||||
|
||||
@return: List of segment start addresses.
|
||||
"""
|
||||
for n in xrange(ida_segment.get_segm_qty()):
|
||||
for n in range(ida_segment.get_segm_qty()):
|
||||
seg = ida_segment.getnseg(n)
|
||||
if seg:
|
||||
yield seg.start_ea
|
||||
@@ -308,7 +308,7 @@ def Entries():
|
||||
@return: List of tuples (index, ordinal, ea, name)
|
||||
"""
|
||||
n = ida_entry.get_entry_qty()
|
||||
for i in xrange(0, n):
|
||||
for i in range(0, n):
|
||||
ordinal = ida_entry.get_entry_ordinal(i)
|
||||
ea = ida_entry.get_entry(ordinal)
|
||||
name = ida_entry.get_entry_name(ordinal)
|
||||
@@ -482,7 +482,7 @@ class Strings(object):
|
||||
s = Strings()
|
||||
|
||||
for i in s:
|
||||
print "%x: len=%d type=%d -> '%s'" % (i.ea, i.length, i.strtype, str(i))
|
||||
print("%x: len=%d type=%d -> '%s'" % (i.ea, i.length, i.strtype, str(i)))
|
||||
|
||||
"""
|
||||
class StringItem(object):
|
||||
@@ -502,10 +502,13 @@ class Strings(object):
|
||||
|
||||
def _toseq(self, as_unicode):
|
||||
strbytes = ida_bytes.get_strlit_contents(self.ea, self.length, self.strtype)
|
||||
return unicode(strbytes, "UTF-8", 'replace') if as_unicode else strbytes
|
||||
if sys.version_info.major >= 3:
|
||||
return strbytes.decode("UTF-8", "replace") if as_unicode else strbytes
|
||||
else:
|
||||
return unicode(strbytes, "UTF-8", 'replace') if as_unicode else strbytes
|
||||
|
||||
def __str__(self):
|
||||
return self._toseq(False)
|
||||
return self._toseq(False if sys.version_info.major < 3 else True)
|
||||
|
||||
def __unicode__(self):
|
||||
return self._toseq(True)
|
||||
@@ -559,7 +562,7 @@ class Strings(object):
|
||||
|
||||
|
||||
def __iter__(self):
|
||||
return (self._get_item(index) for index in xrange(0, self.size))
|
||||
return (self._get_item(index) for index in range(0, self.size))
|
||||
|
||||
|
||||
def __getitem__(self, index):
|
||||
@@ -593,7 +596,7 @@ def _Assemble(ea, line):
|
||||
"""
|
||||
Please refer to Assemble() - INTERNAL USE ONLY
|
||||
"""
|
||||
if type(line) == bytes:
|
||||
if type(line) in ([bytes] + list(ida_idaapi.string_types)):
|
||||
lines = [line]
|
||||
else:
|
||||
lines = line
|
||||
@@ -686,11 +689,9 @@ class _procregs(object):
|
||||
class _cpu(object):
|
||||
"Simple wrapper around get_reg_value/set_reg_value"
|
||||
def __getattr__(self, name):
|
||||
#print "cpu.get(%s)" % name
|
||||
return idc.get_reg_value(name)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
#print "cpu.set(%s)" % name
|
||||
return idc.set_reg_value(value, name)
|
||||
|
||||
|
||||
@@ -784,7 +785,7 @@ class peutils_t(object):
|
||||
cpu = _cpu()
|
||||
"""This is a special class instance used to access the registers as if they were attributes of this object.
|
||||
For example to access the EAX register:
|
||||
print "%x" % cpu.Eax
|
||||
print("%x" % cpu.Eax)
|
||||
"""
|
||||
|
||||
procregs = _procregs()
|
||||
@@ -792,5 +793,5 @@ procregs = _procregs()
|
||||
For example:
|
||||
x = idautils.DecodeInstruction(here())
|
||||
if x[0] == procregs.Esp:
|
||||
print "This operand is the register ESP
|
||||
print("This operand is the register ESP)
|
||||
"""
|
||||
|
||||
+121
-178
@@ -270,16 +270,20 @@ FF_JUMP = ida_bytes.FF_JUMP & 0xFFFFFFFF # Has jump table
|
||||
#
|
||||
# Loader flags
|
||||
#
|
||||
NEF_SEGS = ida_loader.NEF_SEGS # Create segments
|
||||
NEF_RSCS = ida_loader.NEF_RSCS # Load resources
|
||||
NEF_NAME = ida_loader.NEF_NAME # Rename entries
|
||||
NEF_MAN = ida_loader.NEF_MAN # Manual load
|
||||
NEF_FILL = ida_loader.NEF_FILL # Fill segment gaps
|
||||
NEF_IMPS = ida_loader.NEF_IMPS # Create imports section
|
||||
NEF_FIRST = ida_loader.NEF_FIRST # This is the first file loaded
|
||||
NEF_CODE = ida_loader.NEF_CODE # for load_binary_file:
|
||||
NEF_RELOAD = ida_loader.NEF_RELOAD # reload the file at the same place:
|
||||
NEF_FLAT = ida_loader.NEF_FLAT # Autocreated FLAT group (PE)
|
||||
if ida_idaapi.uses_swig_builtins:
|
||||
_scope = ida_loader.loader_t
|
||||
else:
|
||||
_scope = ida_loader
|
||||
NEF_SEGS = _scope.NEF_SEGS # Create segments
|
||||
NEF_RSCS = _scope.NEF_RSCS # Load resources
|
||||
NEF_NAME = _scope.NEF_NAME # Rename entries
|
||||
NEF_MAN = _scope.NEF_MAN # Manual load
|
||||
NEF_FILL = _scope.NEF_FILL # Fill segment gaps
|
||||
NEF_IMPS = _scope.NEF_IMPS # Create imports section
|
||||
NEF_FIRST = _scope.NEF_FIRST # This is the first file loaded
|
||||
NEF_CODE = _scope.NEF_CODE # for load_binary_file:
|
||||
NEF_RELOAD = _scope.NEF_RELOAD # reload the file at the same place:
|
||||
NEF_FLAT = _scope.NEF_FLAT # Autocreated FLAT group (PE)
|
||||
|
||||
# List of built-in functions
|
||||
# --------------------------
|
||||
@@ -359,13 +363,13 @@ def rotate_left(value, count, nbits, offset):
|
||||
tmp = value & mask
|
||||
|
||||
if count > 0:
|
||||
for x in xrange(count):
|
||||
for x in range(count):
|
||||
if (tmp >> (offset+nbits-1)) & 1:
|
||||
tmp = (tmp << 1) | (1 << offset)
|
||||
else:
|
||||
tmp = (tmp << 1)
|
||||
else:
|
||||
for x in xrange(-count):
|
||||
for x in range(-count):
|
||||
if (tmp >> offset) & 1:
|
||||
tmp = (tmp >> 1) | (1 << (offset+nbits-1))
|
||||
else:
|
||||
@@ -808,7 +812,7 @@ def define_local_var(start, end, location, name):
|
||||
frame,
|
||||
name,
|
||||
offset,
|
||||
ida_bytes.byteflag(),
|
||||
ida_bytes.byte_flag(),
|
||||
None, 1) == 0:
|
||||
return 1
|
||||
else:
|
||||
@@ -818,18 +822,7 @@ def define_local_var(start, end, location, name):
|
||||
return ida_frame.add_regvar(func, start, end, location, name, None)
|
||||
|
||||
|
||||
def del_items(ea, flags=0, size=1):
|
||||
"""
|
||||
Convert the current item to an explored item
|
||||
|
||||
@param ea: linear address
|
||||
@param flags: combination of DELIT_* constants
|
||||
@param size: size of the range to undefine
|
||||
|
||||
@return: None
|
||||
"""
|
||||
return ida_bytes.del_items(ea, flags, size)
|
||||
|
||||
del_items = ida_bytes.del_items
|
||||
|
||||
DELIT_SIMPLE = ida_bytes.DELIT_SIMPLE # simply undefine the specified item
|
||||
DELIT_EXPAND = ida_bytes.DELIT_EXPAND # propogate undefined items, for example
|
||||
@@ -985,7 +978,12 @@ def op_stroff(ea, n, strid, delta):
|
||||
"""
|
||||
path = ida_pro.tid_array(1)
|
||||
path[0] = strid
|
||||
return ida_bytes.op_stroff(ea, n, path.cast(), 1, delta)
|
||||
if isinstance(ea, ida_ua.insn_t):
|
||||
insn = ea
|
||||
else:
|
||||
insn = ida_ua.insn_t()
|
||||
ida_ua.decode_insn(insn, ea)
|
||||
return ida_bytes.op_stroff(insn, n, path.cast(), 1, delta)
|
||||
|
||||
|
||||
op_stkvar = ida_bytes.op_stkvar
|
||||
@@ -1765,12 +1763,12 @@ def get_str_type(ea):
|
||||
# flag is combination of the following bits
|
||||
|
||||
# returns BADADDR - not found
|
||||
def find_suspop (ea, flag): return ida_search.find_suspop(ea, flag)
|
||||
def find_code (ea, flag): return ida_search.find_code(ea, flag)
|
||||
def find_data (ea, flag): return ida_search.find_data(ea, flag)
|
||||
def find_unknown (ea, flag): return ida_search.find_unknown(ea, flag)
|
||||
def find_defined (ea, flag): return ida_search.find_defined(ea, flag)
|
||||
def find_imm (ea, flag, value): return ida_search.find_imm(ea, flag, value)
|
||||
find_suspop = ida_search.find_suspop
|
||||
find_code = ida_search.find_code
|
||||
find_data = ida_search.find_data
|
||||
find_unknown = ida_search.find_unknown
|
||||
find_defined = ida_search.find_defined
|
||||
find_imm = ida_search.find_imm
|
||||
|
||||
SEARCH_UP = ida_search.SEARCH_UP # search backward
|
||||
SEARCH_DOWN = ida_search.SEARCH_DOWN # search forward
|
||||
@@ -2366,16 +2364,7 @@ ADDSEG_SPARSE = ida_segment.ADDSEG_SPARSE # Use sparse storage method for the
|
||||
def AddSeg(startea, endea, base, use32, align, comb):
|
||||
return add_segm_ex(startea, endea, base, use32, align, comb, ADDSEG_NOSREG)
|
||||
|
||||
def del_segm(ea, flags):
|
||||
"""
|
||||
Delete a segment
|
||||
|
||||
@param ea: any address in the segment
|
||||
@param flags: combination of SEGMOD_* flags
|
||||
|
||||
@return: boolean success
|
||||
"""
|
||||
return ida_segment.del_segm(ea, flags)
|
||||
del_segm = ida_segment.del_segm
|
||||
|
||||
SEGMOD_KILL = ida_segment.SEGMOD_KILL # disable addresses if segment gets
|
||||
# shrinked or deleted
|
||||
@@ -2444,22 +2433,26 @@ def set_segm_alignment(ea, alignment):
|
||||
return set_segm_attr(ea, SEGATTR_ALIGN, alignment)
|
||||
|
||||
|
||||
saAbs = ida_segment.saAbs # Absolute segment.
|
||||
saRelByte = ida_segment.saRelByte # Relocatable, byte aligned.
|
||||
saRelWord = ida_segment.saRelWord # Relocatable, word (2-byte, 16-bit) aligned.
|
||||
saRelPara = ida_segment.saRelPara # Relocatable, paragraph (16-byte) aligned.
|
||||
saRelPage = ida_segment.saRelPage # Relocatable, aligned on 256-byte boundary
|
||||
# (a "page" in the original Intel specification).
|
||||
saRelDble = ida_segment.saRelDble # Relocatable, aligned on a double word
|
||||
# (4-byte) boundary. This value is used by
|
||||
# the PharLap OMF for the same alignment.
|
||||
saRel4K = ida_segment.saRel4K # This value is used by the PharLap OMF for
|
||||
# page (4K) alignment. It is not supported
|
||||
# by LINK.
|
||||
saGroup = ida_segment.saGroup # Segment group
|
||||
saRel32Bytes = ida_segment.saRel32Bytes # 32 bytes
|
||||
saRel64Bytes = ida_segment.saRel64Bytes # 64 bytes
|
||||
saRelQword = ida_segment.saRelQword # 8 bytes
|
||||
if ida_idaapi.uses_swig_builtins:
|
||||
_scope = ida_segment.segment_t
|
||||
else:
|
||||
_scope = ida_segment
|
||||
saAbs = _scope.saAbs # Absolute segment.
|
||||
saRelByte = _scope.saRelByte # Relocatable, byte aligned.
|
||||
saRelWord = _scope.saRelWord # Relocatable, word (2-byte, 16-bit) aligned.
|
||||
saRelPara = _scope.saRelPara # Relocatable, paragraph (16-byte) aligned.
|
||||
saRelPage = _scope.saRelPage # Relocatable, aligned on 256-byte boundary
|
||||
# (a "page" in the original Intel specification).
|
||||
saRelDble = _scope.saRelDble # Relocatable, aligned on a double word
|
||||
# (4-byte) boundary. This value is used by
|
||||
# the PharLap OMF for the same alignment.
|
||||
saRel4K = _scope.saRel4K # This value is used by the PharLap OMF for
|
||||
# page (4K) alignment. It is not supported
|
||||
# by LINK.
|
||||
saGroup = _scope.saGroup # Segment group
|
||||
saRel32Bytes = _scope.saRel32Bytes # 32 bytes
|
||||
saRel64Bytes = _scope.saRel64Bytes # 64 bytes
|
||||
saRelQword = _scope.saRelQword # 8 bytes
|
||||
|
||||
|
||||
def set_segm_combination(segea, comb):
|
||||
@@ -2474,15 +2467,15 @@ def set_segm_combination(segea, comb):
|
||||
return set_segm_attr(segea, SEGATTR_COMB, comb)
|
||||
|
||||
|
||||
scPriv = ida_segment.scPriv # Private. Do not combine with any other program
|
||||
# segment.
|
||||
scPub = ida_segment.scPub # Public. Combine by appending at an offset that
|
||||
# meets the alignment requirement.
|
||||
scPub2 = ida_segment.scPub2 # As defined by Microsoft, same as C=2 (public).
|
||||
scStack = ida_segment.scStack # Stack. Combine as for C=2. This combine type
|
||||
# forces byte alignment.
|
||||
scCommon = ida_segment.scCommon # Common. Combine by overlay using maximum size.
|
||||
scPub3 = ida_segment.scPub3 # As defined by Microsoft, same as C=2 (public).
|
||||
scPriv = _scope.scPriv # Private. Do not combine with any other program
|
||||
# segment.
|
||||
scPub = _scope.scPub # Public. Combine by appending at an offset that
|
||||
# meets the alignment requirement.
|
||||
scPub2 = _scope.scPub2 # As defined by Microsoft, same as C=2 (public).
|
||||
scStack = _scope.scStack # Stack. Combine as for C=2. This combine type
|
||||
# forces byte alignment.
|
||||
scCommon = _scope.scCommon # Common. Combine by overlay using maximum size.
|
||||
scPub3 = _scope.scPub3 # As defined by Microsoft, same as C=2 (public).
|
||||
|
||||
|
||||
def set_segm_addressing(ea, bitness):
|
||||
@@ -2557,22 +2550,22 @@ def set_segm_type(segea, segtype):
|
||||
return seg.update()
|
||||
|
||||
|
||||
SEG_NORM = ida_segment.SEG_NORM
|
||||
SEG_XTRN = ida_segment.SEG_XTRN # * segment with 'extern' definitions
|
||||
# no instructions are allowed
|
||||
SEG_CODE = ida_segment.SEG_CODE # pure code segment
|
||||
SEG_DATA = ida_segment.SEG_DATA # pure data segment
|
||||
SEG_IMP = ida_segment.SEG_IMP # implementation segment
|
||||
SEG_GRP = ida_segment.SEG_GRP # * group of segments
|
||||
# no instructions are allowed
|
||||
SEG_NULL = ida_segment.SEG_NULL # zero-length segment
|
||||
SEG_UNDF = ida_segment.SEG_UNDF # undefined segment type
|
||||
SEG_BSS = ida_segment.SEG_BSS # uninitialized segment
|
||||
SEG_ABSSYM = ida_segment.SEG_ABSSYM # * segment with definitions of absolute symbols
|
||||
# no instructions are allowed
|
||||
SEG_COMM = ida_segment.SEG_COMM # * segment with communal definitions
|
||||
# no instructions are allowed
|
||||
SEG_IMEM = ida_segment.SEG_IMEM # internal processor memory & sfr (8051)
|
||||
SEG_NORM = _scope.SEG_NORM
|
||||
SEG_XTRN = _scope.SEG_XTRN # * segment with 'extern' definitions
|
||||
# no instructions are allowed
|
||||
SEG_CODE = _scope.SEG_CODE # pure code segment
|
||||
SEG_DATA = _scope.SEG_DATA # pure data segment
|
||||
SEG_IMP = _scope.SEG_IMP # implementation segment
|
||||
SEG_GRP = _scope.SEG_GRP # * group of segments
|
||||
# no instructions are allowed
|
||||
SEG_NULL = _scope.SEG_NULL # zero-length segment
|
||||
SEG_UNDF = _scope.SEG_UNDF # undefined segment type
|
||||
SEG_BSS = _scope.SEG_BSS # uninitialized segment
|
||||
SEG_ABSSYM = _scope.SEG_ABSSYM # * segment with definitions of absolute symbols
|
||||
# no instructions are allowed
|
||||
SEG_COMM = _scope.SEG_COMM # * segment with communal definitions
|
||||
# no instructions are allowed
|
||||
SEG_IMEM = _scope.SEG_IMEM # internal processor memory & sfr (8051)
|
||||
|
||||
|
||||
def get_segm_attr(segea, attr):
|
||||
@@ -2880,25 +2873,7 @@ def writestr(handle, s):
|
||||
# F U N C T I O N S
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
def add_func(start, end = ida_idaapi.BADADDR):
|
||||
"""
|
||||
Create a function
|
||||
|
||||
@param start: function bounds
|
||||
@param end: function bounds
|
||||
|
||||
If the function end address is BADADDR, then
|
||||
IDA will try to determine the function bounds
|
||||
automatically. IDA will define all necessary
|
||||
instructions to determine the function bounds.
|
||||
|
||||
@return: !=0 - ok
|
||||
|
||||
@note: an instruction should be present at the start address
|
||||
"""
|
||||
return ida_funcs.add_func(start, end)
|
||||
|
||||
|
||||
add_func = ida_funcs.add_func
|
||||
del_func = ida_funcs.del_func
|
||||
set_func_end = ida_funcs.set_func_end
|
||||
|
||||
@@ -3026,33 +3001,38 @@ def get_func_flags(ea):
|
||||
return func.flags
|
||||
|
||||
|
||||
FUNC_NORET = ida_funcs.FUNC_NORET # function doesn't return
|
||||
FUNC_FAR = ida_funcs.FUNC_FAR # far function
|
||||
FUNC_LIB = ida_funcs.FUNC_LIB # library function
|
||||
FUNC_STATIC = ida_funcs.FUNC_STATICDEF # static function
|
||||
FUNC_FRAME = ida_funcs.FUNC_FRAME # function uses frame pointer (BP)
|
||||
FUNC_USERFAR = ida_funcs.FUNC_USERFAR # user has specified far-ness
|
||||
# of the function
|
||||
FUNC_HIDDEN = ida_funcs.FUNC_HIDDEN # a hidden function
|
||||
FUNC_THUNK = ida_funcs.FUNC_THUNK # thunk (jump) function
|
||||
FUNC_BOTTOMBP = ida_funcs.FUNC_BOTTOMBP # BP points to the bottom of the stack frame
|
||||
FUNC_NORET_PENDING = ida_funcs.FUNC_NORET_PENDING # Function 'non-return' analysis
|
||||
# must be performed. This flag is
|
||||
# verified upon func_does_return()
|
||||
FUNC_SP_READY = ida_funcs.FUNC_SP_READY # SP-analysis has been performed
|
||||
# If this flag is on, the stack
|
||||
# change points should not be not
|
||||
# modified anymore. Currently this
|
||||
# analysis is performed only for PC
|
||||
FUNC_PURGED_OK = ida_funcs.FUNC_PURGED_OK # 'argsize' field has been validated.
|
||||
# If this bit is clear and 'argsize'
|
||||
# is 0, then we do not known the real
|
||||
# number of bytes removed from
|
||||
# the stack. This bit is handled
|
||||
# by the processor module.
|
||||
FUNC_TAIL = ida_funcs.FUNC_TAIL # This is a function tail.
|
||||
# Other bits must be clear
|
||||
# (except FUNC_HIDDEN)
|
||||
if ida_idaapi.uses_swig_builtins:
|
||||
_scope = ida_funcs.func_t
|
||||
else:
|
||||
_scope = ida_funcs
|
||||
|
||||
FUNC_NORET = _scope.FUNC_NORET # function doesn't return
|
||||
FUNC_FAR = _scope.FUNC_FAR # far function
|
||||
FUNC_LIB = _scope.FUNC_LIB # library function
|
||||
FUNC_STATIC = _scope.FUNC_STATICDEF # static function
|
||||
FUNC_FRAME = _scope.FUNC_FRAME # function uses frame pointer (BP)
|
||||
FUNC_USERFAR = _scope.FUNC_USERFAR # user has specified far-ness
|
||||
# of the function
|
||||
FUNC_HIDDEN = _scope.FUNC_HIDDEN # a hidden function
|
||||
FUNC_THUNK = _scope.FUNC_THUNK # thunk (jump) function
|
||||
FUNC_BOTTOMBP = _scope.FUNC_BOTTOMBP # BP points to the bottom of the stack frame
|
||||
FUNC_NORET_PENDING = _scope.FUNC_NORET_PENDING # Function 'non-return' analysis
|
||||
# must be performed. This flag is
|
||||
# verified upon func_does_return()
|
||||
FUNC_SP_READY = _scope.FUNC_SP_READY # SP-analysis has been performed
|
||||
# If this flag is on, the stack
|
||||
# change points should not be not
|
||||
# modified anymore. Currently this
|
||||
# analysis is performed only for PC
|
||||
FUNC_PURGED_OK = _scope.FUNC_PURGED_OK # 'argsize' field has been validated.
|
||||
# If this bit is clear and 'argsize'
|
||||
# is 0, then we do not known the real
|
||||
# number of bytes removed from
|
||||
# the stack. This bit is handled
|
||||
# by the processor module.
|
||||
FUNC_TAIL = _scope.FUNC_TAIL # This is a function tail.
|
||||
# Other bits must be clear
|
||||
# (except FUNC_HIDDEN)
|
||||
|
||||
|
||||
def set_func_flags(ea, flags):
|
||||
@@ -3979,10 +3959,10 @@ def add_struc_member(sid, name, offset, flag, typeid, nbytes, target=-1, tdelta=
|
||||
|
||||
"""
|
||||
if is_off0(flag):
|
||||
return eval_idc('add_struc_member(%d, "%s", %d, %d, %d, %d, %d, %d, %d);' % (sid, ida_kernwin.str2user(name), offset, flag, typeid, nbytes,
|
||||
return eval_idc('add_struc_member(%d, "%s", %d, %d, %d, %d, %d, %d, %d);' % (sid, ida_kernwin.str2user(name or ""), offset, flag, typeid, nbytes,
|
||||
target, tdelta, reftype))
|
||||
else:
|
||||
return eval_idc('add_struc_member(%d, "%s", %d, %d, %d, %d);' % (sid, ida_kernwin.str2user(name), offset, flag, typeid, nbytes))
|
||||
return eval_idc('add_struc_member(%d, "%s", %d, %d, %d, %d);' % (sid, ida_kernwin.str2user(name or ""), offset, flag, typeid, nbytes))
|
||||
|
||||
|
||||
STRUC_ERROR_MEMBER_NAME = -1 # already has member with this name (bad name)
|
||||
@@ -4136,16 +4116,7 @@ def set_fchunk_attr(ea, attr, value):
|
||||
return 0
|
||||
|
||||
|
||||
def get_fchunk_referer(ea, idx):
|
||||
"""
|
||||
Get a function chunk referer
|
||||
|
||||
@param ea: any address in the chunk
|
||||
@param idx: referer index (0..get_fchunk_attr(FUNCATTR_REFQTY))
|
||||
|
||||
@return: referer address or BADADDR
|
||||
"""
|
||||
return ida_funcs.get_fchunk_referer(ea, idx)
|
||||
get_fchunk_referer = ida_funcs.get_fchunk_referer
|
||||
|
||||
|
||||
def get_next_fchunk(ea):
|
||||
@@ -4664,6 +4635,8 @@ def __GetArrayById(array_id):
|
||||
return __dummy_netnode.instance
|
||||
else:
|
||||
return node
|
||||
except TypeError:
|
||||
return __dummy_netnode.instance
|
||||
except NotImplementedError:
|
||||
return __dummy_netnode.instance
|
||||
|
||||
@@ -5101,8 +5074,8 @@ def apply_type(ea, py_type, flags = TINFO_DEFINITE):
|
||||
|
||||
if py_type is None:
|
||||
py_type = ""
|
||||
if isinstance(py_type, basestring) and len(py_type) == 0:
|
||||
pt = ("", "")
|
||||
if isinstance(py_type, ida_idaapi.string_types) and len(py_type) == 0:
|
||||
pt = (b"", b"")
|
||||
else:
|
||||
if len(py_type) == 3:
|
||||
pt = py_type[1:] # skip name component
|
||||
@@ -5199,7 +5172,7 @@ def print_decls(ordinals, flags):
|
||||
return 0
|
||||
|
||||
sink = def_sink()
|
||||
py_ordinals = map(lambda l : int(l), ordinals.split(","))
|
||||
py_ordinals = list(map(lambda l : int(l), ordinals.split(",")))
|
||||
ida_typeinf.print_decls(sink, None, py_ordinals, flags)
|
||||
|
||||
return sink.text
|
||||
@@ -5687,13 +5660,7 @@ def set_reg_value(value, name):
|
||||
return ida_dbg.set_reg_val(name, value)
|
||||
|
||||
|
||||
def get_bpt_qty():
|
||||
"""
|
||||
Get number of breakpoints.
|
||||
|
||||
@return: number of breakpoints
|
||||
"""
|
||||
return ida_dbg.get_bpt_qty()
|
||||
get_bpt_qty = ida_dbg.get_bpt_qty
|
||||
|
||||
|
||||
def get_bpt_ea(n):
|
||||
@@ -5846,34 +5813,10 @@ def set_bpt_cond(ea, cnd, is_lowcnd=0):
|
||||
return ida_dbg.update_bpt(bpt)
|
||||
|
||||
|
||||
def add_bpt(ea, size=0, bpttype=BPT_DEFAULT):
|
||||
"""
|
||||
Add a new breakpoint
|
||||
|
||||
@param ea: any address in the process memory space:
|
||||
@param size: size of the breakpoint (irrelevant for software breakpoints):
|
||||
@param bpttype: type of the breakpoint (one of BPT_... constants)
|
||||
|
||||
@return: success
|
||||
|
||||
@note: Only one breakpoint can exist at a given address.
|
||||
"""
|
||||
return ida_dbg.add_bpt(ea, size, bpttype)
|
||||
|
||||
|
||||
def del_bpt(ea):
|
||||
"""
|
||||
Delete breakpoint
|
||||
|
||||
@param ea: any address in the process memory space:
|
||||
|
||||
@return: success
|
||||
"""
|
||||
return ida_dbg.del_bpt(ea)
|
||||
|
||||
|
||||
add_bpt = ida_dbg.add_bpt
|
||||
del_bpt = ida_dbg.del_bpt
|
||||
enable_bpt = ida_dbg.enable_bpt
|
||||
check_bpt = ida_dbg.check_bpt
|
||||
check_bpt = ida_dbg.check_bpt
|
||||
|
||||
BPTCK_NONE = -1 # breakpoint does not exist
|
||||
BPTCK_NO = 0 # breakpoint is disabled
|
||||
|
||||
+18
-1
@@ -21,7 +21,8 @@ import warnings
|
||||
lib_dynload = os.path.join(
|
||||
sys.executable,
|
||||
IDAPYTHON_DYNLOAD_BASE,
|
||||
"python", "lib", "python2.7", "lib-dynload")
|
||||
"python",
|
||||
str(sys.version_info.major))
|
||||
|
||||
is_x64 = sys.maxsize >= 0x100000000
|
||||
if is_x64:
|
||||
@@ -140,4 +141,20 @@ userrc = os.path.join(ida_diskio.get_user_idadir(), "idapythonrc.py")
|
||||
if os.path.exists(userrc):
|
||||
ida_idaapi.IDAPython_ExecScript(userrc, globals())
|
||||
|
||||
# In Python3, some modules (e.g., subprocess) will load the 'signal'
|
||||
# module which, upon loading, will registers default handlers for some
|
||||
# signals. In particular, for SIGINT, which we don't want to handle
|
||||
# since it'll prevent us from killing IDA with Ctrl+C on a TTY.
|
||||
if sys.version_info.major >= 3:
|
||||
import signal
|
||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
|
||||
# Also, embedded Python3 will not include the 'site packages' by
|
||||
# default, which means many packages provided by the distribution
|
||||
# would not be reachable. Let's provide a way to load them.
|
||||
import site
|
||||
for sp in site.getsitepackages():
|
||||
if sp not in sys.path:
|
||||
sys.path.append(sp)
|
||||
|
||||
# All done, ready to rock.
|
||||
|
||||
Reference in New Issue
Block a user