Skip to content

Commit

Permalink
Merge branch 'upstream/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryptiiiic committed Oct 16, 2024
2 parents 385315b + 94cec83 commit 86aa783
Show file tree
Hide file tree
Showing 30 changed files with 787 additions and 263 deletions.
13 changes: 0 additions & 13 deletions .github/FUNDING.yml

This file was deleted.

144 changes: 144 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
name: Buildrunner

on: [push]

jobs:
build:

strategy:
matrix:
platform: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.platform }}
env:
BUILDROOT: "buildroot_${{ matrix.platform }}"
GIT_DEPENDENCIES: img3tool,img4tool,libgeneral,libinsn,libplist

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install pre-dependencies
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get update
sudo apt-get install -y jq
wget https://github.com/apple-oss-distributions/cctools/archive/refs/tags/cctools-973.0.1.tar.gz -O cctools.tar.gz
mkdir tmp
tar -xvzf cctools.tar.gz -C tmp
mv tmp/cctoo* tmp/cctools
sed -i 's_#include_//_g' tmp/cctools/include/mach-o/loader.h
sed -i -e 's=<stdint.h>=\n#include <stdint.h>\ntypedef int integer_t;\ntypedef integer_t cpu_type_t;\ntypedef integer_t cpu_subtype_t;\ntypedef integer_t cpu_threadtype_t;\ntypedef int vm_prot_t;=g' tmp/cctools/include/mach-o/loader.h
sudo cp -r tmp/cctools/include/* /usr/local/include/
rm -rf tmp cctools.tar.gz
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install autoconf automake libtool jq pkg-config
else
echo "$RUNNER_OS not supported"
exit 1
fi
shell: bash
- name: download dependencies
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
get_latest_release() {
url="https://api.github.com/repos/$1/releases/latest"
echo "url: ${url}" >&2
curl --silent --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' "${url}" | # Get latest release from GitHub api
jq .tag_name | # Get tag
tr -d '"' # Strip quotes
}
mkdir depdir
cd depdir
mkdir $BUILDROOT
IFS=',' read -r -a deparray <<< "$GIT_DEPENDENCIES"; for d in ${deparray[@]}; do
dep=$d
if ! echo ${dep} | grep -q '/'; then
dep=${{ github.repository_owner }}/${dep}
fi
echo "Got dependency: ${dep}"
tag=$(get_latest_release ${dep});
echo "Found tag: $tag"
wget "https://github.com/${dep}/releases/download/$tag/$BUILDROOT.zip"
unzip -u "$BUILDROOT.zip"
rm "$BUILDROOT.zip"
done
echo "moving dependencies to /"
sudo cp -r $BUILDROOT/* /
cd ..
rm -rf depdir
- name: prepre buildroot
run: mkdir -p $BUILDROOT
- name: autogen
run: ./autogen.sh --enable-static --disable-shared
- name: make
run: |
if [ "$RUNNER_OS" == "macOS" ]; then
IFS=',' read -r -a deparray <<< "$MAC_DYNAMIC_LIBS"; for d in ${deparray[@]}; do
echo "moving library $d"
cd $(brew --prefix $d)
find . -name "*.dylib" -exec mv {} {}.bak \;
done
cd $GITHUB_WORKSPACE
make -j || make
IFS=',' read -r -a deparray <<< "$MAC_DYNAMIC_LIBS"; for d in ${deparray[@]}; do
echo "restoring library $d"
cd $(brew --prefix $d)
find . -name "*.dylib.bak" | while read f; do o=$(echo $f | rev | cut -d '.' -f2- | rev); mv $f $o; done
done
cd $GITHUB_WORKSPACE
else
make -j || make
fi
- name: make install
run: make DESTDIR=$GITHUB_WORKSPACE/$BUILDROOT install
- uses: actions/upload-artifact@v4
with:
name: ${{ env.BUILDROOT }}
path: ${{ env.BUILDROOT }}

release:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download ubuntu artifact
uses: actions/download-artifact@v4
with:
name: buildroot_ubuntu-latest
path: buildroot_ubuntu-latest
- name: Download macos artifact
uses: actions/download-artifact@v4
with:
name: buildroot_macos-latest
path: buildroot_macos-latest
- name: Set env vars and zip
run: |
echo "BUILD_VERSION_NUM=$(echo "$(git rev-list --count HEAD | tr -d '\n')")" >> $GITHUB_ENV
echo "BUILD_VERSION_SHA=$(echo "$(git rev-parse HEAD | tr -d '\n'])")" >> $GITHUB_ENV
echo "BUILD_VERSION_STR=$(echo "$(git rev-list --count HEAD | tr -d '\n')-$(git rev-parse HEAD | tr -d '\n'])")" >> $GITHUB_ENV
echo "COMMIT_MSG=$(echo "$(git log -1 --pretty=%B)")" >> $GITHUB_ENV
zip -r buildroot_macos-latest.zip buildroot_macos-latest
zip -r buildroot_ubuntu-latest.zip buildroot_ubuntu-latest
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
if: github.ref == 'refs/heads/master'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
prerelease: false
draft: false
tag_name: ${{ env.BUILD_VERSION_NUM }}
name: Build ${{ env.BUILD_VERSION_STR }}
body: ${{ env.COMMIT_MSG }}
files: |
buildroot_ubuntu-latest.zip
buildroot_macos-latest.zip
34 changes: 26 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ AC_SUBST([VERSION_COMMIT_COUNT], ["m4_esyscmd([git rev-list --count HEAD | tr -d
AC_SUBST([VERSION_COMMIT_SHA], ["m4_esyscmd([git rev-parse HEAD | tr -d '\n'])"])

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CXX([clang++])
AC_PROG_CC([clang])

# Check for operating system
AC_MSG_CHECKING([whether we need platform-specific build settings])
Expand All @@ -33,15 +33,15 @@ case $host_os in
esac


CXXFLAGS+=" -std=c++11 -O3"
CXXFLAGS+=" -std=c++20 -O3"
CFLAGS+=" -std=c11"
CXXFLAGS+=" -D EXPECTIONNAME=OFexception"

# Checks for libraries.
IMG4TOOL_REQUIRES_STR="libimg4tool >= 202"
IMG3TOOL_REQUIRES_STR="libimg3tool >= 8"
LIBGENERAL_REQUIRES_STR="libgeneral >= 75"
LIBINSN_REQUIRES_STR="libinsn >= 49"
IMG4TOOL_REQUIRES_STR="libimg4tool >= 198"
IMG3TOOL_REQUIRES_STR="libimg3tool >= 2"
LIBGENERAL_REQUIRES_STR="libgeneral >= 65"
LIBINSN_REQUIRES_STR="libinsn >= 38"
PKG_CHECK_MODULES(libimg4tool, $IMG4TOOL_REQUIRES_STR, have_img4tool=yes, have_img4tool=no)
PKG_CHECK_MODULES(libimg3tool, $IMG3TOOL_REQUIRES_STR, have_img3tool=yes, have_img3tool=no)
PKG_CHECK_MODULES(libgeneral, $LIBGENERAL_REQUIRES_STR)
Expand Down Expand Up @@ -158,6 +158,23 @@ fi
AM_CONDITIONAL(WITH_WTFPWNDFU, test x$with_wtfpwndfu == xyes)

# Checks for header files.

ORIG_CFLAGS=${CFLAGS}
CFLAGS+=" -I${lt_sysroot}/include -I${lt_sysroot}/${prefix}/include -I${lt_sysroot}/${ac_default_prefix}/include"
AC_CHECK_HEADERS([mach-o/loader.h mach-o/nlist.h], [
AC_DEFINE(HAVE_MACHO_O_HEADER, 1, [Define if you have apple cctools headers])
AC_SUBST([HAVE_MACHO_O_HEADER], [1])
have_macho_header=yes;
], [
AC_SUBST([HAVE_MACHO_O_HEADER], [0])
have_macho_header=no;
], [])
CFLAGS=${ORIG_CFLAGS}

if test "x$have_macho_header" != "xyes"; then
AC_MSG_ERROR(["Macho-O headers not found, are apple cctools headers installed?"])
fi

AC_CHECK_HEADERS([fcntl.h stdint.h stdlib.h string.h unistd.h arpa/inet.h winsock.h])

# Check for functions
Expand All @@ -173,7 +190,7 @@ AC_CONFIG_FILES([Makefile
tools/Makefile
tools/binrider/Makefile
tools/offsetexporter/Makefile
libpatchfinder.pc])
libpatchfinder.pc])
AC_OUTPUT

echo "
Expand All @@ -183,6 +200,7 @@ Configuration for $PACKAGE-$VERSION:
install prefix ..........: $prefix
have img4tool ...........: $with_img4tool
have img3tool ...........: $with_img3tool
have mach-o header.......: $have_macho_header
debug build ............: $debug_build
asan build .............: $asan_build
with binrider ...........: $with_binrider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ namespace tihmstar {
class ibootpatchfinder64 : public patchfinder64, public ibootpatchfinder {
protected:
ibootpatchfinder64(bool freeBuf);
ibootpatchfinder64(ibootpatchfinder64 &&mv);
public:

static ibootpatchfinder64 *make_ibootpatchfinder64(const char *filename);
Expand Down
12 changes: 7 additions & 5 deletions include/libpatchfinder/patch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
namespace tihmstar {
namespace patchfinder{
class patch{
void *_patch;
size_t _patchSize;
bool _slideme;
bool _dofree;
void(*_slidefunc)(class patch *patch, uint64_t slide);
public:
uint64_t _location;
size_t _patchSize;
const void *_patch;
patch(uint64_t location, const void *patch, size_t patchSize, void(*slidefunc)(class patch *patch, uint64_t slide) = NULL, bool dofree = true);
patch(uint64_t location, const void *patch, size_t patchSize, void(*slidefunc)(class patch *patch, uint64_t slide) = NULL);
patch(const patch& cpy) noexcept;
~patch();


inline const void *getPatch(){return _patch;}
inline size_t getPatchSize(){return _patchSize;}

patch &operator=(const patch& cpy);
void slide(uint64_t slide);
};
Expand Down
6 changes: 6 additions & 0 deletions libpatchfinder.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
2A0D862E2BF4FABC00CE4FA7 /* kernelpatchfinder64_iOS8.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2A0D862C2BF4FABC00CE4FA7 /* kernelpatchfinder64_iOS8.cpp */; };
2A102B482ADD3CDD00F86D9E /* ibootpatchfinder32_iOS8.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2A102B462ADD3CDD00F86D9E /* ibootpatchfinder32_iOS8.cpp */; };
2A32E5DE2A41CD5A007170DA /* kernelpatchfinder64_iOS17.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2A32E5DC2A41CD5A007170DA /* kernelpatchfinder64_iOS17.cpp */; };
2A44ABC12A84C0650076F87C /* StableHash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8739AE2F2A6B48E000630CEA /* StableHash.cpp */; };
Expand Down Expand Up @@ -167,6 +168,8 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
2A0D862C2BF4FABC00CE4FA7 /* kernelpatchfinder64_iOS8.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = kernelpatchfinder64_iOS8.cpp; sourceTree = "<group>"; };
2A0D862D2BF4FABC00CE4FA7 /* kernelpatchfinder64_iOS8.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kernelpatchfinder64_iOS8.hpp; sourceTree = "<group>"; };
2A102B462ADD3CDD00F86D9E /* ibootpatchfinder32_iOS8.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ibootpatchfinder32_iOS8.cpp; sourceTree = "<group>"; };
2A102B472ADD3CDD00F86D9E /* ibootpatchfinder32_iOS8.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ibootpatchfinder32_iOS8.hpp; sourceTree = "<group>"; };
2A32E5DC2A41CD5A007170DA /* kernelpatchfinder64_iOS17.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = kernelpatchfinder64_iOS17.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -472,6 +475,8 @@
87C7D5B22854D9EC001CE584 /* sbops64.h */,
87F0A57626A5BD950090C657 /* kernelpatchfinder64_base.hpp */,
8738E8FA2695981A00C03872 /* kernelpatchfinder64_base.cpp */,
2A0D862D2BF4FABC00CE4FA7 /* kernelpatchfinder64_iOS8.hpp */,
2A0D862C2BF4FABC00CE4FA7 /* kernelpatchfinder64_iOS8.cpp */,
87F0A57526A5BD950090C657 /* kernelpatchfinder64_iOS9.hpp */,
8738E8FC2695981A00C03872 /* kernelpatchfinder64_iOS9.cpp */,
87F0A57426A5BD950090C657 /* kernelpatchfinder64_iOS12.hpp */,
Expand Down Expand Up @@ -653,6 +658,7 @@
8738E8F7269597FE00C03872 /* ibootpatchfinder64.cpp in Sources */,
8738E87226945D5300C03872 /* patchfinder64.cpp in Sources */,
8738E91426959AEE00C03872 /* ibootpatchfinder32_base.cpp in Sources */,
2A0D862E2BF4FABC00CE4FA7 /* kernelpatchfinder64_iOS8.cpp in Sources */,
8738E88626945EE500C03872 /* patchfinder32.cpp in Sources */,
87F8453A2771C93D0018347B /* ibootpatchfinder32_iOS12.cpp in Sources */,
8738E8F4269597FE00C03872 /* ibootpatchfinder64_iOS12.cpp in Sources */,
Expand Down
36 changes: 13 additions & 23 deletions libpatchfinder/ibootpatchfinder/ibootpatchfinder32_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,55 +31,44 @@ using namespace tihmstar::libinsn::arm32;
ibootpatchfinder32_base::ibootpatchfinder32_base(const char * filename) :
ibootpatchfinder32(true)
{
struct stat fs = {0};
int fd = 0;
bool didConstructSuccessfully = false;
int fd = -1;
cleanup([&]{
if (fd>0) close(fd);
if (!didConstructSuccessfully) {
safeFreeConst(_buf);
}
safeClose(fd);
})

struct stat fs = {0};

assure((fd = open(filename, O_RDONLY)) != -1);
assure(!fstat(fd, &fs));
assure((_buf = (uint8_t*)malloc( _bufSize = fs.st_size)));
assure(read(fd,(void*)_buf,_bufSize)==_bufSize);

assure(_bufSize > 0x1000);

assure(!strncmp((char*)&_buf[IBOOT_VERS_STR_OFFSET], "iBoot", sizeof("iBoot")-1));
retassure(*(uint32_t*)&_buf[0] == IBOOT32_RESET_VECTOR_BYTES, "invalid magic");

_entrypoint = _base = (loc_t)((*(uint32_t*)&_buf[0x20]) & ~0xFFF);
debug("iBoot base at=0x%08x", _base);
_vmemThumb = new vmem_thumb({{_buf,_bufSize,_base, (vmprot)(kVMPROTREAD | kVMPROTWRITE | kVMPROTEXEC)}});
_vmemArm = new vmem_arm({{_buf,_bufSize,_base, (vmprot)(kVMPROTREAD | kVMPROTWRITE | kVMPROTEXEC)}});
retassure(_vers = atoi((char*)&_buf[IBOOT_VERS_STR_OFFSET+6]), "No iBoot version found!\n");
debug("iBoot-%d inputted", _vers);

didConstructSuccessfully = true;
init();
}

ibootpatchfinder32_base::ibootpatchfinder32_base(const void *buffer, size_t bufSize, bool takeOwnership)
: ibootpatchfinder32(takeOwnership)
{
_bufSize = bufSize;
_buf = (uint8_t*)buffer;
init();
}

void ibootpatchfinder32_base::init(){
assure(_bufSize > 0x1000);

retassure(*(uint32_t*)&_buf[0] == IBOOT32_RESET_VECTOR_BYTES, "invalid magic");

_entrypoint = _base = (loc_t)((*(uint32_t*)&_buf[0x20]) & ~0xFFF);
debug("iBoot base at=0x%08x", _base);
safeDelete(_vmemThumb);
safeDelete(_vmemArm);
_vmemThumb = new vmem_thumb({{_buf,_bufSize,_base, (vmprot)(kVMPROTREAD | kVMPROTWRITE | kVMPROTEXEC)}});
_vmemArm = new vmem_arm({{_buf,_bufSize,_base, (vmprot)(kVMPROTREAD | kVMPROTWRITE | kVMPROTEXEC)}});

if (!strncmp((char*)&_buf[IBOOT_VERS_STR_OFFSET], "iBoot", sizeof("iBoot")-1)){
retassure(_vers = atoi((char*)&_buf[IBOOT_VERS_STR_OFFSET+6]), "No iBoot version found!\n");
}else{
//iOS 1 iBoot??
loc_t ibootstrloc = memmem("iBoot-", sizeof("iBoot-")-1);
loc_t ibootstrloc = (loc_t)memmem("iBoot-", sizeof("iBoot-")-1);
retassure(ibootstrloc, "No iBoot version found!\n");
const char *ibootstr = (char*)memoryForLoc(ibootstrloc);
retassure(_vers = atoi(ibootstr+6), "No iBoot version found!\n");
Expand All @@ -91,6 +80,7 @@ ibootpatchfinder32_base::~ibootpatchfinder32_base(){
//
}

#pragma mark public
bool ibootpatchfinder32_base::has_kernel_load(){
try {
return (bool) (memstr(KERNELCACHE_PREP_STRING) != 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace tihmstar {
namespace patchfinder {
class ibootpatchfinder32_base : public ibootpatchfinder32{
void init();
public:
ibootpatchfinder32_base(const char *filename);
ibootpatchfinder32_base(const void *buffer, size_t bufSize, bool takeOwnership = false);
Expand Down
6 changes: 0 additions & 6 deletions libpatchfinder/ibootpatchfinder/ibootpatchfinder64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ ibootpatchfinder64::ibootpatchfinder64(bool freeBuf)
//
}

ibootpatchfinder64::ibootpatchfinder64(ibootpatchfinder64 &&mv)
: patchfinder64(std::move(mv))
{
_vers = mv._vers;
}

ibootpatchfinder64 *ibootpatchfinder64::make_ibootpatchfinder64(const char * filename){
bool didConstructSuccessfully = false;
int fd = 0;
Expand Down
Loading

0 comments on commit 86aa783

Please # to comment.