forked from c3rb3ru5d3d53c/binlex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
280 lines (236 loc) · 7.97 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
cmake_minimum_required(VERSION 3.5)
set(VERSION_MAJOR 1)
set(VERSION_MINOR 1)
set(VERSION_PATCH 1)
set(GLOBAL_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
project(binlex
VERSION ${GLOBAL_VERSION}
DESCRIPTION "A Binary Genetic Traits Lexer and C++ Library"
)
if(MSVC)
add_definitions(-D_WIN32=1)
#add_definitions(-DBUILDER_STATIC_DEFINE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
endif()
# capstone
include(ExternalProject)
set(CAPSTONE_ROOT "${CMAKE_BINARY_DIR}/capstone/")
set(CAPSTONE_INCLUDE_DIRS "${CAPSTONE_ROOT}/include/")
set(CAPSTONE_GIT_URL "https://github.com/capstone-engine/capstone.git")
set(CAPSTONE_GIT_TAG 4.0.2)
ExternalProject_Add(
capstone
PREFIX "${CAPSTONE_ROOT}"
INSTALL_DIR "${CAPSTONE_ROOT}"
GIT_REPOSITORY "${CAPSTONE_GIT_URL}"
GIT_TAG "${CAPSTONE_GIT_TAG}"
GIT_SHALLOW ON
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCAPSTONE_BUILD_SHARED=OFF
-DCAPSTONE_BUILD_TESTS=OFF
-DCAPSTONE_MIPS_SUPPORT=OFF
-DCAPSTONE_PPC_SUPPORT=OFF
-DCAPSTONE_SPARC_SUPPORT=OFF
-DCAPSTONE_SYSZ_SUPPORT=OFF
-DCAPSTONE_XCORE_SUPPORT=OFF
-DCAPSTONE_X86_SUPPORT=ON
-DCMAKE_OSX_SYSROOT:STRING=${CMAKE_OSX_SYSROOT}
-DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}
-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
-DCMAKE_C_FLAGS_DEBUG:STRING=${CMAKE_C_FLAGS_DEBUG}
-DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE}
-DCMAKE_C_FLAGS_MINSIZEREL:STRING=${CMAKE_C_FLAGS_MINSIZEREL}
-DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_C_FLAGS_RELWITHDEBINFO}
-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
-DCMAKE_CXX_FLAGS_DEBUG:STRING=${DCMAKE_CXX_FLAGS_DEBUG}
-DCMAKE_CXX_FLAGS_RELEASE:STRING=${DCMAKE_CXX_FLAGS_RELEASE}
-DCMAKE_CXX_FLAGS_MINSIZEREL:STRING=${DCMAKE_CXX_FLAGS_MINSIZEREL}
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=${DCMAKE_CXX_FLAGS_RELWITHDEBINFO}
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
)
add_library(capstone_static STATIC IMPORTED)
set_target_properties(
capstone_static PROPERTIES IMPORTED_LOCATION
${CAPSTONE_ROOT}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}capstone${CMAKE_STATIC_LIBRARY_SUFFIX}
)
add_dependencies(capstone_static capstone)
# end
# lief
set(LIEF_PREFIX "${CMAKE_BINARY_DIR}/LIEF/")
set(LIEF_INSTALL_DIR "${LIEF_PREFIX}")
set(LIEF_INCLUDE_DIRS "${LIEF_PREFIX}/include/")
#set(LIB_LIEF ${CMAKE_BINARY_DIR}/LIEF/lib/LIEFMT${CMAKE_STATIC_LIBRARY_SUFFIX})
set(LIB_LIEF ${LIEF_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}LIEF${CMAKE_STATIC_LIBRARY_SUFFIX})
set(LIEF_GIT_URL "https://github.com/lief-project/LIEF.git")
set(LIEF_VERSION 0.11.0)
set(LIEF_CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE=Release
-DLIEF_DOC=off
-DLIEF_PYTHON_API=off
-DLIEF_EXAMPLES=off
-DCMAKE_CXX_FLAGS_RELEASE:STRING=${DCMAKE_CXX_FLAGS_RELEASE}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
)
if(MSVC)
list(APPEND ${LIEF_CMAKE_ARGS} -DLIEF_USE_CRT_RELEASE=MT)
endif()
# -DCMAKE_BUILD_TYPE=Release
ExternalProject_Add(LIEF
PREFIX ${LIEF_PREFIX}
GIT_REPOSITORY ${LIEF_GIT_URL}
GIT_TAG ${LIEF_VERSION}
INSTALL_DIR ${LIEF_INSTALL_DIR}
CMAKE_ARGS ${LIEF_CMAKE_ARGS}
)
add_library(lief_static STATIC IMPORTED)
set_target_properties(
lief_static PROPERTIES IMPORTED_LOCATION
${LIEF_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}LIEF${CMAKE_STATIC_LIBRARY_SUFFIX}
)
add_dependencies(lief_static LIEF)
# end
add_library(binlex SHARED
src/args.cpp
src/raw.cpp
src/common.cpp
src/blelf.cpp
src/decompiler.cpp
src/pe.cpp
src/sha256.c
)
add_dependencies(binlex LIEF)
add_dependencies(binlex capstone)
set_target_properties(binlex PROPERTIES SOVERSION ${GLOBAL_VERSION})
target_link_libraries(binlex
PUBLIC
lief_static
capstone_static
-lpthread
)
set_target_properties(binlex
PROPERTIES COMPILE_FLAGS
-DCMAKE_CXX_FLAGS_RELEASE:STRING=${DCMAKE_CXX_FLAGS_RELEASE}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
)
add_library(binlex::library ALIAS binlex)
if(MSVC)
target_compile_options(binlex PUBLIC /FIiso646.h)
set_property(TARGET binlex PROPERTY LINK_FLAGS /NODEFAULTLIB:MSVCRT)
endif()
target_include_directories(binlex
PUBLIC
${PROJECT_SOURCE_DIR}/include
${LIEF_INCLUDE_DIRS}
${CAPSTONE_INCLUDE_DIRS}
)
add_executable(binlex-bin
src/binlex.cpp
)
add_dependencies(binlex-bin LIEF)
add_dependencies(binlex-bin capstone)
target_link_libraries(binlex-bin
PRIVATE
binlex::library
)
set_target_properties(binlex-bin
PROPERTIES OUTPUT_NAME binlex
)
install(TARGETS binlex-bin DESTINATION bin)
install(TARGETS binlex
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
project(blyara
VERSION ${GLOBAL_VERSION}
DESCRIPTION "A Binlex Yara Generation Utility"
)
set(SOURCES_BLYARA
src/blyara.cpp
)
add_executable(blyara ${SOURCES_BLYARA})
#target_link_libraries(blyara -lm)
target_include_directories(blyara
PRIVATE
${PROJECT_SOURCE_DIR}/include
${LIEF_INCLUDE_DIRS}
${CAPSTONE_INCLUDE_DIRS}
)
install(TARGETS blyara DESTINATION bin)
if (BUILD_PYTHON_BINDINGS)
include_directories(
include/
${pybind11_INCLUDE_DIRS}
)
link_directories(src/)
add_subdirectory(bindings/python/pybind11/)
pybind11_add_module(pybinlex
SHARED
bindings/python/blelf.cpp
bindings/python/common.cpp
bindings/python/pe.cpp
bindings/python/raw.cpp
bindings/python/decompiler.cpp
bindings/python/pybinlex.cpp
)
target_link_libraries(pybinlex
PRIVATE
pybind11::module
binlex::library
PUBLIC
capstone_static
-lpthread
lief_static
${pybind11_LIBRARIES}
)
endif()
add_custom_target(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_MODULE_PATH}/uninstall.cmake"
)
set(CPACK_PACKAGE_NAME binlex)
string(CONCAT PKG_NAME "${CPACK_PACKAGE_NAME}"
"-"
"${VERSION_MAJOR}"
"."
"${VERSION_MINOR}"
"."
"${VERSION_PATCH}"
)
# Generates Debian Binary Package
SET(CPACK_GENERATOR DEB RPM)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Binary Genetic Traits Lexer Utilities and C++ Library"
CACHE STRING "Binary Genetic Traits Lexer Utilities and C++ Library"
)
set(CPACK_RESOURCE_FILE_LICENSE "")
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "@c3rb3ru5d3d53c")
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_PACKAGE_FILE_NAME "${PKG_NAME}")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libcapstone-dev")
# Generates release tarball
set(CPACK_SOURCE_GENERATOR TGZ ZIP)
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PKG_NAME}")
set(CPACK_SOURCE_IGNORE_FILES
"\.git/"
".*~$"
"\.gitmodules"
"\.gitattributes"
"\.appveyor.yml"
"docker/data/"
"samples/"
"tests/"
"pybinlex.egg-info/"
"*.whl"
"*.so"
"venv/"
"${CMAKE_CURRENT_BINARY_DIR}"
"${CPACK_SOURCE_IGNORE_FILES}"
)
include (CPack)