Tutorial Simple string change - hook method (tweak.xm)

VanHoevenTR

Platinian
Original poster
Jul 8, 2019
19
697
78
Unknown
Author: strejda603

Hey guys!

Have you ever wondered, how to change some string (text) in some app/non-Unity game?

There is very simple way, how to do it!

For changing string, you can use this code in your "tweak.xm" file:

Objective-C:
%hook UILabel /* or other class, i.g.: UITableViewLabel */
-(void) setText:(NSString *)arg1 {
    if ([arg1 isEqualToString:@"Some string"]) { /* the exact string you want to change */
        %orig(@"Some other string");
          // You can also leave this blank: %orig(@""); to remove that string...
    }
    else {
        %orig; /* let any other strings untouched */
    }
}
%end
It can be used, even for long strings, but you need to enter whole string, what you want to change, rewrite manually... Otherwise, it will change just string defined in "isEqualToString", and leaves others unchanged...

For replacement of longer strings, you can use:

Objective-C:
%hook UILabel /* or other class, i.g.: UITableViewLabel */
-(void) setText:(NSString *)arg1 {
    if ([arg1 containsString:@"Some part of long string..."]) { /* define part of string you want to change */
        %orig(@"Some other string"); /* string containing specified part from above will be replaced with this */
          // You can also leave this blank: %orig(@""); to remove that long string...
    }
    else {
        %orig; /* let any other strings untouched */
    }
}
%end
This will replace/remove any strings in hooked class, which contains defined part in "containsString" with string in %orig...

BEWARE: These two methods will change any occurrences of specified string in hooked class!

So if you want to change only one particular string, you must find the exact class/method:

NGINX:
%hook SomeClass
-(void) setSomeString:(id)arg1 { /* just example, could be anything! */
    arg1 = @"Changed string"; /* your desired string */
    %orig(arg1);
}
%end
Hope, it helps
 
  • Like
Reactions: Minhhackios