Skip to content

Commit c53969c

Browse files
committed
Delay locating Finder process up to 5 seconds before injection
When installed as a LuanchAngent, injector could run before Finder is up. If so, resulting pid will be 0, leaving the actual injection not performed. As a remedy, limited delay checks are applied to ensure that Finder pid is correctly located.
1 parent d2984f5 commit c53969c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

source/main.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ int main( int argc, char* argv[] )
3535
ProcessSerialNumber psn; FindProcessBySignature( 'FNDR', 'MACS', &psn );
3636
pid_t pid; GetProcessPID( &psn, &pid );
3737

38+
int retry = 5;
39+
while (!pid && retry--)
40+
{
41+
[NSThread sleepForTimeInterval:1.0f];
42+
FindProcessBySignature( 'FNDR', 'MACS', &psn );
43+
GetProcessPID( &psn, &pid );
44+
}
45+
if (!pid)
46+
{
47+
NSLog(@"missing target");
48+
[pool release];
49+
return -1;
50+
}
51+
3852
NSString* bundlePath = [NSString stringWithCString:argv[1] encoding:NSASCIIStringEncoding];
3953
NSString* stubPath = [NSString stringWithCString:argv[2] encoding:NSASCIIStringEncoding];
4054

0 commit comments

Comments
 (0)