-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
@interface LibCHooks : NSObject { | ||
|
||
} | ||
|
||
+ (void)enableHooks; | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
#include <substrate.h> | ||
|
||
#import "LibCHooks.h" | ||
#import "../SQLiteStorage.h" | ||
#import "../PlistObjectConverter.h" | ||
#import "../CallStackInspector.h" | ||
|
||
// Nice global | ||
extern SQLiteStorage *traceStorage; | ||
|
||
|
||
// Hook rand() | ||
static int (*original_rand)(); | ||
|
||
static int replaced_rand() { | ||
|
||
int origResult = original_rand(); | ||
|
||
// Only log what the application directly calls. For example we don't want to log internal SSL crypto calls | ||
if ([CallStackInspector wasDirectlyCalledByApp]) { | ||
|
||
CallTracer *tracer = [[CallTracer alloc] initWithClass:@"C" andMethod:@"rand"]; | ||
[tracer addReturnValueFromPlistObject: [NSNumber numberWithUnsignedInt:origResult]]; | ||
[traceStorage saveTracedCall: tracer]; | ||
[tracer release]; | ||
} | ||
return origResult; | ||
} | ||
|
||
|
||
// Hook random() | ||
static long (*original_random)(); | ||
|
||
static long replaced_random() { | ||
|
||
long origResult = original_random(); | ||
|
||
// Only log what the application directly calls. For example we don't want to log internal SSL crypto calls | ||
if ([CallStackInspector wasDirectlyCalledByApp]) { | ||
|
||
CallTracer *tracer = [[CallTracer alloc] initWithClass:@"C" andMethod:@"random"]; | ||
[tracer addReturnValueFromPlistObject: [NSNumber numberWithUnsignedLong:origResult]]; | ||
[traceStorage saveTracedCall: tracer]; | ||
[tracer release]; | ||
} | ||
return origResult; | ||
} | ||
|
||
|
||
|
||
@implementation LibCHooks | ||
|
||
+ (void)enableHooks { | ||
MSHookFunction(random, replaced_random, (void **) &original_random); | ||
MSHookFunction(rand, replaced_rand, (void **) &original_rand); | ||
} | ||
|
||
@end |