Rules about including 3rd party libraries in frameworks - objective-c

I'm currently working on a framework for interfacing with a web service I wrote. To make life easier, I'm considering using a wrapper around CFNetwork, called ASIHTTPRequest.
That's all wonderful. But what happens if the user already added that class to their project? I'm sure the linker would throw up an error. Is there any way to 'constrain' classes to only exist in a specific framework, so the linker will ignore them outside of that framework/library? Alternatively, I can always use plain CFNetwork APIs, but that's just a pain and as we all know, programmers are lazy =P
Thanks for any ideas/suggestions.

No. There is absolutely no way to do this. You won't get a linker error if you do, but you'll get a runtime warning printed by dyld directly to the console on every single launch, and if the version of ASIHTTPRequest that you bundle differs in any meaningful way from the version the application uses, then you could get bad behavior or a crash.
HTTP really isn't that hard. Why would you use CFNetwork? Just use NSURLConnection.

Related

How do I convert an armv7 binary to i386/x86_64

I am trying to build a mac(cocoa) app. I have a framework that I am trying to link with that has been compiled for iOS(the armv7 arch). I unfortunately no longer have the source code that I used to compile the original framework. Would it be possible to change the architecture of the framework(perhaps through decompilation and then recompilation) so that it can be compiled into my cocoa app?
So far I have looked into lipo and fat binaries as well as using optool to decompile but haven't made any direct progress towards converting architectures.
Thanks for your help.
No, there is no reasonable way to automate this conversion. Most C decompilers generate code that is a very literal translation of the assembly; it is usually not suitable for compilation.
(One good decompiler is the Hex-Rays plugin for IDA Pro. However, it is extremely expensive -- a license is over $2000. Unless your framework is particularly large and complex, it may be more cost-effective to work without this tool.)
If you have really lost the source code, your only real option will be to rewrite the framework. You can use the disassembly to guide your efforts, but you will need to fill in some of the details.
In theory, if the code doesn't use any POSIX system calls directly, it might be possible to create an Frankensteinian abomination:
Run the code on an arm64 emulator.
Replace all function call linkages into the Objective-C runtime (e.g. objc_msgsend) with emulator traps.
Abort if you find any other function call linkages.
For runtime function calls, call the equivalent runtime function on the x86-64 side.
For alloc calls, return an NSProxy object on the arm64 side that traps into the emulator.
For any objects passed via parameters, return values, or return parameters, pass an NSProxy object.
That said, in practice, unless the framework is insanely complex, it would be faster to rewrite the code. And realistically, even if it is insanely complex, if you know enough arm64 asm to pull this off, you can probably rewrite it from the asm more quickly. :-)

Adding an SQL extension to a precompiled Lua 5.2 project

I have looked into at least 6 different SQL Lua extensions, and they all seem to have their latest version compatible with up to version 5.1 of Lua. I have had zero success in implementing any of them into my current project which uses Lua 5.2, with the best case scenario ending in either silent program crashes or attempt to call global 'module' (a nil value).
I am not the original project owner, so I am trying not to be forced into changing the source code for it (though more recently, I have even gone down that road now).
And often times, it is unclear if these crashes are related to the way the project itself operates, the way the project implements Lua (as a static library), the way that Lua tries to implement it's extensions, the way the extensions implement their dependencies, a versioning conflict, or some sort of crazy combination of each. It's practically impossible to debug a silent crash in this manner, because the source of evil could literally be anything.
As the answer states in this question, I have even tried supporting the module function (which most lua sql extensions utilize, but was deprecated in 5.2), but the program still crashes or just complains about a seemingly infinite amount of missing dependencies. And after spending hours of tracking down (what would seem to be) all of the dependencies it would complain about, it still crashes.
Changing the project's source code to use the Lua 5.1 source appears to break the functionality of the project, resulting in various compiler errors regarding missing 5.2-related functions. Linking the MySQL C/C++ connector to the project results in rather vague runtime errors, which seem to conflict with the way the project implements Lua 5.2.
Are there ANY sqlite/MySQL extensions out there which actually work with Lua 5.2 on a 32-bit Windows machine? Preferably, "out-of-the-box" precompiled binaries with Lua source/ffi bindings?
OR alternatively, are there any clear instructions on how to get this set up properly, without having to scavenge through separate instructions across the web for each required assembly?

Objective C - Protect Framework code

I have to show other people a project I'm working on but I want to protect a framework in the project from being readable. I just packed all the code in the framework and added it to the project.
The problem is that when the framework calls some delegate methods and I set a breakpoint to those Xcode shows the full .m / .mm files where those calls come from. How can I prevent that? I want to protect my code.
You are only seeing the code because it's available on your machine and Spotlight can find it. If you distribute the compiled framework binary, the source will not show up in the debugger, though the names of methods will. Stripping the binary ("Strip Linked Product") will remove some names of functions, but not methods, since these have to be available at runtime in order for message dispatch to work. This will make it harder to make use of crash logs, so I don't generally recommend it unless you really need to save space.
Keep in mind that there is only so much you can (or should) do to protect against reverse engineering. All languages are subject to reverse engineering, but ObjC is particularly susceptible by its nature. See Decompiling Objective-C libraries for more discussion on that.
Compile your framework into a binary. This will "protect" the source code from being readable, with only the header files (you choose) to be exposed.

Monotouch/WCF Error on iPhone Hardware

I created a WCF Client on Monotouch with the Silverlight SLSvcUtil.exe Tool similar to http://docs.xamarin.com/ios/tutorials/Working_with_Web_Services#Consuming_WCF_Services.
On the Simulator everything works fine but when i started it on an iPhone 4S i got the error :
Attempting to JIT compile method '(wrapper delegate-begin-invoke) :begin_invoke_IAsyncResult_this__TimeSpan_AsyncCallback_object (System.TimeSpan,System.AsyncCallback,object)' while running with --aot-only.
Any ideas?
I've called a few wcf services from monotouch without hitting any issues like this- so it can be done.
The jit error within monotouch normally indicates either that something has been removed by the linker, or that some virtual abstract method has been called (at least in my recent experience).
Can you check the linker settings for your real iPhone project? Does the problem go away if you set it to -nolink - see http://docs.xamarin.com/ios/advanced_topics/linker
If that does help, then the next step is to take a look within the wcf generated file - can you find and post some more code about the callback method in this case?
Such issues are rarely linker related, even less if the signature is a wrapper. However you can confirm this easily with Stuart's instructions.
IMO you are likely hitting a case where the AOT compiler could not predict the required code. That can happens when mixing generics and value-types (and you have a TimeSpan in generated signature). This will work on the simulator (where the JIT is used) but not when AOT'ing the application.
The best way to solve such issue is to open a bug report at http://bugzilla.xamarin.com and attach a test case that allow us to replicate the issue.

Manage files on iDevices

Does anyone know how programs like iPhoneExplorer manage to list/add/remove files on an iDevice?
I would like to do something similar (but more basic) in a Cocoa Touch application.
It's technically not an Apple-approved™ method, so don't plan on putting this in the App Store. But it is possible. First, import the MobileDevice framework from /System/Library/PrivateFrameworks. Then use the reverse-engineered header for the MobileDevice framework:
http://code.google.com/p/ziphone/source/browse/trunk/ZiPhone/MobileDevice.h
It includes all the methods necessary to communicate with an attached iOS device.
There's also a C++ wrapper for it that's a bit easier to use, especially for detecting the device in the first place. It also includes methods specifically for jailbreaking, but they're not required.
http://code.google.com/p/independence/source/browse/trunk/libPhoneInteraction/PhoneInteraction.cpp?r=323