Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Theos: Trying to take over UIView _subjectLine from CKContentEntryView in ChatKit

Tags:

ios

jailbreak

I am trying to take control of the subject line in the Messages App. Right now I am just trying to display text in the Subject field.

The main issue I have is to get the compiler to recognize _subjectLine as a valid view. This is what I get if I try and do anything to/with _subjectLine:

Tweak.xm:8: error: ‘_subjectLine’ was not declared in this scope

I don't have any idea how to declare an already existing item to use in a tweak. The standard declarations that I use in Xcode, typically found in a header file, don't seem to work the same.

I've been googling around for about a week now. The most common tutorial or information I found was to do just simple: when method activates – display alert. I can do that, no problem. However, I need to use an already existing object.

like image 984
Calvin J Barrie Avatar asked Aug 12 '12 01:08

Calvin J Barrie


4 Answers

It seems that in your case you are trying to use an instance variable of the class you are hooking. Modifying the instance variable does not work that way in tweaks. You have to use MSHookIvar to 'hook' an instance variable (aka ivar). Example:

[Tweak.xm/mm]

#import <substrate.h> // necessary
#import <Foundation/Foundation.h>

@interface TheClassYouAreHooking : NSObject {
    NSString *_exampleVariable;
}
- (void)doSomething;
@end

NSString *_exampleVariableHooked;

%hook TheClassYouAreHooking
- (void)doSomething 
{
    // 'Hook' the variable

    exampleVariableHooked = MSHookIvar<NSString *>(self, "_exampleVariable");

    // The name of the hooked variable does not need to be the same

    exampleVariableHooked = @"Hello World";

    // You can do ANYTHING with the object Eg. [exampleVariableHooked release];

}
%end

MSHookIvar can also hook stuff like BOOLs and floats etc.

exampleVariableHooked = MSHookIvar<BOOL>(self, "_someBOOL");

Its declared in substrate.h so you need to import that otherwise you will not be able to compile your tweak. Also as a bonus tip, I'm just reminding you that you have to put the identifier of the app/framework you're hooking in your tweakname.plist.

So after you 'hook' the variable you can change it to suit your needs. Happy coding!

like image 191
s6luwJ0A3I Avatar answered Nov 12 '22 10:11

s6luwJ0A3I


You could also use the Objective-C runtime functions to access the instance variable, like so:

UIView *subjectLine;
object_getInstanceVariable(self, "_subjectLine", (void **)&subjectLine);
like image 33
ProtoSphere Avatar answered Nov 12 '22 10:11

ProtoSphere


I'm not familiar with ChatKit, but took a quick peek. You can't access _subjectLine because it's an ivar. You should just access

id subject = [myCKContentEntryView subject]; // should return a CKTextContentView
NSAssert([subject isKindOfClass:[CKTextContentView class]], @"ack");
CKTextContentView * myTextContentView = subject;

The CKTextContentView has a setText method, but no idea what it's expecting since the parameter is id. Might be a view (UILabel?) or might take a string. You might try:

[myTextContentView setText:@"Hello World, w/ jimmies!"];

and see what happens.

like image 1
Dave Avatar answered Nov 12 '22 10:11

Dave


You can use KVC. Example: [object valueForKey:@"whatever"];

It works anywhere, and is cleaner than using the Objective C runtime methods, or Mobile Substrate.

like image 1
coolstar Avatar answered Nov 12 '22 12:11

coolstar