-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex_idphook_asm.py
More file actions
49 lines (40 loc) · 1.37 KB
/
ex_idphook_asm.py
File metadata and controls
49 lines (40 loc) · 1.37 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from __future__ import print_function
import idaapi
import idautils
"""
This is a sample script for extending the assemble() hook.
We add support for assembling the following pseudo instructions:
- "zero eax" -> xor eax, eax
- "nothing" -> nop
(c) Hex-Rays
"""
#--------------------------------------------------------------------------
class assemble_idp_hook_t(idaapi.IDP_Hooks):
def __init__(self):
idaapi.IDP_Hooks.__init__(self)
def assemble(self, ea, cs, ip, use32, line):
line = line.strip()
if line == "xor eax, eax":
return "\x33\xC0"
elif line == "nop":
# Decode current instruction to figure out its size
cmd = idautils.DecodeInstruction(ea)
if cmd:
# NOP all the instruction bytes
return "\x90" * cmd.size
return None
#---------------------------------------------------------------------
# Remove an existing hook on second run
try:
idp_hook_stat = "un"
print("IDP hook: checking for hook...")
idphook
print("IDP hook: unhooking....")
idphook.unhook()
del idphook
except:
print("IDP hook: not installed, installing now....")
idp_hook_stat = ""
idphook = assemble_idp_hook_t()
idphook.hook()
print("IDP hook %sinstalled. Run the script again to %sinstall" % (idp_hook_stat, idp_hook_stat))