Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trietptm/7639e98988d6405effbe2bfe6d435fc4 to your computer and use it in GitHub Desktop.
Save trietptm/7639e98988d6405effbe2bfe6d435fc4 to your computer and use it in GitHub Desktop.
zad2_szablon.py
from unicorn import *
from unicorn.x86_const import *
import struct
def read(name):
with open(name) as f:
return f.read()
def u32(data): #zamien ciag 4 bajtow na liczbe w formacie little-endian
return struct.unpack("I", data)[0]
def p32(num): #zamien liczbe w formacie little-endian na ciag 4 bajtow
return struct.pack("I", num)
BASE = 0x0000000000400000
STACK_ADDR = 0x0
STACK_SIZE = 1024*1024
mu = Uc (UC_ARCH_X86, UC_MODE_64)
mu.mem_map(BASE, 1024*1024)
mu.mem_map(STACK_ADDR, STACK_SIZE)
mu.mem_write(BASE, "\x31\xd2\x52\xb8\xb7\xd8\x3e\x56\x05\x78\x56\x34\x12\x50\xb8\xde\xc0\xad\xde\x2d\xaf\x5e\x44\x70\x50\x6a\x0b\x58\x89\xd1\x89\xe3\x6a\x01\x5e\xcd\x80\x96\xcd\x80")
mu.reg_write(UC_X86_REG_RSP, STACK_ADDR + STACK_SIZE - 1)
def hook_code(uc, address, size, user_data):
#print('>>> Tracing instruction at 0x%x, instruction size = 0x%x' %(address, size))
mu.hook_add(UC_HOOK_CODE, hook_code)
mu.emu_start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment