forked from extremecoders-re/bytecode_simplifier
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecoder.py
More file actions
Latest commit
31 lines (21 loc) · 802 Bytes
/
Copy pathdecoder.py
File metadata and controls
31 lines (21 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
importdis
frominstructionimportInstruction
classDecoder:
"""
Class to decode raw bytes into instruction.
"""
def__init__(self, insBytes):
self.insBytes=insBytes
defdecode_at(self, offset):
assertoffset<len(self.insBytes)
opcode=self.insBytes[offset]
ifopcode==dis.opmap['EXTENDED_ARG']:
raiseException('EXTENDED_ARG not yet implemented')
# Invalid instruction
ifopcodenotindis.opmap.values():
returnInstruction(-1, None, 1)
ifopcode<dis.HAVE_ARGUMENT:
returnInstruction(opcode, None, 1)
ifopcode>=dis.HAVE_ARGUMENT:
arg= (self.insBytes[offset+2] <<8) |self.insBytes[offset+1]
returnInstruction(opcode, arg, 3)