Page 1 of 1

can't load objc class from dylib

Posted: Wed Dec 25, 2019 4:38 am
by K.H.Cyp
Hi.

I'm testing VMProtect on macOS latest demo version.

My product is dynamic library with objc classes. I did load dylib successfully with turning off packing option. But it seems to fail load objc classes in dylib. (tested on 10.15)

Test code:

Code: Select all

//
// in dylib
//
@interface Hello : NSObject
- (void)greeting;
@end

Code: Select all

//
// in app linking with dylib
//
- (void)someMethod {
	// 
	// This code is work well with non protect code. 
	//
	Hello *hello = [[Hello alloc] init]; 
	[hello greeting];
}
Linking with VMP version libHello.dylib, class Hello is nil so it will not work correctly.

I can lookup C-level symbols with dlsym like this:

Code: Select all

Class cls = (__bridge Class)dlsym(RTLD_DEFAULT, "OBJC_CLASS_$_Hello");
but [cls alloc] will rise runtime error "no class for metaclass 0x10037e0d8".
I think C-level linking works successfully but objc runtime don't load classes correctly. Is there way to fix?

Re: can't load objc class from dylib

Posted: Thu Jan 09, 2020 10:24 am
by Admin
Please send us a very simple example (app linking with dylib + original dylib) that shows your problem.