/
Injector.m
96 lines (79 loc) · 3.46 KB
/
Injector.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#define FRAMEWORK_PATH_CONFIG_FILE @"~/.fscript-framework-location"
@interface FScriptMenuItem : NSObject { }
-(id)alloc;
-(void) insertInMainMenu;
- (IBAction)openObjectBrowser:(id)sender;
- (IBAction)showConsole:(id)sender;
- (IBAction)showPreferencePanel:(id)sender;
@end
static bool gInitialized = false;
OSErr HandleInjectionEvent(const AppleEvent *ev, AppleEvent *reply, long refcon) {
@autoreleasepool {
NSLog(@"F-Script Injector: got injection request inside %@", [[NSBundle mainBundle] executablePath]);
NSString* frameworkLocation = [NSString stringWithContentsOfFile:[FRAMEWORK_PATH_CONFIG_FILE stringByStandardizingPath] encoding:NSUTF8StringEncoding error:NULL];
if (!frameworkLocation) {
frameworkLocation = @"/Library/Frameworks/FScript.framework";
}
NSLog(@"F-Script Injector: injecting FScript.framework located at %@", frameworkLocation);
if (![[NSBundle bundleWithPath:frameworkLocation] load]) {
NSLog(@"F-Script Injector: unable to load FScript.framework, please check framework presence and proper rights at %@", frameworkLocation);
return 1;
}
FScriptMenuItem* item = (FScriptMenuItem*)NSClassFromString(@"FScriptMenuItem");
if (!item) {
NSLog(@"F-Script Injector: unable to retrieve FScriptMenuItem");
return 2;
}
[item insertInMainMenu];
gInitialized = true;
}
return 0;
}
OSErr HandleShowConsoleEvent(const AppleEvent *ev, AppleEvent *reply, long refcon) {
@autoreleasepool {
NSLog(@"F-Script Injector: got showConsole request inside %@", [[NSBundle mainBundle] executablePath]);
if (!gInitialized) {
NSLog(@"F-Script Injector: inject FScript.framework first via BAFSinjc event (see https://github.com/binaryage/fscript-osax)");
return 1;
}
FScriptMenuItem* item = (FScriptMenuItem*)NSClassFromString(@"FScriptMenuItem");
if (!item) {
NSLog(@"F-Script Injector: unable to retrieve FScriptMenuItem");
return 2;
}
[[[[item alloc] init] autorelease] showConsole:nil];
}
return 0;
}
OSErr HandleOpenObjectBrowserEvent(const AppleEvent *ev, AppleEvent *reply, long refcon) {
@autoreleasepool {
NSLog(@"F-Script Injector: got openObjectBrowser request inside %@", [[NSBundle mainBundle] executablePath]);
if (!gInitialized) {
NSLog(@"F-Script Injector: inject FScript.framework first via BAFSinjc event (see https://github.com/binaryage/fscript-osax)");
return 1;
}
FScriptMenuItem* item = (FScriptMenuItem*)NSClassFromString(@"FScriptMenuItem");
if (!item) {
NSLog(@"F-Script Injector: unable to retrieve FScriptMenuItem");
return 2;
}
[[[[item alloc] init] autorelease] openObjectBrowser:nil];
}
return 0;
}
OSErr HandleShowPreferencePanelEvent(const AppleEvent *ev, AppleEvent *reply, long refcon) {
@autoreleasepool {
NSLog(@"F-Script Injector: got showPreferencePanel request inside %@", [[NSBundle mainBundle] executablePath]);
if (!gInitialized) {
NSLog(@"F-Script Injector: inject FScript.framework first via BAFSinjc event (see https://github.com/binaryage/fscript-osax)");
return 1;
}
FScriptMenuItem* item = (FScriptMenuItem*)NSClassFromString(@"FScriptMenuItem");
if (!item) {
NSLog(@"F-Script Injector: unable to retrieve FScriptMenuItem");
return 2;
}
[[[[item alloc] init] autorelease] showPreferencePanel:nil];
}
return 0;
}