本文整理汇总了Python中idaapi.segment_t方法的典型用法代码示例。如果您正苦于以下问题:Python idaapi.segment_t方法的具体用法?Python idaapi.segment_t怎么用?Python idaapi.segment_t使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类idaapi
的用法示例。
在下文中一共展示了idaapi.segment_t方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_segment_functions
# 需要导入模块: import idaapi [as 别名]
# 或者: from idaapi import segment_t [as 别名]
def get_segment_functions(segment):
'''Returns functions for a given segment.
Args:
segment (`segment_t`): The segment functions will be returned
from. segment_t objects are returned from IDA's getseg API.
Returns:
list: Empty list or list of MetadataShim objects on success.
None: None on failure.
Fails if argument is not a segment_t or there are no functions
in that segment.
'''
if not isinstance(segment, idaapi.segment_t):
return None
segment_offset = segment.startEA - IDAW.get_imagebase()
if segment_offset not in FIRST.function_list:
return None
return FIRST.function_list[segment_offset].values()
示例2: remove
# 需要导入模块: import idaapi [as 别名]
# 或者: from idaapi import segment_t [as 别名]
def remove(segment, contents=False):
"""Remove the specified `segment`.
If the bool `contents` is specified, then remove the contents of the segment from the database.
"""
if not isinstance(segment, idaapi.segment_t):
cls = idaapi.segment_t
raise E.InvalidParameterError(u"{:s}.remove({!r}) : Expected an `idaapi.segment_t`, but received a {!s}.".format(__name__, segment, type(segment)))
# delete the selector defined by the segment_t
res = idaapi.del_selector(segment.sel)
if res == 0:
logging.warn(u"{:s}.remove({!r}) : Unable to delete the selector {:#x}.".format(__name__, segment, segment.sel))
# remove the actual segment using the address in the segment_t
res = idaapi.del_segm(interface.range.start(segment), idaapi.SEGMOD_KILL if contents else idaapi.SEGMOD_KEEP)
if res == 0:
logging.warn(u"{:s}.remove({!r}) : Unable to delete the segment {:s} with the selector {:s}.".format(__name__, segment, segment.name, segment.sel))
return res
示例3: get_segments_with_functions
# 需要导入模块: import idaapi [as 别名]
# 或者: from idaapi import segment_t [as 别名]
def get_segments_with_functions():
'''Returns a list of segments with defined functions in it.
Returns:
list: Empty list or list of segment_t objects
'''
data = []
if not FIRST.function_list:
return None
for segment_offset in FIRST.function_list:
data.append(IDAW.getseg(segment_offset + IDAW.get_imagebase()))
return data
示例4: myAddSeg
# 需要导入模块: import idaapi [as 别名]
# 或者: from idaapi import segment_t [as 别名]
def myAddSeg(startea, endea, base, use32, name, clas):
s = idaapi.segment_t()
s.start_ea = startea
s.end_ea = endea
s.sel = idaapi.setup_selector(base)
s.bitness = use32
s.align = idaapi.saRelPara
s.comb = idaapi.scPub
#idaapi.add_segm_ex(s, name, clas, idaapi.ADDSEG_NOSREG|idaapi.ADDSEG_OR_DIE)
idaapi.add_segm(base, startea, endea, name, clas)
示例5: by
# 需要导入模块: import idaapi [as 别名]
# 或者: from idaapi import segment_t [as 别名]
def by(segment):
'''Return a segment by its ``idaapi.segment_t``.'''
return segment
示例6: iterate
# 需要导入模块: import idaapi [as 别名]
# 或者: from idaapi import segment_t [as 别名]
def iterate(segment):
'''Iterate through all of the addresses within the ``idaapi.segment_t`` represented by `segment`.'''
left, right = interface.range.unpack(segment)
for ea in database.address.iterate(left, database.address.prev(right)):
yield ea
return
示例7: contains
# 需要导入模块: import idaapi [as 别名]
# 或者: from idaapi import segment_t [as 别名]
def contains(segment, ea):
'''Returns true if the address `ea` is contained within the ``idaapi.segment_t`` specified by `segment`.'''
return interface.range.within(ea, segment)
## functions
# shamefully ripped from idc.py
示例8: save
# 需要导入模块: import idaapi [as 别名]
# 或者: from idaapi import segment_t [as 别名]
def save(filename, segment, offset=0):
"""Export the segment identified by `segment` to the file named `filename`.
If the int `offset` is specified, then begin writing into the file at the specified offset.
"""
if isinstance(segment, idaapi.segment_t):
return __save_file(utils.string.to(filename), interface.range.start(segment), size(segment), offset)
return save(filename, by(segment))
示例9: load_file
# 需要导入模块: import idaapi [as 别名]
# 或者: from idaapi import segment_t [as 别名]
def load_file(li, neflags, format):
# Select the PC processor module
idaapi.set_processor_type("EVM", SETPROC_ALL|SETPROC_FATAL)
# TODO: detect and emulate contract creation code
li.seek(0)
buf = li.read(li.size())
if not buf:
return 0
if buf[0:2] == '0x':
print "Detected hex"
new_buf = buf[2:].strip().rstrip()
buf_set = set()
for c in new_buf:
buf_set.update(c)
hex_set = set(list('0123456789abcdef'))
if buf_set <= hex_set: # subset
print "Replacing original buffer with hex decoded version"
buf = new_buf.decode('hex')
# Load all shellcode into different segments
start = 0x0
seg = idaapi.segment_t()
size = len(buf)
end = start + size
# Create the segment
seg.startEA = start
seg.endEA = end
seg.bitness = 1 # 32-bit
idaapi.add_segm_ex(seg, "evm", "CODE", 0)
# TODO: make segments for stack, memory, storage
# Copy the bytes
idaapi.mem2base(buf, start, end)
# check for swarm hash and make it data instead of code
swarm_hash_address = buf.find('ebzzr0')
if swarm_hash_address != -1:
print "Swarm hash detected, making it data"
for i in range(swarm_hash_address-1, swarm_hash_address+42):
MakeByte(i)
ida_bytes.set_cmt(swarm_hash_address-1, "swarm hash", True)
# add entry point
idaapi.add_entry(start, start, "start", 1)
# add comment to beginning of disassembly
idaapi.describe(start, True, "EVM bytecode disassembly")
# Mark for analysis
AutoMark(start, AU_CODE)
#setup_enums()
return 1