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
6e902641
Commit
6e902641
authored
Sep 24, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
smart nopping of gcenable
parent
0f9a9c0b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
3 deletions
+20
-3
run.py
risc/run.py
+20
-3
No files found.
risc/run.py
View file @
6e902641
...
@@ -3,6 +3,7 @@ import os
...
@@ -3,6 +3,7 @@ import os
import
struct
import
struct
from
elftools.elf.elffile
import
ELFFile
from
elftools.elf.elffile
import
ELFFile
from
termcolor
import
colored
,
cprint
from
hexdump
import
hexdump
from
hexdump
import
hexdump
from
unicorn
import
*
from
unicorn
import
*
from
unicorn.mips_const
import
*
from
unicorn.mips_const
import
*
...
@@ -27,7 +28,14 @@ def hook_interrupt(uc, intno, user_data):
...
@@ -27,7 +28,14 @@ def hook_interrupt(uc, intno, user_data):
fd
=
uc
.
reg_read
(
UC_MIPS_REG_A0
)
fd
=
uc
.
reg_read
(
UC_MIPS_REG_A0
)
buf
=
uc
.
reg_read
(
UC_MIPS_REG_A1
)
buf
=
uc
.
reg_read
(
UC_MIPS_REG_A1
)
count
=
uc
.
reg_read
(
UC_MIPS_REG_A2
)
count
=
uc
.
reg_read
(
UC_MIPS_REG_A2
)
os
.
write
(
fd
,
uc
.
mem_read
(
buf
,
count
))
if
fd
==
1
:
# stdout
os
.
write
(
fd
,
colored
(
uc
.
mem_read
(
buf
,
count
)
.
decode
(
'utf-8'
),
'green'
)
.
encode
(
'utf-8'
))
elif
fd
==
2
:
# stderr
os
.
write
(
fd
,
colored
(
uc
.
mem_read
(
buf
,
count
)
.
decode
(
'utf-8'
),
'red'
)
.
encode
(
'utf-8'
))
else
:
os
.
write
(
fd
,
uc
.
mem_read
(
buf
,
count
))
uc
.
reg_write
(
UC_MIPS_REG_A3
,
0
)
uc
.
reg_write
(
UC_MIPS_REG_A3
,
0
)
return
True
return
True
...
@@ -127,6 +135,7 @@ def hook_code(uc, address, size, user_data):
...
@@ -127,6 +135,7 @@ def hook_code(uc, address, size, user_data):
raise
Exception
(
"ctrl-c"
)
raise
Exception
(
"ctrl-c"
)
elf
=
open
(
"test"
,
"rb"
)
elf
=
open
(
"test"
,
"rb"
)
#elf = open("go-ethereum", "rb")
data
=
elf
.
read
()
data
=
elf
.
read
()
elf
.
seek
(
0
)
elf
.
seek
(
0
)
...
@@ -159,8 +168,16 @@ mu.mem_write(SIZE-0x2000, struct.pack(">IIIIIIII", 1, SIZE-0x1000, 0, SIZE-0x100
...
@@ -159,8 +168,16 @@ mu.mem_write(SIZE-0x2000, struct.pack(">IIIIIIII", 1, SIZE-0x1000, 0, SIZE-0x100
# nop osinit
# nop osinit
#mu.mem_write(0x44524, b"\x03\xe0\x00\x08\x00\x00\x00\x00")
#mu.mem_write(0x44524, b"\x03\xe0\x00\x08\x00\x00\x00\x00")
# nop gcenable
for
section
in
elffile
.
iter_sections
():
mu
.
mem_write
(
0x29448
,
b
"
\x03\xe0\x00\x08\x00\x00\x00\x00
"
)
try
:
for
nsym
,
symbol
in
enumerate
(
section
.
iter_symbols
()):
if
symbol
.
name
==
"runtime.gcenable"
:
print
(
nsym
,
symbol
.
name
)
# nop gcenable
mu
.
mem_write
(
symbol
[
'st_value'
],
b
"
\x03\xe0\x00\x08\x00\x00\x00\x00
"
)
except
Exception
:
pass
#mu.hook_add(UC_HOOK_BLOCK, hook_code, user_data=mu)
#mu.hook_add(UC_HOOK_BLOCK, hook_code, user_data=mu)
#mu.hook_add(UC_HOOK_CODE, hook_code, user_data=mu)
#mu.hook_add(UC_HOOK_CODE, hook_code, user_data=mu)
...
...
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