1 | #include <mach/mach_init.h>
|
---|
2 | extern "C"
|
---|
3 | {
|
---|
4 | #include <mach/thread_act.h>
|
---|
5 | #include <pthread.h>
|
---|
6 | #include <unistd.h>
|
---|
7 | }
|
---|
8 |
|
---|
9 | #include <Carbon/Carbon.h>
|
---|
10 | #include "mach_inject.h"
|
---|
11 | #include "SCPatchClient.h"
|
---|
12 |
|
---|
13 | #ifdef __MWERKS__
|
---|
14 | #pragma export on
|
---|
15 | #endif
|
---|
16 |
|
---|
17 | //-------------------------------------------------------------------------------------------------------------
|
---|
18 | mach_error_t SCPatchInit( SCPatchParams *params )
|
---|
19 | {
|
---|
20 | ProcessSerialNumber psn;
|
---|
21 | mach_error_t err = err_none;
|
---|
22 | SCPatchClient *client = SCPatchClient::GetPatchClientPointer();
|
---|
23 |
|
---|
24 | if(client == NULL)
|
---|
25 | {
|
---|
26 | fprintf(stderr, "SCPc: sGlobalPatchClientInstance is not set!\n");
|
---|
27 | return err_sub(EFAULT);
|
---|
28 | }
|
---|
29 |
|
---|
30 | client->mPatchParams = *params;
|
---|
31 | client->mClientBundleID = CFStringCreateWithCharacters(NULL, params->patchBundleID.unicode, params->patchBundleID.length);
|
---|
32 | client->mControllerBundleID = CFStringCreateWithCharacters(NULL, client->mPatchParams.parentBundleID.unicode, client->mPatchParams.parentBundleID.length);
|
---|
33 |
|
---|
34 | // Just in case
|
---|
35 | if(client->mClientBundleID == NULL || client->mControllerBundleID == NULL)
|
---|
36 | return err_sub(ENOMEM);
|
---|
37 |
|
---|
38 | if(client->Initialize(client->mClientBundleID, client->mControllerBundleID, getpid()) != noErr)
|
---|
39 | return err_threadEntry_image_not_found;
|
---|
40 |
|
---|
41 | // Create a port to receive messages from our patch controller
|
---|
42 | if((err = client->StartListening(client->mClientBundleID, true, true)) != noErr)
|
---|
43 | return err_threadEntry_image_not_found;
|
---|
44 |
|
---|
45 | if((err = GetCurrentProcess(&psn)) != noErr ||
|
---|
46 | (err = client->SendMessage(client->mControllerBundleID, NULL, kSCMessageClass, kSCPatchSuccess,
|
---|
47 | "bndl: TEXT(@), proc: psn (@)",
|
---|
48 | CFStringGetCStringPtr(client->mClientBundleID, kCFStringEncodingMacRoman),
|
---|
49 | sizeof(ProcessSerialNumber), &psn)) != noErr)
|
---|
50 | return err_threadEntry_image_not_found;
|
---|
51 |
|
---|
52 | return noErr;
|
---|
53 | }
|
---|
54 | #ifdef __MWERKS__
|
---|
55 | #pragma export off
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | //-------------------------------------------------------------------------------------------------------------
|
---|
59 | SCPatchClient::SCPatchClient(void)
|
---|
60 | {
|
---|
61 | }
|
---|
62 |
|
---|
63 | //-------------------------------------------------------------------------------------------------------------
|
---|
64 | SCPatchClient::~SCPatchClient(void)
|
---|
65 | {
|
---|
66 | }
|
---|