Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
014c8671
Commit
014c8671
authored
Sep 24, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up heap
parent
e0c8a8bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
10 deletions
+30
-10
run.py
risc/run.py
+30
-10
No files found.
risc/run.py
View file @
014c8671
...
...
@@ -15,8 +15,8 @@ regs = ["at", "v0", "v1", "a0", "a1", "a2", "a3"]
SIZE
=
16
*
1024
*
1024
# 0x4
0000000
heap_start
=
1024
*
1024
*
1024
heap_start
=
0x20000000
# 0x20000000-0x3
0000000
brk_start
=
0x40000000
# 0x40000000-0x80000000
tfd
=
10
files
=
{}
...
...
@@ -27,6 +27,7 @@ def hook_interrupt(uc, intno, user_data):
if
intno
==
17
:
syscall_no
=
uc
.
reg_read
(
UC_MIPS_REG_V0
)
uc
.
reg_write
(
UC_MIPS_REG_V0
,
0
)
uc
.
reg_write
(
UC_MIPS_REG_A3
,
0
)
if
syscall_no
==
4004
:
# write
fd
=
uc
.
reg_read
(
UC_MIPS_REG_A0
)
...
...
@@ -49,20 +50,41 @@ def hook_interrupt(uc, intno, user_data):
elif
syscall_no
==
4194
:
# rt_sigaction
return
elif
syscall_no
==
4195
:
# rt_sigprocmask
return
elif
syscall_no
==
4055
:
# fcntl
return
elif
syscall_no
==
4220
:
# fcntl64
return
elif
syscall_no
==
4249
:
# epoll_ctl
return
elif
syscall_no
==
4263
:
# clock_gettime
return
elif
syscall_no
==
4326
:
# epoll_create1
return
elif
syscall_no
==
4328
:
# pipe2
return
elif
syscall_no
==
4206
:
# sigaltstack
return
elif
syscall_no
==
4222
:
# gettid
return
if
syscall_no
==
4005
:
filename
=
uc
.
reg_read
(
UC_MIPS_REG_A0
)
print
(
'open("
%
s")'
%
uc
.
mem_read
(
filename
,
0x100
)
.
split
(
b
"
\x00
"
)[
0
]
.
decode
(
'utf-8'
))
uc
.
reg_write
(
UC_MIPS_REG_V0
,
4
)
elif
syscall_no
==
4045
:
print
(
"brk"
,
hex
(
brk_start
))
uc
.
reg_write
(
UC_MIPS_REG_V0
,
brk_start
)
elif
syscall_no
==
4288
:
dfd
=
uc
.
reg_read
(
UC_MIPS_REG_A0
)
filename
=
uc
.
reg_read
(
UC_MIPS_REG_A1
)
...
...
@@ -91,7 +113,7 @@ def hook_interrupt(uc, intno, user_data):
elif
syscall_no
==
4006
:
fd
=
uc
.
reg_read
(
UC_MIPS_REG_A0
)
if
fd
>=
10
:
print
(
"close(
%
d)"
%
fd
)
#
print("close(%d)" % fd)
files
[
fd
]
.
close
()
del
files
[
fd
]
uc
.
reg_write
(
UC_MIPS_REG_V0
,
0
)
...
...
@@ -101,7 +123,7 @@ def hook_interrupt(uc, intno, user_data):
count
=
uc
.
reg_read
(
UC_MIPS_REG_A2
)
# changing this works if we want smaller oracle
#count = 4
print
(
"read"
,
fd
,
hex
(
buf
),
count
)
#
print("read", fd, hex(buf), count)
if
fd
==
4
:
val
=
b
"2097152
\n
"
uc
.
mem_write
(
buf
,
val
)
...
...
@@ -135,7 +157,6 @@ def hook_interrupt(uc, intno, user_data):
for
i
,
r
in
zip
(
mregs
,
regs
):
jj
+=
"
%
s:
%8
x "
%
(
r
,
uc
.
reg_read
(
i
))
print
(
''
.
join
(
jj
))
uc
.
reg_write
(
UC_MIPS_REG_A3
,
0
)
return
True
print
(
"interrupt"
,
intno
,
hex
(
pc
))
...
...
@@ -182,13 +203,12 @@ elf.seek(0)
# program memory (16 MB)
mu
.
mem_map
(
0
,
SIZE
)
# extra memory (16 MB) @ 0x1000000
# TODO: why do we need this?
mu
.
mem_map
(
SIZE
,
SIZE
)
# heap (256 MB) @ 0x40000000
# heap (256 MB) @ 0x20000000
mu
.
mem_map
(
heap_start
,
256
*
1024
*
1024
)
# brk (1024 MB) @ 0x40000000
mu
.
mem_map
(
brk_start
,
1024
*
1024
*
1024
)
# regs at 0xC0000000 in merkle
elffile
=
ELFFile
(
elf
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment