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

Suppressing UC_ERR_EXCEPTION when invalid instruction is handled in hook UC_HOOK_INSN_INVALID #2098

Open
HclX opened this issue Feb 10, 2025 · 4 comments

Comments

@HclX
Copy link

HclX commented Feb 10, 2025

Hi,
I'm emulating some ARM firmware code and noticed that unicorn can not emulate 'msr' or 'mrs' and other 'platform specific' instructions. My solution is to use hook UC_HOOK_INSN_INVALID, and inside of the hook function, I manually emulate the behavior of these instructions, and adjust pc to skip them. However, even if I return "true" from the hook function, the emulation still throws UC_ERR_EXCEPTION. Is there a way to avoid execution flow interruption because of this?

I'm using unicorn-2.1.1 with python binding.

@wtdcode
Copy link
Member

wtdcode commented Feb 10, 2025

#2047

@gerph
Copy link
Contributor

gerph commented Feb 11, 2025

I'm emulating some ARM firmware code and noticed that unicorn can not emulate 'msr' or 'mrs' and other 'platform specific' instructions.

The MSR and MRS instructions are supported by the Unicorn emulation. MRC and MCR have more spotty support for the different combinations, but the status to register (and vice-versa) instructions are supported. If you are seeing that they're not supported in your code, please ensure that you are in a privileged mode (which is how most firmware will probably be executed). Only a subset of the MSR/MRS operations are supported when you are in USR mode.

Whilst you may still need the fixes mentioned in the prior reply for other platform specific operations, you should be able to use those two instructions without any special emulation needed (unless, of course, you want to intentionally hook them to change their behaviour of course).

@HclX
Copy link
Author

HclX commented Feb 11, 2025

"The MSR and MRS instructions are supported by the Unicorn emulation" interesting as this is not what I'm seeing. In my case the instructions are something like "MSR r0, BASEPRI" -- maybe this register itself is not supported?

@gerph
Copy link
Contributor

gerph commented Feb 11, 2025

Ah, sorry, I thought you were meaning the standard interpretation of those instructions to manipulate just the PSR. My apologies.

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

No branches or pull requests

3 participants