Skip to content

Commit 281d31d

Browse files
authored
Document Register API (#6)
* Document all the functions in register api * Fix examples in Zelos * Update gitignore with copied README in docs * Update syscall limiter plugin
1 parent e3bd251 commit 281d31d

5 files changed

Lines changed: 52 additions & 129 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ __pycache__/
5959
/docs/_build/
6060
/docs/api/
6161
/docs/log.txt
62+
/docs/README.md
6263

6364
# PyBuilder
6465
/target/

docs/README.md

Lines changed: 0 additions & 117 deletions
This file was deleted.

src/zelos/api/regs_api.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,54 @@ def __setattr__(self, attr, value):
5555
self._current_thread.set_reg(attr, value)
5656

5757
def getIP(self) -> int:
58+
"""
59+
Returns the platform-agnostic instruction pointer. On x86, this
60+
returns the value of the EIP register. On ARM, this returns the
61+
value of register R15. On MIPS, this returns the value of the
62+
PC register.
63+
"""
5864
return self._current_thread.getIP()
5965

6066
def setIP(self, new_ip: int) -> None:
67+
"""
68+
Sets the instruction pointer. On x86, this sets the value of the
69+
EIP register. On ARM, this sets the value of register R15. On
70+
MIPS this sets the value of the PC register.
71+
"""
6172
self._current_thread.setIP(new_ip)
6273

6374
def getSP(self) -> int:
75+
"""
76+
Returns the platform-agnostic stack pointer. On x86, this
77+
returns the value of the ESP register. On ARM, this returns the
78+
value of register R13. On MIPS, this returns the value of the
79+
SP register.
80+
"""
6481
return self._current_thread.getSP()
6582

6683
def setSP(self, new_sp: int) -> None:
84+
"""
85+
Sets the stack pointer. On x86, this sets the value of the
86+
ESP register. On ARM, this sets the value of register R13. On
87+
MIPS this sets the value of the SP register.
88+
"""
6789
self._current_thread.setSP(new_sp)
6890

6991
def getFP(self) -> int:
92+
"""
93+
Returns the platform-agnostic frame pointer. On x86, this
94+
returns the value of the EBP register. On ARM, this returns the
95+
value of register R11. On MIPS, this returns the value of
96+
register $30.
97+
"""
7098
return self._current_thread.getFP()
7199

72100
def setFP(self, new_fp: int) -> None:
101+
"""
102+
Sets the frame pointer. On x86, this sets the value of the
103+
EBP register. On ARM, this sets the value of register R11. On
104+
MIPS this sets the value of register $30.
105+
"""
73106
return self._current_thread.setFP(new_fp)
74107

75108
def getstack(self, offset: int) -> int:
@@ -87,7 +120,13 @@ def setstack(self, offset: int, val: int) -> None:
87120
self._current_thread.setstack(offset, val)
88121

89122
def popstack(self) -> int:
123+
"""
124+
Pop an item from the top of the stack.
125+
"""
90126
return self._current_thread.popstack()
91127

92128
def pushstack(self, data: int) -> None:
129+
"""
130+
Push an item to the top of the stack.
131+
"""
93132
return self._current_thread.pushstack(data)

src/zelos/api/zelos_api.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def hook_execution(
185185
def exec_hook(zelos, address, size):
186186
print(address)
187187
188-
z = ("binary_to_emulate")
188+
z = Zelos("binary_to_emulate")
189189
z.hook_execution(
190190
HookType.EXEC.BLOCK, exec_hook
191191
)
@@ -219,7 +219,7 @@ def hook_close(self, closure: Callable[[], Any]) -> HookInfo:
219219
def close_cleanup():
220220
file.close()
221221
222-
z = ("binary_to_emulate")
222+
z = Zelos("binary_to_emulate")
223223
z.hook_close(close_cleanup)
224224
z.start()
225225
@@ -258,7 +258,7 @@ def hook_syscalls(
258258
def syscall_hook(zelos, sys_name, args, ret_val):
259259
syscall_return_values.append((sys_name, ret_val))
260260
261-
z = ("binary_to_emulate")
261+
z = Zelos("binary_to_emulate")
262262
z.hook_syscalls(
263263
HookType.SYSCALL.AFTER, syscall_hook
264264
)
@@ -289,7 +289,7 @@ def start(self, timeout: float = 0) -> None:
289289
290290
from zelos import Zelos
291291
292-
z = ("binary_to_emulate")
292+
z = Zelos("binary_to_emulate")
293293
294294
# Start execution from the entry point
295295
z.start()
@@ -365,7 +365,7 @@ def set_breakpoint(self, address: int, temporary: bool = False):
365365
366366
from zelos import Zelos
367367
368-
z = ("binary_to_emulate")
368+
z = Zelos("binary_to_emulate")
369369
370370
z.set_breakpoint(0xdeadbeef)
371371
@@ -401,7 +401,7 @@ def remove_breakpoint(self, address: int):
401401
402402
from zelos import Zelos
403403
404-
z = ("binary_to_emulate")
404+
z = Zelos("binary_to_emulate")
405405
406406
z.set_breakpoint(0xdeadbeef)
407407
@@ -425,7 +425,7 @@ def set_syscall_breakpoint(self, syscall_name: str):
425425
426426
from zelos import Zelos
427427
428-
z = ("binary_to_emulate")
428+
z = Zelos("binary_to_emulate")
429429
430430
z.set_syscall_breakpoint("write")
431431
@@ -446,7 +446,7 @@ def remove_syscall_breakpoint(self, syscall_name: str):
446446
447447
from zelos import Zelos
448448
449-
z = ("binary_to_emulate")
449+
z = Zelos("binary_to_emulate")
450450
451451
z.set_syscall_breakpoint("write")
452452
@@ -477,7 +477,7 @@ def set_watchpoint(
477477
478478
from zelos import Zelos
479479
480-
z = ("binary_to_emulate")
480+
z = Zelos("binary_to_emulate")
481481
482482
# Break at any read or write to memory address 0xdeadbeef
483483
z.set_watchpoint(0xdeadbeef, True, True)
@@ -530,7 +530,7 @@ def remove_watchpoint(self, address: int):
530530
531531
from zelos import Zelos
532532
533-
z = ("binary_to_emulate")
533+
z = Zelos("binary_to_emulate")
534534
535535
z.set_watchpoint(0xdeadbeef, True, True)
536536
@@ -574,7 +574,7 @@ def date(self, date_str: str):
574574
575575
from zelos import Zelos
576576
577-
z = ("binary_to_emulate")
577+
z = Zelos("binary_to_emulate")
578578
579579
z.date = "2020-03-04"
580580

src/zelos/ext/plugins/syscall_limiter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _syscall_callback(self, zelos, sysname, args, retval):
6262
if zelos.thread is None:
6363
return
6464

65-
thread_name = zelos.internal_engine.current_thread.name
65+
thread_name = zelos.thread.name
6666

6767
self.syscall_cnt += 1
6868
self.syscall_thread_cnt[thread_name] += 1

0 commit comments

Comments
 (0)