Skip to content

Commit

Permalink
Adjust as needed for Stubber 3 binary analysis usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
flagersgit committed Jun 12, 2024
1 parent 65e130c commit aa0fcb3
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 255 deletions.
13 changes: 7 additions & 6 deletions .github/py_osx.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/sh
#!/usr/bin/env zsh
set -ex
python3 ./bindings/python/setup.py --ninja --osx-arch=arm64 \
--lief-dir=/tmp/third-party/LIEF-0.13.0-Darwin/share/LIEF/cmake \
--llvm-dir=/tmp/third-party/LLVM-14.0.6-Darwin/lib/cmake/llvm \
build --build-temp=/tmp/arm64 bdist_wheel --skip-build \
--plat-name=macosx_${MACOSX_DEPLOYMENT_TARGET}_arm64

export MACOSX_DEPLOYMENT_TARGET=10.13
python3 ./bindings/python/setup.py --ninja --osx-arch='x86_64;arm64' \
--lief-dir=$GITHUB_WORKSPACE/third-party/LIEF-0.14.1-Darwin/share/LIEF/cmake \
--llvm-dir=$GITHUB_WORKSPACE/third-party/LLVM-14.0.6-Darwin/lib/cmake/llvm \
build bdist_wheel --skip-build

92 changes: 0 additions & 92 deletions .github/workflows/linux-x86-64.yml

This file was deleted.

61 changes: 0 additions & 61 deletions .github/workflows/osx.yml

This file was deleted.

7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
third-party/LIEF*
third-party/LLVM*
third-party/LLVM*
.vscode
build
dist
*.egg-info
icdump*.so
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.15)
project(iCDump VERSION 1.0.0 LANGUAGES CXX)
project(iCDump VERSION 1.0.0 LANGUAGES C CXX)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
Expand Down
8 changes: 5 additions & 3 deletions bindings/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SOURCE_DIR = CURRENT_DIR / ".." / ".."
PACKAGE_NAME = "icdump"

_CURRENT_VERSION = "1.1.0"
_CURRENT_VERSION = "1.2.0"

def report(*args):
print(*args)
Expand Down Expand Up @@ -94,7 +94,7 @@ def build_extension(self, ext):
f'-DLIEF_DIR={self.distribution.lief_dir}',
f'-DLLVM_DIR={self.distribution.llvm_dir}',
f'-DClang_DIR={clang_dir.as_posix()}',
'-DICDUMP_LLVM=OFF',
'-DICDUMP_LLVM=ON',
'-DICDUMP_PYTHON_BINDINGS=ON',
f'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={cmake_library_output_directory}',
f'-DPython_EXECUTABLE={sys.executable}',
Expand Down Expand Up @@ -231,8 +231,10 @@ def get_version() -> str:
}

setup(
name=PACKAGE_NAME,
distclass=Distribution,
ext_modules=[Module(PACKAGE_NAME)],
cmdclass=cmdclass,
version=version,
)
scripts=['bindings/python/tools/readobjc.py']
)
26 changes: 0 additions & 26 deletions scripts/docker/compile_icdump.sh

This file was deleted.

24 changes: 0 additions & 24 deletions scripts/docker/compile_lief.sh

This file was deleted.

23 changes: 0 additions & 23 deletions scripts/docker/compile_llvm.sh

This file was deleted.

19 changes: 1 addition & 18 deletions src/ObjC/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,51 +225,34 @@ uintptr_t Parser::decode_ptr(uintptr_t ptr) {
fixup.combined = ptr;
if (fixup.combined & (0xFFFF000000000000)) {
if (fixup.bind.bind == 1) {
// ICDUMP_DEBUG("FIXED PATH: DECODE(0x{:010x}): dyld_chained_ptr_64_bind.ordinal: 0x{:010x}", ptr, fixup.bind.ordinal);
// ICDUMP_DEBUG("FIXED PATH: DECODE(0x{:010x}): dyld_chained_ptr_64_bind.addend: 0x{:010x}", ptr, fixup.bind.addend);
// ICDUMP_DEBUG("FIXED PATH: DECODE(0x{:010x}): dyld_chained_ptr_64_bind.reserved: 0x{:010x}", ptr, fixup.bind.reserved);
// ICDUMP_DEBUG("FIXED PATH: DECODE(0x{:010x}): dyld_chained_ptr_64_bind.next: 0x{:010x}", ptr, fixup.bind.next);
// ICDUMP_DEBUG("FIXED PATH: DECODE(0x{:010x}): dyld_chained_ptr_64_bind.bind: 0x{:010x}", ptr, fixup.bind.bind);
auto linkEditSegment = bin().get_segment("__LINKEDIT");
size_t linkEditOffset = linkEditSegment->virtual_address() - linkEditSegment->file_offset();

size_t fixupsHeaderOffset = bin().dyld_chained_fixups()->data_offset() + linkEditOffset;
auto fixupsHeader = *(stream().peek<dyld_chained_fixups_header>(fixupsHeaderOffset));
// ICDUMP_DEBUG("FIXED PATH: DECODE(0x{:010x}): dyld_chained_fixups_header.symbols_offset: 0x{:010x}", ptr, fixupsHeader.symbols_offset);
// ICDUMP_DEBUG("FIXED PATH: DECODE(0x{:010x}): dyld_chained_fixups_header.imports_count: {}", ptr, fixupsHeader.imports_count);
// ICDUMP_DEBUG("FIXED PATH: DECODE(0x{:010x}): dyld_chained_fixups_header.imports_offset: 0x{:010x}", ptr, fixupsHeader.imports_offset);

dyld_chained_import fixupImport = *(stream().peek<dyld_chained_import>(fixupsHeaderOffset + fixupsHeader.imports_offset
+ (sizeof(dyld_chained_import) * fixup.bind.ordinal)));
auto bindSymbolName = *(stream().peek_string_at(fixupsHeaderOffset + fixupsHeader.symbols_offset + fixupImport.name_offset));
ICDUMP_WARN("FIXED PATH: DECODE(0x{:010x}): bind symbol: {}", ptr, bindSymbolName);
auto symbols = bin().symbols();
const auto it_symbol = std::find_if(std::begin(symbols), std::end(symbols),
[bindSymbolName] (const Symbol& s) {
return (s.name() == bindSymbolName && s.value() > 0);
});
if (it_symbol == std::end(symbols)) {
decoded = 0xFFFFFFFFFFFFFFFF;
ICDUMP_WARN("FIXED PATH: DECODE(0x{:010x}): Returning 0x{:010x} for N_UNDF symbol", ptr, decoded);
ICDUMP_WARN("FIXED PATH: DECODE(0x{:010x}): Returning 0x{:010x} for N_UNDF symbol: {}", ptr, decoded, bindSymbolName);
return decoded;
}
decoded = (*it_symbol).value();
ICDUMP_WARN("FIXED PATH: BIND DECODE(0x{:010x}): result = 0x{:010x}", ptr, decoded);
return decoded;
} else {
// ICDUMP_DEBUG("FIXED PATH: DECODE(0x{:010x}): dyld_chained_ptr_64_rebase.target: 0x{:010x}", ptr, fixup.rebase.target);
// ICDUMP_DEBUG("FIXED PATH: DECODE(0x{:010x}): dyld_chained_ptr_64_rebase.high8: 0x{:010x}", ptr, fixup.rebase.high8);
// ICDUMP_DEBUG("FIXED PATH: DECODE(0x{:010x}): dyld_chained_ptr_64_rebase.reserved: 0x{:010x}", ptr, fixup.rebase.reserved);
// ICDUMP_DEBUG("FIXED PATH: DECODE(0x{:010x}): dyld_chained_ptr_64_rebase.next: 0x{:010x}", ptr, fixup.rebase.next);
// ICDUMP_DEBUG("FIXED PATH: DECODE(0x{:010x}): dyld_chained_ptr_64_rebase.bind: 0x{:010x}", ptr, fixup.rebase.bind);
decoded = imagebase_ + fixup.rebase.target;
// ICDUMP_WARN("FIXED PATH: REBASE DECODE(0x{:010x}): result = 0x{:010x}", ptr, decoded);
return decoded;
}
}
}

ICDUMP_DEBUG("BROKEN PATH: DECODE(0x{:010x}): result = 0x{:010x}", ptr, decoded);
return decoded;
}

Expand Down
3 changes: 3 additions & 0 deletions third-party/Combine-LIEF.tool
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
find . -type d -exec bash -c 'mkdir -p ../LIEF-0.14.1-Darwin/{}' \;
find . -type f -exec bash -c 'if [[ $(lipo -info {} 2>&1) == *"fatal error"* ]]; then cp {} ../LIEF-0.14.1-Darwin/{}; fi ' \;
find . -type f -exec bash -c 'if [[ ! $(lipo -info {} 2>&1) == *"fatal error"* ]]; then lipo -create -output ../LIEF-0.14.1-Darwin/{} {} ../LIEF-0.14.1-Darwin-arm64/{}; fi ' \;
3 changes: 3 additions & 0 deletions third-party/Combine-LLVM.tool
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
find . -type d -exec bash -c 'mkdir -p ../clang-llvm-14.0.6/{}' \;
find . -type f -exec bash -c 'if [[ $(lipo -info {} 2>&1) == *"fatal error"* ]]; then cp {} ../clang-llvm-14.0.6/{}; fi ' \;
find . -type f -exec bash -c 'if [[ ! $(lipo -info {} 2>&1) == *"fatal error"* ]]; then lipo -create -output ../clang-llvm-14.0.6/{} {} ../clang-llvm-14.0.6-arm64/{}; fi ' \;

0 comments on commit aa0fcb3

Please sign in to comment.