Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add x8A4, Switch to libkrw fork #1459

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build_info/libkrw-dev.control
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Package: libkrw-dev
Author: Siguza
Author: Cryptiiiic
Maintainer: @DEB_MAINTAINER@
Architecture: @DEB_ARCH@
Version: @DEB_LIBKRW_V@
Depends: libkrw0 (= @DEB_LIBKRW_V@)
Section: Development
Priority: optional
Homepage: https://github.com/Siguza/libkrw
Homepage: https://github.com/Cryptiiiic/libkrw
Description: A kernel R/W API for jailbreaks (Development Files)
4 changes: 2 additions & 2 deletions build_info/libkrw0-tfp0.control
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Package: libkrw0-tfp0
Author: Siguza
Author: Cryptiiiic
Maintainer: @DEB_MAINTAINER@
Architecture: @DEB_ARCH@
Version: @DEB_LIBKRW_V@
Provides: libkrw0-plugin
Enhances: libkrw0
Section: Libraries
Priority: standard
Homepage: https://github.com/Siguza/libkrw
Homepage: https://github.com/Cryptiiiic/libkrw
Description: Plugin for libkrw that interfaces with tfp0/hgsp4 (Shared Library)
4 changes: 2 additions & 2 deletions build_info/libkrw0.control
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Package: libkrw0
Author: Siguza
Author: Cryptiiiic
Maintainer: @DEB_MAINTAINER@
Architecture: @DEB_ARCH@
Version: @DEB_LIBKRW_V@
Provides: libkrw (= @DEB_LIBKRW_V@)
Depends: libkrw0-plugin
Section: Libraries
Priority: standard
Homepage: https://github.com/Siguza/libkrw
Homepage: https://github.com/Cryptiiiic/libkrw
Description: A kernel R/W API for jailbreaks (Shared Library)
11 changes: 11 additions & 0 deletions build_info/libx8a4-1.control
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Package: libx8a4-1
Author: Cryptiiiic
Maintainer: @DEB_MAINTAINER@
Architecture: @DEB_ARCH@
Version: @DEB_X8A4_V@
Provides: libx8a4-1 (= @DEB_X8A4_V@)
Depends: libkrw0
Section: Libraries
Priority: standard
Homepage: https://github.com/Cryptiiiic/x8A4
Description: An all-in-one tool for firmware nonces, seeds, and downgrade support (Shared Library)
10 changes: 10 additions & 0 deletions build_info/libx8a4-dev.control
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Package: libx8a4-dev
Author: Cryptiiiic
Maintainer: @DEB_MAINTAINER@
Architecture: @DEB_ARCH@
Version: @DEB_X8A4_V@
Depends: libx8a4-1 (= @DEB_X8A4_V@)
Section: Development
Priority: optional
Homepage: https://github.com/Cryptiiiic/x8A4
Description: An all-in-one tool for firmware nonces, seeds, and downgrade support (Development Files)
12 changes: 12 additions & 0 deletions build_info/x8a4.control
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Package: x8a4
Name: x8A4
Author: Cryptiiiic
Maintainer: @DEB_MAINTAINER@
Architecture: @DEB_ARCH@
Version: @DEB_X8A4_V@
Depends: libx8a4-1 (= @DEB_X8A4_V@)
Enhances: dimentio
Section: Utilities
Priority: optional
Homepage: https://github.com/Cryptiiiic/x8A4
Description: An all-in-one tool for firmware nonces, seeds, and downgrade support
21 changes: 21 additions & 0 deletions build_misc/entitlements/x8A4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>get-task-allow</key>
<true/>
<key>task_for_pid-allow</key>
<true/>
<key>platform-application</key>
<true/>
<key>com.apple.private.kernel.get-kext-info</key>
<true/>
<key>com.apple.private.security.no-container</key>
<true/>
<key>com.apple.security.iokit-user-client-class</key>
<array>
<string>AppleMobileApNonceUserClient</string>
<string>IOSurfaceRootUserClient</string>
</array>
</dict>
</plist>
121 changes: 121 additions & 0 deletions build_patch/choma/choma.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
diff --git a/src/arm64.c b/src/arm64.c
index 2b07da0..99420f5 100644
--- a/src/arm64.c
+++ b/src/arm64.c
@@ -442,6 +442,90 @@ int arm64_dec_add_imm(uint32_t inst, arm64_register *destinationRegOut, arm64_re
return 0;
}

+int arm64_gen_sub_imm(arm64_register destinationReg, arm64_register sourceReg, optional_uint64_t optImm, optional_bool optS, uint32_t *bytesOut, uint32_t *maskOut) {
+ if (ARM64_REG_IS_ANY_VECTOR(destinationReg)) return -1;
+ if (ARM64_REG_IS_ANY_VECTOR(sourceReg)) return -1;
+
+ if (!ARM64_REG_IS_ANY(destinationReg) && !ARM64_REG_IS_ANY(sourceReg)) {
+ // if both regs are set and have a mismatching width, abort
+ if (ARM64_REG_IS_W(destinationReg) != ARM64_REG_IS_W(sourceReg)) return -1;
+ }
+
+ uint32_t inst = 0x51000000;
+ uint32_t mask = 0x7f800000;
+ if(OPT_BOOL_IS_SET(optS)) {
+ bool s = OPT_BOOL_GET_VAL(optS);
+ if(s) {
+ inst = 0x71000000;
+ mask |= (1 << 29);
+ inst |= (1 << 29);
+ }
+ }
+
+ // if one is set and 32 bit, include 32 bit in mask and set it in inst
+ if (!ARM64_REG_IS_ANY(destinationReg)) {
+ mask |= (1 << 31);
+ inst |= ((uint32_t)(ARM64_REG_IS_X(destinationReg)) << 31);
+ }
+ else if (!ARM64_REG_IS_ANY(sourceReg)) {
+ mask |= (1 << 31);
+ inst |= ((uint32_t)(ARM64_REG_IS_X(sourceReg)) << 31);
+ }
+
+ if (!ARM64_REG_IS_ANY(destinationReg)) {
+ mask |= 0x1F;
+ inst |= (uint32_t)(ARM64_REG_GET_NUM(destinationReg));
+ }
+ if (!ARM64_REG_IS_ANY(sourceReg)) {
+ mask |= (0x1F << 5);
+ inst |= ((uint32_t)(ARM64_REG_GET_NUM(destinationReg)) << 5);
+ }
+
+ if (OPT_UINT64_IS_SET(optImm)) {
+ uint64_t imm = OPT_UINT64_GET_VAL(optImm);
+ if (imm & ~0xFFF) return -1;
+ mask |= (0xFFF << 10);
+ inst |= (imm << 10);
+ }
+
+ if (bytesOut) *bytesOut = inst;
+ if (maskOut) *maskOut = mask;
+ return 0;
+}
+
+int arm64_dec_sub_imm(uint32_t inst, arm64_register *destinationRegOut, arm64_register *sourceRegOut, uint16_t *immOut, bool *sOut) {
+ if ((inst & 0x7f800000) != 0x51000000) {
+ if ((inst & 0x7f800000) != 0x71000000) {
+ return -1;
+ }
+ }
+ bool is64 = (inst & 0x80000000);
+ bool isS = (inst & 0x20000000);
+ bool shift = (inst & 0x400000);
+
+ if (destinationRegOut) {
+ *destinationRegOut = ARM64_REG(is64 ? ARM64_REG_TYPE_X : ARM64_REG_TYPE_W, inst & 0x1F);
+ }
+ if (sourceRegOut) {
+ *sourceRegOut = ARM64_REG(is64 ? ARM64_REG_TYPE_X : ARM64_REG_TYPE_W, (inst >> 5) & 0x1F);
+ }
+
+ if (immOut) {
+ uint16_t imm = ((inst >> 10) & 0xFFF);
+ if (shift) {
+ imm = (imm << 12);
+ }
+ *immOut = imm;
+ }
+
+ if (sOut) {
+ *sOut = isS;
+ }
+
+ return 0;
+}
+
+
static int _arm64_gen_str_ldr_imm(uint32_t inst, uint32_t mask, char type, arm64_ldr_str_type instType, arm64_register sourceDestinationReg, arm64_register addrReg, optional_uint64_t optImm, uint32_t *bytesOut, uint32_t *maskOut)
{
if (ARM64_REG_IS_ANY_VECTOR(addrReg)) return -1;
diff --git a/src/arm64.h b/src/arm64.h
index 6cc1329..5ad903b 100644
--- a/src/arm64.h
+++ b/src/arm64.h
@@ -85,6 +85,8 @@ int arm64_gen_mov_reg(arm64_register destinationReg, arm64_register sourceReg, u
int arm64_dec_mov_reg(uint32_t inst, arm64_register *destinationRegOut, arm64_register *sourceRegOut);
int arm64_gen_add_imm(arm64_register destinationReg, arm64_register sourceReg, optional_uint64_t optImm, uint32_t *bytesOut, uint32_t *maskOut);
int arm64_dec_add_imm(uint32_t inst, arm64_register *destinationRegOut, arm64_register *sourceRegOut, uint16_t *immOut);
+int arm64_gen_sub_imm(arm64_register destinationReg, arm64_register sourceReg, optional_uint64_t optImm, optional_bool optS, uint32_t *bytesOut, uint32_t *maskOut);
+int arm64_dec_sub_imm(uint32_t inst, arm64_register *destinationRegOut, arm64_register *sourceRegOut, uint16_t *immOut, bool *sOut);
int arm64_gen_ldr_imm(char type, arm64_ldr_str_type instType, arm64_register destinationReg, arm64_register addrReg, optional_uint64_t optImm, uint32_t *bytesOut, uint32_t *maskOut);
int arm64_dec_ldr_imm(uint32_t inst, arm64_register *destinationReg, arm64_register *addrReg, uint64_t *immOut, char *typeOut, arm64_ldr_str_type *instTypeOut);
int arm64_gen_ldrs_imm(char type, arm64_ldr_str_type instType, arm64_register destinationReg, arm64_register addrReg, optional_uint64_t optImm, uint32_t *bytesOut, uint32_t *maskOut);

diff --git a/src/MachOByteOrder.h b/src/MachOByteOrder.h
index 47f6f7d..56e28ea 100644
--- a/src/MachOByteOrder.h
+++ b/src/MachOByteOrder.h
@@ -3,6 +3,7 @@

#include <stdio.h>
#include <stdlib.h>
+#include <libkern/OSByteOrder.h>

// 8-bit integers needed for CodeDirectory
#define BIG_TO_HOST(n) _Generic((n), \
25 changes: 0 additions & 25 deletions build_patch/libkrw/tfp0.patch

This file was deleted.

35 changes: 35 additions & 0 deletions build_patch/xpf/xpf.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
diff --git a/.gitignore b/.gitignore
index 5793cf9..3e81e77 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,5 @@ xpf_test_ios
libxpf.dylib
libxpf_macos.dylib
/kernels
+
+.idea
\ No newline at end of file
diff --git a/src/xpf.c b/src/xpf.c
index c072aaf..f5ca33f 100644
--- a/src/xpf.c
+++ b/src/xpf.c
@@ -551,6 +551,7 @@ void xpf_stop(void)
if (gXPF.kernelPrelinkTextSection) pfsec_free(gXPF.kernelPrelinkTextSection);
if (gXPF.kernelBootdataInit) pfsec_free(gXPF.kernelBootdataInit);
if (gXPF.kernelPLKTextSection) pfsec_free(gXPF.kernelPLKTextSection);
+ if (gXPF.kernelPLKDataConstSection) pfsec_free(gXPF.kernelPLKDataConstSection);
if (gXPF.kernelInfoPlistSection) pfsec_free(gXPF.kernelInfoPlistSection);
if (gXPF.kernelContainer) fat_free(gXPF.kernelContainer);

diff --git a/src/xpf.h b/src/xpf.h
index fddae9c..30130e0 100644
--- a/src/xpf.h
+++ b/src/xpf.h
@@ -64,6 +64,7 @@ typedef struct s_XPF {
PFSection *kernelOSLogSection;
PFSection *kernelPrelinkTextSection;
PFSection *kernelPLKTextSection;
+ PFSection *kernelPLKDataConstSection;
PFSection *kernelBootdataInit;
PFSection *kernelAMFITextSection;
PFSection *kernelAMFIStringSection;
33 changes: 27 additions & 6 deletions makefiles/libkrw.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ ifeq (,$(findstring darwin,$(MEMO_TARGET)))
ifeq ($(shell [ "$(MEMO_CFVER)" -ge 1700 ] && echo 1),1)

STRAPPROJECTS += libkrw
LIBKRW_VERSION := 1.1.1
DEB_LIBKRW_V ?= $(LIBKRW_VERSION)-2
LIBKRW_VERSION := 1.1.2
LIBROOT_COMMIT := 102348f5e9360ad1f509ae4958bd3ca686347ee8
DEB_LIBKRW_V ?= $(LIBKRW_VERSION)

LIBKRW_SOVERSION := 0

libkrw-setup: setup
$(call GITHUB_ARCHIVE,Siguza,libkrw,$(LIBKRW_VERSION),$(LIBKRW_VERSION))
$(call GITHUB_ARCHIVE,Cryptiiiic,libkrw,$(LIBKRW_VERSION),v$(LIBKRW_VERSION))
$(call EXTRACT_TAR,libkrw-$(LIBKRW_VERSION).tar.gz,libkrw-$(LIBKRW_VERSION),libkrw)
$(call DO_PATCH,libkrw,libkrw,-p1)
$(call GITHUB_ARCHIVE,opa334,libroot,$(LIBROOT_COMMIT),$(LIBROOT_COMMIT),libroot)
$(call EXTRACT_TAR,libroot-$(LIBROOT_COMMIT).tar.gz,libroot-$(LIBROOT_COMMIT),libroot)
cp -a $(BUILD_WORK)/libroot $(BUILD_WORK)/libkrw/external
rm -rf $(BUILD_WORK)/libroot
mkdir -p $(BUILD_STAGE)/libkrw/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/{include,lib/libkrw}
sed -i 's|/usr/lib|$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/lib|g' $(BUILD_WORK)/libkrw/src/libkrw.c

ifneq ($(wildcard $(BUILD_WORK)/libkrw/.build_complete),)
libkrw:
Expand All @@ -25,15 +28,33 @@ else
libkrw: libkrw-setup
mkdir -p $(BUILD_WORK)/libkrw/src/.lib/

# libroot.o
if [ ! -z "$(findstring rootless,$(MEMO_TARGET))" ]; then \
$(CC) $(CFLAGS) \
-I$(BUILD_WORK)/libkrw/external/libroot/src \
-c -o $(BUILD_WORK)/libkrw/src/.lib/libroot.o \
-DIPHONEOS_ARM64 \
$(BUILD_WORK)/libkrw/external/libroot/src/dyn.c; \
else \
$(CC) $(CFLAGS) \
-I$(BUILD_WORK)/libkrw/external/libroot/src \
-c -o $(BUILD_WORK)/libkrw/src/.lib/libroot.o \
-DTARGET=libkrw \
$(BUILD_WORK)/libkrw/external/libroot/src/dyn.c; \
fi
# libkrw.o
$(CC) $(CFLAGS) \
-I$(BUILD_WORK)/libkrw/include \
-I$(BUILD_WORK)/libkrw/external/libroot/src \
-DTARGET="\"libkrw\"" \
-c -o $(BUILD_WORK)/libkrw/src/.lib/libkrw.o \
$(BUILD_WORK)/libkrw/src/libkrw.c

# libkrw_tfp0.o
$(CC) $(CFLAGS) \
-I$(BUILD_WORK)/libkrw/include \
-I$(BUILD_WORK)/libkrw/external/libroot/src \
-DTARGET="\"libkrw\"" \
-c -o $(BUILD_WORK)/libkrw/src/.lib/libkrw_tfp0.o \
$(BUILD_WORK)/libkrw/src/libkrw_tfp0.c

Expand All @@ -42,7 +63,7 @@ libkrw: libkrw-setup
-I$(BUILD_WORK)/libkrw/include \
-install_name "$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/lib/libkrw.$(LIBKRW_SOVERSION).dylib" \
-o $(BUILD_STAGE)/libkrw/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/lib/libkrw.$(LIBKRW_SOVERSION).dylib \
$(BUILD_WORK)/libkrw/src/.lib/libkrw.o \
$(BUILD_WORK)/libkrw/src/.lib/{libroot,libkrw}.o \
$(LDFLAGS)

# libkrw-tfp0.dylib
Expand Down
Loading