├── .gitignore
├── .gitmodules
├── CMakeLists.txt
├── LICENSE
├── README.md
├── VTIL-Python.licenseheader
├── VTIL-py.sln
├── VTIL-py.vcxproj
├── VTIL-py.vcxproj.filters
├── appveyor.yml
├── examples
├── arm64
│ └── tracer.py
├── compiler_interface.py
└── routine.py
├── requirements.txt
├── setup.cfg
├── setup.py
└── src
├── architecture
├── arch
│ ├── identifier.hpp
│ ├── instruction_desc.hpp
│ ├── operands.hpp
│ └── register_desc.hpp
├── misc
│ └── debug.hpp
├── routine
│ ├── basic_block.hpp
│ ├── call_convention.hpp
│ ├── instruction.hpp
│ └── routine.hpp
├── symex
│ └── variable.hpp
└── trace
│ ├── cached_tracer.hpp
│ └── tracer.hpp
├── common
└── util
│ ├── enumerator.hpp
│ └── fnv64.hpp
├── compiler
└── common
│ └── interface.hpp
├── external
├── arm64_reg.hpp
└── x86_reg.hpp
├── module.cpp
├── symex
└── expressions
│ ├── expression.hpp
│ └── unique_identifier.hpp
└── wrappers
├── __init__.py
├── arch
└── __init__.py
├── common
└── __init__.py
├── compiler
└── __init__.py
└── symex
└── __init__.py
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Visual Studio
2 | # User-specific files
3 | *.rsuser
4 | *.suo
5 | *.user
6 | *.userosscache
7 | *.sln.docstates
8 |
9 | # User-specific files (MonoDevelop/Xamarin Studio)
10 | *.userprefs
11 |
12 | # Mono auto generated files
13 | mono_crash.*
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | [Ww][Ii][Nn]32/
23 | [Aa][Rr][Mm]/
24 | #[Aa][Rr][Mm]64/
25 | bld/
26 | [Bb]in/
27 | [Oo]bj/
28 | [Ll]og/
29 | [Ll]ogs/
30 |
31 | # Visual Studio 2015/2017 cache/options directory
32 | .vs/
33 | # Uncomment if you have tasks that create the project's static files in wwwroot
34 | #wwwroot/
35 |
36 | # Visual Studio 2017 auto generated files
37 | Generated\ Files/
38 |
39 | # MSTest test Results
40 | [Tt]est[Rr]esult*/
41 | [Bb]uild[Ll]og.*
42 |
43 | # NUnit
44 | *.VisualState.xml
45 | TestResult.xml
46 | nunit-*.xml
47 |
48 | # Build Results of an ATL Project
49 | [Dd]ebugPS/
50 | [Rr]eleasePS/
51 | dlldata.c
52 |
53 | # Benchmark Results
54 | BenchmarkDotNet.Artifacts/
55 |
56 | # .NET Core
57 | project.lock.json
58 | project.fragment.lock.json
59 | artifacts/
60 |
61 | # ASP.NET Scaffolding
62 | ScaffoldingReadMe.txt
63 |
64 | # StyleCop
65 | StyleCopReport.xml
66 |
67 | # Binaries
68 | *.lib
69 | *.exe
70 |
71 | # Files built by Visual Studio
72 | *_i.c
73 | *_p.c
74 | *_h.h
75 | *.ilk
76 | *.meta
77 | *.obj
78 | *.iobj
79 | *.pch
80 | *.pdb
81 | *.ipdb
82 | *.ipch
83 | *.pgc
84 | *.pgd
85 | *.rsp
86 | *.sbr
87 | *.tlb
88 | *.tli
89 | *.tlh
90 | *.tmp
91 | *.tmp_proj
92 | *_wpftmp.csproj
93 | *.log
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*[.json, .xml, .info]
147 |
148 | # Visual Studio code coverage results
149 | *.coverage
150 | *.coveragexml
151 |
152 | # NCrunch
153 | _NCrunch_*
154 | .*crunch*.local.xml
155 | nCrunchTemp_*
156 |
157 | # MightyMoose
158 | *.mm.*
159 | AutoTest.Net/
160 |
161 | # Web workbench (sass)
162 | .sass-cache/
163 |
164 | # Installshield output folder
165 | [Ee]xpress/
166 |
167 | # DocProject is a documentation generator add-in
168 | DocProject/buildhelp/
169 | DocProject/Help/*.HxT
170 | DocProject/Help/*.HxC
171 | DocProject/Help/*.hhc
172 | DocProject/Help/*.hhk
173 | DocProject/Help/*.hhp
174 | DocProject/Help/Html2
175 | DocProject/Help/html
176 |
177 | # Click-Once directory
178 | publish/
179 |
180 | # Publish Web Output
181 | *.[Pp]ublish.xml
182 | *.azurePubxml
183 | # Note: Comment the next line if you want to checkin your web deploy settings,
184 | # but database connection strings (with potential passwords) will be unencrypted
185 | *.pubxml
186 | *.publishproj
187 |
188 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
189 | # checkin your Azure Web App publish settings, but sensitive information contained
190 | # in these scripts will be unencrypted
191 | PublishScripts/
192 |
193 | # NuGet Packages
194 | *.nupkg
195 | # NuGet Symbol Packages
196 | *.snupkg
197 | # The packages folder can be ignored because of Package Restore
198 | **/[Pp]ackages/*
199 | # except build/, which is used as an MSBuild target.
200 | !**/[Pp]ackages/build/
201 | # Uncomment if necessary however generally it will be regenerated when needed
202 | #!**/[Pp]ackages/repositories.config
203 | # NuGet v3's project.json files produces more ignorable files
204 | *.nuget.props
205 | *.nuget.targets
206 |
207 | # Microsoft Azure Build Output
208 | csx/
209 | *.build.csdef
210 |
211 | # Microsoft Azure Emulator
212 | ecf/
213 | rcf/
214 |
215 | # Windows Store app package directories and files
216 | AppPackages/
217 | BundleArtifacts/
218 | Package.StoreAssociation.xml
219 | _pkginfo.txt
220 | *.appx
221 | *.appxbundle
222 | *.appxupload
223 |
224 | # Visual Studio cache files
225 | # files ending in .cache can be ignored
226 | *.[Cc]ache
227 | # but keep track of directories ending in .cache
228 | !?*.[Cc]ache/
229 |
230 | # Others
231 | ClientBin/
232 | ~$*
233 | *~
234 | *.dbmdl
235 | *.dbproj.schemaview
236 | *.jfm
237 | *.pfx
238 | *.publishsettings
239 | orleans.codegen.cs
240 |
241 | # Including strong name files can present a security risk
242 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
243 | #*.snk
244 |
245 | # Since there are multiple workflows, uncomment next line to ignore bower_components
246 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
247 | #bower_components/
248 |
249 | # RIA/Silverlight projects
250 | Generated_Code/
251 |
252 | # Backup & report files from converting an old project file
253 | # to a newer Visual Studio version. Backup files are not needed,
254 | # because we have git ;-)
255 | _UpgradeReport_Files/
256 | Backup*/
257 | UpgradeLog*.XML
258 | UpgradeLog*.htm
259 | ServiceFabricBackup/
260 | *.rptproj.bak
261 |
262 | # SQL Server files
263 | *.mdf
264 | *.ldf
265 | *.ndf
266 |
267 | # Business Intelligence projects
268 | *.rdl.data
269 | *.bim.layout
270 | *.bim_*.settings
271 | *.rptproj.rsuser
272 | *- [Bb]ackup.rdl
273 | *- [Bb]ackup ([0-9]).rdl
274 | *- [Bb]ackup ([0-9][0-9]).rdl
275 |
276 | # Microsoft Fakes
277 | FakesAssemblies/
278 |
279 | # GhostDoc plugin setting file
280 | *.GhostDoc.xml
281 |
282 | # Node.js Tools for Visual Studio
283 | .ntvs_analysis.dat
284 | node_modules/
285 |
286 | # Visual Studio 6 build log
287 | *.plg
288 |
289 | # Visual Studio 6 workspace options file
290 | *.opt
291 |
292 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
293 | *.vbw
294 |
295 | # Visual Studio LightSwitch build output
296 | **/*.HTMLClient/GeneratedArtifacts
297 | **/*.DesktopClient/GeneratedArtifacts
298 | **/*.DesktopClient/ModelManifest.xml
299 | **/*.Server/GeneratedArtifacts
300 | **/*.Server/ModelManifest.xml
301 | _Pvt_Extensions
302 |
303 | # Paket dependency manager
304 | .paket/paket.exe
305 | paket-files/
306 |
307 | # FAKE - F# Make
308 | .fake/
309 |
310 | # CodeRush personal settings
311 | .cr/personal
312 |
313 | # Python Tools for Visual Studio (PTVS)
314 | __pycache__/
315 | *.pyc
316 |
317 | # Cake - Uncomment if you are using it
318 | # tools/**
319 | # !tools/packages.config
320 |
321 | # Tabs Studio
322 | *.tss
323 |
324 | # Telerik's JustMock configuration file
325 | *.jmconfig
326 |
327 | # BizTalk build output
328 | *.btp.cs
329 | *.btm.cs
330 | *.odx.cs
331 | *.xsd.cs
332 |
333 | # OpenCover UI analysis results
334 | OpenCover/
335 |
336 | # Azure Stream Analytics local run output
337 | ASALocalRun/
338 |
339 | # MSBuild Binary and Structured Log
340 | *.binlog
341 |
342 | # NVidia Nsight GPU debugger configuration file
343 | *.nvuser
344 |
345 | # MFractors (Xamarin productivity tool) working folder
346 | .mfractor/
347 |
348 | # Local History for Visual Studio
349 | .localhistory/
350 |
351 | # BeatPulse healthcheck temp database
352 | healthchecksdb
353 |
354 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
355 | MigrationBackup/
356 |
357 | # Ionide (cross platform F# VS Code tools) working folder
358 | .ionide/
359 |
360 | # Fody - auto-generated XML schema
361 | FodyWeavers.xsd
362 |
363 | ## Visual Studio Code
364 | # Workspace
365 | .vscode/*
366 | !.vscode/settings.json
367 | !.vscode/tasks.json
368 | !.vscode/launch.json
369 | !.vscode/extensions.json
370 | *.code-workspace
371 |
372 | # Local History for Visual Studio Code
373 | .history/
374 |
375 | # Custom
376 | build*/
377 | *.pyd
378 | VTIL.egg-info/
379 | dist/
380 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "VTIL-Core"]
2 | path = external/core
3 | url = https://github.com/vtil-project/VTIL-Core
4 | [submodule "pybind11"]
5 | path = external/pybind11
6 | url = https://github.com/pybind/pybind11
7 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Require at least CMake version 3.15 or later for FetchContent
2 | cmake_minimum_required(VERSION 3.15)
3 |
4 | project(VTIL-Python)
5 |
6 | # Variables
7 | option(VTIL_PYTHON_VERSION "Version string" "dev")
8 |
9 | # Dependencies
10 | add_subdirectory(external/core)
11 | add_subdirectory(external/pybind11)
12 |
13 | # Hack to build with -fPIC on Linux
14 | if(UNIX AND NOT APPLE)
15 | target_compile_options(capstone-static PUBLIC -fPIC)
16 | endif()
17 |
18 | # Python module
19 | file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS
20 | src/*.cpp
21 | src/*.hpp
22 | )
23 |
24 | pybind11_add_module(${PROJECT_NAME} NO_EXTRAS ${SOURCES})
25 |
26 | source_group(TREE ${PROJECT_SOURCE_DIR} FILES ${SOURCES})
27 |
28 | target_compile_definitions(${PROJECT_NAME} PRIVATE VERSION_INFO="${VTIL_PYTHON_VERSION}")
29 |
30 | target_link_libraries(${PROJECT_NAME} PRIVATE VTIL)
31 |
32 | if(WIN32)
33 | set(EXTENSION ".pyd")
34 | else()
35 | set(EXTENSION ".so")
36 | endif()
37 |
38 | install(PROGRAMS
39 | $
40 | DESTINATION .
41 | COMPONENT pyd
42 | RENAME vtil${EXTENSION}
43 | )
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2020, Daniel (@L33T), VTIL Project
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | 1. Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | 2. Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | 3. Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
VTIL-Python
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | Virtual-machine Translation Intermediate Language - Python Bindings
23 |
24 |
25 |
26 | # Introduction
27 | // TODO..
28 |
29 | ## Building (CMake)
30 |
31 | Dependencies:
32 |
33 | - Python >=3.5 (x64)
34 | - Visual Studio 2019
35 | - CMake 3.15 or higher
36 |
37 | From a Visual Studio 2019 command prompt:
38 |
39 | ```
40 | mkdir build && cd build
41 | cmake -DPYTHON_EXECUTABLE=%PYTHON_PATH%\python.exe .. ; e.g. c:\Python37-64\python.exe
42 | cmake --build . --config Release
43 | cmake --install . --component pyd --prefix .
44 | ```
45 |
46 | This will give you `vtil.pyd` in the `build` directory.
47 |
--------------------------------------------------------------------------------
/VTIL-Python.licenseheader:
--------------------------------------------------------------------------------
1 | extensions: .hpp .cpp .h .c
2 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | // 2. Redistributions in binary form must reproduce the above copyright
11 | // notice, this list of conditions and the following disclaimer in the
12 | // documentation and/or other materials provided with the distribution.
13 | // 3. Neither the name of VTIL Project nor the names of its contributors
14 | // may be used to endorse or promote products derived from this software
15 | // without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 | //
--------------------------------------------------------------------------------
/VTIL-py.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30114.105
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VTIL-py", "VTIL-py.vcxproj", "{6FC9102F-66A9-4C23-92C7-E27BE8065108}"
7 | ProjectSection(ProjectDependencies) = postProject
8 | {8163E74C-DDE4-4507-BD3D-064CD95FF33B} = {8163E74C-DDE4-4507-BD3D-064CD95FF33B}
9 | {A79E2869-7626-4801-B09D-5C12F5163BA3} = {A79E2869-7626-4801-B09D-5C12F5163BA3}
10 | {F960486B-2DB4-44AF-91BB-0F19F228ABCF} = {F960486B-2DB4-44AF-91BB-0F19F228ABCF}
11 | {EC6B8F7F-730C-4086-B143-4664CC16DF8F} = {EC6B8F7F-730C-4086-B143-4664CC16DF8F}
12 | {FE3202CE-D05C-4E04-AE9B-D30305D8CE31} = {FE3202CE-D05C-4E04-AE9B-D30305D8CE31}
13 | EndProjectSection
14 | EndProject
15 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VTIL", "external\core\VTIL\VTIL.vcxproj", "{8163E74C-DDE4-4507-BD3D-064CD95FF33B}"
16 | EndProject
17 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VTIL-Architecture", "external\core\VTIL-Architecture\VTIL-Architecture.vcxproj", "{A79E2869-7626-4801-B09D-5C12F5163BA3}"
18 | EndProject
19 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VTIL-Common", "external\core\VTIL-Common\VTIL-Common.vcxproj", "{EC6B8F7F-730C-4086-B143-4664CC16DF8F}"
20 | EndProject
21 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VTIL-Compiler", "external\core\VTIL-Compiler\VTIL-Compiler.vcxproj", "{F960486B-2DB4-44AF-91BB-0F19F228ABCF}"
22 | EndProject
23 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VTIL-SymEx", "external\core\VTIL-SymEx\VTIL-SymEx.vcxproj", "{FE3202CE-D05C-4E04-AE9B-D30305D8CE31}"
24 | EndProject
25 | Global
26 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
27 | Debug|x64 = Debug|x64
28 | Release|x64 = Release|x64
29 | EndGlobalSection
30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
31 | {6FC9102F-66A9-4C23-92C7-E27BE8065108}.Debug|x64.ActiveCfg = Debug|x64
32 | {6FC9102F-66A9-4C23-92C7-E27BE8065108}.Debug|x64.Build.0 = Debug|x64
33 | {6FC9102F-66A9-4C23-92C7-E27BE8065108}.Release|x64.ActiveCfg = Release|x64
34 | {6FC9102F-66A9-4C23-92C7-E27BE8065108}.Release|x64.Build.0 = Release|x64
35 | {8163E74C-DDE4-4507-BD3D-064CD95FF33B}.Debug|x64.ActiveCfg = Debug|x64
36 | {8163E74C-DDE4-4507-BD3D-064CD95FF33B}.Debug|x64.Build.0 = Debug|x64
37 | {8163E74C-DDE4-4507-BD3D-064CD95FF33B}.Release|x64.ActiveCfg = Release|x64
38 | {8163E74C-DDE4-4507-BD3D-064CD95FF33B}.Release|x64.Build.0 = Release|x64
39 | {A79E2869-7626-4801-B09D-5C12F5163BA3}.Debug|x64.ActiveCfg = Debug|x64
40 | {A79E2869-7626-4801-B09D-5C12F5163BA3}.Debug|x64.Build.0 = Debug|x64
41 | {A79E2869-7626-4801-B09D-5C12F5163BA3}.Release|x64.ActiveCfg = Release|x64
42 | {A79E2869-7626-4801-B09D-5C12F5163BA3}.Release|x64.Build.0 = Release|x64
43 | {EC6B8F7F-730C-4086-B143-4664CC16DF8F}.Debug|x64.ActiveCfg = Debug|x64
44 | {EC6B8F7F-730C-4086-B143-4664CC16DF8F}.Debug|x64.Build.0 = Debug|x64
45 | {EC6B8F7F-730C-4086-B143-4664CC16DF8F}.Release|x64.ActiveCfg = Release|x64
46 | {EC6B8F7F-730C-4086-B143-4664CC16DF8F}.Release|x64.Build.0 = Release|x64
47 | {F960486B-2DB4-44AF-91BB-0F19F228ABCF}.Debug|x64.ActiveCfg = Debug|x64
48 | {F960486B-2DB4-44AF-91BB-0F19F228ABCF}.Debug|x64.Build.0 = Debug|x64
49 | {F960486B-2DB4-44AF-91BB-0F19F228ABCF}.Release|x64.ActiveCfg = Release|x64
50 | {F960486B-2DB4-44AF-91BB-0F19F228ABCF}.Release|x64.Build.0 = Release|x64
51 | {FE3202CE-D05C-4E04-AE9B-D30305D8CE31}.Debug|x64.ActiveCfg = Debug|x64
52 | {FE3202CE-D05C-4E04-AE9B-D30305D8CE31}.Debug|x64.Build.0 = Debug|x64
53 | {FE3202CE-D05C-4E04-AE9B-D30305D8CE31}.Release|x64.ActiveCfg = Release|x64
54 | {FE3202CE-D05C-4E04-AE9B-D30305D8CE31}.Release|x64.Build.0 = Release|x64
55 | EndGlobalSection
56 | GlobalSection(SolutionProperties) = preSolution
57 | HideSolutionNode = FALSE
58 | EndGlobalSection
59 | GlobalSection(ExtensibilityGlobals) = postSolution
60 | SolutionGuid = {544DC62D-9EC6-4D17-993D-386C63BAB31A}
61 | EndGlobalSection
62 | EndGlobal
63 |
--------------------------------------------------------------------------------
/VTIL-py.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | x64
7 |
8 |
9 | Release
10 | x64
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 | {a79e2869-7626-4801-b09d-5c12f5163ba3}
40 |
41 |
42 | {ec6b8f7f-730c-4086-b143-4664cc16df8f}
43 |
44 |
45 | {f960486b-2db4-44af-91bb-0f19f228abcf}
46 |
47 |
48 | {fe3202ce-d05c-4e04-ae9b-d30305d8ce31}
49 |
50 |
51 | {8163e74c-dde4-4507-bd3d-064cd95ff33b}
52 |
53 |
54 |
55 |
56 |
57 |
58 | 16.0
59 | Win32Proj
60 | {6fc9102f-66a9-4c23-92c7-e27be8065108}
61 | VTILpy
62 | 10.0
63 |
64 |
65 |
66 | DynamicLibrary
67 | true
68 | v142
69 | Unicode
70 |
71 |
72 | DynamicLibrary
73 | false
74 | v142
75 | true
76 | Unicode
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 | true
92 | .pyd
93 | $(SolutionDir)build\$(Platform)\$(Configuration)\
94 | vtil
95 |
96 |
97 | false
98 | .pyd
99 | vtil
100 | $(SolutionDir)build\$(Platform)\$(Configuration)\
101 | build\$(Platform)\$(Configuration)\
102 |
103 |
104 |
105 | Level3
106 |
107 |
108 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
109 | true
110 | stdcpplatest
111 | %PYTHON_PATH%\include;$(ProjectDir)external\pybind11\include;$(ProjectDir)external\core\Keystone\include;$(ProjectDir)external\core\Capstone\include;$(ProjectDir)external\core\VTIL\includes;$(ProjectDir)external\core\VTIL-Architecture\includes;$(ProjectDir)external\core\VTIL-Common\includes;$(ProjectDir)external\core\VTIL-Compiler\includes;$(ProjectDir)external\core\VTIL-SymEx\includes;%(AdditionalIncludeDirectories)
112 | MultiThreadedDLL
113 | false
114 | /bigobj %(AdditionalOptions)
115 |
116 |
117 | Console
118 | true
119 | %PYTHON_PATH%\libs;$(ProjectDir)external\core\x64\Release;$(ProjectDir)external\core\Keystone\llvm\lib\Release;$(ProjectDir)external\core\Capstone\msvc\x64\Release;%(AdditionalLibraryDirectories)
120 | VTIL-Architecture.lib;VTIL-Common.lib;VTIL-Compiler.lib;VTIL.lib;VTIL-SymEx.lib;keystone.lib;capstone.lib;%(AdditionalDependencies)
121 |
122 |
123 |
124 |
125 | Level3
126 | true
127 | true
128 |
129 |
130 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
131 | true
132 | false
133 | %PYTHON_PATH%\include;$(ProjectDir)external\pybind11\include;$(ProjectDir)external\core\Keystone\include;$(ProjectDir)external\core\Capstone\include;$(ProjectDir)external\core\VTIL\includes;$(ProjectDir)external\core\VTIL-Architecture\includes;$(ProjectDir)external\core\VTIL-Common\includes;$(ProjectDir)external\core\VTIL-Compiler\includes;$(ProjectDir)external\core\VTIL-SymEx\includes;%(AdditionalIncludeDirectories)
134 | stdcpplatest
135 | AdvancedVectorExtensions
136 | 26444;%(DisableSpecificWarnings)
137 |
138 |
139 | Console
140 | true
141 | true
142 | true
143 | VTIL-Architecture.lib;VTIL-Common.lib;VTIL-Compiler.lib;VTIL.lib;VTIL-SymEx.lib;keystone.lib;capstone.lib;%(AdditionalDependencies)
144 | %PYTHON_PATH%\libs;$(ProjectDir)external\core\x64\Release;$(ProjectDir)external\core\Keystone\llvm\lib\Release;$(ProjectDir)external\core\Capstone\msvc\x64\Release;%(AdditionalLibraryDirectories)
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
--------------------------------------------------------------------------------
/VTIL-py.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {82ce09c5-f77f-40a4-9771-7527a90d0783}
6 |
7 |
8 | {099d0e0f-8cf0-47c2-a677-2b60a41703bb}
9 |
10 |
11 | {7e8b60b5-facc-4350-95a2-43d18c594041}
12 |
13 |
14 | {d378e1ac-c26d-4f46-9ff0-5881bf084d41}
15 |
16 |
17 | {8276c7a4-81d0-4e18-991a-313cae4c1c3c}
18 |
19 |
20 | {1ea0d256-2e86-43b7-be66-9fb8976864a3}
21 |
22 |
23 | {b64487cc-ccae-4d38-968b-c292a81c77c4}
24 |
25 |
26 | {283abd6f-0713-490f-b44c-095dcfe6a201}
27 |
28 |
29 | {7283022a-283f-462d-ad79-9dcc25e09412}
30 |
31 |
32 | {5ae7a57f-4b64-4370-baff-7052eb00787a}
33 |
34 |
35 | {ff1f2b7f-a133-4499-aba5-c355002c9962}
36 |
37 |
38 | {9c30f849-7662-43f0-9259-40b5f4bc9282}
39 |
40 |
41 | {eda72da3-7790-4203-82b4-86fc602dc30e}
42 |
43 |
44 | {0375c24d-cc5d-4939-95d2-e89df62fe4c5}
45 |
46 |
47 | {4c8f81a1-f7b4-4449-89b3-a0006a6f61ab}
48 |
49 |
50 | {1de51ff6-cad3-478d-a58b-906d14f18477}
51 |
52 |
53 | {9b496201-5d7c-44f0-9797-c79ab8d839ee}
54 |
55 |
56 | {1e1a885e-731c-4180-88c1-ff7f62e05782}
57 |
58 |
59 | {15e578a8-350c-4af2-bd7f-89d1789639f4}
60 |
61 |
62 | {a0fc7009-6593-43c3-a2fa-21085aa2cdd5}
63 |
64 |
65 | {b5c7fe1c-c834-4a9d-95a8-621965fcfe01}
66 |
67 |
68 | {6b185552-7cfb-4f5d-b2c1-ae8eea8f9b72}
69 |
70 |
71 |
72 |
73 | External
74 |
75 |
76 | Architecture\Architecture
77 |
78 |
79 | Architecture\Instruction Stream
80 |
81 |
82 | Architecture\SymEx Integration
83 |
84 |
85 | Architecture\Value Tracing
86 |
87 |
88 | Common\Utility
89 |
90 |
91 | SymEx\Expressions
92 |
93 |
94 | SymEx\Expressions
95 |
96 |
97 | External
98 |
99 |
100 | Architecture\Instruction Stream
101 |
102 |
103 | Architecture\Instruction Stream
104 |
105 |
106 | Architecture\Architecture
107 |
108 |
109 | Architecture\Architecture
110 |
111 |
112 | Architecture\Architecture
113 |
114 |
115 | Architecture\Instruction Stream
116 |
117 |
118 | Architecture\Miscellaneous
119 |
120 |
121 | Architecture\Value Tracing
122 |
123 |
124 | Compiler\Common
125 |
126 |
127 | Common\Utility
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | version: 0.0.{build}
2 |
3 | environment:
4 | matrix:
5 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
6 | PYTHON: C:\Python38-x64
7 | SDIST: true
8 |
9 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
10 | PYTHON: C:\Python38-x64
11 | BUILD: true
12 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
13 | PYTHON: C:\Python37-x64
14 | BUILD: true
15 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
16 | PYTHON: C:\Python36-x64
17 | BUILD: true
18 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
19 | PYTHON: C:\Python35-x64
20 | BUILD: true
21 |
22 | - APPVEYOR_BUILD_WORKER_IMAGE: macos
23 | PYTHON: venv3.9
24 | BUILD: true
25 | - APPVEYOR_BUILD_WORKER_IMAGE: macos
26 | PYTHON: venv3.8
27 | BUILD: true
28 | - APPVEYOR_BUILD_WORKER_IMAGE: macos
29 | PYTHON: venv3.7
30 | BUILD: true
31 | - APPVEYOR_BUILD_WORKER_IMAGE: macos
32 | PYTHON: venv3.6
33 | BUILD: true
34 | - APPVEYOR_BUILD_WORKER_IMAGE: macos
35 | PYTHON: venv3.5
36 | BUILD: true
37 |
38 | matrix:
39 | fast_finish: true
40 |
41 | for:
42 | -
43 | matrix:
44 | only:
45 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
46 | SDIST: true
47 | build_script:
48 | - cmd: "%PYTHON%\\python.exe setup.py sdist"
49 | artifacts:
50 | - path: dist\*
51 |
52 | -
53 | matrix:
54 | only:
55 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
56 | BUILD: true
57 | install:
58 | - cmd: "%PYTHON%\\python.exe -m pip install --user --upgrade setuptools wheel -r requirements.txt"
59 | build_script:
60 | - cmd: "%PYTHON%\\python.exe setup.py bdist_wheel"
61 | artifacts:
62 | - path: dist\*
63 |
64 | -
65 | matrix:
66 | only:
67 | - APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu
68 | BUILD: true
69 | install:
70 | - sh: sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
71 | - sh: sudo apt update
72 | - sh: sudo apt -y install gcc-10 g++-10
73 | - sh: "$HOME/$PYTHON/bin/python -m pip install --upgrade setuptools wheel -r requirements.txt"
74 | - sh: export CC=/usr/bin/gcc-10
75 | - sh: export CXX=/usr/bin/g++-10
76 | build_script:
77 | - sh: "$HOME/$PYTHON/bin/python setup.py bdist_wheel"
78 | artifacts:
79 | - path: dist/*
80 |
81 | -
82 | matrix:
83 | only:
84 | - APPVEYOR_BUILD_WORKER_IMAGE: macos
85 | BUILD: true
86 | install:
87 | - sh: brew install llvm@10 ninja
88 | - sh: "~/$PYTHON/bin/python -m pip install --upgrade setuptools wheel -r requirements.txt"
89 | - sh: export CC=/usr/local/opt/llvm/bin/clang
90 | - sh: export CXX=/usr/local/opt/llvm/bin/clang++
91 | - sh: export LDFLAGS="-L/usr/local/opt/llvm/lib -W1,-rpath,/usr/local/opt/llvm/lib"
92 | build_script:
93 | - sh: "~/$PYTHON/bin/python setup.py bdist_wheel"
94 | artifacts:
95 | - path: dist/*
96 |
--------------------------------------------------------------------------------
/examples/arm64/tracer.py:
--------------------------------------------------------------------------------
1 | from vtil import *
2 |
3 |
4 | def main():
5 | bbl = BasicBlock(0, ArchID.arm64)
6 | t0, zf = bbl.tmp(32, 1)
7 | x0, x1 = ARM64.X0, ARM64.X1
8 | sp = RegisterDesc.SP
9 |
10 | bbl.mov(x0, 100) \
11 | .push(x0) \
12 | .mov(x1, x0) \
13 | .push(x1) \
14 | .ldd(t0, sp, 4) \
15 | .add(t0, 100) \
16 | .store(sp, 4, t0)\
17 | .pop(x1) \
18 | .pop(x0) \
19 | .mov(x0, x1) \
20 | .mov(t0, x0) \
21 | .sub(t0, 100) \
22 | .te(zf, t0, 0)
23 |
24 | bbl_tracer = tracer()
25 | print('jz taken: {}'.format(bbl_tracer(variable(bbl.end(), zf))))
26 |
27 |
28 | if __name__ == '__main__':
29 | main()
30 |
--------------------------------------------------------------------------------
/examples/compiler_interface.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vtil-project/VTIL-Python/f3599e8d0f12f84b401c151b5b0a516adacc108a/examples/compiler_interface.py
--------------------------------------------------------------------------------
/examples/routine.py:
--------------------------------------------------------------------------------
1 | from vtil import *
2 |
3 |
4 | def on_block(bbl: BasicBlock) -> TaggedOrder:
5 | print(bbl)
6 | return Enumerator.obreak
7 |
8 |
9 | def main():
10 | rtn = Routine.load('hello_world.vtil')
11 | rtn.for_each(on_block, tagged=False)
12 | rtn.for_each(on_block, tagged=True)
13 |
14 |
15 | if __name__ == '__main__':
16 | main()
17 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | cmake>=3.15
2 | cmake-generators
3 | GitPython
4 | future_fstrings
5 | pybind11
6 |
--------------------------------------------------------------------------------
/setup.cfg:
--------------------------------------------------------------------------------
1 | [bdist_wheel]
2 | universal=1
3 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | #! /usr/bin/python3
2 | from setuptools import setup, Extension
3 | from setuptools.command.build_ext import build_ext
4 | from setuptools.command.install_lib import install_lib
5 | from distutils.command.build import build
6 | from distutils.command.sdist import sdist
7 | from distutils.dir_util import copy_tree
8 | import platform
9 | import sys
10 | import os
11 |
12 |
13 | VERSION = '0.0.3'
14 | CORE_COMMIT = 'c13dbc0'
15 | PYBIND11_COMMIT = 'd54d6d8'
16 |
17 |
18 | class CMakeExtension(Extension):
19 | def __init__(self, name, src_dir, additional=None, sources=None):
20 | if not sources:
21 | sources = []
22 | for dir_path, _, files in os.walk(src_dir):
23 | for file_name in files:
24 | sources.append(os.path.join(dir_path, file_name))
25 | if additional:
26 | sources.extend(additional)
27 |
28 | super().__init__(name=name, sources=sources)
29 |
30 |
31 | class InstallCMakeLibs(install_lib):
32 | def run(self):
33 | self.skip_build = os.path.exists('build/vtil.pyd')
34 | super().run()
35 |
36 |
37 | class BuildVTIL(build):
38 | def run(self):
39 | self.run_command("build_ext")
40 | super().run()
41 |
42 |
43 | class PackageVTIL(sdist):
44 | def run(self):
45 | # Packaging VTIL doesn't require the build sources.
46 | self.distribution.package_data = {}
47 | self.distribution.packages = []
48 | super().run()
49 |
50 |
51 | class BuildCMakeExtension(build_ext):
52 | def run(self):
53 | for extension in self.extensions:
54 | if extension.name == 'VTIL':
55 | self.build()
56 |
57 | def build(self):
58 | import git
59 |
60 | # Remove old build
61 | if not os.path.exists('build/vtil.pyd'):
62 | os.makedirs('build/lib', exist_ok=True)
63 |
64 | # Update submodules
65 | self.announce('Updating submodules ..')
66 | if os.path.exists('.git'):
67 | # We are running from a cloned version
68 | git.Repo('.').submodule_update(init=True, recursive=False)
69 | else:
70 | # We are running from a pypi tar.gz version
71 | if not os.path.exists('external/core'):
72 | git.Repo.clone_from('https://github.com/vtil-project/VTIL-Core.git', 'external/core').git.checkout(CORE_COMMIT)
73 | if not os.path.exists('external/pybind11'):
74 | git.Repo.clone_from('https://github.com/pybind/pybind11.git', 'external/pybind11').git.checkout(PYBIND11_COMMIT)
75 |
76 | self.announce('Preparing build for platform ..', level=3)
77 | self.spawn(self.build_for_platform())
78 |
79 | self.announce('Building ..', level=3)
80 | self.spawn(self.build_cmake())
81 |
82 | self.announce('Generating libs ..', level=3)
83 | self.spawn(self.gen_libs())
84 |
85 | self.announce('Copying wrappers ..', level=3)
86 | copy_tree("src/wrappers", "vtil")
87 |
88 | @staticmethod
89 | def build_for_platform():
90 | extras = []
91 | if platform.system() == 'Windows':
92 | import cmakegenerators
93 |
94 | if 'Visual Studio 16 2019' not in [gen.name for gen in cmakegenerators.get_generators()]:
95 | raise Exception('Visual Studio 2019 not found')
96 |
97 | extras = ['-G', 'Visual Studio 16 2019']
98 |
99 | return \
100 | [
101 | 'cmake',
102 | '-DPYTHON_EXECUTABLE=' + sys.executable,
103 | '-DVTIL_PYTHON_VERSION=' + VERSION,
104 | '-S', '.',
105 | '-B', 'build'
106 | ] + extras
107 |
108 | @staticmethod
109 | def build_cmake():
110 | return \
111 | [
112 | 'cmake',
113 | '--build', 'build',
114 | '--config', 'Release'
115 | ]
116 |
117 | @staticmethod
118 | def gen_libs():
119 | return \
120 | [
121 | "cmake",
122 | "--install", "build",
123 | "--component", "pyd",
124 | "--prefix", "vtil"
125 | ]
126 |
127 |
128 | setup(
129 | name='VTIL',
130 | version=VERSION,
131 | author='Daniel. (@L33T)',
132 | description='Virtual-machine Translation Intermediate Language',
133 | long_description='VTIL Project, standing for Virtual-machine Translation Intermediate Language, is a set of tools'
134 | ' designed around an optimizing compiler to be used for binary de-obfuscation and'
135 | ' de-virtualization.\n\nThe main difference between VTIL and other optimizing compilers such as '
136 | 'LLVM is that it has an extremely versatile IL that makes it trivial to lift from any'
137 | ' architecture including stack machines. Since it is built for translation, VTIL does not abstract'
138 | ' away the native ISA and keeps the concept of the stack, physical registers, and the non-SSA'
139 | ' architecture of a general-purpose CPU as is. Native instructions can be emitted in the middle '
140 | 'of the IL stream and the physical registers can be addressed from VTIL instructions freely.\n\n'
141 | 'VTIL also makes it trivial to emit code back into the native format at any virtual address'
142 | ' requested without being constrained to a specific file format.',
143 | url='https://github.com/vtil-project/VTIL-Python',
144 | classifiers=[
145 | 'Programming Language :: Python :: 3.4',
146 | 'Programming Language :: Python :: 3.5',
147 | 'Programming Language :: Python :: 3.6',
148 | 'Programming Language :: Python :: 3.7',
149 | 'Programming Language :: Python :: 3.8',
150 | 'Programming Language :: Python :: 3.9',
151 | 'Development Status :: 3 - Alpha',
152 | 'Natural Language :: English',
153 | 'Operating System :: MacOS',
154 | 'Operating System :: POSIX :: Linux',
155 | 'Operating System :: Microsoft :: Windows',
156 | 'Programming Language :: C++',
157 | 'Topic :: Education'
158 | ],
159 | python_requires='>=3.4',
160 | license='BSD 3-Clause "New" or "Revised" License',
161 | cmdclass={
162 | 'sdist': PackageVTIL,
163 | 'build': BuildVTIL,
164 | 'build_ext': BuildCMakeExtension,
165 | 'install_lib': InstallCMakeLibs
166 | },
167 | setup_requires=['cmake>=3.15', 'cmake-generators', 'GitPython', 'future_fstrings'],
168 | install_requires=['pybind11'],
169 | ext_modules=[CMakeExtension('VTIL', src_dir='src', additional=['LICENSE.md', 'CMakeLists.txt'])],
170 | keywords='VTIL, VTIL Project, vtil, Virtual-machine Translation Intermediate Language, '
171 | 'Translation Intermediate Language, Intermediate Language',
172 | zip_safe=True,
173 | packages=['vtil'],
174 | package_data={
175 | 'vtil': ['vtil.pyd', 'vtil.so', '*.py', '**/*.py'],
176 | }
177 | )
178 |
--------------------------------------------------------------------------------
/src/architecture/arch/identifier.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | identifier.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 |
44 | using namespace vtil;
45 | namespace py = pybind11;
46 |
47 |
48 | namespace vtil::python
49 | {
50 | class architecture_identifier_py : public py::enum_
51 | {
52 | public:
53 | architecture_identifier_py( const handle& scope, const char* name )
54 | : enum_( scope, name )
55 | {
56 | ( *this )
57 | .value( "amd64", architecture_identifier::architecture_amd64 )
58 | .value( "arm64", architecture_identifier::architecture_arm64 )
59 | .value( "virtual", architecture_identifier::architecture_virtual );
60 | }
61 | };
62 | }
63 |
--------------------------------------------------------------------------------
/src/architecture/arch/instruction_desc.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | instruction_desc.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 | #include
44 |
45 | using namespace vtil;
46 | namespace py = pybind11;
47 |
48 |
49 | namespace vtil::python
50 | {
51 | class instruction_desc_py : public py::class_
52 | {
53 | public:
54 | instruction_desc_py( const handle& scope, const char* name )
55 | : class_( scope, name )
56 | {
57 | py::enum_( scope, "operand_type" )
58 | .value( "invalid", operand_type::invalid )
59 |
60 | .value( "read_imm", operand_type::read_imm )
61 | .value( "read_reg", operand_type::read_reg )
62 | .value( "read_any", operand_type::read_any ).value( "read", operand_type::read_any )
63 |
64 | .value( "write", operand_type::write )
65 | .value( "readwrite", operand_type::readwrite )
66 | ;
67 |
68 | ( *this )
69 | // Properties
70 | //
71 | .def_readonly( "name", &instruction_desc::name )
72 | .def_readonly( "operand_types", &instruction_desc::operand_types )
73 | .def_readonly( "is_volatile", &instruction_desc::is_volatile )
74 | .def_readonly( "symbolic_operator", &instruction_desc::symbolic_operator )
75 | .def_readonly( "branch_operands_rip", &instruction_desc::branch_operands_rip )
76 | .def_readonly( "branch_operands_vip", &instruction_desc::branch_operands_vip )
77 | .def_readonly( "memory_operand_index", &instruction_desc::memory_operand_index )
78 | .def_readonly( "memory_write", &instruction_desc::memory_write )
79 | .def_readonly( "is_volatile", &instruction_desc::is_volatile )
80 |
81 | // Functions
82 | //
83 | .def( "operand_count", &instruction_desc::operand_count )
84 |
85 | .def( "is_branching_virt", &instruction_desc::is_branching_virt )
86 | .def( "is_branching_real", &instruction_desc::is_branching_real )
87 | .def( "is_branching", &instruction_desc::is_branching )
88 |
89 | .def( "reads_memory", &instruction_desc::reads_memory )
90 | .def( "writes_memory", &instruction_desc::writes_memory )
91 | .def( "accesses_memory", &instruction_desc::accesses_memory )
92 |
93 | .def( "reduce", py::overload_cast< >( &instruction_desc::reduce ) )
94 |
95 | .def( "__repr__", &instruction_desc::to_string )
96 | .def( "__str__", &instruction_desc::to_string )
97 | .def( py::self == py::self )
98 | .def( py::self != py::self )
99 | .def( py::self < py::self )
100 |
101 | // End
102 | //
103 | ;
104 | }
105 | };
106 | }
107 |
--------------------------------------------------------------------------------
/src/architecture/arch/operands.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | operands.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 |
44 | using namespace vtil;
45 | namespace py = pybind11;
46 |
47 |
48 | namespace vtil::python
49 | {
50 | class operand_py : public py::class_
51 | {
52 | public:
53 | operand_py( const handle& scope, const char* name )
54 | : class_( scope, name )
55 | {
56 | py::class_( scope, "operand::immediate_t" )
57 | // Constructor
58 | //
59 | .def( py::init<>() )
60 | .def( py::init() )
61 |
62 | // Properties
63 | //
64 | .def_readwrite( "i64", &operand::immediate_t::i64 )
65 | .def_readwrite( "u64", &operand::immediate_t::u64 )
66 |
67 | .def_readwrite( "bit_count", &operand::immediate_t::bit_count )
68 |
69 | // Functions
70 | //
71 | .def( "reduce", py::overload_cast< >( &operand::immediate_t::reduce ) )
72 | ;
73 |
74 | ( *this )
75 | // Properties
76 | //
77 | .def_readwrite( "descriptor", &operand::descriptor )
78 |
79 | // Functions
80 | //
81 | .def( "imm", py::overload_cast< >( &operand::imm ) )
82 | .def( "reg", py::overload_cast< >( &operand::reg ) )
83 |
84 | .def( "size", &operand::size )
85 | .def( "bit_count", &operand::bit_count )
86 |
87 | .def( "is_register", &operand::is_register )
88 | .def( "is_immediate", &operand::is_immediate )
89 | .def( "is_valid", &operand::is_valid )
90 |
91 | .def( "reduce", py::overload_cast< >( &operand::reduce ) )
92 |
93 | .def( "__str__", &operand::to_string )
94 | .def( "__repr__", &operand::to_string )
95 |
96 | // End
97 | //
98 | ;
99 | }
100 | };
101 | }
102 |
103 | namespace pybind11::detail
104 | {
105 | template<> struct type_caster : public type_caster_base
106 | {
107 | using base = type_caster_base;
108 |
109 | template
110 | bool explicit_cast( handle src )
111 | {
112 | return py::isinstance( src ) && ( this->value = new operand( py::cast( src ) ) );
113 | }
114 |
115 | public:
116 | bool load( handle src, bool convert )
117 | {
118 | if ( py::isinstance( src ) )
119 | {
120 | auto value = py::cast( src );
121 | this->value = new operand( value, sizeof( value ) * 8 );
122 | return true;
123 | }
124 |
125 | return explicit_cast< arm64_reg >( src ) || explicit_cast< x86_reg >( src ) || explicit_cast< register_desc >( src );
126 | }
127 |
128 | static handle cast( operand* src, return_value_policy policy, handle parent )
129 | {
130 | return base::cast( src, policy, parent );
131 | }
132 |
133 | static handle cast( const operand* src, return_value_policy policy, handle parent )
134 | {
135 | return base::cast( src, policy, parent );
136 | }
137 |
138 | static handle cast( operand& src, return_value_policy policy, handle parent )
139 | {
140 | return base::cast( src, policy, parent );
141 | }
142 |
143 | static handle cast( const operand& src, return_value_policy policy, handle parent )
144 | {
145 | return base::cast( src, policy, parent );
146 | }
147 | };
148 | }
149 |
--------------------------------------------------------------------------------
/src/architecture/arch/register_desc.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | register_desc.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 |
44 | using namespace vtil;
45 | namespace py = pybind11;
46 |
47 |
48 | namespace vtil::python
49 | {
50 | class register_desc_py : public py::class_
51 | {
52 | public:
53 | register_desc_py( const handle& scope, const char* name )
54 | : class_( scope, name )
55 | {
56 | ( *this )
57 | // Static
58 | //
59 | .def_property_readonly_static( "SP", [ ] ( const py::object& ) { return REG_SP; } )
60 | .def_property_readonly_static( "FLAGS", [ ] ( const py::object& ) { return REG_FLAGS; } )
61 | .def_property_readonly_static( "IMGBASE", [ ] ( const py::object& ) { return REG_IMGBASE; } )
62 |
63 | // Properties
64 | //
65 | .def_readwrite( "flags", ®ister_desc::flags )
66 | .def_readwrite( "combined_id", ®ister_desc::combined_id )
67 | .def_readwrite( "bit_count", ®ister_desc::bit_count )
68 | .def_readwrite( "bit_offset", ®ister_desc::bit_offset )
69 |
70 | // Functions
71 | //
72 | .def( "is_valid", ®ister_desc::is_valid )
73 | .def( "is_flags", ®ister_desc::is_flags )
74 | .def( "is_undefined", ®ister_desc::is_undefined )
75 | .def( "is_local", ®ister_desc::is_local )
76 | .def( "is_global", ®ister_desc::is_global )
77 | .def( "is_virtual", ®ister_desc::is_virtual )
78 | .def( "is_physical", ®ister_desc::is_physical )
79 | .def( "is_volatile", ®ister_desc::is_volatile )
80 | .def( "is_read_only", ®ister_desc::is_read_only )
81 | .def( "is_stack_pointer", ®ister_desc::is_stack_pointer )
82 | .def( "is_image_base", ®ister_desc::is_image_base )
83 | .def( "is_special", ®ister_desc::is_special )
84 | .def( "is_internal", ®ister_desc::is_internal )
85 |
86 | .def( "get_mask", ®ister_desc::get_mask )
87 | .def( "overlaps", ®ister_desc::overlaps )
88 | .def( "to_string", ®ister_desc::to_string )
89 |
90 | .def( "reduce", py::overload_cast< >( ®ister_desc::reduce ) )
91 |
92 | .def( "__repr__", ®ister_desc::to_string )
93 | .def( "__str__", ®ister_desc::to_string )
94 |
95 | // End
96 | //
97 | ;
98 | }
99 | };
100 | }
101 |
--------------------------------------------------------------------------------
/src/architecture/misc/debug.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | debug.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 | #include
44 |
45 | using namespace vtil::debug;
46 | namespace py = pybind11;
47 |
48 |
49 | namespace vtil::python
50 | {
51 | struct debug_dummy_py
52 | {
53 | // Dummy debug struct
54 | //
55 | };
56 |
57 | class debug_py : public py::class_
58 | {
59 | public:
60 | debug_py( const handle& scope, const char* name )
61 | : class_( scope, name )
62 | {
63 | ( *this )
64 | // Static helpers
65 | //
66 | .def( "dump", py::overload_cast< const instruction&, const instruction* >( &dump ) )
67 | .def( "dump", py::overload_cast< const basic_block*, std::set* >( &dump ) )
68 | .def( "dump", py::overload_cast< const routine* >( &dump ) )
69 |
70 | // End
71 | //
72 | ;
73 | }
74 | };
75 | }
--------------------------------------------------------------------------------
/src/architecture/routine/basic_block.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | basic_block.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 |
44 | using namespace vtil;
45 | namespace py = pybind11;
46 |
47 |
48 | namespace vtil::python
49 | {
50 | class basic_block_py : public py::class_
51 | {
52 | public:
53 | basic_block_py( const handle& scope, const char* name )
54 | : class_( scope, name )
55 | {
56 | // Related
57 | //
58 | py::class_( scope, "il_iterator" )
59 | .def( "get", [ ] ( const il_iterator& it ) { return *it; } );
60 | py::class_( scope, "il_const_iterator" )
61 | .def( "get", [ ] ( const il_const_iterator& it ) { return *it; } );
62 |
63 | ( *this )
64 | // Constructor
65 | //
66 | .def( py::init( py::overload_cast< vip_t, vtil::architecture_identifier >( &basic_block::begin ) ), py::arg("entry_vip"), py::arg("arch_id") = architecture_amd64 )
67 |
68 | // Properties
69 | //
70 | .def_readwrite( "owner", &basic_block::owner )
71 | .def_readwrite( "entry_vip", &basic_block::entry_vip )
72 | .def_readwrite( "prev", &basic_block::prev )
73 | .def_readwrite( "next", &basic_block::next )
74 | .def_readwrite( "sp_index", &basic_block::sp_index )
75 | .def_readwrite( "sp_offset", &basic_block::sp_offset )
76 | .def_readwrite( "last_temporary_index", &basic_block::last_temporary_index )
77 | .def_readwrite( "label_stack", &basic_block::label_stack )
78 | .def_readwrite( "context", &basic_block::context )
79 | .def_readwrite( "epoch", &basic_block::epoch )
80 |
81 | // Functions
82 | //
83 | .def( "fork", &basic_block::fork )
84 |
85 | .def( "label_end", &basic_block::label_end )
86 | .def( "label_begin", &basic_block::label_begin )
87 |
88 | .def( "is_complete", &basic_block::is_complete )
89 |
90 | .def( "hash", &basic_block::hash )
91 |
92 | .def( "tmp", [ ] ( basic_block& bbl, bitcnt_t size ) { return bbl.tmp( size ); } )
93 | .def( "tmp", &tmp_helper )
94 |
95 | .def( "vsfence", &basic_block::vsfence )
96 | .def( "vlfence", &basic_block::vlfence )
97 | .def( "vmfence", &basic_block::vmfence )
98 |
99 | .def( "shift_sp", &basic_block::shift_sp )
100 | .def( "vemits", &basic_block::vemits )
101 | .def( "push", [ ] ( basic_block& bbl, const operand& op ) { return bbl.push( op ); } )
102 | .def( "pop", [ ] ( basic_block& bbl, const operand& op ) { return bbl.pop( op ); } )
103 | .def( "pushf", &basic_block::pushf )
104 | .def( "popf", &basic_block::popf )
105 |
106 | .def("empty", &basic_block::empty)
107 | .def( "size", &basic_block::size )
108 | .def( "back", &basic_block::back )
109 | .def( "front", &basic_block::front )
110 | .def( "wback", &basic_block::wback )
111 | .def( "wfront", &basic_block::wfront )
112 | .def( "begin", py::overload_cast< >( &basic_block::begin ) )
113 | .def( "end", py::overload_cast< >( &basic_block::end ) )
114 |
115 | .def( "insert", &basic_block::insert )
116 | .def( "push_back", [ ] ( basic_block& bbl, instruction& inst ) { return bbl.push_back( inst ); } )
117 | .def( "push_front", [ ] ( basic_block& bbl, instruction& inst ) { return bbl.push_front( inst ); } )
118 | //.def( "emplace", &emplace_helper )
119 | //.def( "emplace_back", &emplace_back_helper )
120 | //.def( "emplace_front", &emplace_front_helper )
121 |
122 | .def( "np_insert", &basic_block::np_insert )
123 | .def( "np_push_back", [ ] ( basic_block& bbl, instruction& inst ) { return bbl.np_push_back( inst ); } )
124 | .def( "np_push_front", [ ] ( basic_block& bbl, instruction& inst ) { return bbl.np_push_front( inst ); } )
125 | //.def( "np_emplace", &np_emplace_helper )
126 | //.def( "np_emplace_back", &np_emplace_back_helper )
127 | //.def( "np_emplace_front", &np_emplace_front_helper )
128 |
129 | // TODO: assign helper?
130 |
131 | .def( "erase", &basic_block::erase )
132 | .def( "pop_front", &basic_block::pop_front )
133 | .def( "pop_back", &basic_block::pop_front )
134 | .def( "clear", &basic_block::clear )
135 |
136 | .def( "acquire", py::overload_cast< basic_block::const_iterator&>(&basic_block::acquire) )
137 |
138 | .def( "prepare_operand", [ ] ( basic_block& bbl, operand* op ) { return op; /* We use type_caster to explicitly cast to operand */ } )
139 |
140 |
141 | // End
142 | //
143 | ;
144 |
145 | ( *this )
146 | // Functions
147 | //
148 | .def( "mov", &basic_block::mov )
149 | .def( "movsx", &basic_block::movsx )
150 | .def( "store", &basic_block::str )
151 | .def( "ldd", &basic_block::ldd )
152 |
153 | .def( "neg", &basic_block::neg )
154 | .def( "add", &basic_block::add )
155 | .def( "sub", &basic_block::sub )
156 | .def( "div", &basic_block::div )
157 | .def( "idiv", &basic_block::idiv )
158 | .def( "mul", &basic_block::mul )
159 | .def( "imul", &basic_block::imul )
160 | .def( "mulhi", &basic_block::mulhi )
161 | .def( "imulhi", &basic_block::imulhi )
162 | .def( "rem", &basic_block::rem )
163 | .def( "irem", &basic_block::irem )
164 |
165 | .def( "popcnt", &basic_block::popcnt )
166 | .def( "bsf", &basic_block::bsf )
167 | .def( "bsr", &basic_block::bsr )
168 | .def( "bnot", &basic_block::bnot )
169 | .def( "bshr", &basic_block::bshr )
170 | .def( "bshl", &basic_block::bshl )
171 | .def( "bxor", &basic_block::bxor )
172 | .def( "bor", &basic_block::bor )
173 | .def( "band", &basic_block::band )
174 | .def( "bror", &basic_block::bror )
175 | .def( "brol", &basic_block::brol )
176 |
177 | .def( "tg", &basic_block::tg )
178 | .def( "tge", &basic_block::tge )
179 | .def( "te", &basic_block::te )
180 | .def( "tne", &basic_block::tne )
181 | .def( "tle", &basic_block::tle )
182 | .def( "tl", &basic_block::tl )
183 | .def( "tug", &basic_block::tug )
184 | .def( "tuge", &basic_block::tuge )
185 | .def( "tule", &basic_block::tule )
186 | .def( "tul", &basic_block::tul )
187 | .def( "ifs", &basic_block::ifs )
188 |
189 | .def( "js", &basic_block::js )
190 | .def( "jmp", &basic_block::jmp )
191 | .def( "vexit", &basic_block::vexit )
192 | .def( "vxcall", &basic_block::vxcall )
193 |
194 | .def( "nop", &basic_block::nop<> )
195 | .def( "vemit", &basic_block::vemit )
196 | .def( "vpinr", &basic_block::vpinr )
197 | .def( "vpinw", &basic_block::vpinw )
198 | .def( "vpinrm", &basic_block::vpinrm )
199 | .def( "vpinwm", &basic_block::vpinwm );
200 | }
201 |
202 | private:
203 | static std::vector tmp_helper( basic_block& bbl, py::args args )
204 | {
205 | std::vector regs( args.size() );
206 | for ( auto [i, o] : zip( regs, args ) )
207 | i = bbl.tmp( py::cast( o ) );
208 | return regs;
209 | }
210 | };
211 | }
212 |
213 | namespace pybind11::detail
214 | {
215 | template<> struct type_caster : public type_caster_base
216 | {
217 | using base = type_caster_base;
218 |
219 | public:
220 | bool load( handle src, bool convert )
221 | {
222 | if ( py::isinstance( src ) )
223 | {
224 | this->value = new il_const_iterator( py::cast( src ) );
225 | return true;
226 | }
227 |
228 | return false;
229 | }
230 |
231 | static handle cast( il_const_iterator src, return_value_policy policy, handle parent )
232 | {
233 | return base::cast( src, policy, parent );
234 | }
235 | };
236 | }
237 |
--------------------------------------------------------------------------------
/src/architecture/routine/call_convention.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | call_convention.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 | #include
44 |
45 | using namespace vtil;
46 | namespace py = pybind11;
47 |
48 |
49 | namespace vtil::python
50 | {
51 | struct call_convention_amd64_py
52 | {
53 | // Dummy amd64 struct
54 | //
55 | };
56 |
57 | struct call_convention_arm64_py
58 | {
59 | // Dummy arm64 struct
60 | //
61 | };
62 |
63 | class call_convention_py : public py::class_
64 | {
65 | public:
66 | call_convention_py( const handle& scope, const char* name )
67 | : class_( scope, name )
68 | {
69 | py::class_( scope, "call_convetion::amd64" )
70 | // Static properties
71 | //
72 | .def_readonly_static( "preserve_all_convention", &amd64::preserve_all_convention )
73 | .def_readonly_static( "default_call_convention", &amd64::default_call_convention )
74 |
75 | // End
76 | //
77 | ;
78 |
79 | py::class_( scope, "call_convetion::arm64" )
80 | // Static properties
81 | //
82 | .def_readonly_static( "preserve_all_convention", &arm64::preserve_all_convention )
83 | .def_readonly_static( "default_call_convention", &arm64::default_call_convention )
84 | .def_readonly_static( "vector_call_convention", &arm64::vector_call_convention )
85 |
86 | // End
87 | //
88 | ;
89 |
90 | ( *this )
91 | // Constructors
92 | //
93 | .def( py::init, std::vector, std::vector, register_desc, size_t, bool>() )
94 |
95 | // Static properties
96 | //
97 | .def_property_readonly_static( "amd64", [ ] ( py::object& ) { static auto instance = call_convention_amd64_py(); return instance; } )
98 | .def_property_readonly_static( "arm64", [ ] ( py::object& ) { static auto instance = call_convention_arm64_py(); return instance; } )
99 |
100 | // Properties
101 | //
102 | .def_readonly( "volatile_registers", &call_convention::volatile_registers )
103 | .def_readonly( "param_registers", &call_convention::param_registers )
104 | .def_readonly( "retval_registers", &call_convention::retval_registers )
105 | .def_readonly( "frame_register", &call_convention::frame_register )
106 | .def_readonly( "shadow_space", &call_convention::shadow_space )
107 | .def_readonly( "purge_stack", &call_convention::purge_stack )
108 |
109 | // End
110 | //
111 | ;
112 | }
113 | };
114 | }
115 |
--------------------------------------------------------------------------------
/src/architecture/routine/instruction.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | instruction.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 |
44 | using namespace vtil;
45 | namespace py = pybind11;
46 |
47 |
48 | namespace vtil::python
49 | {
50 | class instruction_py : public py::class_
51 | {
52 | public:
53 | instruction_py( const handle& scope, const char* name )
54 | : class_( scope, name )
55 | {
56 | ( *this )
57 | // Properties
58 | //
59 | .def_readwrite( "base", &instruction::base )
60 | .def_readwrite( "operands", &instruction::operands )
61 | .def_readwrite( "vip", &instruction::vip )
62 |
63 | .def_readwrite( "sp_offset", &instruction::sp_offset )
64 | .def_readwrite( "sp_index", &instruction::sp_index )
65 | .def_readwrite( "sp_reset", &instruction::sp_reset )
66 |
67 | .def_readwrite( "explicit_volatile", &instruction::explicit_volatile )
68 |
69 | // Functions
70 | //
71 | .def( "is_valid", &instruction::is_valid )
72 | .def( "make_volatile", &instruction::make_volatile )
73 | .def( "is_pseudo", &instruction::is_pseudo )
74 | .def( "is_volatile", &instruction::is_volatile )
75 | .def( "access_size", &instruction::access_size )
76 | .def( "memory_location", py::overload_cast< >( &instruction::memory_location ) )
77 | .def( "enum_operands", py::overload_cast< >( &instruction::enum_operands ) )
78 | .def( "reduce", py::overload_cast< >( &instruction::reduce ) )
79 |
80 | .def( "__repr__", [ ] ( const instruction& ins ) { return ins.to_string( false ); } )
81 | .def( "__str__", [ ] ( const instruction& ins ) { return ins.to_string( false ); } )
82 |
83 | // End
84 | //
85 | ;
86 | }
87 | };
88 | }
89 |
--------------------------------------------------------------------------------
/src/architecture/routine/routine.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | routine.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 | #include
44 | #include
45 | #include
46 |
47 | using namespace vtil;
48 | namespace py = pybind11;
49 |
50 |
51 | namespace vtil::python
52 | {
53 | class memory_input_stream : public std::istream
54 | {
55 | class memory_in_buffer : public std::basic_streambuf
56 | {
57 | public:
58 | memory_in_buffer( const uint8_t* p, size_t l )
59 | {
60 | setg( ( char* ) p, ( char* ) p, ( char* ) p + l );
61 | }
62 | };
63 |
64 | memory_in_buffer _buffer;
65 |
66 | public:
67 | memory_input_stream( const uint8_t* p, size_t l ) : std::istream( &_buffer ), _buffer( p, l )
68 | {
69 | rdbuf( &_buffer );
70 | }
71 | };
72 |
73 | class memory_output_buffer : public std::streambuf
74 | {
75 | std::string data;
76 |
77 | protected:
78 | virtual int_type overflow( int_type c )
79 | {
80 | if ( c != EOF )
81 | data.push_back( c );
82 | return c;
83 | }
84 |
85 | public:
86 | std::string& get_contents() { return data; }
87 | };
88 |
89 | class routine_py : public py::class_
90 | {
91 | public:
92 | routine_py( const handle& scope, const char* name )
93 | : class_( scope, name )
94 | {
95 | ( *this )
96 | // Static helpers
97 | //
98 | .def_static( "load", &load_routine, py::arg( "path" ) )
99 | .def( "save", &save_routine, py::arg( "path" ) )
100 |
101 | .def_static( "load", py::overload_cast< py::object >( &load ), py::arg( "fd" ) )
102 | .def( "save", &save, py::arg( "fd" ), py::arg( "as_bytes" ) = true )
103 |
104 | // Properties
105 | //
106 | .def_readonly( "arch_id", &routine::arch_id )
107 | .def_readonly( "explored_blocks", &routine::explored_blocks )
108 | .def_readonly( "entry_point", &routine::entry_point )
109 | .def_readwrite( "routine_convention", &routine::routine_convention )
110 | .def_readwrite( "subroutine_convention", &routine::subroutine_convention )
111 |
112 | // Functions
113 | //
114 | .def( "alloc", &alloc_helper )
115 | .def( "for_each", &for_each_helper, py::arg("fn"), py::arg("tagged") = false )
116 | .def( "get_cconv", &routine::get_cconv )
117 | .def( "set_cconv", &routine::set_cconv )
118 | .def( "clone", &routine::clone )
119 |
120 | // End
121 | //
122 | ;
123 | }
124 |
125 | private:
126 | static std::vector alloc_helper( routine& rtn, py::args args )
127 | {
128 | std::vector regs( args.size() );
129 | for ( auto [i, o] : zip( regs, args ) )
130 | i = rtn.alloc( py::cast( o ) );
131 | return regs;
132 | }
133 |
134 | static void for_each_helper( routine& rtn, py::object obj, bool tagged )
135 | {
136 | // Workaround: pybind11 has an issue with detecting the proper type to use for the passed function,
137 | // this is due to tagged_order being castable to void (aka None for python) hence we need the tagged argument
138 | // to distingush the proper callback to use.
139 | //
140 | if ( tagged )
141 | {
142 | auto fn = obj.cast>();
143 | rtn.for_each( fn );
144 | }
145 | else
146 | {
147 | auto fn = obj.cast>();
148 | rtn.for_each( fn );
149 | }
150 | }
151 |
152 | static routine* load( py::object obj )
153 | {
154 | if ( !( py::hasattr( obj, "read" ) ) )
155 | {
156 | throw py::type_error( "Argument is not an object of a file-like type" );
157 | }
158 |
159 | // Use Python API to read from file
160 | //
161 | auto file_data = obj.attr( "read" )( );
162 |
163 | // Convert into string
164 | //
165 | if ( !py::isinstance( file_data ) && !py::isinstance( file_data ) )
166 | return nullptr;
167 |
168 | std::string data = py::isinstance( file_data ) ? std::string( file_data.cast() ) : std::string( file_data.cast() );
169 | return load( data );
170 | }
171 |
172 | static routine* load( const std::string& data )
173 | {
174 | memory_input_stream stream( ( uint8_t* ) &data[ 0 ], data.size() );
175 | routine* rtn = nullptr;
176 | deserialize( stream, rtn );
177 |
178 | return rtn;
179 | }
180 |
181 | static void save( routine* rtn, py::object obj, bool as_bytes = true )
182 | {
183 | if ( !( py::hasattr( obj, "write" ) && py::hasattr( obj, "flush" ) ) )
184 | {
185 | throw py::type_error( "Argument is not an object of a file-like type" );
186 | }
187 |
188 | // Create an in memory output buffer
189 | //
190 | memory_output_buffer out_buffer;
191 | std::ostream out( &out_buffer );
192 |
193 | // Write to the buffer and then use Python API to write to file
194 | serialize( out, rtn );
195 | if ( as_bytes )
196 | obj.attr( "write" )( py::bytes( out_buffer.get_contents() ) );
197 | else
198 | obj.attr( "write" )( out_buffer.get_contents() );
199 | }
200 | };
201 | }
--------------------------------------------------------------------------------
/src/architecture/symex/variable.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | variable.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 |
44 | using namespace vtil::symbolic;
45 | namespace py = pybind11;
46 |
47 |
48 | namespace vtil::python
49 | {
50 | class variable_py : public py::class_
51 | {
52 | public:
53 | variable_py( const handle& scope, const char* name )
54 | : class_( scope, name )
55 | {
56 | // Related
57 | //
58 | py::class_( scope, "access_details" )
59 | // Properties
60 | //
61 | .def_readwrite( "bit_offset", &access_details::bit_offset )
62 | .def_readwrite( "bit_count", &access_details::bit_count )
63 |
64 | .def_readwrite( "read", &access_details::read )
65 | .def_readwrite( "write", &access_details::write )
66 | .def_readwrite( "unknown", &access_details::unknown )
67 |
68 | .def( "is_unknown", &access_details::is_unknown )
69 |
70 | // End
71 | //
72 | ;
73 |
74 | py::class_( scope, "variable::memory_t" )
75 | // Constructor
76 | //
77 | .def( py::init<>() )
78 | .def( py::init() )
79 |
80 | // Properties
81 | //
82 | .def_readwrite( "base", &variable::memory_t::base )
83 | .def_readwrite( "bit_count", &variable::memory_t::bit_count )
84 |
85 | // Functions
86 | //
87 | .def( "decay", &variable::memory_t::decay )
88 | .def( "reduce", py::overload_cast< >( &variable::memory_t::reduce ) )
89 |
90 | /* End */
91 | ;
92 |
93 | ( *this )
94 | // Constructor
95 | //
96 | .def( py::init<>() )
97 | .def( py::init() )
98 | .def( py::init() )
99 | .def( py::init() )
100 | .def( py::init() )
101 | .def( py::init() )
102 | .def( py::init() )
103 |
104 | // Properties
105 | //
106 | .def_readwrite( "at", &variable::at )
107 | .def_readwrite( "descriptor", &variable::descriptor )
108 | .def_readwrite( "is_branch_depedant", &variable::is_branch_dependant )
109 |
110 | // Functions
111 | //
112 | .def( "bind", &variable::bind )
113 |
114 | .def( "is_valid", &variable::is_valid )
115 | .def( "is_free_form", &variable::is_free_form )
116 | .def( "is_memory", &variable::is_memory )
117 | .def( "is_register", &variable::is_register )
118 |
119 | .def( "mem", py::overload_cast< >( &variable::mem ) )
120 | .def( "reg", py::overload_cast< >( &variable::reg ) )
121 |
122 | .def( "bit_count", &variable::bit_count )
123 | .def( "to_expression", &variable::to_expression )
124 | .def( "to_string", &variable::to_string )
125 | .def( "reduce", py::overload_cast< >( &variable::reduce ) )
126 |
127 | .def( "pack_all", py::overload_cast< const expression& >( &variable::pack_all ) )
128 | .def( "pack_all", py::overload_cast< const expression::reference& >( &variable::pack_all ) )
129 |
130 | .def( "read_by", &variable::read_by )
131 | .def( "written_by", &variable::written_by )
132 | .def( "accessed_by", &variable::accessed_by )
133 |
134 | .def( "__repr__", &variable::to_string )
135 | .def( "__str__", &variable::to_string )
136 |
137 | // End
138 | //
139 | ;
140 | }
141 | };
142 | }
143 |
--------------------------------------------------------------------------------
/src/architecture/trace/cached_tracer.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | cached_tracer.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 |
44 | using namespace vtil;
45 | namespace py = pybind11;
46 |
47 |
48 | namespace vtil::python
49 | {
50 | class cached_tracer_py : public py::class_
51 | {
52 | public:
53 | cached_tracer_py( const handle& scope, const char* name )
54 | : class_( scope, name )
55 | {
56 | ( *this )
57 | // Constructor
58 | //
59 | .def( py::init<>() )
60 | .def( py::init() )
61 |
62 | // Functions
63 | //
64 | .def( "trace", &cached_tracer::trace )
65 | .def( "flush", py::overload_cast< >( &cached_tracer::flush ) )
66 | .def( "flush", py::overload_cast< basic_block* >( &cached_tracer::flush ) )
67 |
68 | // End
69 | //
70 | ;
71 | }
72 | };
73 | }
74 |
--------------------------------------------------------------------------------
/src/architecture/trace/tracer.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | tracer.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 |
44 | using namespace vtil;
45 | namespace py = pybind11;
46 |
47 |
48 | namespace vtil::python
49 | {
50 | class tracer_py : public py::class_
51 | {
52 | public:
53 | tracer_py( const handle& scope, const char* name )
54 | : class_( scope, name )
55 | {
56 | ( *this )
57 | // Constructor
58 | //
59 | .def( py::init<>() )
60 |
61 | // Functions
62 | //
63 | .def( "trace", &tracer::trace )
64 | .def( "rtrace", &tracer::rtrace )
65 |
66 | .def( "trace_p", &tracer::trace_p )
67 | .def( "rtrace_p", &tracer::rtrace_p )
68 |
69 | .def( "trace_exp", &tracer::trace_exp )
70 | .def( "rtrace_exp", &tracer::rtrace_exp )
71 | .def( "trace_pexp", &tracer::trace_pexp )
72 | .def( "rtrace_pexp", &tracer::rtrace_pexp )
73 |
74 | .def( "__call__", &tracer::trace_p )
75 |
76 | // End
77 | //
78 | ;
79 | }
80 | };
81 | }
82 |
--------------------------------------------------------------------------------
/src/common/util/enumerator.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | enumerator.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 |
44 | using namespace vtil;
45 | namespace py = pybind11;
46 |
47 |
48 | namespace vtil::python
49 | {
50 | class enumerator_py : public py::class_
51 | {
52 | public:
53 | enumerator_py( const handle& scope, const char* name )
54 | : class_( scope, name )
55 | {
56 | py::class_( scope, "TaggedOrder" )
57 | // Members
58 | //
59 | .def_readonly( "should_break", &enumerator::tagged_order::should_break )
60 | .def_readonly( "global_break", &enumerator::tagged_order::global_break )
61 |
62 | // End
63 | //
64 | ;
65 |
66 | ( *this )
67 | // Static Members
68 | //
69 | .def_property_readonly_static( "obreak", [ ] ( py::object& ) { return enumerator::obreak; } )
70 | .def_property_readonly_static( "obreak_r", [ ] ( py::object& ) { return enumerator::obreak_r; } )
71 | .def_property_readonly_static( "ocontinue", [ ] ( py::object& ) { return enumerator::ocontinue; } )
72 |
73 | // End
74 | //
75 | ;
76 | }
77 | };
78 | }
79 |
--------------------------------------------------------------------------------
/src/common/util/fnv64.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | fnv64.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 |
44 | using namespace vtil;
45 | namespace py = pybind11;
46 |
47 |
48 | namespace vtil::python
49 | {
50 | class fnv64_hash_py : public py::class_
51 | {
52 | public:
53 | fnv64_hash_py( const handle& scope, const char* name )
54 | : class_( scope, name )
55 | {
56 | ( *this )
57 | // Functions
58 | //
59 | .def( "as64", &fnv64_hash_t::as64 )
60 | .def( "__eq__", [ ] ( const fnv64_hash_t& a, const fnv64_hash_t& b ) { return a == b; } )
61 | .def( "__repr__", &fnv64_hash_t::to_string )
62 | .def( "__str__", &fnv64_hash_t::to_string )
63 |
64 | // End
65 | //
66 | ;
67 | }
68 | };
69 | }
70 |
--------------------------------------------------------------------------------
/src/compiler/common/interface.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | interface.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 | #include
44 |
45 | using namespace vtil::optimizer;
46 | namespace py = pybind11;
47 |
48 |
49 | namespace vtil::python
50 | {
51 | using pass_interface_t = pass_interface<>;
52 |
53 | class pass_interface_trampoline : public pass_interface_t
54 | {
55 | bool is_serial;
56 |
57 | public:
58 | pass_interface_trampoline( bool is_parallel ) : is_serial( !is_parallel ) {}
59 |
60 | size_t pass( basic_block* blk, bool xblock = false ) override
61 | {
62 | PYBIND11_OVERLOAD_PURE(
63 | size_t,
64 | pass_interface_t,
65 | pass_,
66 | blk, xblock
67 | );
68 | }
69 |
70 | size_t xpass( routine* rtn ) override
71 | {
72 | PYBIND11_OVERLOAD_INT( PYBIND11_TYPE( size_t ), PYBIND11_TYPE( pass_interface_t ), "xpass", rtn );
73 |
74 | size_t n = 0;
75 | if ( is_serial )
76 | rtn->for_each( [ & ] ( auto* bbl ) { n += this->pass( bbl, true ); } );
77 | else
78 | n = this->transform_parallel( rtn, [ & ] ( auto* bbl ) { py::gil_scoped_acquire acquire; return this->pass( bbl, true ); } );
79 |
80 | return n;
81 | }
82 |
83 | std::string name() override
84 | {
85 | PYBIND11_OVERLOAD(
86 | std::string,
87 | pass_interface_t,
88 | name
89 | );
90 | }
91 |
92 | private:
93 | size_t transform_parallel( routine* rtn, const std::function& fn )
94 | {
95 | std::atomic n = { 0 };
96 | std::vector pool;
97 | pool.reserve( rtn->explored_blocks.size() );
98 |
99 | rtn->for_each( [ & ] ( auto* bbl ) { pool.emplace_back( [ & ] ( auto* b ) { n += fn( b ); }, bbl ); } );
100 |
101 | for ( auto& thread : pool )
102 | {
103 | thread.join();
104 | }
105 |
106 | return n;
107 | }
108 | };
109 |
110 | class pass_interface_py : public py::class_
111 | {
112 | public:
113 | pass_interface_py( const handle& scope, const char* name )
114 | : class_( scope, name )
115 | {
116 | ( *this )
117 | // Constructor
118 | //
119 | .def( py::init_alias(), py::arg( "parallel" ) = true )
120 |
121 | // Functions
122 | //
123 | .def( "pass_", &pass_interface_t::pass )
124 | .def( "xpass", &pass_interface_t::xpass, py::call_guard() )
125 | .def( "name", &pass_interface_t::name )
126 |
127 | .def( "__call__", py::overload_cast< basic_block*, bool >( &pass_interface_t::operator() ) )
128 | .def( "__call__", py::overload_cast< routine* >( &pass_interface_t::operator() ) )
129 | ;
130 | }
131 | };
132 | }
133 |
--------------------------------------------------------------------------------
/src/external/arm64_reg.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | arm64_reg.hpp | https://github.com/pybind/pybind11 |
36 | // | | https://github.com/aquynh/capstone/ |
37 | // | | https://github.com/keystone-engine/keystone/ |
38 | // |--------------------------------------------------------------------------|
39 | //
40 | #pragma once
41 |
42 | #include
43 | #include
44 |
45 | namespace py = pybind11;
46 |
47 |
48 | namespace vtil::python
49 | {
50 | class arm64_reg_py : public py::enum_
51 | {
52 | public:
53 | arm64_reg_py( const handle& scope, const char* name )
54 | : enum_( scope, name )
55 | {
56 | ( *this )
57 | .value( "X0", arm64_reg::ARM64_REG_X0 ).value( "W0", arm64_reg::ARM64_REG_W0 )
58 | .value( "X1", arm64_reg::ARM64_REG_X1 ).value( "W1", arm64_reg::ARM64_REG_W1 )
59 | .value( "X2", arm64_reg::ARM64_REG_X2 ).value( "W2", arm64_reg::ARM64_REG_W2 )
60 | .value( "X3", arm64_reg::ARM64_REG_X3 ).value( "W3", arm64_reg::ARM64_REG_W3 )
61 | .value( "X4", arm64_reg::ARM64_REG_X4 ).value( "W4", arm64_reg::ARM64_REG_W4 )
62 | .value( "X5", arm64_reg::ARM64_REG_X5 ).value( "W5", arm64_reg::ARM64_REG_W5 )
63 | .value( "X6", arm64_reg::ARM64_REG_X6 ).value( "W6", arm64_reg::ARM64_REG_W6 )
64 | .value( "X7", arm64_reg::ARM64_REG_X7 ).value( "W7", arm64_reg::ARM64_REG_W7 )
65 | .value( "X8", arm64_reg::ARM64_REG_X8 ).value( "W8", arm64_reg::ARM64_REG_W8 )
66 | .value( "X9", arm64_reg::ARM64_REG_X9 ).value( "W9", arm64_reg::ARM64_REG_W9 )
67 | .value( "X10", arm64_reg::ARM64_REG_X10 ).value( "W10", arm64_reg::ARM64_REG_W10 )
68 | .value( "X11", arm64_reg::ARM64_REG_X11 ).value( "W11", arm64_reg::ARM64_REG_W11 )
69 | .value( "X12", arm64_reg::ARM64_REG_X12 ).value( "W12", arm64_reg::ARM64_REG_W12 )
70 | .value( "X13", arm64_reg::ARM64_REG_X13 ).value( "W13", arm64_reg::ARM64_REG_W13 )
71 | .value( "X14", arm64_reg::ARM64_REG_X14 ).value( "W14", arm64_reg::ARM64_REG_W14 )
72 | .value( "X15", arm64_reg::ARM64_REG_X15 ).value( "W15", arm64_reg::ARM64_REG_W15 )
73 | .value( "X16", arm64_reg::ARM64_REG_X16 ).value( "W16", arm64_reg::ARM64_REG_W16 ).value( "IP0", arm64_reg::ARM64_REG_IP0 )
74 | .value( "X17", arm64_reg::ARM64_REG_X17 ).value( "W17", arm64_reg::ARM64_REG_W17 ).value( "IP1", arm64_reg::ARM64_REG_IP1 )
75 | .value( "X18", arm64_reg::ARM64_REG_X18 ).value( "W18", arm64_reg::ARM64_REG_W18 )
76 | .value( "X19", arm64_reg::ARM64_REG_X19 ).value( "W19", arm64_reg::ARM64_REG_W19 )
77 | .value( "X20", arm64_reg::ARM64_REG_X20 ).value( "W20", arm64_reg::ARM64_REG_W20 )
78 | .value( "X21", arm64_reg::ARM64_REG_X21 ).value( "W21", arm64_reg::ARM64_REG_W21 )
79 | .value( "X22", arm64_reg::ARM64_REG_X22 ).value( "W22", arm64_reg::ARM64_REG_W22 )
80 | .value( "X23", arm64_reg::ARM64_REG_X23 ).value( "W23", arm64_reg::ARM64_REG_W23 )
81 | .value( "X24", arm64_reg::ARM64_REG_X24 ).value( "W24", arm64_reg::ARM64_REG_W24 )
82 | .value( "X25", arm64_reg::ARM64_REG_X25 ).value( "W25", arm64_reg::ARM64_REG_W25 )
83 | .value( "X26", arm64_reg::ARM64_REG_X26 ).value( "W26", arm64_reg::ARM64_REG_W26 )
84 | .value( "X27", arm64_reg::ARM64_REG_X27 ).value( "W27", arm64_reg::ARM64_REG_W27 )
85 | .value( "X28", arm64_reg::ARM64_REG_X28 ).value( "W28", arm64_reg::ARM64_REG_W28 )
86 | .value( "X29", arm64_reg::ARM64_REG_X29 ).value( "W29", arm64_reg::ARM64_REG_W29 ).value( "FP", arm64_reg::ARM64_REG_FP )
87 | .value( "X30", arm64_reg::ARM64_REG_X30 ).value( "W30", arm64_reg::ARM64_REG_W30 ).value( "LR", arm64_reg::ARM64_REG_LR )
88 | .value( "XZR", arm64_reg::ARM64_REG_XZR ).value( "WZR", arm64_reg::ARM64_REG_WZR )
89 | .value( "SP", arm64_reg::ARM64_REG_SP ).value( "WSP", arm64_reg::ARM64_REG_WSP )
90 | .value( "NZCV", arm64_reg::ARM64_REG_NZCV );
91 | }
92 | };
93 | }
94 |
--------------------------------------------------------------------------------
/src/external/x86_reg.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | x86_reg.hpp | https://github.com/pybind/pybind11 |
36 | // | | https://github.com/aquynh/capstone/ |
37 | // | | https://github.com/keystone-engine/keystone/ |
38 | // |--------------------------------------------------------------------------|
39 | //
40 | #pragma once
41 |
42 | #include
43 | #include
44 |
45 | namespace py = pybind11;
46 |
47 |
48 | namespace vtil::python
49 | {
50 | class x86_reg_py : public py::enum_
51 | {
52 | public:
53 | x86_reg_py( const handle& scope, const char* name )
54 | : enum_( scope, name )
55 | {
56 | ( *this )
57 | .value( "RAX", x86_reg::X86_REG_RAX ).value( "EAX", x86_reg::X86_REG_EAX ).value( "AX", x86_reg::X86_REG_AX ).value( "AH", x86_reg::X86_REG_AH ).value( "AL", x86_reg::X86_REG_AL )
58 | .value( "RBP", x86_reg::X86_REG_RBP ).value( "EBP", x86_reg::X86_REG_EBP ).value( "BP", x86_reg::X86_REG_BP ).value( "BPL", x86_reg::X86_REG_BPL )
59 | .value( "RBX", x86_reg::X86_REG_RBX ).value( "EBX", x86_reg::X86_REG_EBX ).value( "BX", x86_reg::X86_REG_BX ).value( "BH", x86_reg::X86_REG_BH ).value( "BL", x86_reg::X86_REG_BL )
60 | .value( "RCX", x86_reg::X86_REG_RCX ).value( "ECX", x86_reg::X86_REG_ECX ).value( "CX", x86_reg::X86_REG_CX ).value( "CH", x86_reg::X86_REG_CH ).value( "CL", x86_reg::X86_REG_CL )
61 | .value( "RDI", x86_reg::X86_REG_RDI ).value( "EDI", x86_reg::X86_REG_EDI ).value( "DI", x86_reg::X86_REG_DI ).value( "DIL", x86_reg::X86_REG_DIL )
62 | .value( "RDX", x86_reg::X86_REG_RDX ).value( "EDX", x86_reg::X86_REG_EDX ).value( "DX", x86_reg::X86_REG_DX ).value( "DH", x86_reg::X86_REG_DH ).value( "DL", x86_reg::X86_REG_DL )
63 | .value( "RIP", x86_reg::X86_REG_RIP ).value( "EIP", x86_reg::X86_REG_EIP ).value( "IP", x86_reg::X86_REG_IP )
64 | .value( "RSI", x86_reg::X86_REG_RSI ).value( "ESI", x86_reg::X86_REG_ESI ).value( "SI", x86_reg::X86_REG_SI ).value( "SIL", x86_reg::X86_REG_SIL )
65 | .value( "RSP", x86_reg::X86_REG_RSP ).value( "ESP", x86_reg::X86_REG_ESP ).value( "SP", x86_reg::X86_REG_SP ).value( "SPL", x86_reg::X86_REG_SPL )
66 | .value( "r8", x86_reg::X86_REG_R8 ).value( "r8d", x86_reg::X86_REG_R8D ).value( "r8w", x86_reg::X86_REG_R8W ).value( "r8b", x86_reg::X86_REG_R8B )
67 | .value( "r9", x86_reg::X86_REG_R9 ).value( "r9d", x86_reg::X86_REG_R9D ).value( "r9w", x86_reg::X86_REG_R9W ).value( "r9b", x86_reg::X86_REG_R9B )
68 | .value( "r10", x86_reg::X86_REG_R10 ).value( "r10d", x86_reg::X86_REG_R10D ).value( "r10w", x86_reg::X86_REG_R10W ).value( "r10b", x86_reg::X86_REG_R10B )
69 | .value( "r11", x86_reg::X86_REG_R11 ).value( "r11d", x86_reg::X86_REG_R11D ).value( "r11w", x86_reg::X86_REG_R11W ).value( "r11b", x86_reg::X86_REG_R11B )
70 | .value( "r12", x86_reg::X86_REG_R12 ).value( "r12d", x86_reg::X86_REG_R12D ).value( "r12w", x86_reg::X86_REG_R12W ).value( "r12b", x86_reg::X86_REG_R12B )
71 | .value( "r13", x86_reg::X86_REG_R13 ).value( "r13d", x86_reg::X86_REG_R13D ).value( "r13w", x86_reg::X86_REG_R13W ).value( "r13b", x86_reg::X86_REG_R13B )
72 | .value( "r14", x86_reg::X86_REG_R14 ).value( "r14d", x86_reg::X86_REG_R14D ).value( "r14w", x86_reg::X86_REG_R14W ).value( "r14b", x86_reg::X86_REG_R14B )
73 | .value( "r15", x86_reg::X86_REG_R15 ).value( "r15d", x86_reg::X86_REG_R15D ).value( "r15w", x86_reg::X86_REG_R15W ).value( "r15b", x86_reg::X86_REG_R15B )
74 |
75 | .value( "FS", x86_reg::X86_REG_FS )
76 | .value( "GS", x86_reg::X86_REG_GS )
77 | .value( "CS", x86_reg::X86_REG_CS )
78 | .value( "SS", x86_reg::X86_REG_SS )
79 | .value( "DS", x86_reg::X86_REG_DS )
80 | .value( "ES", x86_reg::X86_REG_ES )
81 |
82 | .value( "EFLAGS", x86_reg::X86_REG_EFLAGS )
83 | ;
84 | }
85 | };
86 | }
87 |
--------------------------------------------------------------------------------
/src/module.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | module.cpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // | | https://github.com/aquynh/capstone/ |
38 | // | | https://github.com/keystone-engine/keystone/ |
39 | // |--------------------------------------------------------------------------|
40 | //
41 |
42 | #include
43 | #include
44 |
45 | #include "architecture/arch/identifier.hpp"
46 | #include "architecture/arch/instruction_desc.hpp"
47 | #include "architecture/arch/operands.hpp"
48 | #include "architecture/arch/register_desc.hpp"
49 | #include "architecture/routine/basic_block.hpp"
50 | #include "architecture/routine/call_convention.hpp"
51 | #include "architecture/routine/instruction.hpp"
52 | #include "architecture/routine/routine.hpp"
53 | #include "architecture/misc/debug.hpp"
54 | #include "architecture/trace/tracer.hpp"
55 | #include "architecture/trace/cached_tracer.hpp"
56 | #include "architecture/symex/variable.hpp"
57 |
58 | #include "common/util/fnv64.hpp"
59 | #include "common/util/enumerator.hpp"
60 |
61 | #include "compiler/common/interface.hpp"
62 |
63 | #include "symex/expressions/unique_identifier.hpp"
64 | #include "symex/expressions/expression.hpp"
65 |
66 | #include "external/arm64_reg.hpp"
67 | #include "external/x86_reg.hpp"
68 |
69 | using namespace vtil::python;
70 | namespace py = pybind11;
71 |
72 |
73 | PYBIND11_MODULE(vtil, m) {
74 | // Hook error function
75 | //
76 | vtil::logger::error_hook = [ ] ( const std::string& msg )
77 | {
78 | throw std::runtime_error( msg );
79 | };
80 |
81 | // Namespaces
82 | //
83 | auto debugger = m.def_submodule( "debugger", "vtil::debugger" );
84 | auto optimizer = m.def_submodule( "optimizer", "vtil::optimizer" );
85 | auto symbolic = m.def_submodule( "symbolic", "vtil::symbolic" );
86 |
87 |
88 | // VTIL Architecture
89 | //
90 | {
91 | /* Architecture */
92 | architecture_identifier_py( m, "ArchID" );
93 | instruction_desc_py( m, "InstructionDesc" );
94 | operand_py( m, "Operand" );
95 | register_desc_py( m, "RegisterDesc" );
96 |
97 | /* Instruction Stream */
98 | basic_block_py( m, "BasicBlock" );
99 | call_convention_py( m, "CallConvetion" );
100 | instruction_py( m, "Instruction" );
101 | routine_py( m, "Routine" );
102 |
103 | /* Miscellaneous */
104 | debug_py( debugger, "Debug" );
105 |
106 | /* Value Tracing */
107 | tracer_py( m, "Tracer" );
108 | cached_tracer_py( m, "CachedTracer" );
109 |
110 | /* SymEx Integration */
111 | variable_py( symbolic, "Variable" );
112 | }
113 |
114 |
115 | // VTIL Common
116 | //
117 | {
118 | /* Utility */
119 | fnv64_hash_py( m, "FNV64" );
120 | enumerator_py( m, "Enumerator" );
121 | }
122 |
123 |
124 | // VTIL Compiler
125 | {
126 | /* Common */
127 | pass_interface_py( optimizer, "Interface" );
128 | }
129 |
130 |
131 | // VTIL SymEx
132 | //
133 | {
134 | /* Expressions */
135 | unique_identifier_py( symbolic, "UID" );
136 | expression_py( symbolic, "Expression" );
137 | }
138 |
139 |
140 | // External
141 | //
142 | {
143 | arm64_reg_py( m, "ARM64" );
144 | x86_reg_py( m, "AMD64" );
145 | }
146 |
147 |
148 | #ifdef VERSION_INFO
149 | m.attr("__version__") = VERSION_INFO;
150 | #else
151 | m.attr("__version__") = "dev";
152 | #endif
153 |
154 | }
155 |
--------------------------------------------------------------------------------
/src/symex/expressions/expression.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | expression.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 | #include
44 |
45 | using namespace vtil::symbolic;
46 | namespace py = pybind11;
47 |
48 |
49 | namespace vtil::python
50 | {
51 | class expression_py : public py::class_
52 | {
53 | public:
54 | expression_py( const handle& scope, const char* name )
55 | : class_( scope, name )
56 | {
57 | ( *this )
58 | // Constructor
59 | //
60 | .def( py::init<>() )
61 | .def( py::init() )
62 |
63 | .def( py::init() )
64 |
65 | .def( py::init() )
66 | .def( py::init() )
67 |
68 | // Properties
69 | //
70 | .def_readwrite( "uid", &expression::uid )
71 |
72 | .def_readwrite( "op", &expression::op )
73 | .def_readwrite( "lhs", &expression::lhs )
74 | .def_readwrite( "rhs", &expression::rhs )
75 |
76 | .def_readonly( "complexity", &expression::complexity )
77 | .def_readonly( "depth", &expression::depth )
78 | .def_readonly( "hash_value", &expression::hash_value )
79 | .def_readonly( "signature", &expression::depth )
80 |
81 | .def_readwrite( "simplify_hint", &expression::simplify_hint )
82 | .def_readwrite( "is_lazy", &expression::is_lazy )
83 |
84 | // Functions
85 | //
86 | .def( "get_op_desc", &expression::get_op_desc )
87 |
88 | .def( "is_variable", &expression::is_variable )
89 | .def( "is_expression", &expression::is_expression )
90 | .def( "is_unary", &expression::is_unary )
91 | .def( "is_binary", &expression::is_binary )
92 | .def( "is_valid", &expression::is_valid )
93 |
94 | .def( "hash", &expression::hash )
95 | .def( "count_constants", &expression::count_constants )
96 | .def( "count_variables", &expression::count_variables )
97 | .def( "count_unique_variables", &expression::count_unique_variables )
98 |
99 | .def( "update", &expression::update )
100 |
101 | .def( "resize", [ ] ( expression& exp, bitcnt_t size, bool sign ) { return exp.resize( size, sign ); } )
102 | .def( "simplify", py::overload_cast< bool >( &expression::simplify ) )
103 |
104 | .def( "is_identical", &expression::is_identical )
105 | .def( "equals", &expression::equals )
106 |
107 | .def( "match_to", &expression::match_to )
108 | .def( "xvalues", &expression::xvalues )
109 |
110 | .def( "evaluate", [ ] ( expression& exp, std::function < uint64_t( unique_identifier )>& fn ) { exp.evaluate( fn ); } )
111 | .def( "enumerate", [ ] ( expression& exp, std::function& fn, bool bottom ) { return exp.enumerate( fn, bottom ); }, py::arg("fn"), py::arg("bottom") = false )
112 |
113 | .def( "make_lazy", py::overload_cast< >( &expression::make_lazy ) )
114 |
115 | .def( "__repr__", &expression::to_string )
116 | .def( "__str__", &expression::to_string )
117 |
118 | .def( "popcnt", [ ] ( const expression& rhs ) { return __popcnt( rhs ); } )
119 | .def( "mask", [ ] ( const expression& rhs ) { return __mask( rhs ); } )
120 | .def( "bsr", [ ] ( const expression& rhs ) { return __bsr( rhs ); } )
121 | .def( "bsf", [ ] ( const expression& rhs ) { return __bsf( rhs ); } )
122 | .def( "__invert__", [ ] ( const expression& rhs ) { return ~rhs; } )
123 | .def( "__neg__", [ ] ( const expression& rhs ) { return -rhs; } )
124 |
125 | // End
126 | //
127 | ;
128 |
129 | #define IMPLEMENT_OPERATOR( name, ... ) \
130 | .def( name, [ ] ( const expression& lhs, const expression& rhs ) { return __VA_ARGS__; } ) \
131 | .def( name, [ ] ( const expression& lhs, int64_t rhs ) { return __VA_ARGS__; } ) \
132 | .def( name, [ ] ( const expression& lhs, uint64_t rhs ) { return __VA_ARGS__; } )
133 |
134 | ( *this )
135 | // Functions
136 | //
137 | IMPLEMENT_OPERATOR( "rotr", __rotr( lhs, rhs ) )
138 | IMPLEMENT_OPERATOR( "rotl", __rotl( lhs, rhs ) )
139 | IMPLEMENT_OPERATOR( "mulhi", mulhi( lhs, rhs ) )
140 | IMPLEMENT_OPERATOR( "umulhi", umulhi( lhs, rhs ) )
141 | IMPLEMENT_OPERATOR( "umul", umul( lhs, rhs ) )
142 | IMPLEMENT_OPERATOR( "udiv", udiv( lhs, rhs ) )
143 | IMPLEMENT_OPERATOR( "urem", urem( lhs, rhs ) )
144 | IMPLEMENT_OPERATOR( "bt", __bt( lhs, rhs ) )
145 | IMPLEMENT_OPERATOR( "iff", __if( lhs, rhs ) )
146 | IMPLEMENT_OPERATOR( "max", __max( lhs, rhs ) )
147 | IMPLEMENT_OPERATOR( "min", __min( lhs, rhs ) )
148 | IMPLEMENT_OPERATOR( "umax", __umax( lhs, rhs ) )
149 | IMPLEMENT_OPERATOR( "umin", __umin( lhs, rhs ) )
150 | IMPLEMENT_OPERATOR( "ugt", __ugreat( lhs, rhs ) )
151 | IMPLEMENT_OPERATOR( "uge", __ugreat_eq( lhs, rhs ) )
152 | IMPLEMENT_OPERATOR( "ueq", __uequal( lhs, rhs ) )
153 | IMPLEMENT_OPERATOR( "une", __unot_equal( lhs, rhs ) )
154 | IMPLEMENT_OPERATOR( "ule", __uless_eq( lhs, rhs ) )
155 | IMPLEMENT_OPERATOR( "ult", __uless( lhs, rhs ) )
156 | IMPLEMENT_OPERATOR( "__add__", lhs + rhs )
157 | IMPLEMENT_OPERATOR( "__sub__", lhs - rhs )
158 | IMPLEMENT_OPERATOR( "__mul__", lhs * rhs )
159 | IMPLEMENT_OPERATOR( "__truediv__", lhs / rhs )
160 | IMPLEMENT_OPERATOR( "__mod__", lhs % rhs )
161 | IMPLEMENT_OPERATOR( "__and__", lhs & rhs )
162 | IMPLEMENT_OPERATOR( "__or__", lhs | rhs )
163 | IMPLEMENT_OPERATOR( "__xor__", lhs ^ rhs )
164 | IMPLEMENT_OPERATOR( "__lshift__", lhs << rhs )
165 | IMPLEMENT_OPERATOR( "__rshift__", lhs >> rhs )
166 | IMPLEMENT_OPERATOR( "__gt__", lhs > rhs )
167 | IMPLEMENT_OPERATOR( "__ge__", lhs >= rhs )
168 | IMPLEMENT_OPERATOR( "__lt__", lhs < rhs )
169 | IMPLEMENT_OPERATOR( "__le__", lhs <= rhs )
170 | IMPLEMENT_OPERATOR( "__eq__", lhs == rhs )
171 | IMPLEMENT_OPERATOR( "__ne__", lhs != rhs )
172 |
173 | // End
174 | //
175 | ;
176 | #undef IMPLEMENT_OPERATOR
177 |
178 | #define IMPLEMENT_ROPERATOR( name, ... ) \
179 | .def( name, [ ] ( const expression& rhs, int64_t lhs ) { return __VA_ARGS__; } ) \
180 | .def( name, [ ] ( const expression& rhs, uint64_t lhs ) { return __VA_ARGS__; } )
181 |
182 | ( *this )
183 | // Functions
184 | //
185 | IMPLEMENT_ROPERATOR( "__radd__", lhs + rhs )
186 | IMPLEMENT_ROPERATOR( "__rsub__", lhs - rhs )
187 | IMPLEMENT_ROPERATOR( "__rmul__", lhs* rhs )
188 | IMPLEMENT_ROPERATOR( "__rtruediv__", lhs / rhs )
189 | IMPLEMENT_ROPERATOR( "__rmod__", lhs% rhs )
190 | IMPLEMENT_ROPERATOR( "__rand__", lhs& rhs )
191 | IMPLEMENT_ROPERATOR( "__ror__", lhs | rhs )
192 | IMPLEMENT_ROPERATOR( "__rxor__", lhs^ rhs )
193 | IMPLEMENT_ROPERATOR( "__rlshift__", lhs << rhs )
194 | IMPLEMENT_ROPERATOR( "__rrshift__", lhs >> rhs )
195 |
196 | // End
197 | //
198 | ;
199 | #undef IMPLEMENT_ROPERATOR
200 | }
201 | };
202 | }
203 |
--------------------------------------------------------------------------------
/src/symex/expressions/unique_identifier.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel (@L33T) and contributors of the VTIL Project
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | //
7 | // 1. Redistributions of source code must retain the above copyright notice,
8 | // this list of conditions and the following disclaimer.
9 | // 2. Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | // 3. Neither the name of VTIL Project nor the names of its contributors
13 | // may be used to endorse or promote products derived from this software
14 | // without specific prior written permission.
15 | //
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | // POSSIBILITY OF SUCH DAMAGE.
27 | //
28 |
29 | // Furthermore, the following pieces of software have additional copyrights
30 | // licenses, and/or restrictions:
31 | //
32 | // |--------------------------------------------------------------------------|
33 | // | File name | Link for further information |
34 | // |-------------------------|------------------------------------------------|
35 | // | unique_identifier.hpp | https://github.com/vtil-project/VTIL-Core |
36 | // | | https://github.com/pybind/pybind11 |
37 | // |--------------------------------------------------------------------------|
38 | //
39 | #pragma once
40 |
41 | #include
42 | #include
43 |
44 | using namespace vtil::symbolic;
45 | namespace py = pybind11;
46 |
47 |
48 | namespace vtil::python
49 | {
50 | class unique_identifier_py : public py::class_
51 | {
52 | public:
53 | unique_identifier_py( const handle& scope, const char* name )
54 | : class_( scope, name )
55 | {
56 | ( *this )
57 | // Constructor
58 | //
59 | .def( py::init() )
60 |
61 | // Functions
62 | //
63 | .def( "hash", &unique_identifier::hash )
64 | .def( "__eq__", [ ] ( const unique_identifier& a, const unique_identifier& b ) { return a == b; } )
65 | .def( "__repr__", &unique_identifier::to_string )
66 | .def( "__str__", &unique_identifier::to_string )
67 |
68 | // End
69 | //
70 | ;
71 | }
72 | };
73 | }
74 |
--------------------------------------------------------------------------------
/src/wrappers/__init__.py:
--------------------------------------------------------------------------------
1 | from .vtil import *
2 |
--------------------------------------------------------------------------------
/src/wrappers/arch/__init__.py:
--------------------------------------------------------------------------------
1 | from ..vtil.arch import *
2 |
--------------------------------------------------------------------------------
/src/wrappers/common/__init__.py:
--------------------------------------------------------------------------------
1 | from ..vtil.common import *
2 |
--------------------------------------------------------------------------------
/src/wrappers/compiler/__init__.py:
--------------------------------------------------------------------------------
1 | from ..vtil.compiler import *
2 |
--------------------------------------------------------------------------------
/src/wrappers/symex/__init__.py:
--------------------------------------------------------------------------------
1 | from ..vtil.symex import *
2 |
--------------------------------------------------------------------------------