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

Pcode parser rewrite #425

Merged

Conversation

m-rtz
Copy link
Contributor

@m-rtz m-rtz commented Aug 25, 2023

Add translation for blocks from pcode into IR. Pcode relative jumps are considered and required splitting of blocks is implemented.

vandenBosch added 30 commits June 20, 2023 11:41
@m-rtz m-rtz requested a review from Enkelmann August 25, 2023 13:23
Copy link
Contributor

@Enkelmann Enkelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The function process_pcode_relative_jump needs to be refactored, because it is simply too long and that makes the function quite difficult to understand.
  • I did not review the unit test code, since this first review is already quite long. So review of the unit test code has to wait until the next review.

src/cwe_checker_lib/src/ghidra_pcode/mod.rs Outdated Show resolved Hide resolved
}
Some(JmpTarget::Relative(_)) => {
if instr.contains_relative_jump_to_next_instruction() {
jump_targets.insert(instructions.peek().expect("Relative jump to next instruction, but block as no next instruction.").get_u64_address());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This .expect(...) is problematic, because the case will happen in practice! For example, because the next instruction is already the start of a new block. So if peeking fails we should compute the next address from the current address. Either as instruction address + instruction size or by directly parsing the fallthrough address from Ghidra. We may have to add corresponding data to the stuff we parse from Ghidra if it is not already contained in the instruction data.

src/cwe_checker_lib/src/ghidra_pcode/mod.rs Outdated Show resolved Hide resolved

// Special case: Block ends without jump.
// If all instructions are processed and current block is not new, add to blocks.
// TODO: Add branch here?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this TODO I am not sure: Is this part of this PR or will it be handled in the next one? I would guess that it should be handled in this PR.

Comment on lines 355 to 356
// MIPS: Delay slots for C-Jumps. Ghidra verlegt Delay ggf vor, sodas fallthrough ggf. falsch? (alter code lookup)
panic!("Jump target address to consecutive instruction is not provided.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the long run we probably will have to remove this panic!(...) and generate a non-panicking log message instead. But if we want to keep the panic!(...) in the short term, the code comment should be a little bit more verbose and in english. Just to make sure that anyone reading the code can understand the issue here.

src/cwe_checker_lib/src/ghidra_pcode/mod.rs Outdated Show resolved Hide resolved
Comment on lines +28 to +35
// Pcode definition distinguishes between `location` and `offset`.
// Note: $(GHIDRA_PATH)/docs/languages/html/pcodedescription.html#cpui_branch
// Currently, the IR does not distinguishes these cases.
// We do nothing here.
match jmp_type {
BRANCH | CBRANCH | CALL => (), // case `location`
BRANCHIND | CALLIND | CALLOTHER | RETURN => (), // case `offset`
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks like it does nothing... ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I left it there for future logic to "guess" locations. This might be interesting for fixing indirect jump targets..., but it is a long shot.

@Enkelmann Enkelmann merged commit 6076926 into pcode_extracting_and_parsing_collection Sep 12, 2023
2 of 8 checks passed
@Enkelmann Enkelmann deleted the pcode_parser_rewrite branch September 12, 2023 08:48
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