Skip to content

Commit 24ae828

Browse files
committed
Adding files
1 parent 832a72e commit 24ae828

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

ch02/disassembly_example.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/python
2+
3+
import pefile
4+
from capstone import *
5+
6+
# load the target PE file
7+
pe = pefile.PE("IRCBot.exe")
8+
9+
# get the address of the program entry point from the program header
10+
entrypoint = pe.OPTIONAL_HEADER.AddressOfEntryPoint
11+
12+
# compute memory address where the entry code will be loaded into memory
13+
entrypoint_address = entrypoint+pe.OPTIONAL_HEADER.ImageBase
14+
15+
# get the binary code from the PE file object
16+
binary_code = pe.get_memory_mapped_image()[entrypoint:entrypoint+100]
17+
18+
# initialize disassembler to disassemble 32 bit x86 binary code
19+
disassembler = Cs(CS_ARCH_X86, CS_MODE_32)
20+
21+
# disassemble the code
22+
for instruction in disassembler.disasm(binary_code, entrypoint_address):
23+
print "%s\t%s" %(instruction.mnemonic, instruction.op_str)

ch02/ircbot.exe

243 KB
Binary file not shown.

0 commit comments

Comments
 (0)