Skip to content
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

Parsing fixes for riscv64: lui, loads #285

Merged
merged 1 commit into from
Apr 22, 2023

Conversation

strlcat
Copy link
Contributor

@strlcat strlcat commented Apr 21, 2023

lui decompilation is wrong:

  • original produces "a0 = 0x429a000; return;" for "lui a0, 0x17050; ret", but shall produce "a0 = 0x17050000; return;"
  • Note that lui followed by addi is correct and is unaffected.

l{d,w,h,b}[u] decompilation is wrong:

  • original produces "ra = *((sp + 0x40));" for "ld ra, 40(sp)" (note that '40' decimal is simply left unaffected and gets substituted to '0x40' in result, giving impression that this is now correct hex value), but shall produce "ra = *((sp + 0x28));". This affects all load insns of all types.
  • Note that store insns are unaffected by this bug.

lui decompilation is wrong:
* original produces "a0 = 0x429a000; return;" for "lui a0, 0x17050; ret", but shall produce "a0 = 0x17050000; return;"
* Note that lui followed by addi is correct and is unaffected.

l{d,w,h,b}[u] decompilation is wrong:
* original produces "ra = *((sp + 0x40));" for "ld ra, 40(sp)"
(note that '40' decimal is simply left unaffected and gets substituted to '0x40' in result,
giving impression that this is now correct hex value), but shall produce "ra = *((sp + 0x28));".
This affects all load insns of all types.
* Note that store insns are unaffected by this bug.
@strlcat
Copy link
Contributor Author

strlcat commented Apr 21, 2023

Please note that these are quick & dirty fixes by person inexperienced with js, to make it work and be less annoying when decompilation & translation process goes.

@wargio
Copy link
Owner

wargio commented Apr 21, 2023

do you have a test? you can generate it using pddi

@strlcat
Copy link
Contributor Author

strlcat commented Apr 21, 2023

do you have a test? you can generate it using pddi

This generates a really long single line, potentially with sensitive data included about my project. How shall I proceed?
The machine it runs on is same as reversed binary, i.e. riscv64.

@strlcat
Copy link
Contributor Author

strlcat commented Apr 21, 2023

I generated one for random riscv64 binary on my system here: https://rys.strlcat.eu/pddi.json.xz

@wargio
Copy link
Owner

wargio commented Apr 22, 2023

I generated one for random riscv64 binary on my system here: https://rys.strlcat.eu/pddi.json.xz

i get a 403. can you just upload it here?

@wargio wargio merged commit 8624d3f into wargio:master Apr 22, 2023
wargio added a commit to rizinorg/jsdec that referenced this pull request Apr 22, 2023
wargio added a commit to rizinorg/jsdec that referenced this pull request Apr 22, 2023
@strlcat strlcat deleted the PR_riscv_fixes_lui_loads branch April 22, 2023 17:34
@strlcat
Copy link
Contributor Author

strlcat commented Apr 28, 2023

There's still problem with construct like:

lui a4, 0x80010
sw a4, 8(s0)

gives me

a4 = 0x0;
*((s0 + 0x8)) = a4;

but shall be

a4 = 0x80010000;
*((s0 + 0x8)) = a4;

(if assuming uint32_t, I don't know how typing here works, for uint64_t it shall produce 0xffffffff80010000)
I don't know how to solve it right now, so notifying you.

@wargio
Copy link
Owner

wargio commented Apr 28, 2023

true. the sign should extend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants