2

I'm writing a SIMBL plugin for Chrome and I'm getting a particular instance with an unexposed type which is written in C as a NSConcreteValue. I cannot unwrap it or perform selectors on it, but I can get its type string with [myInstance objCType].

The type I'm talking about is GURL.

Here is some code:

NSArray* tabViews = [tabStripController performSelector:@selector(tabViews)];

for (id tabView in tabViews) {

    id tabController = [tabView valueForKey:@"controller_"];

    id tabTitle = [tabController valueForKey:@"toolTip"];

    id tabUrl =  [tabController valueForKey:@"url_"];

    NSLog(@"%@", tabTitle);
    NSLog(@"%s", [tabUrl objCType]);
}

The tab title is not an issue since it's a NSString.

[tabUrl objCType] returns this:

{GURL={basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >={__compressed_pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__rep, std::__1::allocator<char> >={__rep=(?={__long=QQ*}{__short=(?=Cc)[23c]}{__raw=[3Q]})}}}B{Parsed={Component=ii}{Component=ii}{Component=ii}{Component=ii}{Component=ii}{Component=ii}{Component=ii}{Component=ii}^{Parsed}}{unique_ptr<GURL, std::__1::default_delete<GURL> >={__compressed_pair<GURL *, std::__1::default_delete<GURL> >=^{GURL}}}}

GURL has a property called spec_ which I would like to access to get the ASCII string of the GURL instance.
Here is GURL: https://chromium.googlesource.com/chromium/src/+/lkgr/url/gurl.h

Is the objCType string of any help?

ohdeerdog
  • 21
  • 3
  • I don't think so, not without writing code that has knowledge of the C++ ABI. I think a better plan to investigate is compiling as ObjC++ and/or making an ObjC wrapper for `GURL`. – jscs Mar 07 '17 at 13:55
  • Thanks Josh. So you're saying that if I compile as ObjC++ my class will have knowledge of the contained C++ types? In any case, I think I'll have to drop `@import` statements since when I save as .mm, I get a 'modules are disabled' error when compiling. – ohdeerdog Mar 07 '17 at 14:08
  • I think so, but you'll probably have to include the header too. Wish I could be more specific: it's not something I have experience actually doing, I'm afraid. But that's the direction that I'd look in if I were working on this. – jscs Mar 07 '17 at 14:28
  • Ugh. I'm going down the rabbit hole if I do that. `gurl.h` has a ton of other C++ dependencies. Thanks! – ohdeerdog Mar 07 '17 at 14:36
  • Sure thing; good luck. There's other people here who actually do ObjC++, hopefully one of them will come by. Actually, you may want to add the [objective-c++] tag. Also [simbl], maybe? – jscs Mar 07 '17 at 14:38

1 Answers1

2

NSConcreteValue is a private subclass of NSValue.

I suggest you cast to NSValue and then use the NSValue public API.

If you want to be extra safe, surround it with if ([myObj isKindOfClass:[NSValue class]]) {}.

Regarding pulling C++ types from NSValue, this answer shows how to do it. Essentially you just make your variable and then call getValue:&myVar as normal. You will, of course, have to compile as Objective-C++ (use a .mm extension), and import the relevant header.

Community
  • 1
  • 1
Amy Worrall
  • 16,250
  • 3
  • 42
  • 65