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

Mach_Error 4 Occurring When Attempting Injection #21

Open
ELCHILEN0 opened this issue Oct 8, 2011 · 1 comment
Open

Mach_Error 4 Occurring When Attempting Injection #21

ELCHILEN0 opened this issue Oct 8, 2011 · 1 comment

Comments

@ELCHILEN0
Copy link

Hello,
I am trying to inject a bundle into a certain process. I have created a new Xcode Project which solely handles the injection. I added the necessary frameworks and project files to the app. And have also added an "injectee" bundle to the project. I feel that everything that I am doing is right however I keep occurring with the messages in the log:

mach_inject failing.. (os/kern) successful
mach inject done? 4
MyApp[34807:c07] Failure code 4

Here is my relevant code:

  • (void)injectBundleWithPath:(NSString *)bundlePath intoProcess:(pid_t)pid
    {
    if ([bundlePath isAbsolutePath] == 0) {
    bundlePath = [[[[NSFileManager defaultManager] currentDirectoryPath] stringByAppendingPathComponent:bundlePath] stringByStandardizingPath];
    }
    mach_error_t err = mach_inject_bundle_pid([bundlePath fileSystemRepresentation], pid);
    if (err != err_none)
    NSLog(@"Failure code %x", err);
    }
  • (void)injectBundle:(id)sender {
    NSString *bundlePath = [[NSBundle mainBundle]
    pathForResource:@"Injectee" ofType:@"bundle"];
    pid_t pid = GetPidByBundleIdentifier(@"com.bundle.identifier");
    [self injectBundleWithPath:bundlePath intoProcess:pid];
    }

I am not sure why this error is happening and was wondering if other users have experienced the same thing. Thanks.

@albertz
Copy link
Contributor

albertz commented Oct 9, 2011

You could step through mach_inject and see at what line it fails exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants