diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml new file mode 100644 index 0000000..2e4b65a --- /dev/null +++ b/.github/workflows/c-cpp.yml @@ -0,0 +1,22 @@ +name: C/C++ CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: macos-latest + + steps: + - uses: actions/checkout@v3 + - name: build + run: ./build.sh + - name: upload artifact + uses: actions/upload-artifact@v2 + with: + name: iBoot64Patcher + path: ${{ github.workspace }}/iBoot64Patcher diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index ecefc5d..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,109 +0,0 @@ -name: Build - -on: - push: - pull_request: - workflow_dispatch: - schedule: - - cron: '0 0 1 1 *' - - cron: '0 0 1 4 *' - - cron: '0 0 30 6 *' - - cron: '0 0 28 9 *' - - cron: '0 0 27 12 *' - -jobs: - macOS: - env: - PROCURSUS: /opt/procursus - PATH: /opt/procursus/bin:/opt/procursus/libexec/gnubin:/usr/local/lib/ruby/gems/2.7.0/bin:/usr/local/opt/ruby@2.7/bin:/usr/local/opt/pipx_bin:/Users/runner/.cargo/bin:/usr/local/opt/curl/bin:/usr/local/bin:/usr/local/sbin:/Users/runner/bin:/Users/runner/.yarn/bin:/Users/runner/Library/Android/sdk/tools:/Users/runner/Library/Android/sdk/platform-tools:/Users/runner/Library/Android/sdk/ndk-bundle:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/usr/bin:/bin:/usr/sbin:/sbin:/Users/runner/.dotnet/tools:/Users/runner/.ghcup/bin:/Users/runner/hostedtoolcache/stack/2.7.3/x64 - - runs-on: macos-11 - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - submodules: 'true' - fetch-depth: 0 - - - name: Build - run: | - ${{ github.workspace }}/.github/workflows/mac-bootstrap.sh - ${{ github.workspace }}/.github/workflows/mac-build.sh - ${{ github.workspace }}/.github/workflows/mac-post.sh - - - name: Upload versioning - uses: actions/upload-artifact@v2 - with: - name: Versioning - path: | - ${{ github.workspace }}/latest_build_sha.txt - ${{ github.workspace }}/latest_build_num.txt - - - name: Upload x86_64-RELEASE - uses: actions/upload-artifact@v2 - with: - name: iBoot64Patcher-macOS-x86_64-RELEASE - path: ${{ github.workspace }}/iBoot64Patcher-macOS-x86_64-*-RELEASE.tar.xz - - - name: Upload x86_64-DEBUG - uses: actions/upload-artifact@v2 - with: - name: iBoot64Patcher-macOS-x86_64-DEBUG - path: ${{ github.workspace }}/iBoot64Patcher-macOS-x86_64-*-DEBUG.tar.xz - - - name: Upload arm64-RELEASE - uses: actions/upload-artifact@v2 - with: - name: iBoot64Patcher-macOS-arm64-RELEASE - path: ${{ github.workspace }}/iBoot64Patcher-macOS-arm64-*-RELEASE.tar.xz - - - name: Upload arm64-DEBUG - uses: actions/upload-artifact@v2 - with: - name: iBoot64Patcher-macOS-arm64-DEBUG - path: ${{ github.workspace }}/iBoot64Patcher-macOS-arm64-*-DEBUG.tar.xz - - Linux: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - submodules: 'true' - fetch-depth: 0 - - - name: Build - uses: addnab/docker-run-action@v3 - with: - image: debian:buster-slim - options: -v ${{ github.workspace }}/..:/tmp/Builder/repos/ - run: | - /tmp/Builder/repos/iBoot64Patcher/.github/workflows/linux-bootstrap.sh - /tmp/Builder/repos/iBoot64Patcher/.github/workflows/linux-build.sh - /tmp/Builder/repos/iBoot64Patcher/.github/workflows/linux-post.sh - - - name: Build x86_64-RELEASE - run: | - mkdir -p ${{ github.workspace }}/.github/workflows/ - docker cp $(docker ps -ql):/tmp/Builder/repos/iBoot64Patcher/.github/workflows/name1.txt ${{ github.workspace }}/.github/workflows/ - docker cp $(docker ps -ql):/tmp/Builder/repos/iBoot64Patcher/.github/workflows/iBoot64Patcher1.tar.xz ${{ github.workspace }}/.github/workflows/ - mv ${{ github.workspace }}/.github/workflows/iBoot64Patcher1.tar.xz ${{ github.workspace }}/.github/workflows/$(cat ${{ github.workspace }}/.github/workflows/name1.txt) - - - name: Build x86_64-DEBUG - run: | - mkdir -p ${{ github.workspace }}/.github/workflows/ - docker cp $(docker ps -ql):/tmp/Builder/repos/iBoot64Patcher/.github/workflows/name2.txt ${{ github.workspace }}/.github/workflows/ - docker cp $(docker ps -ql):/tmp/Builder/repos/iBoot64Patcher/.github/workflows/iBoot64Patcher2.tar.xz ${{ github.workspace }}/.github/workflows/ - mv ${{ github.workspace }}/.github/workflows/iBoot64Patcher2.tar.xz ${{ github.workspace }}/.github/workflows/$(cat ${{ github.workspace }}/.github/workflows/name2.txt) - - - name: Upload x86_64-RELEASE - uses: actions/upload-artifact@v2 - with: - name: iBoot64Patcher-Linux-x86_64-RELEASE - path: ${{ github.workspace }}/.github/workflows/iBoot64Patcher-Linux-x86_64*-RELEASE.tar.xz - - - name: Upload x86_64-DEBUG - uses: actions/upload-artifact@v2 - with: - name: iBoot64Patcher-Linux-x86_64-DEBUG - path: ${{ github.workspace }}/.github/workflows/iBoot64Patcher-Linux-x86_64*-DEBUG.tar.xz diff --git a/.github/workflows/linux-bootstrap.sh b/.github/workflows/linux-bootstrap.sh deleted file mode 100755 index d14c8ba..0000000 --- a/.github/workflows/linux-bootstrap.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -set -e -export TMPDIR=/tmp -export WORKFLOW_ROOT=${TMPDIR}/Builder/repos/iBoot64Patcher/.github/workflows -export DEP_ROOT=${TMPDIR}/Builder/repos/iBoot64Patcher/dep_root -export BASE=${TMPDIR}/Builder/repos/iBoot64Patcher/ - -#sed -i 's/deb\.debian\.org/ftp.de.debian.org/g' /etc/apt/sources.list -apt-get -qq update -apt-get -yqq dist-upgrade -apt-get install --no-install-recommends -yqq zstd curl gnupg2 lsb-release wget software-properties-common build-essential git autoconf automake libtool-bin pkg-config cmake zlib1g-dev libminizip-dev libpng-dev libreadline-dev libbz2-dev libudev-dev libudev1 -cp -RpP /usr/bin/ld / -rm -rf /usr/bin/ld /usr/lib/x86_64-linux-gnu/lib{usb-1.0,png*,readline}.so* -cd ${WORKFLOW_ROOT} -curl -sO https://apt.llvm.org/llvm.sh -chmod +x llvm.sh -./llvm.sh 13 all -ln -sf /usr/bin/ld.lld-13 /usr/bin/ld -curl -sO https://static.palera.in/cmake_deps/Linux_x86_64_RELEASE.tar.zst & -curl -sO https://static.palera.in/cmake_deps/Linux_x86_64_DEBUG.tar.zst & -curl -sLO https://github.com/Kitware/CMake/releases/download/v3.23.2/cmake-3.23.2-linux-x86_64.tar.gz & -wait -mkdir -p ${DEP_ROOT}/Linux_x86_64_{Release,Debug} -tar xf Linux_x86_64_RELEASE.tar.zst -C ${DEP_ROOT}/Linux_x86_64_Release & -tar xf Linux_x86_64_DEBUG.tar.zst -C ${DEP_ROOT}/Linux_x86_64_Debug & -tar xf cmake-3.23.2-linux-x86_64.tar.gz -cp -RpP cmake-3.23.2-linux-x86_64/* /usr/local/ || true -wait -rm -rf "*.zst" -cd ${WORKFLOW_ROOT} diff --git a/.github/workflows/linux-build.sh b/.github/workflows/linux-build.sh deleted file mode 100755 index ee39cb2..0000000 --- a/.github/workflows/linux-build.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -set -e -export TMPDIR=/tmp -export WORKFLOW_ROOT=${TMPDIR}/Builder/repos/iBoot64Patcher/.github/workflows -export DEP_ROOT=${TMPDIR}/Builder/repos/iBoot64Patcher/dep_root -export BASE=${TMPDIR}/Builder/repos/iBoot64Patcher/ - -cd ${BASE} -rm -rf ${DEP_ROOT}/{lib,include} || true -ln -sf ${DEP_ROOT}/Linux_x86_64_Release/{lib/,include/} ${DEP_ROOT}/ -cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=$(which make) -DCMAKE_C_COMPILER=$(which clang) -DCMAKE_MESSAGE_LOG_LEVEL="WARNING" \ - -DCMAKE_CXX_COMPILER=$(which clang++) -G "CodeBlocks - Unix Makefiles" -S ./ -B cmake-build-release-x86_64 -DARCH=x86_64 -DCMAKE_C_COMPILER=clang-13 \ - -DCMAKE_CXX_COMPILER=clang++-13 -DCMAKE_LINKER=ld.lld-13 -DNO_PKGCFG=1 -DCMAKE_C_FLAGS="-I${DEP_ROOT}/include" -DCMAKE_CXX_FLAGS="-I${DEP_ROOT}/include" \ - -DCMAKE_EXE_LINKER_FLAGS="-L${DEP_ROOT}/lib -linsn -lgeneral -loffsetfinder64" -make -j4 -l4 -C cmake-build-release-x86_64 - -cd ${BASE} -ln -sf ${DEP_ROOT}/Linux_x86_64_Debug/{lib/,include/} ${DEP_ROOT}/ -cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=$(which make) -DCMAKE_C_COMPILER=$(which clang) -DCMAKE_MESSAGE_LOG_LEVEL="WARNING" \ - -DCMAKE_CXX_COMPILER=$(which clang++) -G "CodeBlocks - Unix Makefiles" -S ./ -B cmake-build-debug-x86_64 -DARCH=x86_64 -DCMAKE_C_COMPILER=clang-13 \ - -DCMAKE_CXX_COMPILER=clang++-13 -DCMAKE_LINKER=ld.lld-13 -DNO_PKGCFG=1 -DCMAKE_C_FLAGS="-I${DEP_ROOT}/include" -DCMAKE_CXX_FLAGS="-I${DEP_ROOT}/include" \ - -DCMAKE_EXE_LINKER_FLAGS="-L${DEP_ROOT}/lib -linsn -lgeneral -loffsetfinder64" -make -j4 -l4 -C cmake-build-debug-x86_64 -llvm-strip-13 -s cmake-build-release-x86_64/iBoot64Patcher diff --git a/.github/workflows/linux-post.sh b/.github/workflows/linux-post.sh deleted file mode 100755 index 0b3b7a9..0000000 --- a/.github/workflows/linux-post.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -set -e -export TMPDIR=/tmp -export WORKFLOW_ROOT=${TMPDIR}/Builder/repos/iBoot64Patcher/.github/workflows -export DEP_ROOT=${TMPDIR}/Builder/repos/iBoot64Patcher/dep_root -export BASE=${TMPDIR}/Builder/repos/iBoot64Patcher/ - -cd ${BASE} -export iBoot64Patcher_VERSION=$(git rev-list --count HEAD | tr -d '\n') -cd ${WORKFLOW_ROOT} -echo "iBoot64Patcher-Linux-x86_64-Build_${iBoot64Patcher_VERSION}-RELEASE.tar.xz" > name1.txt -echo "iBoot64Patcher-Linux-x86_64-Build_${iBoot64Patcher_VERSION}-DEBUG.tar.xz" > name2.txt -cp -RpP "${BASE}/cmake-build-release-x86_64/iBoot64Patcher" iBoot64Patcher -tar cpPJvf "iBoot64Patcher1.tar.xz" iBoot64Patcher -cp -RpP "${BASE}/cmake-build-debug-x86_64/iBoot64Patcher" iBoot64Patcher -tar cpPJvf "iBoot64Patcher2.tar.xz" iBoot64Patcher diff --git a/.github/workflows/mac-bootstrap.sh b/.github/workflows/mac-bootstrap.sh deleted file mode 100755 index 1f4ae7c..0000000 --- a/.github/workflows/mac-bootstrap.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env zsh - -set -e -export WORKFLOW_ROOT=/Users/runner/work/iBoot64Patcher/iBoot64Patcher/.github/workflows -export DEP_ROOT=/Users/runner/work/iBoot64Patcher/iBoot64Patcher/dep_root -export BASE=/Users/runner/work/iBoot64Patcher/iBoot64Patcher/ - -cd ${WORKFLOW_ROOT} -curl -sO https://cdn.cryptiiiic.com/bootstrap/bootstrap_x86_64.tar.zst -# curl -sO https://cdn.cryptiiiic.com/bootstrap/Builder_macOS.tar.zst & -curl -sO https://static.palera.in/cmake_deps/macOS_x86_64_RELEASE.tar.zst -curl -sO https://static.palera.in/cmake_deps/macOS_x86_64_DEBUG.tar.zst -curl -sO https://static.palera.in/cmake_deps/macOS_arm64_RELEASE.tar.zst -curl -sO https://static.palera.in/cmake_deps/macOS_arm64_DEBUG.tar.zst -sudo gtar xf ${WORKFLOW_ROOT}/bootstrap_x86_64.tar.zst -C / --warning=none || true || true -echo "${PROCURSUS}/bin" | sudo tee /etc/paths1 -echo "${PROCURSUS}/libexec/gnubin" | sudo tee /etc/paths1 -cat /etc/paths | sudo tee -a /etc/paths1 -sudo mv /etc/paths{1,} -mkdir -p ${DEP_ROOT}/macOS_x86_64_Release ${DEP_ROOT}/macOS_x86_64_Debug ${DEP_ROOT}/macOS_arm64_Release ${DEP_ROOT}/macOS_arm64_Debug -gtar xf macOS_x86_64_RELEASE.tar.zst -C ${DEP_ROOT}/macOS_x86_64_Release -gtar xf macOS_x86_64_DEBUG.tar.zst -C ${DEP_ROOT}/macOS_x86_64_Debug -gtar xf macOS_arm64_RELEASE.tar.zst -C ${DEP_ROOT}/macOS_arm64_Release -gtar xf macOS_arm64_DEBUG.tar.zst -C ${DEP_ROOT}/macOS_arm64_Debug -# gtar xf ${BASE}/Builder_macOS.tar.zst & -sudo ${PROCURSUS}/bin/apt-get update -qq -sudo ${PROCURSUS}/bin/apt-get install llvm-utils -yqq -sudo mv /usr/local/bin{,1} diff --git a/.github/workflows/mac-build.sh b/.github/workflows/mac-build.sh deleted file mode 100755 index 8771fb2..0000000 --- a/.github/workflows/mac-build.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env zsh - -set -e -export WORKFLOW_ROOT=/Users/runner/work/iBoot64Patcher/iBoot64Patcher/.github/workflows -export DEP_ROOT=/Users/runner/work/iBoot64Patcher/iBoot64Patcher/dep_root -export BASE=/Users/runner/work/iBoot64Patcher/iBoot64Patcher/ -export CC="$(xcrun --find clang)" -export CXX="$(xcrun --find clang++)" - -cd /Users/runner/work/iBoot64Patcher/iBoot64Patcher/ -rm -rf ${DEP_ROOT}/{lib,include} -ln -sf ${DEP_ROOT}/macOS_x86_64_Release/{lib/,include/} ${DEP_ROOT}/ -cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM="$(which make)" -DCMAKE_C_COMPILER="${CC}" -DCMAKE_CXX_COMPILER="${CXX}" -DCMAKE_MESSAGE_LOG_LEVEL="WARNING" -G "CodeBlocks - Unix Makefiles" -S ./ -B cmake-build-release-x86_64 -DARCH=x86_64 -DNO_PKGCFG=1 -make -j4 -l4 -C cmake-build-release-x86_64 - -ln -sf ${DEP_ROOT}/macOS_x86_64_Debug/{lib/,include/} ${DEP_ROOT}/ -cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM="$(which make)" -DCMAKE_C_COMPILER="${CC}" -DCMAKE_CXX_COMPILER="${CXX}" -DCMAKE_MESSAGE_LOG_LEVEL="WARNING" -G "CodeBlocks - Unix Makefiles" -S ./ -B cmake-build-debug-x86_64 -DARCH=x86_64 -DNO_PKGCFG=1 -make -j4 -l4 -C cmake-build-debug-x86_64 - -ln -sf ${DEP_ROOT}/macOS_arm64_Release/{lib/,include/} ${DEP_ROOT}/ -cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM="$(which make)" -DCMAKE_C_COMPILER="${CC}" -DCMAKE_CXX_COMPILER="${CXX}" -DCMAKE_MESSAGE_LOG_LEVEL="WARNING" -G "CodeBlocks - Unix Makefiles" -S ./ -B cmake-build-release-arm64 -DARCH=arm64 -DNO_PKGCFG=1 -make -j4 -l4 -C cmake-build-release-arm64 - -ln -sf ${DEP_ROOT}/macOS_arm64_Debug/{lib/,include/} ${DEP_ROOT}/ -cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM="$(which make)" -DCMAKE_C_COMPILER="${CC}" -DCMAKE_CXX_COMPILER="${CXX}" -DCMAKE_MESSAGE_LOG_LEVEL="WARNING" -G "CodeBlocks - Unix Makefiles" -S ./ -B cmake-build-debug-arm64 -DARCH=arm64 -DNO_PKGCFG=1 -make -j4 -l4 -C cmake-build-debug-arm64 -llvm-strip -s cmake-build-release-x86_64/iBoot64Patcher -llvm-strip -s cmake-build-release-arm64/iBoot64Patcher diff --git a/.github/workflows/mac-post.sh b/.github/workflows/mac-post.sh deleted file mode 100755 index f8a941e..0000000 --- a/.github/workflows/mac-post.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env zsh - -set -e -export WORKFLOW_ROOT=/Users/runner/work/iBoot64Patcher/iBoot64Patcher/.github/workflows -export DEP_ROOT=/Users/runner/work/iBoot64Patcher/iBoot64Patcher/dep_root -export BASE=/Users/runner/work/iBoot64Patcher/iBoot64Patcher/ - -cd ${BASE} -export iBoot64Patcher_VERSION=$(git rev-list --count HEAD | tr -d '\n') -export iBoot64Patcher_VERSION_SHA=$(git rev-parse HEAD | tr -d '\n') -echo -n $iBoot64Patcher_VERSION_SHA > latest_build_sha.txt -echo -n $iBoot64Patcher_VERSION > latest_build_num.txt -tar cpPJf "iBoot64Patcher-macOS-x86_64-Build_${iBoot64Patcher_VERSION}-RELEASE.tar.xz" -C cmake-build-release-x86_64 iBoot64Patcher -tar cpPJf "iBoot64Patcher-macOS-x86_64-Build_${iBoot64Patcher_VERSION}-DEBUG.tar.xz" -C cmake-build-debug-x86_64 iBoot64Patcher -tar cpPJf "iBoot64Patcher-macOS-arm64-Build_${iBoot64Patcher_VERSION}-RELEASE.tar.xz" -C cmake-build-release-arm64 iBoot64Patcher -tar cpPJf "iBoot64Patcher-macOS-arm64-Build_${iBoot64Patcher_VERSION}-DEBUG.tar.xz" -C cmake-build-debug-arm64 iBoot64Patcher diff --git a/.gitignore b/.gitignore deleted file mode 100644 index eac9478..0000000 --- a/.gitignore +++ /dev/null @@ -1,83 +0,0 @@ -!dep_root/include -!dep_root/include/.keep -!dep_root/lib -!dep_root/lib/.keep -*.DS_Store -*.[oa] -*.a -*.diff -*.in -*.la -*.lo -*.o -*.patch -*.pc -*.po -*.so -*.swp -*.xcworkspace -*/.deps -*/.deps/* -*/.libs -*/all.h* -*/futurerestore* -*/tsschecker* -*Makefile -*Makefile.in -*~ -.DS_Store -.build_complete -.deps -.idea -.libs -.vscode -Build -CMakeCache.txt -CMakeFiles -Index -Makefile -Makefile.in -aclocal.m4 -autom4te.cache -autom4te.cache/ -autom4te.cache/* -build -cmake-build-debug -cmake-build-debug* -cmake-build-release -cmake-build-release* -cmake_install.cmake -compile -config.* -config.guess -config.h -config.h.in -config.log -config.status -config.sub -configure -configure~ -dep_root/* -dep_root/include/* -dep_root/lib/* -depcomp -install-sh -liboffsetfinder64.pc -libtool -ltmain.sh -m4 -m4/ -m4/* -main -missing -mkinstalldirs -py-compile -src/.libs -src/iBoot64Patcher -src/idevicerestore -stamp-h1 -stamp-h2 -swig/* -test-driver -xcuserdata -*.zst diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index bbe70cc..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,75 +0,0 @@ -cmake_minimum_required(VERSION 3.22) -set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG") -set(CMAKE_CXX_FLAGS_RELEASE "-Os -DNDEBUG") -set(CMAKE_C_FLAGS_DEBUG "-g -O0 -DDEBUG") -set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -DDEBUG") -set(CMAKE_C_STANDARD 17) -set(CMAKE_CXX_STANDARD 20) -set(ignoreMe "${NO_PKGCFG}") -project(iBoot64Patcher) -if("${CMAKE_HOST_SYSTEM_NAME}" MATCHES "Darwin") - if(NOT DEFINED NO_XCODE AND NOT DEFINED ENV{NO_XCODE}) - execute_process(COMMAND xcrun --find clang WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE CC OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND xcrun --find clang++ WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE CXX OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND xcrun --find ar WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE AR OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND xcrun --find ld WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE LD OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND xcrun --show-sdk-path WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE SYSROOT OUTPUT_STRIP_TRAILING_WHITESPACE) - set(CMAKE_C_COMPILER "${CC}") - set(CMAKE_CXX_COMPILER "${CXX}") - endif() - if(NOT DEFINED ARCH) - set(ARCH "$ENV{ARCH}") - if(ARCH STREQUAL "") - set(ARCH "${CMAKE_SYSTEM_PROCESSOR}") - endif() - endif() - if(NOT DEFINED MINVER OR NOT DEFINED "$ENV{MINVER}" AND DEFINED NO_PKGCFG OR "$ENV{NO_PKGCFG}" MATCHES "1") - if("${ARCH}" STREQUAL "x86_64" OR "$ENV{ARCH}" STREQUAL "x86_64") - set(MINVER -mmacosx-version-min=10.12) - set(CMAKE_OSX_DEPLOYMENT_TARGET 10.12) - else() - set(MINVER -mmacosx-version-min=11.0) - set(CMAKE_OSX_DEPLOYMENT_TARGET 11.0) - endif() - endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch ${ARCH} -isysroot ${SYSROOT} ${MINVER} -fembed-bitcode=off -flto=thin -pthread -mrelax-all -std=gnu++20") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch ${ARCH} -isysroot ${SYSROOT} ${MINVER} -fembed-bitcode=off -flto=thin -pthread -mrelax-all -std=gnu17") -elseif("${CMAKE_HOST_SYSTEM_NAME}" MATCHES "Linux") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--allow-multiple-definition -pthread") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--allow-multiple-definition -pthread") -endif() -add_executable(iBoot64Patcher - src/main.cpp) -target_include_directories(iBoot64Patcher PRIVATE - "${CMAKE_SOURCE_DIR}/dep_root/include" - src) -target_link_directories(iBoot64Patcher PRIVATE - "${CMAKE_SOURCE_DIR}/dep_root/lib") -if(NOT DEFINED NO_PKGCFG AND NOT "$ENV{NO_PKGCFG}" MATCHES "1") - find_package(PkgConfig REQUIRED) - pkg_check_modules(DEPS REQUIRED - libgeneral - libinsn - liboffsetfinder64) - target_include_directories(iBoot64Patcher PRIVATE "${DEPS_INCLUDE_DIRS}") - target_link_directories(iBoot64Patcher PRIVATE "${DEPS_LIBRARY_DIRS}") - target_link_libraries(futurerestore PRIVATE "${DEPS_LIBRARIES}" - "-lgeneral" - insn - offsetfinder64) -else() - target_include_directories(iBoot64Patcher PRIVATE "${CMAKE_SOURCE_DIR}/dep_root/include") - target_link_directories(iBoot64Patcher PRIVATE "${CMAKE_SOURCE_DIR}/dep_root/lib") - target_link_libraries(iBoot64Patcher PRIVATE - "-lgeneral" - insn - offsetfinder64) -endif() - -execute_process(COMMAND git rev-list --count HEAD WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE VERSION_COMMIT_COUNT ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) -execute_process(COMMAND git rev-parse HEAD WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE VERSION_COMMIT_SHA ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) -add_definitions( - -DVERSION_COMMIT_COUNT="${VERSION_COMMIT_COUNT}" - -DVERSION_COMMIT_SHA="${VERSION_COMMIT_SHA}") -install(TARGETS iBoot64Patcher - DESTINATION ${CMAKE_INSTALL_PREFIX}) diff --git a/README.md b/README.md deleted file mode 100644 index 29074aa..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# iBoot64Patcher -[![CI Building](https://img.shields.io/github/workflow/status/Cryptiiiic/iBoot64Patcher/iBoot64Patcher/main?style=for-the-badge)](https://github.com/Cryptiiiic/iBoot64Patcher/actions) -## Fork of [tihmstar/iBoot64Patcher](https://github.com/tihmstar/iBoot64Patcher) diff --git a/build.sh b/build.sh index eebac32..36f2ba2 100755 --- a/build.sh +++ b/build.sh @@ -1,30 +1,11 @@ #!/usr/bin/env bash -which cmake >/dev/null - if [[ "$?" -gt 0 ]]; then echo "[!] cmake not installed or not found, refusing to build!"; exit 1; fi -which make >/dev/null -if [[ "$?" -gt 0 ]]; then echo "[!] make not installed or not found, refusing to build!"; exit 1; fi -export CC="$(which clang)" -export CXX="$(which clang++)" -which xcrun >/dev/null - if [[ "$?" -lt 1 ]]; then export CC="$(xcrun --find clang)"; export CXX="$(xcrun --find clang++)"; fi -echo "[*] Building iBoot64Patcher" -export FR_INSTALL_DIR="/usr/local/bin" -if [[ -z "$NO_CLEAN" ]]; then rm -rf cmake-build-release cmake-build-debug; fi -if [[ "$RELEASE" == "1" ]] -then - if [[ ! "$NO_CLEAN" == "1" ]]; then cmake -DCMAKE_INSTALL_PREFIX="${FR_INSTALL_DIR}" -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM="$(which make)" -DCMAKE_C_COMPILER="${CC}" -DCMAKE_CXX_COMPILER="${CXX}" -DCMAKE_MESSAGE_LOG_LEVEL="WARNING" -G "CodeBlocks - Unix Makefiles" -S ./ -B cmake-build-release $@; fi - make -s -C cmake-build-release clean - make -s -C cmake-build-release - if [[ "$?" -gt 0 ]]; then echo "[!] Failed to build iBoot64Patcher!"; exit 1; fi - which llvm-strip >/dev/null - if [[ "$?" -lt 1 ]]; then llvm-strip -s cmake-build-release/src/iBoot64Patcher; else echo "[!] llvm-strip not installed or not found, not stripping release binary."; fi - echo "[*] Run make -C cmake-build-release install, to install iBoot64Patcher or obtain the binary at cmake-build-release/src/iBoot64Patcher" - echo "[*] Successfully built iBoot64Patcher." -else - if [[ ! "$NO_CLEAN" == "1" ]]; then cmake -DCMAKE_INSTALL_PREFIX="${FR_INSTALL_DIR}" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM="$(which make)" -DCMAKE_C_COMPILER="${CC}" -DCMAKE_CXX_COMPILER="${CXX}" -G "CodeBlocks - Unix Makefiles" -S ./ -B cmake-build-debug $@ ; fi - make -s -C cmake-build-debug clean - make -s -C cmake-build-debug - if [[ "$?" -gt 0 ]]; then echo "[!] Failed to build iBoot64Patcher!"; exit 1; fi - echo "[*] Run make -C cmake-build-debug install, to install iBoot64Patcher or obtain the binary at cmake-build-debug/src/iBoot64Patcher" - echo "[*] Successfully built iBoot64Patcher." -fi + +set -e + +mkdir -p /usr/local/include + +sudo cp -R include/libinsn /usr/local/include +sudo cp -R include/libgeneral /usr/local/include +sudo cp -R include/liboffsetfinder64 /usr/local/include + +clang++ -std=c++11 libinsn.a libgeneral.a liboffsetfinder64.a main.cpp -o iBoot64Patcher diff --git a/dep_root/.keep b/dep_root/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/dep_root/include/.keep b/dep_root/include/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/dep_root/lib/.keep b/dep_root/lib/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/include/libgeneral/DeliveryEvent.hpp b/include/libgeneral/DeliveryEvent.hpp new file mode 100644 index 0000000..b21044a --- /dev/null +++ b/include/libgeneral/DeliveryEvent.hpp @@ -0,0 +1,137 @@ +// +// DeliveryEvent.hpp +// libgeneral +// +// Created by tihmstar on 02.11.20. +// + +#ifndef DeliveryEvent_hpp +#define DeliveryEvent_hpp + +#include +#include +#include + +namespace tihmstar { + template + class DeliveryEvent{ + std::atomic_bool _isDying; + std::atomic_bool _isFinished; + std::atomic _members; + Event _membersUpdateEvent; + + Event _dataWait; + std::mutex _dataLock; + std::queue _dataQueue; + + public: + DeliveryEvent(); + ~DeliveryEvent(); + + T wait(); + void post(T data); + /* + Signalizes that no more data will be appended to this queue. + After the last element was dequed, kill() will be called. + further calls to post() are not allowed after this call. + */ + void finish(); + + /* + Releases waiter and hints destruction of the object in near future + Further calls to wait() or post() are not allowed after calling kill() + */ + void kill(); + }; + +#pragma mark implementation + + template + DeliveryEvent::DeliveryEvent() + : _isDying(false),_isFinished(false),_members(0) + { + // + } + + template + DeliveryEvent::~DeliveryEvent(){ + _isDying = true; + while ((uint64_t)_members > 0) { + _dataWait.notifyAll(); //release waiter + _membersUpdateEvent.wait(); + } + } + + template + T DeliveryEvent::wait(){ + assure(!_isDying); + ++_members; + cleanup([&]{ + --_members; + _membersUpdateEvent.notifyAll(); + }); + + std::unique_lock ul(_dataLock); + while (!_dataQueue.size()) { + retassure(!_isDying && !_isFinished, "object died while waiting on it"); + ul.unlock(); + _dataWait.wait(); + + ul.lock(); + } + T mydata = _dataQueue.front(); _dataQueue.pop(); + if (_isFinished && !_dataQueue.size()) { + _isDying = true; + } + _dataWait.notifyAll(); + return mydata; + } + + template + void DeliveryEvent::post(T data){ + assure(!_isDying && !_isFinished); + ++_members; + cleanup([&]{ + --_members; + _membersUpdateEvent.notifyAll(); + }); + + _dataLock.lock(); + _dataQueue.push(data); + _dataWait.notifyAll(); + _dataLock.unlock(); + } + + template + void DeliveryEvent::finish(){ + assure(!_isDying); + ++_members; + cleanup([&]{ + --_members; + _membersUpdateEvent.notifyAll(); + }); + _dataLock.lock(); + _isFinished = true; + if (!_dataQueue.size()) _isDying = true; + _dataWait.notifyAll(); + _dataLock.unlock(); + } + + template + void DeliveryEvent::kill(){ + assure(!_isDying); + ++_members; + cleanup([&]{ + --_members; + _membersUpdateEvent.notifyAll(); + }); + _isDying = true; + _dataLock.lock(); + _dataWait.notifyAll(); + _dataLock.unlock(); + } +}; + + + +#endif /* DeliveryEvent_hpp */ diff --git a/include/libgeneral/Event.hpp b/include/libgeneral/Event.hpp new file mode 100644 index 0000000..973d270 --- /dev/null +++ b/include/libgeneral/Event.hpp @@ -0,0 +1,37 @@ +// +// Event.hpp +// libgeneral +// +// Created by tihmstar on 15.08.20. +// Copyright © 2020 tihmstar. All rights reserved. +// + +#ifndef Event_hpp +#define Event_hpp + +#include +#include +#include +#include +#include + +namespace tihmstar { + class Event{ + std::mutex _m; + std::condition_variable _cv; + std::condition_variable _cm; + std::atomic _members; + uint64_t _curSendEvent; + uint64_t _curWaitEvent; + + public: + Event(); + ~Event(); + + void wait(); + void notifyAll(); + uint64_t members() const; + }; +}; + +#endif /* Event_hpp */ diff --git a/include/libgeneral/Manager.hpp b/include/libgeneral/Manager.hpp new file mode 100644 index 0000000..5858ca7 --- /dev/null +++ b/include/libgeneral/Manager.hpp @@ -0,0 +1,49 @@ +// +// Manager.hpp +// libgeneral +// +// Created by tihmstar on 17.11.20. +// Copyright © 2020 tihmstar. All rights reserved. +// + +#ifndef Manager_hpp +#define Manager_hpp + +#include + +namespace tihmstar { + enum loop_state{ + LOOP_UNINITIALISED = 0, + LOOP_CONSTRUCTING, + LOOP_RUNNING, + LOOP_STOPPING, + LOOP_STOPPED + }; + /* + Abstract class + */ + class Manager{ + std::thread *_loopThread; + protected: + std::atomic _loopState; + + virtual void loopEvent(); + + public: + Manager(const Manager&) = delete; //delete copy constructor + Manager(Manager &&o) = delete; //move constructor + + Manager(); //default constructor + virtual ~Manager(); + + void startLoop(); + void stopLoop() noexcept; + + virtual void beforeLoop(); //execute before Loop started + virtual void afterLoop() noexcept; //execute after Loop stopped (e.g. because it died) + virtual void stopAction() noexcept; //execute when stopping Loop (before waiting for the thread to finish) + }; +}; + + +#endif /* Manager_hpp */ diff --git a/include/libgeneral/exception.hpp b/include/libgeneral/exception.hpp new file mode 100644 index 0000000..4ba7de9 --- /dev/null +++ b/include/libgeneral/exception.hpp @@ -0,0 +1,49 @@ +// +// exception.hpp +// libgeneral +// +// Created by tihmstar on 09.03.18. +// Copyright © 2018 tihmstar. All rights reserved. +// + +#ifndef exception_hpp +#define exception_hpp + +#include +#include + +namespace tihmstar { + class exception : public std::exception{ + const char *_commit_count_str; + const char *_commit_sha_str; + int _line; + std::string _filename; + char *_err; + + public: + exception(const char *commit_count_str, const char *commit_sha_str, int line, const char *filename, const char *err ...); + exception(const char *commit_count_str, const char *commit_sha_str, int line, const char *filename, const char *err, va_list ap); + + exception(const exception &e); //copy constructor + + //custom error can be used + virtual const char *what() const noexcept override; + + /* + -first lowest two bytes of code is sourcecode line + -next two bytes is strlen of filename in which error happened + */ + int code() const; + + virtual void dump() const; + virtual std::string dumpStr() const; + + //Information about build + virtual std::string build_commit_count() const; + virtual std::string build_commit_sha() const; + + ~exception(); + }; +}; + +#endif /* exception_hpp */ diff --git a/include/libgeneral/lck_container.hpp b/include/libgeneral/lck_container.hpp new file mode 100644 index 0000000..5006658 --- /dev/null +++ b/include/libgeneral/lck_container.hpp @@ -0,0 +1,113 @@ +// +// lck_container.hpp +// libgeneral +// +// Created by tihmstar on 17.11.20. +// Copyright © 2020 tihmstar. All rights reserved. +// + +#ifndef lck_container_h +#define lck_container_h + +#include +#include +#include +#include +#include +#include + +namespace tihmstar { + template + class lck_contrainer{ + static constexpr const uint32_t maxMembers = 0x10000; + std::atomic _members; + Event _enterEvent; + Event _leaveEvent; + Event _notifyEvent; + + public: + Container _elems; + + inline lck_contrainer(); + inline ~lck_contrainer(); + + //readonly access + inline void addMember(); + inline void delMember(); + + //write/modify access + inline void lockMember(); + inline void unlockMember(); + + //block until someone removed members + inline void notifyBlock(); + }; + +#pragma mark implementation + + template + lck_contrainer::lck_contrainer() + : _members(0) + { + // + } + + template + lck_contrainer::~lck_contrainer(){ + while (_members) { + _enterEvent.wait(); + } + } + + template + void lck_contrainer::addMember(){ + while (true){ + if (_members.fetch_add(1) >= lck_contrainer::maxMembers){ + _members.fetch_sub(1); + while (_members>=lck_contrainer::maxMembers) + _enterEvent.wait(); + }else{ + break; + } + } + } + + template + void lck_contrainer::delMember(){ + _members.fetch_sub(1); + _enterEvent.notifyAll(); + _leaveEvent.notifyAll(); + _notifyEvent.notifyAll(); + } + + template + void lck_contrainer::lockMember(){ + while (true){ + if (_members.fetch_add(lck_contrainer::maxMembers) >= lck_contrainer::maxMembers){ + _members.fetch_sub(lck_contrainer::maxMembers); + while (_members>=lck_contrainer::maxMembers) + _enterEvent.wait(); + }else{ + while (_members > lck_contrainer::maxMembers) + _leaveEvent.wait(); //wait until all members are gone + break; + } + } + } + + template + void lck_contrainer::unlockMember(){ + _members.fetch_sub(lck_contrainer::maxMembers); + _enterEvent.notifyAll(); + _leaveEvent.notifyAll(); + _notifyEvent.notifyAll(); + } + + template + void lck_contrainer::notifyBlock(){ + _notifyEvent.wait(); + } +}; + + +#endif /* lck_container_h */ diff --git a/include/libgeneral/macros.h b/include/libgeneral/macros.h new file mode 100644 index 0000000..b40cbf3 --- /dev/null +++ b/include/libgeneral/macros.h @@ -0,0 +1,176 @@ +// +// macros.h +// libgeneral +// +// Created by tihmstar on 03.05.19. +// Copyright © 2019 tihmstar. All rights reserved. +// + +#ifndef macros_h +#define macros_h + +#include + +#ifdef HAVE_CONFIG_H +# include +#endif //HAVE_CONFIG_H + +#ifndef VERSION_COMMIT_COUNT +# define VERSION_COMMIT_COUNT "Debug" +#endif +#ifndef VERSION_COMMIT_SHA +# define VERSION_COMMIT_SHA "Build: " __DATE__ " " __TIME__ +#endif + +#ifndef PACKAGE_NAME +#define PACKAGE_NAME "PACKAGE_NAME_not_set" +#endif //PACKAGE_NAME + +#ifndef VERSION_MAJOR +#define VERSION_MAJOR "0" +#endif //VERSION_MAJOR + +#ifdef DEBUG +#define BUILD_TYPE "DEBUG" +#else +#define BUILD_TYPE "RELEASE" +#endif + +#define VERSION_STRING PACKAGE_NAME " version: " VERSION_MAJOR "." VERSION_COMMIT_COUNT "-" VERSION_COMMIT_SHA "-" BUILD_TYPE + + +// ---- functions ---- + +// -- logging -- +#ifndef CUSTOM_LOGGING +# define info(a ...) ({printf(a),printf("\n");}) +# define warning(a ...) ({printf("[WARNING] "), printf(a),printf("\n");}) +# define error(a ...) ({printf("[Error] "),printf(a),printf("\n");}) +# ifdef DEBUG +# define debug(a ...) ({printf("[DEBUG] "),printf(a),printf("\n");}) +# else +# define debug(a ...) +# endif +#else //CUSTOM_LOGGING +# include CUSTOM_LOGGING +#endif //CUSTOM_LOGGING + +#define safeFree(ptr) ({if (ptr) {free(ptr); ptr=NULL;}}) +#define safeFreeCustom(ptr,func) ({if (ptr) {func(ptr); ptr=NULL;}}) +#define safeFreeConst(ptr) ({if(ptr){void *fbuf = (void*)ptr;ptr = NULL; free(fbuf);}}) +#define safeClose(fd) ({if (fd != -1) {close(fd); fd=-1;}}) + + +#ifdef __cplusplus +# define safeDelete(ptr) ({if (ptr) {delete ptr; ptr=NULL;}}) +#endif //__cplusplus + +#ifdef __cplusplus +# include +# ifndef NO_EXCEPT_ASSURE +# define EXCEPT_ASSURE +# endif +#endif //__cplusplus + + +#ifdef STRIP_ASSURES +# define LIBGENERAL__FILE__ "" +# define LIBGENERAL_ERRSTR(errstr ...) "" +#else //STRIP_ASSURES +# define LIBGENERAL__FILE__ __FILE__ +# define LIBGENERAL_ERRSTR(errstr ...) errstr +#endif //STRIP_ASSURES + +// -- assure -- +#define cassure(a) do{ if ((a) == 0){err=__LINE__; goto error;} }while(0) +#define cretassure(cond, errstr ...) do{ if ((cond) == 0){err=__LINE__;error(LIBGENERAL_ERRSTR(errstr)); goto error;} }while(0) +#define creterror(errstr ...) do{error(LIBGENERAL_ERRSTR(errstr));err=__LINE__; goto error; }while(0) + +#ifdef EXCEPT_ASSURE +# include "exception.hpp" +//assure cpp +# define assure(cond) do{ if ((cond) == 0) throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, LIBGENERAL__FILE__, LIBGENERAL_ERRSTR("assure failed")); } while(0) +# define retassure(cond, errstr ...) do{ if ((cond) == 0) throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__,LIBGENERAL__FILE__,LIBGENERAL_ERRSTR(errstr)); } while(0) +# define customassure(custom_except, cond) do{ if ((cond) == 0) throw tihmstar::custom_except(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, LIBGENERAL__FILE__, LIBGENERAL_ERRSTR("assure failed")); } while(0) +# define retcustomassure(custom_except, cond, errstr ...) do{ if ((cond) == 0) throw tihmstar::custom_except(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, LIBGENERAL__FILE__, LIBGENERAL_ERRSTR(errstr)); } while(0) +# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, LIBGENERAL__FILE__, LIBGENERAL_ERRSTR(errstr)); } while(0) +# define retcustomerror(custom_except,errstr ...) do{ throw tihmstar::custom_except(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, LIBGENERAL__FILE__, LIBGENERAL_ERRSTR(errstr)); } while(0) +# define doassure(cond,code) do {if (!(cond)){(code);assure(cond);}} while(0) +//mach assures +# define assureMach(kernRet) do {kern_return_t __kret = kernRet; if (__kret) throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, LIBGENERAL__FILE__, LIBGENERAL_ERRSTR("assure failed"));} while(0) +# define assureMachclean(kernRet) do {kern_return_t __kret = kernRet; if (__kret){clean();assureMach(__kret);}} while(0) +# define assureCatchClean(code) do {try { code; } catch (EXPECTIONNAME &e) { clean(); throw; }} while (0) +# define assureNoDoublethrow(code) \ + do{try {code;} catch (EXPECTIONNAME &e) {if (isInException) {error(LIBGENERAL_ERRSTR("Double exception! Error in line=%d",__LINE__));}else{throw;}}}while (0) + +//DEBUG assures +#ifdef DEBUG +# define assure_dbg(cond) assure(cond) +# define retassure_dbg(cond, errstr ...) retassure(cond, errstr) +# define customassure_dbg(custom_except, cond) customassure(custom_except, cond) +# define retcustomassure_dbg(custom_except, cond, errstr ...) retcustomassure(custom_except, cond, errstr) +# define reterror_dbg(errstr ...) reterror(errstr) +# define retcustomerror_dbg(custom_except,errstr ...) retcustomerror(custom_except,errstr) +#else +# define assure_dbg(cond) ((void)(cond)) +# define retassure_dbg(cond, errstr ...) ((void)(cond)) +# define customassure_dbg(custom_except, cond) ((void)(cond)) +# define retcustomassure_dbg(custom_except, cond, errstr ...) ((void)(cond)) +# define reterror_dbg(errstr ...) +# define retcustomerror_dbg(custom_except,errstr ...) +#endif + + +// //more cpp assure +# ifndef EXPECTIONNAME +# define EXPECTIONNAME exception +# endif + +class guard{ + std::function _f; +public: + guard(std::function cleanup) : _f(cleanup) {} + guard(const guard&) = delete; //delete copy constructor + guard(guard &&o) = delete; //move constructor + + ~guard(){_f();} +}; +# define cleanup(f) guard _cleanup(f); +#endif //EXCEPT_ASSURE + +#ifdef XCODE +# define MAINFUNCTION \ + int main(int argc, const char * argv[]) { \ + int main_r(int argc, const char * argv[]); \ + return main_r(argc, argv); \ + } +# define CATCHFUNC(f) f() +#else +# define MAINFUNCTION \ + int main(int argc, const char * argv[]) { \ + int main_r(int argc, const char * argv[]); \ + try { \ + return main_r(argc, argv); \ + } catch (tihmstar::exception &e) { \ + error("%s: failed with exception:\n%s",PACKAGE_NAME,e.dumpStr().c_str()); \ + return e.code(); \ + } catch (std::exception &e) { \ + error("%s: failed with std::exception (%s)",PACKAGE_NAME,e.what()); \ + exit(-1); \ + } \ + } +# define CATCHFUNC(f) \ + do{ \ + try { \ + f; \ + } catch (tihmstar::exception &e) { \ + error("%s: failed with exception:\n%s",PACKAGE_NAME,e.dumpStr().c_str()); \ + exit(e.code()); \ + } catch (std::exception &e) { \ + error("%s: failed with std::exception (%s)",PACKAGE_NAME,e.what()); \ + exit(-1); \ + } \ + }while (0) +#endif + +#endif /* macros_h */ diff --git a/include/libinsn/INSNexception.hpp b/include/libinsn/INSNexception.hpp new file mode 100644 index 0000000..9be74a5 --- /dev/null +++ b/include/libinsn/INSNexception.hpp @@ -0,0 +1,29 @@ +// +// INSNexception.h +// libinsn +// +// Created by tihmstar on 17.03.20. +// Copyright © 2020 tihmstar. All rights reserved. +// + +#ifndef INSNexception_h +#define INSNexception_h + +#include +#include + + +namespace tihmstar { + class INSNexception : public tihmstar::exception{ + using exception::exception; + }; + +//custom exceptions for makeing it easy to catch + class out_of_range : public INSNexception{ + using INSNexception::INSNexception; + }; + + +}; + +#endif /* INSNexception_h */ diff --git a/include/libinsn/insn.hpp b/include/libinsn/insn.hpp new file mode 100644 index 0000000..eaf86ff --- /dev/null +++ b/include/libinsn/insn.hpp @@ -0,0 +1,182 @@ +// +// insn.hpp +// liboffsetfinder64 +// +// Created by tihmstar on 09.03.18. +// Copyright © 2018 tihmstar. All rights reserved. +// + +#ifndef insn_hpp +#define insn_hpp + +#include +#include + +namespace tihmstar{ + namespace libinsn{ + typedef uint64_t loc_t; + typedef uint64_t offset_t; + + class insn{ + public: //type + enum type{ + unknown = 0, + adrp, + adr, + bl, + cbz, + ret, + tbnz, + add, + sub, + br, + blr, + ldr, + ldrh, + cbnz, + movk, + orr, + tbz, + ldxr, + ldrb, + str, + strb, + stp, + ldp, + movz, + bcond, + b, + nop, + and_, + csel, + mov, + mrs, + subs, + cmp = subs, + ccmp, + madd, + pacib, + pacizb, + pacibsp, + msr + }; + enum subtype{ + st_general, + st_register, + st_register_extended, + st_immediate, + st_literal + }; + enum supertype{ + sut_general, + sut_branch_imm, + sut_memory //load or store + }; + enum classtype{ + cl_general, + cl_preindex, + cl_postindex, + cl_offset + }; + enum cond{ + EQ = 0b0000, + NE = 0b0001, + CS = 0b0010, + CC = 0b0011, + MI = 0b0100, + PL = 0b0101, + VS = 0b0110, + VC = 0b0111, + HI = 0b1000, + LS = 0b1001, + GE = 0b1010, + LT = 0b1011, + GT = 0b1100, + LE = 0b1101, + AL = 0b1110 + }; + enum systemreg : uint64_t{ + tpidr_el1 = 0x4684, + sctlr_el1 = 0x4080, + tcr_el1 = 0x4102, + ttbr0_el1 = 0x4100 + }; + enum pactype{ + pac_none = 0, + pac_AA, //BRAA / BLRAA + pac_AAZ, //BRAAZ / BLRAAZ + pac_AB, //BRAB / BLRAB + pac_ABZ //BRABZ / BLRAB/ + }; + + + private: + uint32_t _opcode; + uint64_t _pc; + type _type; + + public: + insn(uint32_t opcode, uint64_t pc); + + public: + uint32_t opcode(); + uint64_t pc(); + + type type(); + subtype subtype(); + supertype supertype(); + classtype classtype(); + pactype pactype(); + int64_t imm(); + uint8_t rd(); + uint8_t rn(); + uint8_t rt(); + uint8_t rt2(); + uint8_t rm(); + cond condition(); + uint64_t special(); + + public: //cast operators + operator enum type(); + operator loc_t(); + + +#pragma mark constructor functions + public: //constructor functions +#pragma mark general + static insn new_general_adr(loc_t pc, uint64_t imm, uint8_t rd); + static insn new_general_adrp(loc_t pc, uint64_t imm, uint8_t rd); + static insn new_general_br(loc_t pc, uint8_t rn, uint8_t rm = 0, enum pactype pac = pac_none); + static insn new_general_ldp_index(loc_t pc, int8_t imm, uint8_t rt, uint8_t rt2, uint8_t rn, bool isPreindex = false); + static insn new_general_ldp_offset(loc_t pc, int8_t imm, uint8_t rt, uint8_t rt2, uint8_t rn); + static insn new_general_stp_index(loc_t pc, int8_t imm, uint8_t rt, uint8_t rt2, uint8_t rn, bool isPreindex = false); + static insn new_general_stp_offset(loc_t pc, int8_t imm, uint8_t rt, uint8_t rt2, uint8_t rn); + static insn new_general_nop(loc_t pc); + static insn new_general_ret(loc_t pc); + +#pragma mark register + static insn new_register_ccmp(loc_t pc, cond condition, uint8_t flags, uint8_t rn, uint8_t rm); + static insn new_register_mov(loc_t pc, int64_t imm, uint8_t rd, uint8_t rn, uint8_t rm); + +#pragma mark immediate + static insn new_immediate_add(loc_t pc, uint64_t imm, uint8_t rn, uint8_t rd); + static insn new_immediate_b(loc_t pc, uint64_t imm); + static insn new_immediate_bcond(loc_t pc, uint64_t imm, enum cond condition); + static insn new_immediate_bl(loc_t pc, int64_t imm); + static insn new_immediate_cbz(loc_t pc, int32_t imm, int8_t rt, bool isCBNZ = false); + static insn new_immediate_ldr(loc_t pc, int64_t imm, uint8_t rn, uint8_t rt); + static insn new_immediate_movk(loc_t pc, int64_t imm, uint8_t rd, uint8_t rm); + static insn new_immediate_movz(loc_t pc, int64_t imm, uint8_t rd, uint8_t rm); + static insn new_immediate_tbz(loc_t pc, int16_t imm, uint8_t b5, uint8_t b40, uint8_t rt, bool isTBNZ = false); + +#pragma mark literal + static insn new_literal_ldr(loc_t pc, uint64_t imm, uint8_t rt); + }; + }; +}; + + + + + +#endif /* insn_hpp */ diff --git a/include/libinsn/vmem.hpp b/include/libinsn/vmem.hpp new file mode 100644 index 0000000..b3d5595 --- /dev/null +++ b/include/libinsn/vmem.hpp @@ -0,0 +1,71 @@ +// +// vmem.hpp +// liboffsetfinder64 +// +// Created by tihmstar on 28.09.19. +// Copyright © 2019 tihmstar. All rights reserved. +// + +#ifndef vmem_hpp +#define vmem_hpp + +#include + +namespace tihmstar{ + namespace libinsn{ + + class vmem{ + uint32_t _segNum; + std::vector _segments; + + insn myop_plus(int i, uint32_t segNum); + insn myop_minus(int i, uint32_t segNum); + + public: + vmem(const std::vector segments, int perm = vsegment::kVMPROTEXEC); + vmem(const vmem& copy, libinsn::loc_t pos = 0, int perm = vsegment::kVMPROTEXEC); + + vsegment seg(loc_t pos); + + uint64_t deref(loc_t pos); + loc_t memmem(const void *little, size_t little_len, loc_t startLoc = 0); + loc_t memstr(const char *little); + bool isInRange(loc_t pos) noexcept; + + /*--segment functions but for vmem--*/ + //iterator operator + insn operator+(int i); + insn operator-(int i); + insn operator++(); + insn operator--(); + vmem &operator+=(int i); + vmem &operator-=(int i); + vmem &operator=(loc_t p); + + void nextSeg(); + void prevSeg(); + + //segment info functions + int curPerm() const; + vsegment curSeg(); + const vsegment curSeg() const; + const vsegment segmentForLoc(loc_t loc); + const void *memoryForLoc(loc_t loc); + + + //deref operator + uint64_t pc(); + uint32_t value(loc_t p); //arbitrary pos + uint64_t doublevalue(loc_t p); //arbitrary pos + uint32_t value(); //curpos + uint64_t doublevalue(); //curpos + + //insn operator + insn getinsn(); + insn operator()(); + operator loc_t() const; + }; + + }; +}; +#endif /* vmem_hpp */ diff --git a/include/libinsn/vsegment.hpp b/include/libinsn/vsegment.hpp new file mode 100644 index 0000000..35452c0 --- /dev/null +++ b/include/libinsn/vsegment.hpp @@ -0,0 +1,74 @@ +// +// vsegment.hpp +// liboffsetfinder64 +// +// Created by tihmstar on 28.09.19. +// Copyright © 2019 tihmstar. All rights reserved. +// + +#ifndef vsegment_hpp +#define vsegment_hpp + +#include +#include +#include + +namespace tihmstar{ + namespace libinsn{ + class vsegment{ + public: + enum vmprot{ + kVMPROTNONE = 0, + kVMPROTREAD = 1 << 0, + kVMPROTWRITE = 1 << 1, + kVMPROTEXEC = 1 << 2, + }; + private: + int _perms; + const uint8_t *_buf; //noalloc + size_t _size; + loc_t _vaddr; + offset_t _curpos; + std::string _segname; + + public: + vsegment(const void *buf, size_t size, loc_t vmemAddr, int perms, std::string segname = ""); + vsegment(const vsegment &cpy); //copy constructor + vsegment(const vsegment &cpy, loc_t pos); //copy constructor + + + bool isInRange(loc_t p); + loc_t memmem(const void *little, size_t little_len, loc_t startLoc = 0); + + //iterator operator + insn operator+(int i); + insn operator-(int i); + insn operator++(); + insn operator--(); + vsegment &operator+=(int i); + vsegment &operator-=(int i); + vsegment &operator=(loc_t p); + + //segment info functions + loc_t base() const {return _vaddr;} + size_t size() const {return _size;} + int perm() const {return _perms;} + std::string segname() {return _segname;} + const void *memoryForLoc(loc_t loc); + + //deref operator + uint64_t pc() const; + uint32_t value(loc_t p) const; //arbitrary pos + uint64_t doublevalue(loc_t p) const; //arbitrary pos + uint32_t value() const; //curpos + uint64_t doublevalue() const; //curpos + + //insn operator + insn getinsn(); + insn operator()(); + operator loc_t() const; + }; + }; +}; + +#endif /* vsegment_hpp */ diff --git a/include/liboffsetfinder64/OFexception.hpp b/include/liboffsetfinder64/OFexception.hpp new file mode 100644 index 0000000..8b30457 --- /dev/null +++ b/include/liboffsetfinder64/OFexception.hpp @@ -0,0 +1,55 @@ +// +// OFexception.h +// liboffsetfinder64 +// +// Created by tihmstar on 24.02.19. +// Copyright © 2019 tihmstar. All rights reserved. +// + +#ifndef OFexception_h +#define OFexception_h + +#include +#include + +namespace tihmstar { + class OFexception : public tihmstar::exception{ + using exception::exception; + }; + //custom exceptions for makeing it easy to catch + class out_of_range : public OFexception{ + using OFexception::OFexception; + }; + + class not_found : public OFexception{ + using OFexception::OFexception; + }; + + + class symbol_not_found : public OFexception{ + using OFexception::OFexception; + }; + + class load_command_not_found : public OFexception{ + int _cmd; + public: + int cmd() const { return _cmd;}; + load_command_not_found(const char *commit_count_str, const char *commit_sha_str, int line, const char *filename, int cmd) + : OFexception(commit_count_str,commit_sha_str,line,filename, "failed to find cmd: %s",cmd), _cmd(cmd) {}; + }; + + class symtab_not_found : public OFexception{ + using OFexception::OFexception; + }; + + class limit_reached : public OFexception{ + using OFexception::OFexception; + }; + + class bad_branch_destination : public OFexception{ + using OFexception::OFexception; + }; +}; + + +#endif /* OFexception_h */ diff --git a/include/liboffsetfinder64/common.h b/include/liboffsetfinder64/common.h new file mode 100644 index 0000000..974010d --- /dev/null +++ b/include/liboffsetfinder64/common.h @@ -0,0 +1,22 @@ +// +// common.h +// liboffsetfinder64 +// +// Created by tihmstar on 09.03.18. +// Copyright © 2018 tihmstar. All rights reserved. +// + +#ifndef common_h +#define common_h + +#include +#include + +namespace tihmstar{ + namespace offsetfinder64{ + typedef uint64_t loc_t; + typedef uint64_t offset_t; + } +} + +#endif /* common_h */ diff --git a/include/liboffsetfinder64/ibootpatchfinder64.hpp b/include/liboffsetfinder64/ibootpatchfinder64.hpp new file mode 100644 index 0000000..eff9adb --- /dev/null +++ b/include/liboffsetfinder64/ibootpatchfinder64.hpp @@ -0,0 +1,140 @@ +// +// ibootpatchfinder64.hpp +// liboffsetfinder64 +// +// Created by tihmstar on 28.07.20. +// Copyright © 2020 tihmstar. All rights reserved. +// + +#ifndef ibootpatchfinder64_hpp +#define ibootpatchfinder64_hpp + +#include + +#include +#include +#include +#include + +#include +#include + +namespace tihmstar { + namespace offsetfinder64 { + class ibootpatchfinder64 : public patchfinder64{ + protected: + uint32_t _vers; + uint32_t _vers_arr[5]; + int _chipid; + bool stage1 = false; + bool stage2 = false; + bool dev = false; + + ibootpatchfinder64(bool freeBuf); + public: + + static ibootpatchfinder64 *make_ibootpatchfinder64(const char *filename); + static ibootpatchfinder64 *make_ibootpatchfinder64(const void *buffer, size_t bufSize, bool takeOwnership = false); + + + virtual bool has_kernel_load(); + virtual bool has_recovery_console(); + + virtual ~ibootpatchfinder64(); + + /* + disable IM4M value validation (BNCH, ECID ...) + */ + virtual std::vector get_sigcheck_patch(); + + /* + demotion image patch + */ + virtual std::vector get_demotion_patch(); + + /* + make kernel boot with these bootargs + */ + virtual std::vector get_boot_arg_patch(const char *bootargs); + + /* + // + */ + virtual std::vector get_debug_enabled_patch(); + + /* + make an iBoot command jump to a specific address + */ + virtual std::vector get_cmd_handler_patch(const char *cmd_handler_str, uint64_t ptr); + + /* + replace "bgcolor" with command: "memcpy " + */ + virtual std::vector replace_bgcolor_with_memcpy(); + + /* + + */ + virtual std::vector get_ra1nra1n_patch(); + + + /* + allows reading and writing any nvram variable + */ + virtual std::vector get_unlock_nvram_patch(); + + /* + makes saveenv function do nothing + */ + virtual std::vector get_nvram_nosave_patch(); + + /* + disable unsetting environment variables + */ + virtual std::vector get_nvram_noremove_patch(); + + /* + get a fresh nonce every time we need a nonce + */ + virtual std::vector get_freshnonce_patch(); + + /* + replace "reboot" command with "fsboot" command, which boots from filesystem + */ + virtual std::vector get_change_reboot_to_fsboot_patch(); + + /* + local boot + */ + virtual std::vector local_boot_patch(); + + /* + change snapshot name + */ + virtual std::vector renamed_snapshot_patch(); + + /* + kernelcache -> kernelcachd + */ + virtual std::vector rename_kcache_to_kcachd_patch(); + + + virtual loc_t find_iBoot_logstr(uint64_t loghex, int skip = 0, uint64_t shortdec = 0); + + + virtual uint32_t get_el1_pagesize(); + + /* + maps iBoot block writable at 0x2000000 + maps loadaddr block executable at 0x4000000 + + */ + + virtual std::vector get_rw_and_x_mappings_patch_el1(); + + + }; + }; +}; + +#endif /* ibootpatchfinder64_hpp */ diff --git a/include/liboffsetfinder64/ibootpatchfinder64_base.hpp b/include/liboffsetfinder64/ibootpatchfinder64_base.hpp new file mode 100644 index 0000000..ebaba4a --- /dev/null +++ b/include/liboffsetfinder64/ibootpatchfinder64_base.hpp @@ -0,0 +1,108 @@ +// +// ibootpatchfinder64.hpp +// liboffsetfinder64 +// +// Created by tihmstar on 28.09.19. +// Copyright © 2019 tihmstar. All rights reserved. +// + +#ifndef ibootpatchfinder64_base_hpp +#define ibootpatchfinder64_base_hpp + +#include + +#include +#include +#include +#include + +#include +#include + +namespace tihmstar { + namespace offsetfinder64 { + class ibootpatchfinder64_base : public ibootpatchfinder64{ + public: + ibootpatchfinder64_base(const char *filename); + ibootpatchfinder64_base(const void *buffer, size_t bufSize, bool takeOwnership = false); + + virtual ~ibootpatchfinder64_base() override; + + virtual bool has_kernel_load() override; + virtual bool has_recovery_console() override; + + + /* + disable IM4M value validation (BNCH, ECID ...) + */ + virtual std::vector get_sigcheck_patch() override; + + /* + demotion image patch + */ + virtual std::vector get_demotion_patch() override; + + /* + make kernel boot with these bootargs + */ + virtual std::vector get_boot_arg_patch(const char *bootargs) override; + + /* + // + */ + virtual std::vector get_debug_enabled_patch() override; + + /* + make an iBoot command jump to a specific address + */ + virtual std::vector get_cmd_handler_patch(const char *cmd_handler_str, uint64_t ptr) override; + + /* + replace "bgcolor" with command: "memcpy " + */ + virtual std::vector replace_bgcolor_with_memcpy() override; + + /* + + */ + virtual std::vector get_ra1nra1n_patch() override; + + + /* + allows reading and writing any nvram variable + */ + virtual std::vector get_unlock_nvram_patch() override; + + /* + makes saveenv function do nothing + */ + virtual std::vector get_nvram_nosave_patch() override; + + /* + disable unsetting environment variables + */ + virtual std::vector get_nvram_noremove_patch() override; + + /* + get a fresh nonce every time we need a nonce + */ + virtual std::vector get_freshnonce_patch() override; + +// /* +// DEVICE2HOST transfers are set addr=getenv("loadaddr")+getenv("filesize");size=0x800000 +// instead of add=getenv("cmd-results");size=strlen(getenv("cmd-results"))+1 +// */ +// std::vector get_readback_loadaddr_patch(); +// +// /* +// replace "memboot" command with "memload", +// which will load dtre from NAND to getenv("loadaddr") +// */ +// std::vector get_memload_patch(); + + + }; + }; +}; + +#endif /* ibootpatchfinder64_base_hpp */ diff --git a/include/liboffsetfinder64/ibootpatchfinder64_iOS14.hpp b/include/liboffsetfinder64/ibootpatchfinder64_iOS14.hpp new file mode 100644 index 0000000..76d848a --- /dev/null +++ b/include/liboffsetfinder64/ibootpatchfinder64_iOS14.hpp @@ -0,0 +1,44 @@ +// +// ibootpatchfinder64_iOS14.hpp +// liboffsetfinder64 +// +// Created by tihmstar on 28.07.20. +// Copyright © 2020 tihmstar. All rights reserved. +// + +#ifndef ibootpatchfinder64_iOS14_hpp +#define ibootpatchfinder64_iOS14_hpp + +#include + +namespace tihmstar { + namespace offsetfinder64 { + class ibootpatchfinder64_iOS14 : public ibootpatchfinder64_base{ + public: + ibootpatchfinder64_iOS14(const char *filename); + ibootpatchfinder64_iOS14(const void *buffer, size_t bufSize, bool takeOwnership = false); + + + virtual std::vector get_sigcheck_patch() override; + + virtual std::vector get_demotion_patch() override; + + virtual std::vector get_change_reboot_to_fsboot_patch() override; + + virtual std::vector local_boot_patch() override; + + virtual std::vector renamed_snapshot_patch() override; + + virtual std::vector rename_kcache_to_kcachd_patch() override; + + virtual loc_t find_iBoot_logstr(uint64_t loghex, int skip = 0, uint64_t shortdec = 0) override; + + virtual uint32_t get_el1_pagesize() override; + + virtual std::vector get_rw_and_x_mappings_patch_el1() override; + + }; + }; +}; + +#endif /* ibootpatchfinder64_iOS14_hpp */ diff --git a/include/liboffsetfinder64/kernelpatchfinder64.hpp b/include/liboffsetfinder64/kernelpatchfinder64.hpp new file mode 100644 index 0000000..70383fa --- /dev/null +++ b/include/liboffsetfinder64/kernelpatchfinder64.hpp @@ -0,0 +1,51 @@ +// +// kernelpatchfinder64.hpp +// liboffsetfinder64 +// +// Created by tihmstar on 28.09.19. +// Copyright © 2019 tihmstar. All rights reserved. +// + +#ifndef kernelpatchfinder64_hpp +#define kernelpatchfinder64_hpp + +#include + +namespace tihmstar { + namespace offsetfinder64 { + class kernelpatchfinder64 : public machopatchfinder64{ + public: + kernelpatchfinder64(const char *filename); + kernelpatchfinder64(const void *buffer, size_t bufSize); + + loc_t find_syscall0(); + loc_t find_machtrap_table(); + loc_t find_function_for_syscall(int syscall); + loc_t find_function_for_machtrap(int trapcall); + + loc_t find_kerneltask(); + + std::vector get_MarijuanARM_patch(); + std::vector get_task_conversion_eval_patch(); + std::vector get_vm_fault_internal_patch(); + + std::vector get_trustcache_true_patch(); + + std::vector get_mount_patch(); + + std::vector get_tfp0_patch(); + + std::vector get_amfi_patch(bool doApplyPatch = true); //don't use up nop space by multiple patches if this is set to true + + std::vector get_get_task_allow_patch(); + + std::vector get_apfs_snapshot_patch(); + + /*------------------------ Util -------------------------- */ + offsetfinder64::loc_t find_rootvnode(); + offsetfinder64::loc_t find_allproc(); + }; + }; +}; + +#endif /* kernelpatchfinder64_hpp */ diff --git a/include/liboffsetfinder64/machopatchfinder64.hpp b/include/liboffsetfinder64/machopatchfinder64.hpp new file mode 100644 index 0000000..f1e9b41 --- /dev/null +++ b/include/liboffsetfinder64/machopatchfinder64.hpp @@ -0,0 +1,41 @@ +// +// machopatchfinder64.hpp +// liboffsetfinder64 +// +// Created by tihmstar on 28.09.19. +// Copyright © 2019 tihmstar. All rights reserved. +// + +#ifndef machopatchfinder64_hpp +#define machopatchfinder64_hpp + +#include + +struct symtab_command; +namespace tihmstar { + namespace offsetfinder64 { + + class machopatchfinder64 : public patchfinder64{ + struct symtab_command *__symtab; + + void loadSegments(); + __attribute__((always_inline)) struct symtab_command *getSymtab(); + + void init(); + + public: + machopatchfinder64(const char *filename); + machopatchfinder64(const void *buffer, size_t bufSize); + + bool haveSymbols() { return __symtab != NULL;}; + loc_t find_sym(const char *sym); + std::string sym_for_addr(loc_t addr); + + + }; + + }; +}; + + +#endif /* machopatchfinder64_hpp */ diff --git a/include/liboffsetfinder64/patch.hpp b/include/liboffsetfinder64/patch.hpp new file mode 100644 index 0000000..b2b5d91 --- /dev/null +++ b/include/liboffsetfinder64/patch.hpp @@ -0,0 +1,36 @@ +// +// patch.hpp +// liboffsetfinder64 +// +// Created by tihmstar on 09.03.18. +// Copyright © 2018 tihmstar. All rights reserved. +// + +#ifndef patch_hpp +#define patch_hpp + +#include +#include +#include +#include + +namespace tihmstar { + namespace offsetfinder64{ + class patch{ + bool _slideme; + void(*_slidefunc)(class patch *patch, uint64_t slide); + public: + loc_t _location; + size_t _patchSize; + const void *_patch; + patch(loc_t location, const void *patch, size_t patchSize, void(*slidefunc)(class patch *patch, uint64_t slide) = NULL); + patch(const patch& cpy) noexcept; + patch &operator=(const patch& cpy); + void slide(uint64_t slide); + ~patch(); + }; + + } +} + +#endif /* patch_hpp */ diff --git a/include/liboffsetfinder64/patchfinder64.hpp b/include/liboffsetfinder64/patchfinder64.hpp new file mode 100644 index 0000000..efe7612 --- /dev/null +++ b/include/liboffsetfinder64/patchfinder64.hpp @@ -0,0 +1,70 @@ +// +// offsetfinder64.hpp +// offsetfinder64 +// +// Created by tihmstar on 10.01.18. +// Copyright © 2018 tihmstar. All rights reserved. +// + +#ifndef offsetfinder64_hpp +#define offsetfinder64_hpp + +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include + +namespace tihmstar { + namespace offsetfinder64{ + + class patchfinder64 { + protected: + bool _freeBuf; + const uint8_t *_buf; + size_t _bufSize; + offsetfinder64::loc_t _entrypoint; + offsetfinder64::loc_t _base; + tihmstar::libinsn::vmem *_vmem; + std::vector> _usedNops; + + + public: + patchfinder64(bool freeBuf); + ~patchfinder64(); + + const void *buf() { return _buf;} + size_t bufSize() { return _bufSize;} + loc_t find_entry() { return _entrypoint;} + loc_t find_base() { return _base; } + + const void *memoryForLoc(loc_t loc); + + + loc_t findstr(std::string str, bool hasNullTerminator, loc_t startAddr = 0); + loc_t find_bof(loc_t pos); + uint64_t find_register_value(loc_t where, int reg, loc_t startAddr = 0); + loc_t find_literal_ref(loc_t pos, int ignoreTimes = 0, loc_t startPos = 0); + loc_t find_call_ref(loc_t pos, int ignoreTimes = 0, loc_t startPos = 0); + loc_t find_branch_ref(loc_t pos, int limit, int ignoreTimes = 0); + loc_t findnops(uint16_t nopCnt, bool useNops = true); + + + uint32_t pageshit_for_pagesize(uint32_t pagesize); + uint64_t pte_vma_to_index(uint32_t pagesize, uint8_t level, uint64_t address); + uint64_t pte_index_to_vma(uint32_t pagesize, uint8_t level, uint64_t index); + + }; + + }; +} + + +#endif /* offsetfinder64_hpp */ diff --git a/libcrypto.a b/libcrypto.a new file mode 100644 index 0000000..05bc4c5 Binary files /dev/null and b/libcrypto.a differ diff --git a/libgeneral.a b/libgeneral.a new file mode 100644 index 0000000..5038dee Binary files /dev/null and b/libgeneral.a differ diff --git a/libinsn.a b/libinsn.a new file mode 100644 index 0000000..11e233b Binary files /dev/null and b/libinsn.a differ diff --git a/liboffsetfinder64.a b/liboffsetfinder64.a new file mode 100644 index 0000000..a69ef48 Binary files /dev/null and b/liboffsetfinder64.a differ diff --git a/libssl.a b/libssl.a new file mode 100644 index 0000000..9b76af5 Binary files /dev/null and b/libssl.a differ diff --git a/src/main.cpp b/main.cpp similarity index 100% rename from src/main.cpp rename to main.cpp