Skip to content

Commit f56c7c4

Browse files
committed
Fixed minor syntax error in fib example
1 parent 433e60d commit f56c7c4

File tree

3 files changed

+12
-27
lines changed

3 files changed

+12
-27
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*.pyd
1919
*.pyc
2020

21+
__pycache__
22+
2123
# Fortran module files
2224
*.mod
2325
*.smod

examples/long_mode_fibonacci.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import struct
1+
#
2+
# Example: Run in bochscpu Fibonacci sequence in long mode
3+
# Requires: keystone-engine, capstone
4+
#
5+
26
import time
37

48
import capstone
@@ -31,27 +35,6 @@ def dbg(x: str):
3135
print(f"[Py] {x}")
3236

3337

34-
def dump_page_table(addr: int, level: int = 0):
35-
level_str = ("PML", "PDPT", "PD", "PT")
36-
if level == 4:
37-
data = bytes(bochscpu.memory.phy_read(addr, 8))
38-
entry = struct.unpack("<Q", data[:8])[0] & ~0xFFF
39-
print(f"{' '*level} {entry:#x}")
40-
return
41-
42-
print(f"Dumping {level_str[level]} @ {addr:#x}")
43-
44-
for i in range(0, PAGE_SIZE, 8):
45-
data = bytes(bochscpu.memory.phy_read(addr + i, 8))
46-
entry = struct.unpack("<Q", data[:8])[0]
47-
flags = entry & 0xFFF
48-
entry = entry & ~0xFFF
49-
if entry == 0:
50-
continue
51-
print(f"{' '*level} #{i//8} - {hex(entry)}|{flags=:#x}")
52-
dump_page_table(entry, level + 1)
53-
54-
5538
def missing_page_cb(gpa):
5639
raise Exception(f"missing_page_cb({gpa=:#x})")
5740

@@ -136,10 +119,10 @@ def emulate(code: bytes):
136119
evaled_gpa = bochscpu.memory.virt_translate(pml4, stack_gva)
137120
assert evaled_gpa == stack_gpa, f"{evaled_gpa=:#x} != {stack_gpa=:#x}"
138121

139-
# dump_page_table(pml4)
122+
bochscpu.utils.dump_page_table(pml4)
140123

141124
dbg(f"copy code to {shellcode_gva=:#x}")
142-
assert bochscpu.memory.virt_write(pml4, shellcode_gva, bytes(code))
125+
assert bochscpu.memory.virt_write(pml4, shellcode_gva, bytearray(code))
143126
dbg(f"copied to {shellcode_gva=:#x}, testing...")
144127
data = bochscpu.memory.virt_read(pml4, shellcode_gva, len(code))
145128
assert data

examples/real_mode_print_hello.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ def phy_access_cb(sess, cpu_id, a2, a3, a4, a5):
3939

4040

4141
def reset_cb(sess, a1, a2):
42-
print(f"{a1=:} {a2=:}")
42+
logging.debug(f"{a1=:} {a2=:}")
4343

4444

4545
def interrupt_cb(sess, a1, a2):
46-
print(f"{a1=:} {a2=:}")
46+
logging.debug(f"{a1=:} {a2=:}")
4747

4848

4949
def hw_interrupt_cb(sess, a1, a2, a3, a4):
50-
print(f"{a1=:} {a2=:}")
50+
logging.debug(f"{a1=:} {a2=:}")
5151

5252

5353
def exception_cb(

0 commit comments

Comments
 (0)