Created
November 24, 2017 14:03
-
-
Save Eterna1/925b5dada30d9605f01f4f8756984fe8 to your computer and use it in GitHub Desktop.
zadanie3.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = 0x08048000 | |
STACK_ADDR = 0x0 | |
STACK_SIZE = 1024*1024 | |
mu = Uc (UC_ARCH_X86, UC_MODE_32) | |
mu.mem_map(BASE, 1024*1024) | |
mu.mem_map(STACK_ADDR, STACK_SIZE) | |
mu.mem_write(BASE, read("./function")) | |
r_esp = STACK_ADDR + (STACK_SIZE/2) | |
STRING_ADDR = 0x0 | |
mu.mem_write(STRING_ADDR, "zegnam\x00") | |
mu.reg_write(UC_X86_REG_ESP, r_esp) | |
mu.mem_write(r_esp+4, p32(5)) | |
mu.mem_write(r_esp+8, p32(STRING_ADDR)) | |
mu.emu_start(0x08048464, 0x0804849A) | |
r_eax = mu.reg_read(UC_X86_REG_EAX) | |
print r_eax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment