Python keystone.KS_MODE_32 Examples

The following are 2 code examples of keystone.KS_MODE_32(). 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 keystone , or try the search function .
Example #1
Source File: DBGHider.py    From DBGHider with Apache License 2.0 5 votes vote down vote up
def assemble(code, addr = 0, mode = keystone.KS_MODE_32):
    """
    assemble asm code for inline hook
    """

    ks = keystone.Ks(keystone.KS_ARCH_X86, mode)
    encoding, count = ks.asm(code, addr)
    buf = ''.join(chr(c) for c in encoding)
    return buf, count 
Example #2
Source File: pe.py    From crave with GNU General Public License v3.0 5 votes vote down vote up
def patch_code(self, instructions='ret;',va=0):
        """ put instruction(s), at the end of the basic block specified"""
        #TODO: get capstone instruction at the end of the basic_block
        try:
            k = ks.Ks(ks.KS_ARCH_X86, ks.KS_MODE_32)
            encoding, count = k.asm(instructions, va+self.OPTIONAL_HEADER.ImageBase)
        except ks.KsError as e:
            l.error("Error! %s", e)
            raise

        if not self.set_bytes_at_rva(va, ''.join(map(chr, encoding))):
            raise Exception('Cannot patch bytes at %x!', va)