1 | #pragma once
|
---|
2 |
|
---|
3 | #include <Carbon/Carbon.h>
|
---|
4 | #include <list.h>
|
---|
5 |
|
---|
6 | #include "SCPatchPrivate.h"
|
---|
7 | #include "SCPatchContext.h"
|
---|
8 | #include "SCPatchRecord.h"
|
---|
9 | #include "SCPatchMessenger.h"
|
---|
10 |
|
---|
11 | // Mac to Mach error morphing.
|
---|
12 | #define err_mac err_system(0xf) /* Mac (Carbon) errors */
|
---|
13 | #define mac_err(CODE) SCmac_err_FromOSErr((CODE))
|
---|
14 | #define oserr(CODE) SCOSErrFrom_mac_err((CODE))
|
---|
15 | mach_error_t SCmac_err_FromOSErr(OSErr err);
|
---|
16 | OSErr SCOSErrFrom_mac_err(mach_error_t error);
|
---|
17 |
|
---|
18 | typedef OSErr (*SCPatchIterationProc)(ProcessSerialNumber *inPSN, OSType inCreator, UInt32 inFlags, void *data);
|
---|
19 |
|
---|
20 | class SCPatchController : public SCPatchMessenger
|
---|
21 | {
|
---|
22 | public:
|
---|
23 |
|
---|
24 | SCPatchController(void);
|
---|
25 | SCPatchController(CFStringRef bundleIdentifier);
|
---|
26 | ~SCPatchController(void);
|
---|
27 |
|
---|
28 | // Use these to tell the controller where to find the patches
|
---|
29 | void AddPatch(CFStringRef patchBundleIdentifier,
|
---|
30 | CFStringRef subPath,
|
---|
31 | CFStringRef name);
|
---|
32 |
|
---|
33 | // Inject the patches into running applications and start watching app launches
|
---|
34 | OSErr InstallPatches(void);
|
---|
35 |
|
---|
36 | // Patch a single process (ignoring return value of ShouldPatchProcess)
|
---|
37 | mach_error_t PatchProcess(ProcessSerialNumber *psn);
|
---|
38 |
|
---|
39 | // Overload these to customize patch loading and notification (note that
|
---|
40 | // UnpatchNotification is only called when the process dies, since the patches
|
---|
41 | // are not removable).
|
---|
42 | virtual Boolean ShouldPatchProcess(ProcessSerialNumber * /* inPSN */,
|
---|
43 | OSType /* inCreator */, OSType /* type */,
|
---|
44 | CFStringRef /* name */, UInt32 /* flags */) { return false; }
|
---|
45 | virtual void PatchNotification(ProcessSerialNumber * /* inPSN */,
|
---|
46 | OSType /* inCreator */, OSType /* type */,
|
---|
47 | CFStringRef /* name */, UInt32 /* flags */) {}
|
---|
48 | virtual void UnpatchNotification(ProcessSerialNumber * /* inPSN */,
|
---|
49 | OSType /* inCreator */, OSType /* type */,
|
---|
50 | CFStringRef /* name */, UInt32 /* flags */) {}
|
---|
51 |
|
---|
52 | // You must also overload this method in SCPatchMessenger to receive messages.
|
---|
53 | // virtual void ReceiveMessage(const AppleEvent *theAE) = 0;
|
---|
54 |
|
---|
55 | // Get info and keep tabs on patched processes
|
---|
56 | Boolean IsProcessPatched(ProcessSerialNumber *inPSN);
|
---|
57 | UInt32 GetPatchFlags(ProcessSerialNumber *inPSN);
|
---|
58 | void SetPatchFlags(ProcessSerialNumber *inPSN, UInt32 flags, UInt32 whichFlags);
|
---|
59 |
|
---|
60 | // Loop through each patched process and execute a function. Note that this will
|
---|
61 | // not recognize patched processes until after you've called IsProcessPatched() on
|
---|
62 | // them or called InstallPatches() (which calls IsProcessPatched on every process).
|
---|
63 | OSErr ForEachPatchedProcess(SCPatchIterationProc proc, void *data);
|
---|
64 |
|
---|
65 | private:
|
---|
66 | CFBundleRef mBundle;
|
---|
67 | CFStringRef mApplicationBundleIdentifier;
|
---|
68 |
|
---|
69 | private:
|
---|
70 | list<SCPatchRecord> mPatchList;
|
---|
71 | SCPatchContextList mPatchContextList;
|
---|
72 |
|
---|
73 |
|
---|
74 | OSErr HandleMessage(const AppleEvent *theAE);
|
---|
75 | static pascal OSStatus ApplicationEventHandler(EventHandlerCallRef handlerRef,
|
---|
76 | EventRef event, void *userData);
|
---|
77 |
|
---|
78 | mach_error_t InstallPatchesInProcess(ProcessSerialNumber *psn, bool onDemand=false);
|
---|
79 | OSErr AddPatchToParams(CFStringRef bundleID, CFURLRef url, SCPatchLoaderParams **params);
|
---|
80 | mach_error_t InjectPatches(ProcessSerialNumber *psn, SCPatchLoaderParams *params);
|
---|
81 | OSErr RecordPatchAndNotify(ProcessSerialNumber *psn, ProcessInfoRec *info);
|
---|
82 |
|
---|
83 | }; |
---|