Skip to content

Commit

Permalink
Test (#134)
Browse files Browse the repository at this point in the history
Co-authored-by: opa334 <[email protected]>
  • Loading branch information
wwg135 and opa334 authored Aug 10, 2023
1 parent 5ecb44b commit 4b2acd8
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
echo -e "[点击当前版本下载](https://github.com/wwg135/Dopamine/releases/download/${{ env.msT }}/Dopamine.ipa)" >> body.txt
echo -e "\n更新时间:${{ env.logT }}" >> body.txt
echo -e "\n**当前更新日志如下:**" >> body.txt
echo -e "\n> - 1.同步官方正式版1.1.4更新\n> - 3.其他功能更新,请看前面版本更新说明" >> body.txt
echo -e "\n> - 1.同步官方最新代码更新\n> - 3.其他功能更新,请看前面版本更新说明" >> body.txt
- name: Build ipa
run: |
Expand Down
Binary file not shown.
93 changes: 89 additions & 4 deletions BaseBin/forkfix/src/litehook.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
#include "litehook.h"
#include <stdarg.h>
#include <stdbool.h>
#include <sys/types.h>
#include <string.h>
#include <sys/fcntl.h>
#include <mach/mach.h>
#include <mach/arm/kern_return.h>
#include <mach/port.h>
#include <mach/vm_prot.h>
#include <mach-o/dyld.h>
#include <dlfcn.h>
#include <libkern/OSCacheControl.h>

static uint64_t __attribute((naked)) __xpaci(uint64_t a)
{
Expand Down Expand Up @@ -45,9 +57,9 @@ uint32_t br(uint8_t x)

__attribute__((noinline, naked)) volatile kern_return_t litehook_vm_protect(mach_port_name_t target, mach_vm_address_t address, mach_vm_size_t size, boolean_t set_maximum, vm_prot_t new_protection)
{
__asm("mov x16, #0xFFFFFFFFFFFFFFF2");
__asm("svc 0x80");
__asm("ret");
__asm("mov x16, #0xFFFFFFFFFFFFFFF2");
__asm("svc 0x80");
__asm("ret");
}

kern_return_t litehook_unprotect(vm_address_t addr, vm_size_t size)
Expand All @@ -60,12 +72,78 @@ kern_return_t litehook_protect(vm_address_t addr, vm_size_t size)
return litehook_vm_protect(mach_task_self(), addr, size, false, VM_PROT_READ | VM_PROT_EXECUTE);
}

int _dyld_image_index_for_header(const void *header)
{
for (int i = 0; i < _dyld_image_count(); i++) {
const struct mach_header *checkHeader = _dyld_get_image_header(i);
if (header == checkHeader) {
return i;
}
}
return -1;
}

int getSectionBounds(const void *address, mach_vm_address_t *startOut, mach_vm_address_t *endOut) {
Dl_info info;
int dlr = dladdr((void *)address, &info);
if (dlr == 0) return 1;
const struct mach_header_64 *header = info.dli_fbase;

int imageIndex = _dyld_image_index_for_header(header);

if (header && imageIndex != -1) {
intptr_t slide = _dyld_get_image_vmaddr_slide(imageIndex);
uint64_t unslidAddress = ((uint64_t)address) - slide;

const struct segment_command_64 *segmentCmd = NULL;
uint32_t segmentCount = 0;
if (header->magic == MH_MAGIC || header->magic == MH_MAGIC_64) {
segmentCmd = (const struct segment_command_64 *)(((const char *)header) + sizeof(struct mach_header_64));
segmentCount = header->ncmds;
}

for (uint32_t i = 0; i < segmentCount; i++) {
if (segmentCmd->cmd == LC_SEGMENT || segmentCmd->cmd == LC_SEGMENT_64) {
if (unslidAddress >= segmentCmd->vmaddr &&
unslidAddress < segmentCmd->vmaddr + segmentCmd->vmsize) {
mach_vm_address_t subsectionStart = segmentCmd->vmaddr + slide;
mach_vm_address_t subsectionEnd = segmentCmd->vmsize;
*startOut = subsectionStart;
*endOut = subsectionEnd;
return 0;
}
}
segmentCmd = (const struct segment_command_64 *)(((const char *)segmentCmd) + segmentCmd->cmdsize);
}
}

return 1;
}

kern_return_t litehook_hook_function(void *source, void *target)
{
kern_return_t kr = KERN_SUCCESS;

mach_vm_address_t regionStart = 0;
mach_vm_address_t regionSize = 0;
int suc = getSectionBounds(source, &regionStart, &regionSize);
if (suc != 0) return suc;

vm_address_t preWarmAllocation = 0;
kr = vm_allocate(mach_task_self_, &preWarmAllocation, regionSize*2, VM_FLAGS_ANYWHERE);
if (kr != KERN_SUCCESS) return kr;
vm_address_t preWarmAllocationEnd = preWarmAllocation + (regionSize*2);
for (vm_address_t page = preWarmAllocation; page < preWarmAllocationEnd; page += PAGE_SIZE) {
// page in
*((volatile uint64_t *)page);
}
kr = vm_deallocate(mach_task_self_, preWarmAllocation, regionSize*2);
if (kr != KERN_SUCCESS) return kr;

uint32_t *toHook = (uint32_t*)xpaci((uint64_t)source);
uint64_t target64 = (uint64_t)xpaci((uint64_t)target);

kern_return_t kr = litehook_unprotect((vm_address_t)toHook, 5*4);
kr = litehook_unprotect((vm_address_t)toHook, 5*4);
if (kr != KERN_SUCCESS) return kr;

toHook[0] = movk(16, target64 >> 0, 0);
Expand All @@ -77,5 +155,12 @@ kern_return_t litehook_hook_function(void *source, void *target)
kr = litehook_protect((vm_address_t)toHook, 5*4);
if (kr != KERN_SUCCESS) return kr;

sys_icache_invalidate(source, VM_PAGE_SIZE);

for (mach_vm_address_t page = regionStart; page < regionSize; page += PAGE_SIZE) {
// page in
*((volatile uint64_t *)page);
}

return KERN_SUCCESS;
}
14 changes: 7 additions & 7 deletions BaseBin/libjailbreak/src/handoff.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ void pmap_alloc_page_for_ppl(unsigned int options)
}

kern_return_t pmap_enter_options_addr(uint64_t pmap, uint64_t pa, uint64_t va) {
while (1) {
kern_return_t kr = (kern_return_t)kcall8(bootInfo_getSlidUInt64(@"pmap_enter_options_addr"), pmap, va, pa, VM_PROT_READ | VM_PROT_WRITE, 0, 0, 1, 1);
if (kr != KERN_RESOURCE_SHORTAGE) {
return kr;
}
while (1) {
kern_return_t kr = (kern_return_t)kcall8(bootInfo_getSlidUInt64(@"pmap_enter_options_addr"), pmap, va, pa, VM_PROT_READ | VM_PROT_WRITE, 0, 0, 1, 1);
if (kr != KERN_RESOURCE_SHORTAGE) {
return kr;
}
else {
// On resource shortage, alloc new page
pmap_alloc_page_for_ppl(0);
}
}
}
}

void pmap_remove(uint64_t pmap, uint64_t start, uint64_t end) {
kcall8(bootInfo_getSlidUInt64(@"pmap_remove_options"), pmap, start, end, 0x100, 0, 0, 0, 0);
kcall8(bootInfo_getSlidUInt64(@"pmap_remove_options"), pmap, start, end, 0x100, 0, 0, 0, 0);
}

int pmap_map_in(uint64_t pmap, uint64_t ua, uint64_t pa, uint64_t size)
Expand Down
4 changes: 4 additions & 0 deletions BaseBin/systemhook/src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ kBinaryConfig configForBinary(const char* path, char *const argv[restrict])
// Skip ReportCrash too as it might need to execute while jailbreakd is in a crashed state
return (kBinaryConfigDontInject | kBinaryConfigDontProcess);
}
else if (!strcmp(argv[1], "com.apple.ReportMemoryException")) {
// Skip ReportMemoryException too as it might need to execute while jailbreakd is in a crashed state
return (kBinaryConfigDontInject | kBinaryConfigDontProcess);
}
}
}
}
Expand Down
114 changes: 60 additions & 54 deletions Dopamine/Dopamine/UI/Views/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ struct SettingsView: View {
}
}
if isJailbroken() {
Toggle("Options_Enble_Bottom_Forbid_Unject", isOn: $bottomforbidUnject)
.onChange(of: bottomforbidUnject) { newValue in
changBoolean(newValue)
}
if forbidUnject {
Toggle("Options_Enble_Bottom_Forbid_Unject", isOn: $bottomforbidUnject)
.onChange(of: bottomforbidUnject) { newValue in
changBoolean(newValue)
}
}
}
if !isJailbroken() {
Toggle("Options_bridgeToXinA", isOn: $bridgeToXinA)
Expand All @@ -81,60 +83,64 @@ struct SettingsView: View {
if isBootstrapped() {
VStack {
if isJailbroken() {
Button(action: {
UIImpactFeedbackGenerator(style: .light).impactOccurred()
customforbidunjectAlertShown = true
}) {
HStack {
Image(systemName: "eye")
Text("Options_Custom_Forbid_Unject")
.lineLimit(1)
.minimumScaleFactor(0.5)
if bottomforbidUnject {
Button(action: {
UIImpactFeedbackGenerator(style: .light).impactOccurred()
customforbidunjectAlertShown = true
}) {
HStack {
Image(systemName: "eye")
Text("Options_Custom_Forbid_Unject")
.lineLimit(1)
.minimumScaleFactor(0.5)
}
.padding(.horizontal, 4)
.padding(8)
.frame(maxWidth: .infinity)
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(Color.white.opacity(0.25), lineWidth: 0.5)
)
}
.padding(.horizontal, 4)
.padding(8)
.frame(maxWidth: .infinity)
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(Color.white.opacity(0.25), lineWidth: 0.5)
)
}
Button(action: {
UIImpactFeedbackGenerator(style: .light).impactOccurred()
mountPathAlertShown = true
}) {
HStack {
Image(systemName: "mappin.circle")
Text("Button_Set_Mount_Path")
.lineLimit(1)
.minimumScaleFactor(0.5)
if enableMount {
Button(action: {
UIImpactFeedbackGenerator(style: .light).impactOccurred()
mountPathAlertShown = true
}) {
HStack {
Image(systemName: "mappin.circle")
Text("Button_Set_Mount_Path")
.lineLimit(1)
.minimumScaleFactor(0.5)
}
.padding(.horizontal, 4)
.padding(8)
.frame(maxWidth: .infinity)
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(Color.white.opacity(0.25), lineWidth: 0.5)
)
}
Button(action: {
UIImpactFeedbackGenerator(style: .light).impactOccurred()
removeZmountAlertShown = true
}) {
HStack {
Image(systemName: "mappin.slash.circle")
Text("Button_Remove_Zmount")
.lineLimit(1)
.minimumScaleFactor(0.5)
}
.padding(.horizontal, 4)
.padding(8)
.frame(maxWidth: .infinity)
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(Color.white.opacity(0.25), lineWidth: 0.5)
)
}
.padding(.horizontal, 4)
.padding(8)
.frame(maxWidth: .infinity)
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(Color.white.opacity(0.25), lineWidth: 0.5)
)
}
}
Button(action: {
UIImpactFeedbackGenerator(style: .light).impactOccurred()
removeZmountAlertShown = true
}) {
HStack {
Image(systemName: "mappin.slash.circle")
Text("Button_Remove_Zmount")
.lineLimit(1)
.minimumScaleFactor(0.5)
}
.padding(.horizontal, 4)
.padding(8)
.frame(maxWidth: .infinity)
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(Color.white.opacity(0.25), lineWidth: 0.5)
)
}
if isJailbroken() {
Button(action: {
Expand Down

0 comments on commit 4b2acd8

Please sign in to comment.