I'm 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;
    strcpy(value->machine, getModelIdentifier());
    strcpy(value->nodename, getHostname());
    return ret;


Here is my tweak that using MSHookFunction

#import "substrate.h"

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, "thao");
    return ret;

%ctor {
    MSHookFunction((void*)gethostname, (void*)replace_gethostname, (void**)&original_gethostname);
  • Have you tried using theos/theos instead of rpetrich/theos?
    – kennytm
    Oct 2, 2016 at 17:03
  • yes. I have tried. but looks like original theos doesn't support xmi file. I compile and meet error :( There are some sources tell me that use Rpetrich fixes this problem.
    – hqt
    Oct 2, 2016 at 17:10
  • Could you use multiple *.x files instead of *.xmi?
    – kennytm
    Oct 2, 2016 at 17:15
  • Can you tell me how to use multiple *.x files? just include in Makefile ?
    – hqt
    Oct 2, 2016 at 18:02
  • If all of those *.x are independent, just put all of them into your tweakname_FILES setting.
    – kennytm
    Oct 2, 2016 at 18:06

1 Answer 1


You should give the newer theos/theos a try, perhaps it has fixed this bug already.

*.xmi/*.xi support was broken (seems still is), and the lead developer discourages its usage, and including a source file instead of header file is strange anyway. If you just want to separate the hooks into different files, simply put all the *.xm/*.x and into the _FILES setting:

tweakname_FILES = first.x second.x third.x
  • Very thanks for pointing me to github's discussing. I found out many useful information here :D
    – hqt
    Oct 2, 2016 at 18:56
  • The bug from official theos still be here. As in discussing, xi/xmi files have some advantages in management. But your option is suitable with me currently.
    – hqt
    Oct 2, 2016 at 18:57
  • @hqt I'm using the master version theos/theos and no "%orig outside" error. Have you #include <sys/utsname.h>, and could you check if there's any unbalanced %hook/%group?
    – kennytm
    Oct 2, 2016 at 19:04
  • I have changed to original theos version. Using multi tweak files. But If I use hookf function, I still meet the same error. But when I move to MSHookFunction, I can compile and run successfully. Nevertheless, everytime I open any apps, it will close permantly as it has crashed.
    – hqt
    Oct 3, 2016 at 19:41
  • I have added my tweak code that caused crash. Please take a look
    – hqt
    Oct 3, 2016 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.