question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RISC-V: Cannot invoke Varnode.getAddress because the return value of VariableStorage.getFirstVarnode is null

See original GitHub issue

Describe the bug I’m reverse engineering rv32imafc binary, and for some functions, decompiler shows this error:

  Cannot invoke "ghidra.program.model.pcode.Varnode.getAddress()" because the return value of
       "ghidra.program.model.listing.VariableStorage.getFirstVarnode()" is null

To Reproduce Steps to reproduce the behavior:

  1. Open firmware.bin attached, select RV32IMC language, and set base address to 0x23000000
  2. Go to 0x23000dae and check decompile panel
  3. (Optional) Go to similar function (but smaller) at 0x23000d68, this decompiles nicely.

Expected behavior Decompiler should be able to decompile the function.

Screenshots Stacktrace: image

Attachments firmware.bin.zip

(In show log, there wasn’t anything useful)

Environment

  • OS: Linux 6.0.8
  • Java Version: 19.0.1
  • Ghidra Version: 10.2.2 DEV 2022-Nov-15 2224 CET
  • Ghidra Origin: ArchLinux Packages

Additional context Let me know if any other information will be needed. Thanks

Issue Analytics

  • State:open
  • Created 10 months ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gamelastercommented, Nov 26, 2022

Hi @mumbel , thanks for all the help. (For anyone struggling with this) Since I applied mumbel’s recommendation, I got memory reads on memory areas, which didn’t gave any sense, generally having GP at 0x1F0164F0 didn’t gave any sense in context of real MCU memory map. After a bit thinking, I find out, this GP is wrong.

The first instruction is AUIPC, which add upper immediate to PC. This instruction adds a 20-bit immediate value to the upper 20 bits of the program counter and set it to register. This means for:

  • 23000000 97 61 01 1f auipc gp,0x1f016: 0x23000000 + (0x1F016 << 12) = 0x42016000
  • 23000004 93 81 01 4f addi gp,gp,0x4f0: 0x42016000 + 0x4F0 = 0x420164F0

So correct GP is 0x420164F0.

1reaction
mumbelcommented, Nov 25, 2022

You might be able to close the code browser and right click firmware.bin in the frontend window and “choose language” (I think, AFK now) and see if it lets yous choose a new language.

Id leave open for now just track if there’s something that could be fixed for gp detection

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · NationalSecurityAgency/ghidra - GitHub
RISC-V : Cannot invoke Varnode.getAddress because the return value of VariableStorage.getFirstVarnode is null Status: Internal This is being ...
Read more >
cannot invoke org.springframework.web.servlet.mvc.condition ...
NationalSecurityAgency/ghidraRISC-V: Cannot invoke Varnode.getAddress because the return value of VariableStorage.getFirstVarnode is null#4770.
Read more >
CS61C Discussion 3 – RISC-V
Write a function power in RISC-V that takes in two numbers x and n, and returns xn. You may assume that n ≥...
Read more >
RISC-V recursive function debugging - Stack Overflow
On a machine where the return address linkage is done in a register (RISC V, MIPS, ARM), a nested call done without having...
Read more >
ghidra - bytemeta
RISC-V : Cannot invoke Varnode.getAddress because the return value of VariableStorage.getFirstVarnode is null. KooShnoo.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found