init commit

vs2017
_xeroxz 2 years ago
commit 095f1b17d0

10
.NOTE

@ -0,0 +1,10 @@
Checklist for a new release:
- update ChangeLog
- cd bindings; make
- update API version in keystone.h
- update API version in CMakeLists.txt
- change version + dev status in bindings/python/setup.py
- push all local commits
- tag + push -- tags -> check for new Pypi package

@ -0,0 +1,33 @@
version: 1.0-{build}
os:
- Visual Studio 2015
before_build:
- call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
build_script:
- mkdir build
- cd build
- ..\nmake-dll.bat
- ..\nmake-lib.bat
after_build:
- mkdir keystone-windows-latest
- copy llvm\bin\keystone.dll keystone-windows-latest
- copy llvm\lib\keystone.lib keystone-windows-latest
- copy kstool\kstool.exe keystone-windows-latest
- 7z a keystone-windows-latest.zip keystone-windows-latest\*
artifacts:
- path: build\keystone-windows-latest.zip
name: All Windows binaries
- path: build\llvm\bin\keystone.dll
name: keystone.dll
- path: build\llvm\lib\keystone.lib
name: keystone.lib
- path: build\kstool\kstool.exe
name: kstool.exe

@ -0,0 +1,80 @@
name: PyPI ๐Ÿ“ฆ Distribution
on: [push]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
platform: [x32, x64]
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Set up MSVC x86
if: matrix.os == 'windows-latest' && matrix.platform == 'x32'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x86
- name: Set up MSVC x64
if: matrix.os == 'windows-latest' && matrix.platform == 'x64'
uses: ilammy/msvc-dev-cmd@v1
- name: Install dependencies
run: |
pip install setuptools wheel
- name: Build distribution ๐Ÿ“ฆ
shell: bash
run: |
if [ ${{ matrix.platform }} == 'x32' ] && [ ${{ matrix.os }} == 'windows-latest' ]; then
cd bindings/python && python setup.py build -p win32 bdist_wheel -p win32
elif [ ${{ matrix.platform }} == 'x32' ] && [ ${{ matrix.os }} == 'ubuntu-latest' ]; then
docker run --rm -v `pwd`/:/work dockcross/manylinux1-x86 > ./dockcross
chmod +x ./dockcross
./dockcross bindings/python/build_wheel.sh
elif [ ${{ matrix.platform }} == 'x64' ] && [ ${{ matrix.os }} == 'ubuntu-latest' ]; then
docker run --rm -v `pwd`/:/work dockcross/manylinux1-x64 > ./dockcross
chmod +x ./dockcross
./dockcross bindings/python/build_wheel.sh
elif [ ${{ matrix.platform }} == 'x32' ] && [ ${{ matrix.os }} == 'macos-latest' ]; then
cd bindings/python && python setup.py sdist
else
cd bindings/python && python setup.py bdist_wheel
fi
- uses: actions/upload-artifact@v2
with:
path: ${{ github.workspace }}/bindings/python/dist/*
publish:
needs: [build]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags')
steps:
- uses: actions/download-artifact@v2
with:
name: artifact
path: dist
- name: Publish distribution ๐Ÿ“ฆ to test PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.testpypi_pass }}
repository_url: https://test.pypi.org/legacy/
- name: Publish distribution ๐Ÿ“ฆ to PyPI
if: ${{ success() }}
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_pass }}

29
.gitignore vendored

@ -0,0 +1,29 @@
.DS_Store
*.swp
*.d
*.o
*.a
*.dSYM
*.so
*.so.*
*.exe
*.dll
*.dylib
*.class
*.jar
*.pyc
*.egg-info
*.tgz
*.tar.gz
*.github.io
_*.diff
build*/
samples/sample
_sample*.txt
tmp
MANIFEST
bindings/python/dist/
bindings/python/src/

@ -0,0 +1,67 @@
language: cpp
sudo: false
script:
- mkdir build
- cd build
- cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DLLVM_TARGETS_TO_BUILD="all" -G "Unix Makefiles" ..
- make -j 8
compiler:
- clang
- gcc
os:
- linux
- osx
matrix:
fast_finish: true
include:
- if: branch = master
os: osx
osx_image: xcode10.1
compiler: clang
before_cache:
- brew cleanup
- find /usr/local/Homebrew \! -regex ".+\.git.+" -delete;
cache:
directories:
- $HOME/Library/Caches/Homebrew
- /usr/local/Homebrew
before_install:
- cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core && git stash && git clean -d -f
script: brew update && brew install --HEAD keystone
- if: branch = master
os: osx
osx_image: xcode10.1
compiler: gcc
before_cache:
- brew cleanup
- find /usr/local/Homebrew \! -regex ".+\.git.+" -delete;
cache:
directories:
- $HOME/Library/Caches/Homebrew
- /usr/local/Homebrew
before_install:
- cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core && git stash && git clean -d -f
script: brew update && brew install --HEAD keystone
- name: "Windows nmake 32bit"
os: windows
language: shell
script:
- mkdir build
- cd build
- cmd.exe //C 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat' x86 '&' cmd.exe //C '..\nmake-dll.bat' X86 '&' cmd.exe //c '..\nmake-lib.bat' X86
- name: "Windows nmake 64bit"
os: windows
language: shell
script:
- mkdir build
- cd build
- cmd.exe //C 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat' amd64 '&' cmd.exe //C '..\nmake-dll.bat' '&' cmd.exe //c '..\nmake-lib.bat'

@ -0,0 +1 @@
Nguyen Anh Quynh <aquynh -at- gmail.com>

@ -0,0 +1,123 @@
# Keystone Assembler Engine (www.keystone-engine.org)
# By Nguyen Anh Quynh, 2016
cmake_minimum_required(VERSION 2.8.7)
project(keystone)
set(KEYSTONE_VERSION_MAJOR 0)
set(KEYSTONE_VERSION_MINOR 9)
option(KEYSTONE_BUILD_STATIC_RUNTIME "Embed static runtime" ON)
option(BUILD_LIBS_ONLY "Only build keystone library" 0)
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "No build type selected, default to Debug")
set(CMAKE_BUILD_TYPE "Debug")
endif()
if (POLICY CMP0022)
cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required
endif()
if (POLICY CMP0051)
# CMake 3.1 and higher include generator expressions of the form
# $<TARGETLIB:obj> in the SOURCES property. These need to be
# stripped everywhere that access the SOURCES property, so we just
# defer to the OLD behavior of not including generator expressions
# in the output for now.
cmake_policy(SET CMP0051 OLD)
endif()
if (POLICY CMP0063)
set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) # automatic when 3.3.2 is required
endif()
if (CMAKE_VERSION VERSION_LESS 3.1.20141117)
set(cmake_3_2_USES_TERMINAL)
else()
set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
endif()
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /EHsc")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /EHsc")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /EHsc")
else()
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
# Use GNUInstallDirs to set LLVM_LIBDIR_SUFFIX. This should automatically
# handle cases where the libdir should be lib/, lib64/, or lib/<arch>/
# depending on the target system and cmake options.
include(GNUInstallDirs)
string(REGEX REPLACE "lib(.*)$" "\\1" LLVM_LIBDIR_SUFFIX "${CMAKE_INSTALL_LIBDIR}")
set(LLVM_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING "Define suffix of library directory name (32/64)")
endif()
# Force static runtime libraries
if (KEYSTONE_BUILD_STATIC_RUNTIME)
FOREACH(flag
CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG_INIT
CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG_INIT)
if (MSVC)
STRING(REPLACE "/MD" "/MT" "${flag}" "${${flag}}")
SET("${flag}" "${${flag}} /EHsc")
endif (MSVC)
ENDFOREACH()
endif ()
add_subdirectory(llvm)
# for Windows, do not build kstool if buiding DLL
# TODO: fix this
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
if (NOT BUILD_LIBS_ONLY AND NOT BUILD_SHARED_LIBS)
add_subdirectory(kstool)
endif()
else()
if (NOT BUILD_LIBS_ONLY)
add_subdirectory(kstool)
endif()
endif()
# generate and install pkg-config.pc
FIND_PACKAGE(PkgConfig)
SET(PKG_CONFIG_FILE_PATH
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
)
SET(PKG_CONFIG_LIBDIR
"${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}"
)
SET(PKG_CONFIG_INCLUDEDIR
"${CMAKE_INSTALL_PREFIX}/include"
)
SET(PKG_CONFIG_LIBS
"-L\${libdir} -lkeystone"
)
SET(PKG_CONFIG_CFLAGS
"-I\${includedir}"
)
CONFIGURE_FILE(
"${CMAKE_CURRENT_SOURCE_DIR}/pkg-config.pc.cmake"
"${PKG_CONFIG_FILE_PATH}"
)
INSTALL(FILES "${PKG_CONFIG_FILE_PATH}"
DESTINATION lib${LLVM_LIBDIR_SUFFIX}/pkgconfig)
# uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/CMakeUninstall.in"
"${CMAKE_CURRENT_BINARY_DIR}/CMakeUninstall.cmake"
IMMEDIATE @ONLY)
if(NOT BUILD_LIBS_ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/CMakeUninstall.cmake)
endif()
if(NOT BUILD_LIBS_ONLY)
add_subdirectory(suite/fuzz)
endif()

@ -0,0 +1,21 @@
if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach(file ${files})
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
exec_program(
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
OUTPUT_VARIABLE rm_out
RETURN_VALUE rm_retval
)
if(NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
endif(NOT "${rm_retval}" STREQUAL 0)
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
endforeach(file)

@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

@ -0,0 +1,54 @@
๏ปฟThis file credits all the contributors of Keystone Engine (keystone-engine.org).
Beta testers (in no particular order)
=====================================
Mike Guidry
Eloi Vanderbeken
Tim "diff" Strazzere
Matt Graeber
Edgar Barbosa
Loi Anh Tuan
Sascha Schirra
hugsy
Alexander Tereshkin
Sรฉbastien Duquette
Sergi Alvarez, aka pancake (author of radare)
Richo Healey
Remco Verhoef (honeytrap.io)
Duncan Ogilvie
Bruce Dang
Dan Caselden
Jaime Peรฑalba
Daniel Collin
Vitaly Osipov
Dang Hoang Vu
Paul Rascagneres
postmodern
Fotis Loukos
Peter Geissler
Ingmar Steen (CED)
Matteo Favaro
Julien Legras
Anton Kochkov
Francisco Alonso
rdmz
practicalswift
Jurriaan Bremer
Contributors (in no particular order)
=====================================
Ingmar Steen: NodeJS binding.
Sascha Schirra: Ruby binding.
Remco Verhoef: Go & Rust bindings.
Adrian Herrera: Haskell binding.
practicalswift: Various cool bugs found by fuzzing.
Aziem Chawdhary: OCaml binding.
Ruben Boonen: PowerShell binding.
Marco Fornaro: C# binding.
David Zimmer: VB6 binding.
Michael Mohr: Debian packaging.
Jรคmes Mรฉnรฉtrey (ZenLulz): Java binding.
Philippe Antoine (Catena cyber): fuzzing.
Kevin Foo (chfl4gs): PyPI packaging, Travis-CI, fixes for Python binding.

@ -0,0 +1,96 @@
This file details the changelog of Keystone.
------------------------------
Version 0.9.2: June 21st, 2020
- Fix for Python binding (Pypi package)
----------------------------------
Version 0.9.2-rc1: June 13th, 2020
[ Core & tool ]
- Default radix set to 16
- kstool accepts -b option to print out encoding binary to output
- Do not build Universal binaries for Mac
- Better installer for Linux
- Add Ethereum VM architecture
- Better support for older compiler
- Add Masm binding
- Rename namespace llvm to llvm_ks
- Better cross compile with Android NDK
- Add KS_VERSION_{MAJOR, MINOR, EXTRA}
- Add new option KS_OPT_SYM_RESOLVER
- Fix memory leaks in ks_asm()
[ X86 ]
- Fix X86 prefix ordering
[ Arm ]
- Fix Thumb backward branch
- Fix Thumb2 ADR, B.W
- Fix BL, BLX in Thumb mode
[ Arm64 ]
- Fix ADRP
- Fix PC-relative offset for branch instructions
[ Mips ]
- Fix JAL IMM
[ PowerPC ]
- Remove bound check on branch instructions
[ Python binding ]
- Fix module loading issue
- Load library versioning
- Add as_bytes=True param to asm()
[ Bindings ]
- Multiple fixes for Python, Go, Rust, .NET
- Add Java, VB6, C#, Powershell, Perl bindings
------------------------------
Version 0.9.1: July 27th, 2016
[ Core & tool ]
- Fix a segfault in kstool (on missing assembly input).
- kstool now allows to specify instruction address.
- Build Mac libraries in universal format by default.
- Add "lib32" option to cross-compile to 32-bit *nix (on 64-bit system).
- Add "lib_only" option to only build libraries (skip kstool).
- New bindings: Haskell & OCaml.
[ X86 ]
- Fix instructions: LJMP, LCALL, CDQE, SHR, SHL, SAR, SAL, LOOP, LOOPE, LOOPNE
- Better handling a lot of tricky input caught by assert() before.
- Better support for Nasm syntax.
[ Arm ]
- Fix BLX instruction.
[ Python binding ]
- Better Python3 support.
- Expose @stat_count in KsError class when ks_asm() returns with error.
See sample code in bindings/python/sample_asm_count.py
[ Go binding ]
- Fix Go binding for 32-bit
---------------------------
Version 0.9: May 31th, 2016
- Initial public release.

@ -0,0 +1,132 @@
FOSS License Exception
What is the FOSS License Exception?
This is based on the Oracle's Free and Open Source Software ("FOSS")
License Exception.
The Free and Open Source Software ("FOSS") License Exception allows
developers of FOSS applications to include Keystone Libraries with their
FOSS applications. This exception permits distribution of Keystone libraries
with a developer's FOSS applications licensed under the terms of another
FOSS license listed below, even though such other FOSS license may be
incompatible with the GPL.
The following terms and conditions describe the circumstances under which
Oracle's FOSS License Exception applies.
FOSS License Exception Terms and Conditions
1. Definitions. "Derivative Work" means a derivative work, as defined
under applicable copyright law, formed entirely from the Program and
one or more FOSS Applications.
"FOSS Application" means a free and open source software application
distributed subject to a license listed in the section below titled
"FOSS License List."
"FOSS Notice" means a notice put in a copy of Keystone Libraries
stating that such copy of Keystone Libraries may be distributed under
FOSS License Exception.
"Independent Work" means portions of the Derivative Work that are not
derived from the Program and can reasonably be considered independent
and separate works.
"Program" means a copy of Keystone Libraries that contains
a FOSS Notice.
2. A FOSS application developer ("you" or "your") may distribute a
Derivative Work provided that you and the Derivative Work meet all of
the following conditions:
a. You obey the GPL in all respects for the Program and all portions
(including modifications) of the Program included in the
Derivative Work (provided that this condition does not apply to
Independent Works);
b. The Derivative Work does not include any work licensed under the
GPL other than the Program;
c. You distribute Independent Works subject to a license listed in
the section below titled "FOSS License List";
d. You distribute Independent Works in object code or executable
form with the complete corresponding machine-readable source code
on the same medium and under the same FOSS license applying to
the object code or executable forms;
e. All works that are aggregated with the Program or the Derivative
Work on a medium or volume of storage are not derivative works of
the Program, Derivative Work or FOSS Application, and must
reasonably be considered independent and separate works.
3. Keystone's authors reserves all rights not expressly granted in these
terms and conditions. If all of the above conditions are not met, then
this FOSS License Exception does not apply to you/your Derivative Work.
FOSS License List
+------------------------------------------------------------------------+
|License Name |Version(s)/Copyright Date|
|----------------------------------------------+-------------------------|
|Academic Free License |2.0 |
|----------------------------------------------+-------------------------|
|Apache Software License |1.0/1.1/2.0 |
|----------------------------------------------+-------------------------|
|Apple Public Source License |2.0 |
|----------------------------------------------+-------------------------|
|Artistic license |From Perl 5.8.0 |
|----------------------------------------------+-------------------------|
|BSD license |"July 22 1999" |
|----------------------------------------------+-------------------------|
|Common Development and Distribution License |1.0 |
|(CDDL) | |
|----------------------------------------------+-------------------------|
|Common Public License |1.0 |
|----------------------------------------------+-------------------------|
|Eclipse Public License |1.0 |
|----------------------------------------------+-------------------------|
|European Union Public License (EUPL)ยน |1.1 |
|----------------------------------------------+-------------------------|
|GNU Affero General Public License (AGPL) |3.0 |
|----------------------------------------------+-------------------------|
|GNU Library or "Lesser" General Public License|2.0/2.1/3.0 |
|(LGPL) | |
|----------------------------------------------+-------------------------|
|GNU General Public License (GPL) |3.0 |
|----------------------------------------------+-------------------------|
|IBM Public License |1.0 |
|----------------------------------------------+-------------------------|
|Jabber Open Source License |1.0 |
|----------------------------------------------+-------------------------|
|MIT License (As listed in file |- |
|MIT-License.txt) | |
|----------------------------------------------+-------------------------|
|Mozilla Public License (MPL) |1.0/1.1 |
|----------------------------------------------+-------------------------|
|Open Software License |2.0 |
|----------------------------------------------+-------------------------|
|OpenSSL license (with original SSLeay license)|"2003" ("1998") |
|----------------------------------------------+-------------------------|
|PHP License |3.0/3.01 |
|----------------------------------------------+-------------------------|
|Python license (CNRI Python License) |- |
|----------------------------------------------+-------------------------|
|Python Software Foundation License |2.1.1 |
|----------------------------------------------+-------------------------|
|Sleepycat License |"1999" |
|----------------------------------------------+-------------------------|
|University of Illinois/NCSA Open Source |- |
|License | |
|----------------------------------------------+-------------------------|
|W3C License |"2001" |
|----------------------------------------------+-------------------------|
|X11 License |"2001" |
|----------------------------------------------+-------------------------|
|Zlib/libpng License |- |
|----------------------------------------------+-------------------------|
|Zope Public License |2.0 |
+------------------------------------------------------------------------+
ยน) When an Independent Work is licensed under a "Compatible License"
pursuant to the EUPL, the Compatible License rather than the EUPL is the
applicable license for purposes of these FOSS License Exception Terms and
Conditions.

@ -0,0 +1,8 @@
The commercial license of Keystone allows you to use Keystone libraries & tools
in commercial products.
- The Keystone commercial license is perpetual and royalty-free.
- You have the right to distribute the binary and modifications of Keystone.
- No source code redistribution is allowed in any way.
Contact keystone.engine@gmail.com for further information.

@ -0,0 +1,63 @@
Keystone Engine
==============
[![Build Status](https://travis-ci.org/keystone-engine/keystone.svg?branch=master)](https://travis-ci.org/keystone-engine/keystone)
[![Build Status](https://semaphoreci.com/api/v1/aquynh/keystone/branches/master/badge.svg)](https://semaphoreci.com/aquynh/keystone)
[![Build status](https://ci.appveyor.com/api/projects/status/c27slvyrijiejvqs?svg=true)](https://ci.appveyor.com/project/aquynh/keystone)
Keystone is a lightweight multi-platform, multi-architecture assembler framework.
It offers some unparalleled features:
- Multi-architecture, with support for Arm, Arm64 (AArch64/Armv8), Ethereum Virtual Machine, Hexagon, Mips, PowerPC, Sparc, SystemZ & X86 (include 16/32/64bit).
- Clean/simple/lightweight/intuitive architecture-neutral API.
- Implemented in C/C++ languages, with bindings for Java, Masm, C#, PowerShell, Perl, Python, NodeJS, Ruby, Go, Rust, Haskell, VB6 & OCaml available.
- Native support for Windows & \*nix (with Mac OSX, Linux, \*BSD & Solaris confirmed).
- Thread-safe by design.
- Open source - with a dual license.
Keystone is based on LLVM, but it goes much further with [a lot more to offer](/docs/beyond_llvm.md).
Further information is available at http://www.keystone-engine.org
License
-------
Keystone is available under a dual license:
- Version 2 of the GNU General Public License (GPLv2). (I.e. Without the "any later version" clause.).
License information can be found in the [COPYING file](COPYING) and the [EXCEPTIONS-CLIENT file](EXCEPTIONS-CLIENT).
This combination allows almost all of open source projects to use Keystone without conflicts.
- For commercial usage in production environments, contact the authors of Keystone to buy a royalty-free license.
See [LICENSE-COM.TXT](LICENSE-COM.TXT) for more information.
Compilation & Docs
------------------
See [COMPILE.md](docs/COMPILE.md) file for how to compile and install Keystone.
More documentation is available in [docs/README.md](docs/README.md).
Contact
-------
[Contact us](http://www.keystone-engine.org/contact/) via mailing list, email or twitter for any questions.
Contribute
----------
Keystone is impossible without generous support from [our sponsors](/SPONSORS.TXT). We cannot thank them enough!
[CREDITS.TXT](CREDITS.TXT) records other important contributors of our project.
If you want to contribute, please pick up something from our [Github issues](https://github.com/keystone-engine/keystone/issues).
We also maintain a list of more challenged problems in a [TODO list](https://github.com/keystone-engine/keystone/wiki/TODO).

@ -0,0 +1,6 @@
Version 0.9.2 works quite well for all architectures, but is known to not be able
to deal with some malformed craft input. In such a case, Keystone usually exits
with some error messages. Report if you experience this issue, so we can fix
that in the next release.
See details of open bugs at https://github.com/keystone-engine/keystone/issues

@ -0,0 +1,8 @@
This file lists all the sponsors of Keystone Engine.
Thanks a lot for your great support!
----------------------------------------------------
Mike Guidry
Synacktiv Digital Security (www.synacktiv.com)
Tim "diff" Strazzere
Veris Group (www.verisgroup.com)

@ -0,0 +1,87 @@
# Keystone Engine
# By Nguyen Anh Quynh & Dang Hoang Vu, 2015
TMPDIR = /tmp/keystone_sample
DIFF = diff -u -w
SAMPLE_ARM = $(TMPDIR)/sample_arm
SAMPLE_ARM64 = $(TMPDIR)/sample_arm64
SAMPLE_MIPS = $(TMPDIR)/sample_mips
SAMPLE_M68K = $(TMPDIR)/sample_m68k
SAMPLE_SPARC = $(TMPDIR)/sample_sparc
SAMPLE_X86 = $(TMPDIR)/sample_x86
.PHONY: all expected python rust go nodejs ruby
all:
cd python && $(MAKE) gen_const
cd nodejs && $(MAKE) gen_const
python const_generator.py rust
python const_generator.py go
cd ruby && $(MAKE) gen_const
python const_generator.py powershell
samples: expected python
sample_python: expected python
expected:
cd ../samples && $(MAKE)
mkdir -p $(TMPDIR)
../samples/sample_arm > $(SAMPLE_ARM)_e
../samples/sample_arm64 > $(SAMPLE_ARM64)_e
../samples/sample_mips > $(SAMPLE_MIPS)_e
../samples/sample_sparc > $(SAMPLE_SPARC)_e
../samples/sample_m68k > $(SAMPLE_M68K)_e
../samples/sample_x86 > $(SAMPLE_X86)_e
python: FORCE
cd python && $(MAKE)
python python/sample_arm.py > $(SAMPLE_ARM)_o
python python/sample_arm64.py > $(SAMPLE_ARM64)_o
python python/sample_mips.py > $(SAMPLE_MIPS)_o
python python/sample_sparc.py > $(SAMPLE_SPARC)_o
python python/sample_m68k.py > $(SAMPLE_M68K)_o
python python/sample_x86.py > $(SAMPLE_X86)_o
$(MAKE) sample_diff
ruby: FORCE
cd ruby && $(MAKE)
nodejs: FORCE
cd nodejs && $(MAKE)
rust: FORCE
cd rust && $(MAKE)
go: FORCE
cd go && $(MAKE)
ocaml: FORCE
cd ocaml && $(MAKE)
sample_diff: FORCE
$(DIFF) $(SAMPLE_ARM)_e $(SAMPLE_ARM)_o
$(DIFF) $(SAMPLE_ARM64)_e $(SAMPLE_ARM64)_o
$(DIFF) $(SAMPLE_MIPS)_e $(SAMPLE_MIPS)_o
$(DIFF) $(SAMPLE_SPARC)_e $(SAMPLE_SPARC)_o
$(DIFF) $(SAMPLE_M68K)_e $(SAMPLE_M68K)_o
$(DIFF) $(SAMPLE_X86)_e $(SAMPLE_X86)_o
clean:
rm -rf $(TMPDIR)
cd python && $(MAKE) clean
cd rust && $(MAKE) clean
cd go && $(MAKE) clean
cd nodejs && $(MAKE) clean
cd ruby && $(MAKE) clean
cd ocaml && $(MAKE) clean
check:
cd python && $(MAKE) check
cd rust && $(MAKE) check
cd go && $(MAKE) check
cd nodejs && $(MAKE) check
cd ruby && $(MAKE) check
FORCE:

@ -0,0 +1,23 @@
This directory contains bindings for Keystone.
See <language>/README* for how to install each binding.
Except Python, all other bindings are contributed by community.
- NodeJS binding: by Ingmar Steen
- Ruby binding: by Sascha Schirra
- Go binding: by Remco Verhoef
- Rust binding: by Remco Verhoef
- Haskell binding: by Adrian Herrera
- OCaml binding: by Aziem Chawdhary
- PowerShell binding: by Ruben Boonen
- C# binding: by Marco Fornaro
- VB6 binding: by David Zimmer
- Masm binding: by mrfearless
- Java binding: by Jรคmes Mรฉnรฉtrey (ZenLulz)
Other bindings maintained externally by community:
- Perl-Keystone: Perl binding made by @t00sh.
https://github.com/t00sh/perl-keystone
- keystone-rs: Rust binding by @tathanhdinh
https://github.com/tathanhdinh/keystone-rs

@ -0,0 +1,430 @@
# Keystone Engine
# Adapted from the code of Dang Hoang Vu for Capstone Engine, 2013
from __future__ import print_function
import sys, re, os
INCL_DIR = os.path.join('..', 'include', 'keystone')
# NOTE: this reflects the value of KS_ERR_ASM_xxx in keystone.h
ks_err_val = { 'KS_ERR_ASM': '128', 'KS_ERR_ASM_ARCH': '512' }
include = [ 'arm.h', 'arm64.h', 'mips.h', 'x86.h', 'sparc.h', 'ppc.h', 'systemz.h', 'hexagon.h', 'evm.h', 'keystone.h' ]
def CamelCase(s):
# return re.sub(r'(\w)+\_?', lambda m:m.group(0).capitalize(), s)
return ''.join(''.join([w[0].upper(), w[1:].lower()]) for w in s.split('_'))
template = {
'powershell': {
'header': "/// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [%s_h.cs]\n",
'footer': "",
'out_file': './powershell/Keystone/Const/%s_h.cs',
# prefixes for constant filenames of all archs - case sensitive
'keystone.h': 'keystone',
'comment_open': '///',
'comment_close': '',
'rules': [
{
'regex': r'.*',
'line_format': 'KS_{0} = {1},\n',
'fn': (lambda x: x),
},
]
},
'rust': {
'header': "#![allow(non_camel_case_types)]\n// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [%s_const.rs]\nuse ::libc::*;\n",
'footer': "",
# prefixes for constant filenames of all archs - case sensitive
'arm.h': 'keystone',
'arm64.h': 'keystone',
'mips.h': 'keystone',
'x86.h': 'keystone',
'sparc.h': 'keystone',
'systemz.h': 'keystone',
'ppc.h': 'keystone',
'hexagon.h': 'keystone',
'evm.h': 'keystone',
'keystone.h': 'keystone',
'comment_open': '/*',
'comment_close': '*/',
'out_file': './rust/keystone-sys/src/%s_const.rs',
'rules': [
{
'regex': r'(API)_.*',
'pre': '\n',
'line_format': 'pub const {0}: c_uint = {1};\n',
'fn': (lambda x: x),
},
{ 'regex': r'MODE_.*',
'pre': '\n' +
'bitflags! {{\n' +
'#[repr(C)]\n' +
' pub struct Mode: c_int {{\n',
'line_format': ' const {0} = {1};\n',
'fn': (lambda x: '_'.join(x.split('_')[1:]) if not re.match(r'MODE_\d+', x) else x),
'post': ' }\n}',
},
{
'regex': r'ARCH_.*',
'pre': '\n' +
'#[repr(C)]\n' +
'#[derive(Debug, PartialEq, Clone, Copy)]\n' +
'pub enum Arch {{\n',
'line_format': ' {0} = {1},\n',
'fn': (lambda x: '_'.join(x.split('_')[1:])),
'post': '}\n',
},
{
'regex': r'(OPT_([A-Z]+)|OPT_SYM_RESOLVER)$',
'pre': '#[repr(C)]\n' +
'#[derive(Debug, PartialEq, Clone, Copy)]\n' +
'pub enum OptionType {{\n',
'line_format': ' {0} = {1},\n',
'fn': (lambda x: '_'.join(x.split('_')[1:])),
'post': '}\n',
},
{
'regex': r'OPT_(?!SYM)([A-Z]+\_)+[A-Z]+',
'pre': 'bitflags! {{\n'
'#[repr(C)]\n' +
' pub struct OptionValue: size_t {{\n',
'line_format': ' const {0} = {1};\n',
'fn': (lambda x: '_'.join(x.split('_')[1:])),
'post': ' }\n}\n',
},
{
'regex': r'ERR_(.*)',
'pre': 'bitflags! {{\n' +
'#[repr(C)]\n' +
' pub struct Error: c_int {{\n',
'line_format': ' const {0} = {1};\n',
'fn': (lambda x: '_'.join(x.split('_')[1:])),
'post': ' }\n}',
},
],
},
'go': {
'header': "package keystone\n// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [%s_const.go]\n\n",
'footer': "",
# prefixes for constant filenames of all archs - case sensitive
'arm.h': 'arm',
'arm64.h': 'arm64',
'mips.h': 'mips',
'x86.h': 'x86',
'sparc.h': 'sparc',
'systemz.h': 'systemz',
'ppc.h': 'ppc',
'hexagon.h': 'hexagon',
'evm.h': 'evm',
'keystone.h': 'keystone',
'comment_open': '/*',
'comment_close': '*/',
'out_file': './go/keystone/%s_const.go',
'rules': [
{
'regex': r'API_.*',
'pre': 'const (\n',
'line_format': '\t{0} = {1}\n',
'fn': (lambda x: x),
'post': ')\n',
},
{ 'regex': r'MODE_.*',
'pre': 'const (\n',
'line_format': '\t{0} Mode = {1}\n',
'fn': (lambda x: x),
'post': ')\n',
},
{
'regex': r'ARCH_.*',
'pre': 'const (\n',
'line_format': '\t{0} Architecture = {1}\n',
'fn': (lambda x: x),
'post': ')\n',
},
{
'regex': r'OPT_([A-Z]+)$',
'pre': 'const (\n',
'line_format': '\t{0} OptionType = {1}\n',
'fn': (lambda x: x),
'post': ')\n',
},
{
'regex': r'OPT_([A-Z]+\_)+[A-Z]+',
'pre': 'const (\n',
'line_format': '\t{0} OptionValue = {1}\n',
'fn': (lambda x: x),
'post': ')\n',
},
{
'regex': r'ERR_.*',
'pre': 'const (\n',
'line_format': '\t{0} Error = {1}\n',
'fn': (lambda x: x),
'post': ')\n',
},
]
},
'python': {
'header': "# For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [%s_const.py]\n",
'footer': "",
'out_file': './python/keystone/%s_const.py',
# prefixes for constant filenames of all archs - case sensitive
'arm.h': 'arm',
'arm64.h': 'arm64',
'mips.h': 'mips',
'x86.h': 'x86',
'sparc.h': 'sparc',
'systemz.h': 'systemz',
'ppc.h': 'ppc',
'hexagon.h': 'hexagon',
'evm.h': 'evm',
'keystone.h': 'keystone',
'comment_open': '#',
'comment_close': '',
'rules': [
{
'regex': r'.*',
'line_format': 'KS_{0} = {1}\n',
'fn': (lambda x: x),
},
]
},
'nodejs': {
'header': "// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [%s_const.js]\n",
'footer': "",
'out_file': './nodejs/consts/%s.js',
# prefixes for constant filenames of all archs - case sensitive
'arm.h': 'arm',
'arm64.h': 'arm64',
'mips.h': 'mips',
'x86.h': 'x86',
'sparc.h': 'sparc',
'systemz.h': 'systemz',
'ppc.h': 'ppc',
'hexagon.h': 'hexagon',
'evm.h': 'evm',
'keystone.h': 'keystone',
'comment_open': '//',
'comment_close': '',
'rules': [
{
'regex': r'.*',
'line_format': 'module.exports.{0} = {1}\n',
'fn': (lambda x: x),
},
]
},
'ruby': {
'header': "# For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [%s_const.rb]\n\nmodule Keystone\n",
'footer': "end",
'out_file': './ruby/keystone_gem/lib/keystone/%s_const.rb',
# prefixes for constant filenames of all archs - case sensitive
'arm.h': 'arm',
'arm64.h': 'arm64',
'mips.h': 'mips',
'x86.h': 'x86',
'sparc.h': 'sparc',
'systemz.h': 'systemz',
'ppc.h': 'ppc',
'hexagon.h': 'hexagon',
'evm.h': 'evm',
'keystone.h': 'keystone',
'comment_open': '#',
'comment_close': '',
'rules': [
{
'regex': r'.*',
'line_format': '\tKS_{0} = {1}\n',
'fn': (lambda x: x),
},
]
},
'csharp': {
'header': "// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [%sConstants.cs]\nnamespace KeystoneNET\n{",
'footer': "}",
'out_file': './csharp/KeystoneNET/KeystoneNET/Constants/%sConstants.cs',
# prefixes for constant filenames of all archs - case sensitive
'keystone.h': 'keystone',
'arm.h': 'arm',
'arm64.h': 'arm64',
'mips.h': 'mips',
'x86.h': 'x86',
'sparc.h': 'sparc',
'systemz.h': 'systemz',
'ppc.h': 'ppc',
'hexagon.h': 'hexagon',
'evm.h': 'evm',
'keystone.h': 'keystone',
'comment_open': '//',
'comment_close': '',
'rules': [
{
'regex': r'(ARCH)_.*',
'pre': '\n\tpublic enum KeystoneArchitecture : int\n\t{{\n',
'post': '\t}',
'line_format': '\t\tKS_{0} = {1},\n',
'fn': (lambda x: x),
},
{
'regex': r'(MODE)_.*',
'pre': '\n\tpublic enum KeystoneMode : uint\n\t{{\n',
'post': '\t}',
'line_format': '\t\tKS_{0} = {1},\n',
'fn': (lambda x: x),
},
{
'regex': r'(ERR)_.*',
'pre': '\n\tpublic enum {0}Error : short\n\t{{\n',
'post': '\t}',
'line_format': '\t\tKS_{0} = {1},\n',
'fn': (lambda x: x),
},
{
'regex': r'((OPT_([A-Z]+))|(OPT_SYM_RESOLVER))$',
'pre': '\n\tpublic enum KeystoneOptionType : short\n\t{{\n',
'post': '\t}',
'line_format': '\t\tKS_{0} = {1},\n',
'fn': (lambda x: x),
},
{
'regex': r'OPT_(?!SYM)([A-Z]+\_)+[A-Z]+',
'pre': '\n\tpublic enum KeystoneOptionValue : short\n\t{{\n',
'post': '\t}',
'line_format': '\t\tKS_{0} = {1},\n',
'fn': (lambda x: x),
},
]
},
}
# markup for comments to be added to autogen files
MARKUP = '//>'
def gen(lang):
global include, INCL_DIR
consts = {}
templ = template[lang]
for target in include:
if target not in templ:
continue
prefix = templ[target]
if target == 'keystone.h':
prefix = 'keystone'
lines = open(os.path.join(INCL_DIR, target)).readlines()
consts[prefix] = []
previous = {}