Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mach_override.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrentzsch <jwr.git@redshed.net>2011-09-22 06:37:48 +0400
committerrentzsch <jwr.git@redshed.net>2011-09-22 06:37:48 +0400
commite0a5b11f8a0412c7cac80200849190c2d7f7d9fc (patch)
treee251ca4c7edf2c62d0a7abe7ce86428c85a8aa6f
parent23155cb2048ecdf61bb6461440859319f45b6684 (diff)
parentb655ca13070f32ef74b86d9f071cfce7619da415 (diff)
Merge pull request #18 from albertz/mach_star
--- Some cleanup (better suited for production use). Some additions. Also to stderr instead of stdout. Not sure if you want to merge this (or how you think about such changes). Those are just my changes I have laying around here. I think I also will comment out my additions later on (because it works good now for me) and maybe you want to wait for that before merging.
-rw-r--r--mach_inject/mach_inject.c10
-rw-r--r--mach_inject_bundle_stub/load_bundle.c33
-rw-r--r--mach_inject_bundle_stub/mach_inject_bundle_stub.c9
3 files changed, 37 insertions, 15 deletions
diff --git a/mach_inject/mach_inject.c b/mach_inject/mach_inject.c
index f0e0c29..9c021c6 100644
--- a/mach_inject/mach_inject.c
+++ b/mach_inject/mach_inject.c
@@ -37,6 +37,9 @@ void* fixedUpImageFromImage (
ptrdiff_t fixUpOffset);
#endif /* __i386__ */
+#include <mach/MACH_ERROR.h>
+#define MACH_ERROR(msg, err) { if(err != err_none) mach_error(msg, err); }
+
/*******************************************************************************
*
* Interface
@@ -63,6 +66,7 @@ mach_inject(
unsigned int jumpTableOffset;
unsigned int jumpTableSize;
mach_error_t err = machImageForPointer( threadEntry, &image, &imageSize, &jumpTableOffset, &jumpTableSize );
+ //fprintf(stderr, "mach_inject: found threadEntry image at: %p with size: %lu\n", image, imageSize);
// Initialize stackSize to default if requested.
if( stackSize == 0 )
@@ -76,7 +80,6 @@ mach_inject(
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
}
@@ -271,6 +274,7 @@ mach_inject(
#endif
if( err ) {
+ MACH_ERROR("mach_inject failing..", err);
if( remoteParamBlock )
vm_deallocate( remoteTask, remoteParamBlock, paramSize );
if( remoteCode )
@@ -278,9 +282,7 @@ mach_inject(
if( remoteStack )
vm_deallocate( remoteTask, remoteStack, stackSize );
}
-
- printf("mach inject done? %d\n", err);
-
+
return err;
}
diff --git a/mach_inject_bundle_stub/load_bundle.c b/mach_inject_bundle_stub/load_bundle.c
index 14039af..007b0dd 100644
--- a/mach_inject_bundle_stub/load_bundle.c
+++ b/mach_inject_bundle_stub/load_bundle.c
@@ -11,16 +11,19 @@
#include <mach-o/dyld.h>
#include <dlfcn.h>
+#include <mach/MACH_ERROR.h>
+#define MACH_ERROR(msg, err) { if(err != err_none) mach_error(msg, err); }
+
mach_error_t
load_bundle_package(
const char *bundlePackageFileSystemRepresentation )
{
- printf("LBP\n");
+ fprintf(stderr, "mach_inject_bundle load_bundle_package: %s\n", bundlePackageFileSystemRepresentation);
assert( bundlePackageFileSystemRepresentation );
assert( strlen( bundlePackageFileSystemRepresentation ) );
mach_error_t err = err_none;
- mach_error("mach error on bundle load", err);
+ MACH_ERROR("mach error on bundle load", err);
// Morph the FSR into a URL.
CFURLRef bundlePackageURL = NULL;
@@ -33,7 +36,7 @@ load_bundle_package(
if( bundlePackageURL == NULL )
err = err_load_bundle_url_from_path;
}
- mach_error("mach error on bundle load", err);
+ MACH_ERROR("mach error on bundle load", err);
// Create bundle.
CFBundleRef bundle = NULL;
@@ -42,7 +45,7 @@ load_bundle_package(
if( bundle == NULL )
err = err_load_bundle_create_bundle;
}
- mach_error("mach error on bundle load", err);
+ MACH_ERROR("mach error on bundle load", err);
// Discover the bundle's executable file.
CFURLRef bundleExecutableURL = NULL;
@@ -52,7 +55,7 @@ load_bundle_package(
if( bundleExecutableURL == NULL )
err = err_load_bundle_package_executable_url;
}
- mach_error("mach error on bundle load", err);
+ MACH_ERROR("mach error on bundle load", err);
// Morph the executable's URL into an FSR.
char bundleExecutableFileSystemRepresentation[PATH_MAX];
@@ -67,7 +70,7 @@ load_bundle_package(
err = err_load_bundle_path_from_url;
}
}
- mach_error("mach error on bundle load", err);
+ MACH_ERROR("mach error on bundle load", err);
// Do the real work.
if( !err ) {
@@ -83,7 +86,7 @@ load_bundle_package(
if( bundlePackageURL )
CFRelease( bundlePackageURL );
- mach_error("mach error on bundle load", err);
+ MACH_ERROR("mach error on bundle load", err);
return err;
}
@@ -92,13 +95,25 @@ load_bundle_executable(
const char *bundleExecutableFileSystemRepresentation )
{
assert( bundleExecutableFileSystemRepresentation );
+
+ /*
+ NSBundle* bundle = [NSBundle bundleWithPath:[NSString stringWithUTF8String:bundleExecutableFileSystemRepresentation]];
+
+ if(![bundle load]) {
+ fprintf(stderr, "mach_inject: failed to load %s\n", bundleExecutableFileSystemRepresentation);
+ return err_load_bundle_NSObjectFileImageFailure;
+ }
+ else
+ fprintf(stderr, "mach_inject: loaded succesfull: %s\n", bundleExecutableFileSystemRepresentation);
+ */
- printf("FS rep %s\n", bundleExecutableFileSystemRepresentation);
+ //fprintf(stderr, "FS rep %s\n", bundleExecutableFileSystemRepresentation);
void *image = dlopen(bundleExecutableFileSystemRepresentation, RTLD_NOW);
- printf("OH shit load? %p\n", image);
+ //fprintf(stderr, "OH shit load? %p\n", image);
if (!image) {
dlerror();
return err_load_bundle_NSObjectFileImageFailure;
}
+
return 0;
} \ No newline at end of file
diff --git a/mach_inject_bundle_stub/mach_inject_bundle_stub.c b/mach_inject_bundle_stub/mach_inject_bundle_stub.c
index 60ee56e..9de382c 100644
--- a/mach_inject_bundle_stub/mach_inject_bundle_stub.c
+++ b/mach_inject_bundle_stub/mach_inject_bundle_stub.c
@@ -68,7 +68,10 @@ INJECT_ENTRY(
extern void __pthread_set_self(char*);
__pthread_set_self(dummy_pthread_struct);
#endif
-
+
+ fprintf(stderr, "mach_inject_bundle: entered in %s, codeOffset: %td, param: %p, paramSize: %lu\n",
+ INJECT_ENTRY_SYMBOL, codeOffset, param, paramSize);
+
pthread_attr_t attr;
pthread_attr_init(&attr);
@@ -95,6 +98,7 @@ INJECT_ENTRY(
pthread_entry(
mach_inject_bundle_stub_param *param )
{
+ fprintf(stderr, "mach_inject_bundle: entered in pthread_entry, param: %p\n", param);
assert( param );
EventLoopTimerProcPtr proc = (EventLoopTimerProcPtr) EventLoopTimerEntry;
@@ -111,7 +115,8 @@ EventLoopTimerEntry(
EventLoopTimerRef inTimer,
mach_inject_bundle_stub_param *param )
{
+ fprintf(stderr, "mach_inject_bundle: entered in EventLoopTimerEntry, inTimer: %p, param: %p\n", inTimer, param);
assert( inTimer );
assert( param );
load_bundle_package( param->bundlePackageFileSystemRepresentation );
-} \ No newline at end of file
+}