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

Fix bug in rendering actual PC from NEXT_PC with thumb preffix/suffix instructions #661

Merged
merged 7 commits into from
Apr 5, 2023

Conversation

2over12
Copy link
Contributor

@2over12 2over12 commented Apr 4, 2023

Since we group preffix suffix instructions using the current instruction size to work out the mode was buggy

SleighAArch32ThumbDecoder::LiftPcFromCurrPc(llvm::IRBuilder<> &bldr,

instead this passes down the decoding context to figure out where PC should be

@2over12 2over12 changed the title Fixe bug in rendering actual PC from NEXT_PC with thumb preffix/suffix instructions Fix bug in rendering actual PC from NEXT_PC with thumb preffix/suffix instructions Apr 4, 2023
@2over12 2over12 marked this pull request as draft April 4, 2023 02:20
@2over12
Copy link
Contributor Author

2over12 commented Apr 4, 2023

There's an additional issue here in how we compute the patch expressions for sleigh files. We assume we can compute the address of inst_next given the value in PC, but we do it using inst_last, in reality regardless of the instruction size this should be -4 on thumb and -8 on arm which requires determining what mode, this will require another macro

@2over12
Copy link
Contributor Author

2over12 commented Apr 4, 2023

replacing all context reg references with a known constant is too naive, we need to just assign the entry value then lift the register like normal. A better way to do this is to allocate the local context reg as a pointer, store the assumed constant, then lift

@2over12 2over12 marked this pull request as ready for review April 4, 2023 22:38
@2over12 2over12 requested a review from Ninja3047 April 5, 2023 01:10
@2over12
Copy link
Contributor Author

2over12 commented Apr 5, 2023

Should really integrate TestLifting.cpp from ARM and PPC but Im pressed for time at the moment.

public:
ContextRegMappings(
std::unordered_map<std::string, std::string> context_reg_mapping,
std::unordered_map<std::string, size_t> vnode_size_mapping)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you put a comment somewhere that explains what vnode_size_mapping is for? looks like it's set maps to 1 for both ppc and thumb?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ill add a comment, it's just with the approach above we need to alloca some memory to store the context register, consequently we need to know the size ghidra expects for the register and we don't really have a way to get that

@2over12 2over12 merged commit db394b3 into master Apr 5, 2023
@2over12 2over12 deleted the ian/fix-lifted-pc-for-suffix-prefix-insns-in-thumb branch April 5, 2023 14:41
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