-
-
Save karajanyp/285525aecfb71e83802d4bf1d6a33562 to your computer and use it in GitHub Desktop.
Hooking a variadic function with Cydia Substrate
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
// | |
// LibC.m | |
// | |
// Created by Alban Diquet on 5/14/14. | |
// Copyright (c) 2014 Alban Diquet. All rights reserved. | |
// | |
#import <CydiaSubstrate.h> | |
#import "LibC.h" | |
// Hook open() to catch the path of all files being accessed | |
static int (*original_open)(const char *path, int oflag, ...); | |
static int replaced_open(const char *path, int oflag, ...) { | |
int result = 0; | |
// Handle the optional third argument | |
if (oflag & O_CREAT) { | |
mode_t mode; | |
va_list args; | |
va_start(args, oflag); | |
mode = (mode_t)va_arg(args, int); | |
va_end(args); | |
result = original_open(path, oflag, mode); | |
} | |
else { | |
result = original_open(path, oflag); | |
} | |
NSLog(@"OPEN: %s", path); | |
return result; | |
} | |
void hookLibC(void) { | |
MSHookFunction(open, replaced_open, (void **) &original_open); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment