Skip to content

Commit 96953b0

Browse files
authored
upgrade to the latest lief version (#86)
* upgrade to the latest lief version * fix formatting * LIEF dropped MT postfix for windows, we will need to test the debug build to see if that also needs to change * update version.txt to 0.0.2 * add caching to speed up windows debug dependency builds Co-authored-by: Farzon Lotfi <[email protected]>
1 parent 3713d67 commit 96953b0

File tree

9 files changed

+239
-23
lines changed

9 files changed

+239
-23
lines changed

.github/workflows/cmake-debug.yml

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: CMake Debug
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
env:
12+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
13+
BUILD_TYPE: Debug
14+
15+
jobs:
16+
build:
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
matrix:
20+
os: [ubuntu-latest, macos-latest, windows-2019]
21+
include:
22+
- os: ubuntu-latest
23+
artifact_dlib_ext: .so
24+
artifact_staticlib_ext: .a
25+
- os: windows-2019
26+
artifact_exec_ext: .exe
27+
artifact_dlib_ext: .dll
28+
artifact_staticlib_ext: .lib
29+
# Note: I wanted to use env.BUILD_TYPE, but it isn't taking
30+
#artifact_out_dir: ${{ BUILD_TYPE }}/
31+
artifact_out_dir: Debug/
32+
artifact_os_name: Windows
33+
artifact_arch: x86_64
34+
- os: macos-latest
35+
artifact_dlib_ext: .dylib
36+
artifact_staticlib_ext: .a
37+
steps:
38+
- uses: actions/checkout@v2
39+
- run: |
40+
sudo apt install libcapstone-dev nasm mingw-w64 libedit-dev \
41+
libgl1-mesa-dev mesa-utils libgl1-mesa-glx libxrandr-dev \
42+
libxinerama-dev libxcursor-dev libxi-dev
43+
if: matrix.os == 'ubuntu-latest'
44+
- run: brew install capstone nasm mingw-w64 glfw glm
45+
if: matrix.os == 'macOS-latest'
46+
- run: choco install python3 nasm
47+
if: matrix.os == 'windows-2019'
48+
- name: Create Build Environment
49+
# Some projects don't allow in-source building, so create a separate build directory
50+
# We'll use this as our working directory for all subsequent commands
51+
run: cmake -E make_directory ${{github.workspace}}/build
52+
- name: Cache C++ dependencies in Packages Directory
53+
uses: actions/cache@v3
54+
with:
55+
path: |
56+
${{github.workspace}}/packages
57+
key: ${{ runner.OS }}-c++-packages-cache-${{ hashFiles('${{github.workspace}}/depsCache.json') }}
58+
restore-keys: |
59+
${{ runner.OS }}-c++-packages-cache
60+
#NOTE: this is temporary until i understand a bit more why i can't build binutil
61+
# Monitored with issue-32 https://github.com/farzonl/Disassembler/issues/32
62+
- name: Configure CMake (Mac)
63+
if: matrix.os == 'macOS-latest'
64+
# Use a bash shell so we can use the same syntax for environment variable
65+
# access regardless of the host operating system
66+
shell: bash
67+
working-directory: ${{github.workspace}}/build
68+
# Note the current convention is to use the -S and -B options here to specify source
69+
# and build directories, but this is only available with CMake 3.13 and higher.
70+
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
71+
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
72+
73+
- name: Configure CMake (Linux\Windows)
74+
if: matrix.os == 'ubuntu-latest' || matrix.os == 'windows-2019'
75+
# Use a bash shell so we can use the same syntax for environment variable
76+
# access regardless of the host operating system
77+
shell: bash
78+
working-directory: ${{github.workspace}}/build
79+
# Note the current convention is to use the -S and -B options here to specify source
80+
# and build directories, but this is only available with CMake 3.13 and higher.
81+
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
82+
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_INT_TESTS=true
83+
84+
- name: Build
85+
working-directory: ${{github.workspace}}/build
86+
shell: bash
87+
# Execute the build. You can specify a specific target with "--target <NAME>"
88+
run: cmake --build . --config $BUILD_TYPE
89+
90+
- name: Test (Unix-like)
91+
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macOS-latest'
92+
working-directory: ${{github.workspace}}/build
93+
shell: bash
94+
# Execute tests defined by the CMake configuration.
95+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
96+
run: ./src/test/Disassembler_TEST
97+
98+
- name: Test Windows
99+
if: matrix.os == 'windows-2019'
100+
working-directory: ${{github.workspace}}/build
101+
shell: bash
102+
# Execute tests defined by the CMake configuration.
103+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
104+
run: ./src/test/$BUILD_TYPE/Disassembler_TEST.exe
105+
- name: Prepare Binaries for upload (Mac\Linux)
106+
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macOS-latest'
107+
shell: bash
108+
run: |
109+
mkdir ${{github.workspace}}/artifacts
110+
cp build/src/libDisassembler${{ matrix.artifact_staticlib_ext }} ${{github.workspace}}/artifacts
111+
cp build/src/cli/disasm ${{github.workspace}}/artifacts
112+
cp build/src/gui/disasm-gui ${{github.workspace}}/artifacts
113+
cp build/plugins/xedPlugin/libxedPlugin${{ matrix.artifact_dlib_ext }} ${{github.workspace}}/artifacts
114+
pushd ${{github.workspace}}
115+
zip -r Gozihr-$(uname -s)-$(uname -m).zip artifacts
116+
popd
117+
- name: Prepare Binaries for upload (windows)
118+
if: matrix.os == 'windows-2019'
119+
shell: powershell
120+
run: |
121+
[system.io.directory]::CreateDirectory("${{github.workspace}}/artifacts")
122+
Copy-Item "build/src/${{ matrix.artifact_out_dir}}Disassembler${{ matrix.artifact_staticlib_ext }}" -Destination "${{github.workspace}}/artifacts"
123+
Copy-Item "build/src/cli/${{ matrix.artifact_out_dir }}disasm${{ matrix.artifact_exec_ext }}" -Destination "${{github.workspace}}/artifacts"
124+
Copy-Item "build/src/gui/${{ matrix.artifact_out_dir }}disasm-gui${{ matrix.artifact_exec_ext }}" -Destination "${{github.workspace}}/artifacts"
125+
Copy-Item "build/plugins/xedPlugin/${{ matrix.artifact_out_dir }}xedPlugin${{ matrix.artifact_dlib_ext }}" -Destination "${{github.workspace}}/artifacts"
126+
Compress-Archive -Path ${{github.workspace}}/artifacts/* -DestinationPath Gozihr-${{matrix.artifact_os_name}}-${{matrix.artifact_arch}}.zip
127+
- name: 'Upload Pull Request Artifact'
128+
uses: actions/upload-artifact@v3
129+
if: startsWith(github.ref, 'refs/pull/')
130+
with:
131+
name: Gozihr Pull Request Artifacts
132+
path: Gozihr-*.zip
133+
retention-days: 5

.github/workflows/cmake.yml renamed to .github/workflows/cmake-release.yml

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CMake
1+
name: CMake Release
22

33
on:
44
push:
@@ -50,6 +50,15 @@ jobs:
5050
# We'll use this as our working directory for all subsequent commands
5151
run: cmake -E make_directory ${{github.workspace}}/build
5252

53+
- name: Cache C++ dependencies in Packages Directory
54+
uses: actions/cache@v3
55+
with:
56+
path: |
57+
${{github.workspace}}/packages
58+
key: ${{ runner.OS }}-c++-packages-cache-${{ hashFiles('${{github.workspace}}/depsCache.json') }}
59+
restore-keys: |
60+
${{ runner.OS }}-c++-packages-cache
61+
5362
#NOTE: this is temporary until i understand a bit more why i can't build binutil
5463
# Monitored with issue-32 https://github.com/farzonl/Disassembler/issues/32
5564
- name: Configure CMake (Mac)
@@ -62,7 +71,14 @@ jobs:
6271
# and build directories, but this is only available with CMake 3.13 and higher.
6372
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
6473
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
65-
74+
- name: Cache C++ dependencies in Packages Directory
75+
uses: actions/cache@v3
76+
with:
77+
path: |
78+
${{github.workspace}}/packages
79+
key: ${{ runner.OS }}-c++-packages-cache-${{ hashFiles('${{github.workspace}}/depsCache.json') }}
80+
restore-keys: |
81+
${{ runner.OS }}-c++-packages-cache
6682
- name: Configure CMake (Linux\Windows)
6783
if: matrix.os == 'ubuntu-latest' || matrix.os == 'windows-2019'
6884
# Use a bash shell so we can use the same syntax for environment variable
@@ -134,8 +150,10 @@ jobs:
134150
- name: Set variables (Windows)
135151
if: matrix.os == 'windows-2019'
136152
run: |
137-
echo "VERSION=0.0.1" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
138-
echo "APPNAME=Gozihr" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
153+
$APP = type .\src\version\AppName.txt
154+
$VER = type .\src\version\Version.txt
155+
echo "VERSION=$VER" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
156+
echo "APPNAME=$APP" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
139157
140158
- name: Upload binaries to Release
141159
uses: softprops/action-gh-release@v1

CMakeLists.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ if(WIN32)
6868
endif()
6969
endif()
7070

71-
set(LIEF_VERSION "0.11.3")
71+
set(LIEF_VERSION "0.12.1")
7272
if( DEFINED BUILDLIEFSRC OR (WIN32 AND CMAKE_BUILD_TYPE MATCHES Debug))
7373
message(STATUS "starting a LIEF source build")
7474
download_file(https://github.com/lief-project/LIEF/archive/${LIEF_VERSION}.zip
7575
${CMAKE_SOURCE_DIR}/packages/LIEF-${LIEF_VERSION}.zip
7676
MD5
77-
fc6f9e277de0f25993007c0b10de2daf
77+
465563d8342e148a3d82b6b1cb36bd11
7878
)
7979
decompress(${CMAKE_SOURCE_DIR}/packages/LIEF-${LIEF_VERSION}.zip ${CMAKE_SOURCE_DIR}/packages/LIEF-src)
8080
buildLIEF(${CMAKE_SOURCE_DIR}/packages/LIEF-src
@@ -89,19 +89,19 @@ else()
8989
download_file(https://github.com/lief-project/LIEF/releases/download/${LIEF_VERSION}/LIEF-${LIEF_VERSION}-Linux-x86_64.tar.gz
9090
${CMAKE_SOURCE_DIR}/packages/LIEF-${LIEF_VERSION}.tar.gz
9191
MD5
92-
cffdd77556bd35e8cc32ff9742605a4e)
92+
eb604e6d494e86a888e41ef4df549b3a)
9393
decompress(${CMAKE_SOURCE_DIR}/packages/LIEF-${LIEF_VERSION}.tar.gz ${CMAKE_SOURCE_DIR}/packages/LIEF)
9494
elseif(WIN32)
9595
download_file(https://github.com/lief-project/LIEF/releases/download/${LIEF_VERSION}/LIEF-${LIEF_VERSION}-win64.zip
9696
${CMAKE_SOURCE_DIR}/packages/LIEF-${LIEF_VERSION}-win64.zip
9797
MD5
98-
a5e6a5ef5933b1296739d859b198f857)
98+
ca4665c47fb6d4b68a30199195fa7037)
9999
decompress(${CMAKE_SOURCE_DIR}/packages/LIEF-${LIEF_VERSION}-win64.zip ${CMAKE_SOURCE_DIR}/packages/LIEF)
100100
elseif(APPLE)
101101
download_file(https://github.com/lief-project/LIEF/releases/download/${LIEF_VERSION}/LIEF-${LIEF_VERSION}-Darwin-x86_64.tar.gz
102102
${CMAKE_SOURCE_DIR}/packages/LIEF-${LIEF_VERSION}.tar.gz
103103
MD5
104-
d033f69581f61386cca64ff0fb9b4e88)
104+
5d609361f22b6f9a8dc22f2c6fb541a7)
105105
decompress(${CMAKE_SOURCE_DIR}/packages/LIEF-${LIEF_VERSION}.tar.gz ${CMAKE_SOURCE_DIR}/packages/LIEF)
106106
else()
107107
message(FATAL_ERROR "No other platforms are supported.")

depsCache.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"LIEF" : {
3+
"Src": "465563d8342e148a3d82b6b1cb36bd11",
4+
"Linux": "eb604e6d494e86a888e41ef4df549b3a",
5+
"Windows" : "ca4665c47fb6d4b68a30199195fa7037",
6+
"MacOS": "5d609361f22b6f9a8dc22f2c6fb541a7"
7+
},
8+
"Catch2" : {
9+
"Src": "209cbb2f8f37224cc5f7261cf9388bc2"
10+
},
11+
"CMDParser" : {
12+
"Src": "8449f7da1097659698193bc0ddb24ef7"
13+
},
14+
"nlohmannJson" : {
15+
"Src": "7804b38146921d03374549c9e2a5e3acda097814c43caf2b96a0278e58df26e0"
16+
},
17+
"Capstone" : {
18+
"Windows": "a6ad5a3bd6842cb7fadc3f3e5ed8bf20"
19+
},
20+
"myers-diff" : {
21+
"Src" : "90486b3453ab76ab2a1498dc64c79060"
22+
},
23+
"glad" : {
24+
"Src" : "262e8984dbde2f359207ffa8e609aa50"
25+
},
26+
"glfw3" : {
27+
"Src": "f794d9ad899a64894782884be79d644b"
28+
},
29+
"imgui" : {
30+
"Src": "78af0cf170fb3f2a431eb39cac7f55b8"
31+
},
32+
"ImGuiFileDialog": {
33+
"Src" : "13e1abe33aeb0b869307a238967038ae"
34+
}
35+
}

src/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ elseif(WIN32)
2727
set(CAPSTONE_INCLUDE_DIRS ${CAPSTONE_DIR}/include/capstone)
2828

2929
set(CAPSTONE_LDFLAGS "${CAPSTONE_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}capstone${CMAKE_STATIC_LIBRARY_SUFFIX}")
30-
set(LIEF_LDFLAGS "${LIEF_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}LIEF${MTPOSTFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}")
30+
set(LIEF_LDFLAGS "${LIEF_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}LIEF${CMAKE_STATIC_LIBRARY_SUFFIX}")
3131
list(APPEND TargetLibraries
3232
${LIEF_LDFLAGS}
3333
)

src/parser.cpp

+31-11
Original file line numberDiff line numberDiff line change
@@ -75,43 +75,63 @@ void Binary::elfParser() {
7575
std::unique_ptr<LIEF::ELF::Binary> elfBinary =
7676
LIEF::ELF::Parser::parse(this->Path());
7777
auto header = elfBinary->header();
78-
LIEF::ELF::Section &textSection = elfBinary->get_section(".text");
79-
textSection.content().swap(this->mInstructions);
78+
LIEF::ELF::Section *textSection = elfBinary->get_section(".text");
79+
this->mInstructions.resize(
80+
std::max(this->mInstructions.size(), textSection->content().size()));
81+
std::copy(textSection->content().begin(), textSection->content().end(),
82+
this->mInstructions.begin());
8083

8184
this->os = OStype::LINUX;
8285
this->arch = ::GetArch(header.machine_type());
83-
this->textSectionStartAddress = textSection.virtual_address();
86+
this->textSectionStartAddress = textSection->virtual_address();
8487
this->mBinaryInternal->setElf(elfBinary);
8588
}
8689

8790
void Binary::peParser() {
8891

8992
auto peBinary = LIEF::PE::Parser::parse(this->Path());
90-
LIEF::PE::Section &textSection = peBinary->get_section(".text");
91-
textSection.content().swap(this->mInstructions);
93+
LIEF::PE::Section *textSection = peBinary->get_section(".text");
94+
this->mInstructions.resize(
95+
std::max(this->mInstructions.size(), textSection->content().size()));
96+
std::copy(textSection->content().begin(), textSection->content().end(),
97+
this->mInstructions.begin());
9298
this->os = OStype::WINDOWS;
9399
this->arch = ::GetArch(peBinary->header().machine());
94-
this->textSectionStartAddress = textSection.virtual_address();
100+
this->textSectionStartAddress = textSection->virtual_address();
95101
this->mBinaryInternal->setPE(peBinary);
96102
}
97103

98104
void Binary::machOParser() {
99105
// For fat binary we take the last one...
100106
LIEF::MachO::FatBinary *fat =
101107
LIEF::MachO::Parser::parse(this->Path()).release();
102-
LIEF::MachO::Binary *binaryData = nullptr;
108+
std::unique_ptr<LIEF::MachO::Binary> binaryData = nullptr;
103109
if (fat) {
110+
if (fat->size() > 1) {
111+
std::cout << "Warning number of mach-O binary files is: " << fat->size()
112+
<< std::endl;
113+
for (int i = 0; i < fat->size(); i++) {
114+
std::cout << "fat[" << i
115+
<< "] Arch = " << ::GetArch(fat->at(i)->header().cpu_type())
116+
<< std::endl;
117+
}
118+
std::cout << "Picking the last format: "
119+
<< GetArch(fat->at(fat->size() - 1)->header().cpu_type())
120+
<< std::endl;
121+
}
104122
binaryData = fat->pop_back();
105-
delete fat;
106123
}
107124

108125
auto header = binaryData->header();
109-
LIEF::MachO::Section &textSection = binaryData->get_section("__text");
110-
textSection.content().swap(this->mInstructions);
126+
LIEF::MachO::Section *textSection = binaryData->get_section("__text");
127+
this->mInstructions.resize(
128+
std::max(this->mInstructions.size(), textSection->content().size()));
129+
std::copy(textSection->content().begin(), textSection->content().end(),
130+
this->mInstructions.begin());
111131

112132
this->os = OStype::MACOS;
113133
this->arch = ::GetArch(header.cpu_type());
114-
this->textSectionStartAddress = textSection.virtual_address();
134+
this->textSectionStartAddress = textSection->virtual_address();
115135
this->mBinaryInternal->setMachO(binaryData);
116136
}
117137

src/runtime/binaryDisassemble.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,20 @@ BinaryDisassemble::disassemble(const std::string &filename,
3333
return BinaryDisassemble::disassemble(*(binary.get()), dType);
3434
}
3535

36+
std::unique_ptr<AbstractDisassembler>
37+
BinaryDisassemble::disassemble(const Binary &binary,
38+
const std::string &dynamicLibPaths) {
39+
DisassemblerType dType =
40+
Disassembler::checkAndInitDynamicDisassemblers(dynamicLibPaths);
41+
return BinaryDisassemble::disassemble(binary, dType);
42+
}
43+
3644
bool BinaryDisassemble::action(const std::string &filename,
3745
const std::string &dynamicLibPaths,
3846
bool shouldPrintFileNames, std::ostream &out) {
3947
std::unique_ptr<Binary> binary = ASMParser::Parser(filename);
4048

41-
auto disasm = disassemble(filename, dynamicLibPaths);
49+
auto disasm = disassemble(*(binary.get()), dynamicLibPaths);
4250

4351
out << *(binary.get()) << std::endl;
4452
if (shouldPrintFileNames) {

src/runtime/binaryDisassemble.h

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class BinaryDisassemble {
2525
DisassemblerType dtype = DisassemblerType::CAPSTONE);
2626
static std::unique_ptr<AbstractDisassembler>
2727
disassemble(const std::string &filename, const std::string &dynamicLibPaths);
28+
static std::unique_ptr<AbstractDisassembler>
29+
disassemble(const Binary &binary, const std::string &dynamicLibPaths);
2830
static bool action(const std::string &filename,
2931
const std::string &dynamicLibPaths,
3032
bool shouldPrintFileNames = false,

src/version/Version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.1
1+
0.0.2

0 commit comments

Comments
 (0)