Fixing Bugs

When you do not have the source code

After a complete system lockup, my computer booted back up to reveal that hours logged in TrackRecord for the day were nowhere to be found. Solution? Fix it, of course! Resolving these kinds of bugs usually require the source code to the application. Unfortunately, I do not have access to the TrackRecord codebase, but the fantastic SIMBL library streamlines injecting your own code into an existing binary.

The first step was to determine what methods were exposed in the application. Running class-dump on the binary revealed some interesting methods. Most importantly, a saveAction: method in the AppDelegate class. I whipped up a quick SIMBL extension class that would confirm that saveAction would, in fact, save the data.

	
@implementation TRPeriodicSave

- (void)startTimer
{
	[NSTimer scheduledTimerWithTimeInterval:10.0 target:self
		selector:@selector(performSave:) userInfo:nil repeats:YES];
}

- (void)performSave:(NSTimer *)aTimer
{
    [[[NSApplication sharedApplication] delegate] saveAction:self];
}

@end
	

Success! The injected code worked like a charm. I could have stopped there, but not to be outdone, I decided that the data should only be saved while the timers are active. Going back to the class-dump results, I noticed a controller which exposed a toggleTimer: method. I extended my extension to see if it did as the name implied.

By extending the NSObject of which the aforementioned controller was inherited from, I was able to swizzle the existing toggleTimer method with my own.

    	
    @implementation NSObject (TRPeriodicSave)

    - (void)TRPeriodicSave_toggleTimer:(id)arg1
    {
        NSLog(@"Timer was toggled");
        [self TRPeriodicSave_toggleTimer:arg1];
    }

    @end
    	
    

I quickly launched the application and pull up Console. I was pleased to find that the toggle was called on each start and stop of the timers. The final step was tying up the lose ends and putting it all together. You can find the project in its entirety on its GitHub project page.