A fork of Unicorn Engine 2 that adds the AArch64 user-mode fidelity the unidbg unicorn2 backend relies on.
This branch tracks zhkl0228/unicorn
branch unicorn2 (itself a fork of unicorn-engine/unicorn).
It is maintained as the engine behind unidbg's optional unicorn2 backend, and
is published separately so that the backend can clone just this engine instead
of vendoring the full QEMU/Unicorn source tree. Everything else is unchanged
upstream Unicorn; the original project README is preserved in full below.
The base unicorn2 branch leaves several pieces of ARM64 user-mode behaviour to
the embedder. When unidbg runs an Android native library, code inside the guest
can observe where the emulator diverges from a real ARM64 device. This fork
closes those gaps so the guest sees the same architectural and kernel behaviour
it would on hardware. Each change is a self-contained commit, tagged in the
source with a unidbg: comment that states what it does.
- EL0 privilege boundary. System instructions (
MRS/MSR/SYS/SYSL) reach the embedder's hook over the whole encoding space, includingMSRwith an immediate. The translation block ends after a hooked system instruction.ERET,HVCandSMCare undefined at EL0, as isLDPwith the same destination register twice. - Pointer authentication. Key setup through
uc_arm64_cp_reg, withFEAT_FPACfaults gated on the selected CPU model. - SVE. Usable at every vector length the model reports, rather than the empty vector-length map the base branch leaves behind.
- Instruction counting and limits.
uc_ctlcan read the number of guest instructions executed sinceuc_open, and stop emulation before the block that would pass a given limit. Blocks are translated with the check only while a limit is in use, so there is no cost otherwise. - Precise memory faults. Emulation stops at the faulting access with the guest state restored, instead of at the start of the block.
- Translation cache coherence. Cached translations are dropped when the
host writes to executable memory, when a region is unmapped, when a region
loses execute permission, and when a code, block or memory hook is added.
mprotectapplies to cached translations and TLB entries. - MinGW heap corruption fix.
qemu_vfreereleases memory the wayqemu_memalignallocated it (port of upstreama5fa5480).
New uc_ctl control values are placed at 0x7f00 and above, away from the
upstream enumeration, so that values added upstream do not collide with them.
Clone this branch and build the static library the same way as upstream Unicorn (see the original README's build instructions below):
git clone -b unidbg https://github.com/GitKittys/unicorn-kitty ~/git/unicornThis engine is consumed by the unidbg unicorn2 backend, whose build script
clones the branch above and links the resulting libunicorn static library. The
build steps for each target platform (macOS, Linux, Windows) are described in
backend/unicorn2/README.md
in the unidbg repository. The C API is the upstream Unicorn 2 API plus the
uc_ctl instruction-count controls noted above; see the original documentation
below for the base API.
This fork exists to serve the unidbg unicorn2 backend; changes here are driven
by that backend's needs. For the engine itself, upstream
unicorn-engine/unicorn and
zhkl0228/unicorn are the primary projects.
Issues and pull requests specific to the unidbg fidelity changes are welcome on
this repository.
GPL-2.0, the same as upstream Unicorn Engine. State the license owner per the original project; see COPYING for the full text.
The original Unicorn Engine README follows.
Unicorn is a lightweight, multi-platform, multi-architecture CPU emulator framework, based on QEMU.
Unicorn offers some unparalleled features:
- Multi-architecture: ARM, ARM64 (ARMv8), M68K, MIPS, PowerPC, RISCV, SPARC, S390X, TriCore and X86 (16, 32, 64-bit)
- Clean/simple/lightweight/intuitive architecture-neutral API
- Implemented in pure C language, with bindings for Crystal, Clojure, Visual Basic, Perl, Rust, Ruby, Python, Java, .NET, Go, Delphi/Free Pascal, Haskell, Pharo, and Lua.
- Native support for Windows & *nix (with Mac OSX, Linux, Android, *BSD & Solaris confirmed)
- High performance via Just-In-Time compilation
- Support for fine-grained instrumentation at various levels
- Thread-safety by design
- Distributed under free software license GPLv2
Further information is available at http://www.unicorn-engine.org
This project is released under the GPL license.
See docs/COMPILE.md file for how to compile and install Unicorn.
More documentation is available in docs/README.md.
Contact us via mailing list, email or twitter for any questions.
If you want to contribute, please pick up something from our Github issues.
We also maintain a list of more challenged problems in milestones for our regular release.
CREDITS.TXT records important contributors of our project.
