Commits

Peter Hosey committed 3e357b3

Upgraded mach_star to boredzo/mach_star revision 866c69efc3f0f08c9dfcb69927668759d65d65c2.

Comments (0)

Files changed (5)

external_dependencies/mach_star/.github_commit_id

-b03c84bf53dceb7791a5c02d1fd41318364b6100
+866c69efc3f0f08c9dfcb69927668759d65d65c2

external_dependencies/mach_star/mach_inject/mach_inject.c

 	if( !err ) {
 		err = task_for_pid( mach_task_self(), targetProcess, &remoteTask );
 #if defined(__i386__) || defined(__x86_64__)
+		mach_error("mach_inject failing..", err);
 		if (err == 5) fprintf(stderr, "Could not access task for pid %d. You probably need to add user to procmod group\n", targetProcess);
 #endif
 	}
 			}
 #if defined(__i386__) // this segment is only available on IA-32
 			if (jumpTableOffset && jumpTableSize) {
-				const struct section * jumpTableSection = getsectbynamefromheader( header, SEG_IMPORT, "__jump_table" );
-				if (jumpTableSection) {
-					*jumpTableOffset = jumpTableSection->offset;
-					*jumpTableSize = jumpTableSection->size;
-				}
+			  const struct section * jumpTableSection = getsectbynamefromheader( header, SEG_IMPORT, "__jump_table" );
+
+			  if (!jumpTableSection) {
+			    unsigned char *start, *end;
+			    jumpTableSection = getsectbynamefromheader( header, SEG_TEXT, "__symbol_stub" );
+			    /*
+			    start = end = (char *) header + jumpTableSection->offset;
+			    end += jumpTableSection->size;
+
+			    fprintf(stderr, "start: %p\n", start);
+			    for (; start < end; start += 6) {
+			      fprintf(stderr, "%p: %p: %p\n",
+				      start,
+				      *(void **)(start+2),
+				      **(void ***)(start+2));
+			    }
+			    */
+			  }
+			  
+			  if (jumpTableSection) {
+			    *jumpTableOffset = jumpTableSection->offset;
+			    *jumpTableSize = jumpTableSection->size;
+			  }
 			}
 #endif
 			return err_none;
 	
 	// address of jump table in copied image
 	void *jumpTable = fixedUpImage + jumpTableOffset;
-	// each JMP instruction is 5 bytes (E9 xx xx xx xx) where E9 is the opcode for JMP
-	int jumpTableCount = jumpTableSize / 5;
+
 	
-	// skip first "E9"
-	jumpTable++;
+	/* indirect jump table */
+	if (*(unsigned char *) jumpTable == 0xff) {
+	  // each indirect JMP instruction is 6 bytes (FF xx xx xx xx xx) where FF is the opcode for JMP
+	  int jumpTableCount = jumpTableSize / 6;
 	
-	int entry=0;
-	for (entry = 0; entry < jumpTableCount; entry++) {
-		unsigned int jmpValue = *((unsigned int *)jumpTable);
-		jmpValue += fixUpOffset;
-		*((unsigned int *)jumpTable) = jmpValue;
-		jumpTable+=5;
+	  // skip first "ff xx"
+	  jumpTable += 2;
+	
+	  int entry=0;
+	  for (entry = 0; entry < jumpTableCount; entry++) {
+	    void *jmpValue = *((void **)jumpTable);
+	    /*
+	    fprintf(stderr, "at %p correcting %p to %p\n",
+		    (char *)jumpTable -2,
+		    jmpValue, jmpValue + fixUpOffset);
+	    */
+	    jmpValue -= fixUpOffset;
+	    *((void **)jumpTable) = jmpValue;
+	    jumpTable+=6;
+	  }
+	}
+	else {
+	  // each JMP instruction is 5 bytes (E9 xx xx xx xx) where E9 is the opcode for JMP
+	  int jumpTableCount = jumpTableSize / 5;
+	
+	  // skip first "E9"
+	  jumpTable++;
+	
+	  int entry=0;
+	  for (entry = 0; entry < jumpTableCount; entry++) {
+	    unsigned int jmpValue = *((unsigned int *)jumpTable);
+	    jmpValue += fixUpOffset;
+	    *((unsigned int *)jumpTable) = jmpValue;
+	    jumpTable+=5;
+	  }
 	}
 	
 	return fixedUpImage;

external_dependencies/mach_star/mach_inject_bundle/mach_inject_bundle.xcodeproj/project.pbxproj

 		33B2AC7C09285567004B1632 /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
+				SDKROOT = macosx10.5;
 			};
 			name = Debug;
 		};
 		33B2AC7D09285567004B1632 /* Release */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
+				SDKROOT = macosx10.5;
 			};
 			name = Release;
 		};
 		33B2AC7E09285567004B1632 /* Default */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
+				SDKROOT = macosx10.5;
 			};
 			name = Default;
 		};

external_dependencies/mach_star/mach_inject_bundle_stub/load_bundle.c

 	
 	printf("FS rep %s\n", bundleExecutableFileSystemRepresentation);
 	void *image = dlopen(bundleExecutableFileSystemRepresentation, RTLD_NOW);
-	printf("OH shit load? %p\n", image);
 	if (!image) {
 		dlerror();
 		return err_load_bundle_NSObjectFileImageFailure;

external_dependencies/mach_star/mach_inject_bundle_stub/mach_inject_bundle_stub.xcodeproj/project.pbxproj

 				GCC_ENABLE_FIX_AND_CONTINUE = NO;
 				GCC_ENABLE_TRIGRAPHS = NO;
 				GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
+				GCC_OPTIMIZATION_LEVEL = 0;
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = mach_inject_bundle_stub_Prefix.pch;
 				GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
 		33B2AC4F092854FB004B1632 /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
+				SDKROOT = macosx10.5;
 			};
 			name = Debug;
 		};
 		33B2AC50092854FB004B1632 /* Release */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
+				SDKROOT = macosx10.5;
 			};
 			name = Release;
 		};
 		33B2AC51092854FB004B1632 /* Default */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
+				SDKROOT = macosx10.5;
 			};
 			name = Default;
 		};