import Unicorn2

This commit is contained in:
Nguyen Anh Quynh
2021-10-03 22:14:44 +08:00
parent 772558119a
commit aaaea14214
837 changed files with 368717 additions and 200912 deletions

View File

@@ -1,57 +0,0 @@
This documentation explains how to compile Unicorn with CMake on Windows or
*nix.
----
Requirements:
- Windows: MicroSoft Visual Studio(>=2013).
- *nix: GNU gcc or clang to generate dynamic source files.
Get CMake for free from http://www.cmake.org.
[1] To build Unicorn using Nmake of Windows SDK, do:
mkdir build
cd build
..\nmake.bat
After this, find the samples test*.exe, unicorn.lib & unicorn.dll
in the same directory.
- To build Unicorn using Visual Studio, choose the generator accordingly to the
version of Visual Studio on your machine. For example, with Visual Studio 2013, do:
mkdir build
cd build
cmake -G "Visual Studio 12" ..
After this, find unicorn.sln in the same directory. Open it with Visual Studio
and build the solution including libraries & all test as usual.
[2] You can make sure the prior steps successfully worked by launching one of the
sample binary (sample_*.exe).
[3] You can also enable just one specific architecture by passing the architecture name
to either the cmake.sh or nmake.bat scripts. e.g.:
..\nmake.bat x86
Will just target the x86 architecture. The list of available architectures are:
X86 ARM AARCH64 M68K MIPS SPARC.
[4] You can also create an installation image with cmake, by using the 'install' target.
Use:
cmake --build . --config Release --target install
This will normally install an image in a default location (on MacOS and Linux, but this is not supported
on Windows). So in case you want to change the install location, set this when configuring CMake.
Use: `-DCMAKE_INSTALL_PREFIX=path` for instance, to put the installation in the 'path' subdirectory of
the build directory.
The default value of 'CMAKE_INSTALL_PREFIX' on *nix is '/usr/local'.

View File

@@ -1,164 +0,0 @@
This documentation explains how to compile, install & run Unicorn on MacOSX,
Linux, BSD, Solaris, Android & iOS.
To compile for Microsoft Windows, see [COMPILE-WINDOWS.md](COMPILE-WINDOWS.md)
----
[1] Tailor Unicorn to your need.
Out of 6 archtitectures supported by Unicorn (Arm, Arm64, M68K, Mips, Sparc,
& X86), if you just need several selected archs, choose which ones you want
to compile in by editing "config.mk" before going to next steps.
By default, all 6 architectures are compiled. If this is what you want, skip
to the section 2.
The other way of customize Unicorn without having to edit config.mk is to
pass the desired options on the commandline to ./make.sh. Currently,
Unicorn supports 4 options, as follows.
- UNICORN_ARCHS: specify list of architectures to compiled in.
- UNICORN_STATIC: build static library.
- UNICORN_SHARED: build dynamic (shared) library.
- UNICORN_QEMU_FLAGS: specify extra flags for qemu's configure script
To avoid editing config.mk for these customization, we can pass their values to
make.sh, as follows.
$ UNICORN_ARCHS="arm aarch64 x86" ./make.sh
NOTE: on commandline, put these values in front of ./make.sh, not after it.
For each option, refer to docs/README for more details.
[2] Compile and install from source on *nix
To build Unicorn on *nix (such as MacOSX, Linux, *BSD, Solaris):
- To compile for current platform, run:
$ ./make.sh
On Mac OS, to build non-universal binaries that includes only 64-bit code,
replace above command with:
$ ./make.sh macos-universal-no
- To cross-compile Unicorn on 64-bit Linux to target 32-bit binary,
cross-compile to 32-bit with:
$ ./make.sh linux32
After compiling, install Unicorn with:
$ sudo ./make.sh install
For FreeBSD/OpenBSD, where sudo is unavailable, run:
$ su; ./make.sh install
Users are then required to enter root password to copy Unicorn into machine
system directories.
Afterwards, run ./samples/sample_all.sh to test the sample emulations.
NOTE: The core framework installed by "./make.sh install" consist of
following files:
/usr/include/unicorn/unicorn.h
/usr/include/unicorn/x86.h
/usr/include/unicorn/arm.h
/usr/include/unicorn/arm64.h
/usr/include/unicorn/mips.h
/usr/include/unicorn/ppc.h
/usr/include/unicorn/sparc.h
/usr/include/unicorn/m68k.h
/usr/lib/libunicorn.so (for Linux/*nix), or /usr/lib/libunicorn.dylib (OSX)
/usr/lib/libunicorn.a
[3] Cross-compile for iOS from macOS.
To cross-compile for iOS (iPhone/iPad/iPod), macOS with Xcode installed is required.
- To cross-compile for iOS ArmV7 (iPod 4, iPad 1/2/3, iPhone4, iPhone4S), run:
$ ./make.sh ios_armv7
- To cross-compile for iOS ArmV7s (iPad 4, iPhone 5C, iPad mini), run:
$ ./make.sh ios_armv7s
- To cross-compile for iOS Arm64 (iPhone 5S, iPad mini Retina, iPad Air), run:
$ ./make.sh ios_arm64
- To cross-compile for all iOS devices (armv7 + armv7s + arm64), run:
$ ./make.sh ios
Resulted files libunicorn.dylib, libunicorn.a & tests/test* can then
be used on iOS devices.
[4] Cross-compile for Android
To cross-compile for Android (smartphone/tablet), Android NDK is required.
- To cross-compile for Android Arm, run:
$ NDK=~/android/android-ndk-r20 ./make.sh cross-android_arm
- To cross-compile for Android Arm64, run:
$ NDK=~/android/android-ndk-r20 ./make.sh cross-android_arm64
Resulted files libunicorn.so, libunicorn.a & tests/test* can then
be used on Android devices.
[5] By default, "cc" (default C compiler on the system) is used as compiler.
- To use "clang" compiler instead, run the command below:
$ ./make.sh clang
- To use "gcc" compiler instead, run:
$ ./make.sh gcc
[6] To uninstall Unicorn, run the command below:
$ sudo ./make.sh uninstall
[7] Language bindings
Look for the bindings under directory bindings/, and refer to README file
of corresponding languages.
[8] Unit tests
Mac OS X users will also need the GNU version of binutils (for gobjcopy).
It can be easily installed with Homebrew: `brew install binutils`.
Automated unit tests use the cmocka unit testing framework (https://cmocka.org/).
It can be installed in most Linux distros using the package manager, e.g.
`sudo yum install libcmocka libcmocka-devel`.
On Mac OS X with Homebrew: `brew install cmocka`.
You can also easily build and install it from source.
You can run the tests by running `make test` in the project directory. If you don't
build some architecture support then the corresponding tests will fail when run.

View File

@@ -1,184 +0,0 @@
To build Unicorn on Windows natively using Visual Studio, see docs under "msvc"
directory in root directory.
The rest of this manual shows how to cross-compile Unicorn for Windows using
either MingW or Msys2.
To compile for Linux, Mac OS X and Unix-based OS, see [COMPILE-NIX.md](COMPILE-NIX.md)
---
[0] Dependencies
For Windows, cross-compile requires Mingw. At the moment, it is confirmed that
Unicorn can be compiled either on Ubuntu or Windows.
- On Ubuntu 14.04 64-bit, do:
- Download DEB packages for Mingw64 from:
https://launchpad.net/~greg-hellings/+archive/ubuntu/mingw-libs/+build/2924251
- On Windows, install MinGW via package MSYS2 at https://msys2.github.io/
Follow the install instructions and don't forget to update the system packages with:
$ pacman --needed -Sy bash pacman pacman-mirrors msys2-runtime
Then close MSYS2, run it again from Start menu and update the rest with:
$ pacman -Su
Finally, install required toolchain to build C projects.
- To compile for Windows 32-bit, run:
$ pacman -S make
$ pacman -S mingw-w64-i686-toolchain
- To compile for Windows 64-bit, run:
$ pacman -S make
$ pacman -S mingw-w64-x86_64-toolchain
- For Cygwin, "make", "gcc-core", "libpcre-devel", "zlib-devel" are needed.
If apt-cyg is available, you can install these with:
$ apt-cyg install make gcc-core libpcre-devel zlib-devel
[1] Tailor Unicorn to your need.
Out of 6 archtitectures supported by Unicorn (Arm, Arm64, M68K, Mips, Sparc,
& X86), if you just need several selected archs, choose which ones you want
to compile in by editing "config.mk" before going to next steps.
By default, all 6 architectures are compiled.
The other way of customize Unicorn without having to edit config.mk is to
pass the desired options on the commandline to ./make.sh. Currently,
Unicorn supports 4 options, as follows.
- UNICORN_ARCHS: specify list of architectures to compiled in.
- UNICORN_STATIC: build static library.
- UNICORN_SHARED: build dynamic (shared) library.
- UNICORN_QEMU_FLAGS: specify extra flags for qemu's configure script
To avoid editing config.mk for these customization, we can pass their values to
make.sh, as follows.
$ UNICORN_ARCHS="arm aarch64 x86" ./make.sh
NOTE: on commandline, put these values in front of ./make.sh, not after it.
For each option, refer to docs/README for more details.
[2] Compile from source on Windows - with MinGW (MSYS2)
To compile with MinGW, install MSYS2 as instructed in the first section.
Note: After MSYS2 is installed, you will have 3 shortcuts to open the command prompt: "MSYS2 MSYS", "MSYS2 MinGW-32 bit" and "MSYS2 MinGW 64-bit". Use the MinGW shortcut so that compilation succeeds.
Then, build Unicorn with the next steps:
- To compile Windows 32-bit binary with MinGW, run:
$ ./make.sh cross-win32
- To compile Windows 64-bit binary with MinGW, run:
$ ./make.sh cross-win64
Resulted files unicorn.dll, unicorn.lib & samples/sample*.exe can then
be used on Windows machine.
To run sample_x86.exe on Windows 32-bit, you need the following files:
unicorn.dll
%MSYS2%\mingw32\bin\libgcc_s_dw2-1.dll
%MSYS2%\mingw32\bin\libwinpthread-1.dll
To run sample_x86.exe on Windows 64-bit, you need the following files:
unicorn.dll
%MSYS2%\mingw64\bin\libgcc_s_seh-1.dll
%MSYS2%\mingw64\bin\libwinpthread-1.dll
[3] Compile and install from source on Cygwin
To build Unicorn on Cygwin, run:
$ ./make.sh
After compiling, install Unicorn with:
$ ./make.sh install
Resulted files cygunicorn.dll, libunicorn.dll.a and libunicorn.a can be
used on Cygwin but not native Windows.
NOTE: The core framework installed by "./make.sh install" consist of
following files:
/usr/include/unicorn/*.h
/usr/bin/cygunicorn.dll
/usr/lib/libunicorn.dll.a
/usr/lib/libunicorn.a
[4] Cross-compile for Windows from *nix
To cross-compile for Windows, Linux & gcc-mingw-w64-i686 (and also gcc-mingw-w64-x86-64
for 64-bit binaries) are required.
- To cross-compile Windows 32-bit binary, simply run:
$ ./make.sh cross-win32
- To cross-compile Windows 64-bit binary, run:
$ ./make.sh cross-win64
Resulted files unicorn.dll, unicorn.lib & samples/sample*.exe can then
be used on Windows machine.
To run sample_x86.exe on Windows 32-bit, you need the following files:
unicorn.dll
/usr/lib/gcc/i686-w64-mingw32/4.8/libgcc_s_sjlj-1.dll
/usr/i686-w64-mingw32/lib/libwinpthread-1.dll
To run sample_x86.exe on Windows 64-bit, you need the following files:
unicorn.dll
/usr/lib/gcc/x86_64-w64-mingw32/4.8/libgcc_s_sjlj-1.dll
/usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll
Then run either "sample_x86.exe -32" or "sample_x86.exe -64" to test emulators for X86 32-bit or X86 64-bit.
For other architectures, run "sample_xxx.exe" found in the same directory.
[5] Language bindings
Look for the bindings under directory bindings/, and refer to README file
of corresponding languages.
[6] Unit tests
Automated unit tests use the cmocka unit testing framework (https://cmocka.org/).
It can be installed in most Linux distros using the package manager, e.g.
`sudo yum install libcmocka libcmocka-devel`, or you can easily build and install it from source.
You can run the tests by running `make test` in the project directory.

View File

@@ -1,25 +1,131 @@
To compile Unicorn on Mac OS X, Linux, BSD, Solaris and all kind of nix OS,
see [COMPILE-NIX.md](COMPILE-NIX.md)
This HOWTO introduces how to build Unicorn2 natively on Linux/Mac/Windows,
or cross-build to Windows from Linux host.
To compile Unicorn on Windows, see [COMPILE-WINDOWS.md](COMPILE-WINDOWS.md)
---
### Native build on Linux/MacOS
To compile Unicorn with CMake on Windows or *nix, see
[COMPILE-CMAKE.md](COMPILE-CMAKE.md)
This builds Unicorn2 on Linux/MacOS. The output is `libunicorn.so` or `libunicorn.dylib`, respectively.
Then learn more on how to code your own tools with our samples.
- Require `cmake` & `pkg-config` packages (besides `gcc`/`clang` compiler):
- For C sample code, see code in directory samples/sample*.c
- For Python sample code, see code in directory bindings/python/sample*.py
- For samples of other bindings, look into directories bindings/<language>/
```
$ sudo apt install cmake pkg-config
```
#Building unicorn - Using vcpkg
- Build with the following commands.
You can download and install unicorn using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:
```
$ mkdir build; cd build
$ ../cmake.sh
```
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install unicorn
Then run the sample `sample_riscv` with:
The unicorn port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
```
$ ./sample_riscv
```
---
### Native build on Windows, with MSVC
This builds Unicorn2 on Windows, using Microsoft MSVC compiler. The output is `unicorn.dll`.
- Require `cmake` & `Microsoft Visual Studio`.
- From Visual Studio Command Prompt, build with the following commands.
```
mkdir build; cd build
../nmake.sh
```
Then run the sample `sample_riscv` with:
```
sample_riscv.exe
```
---
### Cross build from Linux host to Windows, with Mingw
This cross-builds Unicorn2 from **Linux host** to Windows, using `Mingw` compiler. The output is `libunicorn.dll`
- Install required package.
```
$ sudo apt install mingw-w64-x86-64-dev
```
- Build Unicorn and samples with the following commands.
```
$ mkdir build; cd build
$ ../cmake.sh mingw
```
The resulted `sample_riscv.exe` can be run with `libunicorn.dll`, and some dependecies DLLs
already provided in `bin/` directory.
To prepare for `sample_riscv.exe`, do:
```
cp libunicorn.dll ../bin
cp sample_riscv.exe ../bin
```
Then inside the `bin/` directory, you can run `sample_riscv.exe` (from `CMD.exe` prompt, for example)
---
### Native build on Windows host, with MSYS2/Mingw
This builds Unicorn2 on **Windows host**, using **MSYS2/Mingw** compiler. The output is `libunicorn.dll`
This requires MSYS2 to be installed on Windows machine. You need to download & install MSYS2 from https://www.msys2.org.
Then from MSYS2 console, install required packages:
```
pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake
```
- Build Unicorn and samples with the following commands.
```
mkdir build; cd build
../cmake.sh msys
```
The resulted `sample_riscv.exe` can be run with `libunicorn.dll`, and some dependecies DLLs
already provided in `bin/` directory.
To prepare for `sample_riscv.exe`, do:
```
cp libunicorn.dll ../bin
cp sample_riscv.exe ../bin
```
Then inside the `bin/` directory, you can run `sample_riscv.exe` (from `CMD.exe` prompt, for example)
---
### Cross build from Linux host to other arch
This cross-builds Unicorn2 from **Linux host** to other arch, using cross compiler. The output is `libunicorn.so`
- Install cross compiler package. For example, cross compile to ARM require below command.
```
$ sudo apt install gcc-arm-linux-gnueabihf
```
- Build Unicorn and samples with the following commands (note that you need to specify compiler with CC).
```
$ mkdir build; cd build
$ CC=arm-linux-gnueabihf-gcc ../cmake.sh
```

BIN
docs/unicorn-logo-text.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 34 KiB

31
docs/unicorn-logo.svg Normal file
View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Creator: CorelDRAW X7 -->
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="113.496mm" height="95.7057mm" version="1.1" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd"
viewBox="0 0 11350 9571"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<style type="text/css">
<![CDATA[
.fil2 {fill:#FEFEFE}
.fil0 {fill:#E62129}
.fil1 {fill:black}
]]>
</style>
</defs>
<g id="Layer_x0020_1">
<metadata id="CorelCorpID_0Corel-Layer"/>
<g id="_307418024">
<path class="fil0" d="M7101 1434l-1 0c487,-344 1238,-810 1653,-1216 2,-11 4,-25 -31,-17 -121,27 -433,159 -512,209 21,20 106,47 151,60 -50,6 -96,-1 -140,-5 -129,-13 -220,38 -344,99 -41,20 -79,39 -117,59 -1,26 231,92 280,88 -78,15 -136,9 -191,3 -85,-11 -151,-31 -233,-3 -113,39 -249,120 -353,173 -1,32 281,131 341,127 -240,21 -249,-21 -421,-41 -30,-3 -64,0 -113,19 -39,15 -205,96 -272,131l7 -6 0 1 -15 6c6,37 35,99 38,145 3,45 225,145 273,168z"/>
<g>
<path class="fil1" d="M1118 8018l0 -1025 373 0 0 1025c0,311 -155,466 -466,466l-559 0c-311,0 -466,-155 -466,-466l0 -1025 373 0 0 1025c0,62 31,93 93,93l559 0c62,0 93,-31 93,-93zm1084 -339l0 805 -373 0 0 -1581 1119 895 0 -805 373 0 0 1581 -1119 -895zm1830 805l-373 0 0 -1491 373 0 0 1491zm1457 -466l0 -93 372 0 0 93c0,311 -155,466 -466,466l-559 0c-311,0 -466,-155 -466,-466l0 -559c0,-311 155,-466 466,-466l559 0c311,0 466,155 466,466l0 93 -372 0 0 -93c0,-62 -32,-93 -94,-93l-559 0c-62,0 -93,31 -93,93l0 559c0,62 31,93 93,93l559 0c62,0 94,-31 94,-93zm1829 -559c0,-62 -31,-93 -93,-93l-559 0c-62,0 -94,31 -94,93l0 559c0,62 32,93 94,93l559 0c62,0 93,-31 93,-93l0 -559zm-93 -466c310,0 466,155 466,466l0 559c0,311 -156,466 -466,466l-559 0c-311,0 -466,-155 -466,-466l0 -559c0,-311 155,-466 466,-466l559 0zm804 0l1025 0c311,0 466,155 466,466 0,274 -121,427 -362,460l452 565 -478 0 -448 -559 -282 0 0 559 -373 0 0 -1491zm373 373l0 186 652 0c62,0 93,-31 93,-93 0,-62 -31,-93 -93,-93l-652 0zm1829 313l0 805 -373 0 0 -1581 1119 895 0 -805 373 0 0 1581 -1119 -895z"/>
<path class="fil1" d="M2004 9551l0 -638 598 0 0 93 -498 0 0 159 327 0 0 92 -327 0 0 202 526 0 0 92 -626 0zm1409 0l0 -638 52 0 405 448 0 -448 98 0 0 638 -52 0 -405 -447 0 447 -98 0zm1846 -248l0 -92 262 0 0 193c-36,54 -84,96 -144,124 -59,28 -128,43 -206,43 -117,0 -213,-32 -288,-95 -75,-64 -112,-144 -112,-242 0,-97 37,-178 112,-242 76,-64 171,-96 288,-96 74,0 139,13 196,38 57,26 105,63 142,112l-76 55c-27,-35 -64,-63 -110,-83 -46,-20 -97,-30 -152,-30 -87,0 -158,23 -214,69 -56,47 -84,105 -84,176 0,70 28,129 84,175 55,46 126,69 214,69 55,0 106,-10 152,-29 47,-20 79,-46 98,-76l0 -69 -162 0zm1086 248l0 -639 101 0 0 639 -101 0zm962 0l0 -638 52 0 405 448 0 -448 98 0 0 638 -52 0 -405 -447 0 447 -98 0zm1413 0l0 -638 598 0 0 93 -499 0 0 159 327 0 0 92 -327 0 0 202 526 0 0 92 -625 0z"/>
<polygon class="fil1" points="0,9165 1300,9165 1300,9257 0,9257 "/>
<polygon class="fil1" points="10050,9165 11350,9165 11350,9257 10050,9257 "/>
</g>
<path class="fil0" d="M6093 1928c-68,808 676,845 742,827 143,29 409,219 409,219 19,168 46,178 119,216 169,90 504,48 596,-158 108,-240 -244,-791 -381,-961 -171,-211 -25,-195 -113,-398 -50,-114 -146,-235 -238,-336 -44,-25 -232,-136 -241,-182 -2,-14 -8,-32 -15,-50 82,-41 348,-534 371,-616 -193,-13 -642,82 -703,233 18,76 95,130 112,206 -120,-51 -172,-117 -292,-167l-130 -761c-315,130 -399,508 -365,798 -331,-279 -667,-228 -1127,-51 208,6 316,80 361,163 -266,94 -570,161 -1121,197 82,136 254,233 389,258 -92,61 -845,-136 -1223,557 199,-199 740,-294 870,-68 -214,106 -242,312 -608,374 86,95 355,102 539,95 -464,216 -780,610 -1364,699 501,155 749,74 1051,18 -278,249 -557,583 -506,1176 59,-275 360,-529 591,-410 -122,205 -326,620 -669,844 309,48 610,-116 760,-221 -167,266 -251,557 -394,833 79,67 162,130 248,189 12,-10 24,-19 35,-29l247 134c3,25 6,49 10,73 56,30 113,58 171,85 15,-40 35,-81 58,-118 24,59 49,118 75,176 368,150 769,232 1190,232 1063,0 2002,-524 2576,-1328 -86,-12 -1934,-233 -1529,-1704 -337,-164 -688,-486 -501,-1044zm-790 -679c-807,838 -83,1836 699,2200 -576,-416 -1302,-1282 -699,-2200zm-737 870c-408,546 -247,1080 64,1388 102,102 229,188 370,267 657,365 1590,567 2009,1199 -159,-412 -359,-636 -616,-799 -603,-381 -1604,-489 -1884,-1204 -94,-241 -81,-522 57,-851z"/>
<path class="fil0" d="M5319 6134c1651,121 3087,-1120 3207,-2771 53,-727 -158,-1412 -552,-1962l-9 7c250,477 375,1027 333,1603 -119,1642 -1547,2875 -3189,2756 -974,-71 -1804,-603 -2293,-1366 442,957 1377,1651 2503,1733z"/>
<path class="fil2" d="M6976 1558c117,44 208,189 330,310 -118,-13 -192,-47 -279,-53 74,-103 -11,-187 -51,-257z"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
docs/unicorn1-logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB