Last active
December 23, 2019 14:27
-
-
Save Barakat/9e98eeffd16f95b8a60fe648220fa3da to your computer and use it in GitHub Desktop.
Detect if arch is x86 or x64
This file contains hidden or 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
#!python3 | |
# -*- coding: utf-8 -*- | |
# pip install unicorn | |
import unicorn | |
import unicorn.x86_const | |
def main(): | |
emulation_address = 0x08000000 | |
# | |
# unicorn.UC_MODE_64 (eax = 0): | |
# | |
# 0: 31 c0 xor eax,eax | |
# 2: 40 90 rex xchg eax,eax | |
# | |
# unicorn.UC_MODE_32 (eax = 1) | |
# | |
# 0: 31 c0 xor eax,eax | |
# 2: 40 inc eax | |
# 3: 90 nop | |
code = b'\x31\xc0\x40\x90' | |
emulator = unicorn.Uc(unicorn.UC_ARCH_X86, unicorn.UC_MODE_64) | |
emulator.mem_map(emulation_address, 4 * 1024) | |
emulator.mem_write(emulation_address, code) | |
emulator.emu_start(emulation_address, emulation_address + len(code)) | |
eax = emulator.reg_read(unicorn.x86_const.UC_X86_REG_EAX) | |
print(f'[!] eax value after emulation = {eax}') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment