-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
62 lines (47 loc) · 1.28 KB
/
util.py
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
50
51
52
53
54
55
56
57
58
59
60
61
import logging
import time
from pwn import *
import re
# pwntools log level
context.log_level = 'critical'
# ver 1.44
#Miscellaneous utility functions, variables
white_list = [[8, 'rax', 'rbx', 'rcx', 'rdx', 'rsi', 'rdi', 'rbp', 'rsp', 'rip', 'r8', 'r9', 'r10', 'r11', 'r12', 'r13', 'r14', 'r15'],
[4, 'eax', 'ebx', 'ecx', 'edx', 'esi', 'edi', 'ebp', 'esp', 'eip'],
[2, 'ax', 'bx', 'cx', 'dx'],
[1, 'al', 'bl', 'cl', 'dl',
'ah', 'bh', 'ch', 'dh']]
segment_reg = ['fs', 'gs', 'cs', 'ss', 'ds', 'es']
## 1.44, special length for Memory class
UNLIMITED_LENGTH = 0x10000
UNKNOWN_LENGTH = 0
DEFAULT_STRLEN = -1
## 1.5, Memory constant
NOT_CONTAIN = 0xf0
FULL_CONTAIN = 0xf1
TAILPART_CONTAIN = 0xf2
HEADPART_CONTAIN = 0xf3
# Instruction constant
CALL_INST = 0xe0
CONDITION_INST = 0xe1
REGULAR_INST = 0xe2
# Debugger constant
STEP_INTO = 0
STEP_OVER = 1
# TList constant
RETURN_THIS = 0xd0
RETURN_ROOT = 0xd1
# TAnalyzer constant
DEFAULT_FILE = 0xc0
CANARY_DETECT = 0xc1
NOT_32BIT_ELF = 0xc2
def is_memory(s):
if 'gs:' not in s:
return 'PTR' in s
return False
def is_address(s):
return (s[0] == '[' and s[-1] == ']') or is_segment_reg(s.split(':')[0])
def is_segment_reg(s):
return s in segment_reg
def is_register(s):
return sum((s in reg)*reg[0] for reg in white_list)