-
Notifications
You must be signed in to change notification settings - Fork 744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fuzz stm32f407_hacklock example #1108
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good example has to be minimalistic [to avoid confusion] and descriptive [to let people learn from it]. Please comment the example as much as you can and clean up residuals or unnecessary code.
from qiling.arch.arm import QlArchARM | ||
|
||
|
||
def watch(ql:Qiling): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage of this function is commented out.
Consider commenting out the function as well, or remove it altogether.
|
||
def watch(ql:Qiling): | ||
r0 = hex(ql.arch.regs.read('r0')) | ||
if r0 != '0x0': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why comparing strings when you can compare integers..?
ql.emu_stop() | ||
|
||
def fuzz_cb(ql:Qiling): | ||
if isinstance(ql.arch, QlArchARM): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use ql.ostype
to determine this, or just hasattr(ql.arch, 'effective_pc')
if you want to avoid the extra import
.
ql.hw.create('usart1') | ||
ql.hw.create('rcc') | ||
|
||
# ql.hw.show_info() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary leftovers to keep the example as clear as possible.
# ql.hw.show_info() | ||
# ql.hook_address(watch, 0x08003232) | ||
|
||
ql.patch(0x8000238, b'\x00\xBF' * 4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is that..? What are we patching here and why?
Comments are critical for users to understand the example.
|
||
def disasm(count, ql, address, size): | ||
buf = ql.mem.read(address, size) | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary try
/ exept
.
There is nothing to catch here really.
buf = ql.mem.read(address, size) | ||
try: | ||
for i in md.disasm(buf, address): | ||
return "{:08X}\t{:08X}: {:24s} {:10s} {:16s}".format(count[0], i.address, spaced_hex(buf), i.mnemonic, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loop doesn't make much sense if you return
unconditionally.
Perhaps you mean yield
..?
rtn = '{:100s}'.format(disasm(count, ql, address, size)) | ||
print(rtn) | ||
count[0] += 1 | ||
# pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean up here too
# ql.run(end=0x8003236, count=-1) | ||
ql.run(end=0x080031DC) | ||
|
||
exits = [0x08003270, 0x08003222] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments?
No idea what this is about.
@elicn This example is an experimental test yet and depending on some unpublished interface, converting it to draft for now. |
Checklist
Which kind of PR do you create?
Coding convention?
Extra tests?
Changelog?
Target branch?
One last thing