I am working with an iOS project that uses
#if defined (FREE_VERSION)
The project has two targets, each of a free and paid version. If I run the free, the code under the above statement fires, and if I run the paid, the "else" code fires. That's all as expected.
But when I search the project for "FREE_VERSION" or "#defined", I get no results (other than the "#if defined" statements). So where might FREE_VERSION be defined?
I'm not very familiar with pre-processor directives and #define, so I may not be using the right terminology here. But, any help would be appreciated!
With defines like this, I assume you will find it in project settings -> build settings -> preprocessing.
The idea behind it is that you have several schemes/build targets which behave differently and you don't have to change code to setup your build, you just switch between schemes/targets.
DEBUG is an example of a similar macro, which is defined by default for Debug configuration.
That's up to you to #define it somewhere. You could have a constants header file and define it there.
In free version:
Global.h:
#define FREE_VERSION
Then you can comment it out later when compiling paid version.
Related
In my application i have worked for some part of the next version implementations,
So we need to prevent those some implementations for this version.
our superiors asked me to do with pre macro processor, having #ifDef, endif like that and you need to define the version number in buildsettings as preprocessor macro
I have added a user defined setting 'App_Version' in build Setting,
"
How do i use it like
#ifDef AppVersion 1.0
NSLOG (current version implementation)
else
NSLOG (NEXT version implementation)
Actually i was not much awair on it, so that my interpretation was poor
#if App_Version == 1.0
I don't remember exactly how new preprocessor macros are defined in XCode but I don't think that you are defining it correctly. See How do I define preprocessor macros in Xcode 4?
However, using preprocessor macros for such things is far from recommended.
You should
Create a method that will read the application version from the bundle
Call the method to check version and use standard if-elseif-else
With iPhone development I can't really imagine why would you use such a macro/method though. How many versions of an app do you want to build? All the applications I have implemented for iOS needed only 1 version - the latest one. I don't see any reason why would you like to build an older application version from current code.
Use a versioning system and if you are implementing features for the next version into current code, use a dedicated branch! Otherwise it's just a mess and your supervisor is ... not smart ... for not seeing it.
The compiler doesn't need (or want) to know anything about application version (it is information for the application submission process). This should not be done with preprocessor macros, unless you want to define your own (even then, I wouldn't recommend it). You should check the application version at runtime
[[NSBundle mainBundle] objectForInfoDictionaryKey:#"CFBundleVersion"];
and prevent new features from being accessible in the current version based on that. More generally I would consider using branching models like git flow to handle things like that. What will happen when you have 3,4,5 ... versions to handle. The preprocessor macros will become a nightmare to manage.
Working on an iOS App I'm using an static library integrated as a submodule. No problem, but when I want to step into a method of this submodule while debugging the debugger just step over that method call.
I guess it's related to the Build settings but I don't have any idea.
Thanks for your help!
kober
You cannot step into the library code unless you have source code for it.
This is the purpose of libs, if you make your own you may want to prevent others to look how its built. If you want to check library function correctness you have two ways:
Get the source code - which is in most cases impossible unless you get it from the author
Do unit testing. Check if library function's arguments give correct results.
If you do have the source code for the lib you have to set its build to debug mode, so you can provide symbols for Xcode to get through library's methods.
After a search here on the forum I found a question like that, and it redirected me to a tutorial which gave em some basic instructions on manipulating SpringBoard with CapitainHook.
To start I'd like to do it with normal %hooks only. Any hint where I could start?
This little introduction is meant for whoever has a minimal knowledge on Objective-C and knows what he is doing.
NOTE: I will refer to the theos install path as $THEOS. This could be ~/theos, /var/theos, /usr/theos... Yeah.
The most popular way of creating MobileSubstrate extensions, also known as tweaks, is using Dustin Howett's theos build suite. Details follow:
What is theos?
So, we should start with what theos is not:
The Operating System
A Greek God
A compiler
And of course, what theos doesn't do:
Teaches you how to code.
Creates tweaks without having you to think
Sets up a whole building environment and/or installs the iOS SDK.
Theos is a cross-platform suite of development tools for managing, developing, and deploying iOS software without the use of Xcode, featuring:
A robust build system driven by GNU Make, which makes its Makefiles easily deployable through everywhere with theos installed too.
NIC, a project templating system which creates ready-to-build empty projects for varying purposes.
Logos, a built-in preprocessor-based library of directives designed to make MobileSubstrate extension development easy and with optimal code generation.
Automated packaging: Theos is capable of directly creating DEB packages for distribution in Cydia, the most popular mean of package distribution in the jailbreak scene.
How to install theos?
On OSX: Have the iOS SDK installed and follow these instructions.
On iOS: Install the BigBoss Recommended Tools package from Cydia and run installtheos3.
On Linux: Find a mean to have the toolchain installed, and follow these instructions.
On Windows: Nothing is impossible, but if you actually manage to do so, please let me know. :P
How to use theos?
This is a very asked question and too vague. Since theos is a whole suite of development tools, it doesn't make sense to ask How to use it, but more specifically, to ask How to create software using theos.
First of all, always have the Theos Makefile Reference in hand. It covers the basics of creating a theos Makefile, and that includes solving your linking issues adding a framework or private framework to the project.
Now, you can either create your own Makefile from scratch, create your little theos clone/symlink and start coding, but theos makes this step easier. You can just use nic.pl.
A very simple example of running NIC to create something can be found here. It's very straight-forward and sets you up right-away for programming.
Now, here's where we start getting back to topic.
Creating a tweak with theos
First of all, do not run NIC when inside $THEOS/bin. NIC will create the project directory exactly where you're running it from, and it avoids any project being created in $THEOS/bin. Therefore, you'll end up with a simple error which can be avoided by creating the project directory somewhere decent.
Run $THEOS/bin/nic.pl and choose the iphone/tweak template. You will be prompted by simple information which you may well know well how to answer, except for the last field: MobileSubstrate bundle filter.
Since a big part of MobileSubstrate is not just the hooker (the library which switches original methods/functions with yours), but also the loader (the part which gets your hooking to be inserted into certain processes), you have to supply this basic information for the Loader to know where to load your tweak. This field is but the bundle identifier for the application where this project will be inserted.
com.apple.springboard, the default option is the bundle identifier for SpringBoard, the application which is:
The iOS Homescreen
The launcher/displayer of common applications
The iOS Status Bar
Handler of some high-level essential background processes
Therefore, there's where many tweaks take place, altering behavior from something as trivial as app launching to something like how the whole homescreen UI looks like.
Programming a tweak with Logos
Now, the directory generated by NIC will contain:
The Theos Makefile, where you'll change information related to compiling
The control file, where you'll change packaging-related information
A symbolic link (or shortcut) to $THEOS named theos/
The main code file, defaulted as Tweak.xm. It is already added to the Makefile for compiling, so you can start coding right-away with it!
On knowing what to do
Now, you don't have SpringBoard's source code laying around, and you can't guess what methods to hook from nowhere. Therefore, you need a SpringBoard header set. For that, you need to use a tool named class-dump-z and run it into the SpringBoard binary (which is inside the iOS filesystem) to obtain header files including all class declarations and its methods inside the application.
From that (a deal of guessing and logging a method call is involved) you can start messing around with what you want in a tweak.
Of course, if you are not hooking SpringBoard you can use class-dump-z as you would in other binaries, such as UIKit, MobileSafari, etc.
Note that for when reversing App Store apps, they'll be encrypted. You'll need to decrypt those (I am unfortunately not allowed to tell you how-to), and then just run class-dump-z on them.
On obtaining private headers
Stuff like preference bundles require the headers for private frameworks, in that case the Preferences framework's headers. Else you'll get endless missing declaration errors (as I guess you could assume).
Getting them has the same logic applied the previous step. Run class-dump-z on, at this case, the Preferences binary and throw the headers at your INCLUDEPATH. The INCLUDEPATH is where the compiler will go looking for headers you include like #include <stdio.h>. Yes, stdio.h is inside one of the directories which build a compiler's INCLUDEPATH!
When compiling with a theos Makefile, $THEOS/include counts as part of your INCLUDEPATH, which means, you can just throw your dumped headers over there and include them later.
(Note that class-dumped headers aren't always perfect, so you're likely to have a couple of header-related compilation errors which can be easily fixed with something like removing a #import directive or changing it, or adding a couple of declarations.)
Code tips
You can't link against SpringBoard, so whenever you require a class from SpringBoard you have to use either the Logos %c directive or the objc_getClass function, as defined at <objc/runtime.h> to get it. Example: [%c(SBUIController) sharedInstance], [objc_getClass("SBUIController") sharedInstance].
When not knowing what a method does or how something works in SpringBoard, try disassembling it with IDA or others. I use IDA Demo (<- noob!) for my disassembling.
Looking at example code is amazingly helpful for both learning and figuring out how something works inside SpringBoard or others (again..). Great people at GitHub to have a projects looked at are rpetrich, chpwn, DHowett, EvilPenguin, and of course way more.
To also find about how SpringBoard and other works (...), have a look at a class's article at the iPhone Dev Wiki!
Epilogue
Wait, where's the good part? Where do I learn about coding in Tweak.xm?
Well, the original question was actually How to start MobileSubstrate tweaks programming?. You're all setup, hopefully with all headers placed, ready to type in make and see your project magically compiled with theos.
All you need to do is now to actually dig into your headers or your disassembly and go hooking, calling, etc.!
Logos Reference contains exactly how to hook and use other features of Logos, and the MobileSubstrate article on the devwiki is also a great read.
In case there is any doubt, don't hesitate joining the irc.saurik.com #theos IRC channel. It's a great way to discuss theos-related topics and ask questions. I'm mostly there, along with other greatly smart people ;)
You are looking for Theos created by DHowett.. Theos allows you to make tweaks, but it doesn't give you everything you need. You don't get every header for iOS, so you have to class-dump-z the frameworks/private-frameworks from the iOS SDK. Get started here: http://iphonedevwiki.net/index.php/Theos/Getting_Started, or join irc.saurik.net #theos for more help. You can also look at my projects that use theos: https://github.com/evilpenguin
You sound like you're looking for theos. Take a look at this, it should help get you started.
I'm working in an embedded system (RTXC) where I need to disable the debugger functionality which is enabled through a #define command. However, when I change the #define to undefine, compilation goes off fine, but when the linker runs, it encounters an error about a symbol not existing that belongs to the debug code (which should have been taken care of by the debugger variable not being defined). Is there any way for Make to ensure that a preprocessor variable does not get defined or stays undefined ?
The answer to your question is no, Make can't absolutely prevent a variable from being defined by, say, a #define expression in the code.
You seem to have an elusive problem. It could be a bug in your Makefiles, a misspelled directive, a bad macro (if you'll pardon the tautology) or something trivial. I'd suggest burning the forest: cut out everything until the problem stops, then see where it was hiding. If you get down to HelloWorld and the problem persists, let us know.
No. You will need to fix the bug in your code.
More specifically, there is something that is referencing the debug side of things outside of an #ifdef. Make won't be able to help you there.
Another possibility is that you have a .o or something left over from a previous build; you might want to try cleaning the build tree.
when i was trying to build my project in MPLAB,i got this Build error message..
Clean: Deleting intermediary and output files.
Clean: Deleted file "M:\12 CCP PWM\12 CCP PWM.o".
Clean: Done.
Executing: "C:\MCC18\bin\mcc18.exe" -p=18F46K20 "12 CCP PWM.c" -fo="12 CCP PWM.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
MPLAB C18 v3.20 (feature limited)
Copyright 1999-2005 Microchip Technology Inc.
This version of MPLAB C18 does not support the extended mode
and will not perform all optimizations. To purchase a full
copy of MPLAB C18, please contact your local distributor or
visit buy.microchip.com.
Executing: "C:\MCC18\bin\mplink.exe" /l"C:\MCC18\lib" "C:\MCC18\lkr\18f46k20i.lkr" "12 CCP PWM.o" /u_CRUNTIME /o"12 CCP PWM.cof" /M"12 CCP PWM.map" /W
MPLINK 4.20, Linker
Copyright (c) 2008 Microchip Technology Inc.
Error - could not find definition of symbol 'main' in file 'C:\MCC18\lib/c018i.o'.
Errors : 1
Link step failed.
----------------------------------------------------------------------
Release build of project `M:\12 CCP PWM\12 CCP PWM.mcp' failed.
Thu Apr 16 14:34:41 2009
----------------------------------------------------------------------
BUILD FAILED
I have checked that the path to the linker library was correct.I suspect it has something to do with my source code...Any helps are very much appreciated.
Here is my source code.. http://cl1p.net/mplabc18
The compiler may be looking for a different definition of main. I have seen this in some PIC code:
// Main application entry point.
#ifdef __C30__
int main(void)
#else
void main(void)
#endif
{ ... }
It is a good idea to add the specific linker file to your project. If you are using MPLAB, under the workspace, right click on linker files and add the linker file from mcc16\lkr folder for the specific processor.
Clean and Re-compile the solution
The only thing that stood out to me in your source file is this part of the ISR declaration:
#pragma code InterruptVectorLow = 0x18
The user guide of the compiler you're using states this should be:
#pragma code low_vector=0x18
Since this declaration is just before your main function it might be giving you trouble.
Edit:
None of the presented solutions seem to work so I have just copy-pasted your code into a new MPLAB project, set up for the PIC18F46K20 device. It compiles just fine with the MCC18 compiler. The only thing that's missing from the project is the "12 CCP PWM.h" header file (which I do not have). So either there's something wrong with your header file, there's something wrong with your project setup, or the fact that I'm using MCC18 3.30 instead of 3.20 is the problem.
code compiles fine for me (C18 3.30 full)
i've had MPLAB flake out a bit on me especially on large source trees, many times a reboot has solved it, absolutely no idea why, tried everything else and it was the only way to get mplab to reset.
Personally I would not strain the corners of the implementation by having source file names with several spaces in, particularly with an embedded toolchain!
But it seems like they're making a reasonable effort to add all the double-quotes, so maybe that's not a real problem.
Do you actually have a 'main' function in your code, and if so, exactly how is it defined?
I use a third-party compiler, so I can't offer any specific experience on that. But one thing I may suspect is that something in the code is causing the compilation to stop partway through. This can be an unterminated comment, or a function with a closing brace missing. Consider especially the #included files, because you can't see the effects in your editor when you look at the main file, and particularly check any #includes that you have written yourself. And at the top of the list is, "what did you change last"?
What I do at this point is make a branch copy, and start mercilessly hacking out huge blocks of code, just to see when the error goes away. Divide and conquer. Of course, this can be time consuming, so I'd probably ask on StackOverflow, first :)
It's been a while, but I saw that you used a pragma to define the location of the interrupt handler before you created the function, might you need to do the same thing with main()?
It might be handled in the .h file - I'm not sure. I only ever used ASM on the PICs and I explicitly handled everything (ie, at 0x000 jump to main; at the interrupt vector address jump to this memory address; at main address do these things, etc). 'main' for me was defined to be an available address in the code section (which I see you've done, started the code section then defined main) but I believe I had to explicitly define that 'main' was to start at a memory address in the code section. Again, it was ASM, but I wouldn't doubt that you need to do something similar - a pragma to define main as main.
If c018i.o contains the reset vector, and it refers to the function main by name, then the issue could be that main needs a prototype - even in the same file as the function itself, so the linker can pick this up and put main in its list of functions.
So, try inserting:
void main (void);
immediately above the main function.