-
Notifications
You must be signed in to change notification settings - Fork 19
/
setup.py
177 lines (149 loc) · 6.33 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#! /usr/bin/python3
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from setuptools.command.install_lib import install_lib
from distutils.command.build import build
from distutils.command.sdist import sdist
from distutils.dir_util import copy_tree
import platform
import sys
import os
VERSION = '0.0.3'
CORE_COMMIT = 'c13dbc0'
PYBIND11_COMMIT = 'd54d6d8'
class CMakeExtension(Extension):
def __init__(self, name, src_dir, additional=None, sources=None):
if not sources:
sources = []
for dir_path, _, files in os.walk(src_dir):
for file_name in files:
sources.append(os.path.join(dir_path, file_name))
if additional:
sources.extend(additional)
super().__init__(name=name, sources=sources)
class InstallCMakeLibs(install_lib):
def run(self):
self.skip_build = os.path.exists('build/vtil.pyd')
super().run()
class BuildVTIL(build):
def run(self):
self.run_command("build_ext")
super().run()
class PackageVTIL(sdist):
def run(self):
# Packaging VTIL doesn't require the build sources.
self.distribution.package_data = {}
self.distribution.packages = []
super().run()
class BuildCMakeExtension(build_ext):
def run(self):
for extension in self.extensions:
if extension.name == 'VTIL':
self.build()
def build(self):
import git
# Remove old build
if not os.path.exists('build/vtil.pyd'):
os.makedirs('build/lib', exist_ok=True)
# Update submodules
self.announce('Updating submodules ..')
if os.path.exists('.git'):
# We are running from a cloned version
git.Repo('.').submodule_update(init=True, recursive=False)
else:
# We are running from a pypi tar.gz version
if not os.path.exists('external/core'):
git.Repo.clone_from('https://github.com/vtil-project/VTIL-Core.git', 'external/core').git.checkout(CORE_COMMIT)
if not os.path.exists('external/pybind11'):
git.Repo.clone_from('https://github.com/pybind/pybind11.git', 'external/pybind11').git.checkout(PYBIND11_COMMIT)
self.announce('Preparing build for platform ..', level=3)
self.spawn(self.build_for_platform())
self.announce('Building ..', level=3)
self.spawn(self.build_cmake())
self.announce('Generating libs ..', level=3)
self.spawn(self.gen_libs())
self.announce('Copying wrappers ..', level=3)
copy_tree("src/wrappers", "vtil")
@staticmethod
def build_for_platform():
extras = []
if platform.system() == 'Windows':
import cmakegenerators
if 'Visual Studio 16 2019' not in [gen.name for gen in cmakegenerators.get_generators()]:
raise Exception('Visual Studio 2019 not found')
extras = ['-G', 'Visual Studio 16 2019']
return \
[
'cmake',
'-DPYTHON_EXECUTABLE=' + sys.executable,
'-DVTIL_PYTHON_VERSION=' + VERSION,
'-S', '.',
'-B', 'build'
] + extras
@staticmethod
def build_cmake():
return \
[
'cmake',
'--build', 'build',
'--config', 'Release'
]
@staticmethod
def gen_libs():
return \
[
"cmake",
"--install", "build",
"--component", "pyd",
"--prefix", "vtil"
]
setup(
name='VTIL',
version=VERSION,
author='Daniel. (@L33T)',
description='Virtual-machine Translation Intermediate Language',
long_description='VTIL Project, standing for Virtual-machine Translation Intermediate Language, is a set of tools'
' designed around an optimizing compiler to be used for binary de-obfuscation and'
' de-virtualization.\n\nThe main difference between VTIL and other optimizing compilers such as '
'LLVM is that it has an extremely versatile IL that makes it trivial to lift from any'
' architecture including stack machines. Since it is built for translation, VTIL does not abstract'
' away the native ISA and keeps the concept of the stack, physical registers, and the non-SSA'
' architecture of a general-purpose CPU as is. Native instructions can be emitted in the middle '
'of the IL stream and the physical registers can be addressed from VTIL instructions freely.\n\n'
'VTIL also makes it trivial to emit code back into the native format at any virtual address'
' requested without being constrained to a specific file format.',
url='https://github.com/vtil-project/VTIL-Python',
classifiers=[
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Development Status :: 3 - Alpha',
'Natural Language :: English',
'Operating System :: MacOS',
'Operating System :: POSIX :: Linux',
'Operating System :: Microsoft :: Windows',
'Programming Language :: C++',
'Topic :: Education'
],
python_requires='>=3.4',
license='BSD 3-Clause "New" or "Revised" License',
cmdclass={
'sdist': PackageVTIL,
'build': BuildVTIL,
'build_ext': BuildCMakeExtension,
'install_lib': InstallCMakeLibs
},
setup_requires=['cmake>=3.15', 'cmake-generators', 'GitPython', 'future_fstrings'],
install_requires=['pybind11'],
ext_modules=[CMakeExtension('VTIL', src_dir='src', additional=['LICENSE.md', 'CMakeLists.txt'])],
keywords='VTIL, VTIL Project, vtil, Virtual-machine Translation Intermediate Language, '
'Translation Intermediate Language, Intermediate Language',
zip_safe=True,
packages=['vtil'],
package_data={
'vtil': ['vtil.pyd', 'vtil.so', '*.py', '**/*.py'],
}
)