Skip to content

Commit

Permalink
BDDISASM v2.1.0 release - please consult the CHANGELOG for details ab…
Browse files Browse the repository at this point in the history
…out the modifications.
  • Loading branch information
vlutas committed Feb 20, 2024
1 parent 727c87e commit fad9c7e
Show file tree
Hide file tree
Showing 132 changed files with 303,153 additions and 112,057 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ compile_commands.json
pydis/.eggs
bdshemu_fuzz/out
bdshemu_fuzz/shfuzz
bdshemu_fuzz/in-32
bdshemu_fuzz/out-32
bdshemu_fuzz/in-64
bdshemu_fuzz/out-64
docs/build
libbddisasm.pc
Expand All @@ -67,3 +69,9 @@ disasmtool_lix/_build
bindings/rsbddisasm/target
bindings/rsbddisasm/Cargo.lock
bindings/pybddisasm/pybddisasm.egg-info
bindings/rsbddisasm/bddisasm/target
bindings/pybddisasm/pybddisasm/pybddisasm.py
bindings/pybddisasm/pybddisasm/pybddisasm_wrap.c

bddfuzz.tar
bindings/pybddisasm/.eggs
54 changes: 54 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Changelog

All notable (user-facing) changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).



## [2.1.0] - 2024-02-20

### Added
- Support in bddisasm for Intel REX2 prefix.
- Support in bddisasm for Intel APX extensions.
- Support in bddisasm for Intel USERMSR extensions.
- Support in bddisasm for prefix activation fields inside `INSTRUX` - these fields can be consulted to determine whether a particular prefix is present, accepted & active.
- New feature in bdshemu: `SHEMU_OPT_DIRECT_MAPPED_SHELL` - allows emulation with a smaller `IntBuff` at the cost of not having `WRITE_SELF` detections. The shellcode can be provided directly from its original location, without the need to allocate it in a dedicated memory region.
- New feature in bdshemu: `SHEMU_OPT_TRACK_LOOPS` - loops can now be tracked by bdshemu. `SHEMU_OPT_TRACE_LOOPS` can be used to log loop information.
- Support in bdshemu for APX instructions (both REX2 and EVEX encoded instructions) - the new `SHEMU_OPT_SUPPORT_APX` must be set in order to enable APX emulation.

### Changed
- Reduced the size of the `INSTRUX` structure from 856 bytes to 488 bytes (almost -43%!).
- Increased decoding performance from average 300 clocks/instruction to average 235 clocks/instruction (almost +20%!).
- New decode options - do not decode implicit operands - this further increases performance from average 235 clocks/instruction to 200 clocks/instruction (almost +15%!).
- Re-worked the Python scripts - both `disasmlib.py` and `generate_tables.py` have been significantly reworked, improving readability, and making them more efficient.
- `disasmtool` builds on Linux.

### Removed
- Support for Cyrix & VIA instructions - only current Intel & AMD instructions remain supported.
- disasmtool_lix has been removed. `disasmtool` is available on Linux as well.

### Breaking changes

#### Inside INSTRUX
- Removed `Iclass` field - it was aliased over `Instruction` field, which must be used from now on.
- Removed `OperandsEncodingMap` field - one can consult the `Encoding` field in each operand to determine the encoding.
- Removed `ExceptionClass` field - only `ExceptionType` remains, which contains an enum with all the exception types.
- Removed `Predicate` field - only `Condition` remains, which was aliased over `Predicate`.
- Removed `HasImm3`, `Immediate3`, `Imm3Length` and `Imm3Offset` fields, as they were not used/needed.
- Removed `Bhint`, `SseCondition`, `SignDisp` fields, as they were not used.
- Moved `FlagsAccess.RegAccess` outside and renamed it to `RflAccess`, to save more space.
- Switched from `char Mnemonic[32]` to `const char *Mnemonic` - this decreases INSTRUX size by almost 32 bytes, and increases perf.

#### Inside ND_OPERAND
- Removed `RawSize` - in most cases, `Size` and `RawSize` are identical; the only case where they might differ is for `Immediate` and `RelativeOffset` operands - in that case, one can consult the `RawSize` field in `Immediate` or `RelativeOffset`.

#### Inside ND_OPERAND_DECORATOR
- Removed `Broadcast` field, moved it inside `ND_OPDESC_MEMORY`.
- Removed `HasSae`, `HasEr` - they are per instruction, not per operand, and can be consulted directly inside `INSTRUX`.
- Moved `Msk` one level up, inside the `ND_OPERAND_DECORATOR` structure.

#### Defines & constants
- Removed `ND_PRED_*` defines - search & replace them with `ND_COND_*`.
- Removed `ND_HAS_PREDICATE` - use `ND_HAS_CONDITION` instead.
- Removed `ND_VEND_GEODE` and `ND_VEND_CYRIX`.
88 changes: 53 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
cmake_minimum_required(VERSION 3.16)

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_INCLUDE_ISAGENERATOR_X86 "Include the x86 isagenerator target (if a python interpreter is found)" ON)
option(BDD_INCLUDE_FUZZERS "Include the bdshemu fuzzer" OFF)
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)
option(BDD_ASAN "Build with ASAN" OFF)
option(BDD_UBSAN "Build with UBSAN" OFF)

set(BDD_VER_FILE ${CMAKE_CURRENT_LIST_DIR}/inc/version.h)
set(BDD_VER_FILE ${CMAKE_CURRENT_LIST_DIR}/inc/bddisasm_version.h)

file(STRINGS ${BDD_VER_FILE} disasm_ver_major REGEX "DISASM_VERSION_MAJOR")
file(STRINGS ${BDD_VER_FILE} disasm_ver_minor REGEX "DISASM_VERSION_MINOR")
file(STRINGS ${BDD_VER_FILE} disasm_ver_patch REGEX "DISASM_VERSION_REVISION")
file(STRINGS ${BDD_VER_FILE} disasm_ver_major REGEX "#define DISASM_VERSION_MAJOR")
file(STRINGS ${BDD_VER_FILE} disasm_ver_minor REGEX "#define DISASM_VERSION_MINOR")
file(STRINGS ${BDD_VER_FILE} disasm_ver_patch REGEX "#define 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_MINOR[ \t\r\n]*" "" disasm_ver_minor ${disasm_ver_minor})
Expand All @@ -25,7 +27,7 @@ project(
LANGUAGES C
HOMEPAGE_URL https://github.com/bitdefender/bddisasm)

# Use Release as the build type if no build type was specified and we're not using a multi-config generator .
# 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
Expand Down Expand Up @@ -79,12 +81,17 @@ endif ()

set(BDDISASM_PUBLIC_HEADERS
"inc/bddisasm.h"
"inc/constants.h"
"inc/cpuidflags.h"
"inc/disasmstatus.h"
"inc/disasmtypes.h"
"inc/registers.h"
"inc/version.h")
"inc/bddisasm_status.h"
"inc/bddisasm_types.h"
"inc/bddisasm_version.h"
"inc/bdx86_constants.h"
"inc/bdx86_core.h"
"inc/bdx86_cpuidflags.h"
"inc/bdx86_registers.h")

set(BDSHEMU_PUBLIC_HEADERS
"inc/bdshemu_x86.h"
"inc/bdshemu.h")

include(GNUInstallDirs)

Expand All @@ -100,20 +107,20 @@ include(CheckCCompilerFlag)

add_library(
bddisasm STATIC
bddisasm/crt.c
bddisasm/bddisasm.c
bddisasm/bdformat.c
bddisasm/bdhelpers.c
bddisasm/bddisasm_crt.c
bddisasm/bdx86_decoder.c
bddisasm/bdx86_formatter.c
bddisasm/bdx86_helpers.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/include/bddisasm_crt.h
bddisasm/include/bdx86_instructions.h
bddisasm/include/bdx86_mnemonics.h
bddisasm/include/bdx86_prefixes.h
bddisasm/include/bdx86_tabledefs.h
bddisasm/include/bdx86_table_evex.h
bddisasm/include/bdx86_table_root.h
bddisasm/include/bdx86_table_vex.h
bddisasm/include/bdx86_table_xop.h
"${BDDISASM_PUBLIC_HEADERS}")

if (NOT BDD_USE_EXTERNAL_VSNPRINTF)
Expand Down Expand Up @@ -154,15 +161,31 @@ set_target_properties(
VERSION ${CMAKE_PROJECT_VERSION}
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR})

if (BDD_ASAN)
target_compile_options(bddisasm PUBLIC "-fsanitize=address")
target_link_libraries(bddisasm PUBLIC "-fsanitize=address")
endif ()

if (BDD_UBSAN)
target_compile_options(bddisasm PUBLIC
"-fsanitize=undefined"
"-fno-sanitize=alignment")
target_link_libraries(bddisasm PUBLIC
"-fsanitize=undefined"
"-fno-sanitize=alignment")
endif ()

add_library(bddisasm::bddisasm ALIAS bddisasm)

# -- bdshemu --

add_library(
bdshemu STATIC
bdshemu/bdshemu.c
bdshemu/bdshemu_x86.c
# Add the headers so they will show up in IDEs.
inc/bdshemu.h)
bdshemu/include/bdshemu_common.h
"${BDSHEMU_PUBLIC_HEADERS}")

set_target_properties(
bdshemu
Expand All @@ -185,27 +208,22 @@ endif ()

set_target_properties(
bdshemu
PROPERTIES PUBLIC_HEADER "inc/bdshemu.h"
PROPERTIES PUBLIC_HEADER "${BDSHEMU_PUBLIC_HEADERS}"
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 ()
add_subdirectory(disasmtool)
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)
if ((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) AND BDD_INCLUDE_ISAGENERATOR_X86)
add_subdirectory(isagenerator)
endif ()

# If this is the master project (and if the user requested it) add the fuzzer.
if ((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) AND BDD_INCLUDE_FUZZERS)
add_subdirectory(bdshemu_fuzz)
endif ()
Expand Down Expand Up @@ -236,7 +254,7 @@ if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
COMPONENT bddisasm_Runtime
NAMELINK_COMPONENT bddisasm_Development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT bddisasm_Development)

if (BDD_INCLUDE_TOOL)
install(
TARGETS disasmtool
Expand Down
118 changes: 118 additions & 0 deletions Dockerfile.fuzzing
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
FROM ubuntu:22.04 as build

WORKDIR /bddfuzz

# Install everything we need to build AFL++ and honggfuzz and bdshemu
# We install both clang-13 and clang-15 because honggfuzz does not support newer versions of clang, but AFL++ wants
# the latest version so it is what it is
RUN apt-get update && apt-get install -y \
cmake make git \
binutils-dev \
libunwind-dev \
libblocksruntime-dev \
clang-13 \
clang-15 \
llvm-15 llvm-15-dev llvm-15-linker-tools llvm-15-runtime llvm-15-tools lld-15

# Cleanup
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

RUN mkdir /bddfuzz/fuzzers

# Build and install AFL++
RUN cd /bddfuzz/fuzzers && git clone https://github.com/AFLplusplus/AFLplusplus.git
RUN cd /bddfuzz/fuzzers/AFLplusplus && \
CC=clang-15 CXX=clang++-15 make source-only install LLVM_CONFIG=llvm-config-15 NO_NYX=1

# Build and install honggfuzz
RUN cd /bddfuzz/fuzzers && git clone --depth 1 --branch 2.5 https://github.com/google/honggfuzz.git
RUN cd /bddfuzz/fuzzers/honggfuzz && make install

# Remove the fuzzer source files as we no longer need them
RUN cd /bddfuzz/fuzzers/AFLplusplus && git clean -dxf && git clean -dXf && rm -rf /bddfuzz/fuzzers/AFLplusplus
RUN rm -rf /bddfuzz/fuzzers/honggfuzz
RUN rm -rf /bddfuzz/fuzzers/

ENV SRC /bddfuzz/src/

# Copy the relevant bddisasm sources
RUN mkdir "${SRC}"

COPY CMakeLists.txt "${SRC}"/CMakeLists.txt
COPY bddisasm.pc.in "${SRC}"/bddisasm.pc.in
COPY bddisasmConfig.cmake "${SRC}"/bddisasmConfig.cmake
COPY bddisasm "${SRC}"/bddisasm
COPY bdshemu "${SRC}"/bdshemu
COPY bdshemu_fuzz "${SRC}"/bdshemu_fuzz
COPY inc "${SRC}"/inc

# Now build all the variants
RUN mkdir build

# Build for AFL++ with afl-clang-lto
RUN mkdir /bddfuzz/build/afllto && cd /bddfuzz/build/afllto && \
cmake "${SRC}" -DCMAKE_C_COMPILER=afl-clang-lto -DCMAKE_CXX_COMPILER=afl-clang-lto++ \
-DCMAKE_BUILD_TYPE=Releaase \
-DBDD_INCLUDE_TOOL=OFF -DBDD_INCLUDE_ISAGENERATOR_X86=OFF \
-DBDD_INCLUDE_FUZZERS=ON && \
make shfuzz

# Build for honggfuzz
RUN mkdir /bddfuzz/build/hfuzz && cd /bddfuzz/build/hfuzz && \
cmake "${SRC}" -DCMAKE_C_COMPILER=hfuzz-clang -DCMAKE_CXX_COMPILER=hfuzz-clang++ \
-DCMAKE_BUILD_TYPE=Releaase \
-DBDD_INCLUDE_TOOL=OFF -DBDD_INCLUDE_ISAGENERATOR_X86=OFF \
-DBDD_INCLUDE_FUZZERS=ON && \
make shfuzz

# Build for libfuzzer with ASAN and UBSAN
RUN mkdir /bddfuzz/build/san && cd /bddfuzz/build/san && \
cmake "${SRC}" -DCMAKE_C_COMPILER=clang-15 -DCMAKE_CXX_COMPILER=clang-15++ \
-DCMAKE_BUILD_TYPE=Releaase \
-DBDD_INCLUDE_TOOL=OFF -DBDD_INCLUDE_ISAGENERATOR_X86=OFF \
-DBDD_INCLUDE_FUZZERS=ON -DBDD_FUZZ_WITH_LOGS=ON \
-DBDD_ASAN=ON -DBDD_UBSAN=ON && \
make shfuzz

RUN rm -rf "${SRC}"

# Save the fuzzers
RUN mkdir /bddfuzz/shf && cd /bddfuzz/shf && \
for d in /bddfuzz/build/*; do \
mkdir ./`basename "${d}"` && \
cp -v "${d}"/bdshemu_fuzz/shfuzz* ./`basename "${d}"`; \
done

# Remove the build directory
RUN rm -rf build

FROM ubuntu:22.04 as run

WORKDIR /bddfuzz

# Copy the fuzzers from the build stage
COPY --from=build /bddfuzz/shf /bddfuzz/shf

# Copy AFL++ and honggfuzz binaries
COPY --from=build /usr/local/bin/afl-* /usr/local/bin/
COPY --from=build /usr/local/bin/hfuzz-* /usr/local/bin/
COPY --from=build /usr/local/bin/honggfuzz /usr/local/bin/

RUN mkdir /bddfuzz/inputs
COPY bdshemu_fuzz/in-32 /bddfuzz/inputs/in-32
COPY bdshemu_fuzz/in-64 /bddfuzz/inputs/in-64

# Runtime dependencies for honggfuzz
RUN apt-get update && apt-get install -y binutils-dev libunwind-dev libblocksruntime-dev

# Cleanup
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# So we can share files between the host and the container (we don't want to loose the results when we stop the
# container).
ENV SHARE_DIR share

COPY bdshemu_fuzz/fuzzing_image_entrypoint.sh /bddfuzz/fuzzing_image_entrypoint.sh
RUN chmod +x /bddfuzz/fuzzing_image_entrypoint.sh

ENTRYPOINT ["/bddfuzz/fuzzing_image_entrypoint.sh"]
Loading

0 comments on commit fad9c7e

Please sign in to comment.