1
0
mirror of https://github.com/bitdefender/bddisasm.git synced 2025-01-05 12:50:56 +00:00

Merge pull request #40 from ianichitei/master

Improved installation
This commit is contained in:
Anichitei Ionel-Cristinel 2021-03-31 11:44:38 +03:00 committed by GitHub
commit 935654d5f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 548 additions and 513 deletions

View File

@ -38,24 +38,24 @@ jobs:
- name: Build dependencies - name: Build dependencies
run: | run: |
cd rapidjson cd rapidjson
mkdir _build mkdir build
cd _build cd build
cmake .. cmake ..
make -j$(nproc) make -j$(nproc)
sudo make install sudo make install
cd .. cd ..
cd .. cd ..
- name: Build bddisasm and bdshemu - name: Build all
run: | run: |
mkdir build mkdir build
cd build cd build
cmake .. -DINCLUDE_TOOL=y -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr
make bddisasm bdshemu -j$(nproc) make -j$(nproc)
cd - cd -
- name: Build disasmtool_lix - name: Install
run: | run: |
cd build cd build
make disasmtool -j$(nproc) sudo make install
cd - cd -
- name: Install setuptools - name: Install setuptools
run: | run: |
@ -63,15 +63,14 @@ jobs:
python3 -m pip install setuptools python3 -m pip install setuptools
- name: Build pybddisasm - name: Build pybddisasm
run: | run: |
sudo make install
cd pybddisasm cd pybddisasm
python3 setup.py build python3 setup.py build
cd .. cd -
- name: Create package - name: Create package
if: ${{ github.event_name == 'release' }} if: ${{ github.event_name == 'release' }}
run: | run: |
cd build cd build
make package sudo make package
cd - cd -
- name: Release - name: Release
if: ${{ github.event_name == 'release' }} if: ${{ github.event_name == 'release' }}
@ -80,7 +79,7 @@ jobs:
files: 'build/*.deb' files: 'build/*.deb'
repo-token: ${{ secrets.GITHUB_TOKEN }} repo-token: ${{ secrets.GITHUB_TOKEN }}
Windows-build: Windows-msbuild:
runs-on: windows-latest runs-on: windows-latest
@ -88,7 +87,7 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Add msbuild to PATH - name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2 uses: microsoft/setup-msbuild@v1.0.2
- name: Build bddisasm and bdshemu for x64 - name: Build all
run: MSBuild /t:Rebuild /p:Configuration=Release /p:Platform=x64 bddisasm.sln run: MSBuild /t:Rebuild /p:Configuration=Release /p:Platform=x64 bddisasm.sln
- name: Build bddisasm and bdshemu for Win32 - name: Build bddisasm and bdshemu for Win32
run: MSBuild /t:Rebuild /p:Configuration=Release /p:Platform=Win32 bddisasm.sln run: MSBuild /t:Rebuild /p:Configuration=Release /p:Platform=Win32 bddisasm.sln
@ -110,6 +109,23 @@ jobs:
files: 'x64-windows-release.zip;x86-windows-release.zip' files: 'x64-windows-release.zip;x86-windows-release.zip'
repo-token: ${{ secrets.GITHUB_TOKEN }} repo-token: ${{ secrets.GITHUB_TOKEN }}
Windows-cmake-build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
- uses: ilammy/msvc-dev-cmd@v1
- uses: seanmiddleditch/gha-setup-ninja@master
- name: Build all
run: |
mkdir build
cd build
cmake .. -G Ninja -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl
ninja
cd -
Code-checks: Code-checks:

2
.gitignore vendored
View File

@ -64,6 +64,6 @@ bdshemu_fuzz/out-32
bdshemu_fuzz/out-64 bdshemu_fuzz/out-64
docs/build docs/build
libbddisasm.pc libbddisasm.pc
build build*
.vscode .vscode
disasmtool_lix/_build disasmtool_lix/_build

View File

@ -1,172 +1,273 @@
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.12)
include("${CMAKE_CURRENT_LIST_DIR}/project-meta-info.in") option(BDD_INCLUDE_TOOL "Include the disasmtool executable" ON)
option(BDD_INCLUDE_ISAGENERATOR "Include the isagenerator target (if a python interpreter is found)" ON)
option(BDD_USE_EXTERNAL_VSNPRINTF "Expect nd_vsnprintf_s implementation from the integrator" OFF)
option(BDD_USE_EXTERNAL_MEMSET "Expect nd_memset implementation from the integrator" OFF)
set(disasm_version_file ${CMAKE_CURRENT_LIST_DIR}/inc/version.h) set(BDD_VER_FILE ${CMAKE_CURRENT_LIST_DIR}/inc/version.h)
file(STRINGS ${disasm_version_file} disasm_ver_major REGEX "DISASM_VERSION_MAJOR") file(STRINGS ${BDD_VER_FILE} disasm_ver_major REGEX "DISASM_VERSION_MAJOR")
file(STRINGS ${disasm_version_file} disasm_ver_minor REGEX "DISASM_VERSION_MINOR") file(STRINGS ${BDD_VER_FILE} disasm_ver_minor REGEX "DISASM_VERSION_MINOR")
file(STRINGS ${disasm_version_file} disasm_ver_patch REGEX "DISASM_VERSION_REVISION") file(STRINGS ${BDD_VER_FILE} disasm_ver_patch REGEX "DISASM_VERSION_REVISION")
string(REGEX REPLACE "#define DISASM_VERSION_MAJOR[ \t\r\n]*" "" disasm_ver_major ${disasm_ver_major}) string(REGEX REPLACE "#define DISASM_VERSION_MAJOR[ \t\r\n]*" "" disasm_ver_major ${disasm_ver_major})
string(REGEX REPLACE "#define DISASM_VERSION_MINOR[ \t\r\n]*" "" disasm_ver_minor ${disasm_ver_minor}) string(REGEX REPLACE "#define DISASM_VERSION_MINOR[ \t\r\n]*" "" disasm_ver_minor ${disasm_ver_minor})
string(REGEX REPLACE "#define DISASM_VERSION_REVISION[ \t\r\n]*" "" disasm_ver_patch ${disasm_ver_patch}) string(REGEX REPLACE "#define DISASM_VERSION_REVISION[ \t\r\n]*" "" disasm_ver_patch ${disasm_ver_patch})
message(STATUS "Extracted version from ${disasm_version_file}: ${disasm_ver_major}.${disasm_ver_minor}.${disasm_ver_patch}") message(STATUS "Extracted version from ${BDD_VER_FILE}: ${disasm_ver_major}.${disasm_ver_minor}.${disasm_ver_patch}")
project(bddisasm project(
bddisasm
VERSION ${disasm_ver_major}.${disasm_ver_minor}.${disasm_ver_patch} VERSION ${disasm_ver_major}.${disasm_ver_minor}.${disasm_ver_patch}
DESCRIPTION ${project_description} DESCRIPTION "Bitdefender x86 instruction decoder and emulator"
LANGUAGES C LANGUAGES C
) HOMEPAGE_URL https://github.com/bitdefender/bddisasm)
if (NOT CMAKE_BUILD_TYPE) # Use Release as the build type if no build type was specified and we're not using a multi-config generator .
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "No build type given. Will use 'Release'") message(STATUS "No build type given. Will use 'Release'")
set(CMAKE_BUILD_TYPE Release) set(CMAKE_BUILD_TYPE
"Release"
CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui.
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif () endif ()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/x64/${CMAKE_BUILD_TYPE}) # These are shared by bddisasm and bdshemu.
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/x64/${CMAKE_BUILD_TYPE}) if (NOT MSVC)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/x64/${CMAKE_BUILD_TYPE}) set(BDDISASM_COMMON_COMPILE_OPTIONS
"$<$<CONFIG:Release>:-U_FORTIFY_SOURCE>"
message(STATUS "Output directory set to: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") "$<$<CONFIG:Release>:-D_FORTIFY_SOURCE=2>"
-Wall
set(bddisasm_src -Wno-unknown-pragmas
bddisasm/crt.c -Wextra
bddisasm/bddisasm.c -Wshadow
) -Wformat-security
add_library(bddisasm STATIC ${bddisasm_src}) -Wstrict-overflow=2
set_target_properties(bddisasm PROPERTIES -Wstrict-prototypes
POSITION_INDEPENDENT_CODE ON -Wwrite-strings
C_STANDARD 11 -Wshadow
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} -Winit-self
) -Wno-unused-function
-Wno-multichar
set(bdshemu_src -Wno-incompatible-pointer-types
bdshemu/bdshemu.c -Wno-discarded-qualifiers
) -Wnull-dereference
add_library(bdshemu STATIC ${bdshemu_src}) -Wduplicated-cond
set_target_properties(bdshemu PROPERTIES -Werror=format-security
POSITION_INDEPENDENT_CODE ON -Werror=implicit-function-declaration
C_STANDARD 11 -pipe
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} -fwrapv
) -fno-strict-aliasing
add_dependencies(bdshemu bddisasm) -fstack-protector-strong
-fno-omit-frame-pointer
include_directories( -ffunction-sections
inc -fdata-sections
bddisasm/include -g3
) -gdwarf-4
-grecord-gcc-switches
if (CMAKE_BUILD_TYPE EQUAL "Release") -march=westmere)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Ofast -DNDEBUG")
else () else ()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -D_DEBUG -DDEBUG") set(BDDISASM_COMMON_COMPILE_OPTIONS /W4 /WX)
endif () endif ()
set(BDDISASM_COMPILE_OPTIONS set(BDDISASM_PUBLIC_HEADERS
"$<$<CONFIG:Release>:-U_FORTIFY_SOURCE>" "inc/bddisasm.h"
"$<$<CONFIG:Release>:-D_FORTIFY_SOURCE=2>" "inc/constants.h"
-Wall "inc/cpuidflags.h"
-Wno-unknown-pragmas "inc/disasmstatus.h"
-Wextra "inc/disasmtypes.h"
-Wshadow "inc/registers.h"
-Wformat-security "inc/version.h")
-Wstrict-overflow=2
-Wstrict-prototypes
-Wwrite-strings
-Wshadow
-Winit-self
-Wno-unused-function
-Wno-multichar
-Wno-incompatible-pointer-types
-Wno-discarded-qualifiers
-Wnull-dereference
-Wduplicated-cond
-Werror=format-security
-Werror=implicit-function-declaration
-pipe
-fwrapv
-fno-strict-aliasing
-fstack-protector-strong
-fno-omit-frame-pointer
-ffunction-sections
-fdata-sections
-g3
-gdwarf-4
-grecord-gcc-switches
-march=westmere
)
target_compile_options(bddisasm PRIVATE ${BDDISASM_COMPILE_OPTIONS})
target_compile_options(bdshemu PRIVATE ${BDDISASM_COMPILE_OPTIONS} -maes)
include(GNUInstallDirs) include(GNUInstallDirs)
set(CMAKE_SKIP_BUILD_RPATH TRUE) set(BDDISASM_INSTALL_INCLUDE_DIR
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) "${CMAKE_INSTALL_INCLUDEDIR}/bddisasm"
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") CACHE STRING "Path to bddisasm public include files.")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
get_filename_component(public_header_path "${PROJECT_SOURCE_DIR}/inc" REALPATH) # -- bddisasm --
file(GLOB_RECURSE public_headers "${public_header_path}/*.h")
set_target_properties(bddisasm PROPERTIES PUBLIC_HEADER "${public_headers}")
set(DEST_DIR "${CMAKE_INSTALL_PREFIX}") include(CheckFunctionExists)
set(LIB_DIR "${CMAKE_INSTALL_LIBDIR}") include(CheckSymbolExists)
set(INC_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
set(PRIVATE_LIBS "-lbdshemu -lbddisasm")
set(DATA_DIR "${CMAKE_INSTALL_DATADIR}")
CONFIGURE_FILE("${CMAKE_STATIC_LIBRARY_PREFIX}bddisasm.pc.in" add_library(
"${PROJECT_SOURCE_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}bddisasm.pc" bddisasm STATIC
@ONLY bddisasm/crt.c
) bddisasm/bddisasm.c
# Add the headers so they will show up in IDEs.
bddisasm/include/instructions.h
bddisasm/include/mnemonics.h
bddisasm/include/nd_crt.h
bddisasm/include/prefixes.h
bddisasm/include/table_evex.h
bddisasm/include/table_root.h
bddisasm/include/table_vex.h
bddisasm/include/table_xop.h
bddisasm/include/tabledefs.h
"${BDDISASM_PUBLIC_HEADERS}")
INSTALL(TARGETS bddisasm bdshemu if (NOT BDD_USE_EXTERNAL_VSNPRINTF)
EXPORT bddisasmTargets check_function_exists(vsnprintf HAS_VSNPRINTF)
LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" if (HAS_VSNPRINTF)
ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" target_compile_definitions(bddisasm PUBLIC -DBDDISASM_HAS_VSNPRINTF)
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/bddisasm" else ()
) # See https://cmake.org/Bug/view.php?id=15659
check_symbol_exists(vsnprintf stdio.h HAS_VSNPRINTF_SYMBOL)
if (HAS_VSNPRINTF_SYMBOL)
target_compile_definitions(bddisasm PUBLIC -DBDDISASM_HAS_VSNPRINTF)
endif ()
endif ()
endif ()
set(CMAKE_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/bddisasm) if (NOT BDD_USE_EXTERNAL_MEMSET)
install(EXPORT bddisasmTargets check_function_exists(memset HAS_MEMSET)
DESTINATION ${CMAKE_INSTALL_CONFIGDIR} if (HAS_MEMSET)
) target_compile_definitions(bddisasm PUBLIC -DBDDISASM_HAS_MEMSET)
endif ()
endif ()
include(CMakePackageConfigHelpers) set_target_properties(
bddisasm
PROPERTIES POSITION_INDEPENDENT_CODE ON
C_STANDARD 11
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
configure_package_config_file(${PROJECT_SOURCE_DIR}/bddisasmConfig.cmake.in ${PROJECT_BINARY_DIR}/bddisasmConfig.cmake target_include_directories(bddisasm PRIVATE bddisasm/include)
INSTALL_DESTINATION ${CMAKE_INSTALL_CONFIGDIR} target_include_directories(bddisasm PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR CMAKE_INSTALL_FULL_LIBDIR $<INSTALL_INTERFACE:${BDDISASM_INSTALL_INCLUDE_DIR}>)
)
write_basic_package_version_file(${PROJECT_BINARY_DIR}/bddisasmConfigVersion.cmake target_compile_options(bddisasm PRIVATE ${BDDISASM_COMMON_COMPILE_OPTIONS})
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES ${PROJECT_BINARY_DIR}/bddisasmConfig.cmake ${PROJECT_BINARY_DIR}/bddisasmConfigVersion.cmake set_target_properties(
DESTINATION ${CMAKE_INSTALL_CONFIGDIR} bddisasm
) PROPERTIES PUBLIC_HEADER "${BDDISASM_PUBLIC_HEADERS}"
VERSION ${CMAKE_PROJECT_VERSION}
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR})
INSTALL(FILES "${PROJECT_SOURCE_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}bddisasm.pc" add_library(bddisasm::bddisasm ALIAS bddisasm)
DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)
if (NOT CPACK_GENERATOR) # -- bdshemu --
set(CPACK_GENERATOR "DEB")
endif()
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Bitdefender HVI Team <hvmi-oss@bitdefender.com>") add_library(
set(CPACK_DEBIAN_PACKAGE_DEPENDS "") bdshemu STATIC
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64") bdshemu/bdshemu.c
set(CPACK_DEBIAN_PACKAGE_SECTION "devel") # Add the headers so they will show up in IDEs.
inc/bdshemu.h)
if (INCLUDE_TOOL) set_target_properties(
add_subdirectory("disasmtool_lix") bdshemu
add_dependencies(disasmtool bdshemu) PROPERTIES POSITION_INDEPENDENT_CODE ON
endif() C_STANDARD 11
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
include(CPack) target_include_directories(bdshemu PRIVATE bddisasm/include)
target_include_directories(bddisasm PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
$<INSTALL_INTERFACE:${BDDISASM_INSTALL_INCLUDE_DIR}>)
target_link_libraries(bdshemu PUBLIC bddisasm)
target_compile_options(bdshemu PRIVATE ${BDDISASM_COMMON_COMPILE_OPTIONS})
if (NOT MSVC)
target_compile_options(bdshemu PRIVATE -maes)
endif ()
set_target_properties(
bdshemu
PROPERTIES PUBLIC_HEADER "inc/bdshemu.h"
VERSION ${CMAKE_PROJECT_VERSION}
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR})
add_library(bddisasm::bdshemu ALIAS bdshemu)
# If this is the master project (and if the user requested it) add disasmtool.
if ((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) AND BDD_INCLUDE_TOOL)
if (WIN32)
add_subdirectory(disasmtool)
else ()
add_subdirectory(disasmtool_lix)
endif ()
endif ()
# If this is the master project (and if the user requested it) add isagenerator.
if ((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) AND BDD_INCLUDE_ISAGENERATOR)
add_subdirectory(isagenerator)
endif ()
# If this is the master project add install and package targets.
if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
set(BDDISASM_INSTALL_CMAKEDIR
"${CMAKE_INSTALL_LIBDIR}/cmake/bddisasm"
CACHE STRING "Path to bddisasm cmake files.")
set(BDDISASM_INSTALL_PCDIR
"${CMAKE_INSTALL_LIBDIR}/pkgconfig"
CACHE STRING "Path to bddisasm pkgconfig files.")
set(CMAKE_SKIP_BUILD_RPATH TRUE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
install(
TARGETS bddisasm bdshemu
EXPORT bddisasmTargets
INCLUDES
DESTINATION ${BDDISASM_INSTALL_INCLUDE_DIR}
PUBLIC_HEADER DESTINATION ${BDDISASM_INSTALL_INCLUDE_DIR} COMPONENT bddisasm_Development
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bddisasm_Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT bddisasm_Runtime
NAMELINK_COMPONENT bddisasm_Development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT bddisasm_Development)
if (BDD_INCLUDE_TOOL)
install(
TARGETS disasmtool
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bddisasm_Runtime)
endif ()
install(
EXPORT bddisasmTargets
DESTINATION ${BDDISASM_INSTALL_CMAKEDIR}
NAMESPACE bddisasm::
FILE bddisasmTargets.cmake
COMPONENT bddisasm_Development)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"bddisasmConfigVersion.cmake"
VERSION ${CMAKE_PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
install(
FILES bddisasmConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/bddisasmConfigVersion.cmake
DESTINATION ${BDDISASM_INSTALL_CMAKEDIR}
COMPONENT bddisasm_Development)
configure_file("bddisasm.pc.in" "${CMAKE_STATIC_LIBRARY_PREFIX}bddisasm.pc" @ONLY)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}bddisasm.pc"
DESTINATION "${BDDISASM_INSTALL_PCDIR}"
COMPONENT bddisasm_Development)
set(CPACK_PACKAGE_VENDOR "Bitdefender")
if (NOT CPACK_GENERATOR)
if (NOT WIN32)
set(CPACK_GENERATOR "DEB")
else ()
set(CPACK_GENERATOR "ZIP")
endif ()
endif ()
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Bitdefender HVI Team <hvmi-oss@bitdefender.com>")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
include(CPack)
endif ()

171
README.md
View File

@ -29,82 +29,146 @@ The main objectives of this disassembler are:
## Build and install ## Build and install
### Windows ### Using CMake
This is the recommended way of using the library.
Prerequesites:
- CMake 3.16 or newer (older version may work, but they have not been tested)
- Ninja (optional, but recommended, especially on Windows)
The build process was tested with GCC and Clang on Linux and MSVC on Windows. Note that the Windows kernel build target is available only when using [MSBuild](#Using-MSBuild-on-Windows).
To build the project run:
```console
mkdir build
cmake -B build .
cmake --build build
```
This will build `bddisasm`, `bdshemu`, and `disasmtool`. For skipping the `disasmtool` build configure CMake with `BDD_INCLUDE_TOOL=OFF`:
```console
mkdir build
cmake -B build . -DBDD_INCLUDE_TOOL=OFF
```
To install the project use:
```console
cmake --build build --target install
```
This will install the `bddisasm` and `bdshemu` static libraries and their public headers. If `disasmtool` was built it will also be installed. Depending on the install location you may need to run the command as root.
Optionally, if a python 3 interpreter is found the instruction tables can be regenerated with:
```console
cmake --build build --target isagenerator
```
To disable the `isagenerator` target configure CMake with `BDD_INCLUDE_ISAGENERATOR=OFF`.
Once installed, CMake projects can use `find_package` to find the library:
```cmake
find_package(bddisasm REQUIRED)
```
Two targets are provided:
- `bddisasm::bddisasm` - this should be used for targets that need only the decoder, without the shell code emulator
- `bddisasm::bdshemu` - this should be used for targets that need the shell code emulator (note that it will pull in `bddisasm::bddisasm` automatically)
There is no need to manually set include or link directories, simply use `target_link_libraries` with the needed target, for example:
```cmake
find_package(bddisasm REQUIRED)
# decoder-tool needs only the decoder library
target_link_libraries(decoder-tool PRIVATE bddisasm::bddisasm)
# emulator-tool needs bdshemu
target_link_libraries(emulator-tool PRIVATE bddisasm::bdshemu)
```
### nd_vsnprintf_s and nd_memset
By default, if `vsnprintf` and `memset` functions are available, the `nd_vsnprintf_s` and `nd_memset` functions are implemented directly by `bddisasm`. To signal this, `BDDISASM_HAS_VSNPRINTF` and `BDDISASM_HAS_MEMSET` will be added to the public compile definitions of `bddisasm`. This can be disabled by configuring CMake with `BDD_USE_EXTERNAL_VSNPRINTF=ON` and `BDD_USE_EXTERNAL_MEMSET=ON`.
#### Using as a sub-project
The project can be consumed as a sub-project, either by adding it as a git submodule, or by using [CMake's FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html):
With `FetchContent`:
```cmake
FetchContent_Declare(
bddisasm
GIT_REPOSITORY https://github.com/bddisasm/bddisasm
GIT_TAG origin/master
)
FetchContent_MakeAvailable(bddisasm)
```
As a git submodule:
```cmake
# Assuming the submodule is checked out at external/bddisasm
add_subdirectory(external/bddisasm)
```
In both cases the `bddisasm::bddisasm` and `bddisasm::bdshemu` targets will be provided.
When used as a sub-project the `disasmtool`, `isagenerator`, and `install` targets are not available.
### Using Make on Linux
To build the project run `make` in the root of the repository. This will build only the `bddisasm` and `bdshemu` static libraries, without `disasmtool`.
To install the project run `make install`. Depending on the install location you may need to run the command as root.
[nd_vsnprintf_s and nd_memset](#nd_vsnprintf_s-and-nd_memset) will not be defined by `bddisasm`, integrators must provide these functions.
### Using MSBuild on Windows
In order to build the projects on Windows you need: In order to build the projects on Windows you need:
* [Visual Studio 2019](https://visualstudio.microsoft.com/vs/) with the Desktop development with C++ workload. - [Visual Studio 2019](https://visualstudio.microsoft.com/vs/) with the Desktop development with C++ workload.
* [Windows SDK 10.0.18362.0](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk/). - [Windows SDK 10.0.18362.0](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk/).
* [Python 3.7 or newer](https://www.python.org/downloads/release/python-373/) - [Python 3.7 or newer](https://www.python.org/downloads/release/python-373/) (optional)
When you first open the solution Visual Studio should prompt you to install any missing components. When you first open `bddisasm.sln` in Visual Studio should prompt you to install any missing components.
This should be enough to build bddisasm, disasmtool and bdshemu for the Debug and Release configurations. This should be enough to build `bddisasm`, `bdshemu`, and `disasmtool`.
For the DebugKernel and ReleaseKernel configurations, [WDK 1903](https://go.microsoft.com/fwlink/?linkid=2085767) is needed, alongside the Windows Driver Kit Visual Studio extension (the WDK installer should take care of this). For the DebugKernel and ReleaseKernel configurations, [WDK 1903](https://go.microsoft.com/fwlink/?linkid=2085767) is needed, alongside the Windows Driver Kit Visual Studio extension (the WDK installer should take care of this).
For isagenerator, Python 3 is needed. For `isagenerator`, Python 3 is needed.
Building any of the projects is done directly from Visual Studio. Building any of the projects is done directly from Visual Studio.
The results will be in the bin directory in the root of the repository. The results will be in the bin directory in the root of the repository.
### Linux [nd_vsnprintf_s and nd_memset](#nd_vsnprintf_s-and-nd_memset) will not be defined by `bddisasm`, integrators must provide these functions.
In order to build the projects on Linux you need:
* gcc
* make
* cmake 3.12 or newer (optional)
#### Building and installing with make
In order to build bddisasm and bdshemu run `make` in the root of the repository. The results will be placed in the bin directory.
In order to install bddisasm and bdshemu run `make install`.
#### Building and installing with cmake
```console
mkdir build
cd build
cmake ..
make
make install
```
The default build type is Release. Using cmake provides support for pkg-config. Other CMake projects can also use `find_package(bddisasm CONFIG REQUIRED)` to find bddisasm. In both cases the following variables will be defined:
* `BDDISASM_INCLUDE_DIRS` - holds the path of the `bddisasm` directory, which contains the public `bddisasm` and `bdshemu` headers.
* `BDDISASM_LIBRARY_DIRS` - holds the path of the directory that contains the `libbddisasm.a` and `libbdshemu.a` libraries.
* `BDDISASM_LIBRARIES` - holds the libraries against which integrators should link.
### Building disasmtool_lix
For disasmtool_lix you also need:
* g++
* cmake 3.12 or newer
* [RapidJSON](https://github.com/Tencent/rapidjson/)
In order to build disasmtool_lix go to the disasmtool_lix directory and run `make`. The results will be in the bin directory in the disasmtool_lix/build directory.
## Decoding instructions ## Decoding instructions
### Decoding API ### Decoding API
There are 4 decoding functions, but internally, they all do the same, albeit some of them with implicit arguments: There are 4 decoding functions, but internally, they all do the same, albeit some of them with implicit arguments:
* `NDSTATUS NdDecode(INSTRUX *Instrux, const uint8_t *Code, uint8_t DefCode, uint8_t DefData)` - this API should be used only if you don't care about the length of the input buffer;
* `NDSTATUS NdDecodeEx(INSTRUX *Instrux, const uint8_t *Code, size_t Size, uint8_t DefCode, uint8_t DefData);` - decode instruction from a buffer with maximum length `Size`; - `NDSTATUS NdDecode(INSTRUX *Instrux, const uint8_t *Code, uint8_t DefCode, uint8_t DefData)` - this API should be used only if you don't care about the length of the input buffer;
* `NDSTATUS NdDecodeEx2(INSTRUX *Instrux, const uint8_t *Code, size_t Size, uint8_t DefCode, uint8_t DefData, uint8_t DefStack, uint8_t PreferedVendor);` - decode instructions with a preferred vendor; - `NDSTATUS NdDecodeEx(INSTRUX *Instrux, const uint8_t *Code, size_t Size, uint8_t DefCode, uint8_t DefData);` - decode instruction from a buffer with maximum length `Size`;
* `NDSTATUS NdDecodeWithContext(INSTRUX *Instrux, const uint8_t *Code, size_t Size, ND_CONTEXT *Context);` - base decode API; the input parameters - `DefCode`, `DefData`, `DefStack`, `VendMode` and `FeatMode` must all be filled in the `Context` structure before calling this function. The Context structure should also be initialized using `NdInitContext` before the first decode call. - `NDSTATUS NdDecodeEx2(INSTRUX *Instrux, const uint8_t *Code, size_t Size, uint8_t DefCode, uint8_t DefData, uint8_t DefStack, uint8_t PreferedVendor);` - decode instructions with a preferred vendor;
- `NDSTATUS NdDecodeWithContext(INSTRUX *Instrux, const uint8_t *Code, size_t Size, ND_CONTEXT *Context);` - base decode API; the input parameters - `DefCode`, `DefData`, `DefStack`, `VendMode` and `FeatMode` must all be filled in the `Context` structure before calling this function. The Context structure should also be initialized using `NdInitContext` before the first decode call.
Note that by default, the default vendor `ND_VEND_ANY` is used for decoding (which means that bddisasm will try to decode as much as possible). Also, the default features mask is `ND_FEAT_ALL`, meaning that bddisasm will optimistically try to decode instructions which are mapped onto the wide NOP space as well (for example, MPX or CET). If these parameters must be changed, it is advised to use the `NdDecodeWithContext` API. Note that by default, the default vendor `ND_VEND_ANY` is used for decoding (which means that bddisasm will try to decode as much as possible). Also, the default features mask is `ND_FEAT_ALL`, meaning that bddisasm will optimistically try to decode instructions which are mapped onto the wide NOP space as well (for example, MPX or CET). If these parameters must be changed, it is advised to use the `NdDecodeWithContext` API.
Converting decoded instructions to textual disassembly must be done using the `NdToText` API. bddisasm only supports Intel, masm-style syntax. Converting decoded instructions to textual disassembly must be done using the `NdToText` API. bddisasm only supports Intel, masm-style syntax.
### Example ### Example
Working with bddisasm is very easy. Decoding and printing the disassembly of an instruction is quick & simple: Working with bddisasm is very easy. Decoding and printing the disassembly of an instruction is quick & simple:
@ -201,6 +265,7 @@ int main()
``` ```
Working with the extended API is also trivial: Working with the extended API is also trivial:
```c ```c
INSTRUX ix; INSTRUX ix;
ND_CONTEXT ctx; ND_CONTEXT ctx;

View File

@ -1,7 +1,7 @@
dir_prefix=@DEST_DIR@ dir_prefix=@CMAKE_INSTALL_PREFIX@
lib=@LIB_DIR@ lib=@CMAKE_INSTALL_LIBDIR@
include=@INC_DIR@ include=@BDDISASM_INSTALL_INCLUDE_DIR@
data_dir=@DATA_DIR@ data_dir=@CMAKE_INSTALL_DATADIR@
prefix=${dir_prefix} prefix=${dir_prefix}
lib_dir=${dir_prefix}/${lib} lib_dir=${dir_prefix}/${lib}
@ -15,5 +15,5 @@ Description: "Bitdefender x86 instruction decoder and shellcode emulator"
URL: https://github.com/bitdefender/bddisasm URL: https://github.com/bitdefender/bddisasm
Version: @PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@ Version: @PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@
Libs: -L${lib_dir} @PRIVATE_LIBS@ Libs: -L${lib_dir} -lbdshemu -lbddisasm
Cflags: -I${include_dir} Cflags: -I${include_dir}

View File

@ -4,7 +4,6 @@
*/ */
#include "include/nd_crt.h" #include "include/nd_crt.h"
// //
// nd_strcat_s // nd_strcat_s
// //
@ -42,3 +41,22 @@ nd_strcat_s(
return dst; return dst;
} }
#if !defined(BDDISASM_NO_FORMAT) && defined(BDDISASM_HAS_VSNPRINTF)
#include <stdio.h>
int nd_vsnprintf_s(char *buffer, size_t sizeOfBuffer, size_t count, const char *format, va_list argptr)
{
UNREFERENCED_PARAMETER(count);
return vsnprintf(buffer, sizeOfBuffer, format, argptr);
}
#endif // !defined(BDDISASM_NO_FORMAT) && defined(BDDISASM_HAS_VSNPRINTF)
#if !defined(BDDISASM_NO_FORMAT) && defined(BDDISASM_HAS_MEMSET)
#include <string.h>
void *nd_memset(void *s, int c, size_t n)
{
return memset(s, c, n);
}
#endif // !defined(BDDISASM_NO_FORMAT) && defined(BDDISASM_HAS_MEMSET)

1
bddisasmConfig.cmake Normal file
View File

@ -0,0 +1 @@
include(${CMAKE_CURRENT_LIST_DIR}/bddisasmTargets.cmake)

View File

@ -1,13 +0,0 @@
@PACKAGE_INIT@
set(BDDISASM_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@")
set(BDDISASM_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@")
set(BDDISASM_LIBRARY_DIRS "@PACKAGE_CMAKE_INSTALL_FULL_LIBDIR@")
include(${CMAKE_CURRENT_LIST_DIR}/bddisasmTargets.cmake)
set(BDDISASM_LIBRARIES @PRIVATE_LIBS@)
check_required_components(bddisasm)
check_required_components(bdshemu)
set(BDDISASM_FOUND 1)

60
disasmtool/CMakeLists.txt Normal file
View File

@ -0,0 +1,60 @@
cmake_minimum_required(VERSION 3.16)
project(disasmtool LANGUAGES C)
# Use Release as the build type if no build type was specified and we're not using a multi-config generator .
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "No build type given. Will use 'Release'")
set(CMAKE_BUILD_TYPE
"Release"
CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui.
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif ()
add_executable(disasmtool disasmtool.c)
target_link_libraries(disasmtool PRIVATE bddisasm::bddisasm bddisasm::bdshemu)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
include(CheckIPOSupported)
check_ipo_supported(RESULT USE_IPO)
if (USE_IPO)
set_target_properties(bddisasm PROPERTIES INTERPROCEDURAL_OPTIMIZATION True)
endif ()
endif ()
if (NOT MSVC)
target_compile_options(
disasmtool
PRIVATE -Wall
-Wno-unknown-pragmas
-Wextra
-Wshadow
-Wformat-security
-Wstrict-overflow=2
-Wstrict-prototypes
-Wwrite-strings
-Wshadow
-Winit-self
-Wno-unused-function
-Wno-multichar
-Wno-incompatible-pointer-types
-Wno-discarded-qualifiers
-Wnull-dereference
-Wduplicated-cond
-Werror=format-security
-Werror=implicit-function-declaration
-pipe
-fwrapv
-fno-strict-aliasing
-fstack-protector-strong
-fno-omit-frame-pointer
-ffunction-sections
-fdata-sections
-g3
-gdwarf-4
-grecord-gcc-switches
-march=westmere)
else ()
target_compile_options(disasmtool PRIVATE /W4 /WX)
endif ()

View File

@ -7,6 +7,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <time.h> #include <time.h>
#include <Intrin.h>
typedef uint64_t QWORD, *PQWORD; typedef uint64_t QWORD, *PQWORD;
@ -61,6 +62,7 @@ char *gSpaces[16] =
}; };
#if !defined(BDDISASM_HAS_VSNPRINTF)
// //
// nd_vsnprintf // nd_vsnprintf
// //
@ -74,12 +76,14 @@ int nd_vsnprintf_s(
{ {
return _vsnprintf_s(buffer, sizeOfBuffer, count, format, argptr); return _vsnprintf_s(buffer, sizeOfBuffer, count, format, argptr);
} }
#endif // !defined(BDDISASM_HAS_VSNPRINTF)
#if !defined(BDDISASM_HAS_MEMSET)
void* nd_memset(void *s, int c, size_t n) void* nd_memset(void *s, int c, size_t n)
{ {
return memset(s, c, n); return memset(s, c, n);
} }
#endif // !defined(BDDISASM_HAS_MEMSET)
// //
// set_to_string // set_to_string

View File

@ -1,282 +1,66 @@
cmake_minimum_required (VERSION 3.12) cmake_minimum_required(VERSION 3.12)
project(disasmtool LANGUAGES CXX) project(disasmtool LANGUAGES CXX)
if (NOT CMAKE_BUILD_TYPE) # Use Release as the build type if no build type was specified and we're not using a multi-config generator .
message(STATUS "No build type given. Will use 'Release'!") if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release) message(STATUS "No build type given. Will use 'Release'")
endif() set(CMAKE_BUILD_TYPE
"Release"
CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui.
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif ()
if (CMAKE_CXX_FLAGS) add_executable(disasmtool disasmtool.cpp dumpers.cpp)
message(STATUS "Passed CXXFLAGS: ${CMAKE_CXX_FLAGS}")
endif()
if (("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") AND (CMAKE_CXX_FLAGS_DEBUG)) target_compile_options(
message(STATUS "Passed CXXFLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}") disasmtool
endif() PRIVATE "$<$<CONFIG:Release>:-U_FORTIFY_SOURCE>"
"$<$<CONFIG:Release>:-D_FORTIFY_SOURCE=2>"
-Wall
-Wextra
-Wshadow
-Wformat-security
-Wstrict-overflow=2
-Wno-unused-function
-Wno-multichar
-Werror=format-security
-pipe
-fpie
-fwrapv
-fno-strict-aliasing
-fstack-protector-strong
-ffunction-sections
-fdata-sections
-g3
-gdwarf-4
-grecord-gcc-switches
-march=nehalem
-fno-omit-frame-pointer)
if (("${CMAKE_BUILD_TYPE}" STREQUAL "Release") AND (CMAKE_CXX_FLAGS_RELEASE)) # find_package(bddisasm REQUIRED)
message(STATUS "Passed CXXFLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}") find_package(RapidJSON QUIET)
endif()
get_filename_component(DISASM_DIRECTORY "${PROJECT_SOURCE_DIR}/.." REALPATH)
set(DISASM_BUILD_PREFIX "bin/x64")
set(disasmtool_src_files
disasmtool.cpp
dumpers.cpp
)
find_package(RapidJSON)
target_link_libraries(disasmtool PRIVATE bddisasm::bddisasm bddisasm::bdshemu)
if (RapidJSON_FOUND) if (RapidJSON_FOUND)
message(STATUS "Dependency: rapidjson found") # :( https://github.com/satishbabariya/modern-cmake#good-boys-export-their-targets
include_directories(${RapidJSON_INCLUDE_DIRS}) target_include_directories(disasmtool PRIVATE ${RapidJSON_INCLUDE_DIRS})
add_compile_definitions(HAS_RAPIDJSON) target_sources(disasmtool PRIVATE rapidjson.cpp)
list(APPEND disasmtool_src_files rapidjson.cpp) target_compile_definitions(disasmtool PRIVATE HAS_RAPIDJSON)
else() endif ()
message(FATAL_ERROR "Dependency: rapidjson not found")
endif()
add_executable(${PROJECT_NAME} ${disasmtool_src_files})
target_compile_options(${PROJECT_NAME} PRIVATE
"$<$<CONFIG:Release>:-U_FORTIFY_SOURCE>"
"$<$<CONFIG:Release>:-D_FORTIFY_SOURCE=2>"
-Wall
-Wextra
-Wshadow
-Wformat-security
-Wstrict-overflow=2
-Wno-unused-function
-Wno-multichar
-Werror=format-security
-pipe
-fpie
-fwrapv
-fno-strict-aliasing
-fstack-protector-strong
-ffunction-sections
-fdata-sections
-g3
-gdwarf-4
-grecord-gcc-switches
-march=nehalem
-fno-omit-frame-pointer
# -fsanitize=leak
# -fsanitize=address
)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} \
-Wl,--fatal-warnings \
-Wl,--warn-common \
-Wl,--no-undefined \
-Wl,-z,noexecstack \
-Wl,-z,relro \
-Wl,-z,now \
-Wl,--build-id")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -Wl,-O1")
if (CMAKE_COMPILER_IS_GNUCXX)
if (NOT (CMAKE_CXX_COMPILER_VERSION LESS 6.0))
target_compile_options(${PROJECT_NAME} PRIVATE
-Wshift-overflow=2
-Wnull-dereference
-Wduplicated-cond
-Wlogical-op
-Wvla
)
endif()
if (NOT (CMAKE_CXX_COMPILER_VERSION LESS 7.0))
target_compile_options(${PROJECT_NAME} PRIVATE
-Wdangling-else
-Wshadow=global
-Walloc-zero
)
endif()
if (NOT (CMAKE_CXX_COMPILER_VERSION LESS 8.0))
target_compile_options(${PROJECT_NAME} PRIVATE
-Wmultistatement-macros
-Warray-bounds=2
-Wformat-overflow=2
-Wformat-truncation=1
-Wstringop-truncation
-Wpointer-arith
-Wdouble-promotion
-Wmissing-include-dirs
-Wuninitialized
-Wmissing-noreturn
-Wsuggest-attribute=noreturn
-Walloca
-Wtrampolines
-Wcast-qual
-Wcast-align
-Wparentheses
-Wfloat-conversion
-Wredundant-decls
-Wdisabled-optimization
-Woverlength-strings
-Wswitch-enum
-fstack-clash-protection
-static
)
endif()
if (NOT (CMAKE_CXX_COMPILER_VERSION LESS 9.0))
target_compile_options(${PROJECT_NAME} PRIVATE
-Wcatch-value=2
-Wduplicated-branches
-Wextra-semi
-Wif-not-aligned
-Wplacement-new=2
-Wsuggest-override
-Wunused-but-set-parameter
-Wswitch-enum
-Wuseless-cast
)
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_compile_options(${PROJECT_NAME} PRIVATE
-Wno-missing-braces
)
if (NOT (CMAKE_CXX_COMPILER_VERSION LESS 6.0))
target_compile_options(${PROJECT_NAME} PRIVATE
-Wshift-overflow
-Wnull-dereference
-Wvla
-Wdangling-else
-Wpragmas
-Wtautological-compare
-Wzero-as-null-pointer-constant
)
endif()
if (NOT (CMAKE_CXX_COMPILER_VERSION LESS 10.0))
target_compile_options(${PROJECT_NAME} PRIVATE
-Warray-bounds-pointer-arithmetic
-Wassign-enum
-Watomic-implicit-seq-cst
-Watomic-properties
-Wauto-import
-Wbad-function-cast
-Wbind-to-temporary-copy
-Wbitfield-enum-conversion
-Wbitwise-op-parentheses
-Wcomma
-Wconditional-uninitialized
-Wconsumed
-Wcstring-format-directive
-Wctad-maybe-unsupported
-Wcustom-atomic-properties
-Wdelete-non-abstract-non-virtual-dtor
-Wdeprecated-copy
-Wdeprecated-copy-dtor
-Wdeprecated-dynamic-exception-spec
-Wdeprecated-implementations
-Wdouble-promotion
-Wduplicate-enum
-Wduplicate-method-arg
-Wduplicate-method-match
-Wembedded-directive
-Wempty-init-stmt
-Wexit-time-destructors
-Wexplicit-ownership-type
-Wextra-semi
-Wfloat-conversion
-Wfor-loop-analysis
-Wformat-non-iso
-Wformat-type-confusion
-Wheader-hygiene
-Widiomatic-parentheses
-Winfinite-recursion
-Wlogical-op-parentheses
-Wmethod-signatures
-Wmissing-noreturn
-Wmissing-variable-declarations
-Wmove
-Wnon-gcc
-Wnon-virtual-dtor
-Wnull-pointer-arithmetic
-Wnullable-to-nonnull-conversion
-Wover-aligned
-Woverlength-strings
-Woverloaded-virtual
-Woverriding-method-mismatch
-Wpragma-pack
-Wpragma-pack-suspicious-include
-Wquoted-include-in-framework-header
-Wrange-loop-analysis
-Wredundant-move
-Wredundant-parens
-Wreserved-id-macro
-Wreturn-std-move
-Wself-assign
-Wself-move
-Wsemicolon-before-method-body
-Wshadow-all
-Wshift-sign-overflow
-Wsometimes-uninitialized
-Wstatic-in-inline
-Wstrict-prototypes
-Wstrict-selector-match
-Wstring-conversion
-Wsuper-class-method-mismatch
-Wswitch-enum
-Wtautological-bitwise-compare
-Wtautological-constant-in-range-compare
-Wtautological-overlap-compare
-Wtautological-type-limit-compare
-Wtautological-unsigned-enum-zero-compare
-Wtautological-unsigned-zero-compare
-Wunneeded-internal-declaration
-Wunneeded-member-function
-Wunreachable-code-aggressive
-Wunused-label
-Wunused-lambda-capture
-Wunused-local-typedef
-Wunused-variable
-Wvla-extension
-Wzero-length-array
-Wno-sign-conversion
-Wno-shorten-64-to-32
)
endif()
else()
message(FATAL_ERROR "Unsupported compiler!")
endif()
target_include_directories(${PROJECT_NAME} PRIVATE
${DISASM_DIRECTORY}/inc
${DISASM_DIRECTORY}/bddisasm/include
)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release") if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
include(CheckIPOSupported) include(CheckIPOSupported)
check_ipo_supported(RESULT USE_IPO) check_ipo_supported(RESULT USE_IPO)
set_target_properties(${PROJECT_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION True) if (USE_IPO)
endif() set_target_properties(bddisasm PROPERTIES INTERPROCEDURAL_OPTIMIZATION True)
endif ()
endif ()
set_target_properties(${PROJECT_NAME} set_target_properties(
PROPERTIES disasmtool
POSITION_INDEPENDENT_CODE ON PROPERTIES POSITION_INDEPENDENT_CODE ON
CXX_STANDARD 17 CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS ON CXX_EXTENSIONS ON)
)
target_link_directories(${PROJECT_NAME} PRIVATE "${DISASM_DIRECTORY}/bin/x64/${CMAKE_BUILD_TYPE}")
target_link_libraries(${PROJECT_NAME} PRIVATE bddisasm bdshemu)
INSTALL(TARGETS disasmtool
RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}"
)
unset(DISASM_LIB CACHE)
unset(SHEMU_LIB CACHE)

View File

@ -77,19 +77,22 @@ struct options {
extern "C" extern "C"
{ {
#if !defined(BDDISASM_HAS_VSNPRINTF)
int nd_vsnprintf_s(char *buffer, size_t sizeOfBuffer, [[maybe_unused]] size_t count, const char *format, va_list argptr) int nd_vsnprintf_s(char *buffer, size_t sizeOfBuffer, [[maybe_unused]] size_t count, const char *format, va_list argptr)
{ {
return vsnprintf(buffer, sizeOfBuffer, format, argptr); return vsnprintf(buffer, sizeOfBuffer, format, argptr);
} }
#endif // !defined(BDDISASM_HAS_VSNPRINTF)
#if !defined(BDDISASM_HAS_MEMSET)
void * void *
nd_memset(void *s, int c, size_t n) nd_memset(void *s, int c, size_t n)
{ {
return memset(s, c, n); return memset(s, c, n);
} }
#endif // !defined(BDDISASM_HAS_MEMSET)
} }
static bool _hexstring_to_bytes(options &opts) static bool _hexstring_to_bytes(options &opts)
{ {
if (!opts.hex_file.empty()) { if (!opts.hex_file.empty()) {

View File

@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.12)
project(isagenerator)
include(FindPython3)
find_package(Python3 COMPONENTS Interpreter)
if (Python3_FOUND)
add_custom_target(
isagenerator
COMMAND Python3::Interpreter generate_tables.py instructions
WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}"
COMMENT "Generating instruction tables")
endif (Python3_FOUND)

View File

@ -1,3 +0,0 @@
# project-meta-info.in
set(project_description "Bitdefender x86 instruction decoder and emulator")

View File

@ -22,18 +22,3 @@ int nd_to_text(INSTRUX *instrux, size_t rip, size_t bufsize, char *buf)
{ {
return NdToText(instrux, rip, bufsize, buf); return NdToText(instrux, rip, bufsize, buf);
} }
#include <stdio.h>
#include <string.h>
int
nd_vsnprintf_s(char *str, size_t sizeOfBuffer, size_t count, const char *format, va_list args)
{
(void)(sizeOfBuffer);
return vsnprintf(str, count, format, args);
}
void *nd_memset(void *s, int c, size_t n)
{
return memset(s, c, n);
}