Python ida_bytes.get_bytes() Examples

The following are 8 code examples of ida_bytes.get_bytes(). 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 also want to check out all available functions/classes of the module ida_bytes , or try the search function .
Example #1
Source File: utils.py    From UEFI_RETool with MIT License 5 votes vote down vote up
def check_guid(address):
    """correctness is determined based on the number of unique bytes"""
    return (len(set(ida_bytes.get_bytes(address, 16))) > 8) 
Example #2
Source File: findcrypt3.py    From findcrypt-yara with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _get_memory(self):
        result = bytearray()
        segment_starts = [ea for ea in idautils.Segments()]
        offsets = []
        start_len = 0
        for start in segment_starts:
            end = idc.get_segm_attr(start, idc.SEGATTR_END)
            result += ida_bytes.get_bytes(start, end - start)
            offsets.append((start, start_len, len(result)))
            start_len = len(result)
        return bytes(result), offsets 
Example #3
Source File: IdaInterface.py    From smda with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def getInstructionBytes(self, offset):
        ins = idautils.DecodeInstruction(offset)
        ins_bytes = ida_bytes.get_bytes(offset, ins.size)
        return ins_bytes 
Example #4
Source File: IdaInterface.py    From smda with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def getBinary(self):
        result = b""
        segment = ida_segment.get_first_seg()
        while segment:
            result += ida_bytes.get_bytes(segment.start_ea, segment.end_ea - segment.start_ea)
            segment = ida_segment.get_next_seg(segment.end_ea)
        return result 
Example #5
Source File: IdaInterface.py    From smda with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def getInstructionBytes(self, offset):
        ins = idautils.DecodeInstruction(offset)
        ins_bytes = idc.get_bytes(offset, ins.size)
        return ins_bytes 
Example #6
Source File: IdaInterface.py    From smda with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def getBinary(self):
        result = b""
        segment_starts = [ea for ea in idautils.Segments()]
        offsets = []
        start_len = 0
        for start in segment_starts:
            end = idc.SegEnd(start)
            result += idc.get_bytes(start, end - start)
            offsets.append((start, start_len, len(result)))
            start_len = len(result)
        return result 
Example #7
Source File: objc2_xrefs_helper.py    From flare-ida with Apache License 2.0 5 votes vote down vote up
def add_method_xref(self,xref):
        Message("Adding cross reference to method implementation for %s\n" % GetFunctionName(self.method_pointer))
        
        add_dref(xref.frm,self.method_pointer,dr_I|XREF_USER)

        offset=self.method_pointer-xref.frm
        
        instruction_bytes=get_bytes(xref.frm,self.ARM64_INSTRUCTION_SIZE)
        #TODO: are there other instructions that could reference a method selector
        #and then move the selector reference into a register?
        arm64_ldr=AArch64LDRInstruction(instruction_bytes)
        
        arm64_ldr.patch_offset(offset)

        PatchDword(xref.frm,arm64_ldr.instruction_int)
        return ObjcMethodXref(xref.frm,self.method_pointer,xref.to) 
Example #8
Source File: wasm_emu.py    From idawasm with Apache License 2.0 4 votes vote down vote up
def main():
    is_selected, sel_start, sel_end = idaapi.read_selection()
    if not is_selected:
        logger.error('range must be selected')
        return -1

    sel_end = idc.NextHead(sel_end)

    buf = ida_bytes.get_bytes(sel_start, sel_end - sel_start)
    if buf is None:
        logger.error('failed to fetch instruction bytes')
        return -1

    f = idaapi.get_func(sel_start)
    if f != idaapi.get_func(sel_end):
        logger.error('range must be within a single function')
        return -1

    # find mappings from "$localN" to "custom_name"
    regvars = {}
    for i in range(0x1000):
        regvar = idaapi.find_regvar(f, sel_start, '$local%d' % (i))
        if regvar is None:
            continue
        regvars[regvar.canon] = regvar.user

        if len(regvars) >= f.regvarqty:
            break

    globals_ = {}
    for i, offset in netnode.Netnode('$ wasm.offsets').get('globals', {}).items():
        globals_['$global' + i] = ida_name.get_name(offset)

    frame = {}
    if f.frame != idc.BADADDR:
        names = set([])
        for i in range(idc.GetStrucSize(f.frame)):
            name = idc.GetMemberName(f.frame, i)
            if not name:
                continue
            if name in names:
                continue
            frame[i] = name
            names.add(name)

    emu = Emulator(buf)
    emu.run()
    print(emu.render(ctx={
        'regvars': regvars,
        'frame': frame,
        'globals': globals_,
    }))