9 from distutils
import log
10 from setuptools
import setup
11 from distutils.util
import get_platform
12 from distutils.command.build
import build
13 from distutils.command.sdist
import sdist
14 from setuptools.command.bdist_egg
import bdist_egg
20 IS_64BITS = sys.maxsize > 2**32
23 ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
24 LIBS_DIR = os.path.join(ROOT_DIR,
'capstone',
'lib')
25 HEADERS_DIR = os.path.join(ROOT_DIR,
'capstone',
'include')
26 SRC_DIR = os.path.join(ROOT_DIR,
'src')
27 BUILD_DIR = SRC_DIR
if os.path.exists(SRC_DIR)
else os.path.join(ROOT_DIR,
'../..')
31 with open(os.path.join(BUILD_DIR,
'pkgconfig.mk'))
as fp:
32 lines = fp.readlines()
37 if line.startswith(
'#'):
42 k, v = line.split(
'=', 1)
45 if len(k) == 0
or len(v) == 0:
49 if 'PKG_MAJOR' not in VERSION_DATA
or \
50 'PKG_MINOR' not in VERSION_DATA
or \
51 'PKG_EXTRA' not in VERSION_DATA:
52 raise Exception(
"Malformed pkgconfig.mk")
54 if 'PKG_TAG' in VERSION_DATA:
55 VERSION =
'{PKG_MAJOR}.{PKG_MINOR}.{PKG_EXTRA}.{PKG_TAG}'.format(**VERSION_DATA)
57 VERSION =
'{PKG_MAJOR}.{PKG_MINOR}.{PKG_EXTRA}'.format(**VERSION_DATA)
59 if SYSTEM ==
'darwin':
60 VERSIONED_LIBRARY_FILE =
"libcapstone.{PKG_MAJOR}.dylib".format(**VERSION_DATA)
61 LIBRARY_FILE =
"libcapstone.dylib"
62 STATIC_LIBRARY_FILE =
'libcapstone.a'
63 elif SYSTEM
in (
'win32',
'cygwin'):
64 VERSIONED_LIBRARY_FILE =
"capstone.dll"
65 LIBRARY_FILE =
"capstone.dll"
66 STATIC_LIBRARY_FILE =
None
68 VERSIONED_LIBRARY_FILE =
"libcapstone.so.{PKG_MAJOR}".format(**VERSION_DATA)
69 LIBRARY_FILE =
"libcapstone.so"
70 STATIC_LIBRARY_FILE =
'libcapstone.a'
73 shutil.rmtree(LIBS_DIR, ignore_errors=
True)
74 shutil.rmtree(HEADERS_DIR, ignore_errors=
True)
77 """Copy the C sources into the source directory.
78 This rearranges the source files under the python distribution
85 except (IOError, OSError):
88 shutil.copytree(os.path.join(BUILD_DIR,
"arch"), os.path.join(SRC_DIR,
"arch"))
89 shutil.copytree(os.path.join(BUILD_DIR,
"include"), os.path.join(SRC_DIR,
"include"))
91 src.extend(glob.glob(os.path.join(BUILD_DIR,
"*.[ch]")))
92 src.extend(glob.glob(os.path.join(BUILD_DIR,
"*.mk")))
94 src.extend(glob.glob(os.path.join(BUILD_DIR,
"Makefile")))
95 src.extend(glob.glob(os.path.join(BUILD_DIR,
"LICENSE*")))
96 src.extend(glob.glob(os.path.join(BUILD_DIR,
"README")))
97 src.extend(glob.glob(os.path.join(BUILD_DIR,
"*.TXT")))
98 src.extend(glob.glob(os.path.join(BUILD_DIR,
"RELEASE_NOTES")))
99 src.extend(glob.glob(os.path.join(BUILD_DIR,
"make.sh")))
100 src.extend(glob.glob(os.path.join(BUILD_DIR,
"CMakeLists.txt")))
101 src.extend(glob.glob(os.path.join(BUILD_DIR,
"pkgconfig.mk")))
104 outpath = os.path.join(SRC_DIR, os.path.basename(filename))
105 log.info(
"%s -> %s" % (filename, outpath))
106 shutil.copy(filename, outpath)
110 Prepare the capstone directory for a binary distribution or installation.
111 Builds shared libraries and copies header files.
113 Will use a src/ dir if one exists in the current directory, otherwise assumes it's in the repo
117 os.mkdir(HEADERS_DIR)
121 shutil.copytree(os.path.join(BUILD_DIR,
'include',
'capstone'), os.path.join(HEADERS_DIR,
'capstone'))
124 if os.path.exists(os.path.join(ROOT_DIR,
'prebuilt', LIBRARY_FILE))
and \
125 (
not STATIC_LIBRARY_FILE
or os.path.exists(os.path.join(ROOT_DIR,
'prebuilt', STATIC_LIBRARY_FILE))):
126 shutil.copy(os.path.join(ROOT_DIR,
'prebuilt', LIBRARY_FILE), LIBS_DIR)
127 if STATIC_LIBRARY_FILE
is not None:
128 shutil.copy(os.path.join(ROOT_DIR,
'prebuilt', STATIC_LIBRARY_FILE), LIBS_DIR)
134 if SYSTEM ==
"win32":
138 if not os.path.exists(
"build"): os.mkdir(
"build")
141 os.system(
'cmake -DCMAKE_BUILD_TYPE=RELEASE -DCAPSTONE_BUILD_TESTS=0 -DCAPSTONE_BUILD_STATIC=0 -G "NMake Makefiles" ..')
144 os.system(
"CAPSTONE_BUILD_CORE_ONLY=yes bash ./make.sh")
146 shutil.copy(VERSIONED_LIBRARY_FILE, os.path.join(LIBS_DIR, LIBRARY_FILE))
149 if STATIC_LIBRARY_FILE
and os.path.exists(STATIC_LIBRARY_FILE):
150 shutil.copy(STATIC_LIBRARY_FILE, LIBS_DIR)
158 return sdist.run(self)
163 if 'LIBCAPSTONE_PATH' in os.environ:
164 log.info(
'Skipping building C extensions since LIBCAPSTONE_PATH is set')
166 log.info(
'Building C extensions')
168 return build.run(self)
173 self.run_command(
'build')
174 return bdist_egg.run(self)
180 cmdclass[
'build'] = custom_build
181 cmdclass[
'sdist'] = custom_sdist
182 cmdclass[
'bdist_egg'] = custom_bdist_egg
185 from setuptools.command.develop
import develop
188 log.info(
"Building C extensions")
190 return develop.run(self)
192 cmdclass[
'develop'] = custom_develop
194 print(
"Proper 'develop' support unavailable.")
196 if 'bdist_wheel' in sys.argv
and '--plat-name' not in sys.argv:
197 idx = sys.argv.index(
'bdist_wheel') + 1
198 sys.argv.insert(idx,
'--plat-name')
199 name = get_platform()
205 sys.argv.insert(idx + 1,
'manylinux1_' + platform.machine())
208 sys.argv.insert(idx + 1, name.replace(
'.',
'_').
replace(
'-',
'_'))
211 Capstone is a disassembly framework with the target of becoming the ultimate
212 disasm engine for binary analysis and reversing in the security community.
214 Created by Nguyen Anh Quynh, then developed and maintained by a small community,
215 Capstone offers some unparalleled features:
217 - Support multiple hardware architectures: ARM, ARM64 (ARMv8), Mips, PPC, Sparc,
218 SystemZ, XCore and X86 (including X86_64).
220 - Having clean/simple/lightweight/intuitive architecture-neutral API.
222 - Provide details on disassembled instruction (called "decomposer" by others).
224 - Provide semantics of the disassembled instruction, such as list of implicit
225 registers read & written.
227 - Implemented in pure C language, with lightweight wrappers for C++, C#, Go,
228 Java, NodeJS, Ocaml, Python, Ruby & Vala ready (available in main code,
229 or provided externally by the community).
231 - Native support for all popular platforms: Windows, Mac OSX, iOS, Android,
232 Linux, *BSD, Solaris, etc.
234 - Thread-safe by design.
236 - Special support for embedding into firmware or OS kernel.
238 - High performance & suitable for malware analysis (capable of handling various
241 - Distributed under the open source BSD license.
243 Further information is available at http://www.capstone-engine.org
248 This project is released under the BSD license. If you redistribute the binary
249 or source code of Capstone, please attach file LICENSE.TXT with your products.
253 provides=[
'capstone'],
254 packages=[
'capstone'],
257 author=
'Nguyen Anh Quynh',
258 author_email=
'aquynh@gmail.com',
259 description=
'Capstone disassembly engine',
260 long_description=long_desc,
261 long_description_content_type=
"text/markdown",
262 url=
'https://www.capstone-engine.org',
263 python_requires=
'>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
265 'Development Status :: 5 - Production/Stable',
266 'Intended Audience :: Developers',
267 'Topic :: Software Development :: Build Tools',
268 'License :: OSI Approved :: BSD License',
269 'Programming Language :: Python :: 2',
270 'Programming Language :: Python :: 2.7',
271 'Programming Language :: Python :: 3',
276 include_package_data=
True,
279 "capstone": [
"lib/*",
"include/capstone/*"],
static RzBuffer * build(RzEgg *egg)
int replace(char *string, const char *token, const char *fmt,...)