%orig found outside of hook or subclass when using Tweak.xmi


#1

I am using Rpetrich’s Theos repository and I’m using tweak.xmi for making tweak on multiple files for easier in management.

I can build and run successfully except one thing: I cannot use hookf. Before that, when I put all source code inside one tweak.x, everything works normal. But now, everytime I compile, I meet this error:

error: %orig found outside of hook or subclass 

One example of my hook is:

%hookf(int, uname, struct utsname *value) {
    int ret = %orig;   // error at this line.
    strcpy(value->machine, getModelIdentifier());
    strcpy(value->nodename, getHostname());
    return ret;
}

#2

I’ve never used rpetrich’s fork, but don’t you need a %end to pair with %hookf?


#3

I have rechecked. I have put %hookf pair with %end put error is same. Moreover I use original Theos’ repository I compile error because original theos doesn’t support Tweak.xmi ;( As I read in this Discusstion

I have moved from hookf to MSHookFunction. I can compile and run successfully. The hook works. But I don’t know why all my apps crash when running. here is one example:

static int (*original_gethostname)(char *, size_t);

static int replace_gethostname(char *value, size_t valueLen) {
    int ret = gethostname(value, valueLen);
    if (value) strcpy(value, [SystemInfo getHostName]);
    return ret;
}

MSHookFunction((void*)gethostname, (void*)replace_gethostname, (void**)&original_gethostname);

#4

What’s the crash log?


#5

as far as I remember.
gethostname is only a wrapper around syscall, which makes it too short for MSHF to work. Try fishhook.

(You can locate this function using dladdr and check if it’s indeed too short


#6

thanks for letting me know this information. :"D