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
b88ce129
Commit
b88ce129
authored
Sep 24, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
failing at clone
parent
94ca24b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
5 deletions
+20
-5
run.py
risc/run.py
+20
-5
No files found.
risc/run.py
View file @
b88ce129
...
...
@@ -12,6 +12,7 @@ mu = Uc(UC_ARCH_MIPS, UC_MODE_32 + UC_MODE_BIG_ENDIAN)
mregs
=
[
UC_MIPS_REG_AT
,
UC_MIPS_REG_V0
,
UC_MIPS_REG_V1
,
UC_MIPS_REG_A0
,
UC_MIPS_REG_A1
,
UC_MIPS_REG_A2
,
UC_MIPS_REG_A3
]
regs
=
[
"at"
,
"v0"
,
"v1"
,
"a0"
,
"a1"
,
"a2"
,
"a3"
]
SIZE
=
16
*
1024
*
1024
heap_start
=
16
*
1024
*
1024
def
hook_interrupt
(
uc
,
intno
,
user_data
):
...
...
@@ -19,7 +20,6 @@ def hook_interrupt(uc, intno, user_data):
pc
=
uc
.
reg_read
(
UC_MIPS_REG_PC
)
if
intno
==
17
:
syscall_no
=
uc
.
reg_read
(
UC_MIPS_REG_V0
)
uc
.
reg_write
(
UC_MIPS_REG_A3
,
0
)
uc
.
reg_write
(
UC_MIPS_REG_V0
,
0
)
if
syscall_no
==
4004
:
# write
...
...
@@ -27,6 +27,7 @@ def hook_interrupt(uc, intno, user_data):
buf
=
uc
.
reg_read
(
UC_MIPS_REG_A1
)
count
=
uc
.
reg_read
(
UC_MIPS_REG_A2
)
os
.
write
(
fd
,
uc
.
mem_read
(
buf
,
count
))
uc
.
reg_write
(
UC_MIPS_REG_A3
,
0
)
return
True
print
(
"syscall"
,
syscall_no
,
hex
(
pc
))
...
...
@@ -35,6 +36,14 @@ def hook_interrupt(uc, intno, user_data):
print
(
'open("
%
s")'
%
uc
.
mem_read
(
filename
,
0x100
)
.
split
(
b
"
\x00
"
)[
0
]
.
decode
(
'utf-8'
))
# open fd=4
uc
.
reg_write
(
UC_MIPS_REG_V0
,
4
)
elif
syscall_no
==
4120
:
print
(
"clone not supported"
)
uc
.
reg_write
(
UC_MIPS_REG_V0
,
-
1
)
uc
.
reg_write
(
UC_MIPS_REG_A3
,
0
)
return
True
elif
syscall_no
==
4263
:
print
(
"clock gettime"
)
#raise Exception
elif
syscall_no
==
4003
:
fd
=
uc
.
reg_read
(
UC_MIPS_REG_A0
)
buf
=
uc
.
reg_read
(
UC_MIPS_REG_A1
)
...
...
@@ -42,16 +51,22 @@ def hook_interrupt(uc, intno, user_data):
print
(
"read"
,
fd
,
hex
(
buf
),
count
)
uc
.
mem_write
(
buf
,
b
"16384
\n\x00
"
)
uc
.
reg_write
(
UC_MIPS_REG_V0
,
6
)
elif
syscall_no
==
4246
:
print
(
"EXIT"
)
return
False
elif
syscall_no
==
4090
:
a0
=
uc
.
reg_read
(
UC_MIPS_REG_A0
)
a1
=
uc
.
reg_read
(
UC_MIPS_REG_A1
)
a2
=
uc
.
reg_read
(
UC_MIPS_REG_A2
)
print
(
"mmap"
,
hex
(
a0
),
hex
(
a1
),
hex
(
a2
),
"at"
,
hex
(
heap_start
))
a3
=
uc
.
reg_read
(
UC_MIPS_REG_A3
)
a4
=
uc
.
reg_read
(
UC_MIPS_REG_T0
)
a5
=
uc
.
reg_read
(
UC_MIPS_REG_T1
)
print
(
"mmap"
,
hex
(
a0
),
hex
(
a1
),
hex
(
a2
),
hex
(
a3
),
hex
(
a4
),
hex
(
a5
),
"at"
,
hex
(
heap_start
))
if
a0
==
0
:
print
(
"malloced new"
)
#mu.mem_map(heap_start, a1)
heap_start
+=
a1
uc
.
reg_write
(
UC_MIPS_REG_V0
,
heap_start
)
heap_start
+=
a1
else
:
uc
.
reg_write
(
UC_MIPS_REG_V0
,
a0
)
...
...
@@ -60,6 +75,7 @@ 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
))
...
...
@@ -102,11 +118,10 @@ elf.seek(0)
#rte = data.find(b"\x08\x02\x2c\x95")
#print(hex(rte))
SIZE
=
16
*
1024
*
1024
mu
.
mem_map
(
0
,
SIZE
)
# heap
mu
.
mem_map
(
SIZE
,
0x10000000
)
mu
.
mem_map
(
heap_start
,
0x10000000
)
elffile
=
ELFFile
(
elf
)
for
seg
in
elffile
.
iter_segments
():
...
...
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