Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite x86 decoder to use Capstone for instruction decoding #69

Merged
merged 82 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
0a599be
Add Capstone decoder
ceeac Jun 25, 2018
1fdd0b5
Add parity flag computation to flag funcs
ceeac Jun 27, 2018
f748753
Mark computed calls as computed
ceeac Jun 27, 2018
4223964
Add support for FP instructions and string instruction REP/REPNE pref…
ceeac Jun 28, 2018
f86ee18
Update SSL file for x86 semantics
ceeac Jun 28, 2018
f1bcc58
Add missing instructions to x86.ssl
ceeac Jun 28, 2018
fa1ec00
Fix wrong register names being returned by CapstoneDecoder::getRegName
ceeac Jun 28, 2018
a5a722d
Correct decoding of branch instructions
ceeac Jun 28, 2018
6f6eb03
Implement CapstoneDecoder::getRegSize
ceeac Jun 29, 2018
ded0715
Partially fix decompilation of fortran asgngoto
ceeac Jul 2, 2018
c57592d
Fix handling of floating point comparisons
ceeac Jul 2, 2018
7725028
Fix errors after rebase
ceeac Jul 14, 2018
1c6e89f
Fix wrong register name for FP stack registers
ceeac Jul 15, 2018
cf4be10
Update expected regression test outputs
ceeac Jul 15, 2018
d1f0366
Update changelog [ci skip]
ceeac Jul 15, 2018
4f9c151
Remove pentiumdecoder.h/cpp
ceeac Jul 24, 2018
fa17c99
Remove dead code from PentiumFrontend
ceeac Jul 24, 2018
26ad7e2
Temporarily disable failing regression tests
ceeac Jul 24, 2018
48f6b45
Install libcapstone via vcpkg on Windows
ceeac Jul 24, 2018
6cd9472
Use FindCapstone module for finding capstone
ceeac Jul 24, 2018
e28af37
Include vcpkg toolchain file for AppVeyor
ceeac Jul 24, 2018
ab6be1a
Use correct triplet for capstone library
ceeac Jul 24, 2018
505e572
Output prefix path on build
ceeac Jul 24, 2018
7cc32fb
Find Qt libraries via QTDIR instead of CMAKE_PREFIX_PATH
ceeac Jul 24, 2018
f89919d
Fix packages not found
ceeac Jul 25, 2018
c1ddeee
Fix compile error wrt. printing 64 bit ints on Windows
ceeac Jul 25, 2018
5aa0f23
Remove deprecated special processing of x86 instructions
ceeac Jul 25, 2018
0358f91
Add missing instructions to x86.ssl
ceeac Jul 25, 2018
7e1c80e
Fix debug output of x86 decoder
ceeac Jul 25, 2018
ae4b30c
Update comments for CapstoneDecoder
ceeac Aug 17, 2018
5ad3603
Disable call stack output when not in verbose mode
ceeac Aug 17, 2018
b3429d0
Use correct escape character in powershell script
ceeac Aug 18, 2018
93a83af
Do not link to capstone twice
ceeac Aug 18, 2018
d6842ff
Move x86 architecture specific decoding routines to separate class
ceeac Aug 19, 2018
0aa4988
Remove deprecated comment
ceeac Aug 22, 2018
ec927f5
Clean up CapstoneX86Decoder
ceeac Aug 22, 2018
906c3f4
Remove deprecated pentium.ssl file
ceeac Aug 22, 2018
f07ee8c
Add WAIT and CMP.reg8.reg8 instruction
ceeac Aug 22, 2018
2180d09
Fix crash when decoding jecxz instruction
ceeac Aug 24, 2018
0c72f9a
Add more semantics for x86 instructions
ceeac Aug 24, 2018
5a5663b
Fix order of instructions in x86.ssl
ceeac Aug 27, 2018
5b3a5c1
Clean up string instructions
ceeac Aug 27, 2018
f3968d9
Add semantics for CMOVcc instructions
ceeac Aug 27, 2018
185c7c7
Fix order of instruction operands for string instructions
ceeac Aug 27, 2018
8b850d9
Add semantics for LOOP instruction and for a BTS variant
ceeac Aug 27, 2018
9e2a0dd
Remove dead code from StatementHelper.cpp
ceeac Aug 28, 2018
070f625
Add semantics for FCOMPP instruction
ceeac Aug 28, 2018
108aa1a
Add more semantics for specific instruction variants
ceeac Aug 28, 2018
c626cf1
Fix crash when encountering unimplemented floating point comparison i…
ceeac Aug 28, 2018
dbcc000
Fix potential crash when replacing constant references
ceeac Aug 28, 2018
43e0998
Add %flags and %eflags register
ceeac Aug 28, 2018
b855329
Add more semantics for FP instructions
ceeac Aug 28, 2018
59d531d
Fix parameters of FISTP instruction
ceeac Aug 28, 2018
0d6b597
Fix assertion failure when decoding LOOP instruction
ceeac Aug 29, 2018
b7f6546
Add required Capstone dependency to readme [ci skip]
ceeac Oct 2, 2018
80762f5
Update x86.ssl
ceeac Oct 6, 2018
c878fb0
Add more semantics for shift and rotate instructions
ceeac Oct 12, 2018
0562ff0
Update x86.ssl
ceeac Oct 13, 2018
e706f81
Add semantics for ENTER instruction
ceeac Oct 30, 2018
dd66522
Fix errors after rebase
ceeac Oct 30, 2018
5a8e68e
Generate semantics for BSF/BSR instructions
ceeac Nov 12, 2018
be278ad
Add more semantics for x86 instructions
ceeac Nov 12, 2018
3d7b52b
Remove debug code
ceeac Nov 12, 2018
2b6d354
Remove unused regression test output files
ceeac Nov 12, 2018
0189ade
Update changelog [ci skip]
ceeac Nov 12, 2018
2652d2e
Clean up spacing for string instructions
ceeac Nov 13, 2018
c0b19b3
Add semantics for more string instructions
ceeac Nov 13, 2018
3c45073
Update required Capstone version in readme
ceeac Nov 13, 2018
e4f5400
Remove unused code for finding Qt
ceeac Nov 13, 2018
af8a8a8
Fix x86.ssl
ceeac Nov 13, 2018
1dad3d6
Fix CF usage for INC/DEC instructions
ceeac Nov 14, 2018
3209427
Fix semantics for shift flag functions
ceeac Nov 14, 2018
516f69a
Fix semantics for multiplication instructions
ceeac Nov 14, 2018
bf2a810
Add semantics for a ROR variant
ceeac Nov 14, 2018
76059e1
Fix FADD instruction
ceeac Nov 14, 2018
f7d6310
Add more FP instructions
ceeac Nov 14, 2018
04c2895
Add FCOS and FSINCOS instruction
ceeac Nov 14, 2018
1fcbb20
Add missing assignment types to x86.ssl
ceeac Nov 14, 2018
ba28b58
Add semantics for FP comparison instructions
ceeac Nov 14, 2018
607d4a4
Add semantics for LOOPE/LOOPNE
ceeac Nov 14, 2018
c72429f
Add semantics for STI instruction
ceeac Nov 14, 2018
92b573a
Update changelog
ceeac Nov 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ if (CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
endif(CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)

if (DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
endif (DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)

if (CMAKE_TOOLCHAIN_FILE)
include("${CMAKE_TOOLCHAIN_FILE}")
endif (CMAKE_TOOLCHAIN_FILE)


set(CMAKE_WARN_DEPRECATED ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake-scripts")
find_package(CCache)
Expand Down
11 changes: 11 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
v0.5.0 (in development)
-----------------------
- Fixed: Crash when decoding instructions with multiple instruction prefixes in some cases.
- Feature: The x86 decoder now recognizes a larger subset of the x86 instruction set.
- Improved: Better high level code output quality for x86 binaries due to more instructions being recognized.
- Improved: Performance of decoding x86 instructions.
- Improved: Unit test coverage.
- Improved: Regression test coverage.
- Changed: Replaced old pentium (x86) decoder by x86 decoder using libcapstone for decoding instructions.
- Technical: Improved compilation times and memory usage while compiling.

v0.4.0-alpha (2018-11-11)
-------------------------
- Fixed: Crashes when decompiling SPARC binaries.
Expand Down
3 changes: 2 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ it is currently recomended to build the development version (`develop`) of the d
- A C++ compiler compatible with C++17 (GCC 7+, Clang 5+, MSVC 2017+ are known to work)
- [CMake 3.8.0 or newer](https://cmake.org/download/)
- [Qt5](https://www.qt.io/download-open-source/) (Qt 5.9+ is known to work, earlier versions should also work)
- [Capstone 3.0.5 or newer](http://www.capstone-engine.org/)
- [Doxygen 1.8.13 or newer](http://www.doxygen.nl/) (optional, for documentation)
- [Python 3](https://www.python.org/downloads/) (optional, for regression tests)

Expand All @@ -29,7 +30,7 @@ On a Linux system you can build and install Boomerang with the usual cmake-make-
On a Debian-compatible system (e.g. Ubuntu) these commands will clone, build and install Boomerang:

```bash
sudo apt-get install git build-essential cmake qt5-default
sudo apt-get install git build-essential cmake qt5-default libcapstone-dev
cd YOUR_FAVOURITE_DEVELOPMENT_DIRECTORY
git clone https://github.com/BoomerangDecompiler/boomerang.git
cd boomerang && mkdir build && cd build
Expand Down
15 changes: 12 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#
# This file is part of the Boomerang Decompiler.
#
# See the file "LICENSE.TERMS" for information on usage and
# redistribution of this file, and for a DISCLAIMER OF ALL
# WARRANTIES.
#

version: "Build {build}"

os:
Expand All @@ -17,8 +25,7 @@ branches:
skip_commits:
message: /\[[aA]ppveyor [sS]kip\]/

pull_requests:
do_not_increment_build_number: true
cache: c:\tools\vcpkg\installed\

clone_folder: C:\projects\boomerang

Expand All @@ -29,6 +36,9 @@ build:
matrix:
fast_finish: true

pull_requests:
do_not_increment_build_number: true

init:
- cmd: cmake --version
- cmd: msbuild /version
Expand All @@ -52,4 +62,3 @@ artifacts:
- path: 'build\boomerang-*.zip'
name: Portable ZIP
type: File

90 changes: 90 additions & 0 deletions cmake-scripts/FindCapstone.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#
# This file is part of the Boomerang Decompiler.
#
# See the file "LICENSE.TERMS" for information on usage and
# redistribution of this file, and for a DISCLAIMER OF ALL
# WARRANTIES.
#
# - Find Capstone disassembler library.
#
# This module defines the following variables:
# Capstone_FOUND - true if Capstone was found
# Capstone_INCLUDE_DIRS - Include directories needed for Capstone
# Capstone_LIBRARIES - Libraries to link to when using Capstone
# Capstone_DLL - Path to Capstone DLL, if applicable
# Capstone_PDB - Path to Capstone PDB, if applicable

# Additionally, this module defines the IMPORTED target Capstone::Capstone,
# if Capstone has been found.
#

include(FindPackageHandleStandardArgs)

if (Capstone_INCLUDE_DIRS AND Capstone_LIBRARIES)
set(Capstone_FIND_QUIETLY TRUE)
endif (Capstone_INCLUDE_DIRS AND Capstone_LIBRARIES)

find_path(Capstone_INCLUDE_DIR capstone/capstone.h
/usr/local/include
/usr/include
$ENV{MINGDIR}/include
)

set(Capstone_NAMES capstone capstone_dll)
find_library(Capstone_LIBRARY
NAMES ${Capstone_NAMES}
PATHS /usr/local/lib /usr/lib/ $ENV{MINGDIR}/lib
)

if (WIN32)
foreach (DLLNAME ${Capstone_NAMES})
find_file(Capstone_DLL
NAME ${DLLNAME}.dll
PATHS /usr/local/bin /usr/bin/ $ENV{MINGDIR}/bin
)

find_file(Capstone_PDB
NAME ${DLLNAME}.pdb
PATHS /usr/local/bin /usr/bin/ $ENV{MINGDIR}/bin
)
endforeach ()

# Allow dll to be built without debug symbol support
find_package_handle_standard_args(Capstone
FOUND_VAR Capstone_FOUND
REQUIRED_VARS Capstone_LIBRARY Capstone_INCLUDE_DIR Capstone_DLL
)
else (WIN32)
find_package_handle_standard_args(Capstone
FOUND_VAR Capstone_FOUND
REQUIRED_VARS Capstone_LIBRARY Capstone_INCLUDE_DIR
)
endif (WIN32)


set(Capstone_INCLUDE_DIRS "${Capstone_INCLUDE_DIR}")
set(Capstone_LIBRARIES "${Capstone_LIBRARY}")

if (Capstone_FOUND OR NOT Capstone_FIND_REQUIRED)
# Only show variables when Capstone is required and not found
mark_as_advanced(
Capstone_INCLUDE_DIRS
Capstone_LIBRARIES
Capstone_CONFIG
Capstone_INCLUDE_DIR
Capstone_LIBRARY
)

if (WIN32)
mark_as_advanced(Capstone_DLL Capstone_PDB)
endif (WIN32)
endif (Capstone_FOUND OR NOT Capstone_FIND_REQUIRED)

if (Capstone_FOUND)
if (NOT TARGET Capstone::Capstone)
add_library(Capstone::Capstone UNKNOWN IMPORTED)
endif (NOT TARGET Capstone::Capstone)

set_target_properties(Capstone::Capstone PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Capstone_INCLUDE_DIRS}")
set_target_properties(Capstone::Capstone PROPERTIES IMPORTED_LOCATION "${Capstone_LIBRARIES}")
endif (Capstone_FOUND)
1 change: 1 addition & 0 deletions cmake-scripts/boomerang-configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,4 @@ add_definitions(-DV9_ONLY=0)
if (NOT BUILD_SHARED_LIBS)
add_definitions(-DBOOMERANG_BUILD_STATIC=1)
endif ()

2 changes: 1 addition & 1 deletion cmake-scripts/boomerang-dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# WARRANTIES.
#


find_package(Qt5Core REQUIRED HINTS $ENV{QTDIR})
if (Qt5Core_FOUND)
mark_as_advanced(Qt5Core_DIR)
Expand All @@ -18,3 +17,4 @@ if (Qt5Xml_FOUND)
endif (Qt5Xml_FOUND)

find_package(Threads)
find_package(Capstone REQUIRED)
1 change: 1 addition & 0 deletions data/signatures/common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@ signal.h
netdb.h
socket.h
termios.h
fortran.h

misc.h
6 changes: 6 additions & 0 deletions data/signatures/fortran.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
void f_setarg(int argc, char *argv[]);
void f_setsig();
void f_init();
void f_exit();

void do_lio(void *arg0, void *arg1, void *arg2, int arg3);
Loading