Tweak:
#import <substrate.h>
void (*old__ZN8CPPClass11CPPFunctionEPKc)(void *, const char *);
void new__ZN8CPPClass11CPPFunctionEPKc(void * hiddenThis, const char * arg0) {
if (strcmp(arg0, "This is a short C function!") == 0) {
old__ZN8CPPClass11CPPFunctionEPKc(hiddenThis, "This is a hijacked short C function from new__ZN8CPPClass11CPPFunctionEPKc");
} else {
old__ZN8CPPClass11CPPFunctionEPKc(hiddenThis, "This is a hijacked C++ function!");
}
}
void (*old_CFunction) (const char *);
void new_CFunction(const char * arg0) {
old_CFunction("This is a hijacked C function!");
}
void (*old_ShortCFunction)(const char *);
void new_ShortCFunction(const char *arg0) {
old_CFunction("This is a hijacked short C function from new_ShortCFunction!");
}
%ctor
{
@autoreleasepool
{
MSImageRef image = MSGetImageByName("/Applications/iOSRETargetApp.app/iOSRETargetApp");
void *__ZN8CPPClass11CPPFunctionEPKc = MSFindSymbol(image, "__ZN8CPPClass11CPPFunctionEPKc");
if (__ZN8CPPClass11CPPFunctionEPKc) {
NSLog(@"iOSRE: Found CPPFuction!");
}
MSHookFunction((void *)__ZN8CPPClass11CPPFunctionEPKc, (void *)&new__ZN8CPPClass11CPPFunctionEPKc, (void **)&old__ZN8CPPClass11CPPFunctionEPKc);
void *_CFunction = MSFindSymbol(image, "_CFunction");
if (_CFunction) {
NSLog(@"iOSRE: Found CFunction!");
}
MSHookFunction((void *)_CFunction, (void *)&new_CFunction, (void **)&old_CFunction);
void *_ShortCFunction = MSFindSymbol(image, "_ShortCFunction");
if (_ShortCFunction) {
NSLog(@"iOSRE: Found ShortCFunction!");
}
MSHookFunction((void *)_ShortCFunction, (void *)&new_ShortCFunction, (void **)&old_ShortCFunction);
}
}
RootViewController:
#import "RootViewController.h"
class CPPClass
{
public:
void CPPFunction(const char *);
};
void CPPClass::CPPFunction(const char *arg0)
{
NSLog(@"iOSRE: CPPFuction: %s", arg0);
}
extern "C" void CFunction(const char *arg0)
{
NSLog(@"iOSRE: CFunction: %s", arg0);
}
extern "C" void ShortCFunction(const char *arg0)
{
CPPClass cppClass;
cppClass.CPPFunction(arg0);
}
@implementation RootViewController
- (void)loadView
{
NSLog(@"- loadView -");
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
self.view.backgroundColor = [UIColor redColor];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"- viewDidLoad -");
CPPClass cppClass;
cppClass.CPPFunction("This is a C++ function!");
CFunction("This is a C function!");
ShortCFunction("This is a short c function!");
}
@end