Skip to content

Commit 4ba8c73

Browse files
authored
Move default symbol hooks to arch (#40)
1 parent 346c42f commit 4ba8c73

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

src/infernum/arch.py

+18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from unicorn import arm_const, arm64_const
2+
3+
from . import hooks
24
from .structs import Arch
35

46

@@ -17,6 +19,14 @@
1719
arm_const.UC_ARM_REG_R3,
1820
],
1921
reg_ret=arm_const.UC_ARM_REG_R0,
22+
symbol_hooks={
23+
"__ctype_get_mb_cur_max": hooks.simply_return(1),
24+
"malloc": hooks.hook_malloc,
25+
"free": hooks.hook_free,
26+
"getcwd": hooks.hook_getcwd,
27+
"getpid": hooks.hook_getpid,
28+
"gettid": hooks.hook_gettid,
29+
},
2030
)
2131

2232

@@ -39,4 +49,12 @@
3949
arm64_const.UC_ARM64_REG_X7,
4050
],
4151
reg_ret=arm64_const.UC_ARM64_REG_X0,
52+
symbol_hooks={
53+
**arch_arm.symbol_hooks,
54+
"arc4random": hooks.hook_arc4random,
55+
"clock_nanosleep": hooks.simply_return(0),
56+
"nanosleep": hooks.simply_return(0),
57+
"pthread_mutex_lock": hooks.simply_return(),
58+
"pthread_mutex_unlock": hooks.simply_return(),
59+
},
4260
)

src/infernum/core.py

+2-25
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
)
2222
from unicorn.unicorn import UC_HOOK_CODE_TYPE
2323

24-
from . import const, hooks
24+
from . import const
2525
from .arch import arch_arm, arch_arm64
2626
from .exceptions import EmulatorCrashedException, SymbolMissingException
2727
from .log import get_logger
@@ -113,30 +113,7 @@ def _create_cs(self) -> Cs:
113113

114114
def _init_symbol_hooks(self):
115115
"""Initialize default symbol hooks."""
116-
_hooks = {
117-
"__ctype_get_mb_cur_max": hooks.simply_return(1),
118-
"malloc": hooks.hook_malloc,
119-
"free": hooks.hook_free,
120-
"getcwd": hooks.hook_getcwd,
121-
"getpid": hooks.hook_getpid,
122-
"gettid": hooks.hook_gettid,
123-
}
124-
125-
if self.arch == arch_arm:
126-
_hooks.update({})
127-
128-
elif self.arch == arch_arm64:
129-
_hooks.update(
130-
{
131-
"arc4random": hooks.hook_arc4random,
132-
"clock_nanosleep": hooks.simply_return(0),
133-
"nanosleep": hooks.simply_return(0),
134-
"pthread_mutex_lock": hooks.simply_return(),
135-
"pthread_mutex_unlock": hooks.simply_return(),
136-
}
137-
)
138-
139-
self._symbol_hooks.update(_hooks)
116+
self._symbol_hooks.update(self.arch.symbol_hooks)
140117

141118
def _init_trap_memory(self):
142119
"""Initialize trap area memory."""

src/infernum/structs.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from dataclasses import dataclass
2-
from typing import List, Optional
2+
from typing import Dict, List, Optional
3+
4+
from unicorn.unicorn import UC_HOOK_CODE_TYPE
35

46

57
@dataclass
@@ -60,3 +62,5 @@ class Arch:
6062

6163
reg_args: List[int]
6264
reg_ret: int
65+
66+
symbol_hooks: Dict[str, UC_HOOK_CODE_TYPE]

0 commit comments

Comments
 (0)