Python idaapi.segment_t() Examples
The following are 9 code examples for showing how to use idaapi.segment_t(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
idaapi
, or try the search function
.
Example 1
Project: FIRST-plugin-ida Author: vrtadmin File: first.py License: GNU General Public License v2.0 | 6 votes |
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()
Example 2
Project: ida-minsc Author: arizvisa File: segment.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example 3
Project: FIRST-plugin-ida Author: vrtadmin File: first.py License: GNU General Public License v2.0 | 5 votes |
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
Example 4
Project: ida_haru Author: TakahiroHaruyama File: ida_loader_drv_vm.py License: Apache License 2.0 | 5 votes |
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)
Example 5
Project: ida-minsc Author: arizvisa File: segment.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def by(segment): '''Return a segment by its ``idaapi.segment_t``.''' return segment
Example 6
Project: ida-minsc Author: arizvisa File: segment.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example 7
Project: ida-minsc Author: arizvisa File: segment.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example 8
Project: ida-minsc Author: arizvisa File: segment.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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))
Example 9
Project: ida-evm Author: crytic File: evm-loader.py License: Apache License 2.0 | 4 votes |
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