-1

I am trying to hook a simple function in Theos:

- (_Bool)sendData:(id)arg1 {
    NSLog(@"%@", arg1);
    _Bool r = %orig;
    return r;
};

But the output I get is in hex:

<3c736f61 70656e76 3a456e76 656c6f70 6520786d 6c6e733a 736f6170 656e763d>

I have tried a few conversion codes found from stack overflow but have had no luck printing the ASCII text from that.

Any help is appreciated. Thank you!

d123
  • 1,497
  • 2
  • 12
  • 22
  • The output is in hex because that is the way NSLog displays it. Using a type of `id` is a bad idea, use the real type. We can't tell what should happen it we don't know the type? `NSData`, `NSString`, something else? – zaph Feb 10 '15 at 12:39
  • Yes I know, I would like to know how I can output it in ASCII. I've tried converting to Char *. or used [arg1 UTF8String] no luck – d123 Feb 10 '15 at 12:42
  • @Zaph you don't seem to understand me, I'm hooking a function, I don't know the type. – d123 Feb 10 '15 at 12:42
  • Add your code to the question and change id to the real type. – zaph Feb 10 '15 at 12:43
  • Is that: " – Larme Feb 10 '15 at 12:49
  • Use `NSLog(@"%@", NSStringFromClass([arg1 class]))` for determine object class. – rock88 Feb 10 '15 at 12:52
  • @Larme YES! correct! – d123 Feb 10 '15 at 12:55
  • @rock88 Yes, but I cannot be sure that the type will always be the same all the time. – d123 Feb 10 '15 at 12:56
  • @rock88 just in case you're wondering the class output NSConcreteMutableData – d123 Feb 10 '15 at 13:01
  • if ([arg1 isKindOfClass:[NSData class]){NSString *string = [[NSString alloc] initWithData:(NSData *)arg1 encoding:NSUTF8StringEncoding];}. Note that for your thing, there is a few of the encoding that works. – Larme Feb 10 '15 at 13:01
  • @Larme Wonderful that worked! You wanna place an answer then I'll be able to mark it as correct – d123 Feb 10 '15 at 13:05

1 Answers1

1

From you data output, your response is: <soapenv:Envelope xmlns:soapenv=

if ([arg1 isKindOfClass:[NSData class])
{
    NSString *string = [[NSString alloc] initWithData:(NSData *)arg1 encoding:NSUTF8StringEncoding];
}

I tried various encodings, and NSUTF8StringEncoding wasn't the only one to give the correct response. So you may want to check which one is really the appropriate one.

Larme
  • 24,190
  • 6
  • 51
  • 81