iostheostweak

Is it possible to intercept System Calls via Theos Tweak? Jailed Version


Can i intercept generic system calls like sqlite3_prepare or sqlite3_open also CC_MD5 of libcommonCrypto with a Theos (jailed versione) Tweak?

I would intercept all these calls and print on the console or into a log file. I've read something about MSHookFunction, but i'm not sure about it.

EDIT: i add some code which i've wrote in these days. This is my Tweak.xm, where i would intercept CC_MD5 call, and after a simple message log, i would return to the normal flow. The tweak is injected, but i can not see any message.

#include <substrate.h>
#include <CommonCrypto/CommonDigest.h>

static unsigned char * (*original_CC_MD5)(const void *data, CC_LONG len, unsigned char *md);

static unsigned char * replaced_CC_MD5(const void *data, CC_LONG len, unsigned char *md) {

        NSLog(@"Calling MD5");
        return original_CC_MD5(data, len, md);
}

MSInitialize {
        MSHookFunction(CC_MD5, replaced_CC_MD5, &original_CC_MD5);
}

Solution

  • I've found the problem. The Theos version that i'm using is for jailed device. With this version MSHookFunction is substituted by fishhook.

    Using fishhook it's all ok: obviously the code changes

    #include <substrate.h>
    #include <CommonCrypto/CommonDigest.h>
    #import <fishhook.h>
    
    static unsigned char * (*original_CC_MD5)(const void *data, CC_LONG len, unsigned char *md);
    
    static unsigned char * replaced_CC_MD5(const void *data, CC_LONG len, unsigned char *md) {
    
            NSLog(@"Calling MD5");
            return original_CC_MD5(data, len, md);
    }
    
    %ctor {
    
    rebind_symbols((struct rebinding[1]){{"CC_MD5", replaced_CC_MD5, (void *)&original_CC_MD5}},1);
    
    }