Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karajanyp/285525aecfb71e83802d4bf1d6a33562 to your computer and use it in GitHub Desktop.
Save karajanyp/285525aecfb71e83802d4bf1d6a33562 to your computer and use it in GitHub Desktop.
Hooking a variadic function with Cydia Substrate
//
// 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