Archive

Archive for May, 2009

iTuna – Chromatic Tuner

May 21st, 2009

appstore
iTuna is an application that allows you to determine the pitch of your surrounding sound via the built in microphone on the iPhone or the external microphone on the iPod touch. It's chromatic tuner is ideal for tuning almost any instrument on, and its interface should be familiar to many as a standard in commercial chromatic tuners.

Note to iPod Touch users: You will need the microphone device addition to use audio recording on the this application.

Support: admin@iwillapps.com
Status: On Sale
Version: 1.1
Screenshots:

The iTuna Interface

The iTuna Interface

Author: admin Categories: Apps Tags:

Automatic Emails

May 11th, 2009


Automatic emails are a feature some apps will need, especially in an app that requires updates to the user (such as a burglary alarm). This is not as hard as people think it is, and it certainly does not require use of the Mail.app that comes with the iPhone, nor does it require low level socket programming. It does however require a bit of know how in PHP and a server from which you can send the email from. First I'll discuss the PHP code associated with automatic emailing:

<?
	if(isset($_GET['address']) && eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$',$_GET['address']))
	{
		$message =
'<html>
	<body>
 
 
			This is the automatic email<br/>
 
 
	</body>
</html>';
		$headers =
'From: No-Reply <no-reply@www.mydomain.com>'."\r\n".
'Reply-To: no-reply@www.mydomain.com'."\r\n".
'X-Mailer: PHP/'.phpversion()."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-type: text/html; charset=iso-8859-1'."\r\n";
		if(mail($_GET['address'],'My Automatic Email',$message,$headers))
		{
			echo 'Sent email';
			exit;
		}
	}
?>

This code, upon execution will send an email to the address defined in the GET variable, so how do I make it execute on the server from an iPhone using Objective C? Simply call the URL in the NSString:

NSString* urlString = [[NSString alloc] initWithFormat:@"http://www.mydomain.com/update.php?address=%@",
	@"myemail@mydomain.com"];
NSURL* url = [[NSURL alloc] initWithString:urlString];
NSString* queryContents = [NSString stringWithContentsOfURL:url];

And that's all there is to it, when you call that NSString method you should get a new email to the address of your choice. Also notice that you can add in subjects as well just by playing around with the GET variables, but be careful, and disguise this string using encryption. We wouldn't want spammers playing around with it now would we?

Author: admin Categories: Tutorials Tags:

Reading, Writing and Splitting Files

May 7th, 2009


It's very important in any programming language to know how to read, write and split the contents of files into an array, and there's no exception to Objective C. So the first aspect we'll focus on is reading files, which is really easy and can be done in just 1 line of code:

NSString* currentString = [[NSString alloc] initWithContentsOfFile:fileName];

This simply dumps the contents of the path fileName into the currentString variable, now we can use currentString to append to a new string and rewrite to our file.

NSString* finalString = [[NSString alloc] initWithFormat:@"%@\n%@",currentString,@"My Appended Text"];

This will append "My Appended Text" to the variable finalString, now all we need to do is put finalString into a file:

NSData* finalData = [finalString dataUsingEncoding:NSUTF8StringEncoding];
[finalData writeToFile:fileName atomically:YES];

This writes our appended string to the fileName we just opened, so we just successfully appended a file in Objective C. Now here's a trick, splitting the file by newline characters so we can analyse each line respectively.

NSArray* logArray = [[[NSString alloc] initWithContentsOfFile:fileName] componentsSeparatedByString:@"\n"];
for(int i=0;i<[logArray count];i++)
	NSLog([logArray objectAtIndex:i]);

This will print every line in the file, one by one. To access a specific line in a line (lets say line 5), simply do [logArray objectAtIndex:4], and it will return the 5th line (this is because it counts 0 as 1).

Author: admin Categories: Tutorials Tags:

Detecting Touches

May 7th, 2009


To detect whether a touch has been performed on the screen, you just have to add a function to your view controller, this is helpful when you just want someone to touch the screen rather than a button:

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
	NSLog(@"The View Has Been Touched");
}

Even better, it will only call the touchesBegan function once the the view we put the touchesBegan function in gets touched. I usually use the touchesBegan in place of buttons in an app that has an activation function (ie. Touch the screen to activate.).

Author: admin Categories: Tutorials Tags:

Callbacks and Protocols

May 7th, 2009


At some point in designing an application, you may want to implement callbacks through protocols. To do this you just need to declare a protocol, have a delegate instance variable, and a method that calls your callback. The first part is simple, declare the protocol in the header:

@protocol MyClassDelegate <NSObject>
-(void) myClassUpdate:(int)myVar;
@end

This turns MyClassDelegate into a protocol, and declares that all classes using this protocol have to have the function myClassUpdate the way it is defined in the class. Now in your class interface, you have to declare your delegate variable, like so:

id <MyClassDelegate> delegate;

It's also very important that you make this delegate public, so other classes can add themselves to it. Now it's just a matter of calling the functions in the delegate variable, which we can do like so:

-(void) timerFired
{
	if(delegate != nil && [delegate respondsToSelector:@selector(myClassUpdate:)])
		[delegate myClassUpdate:3];
}

This calls myClassUpdate in our delegate, and finally to set our delegate variable:

MyClass* myClass = [[MyClass alloc] init];
myClass.delegate = self;

This will change the delegate variable so that it will call myClassUpdate when it needs to.

Author: admin Categories: Tutorials Tags:

Implementing Ads

May 7th, 2009


For those iPhone developers who want to make a free app, but still want to monetize traffic a good way to go about it would be advertising on the iPhone. While I can't speak for myself and give you any solid financial data on advertising, I can show you how to implement it cleverly. Implementation is in fact incredibly basic thanks to these AdWhirl instructions. In fact the only problem I had was putting the Ad Roller at the bottom of the screen, where I think it wouldn't get in the way of my design so much (due to my Navigation Titles). Though thankfully AdWhirl gives you access to view's frame, and you can just change the CGRect object to put it anywhere on the screen, here's the code to put it on the bottom:

ARRollerView* rollerView = [ARRollerView requestRollerViewWithDelegate:self];
rollerView.frame = CGRectMake(0.0,410.0,350.0,50.0);
[self.view addSubview:rollerView];

And that's really it, a very simple way to monetize traffic.

Author: admin Categories: Tutorials Tags:

Detecting Piracy

May 3rd, 2009


Some of you may know of sites either selling or distribution pirated versions of apps, that have had the encryption taken out of them and are available on any iPhone (as long as its jailbroken). Well the first step towards preventing the piracy of your apps is detecting the piracy on those apps, and then taking steps to either monetize your freeloading traffic or disabling your app altogether. A very basic check some iPhone applications apply is this:

if([[[NSBundle mainBundle] infoDictionary] objectForKey:@"SignerIdentity"] != nil)
{
// The app is pirated
}

While this actually works if you just use the software designed to strip encryption from the app to make a pirated copy, it can easily be overcome by simply scanning the binary for the string "SignerIdentity", and changing it to a random string forcing the objectForKey to throw a null at the if statement, so it's not as secure as I would like. So I'd like to recap, and say that I like the method of checking the SignerIdentity, but not how the string is in full display in the binary, but with some very, very basic cryptography and honeytraps we can fix that. Now we need a string that isn't like "SignerIdentity", but can be translated into "SignerIdentity" on the fly, now since I simply want to use strings, and not any data, I would start with either a substitution or transposition cipher, since they are incredibly easy to implement and still manage to hide the text from the plain site of the binary. Both are fairly simple to implement, but I'll start off with a substitution cipher:

NSLog(@"Substitution Cipher:");
char symCipher[] = { '(', 'H', 'Z', '[', '9', '{', '+', 'k', ',', 'o', 'g', 'U', ':', 'D', 'L', '#', 'S', ')', '!', 'F', '^', 'T', 'u', 'd', 'a', '-', 'A', 'f', 'z', ';', 'b', '\'', 'v', 'm', 'B', '0', 'J', 'c', 'W', 't', '*', '|', 'O', '\\', '7', 'E', '@', 'x', '"', 'X', 'V', 'r', 'n', 'Q', 'y', '>', ']', '$', '%', '_', '/', 'P', 'R', 'K', '}', '?', 'I', '8', 'Y', '=', 'N', '3', '.', 's', '<', 'l', '4', 'w', 'j', 'G', '`', '2', 'i', 'C', '6', 'q', 'M', 'p', '1', '5', '&', 'e', 'h' };
char cfile[256];
[[[NSString alloc] initWithString:@"SignerIdentity"] getCString:cfile maxLength:sizeof(cfile) encoding:NSUTF8StringEncoding];
NSLog(@"%s",cfile);
for(int i=0;i<strlen(cfile);i++)
	cfile[i] = symCipher[cfile[i]-0x21];
NSLog(@"%s",cfile);
for(int i=0;i<strlen(cfile);i++)
{
	for(int j=0;j<sizeof(symCipher);j++)
	{
		if(cfile[i] == symCipher[j])
		{
			cfile[i] = j+0x21;
			break;
		}
	}
}
NSLog(@"%s",cfile);

This code may seem complicated, but it's not. Basically it contains a lookup array of characters to substitute for other characters, like rearranging the alphabet. The output here will be:
Substitution Cipher:
SignerIdentity
V.NwY2*8YwC.C1
SignerIdentity
So as you can see, it encrypts the string SignerIdentity to the string V.NwY2*8YwC.C1, the decrypts it back to SignerIdentity. So getting back to what we wanted to do, which was disguise our string, we could quite easily do this to disguise our piracy check:

char symCipher[] = { '(', 'H', 'Z', '[', '9', '{', '+', 'k', ',', 'o', 'g', 'U', ':', 'D', 'L', '#', 'S', ')', '!', 'F', '^', 'T', 'u', 'd', 'a', '-', 'A', 'f', 'z', ';', 'b', '\'', 'v', 'm', 'B', '0', 'J', 'c', 'W', 't', '*', '|', 'O', '\\', '7', 'E', '@', 'x', '"', 'X', 'V', 'r', 'n', 'Q', 'y', '>', ']', '$', '%', '_', '/', 'P', 'R', 'K', '}', '?', 'I', '8', 'Y', '=', 'N', '3', '.', 's', '<', 'l', '4', 'w', 'j', 'G', '`', '2', 'i', 'C', '6', 'q', 'M', 'p', '1', '5', '&', 'e', 'h' };
char csignid[] = "V.NwY2*8YwC.C1";
for(int i=0;i<strlen(csignid);i++)
{
	for(int j=0;j<sizeof(symCipher);j++)
	{
		if(csignid[i] == symCipher[j])
		{
			csignid[i] = j+0x21;
			break;
		}
	}
}
NSString* signIdentity = [[NSString alloc] initWithCString:csignid encoding:NSUTF8StringEncoding];

The NSString signIdentity now contains the string "SignerIdentity", without us having to declare it in the binary! Excellent, another obstacle for piracy. It would be a good idea to generate your own symCipher array, and generating your own encrypted strings, to do this I've made a small PHP script that simply outputs your decrypted string and the substitution array needed to generate it here. I'll also discuss the other simple cipher method of string encryption, a transitional cipher. The principal is really simple, just replacing a letter in the ASCII table with one a defined amount above or below it, so if I wanted -1, B would be A, A would be Z etc. An objective-C implementation would look like this:

NSLog(@"Transpositional Cipher:");
char csignid[] = "SignerIdentity";
NSLog(@"%s",csignid);
for(int i=0;i<strlen(csignid);i++)
	csignid[i] = csignid[i]-3;
NSLog(@"%s",csignid);
for(int i=0;i<strlen(csignid);i++)
	csignid[i] = csignid[i]+3;
NSLog(@"%s",csignid);

This will give us the log:
Transpositional Cipher:
SignerIdentity
PfdkboFabkqfqv
SignerIdentity
So now to do a basic decryption into the SignerIdentity string we need, I we just use the decryption method with our encrypted string:

char csignid[] = "PfdkboFabkqfqv";
for(int i=0;i<strlen(csignid);i++)
	csignid[i] = csignid[i]+3;
NSString* signIdentity = [[NSString alloc] initWithCString:csignid encoding:NSUTF8StringEncoding];

Now as you can see this contains a lot less code, but with the drawback being its a lot more crackable. So now we can hide our string from simple hex edits, we can lay a honeytrap in our code. Let's go back to the code we used at the beginning of the article, we used the string in full sight back then. Now what if we added a small boolean in there to return true if its been executed if the objectForKey is null?

bool checked = false;
if([[[NSBundle mainBundle] infoDictionary] objectForKey:@"SignerIdentity"] == nil || [[[NSBundle mainBundle] infoDictionary] objectForKey:@"SignerIdentity"] != nil)
{
	checked = true;
}
if(!checked)
{
// This app be hacked!
}

In this code, the variable checked will be false if someone hex edits out SignerIdentity, a nice little honeytrap. Now what you do after you have detected this piracy is up to you, I choose to display ads and turn the pirates into monetized traffic, but other developers choose to crash their apps, exit them normally, or restrict the functionality, that part of this however, is up to you.

Author: admin Categories: Tutorials Tags:

File Directories

May 2nd, 2009

There are 3 main types of file directories an iPhone coder can access, but today I'm just going to discuss the 2 that are the most common: Resources and Documents. Now it's very important to remember that each iPhone app will have its own Resources and Documents directory, they do not share these directories with other apps, if you want to learn how to share info between apps, this is not the way to do it. So basically in an iPhone app, we have the resources directory (or base directory), where you can access items you put in your apps resource folder in XCode. From there we have a documents subdirectory, which stores... well documents or any other files the app needs to access. You cannot create any new directories, the iPhone doesn't allow it and you will just end up with broken code. So to access resource files, you have to use the NSBundle library, it's actually very easy:

NSString* myResourceFile = [[NSBundle mainBundle]
                             pathForResource:@"myResourceFile"
                             ofType:@"txt"];

myResourceFile now contains the path to the file myResourceFile.txt in the resources directory. The documents directory is slightly more complex, but still completely achievable:

NSArray* paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString* docDir = [paths objectAtIndex:0];
NSString* myDocumentsFile = [docDir
                            stringByAppendingString:@"/myDocumentsFile.txt"];

myDocumentsFile now contains the path to the file myDocumentsFile.txt in the documents directory. We won't go into using the tmp directory, since there is a very small chance you will actually need to use it (I haven't had to yet).

Author: admin Categories: Tutorials Tags:

Timers

May 1st, 2009

Timers are thankfully very simple on the iPhone. Timers are pretty much essential to most applications, they let you poll through events in your own time, you often don't get an infinite loop or a tick like you do in C or C++. In Objective C there is an object called NSTimer that helps us easily set up timers:

NSTimer* myTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self
                            selector:@selector(myTick) userInfo:nil repeats:YES];

This tells us that every 0.1 seconds, the function myTick will be called repeatedly. So now all that's left to do is declare the myTick function in your code:

-(void) myTick
{
	 NSLog(@"My Timer Fired");
}

Now every 0.1 seconds you will see the log "My Timer Fired", that's cool, but how do we stop the timer? Simply call invalidate on the myTimer object:

[myTimer invalidate];

And your done.

Author: admin Categories: Tutorials Tags:

iKnox – Audio Bug

May 1st, 2009

iKnox is an iPhone application that allows you to plant your very own audio bug into different environments, set it to automatically record when audio gets to a certain volume, email you when the volume gets to a certain level and tell if you if someone is handling your iPhone.

Want to see if someone is using your iPhone while your out? No problem, just load up this application and look at the log view when you get back, it will not only tell you if there has been any significant audio in the background, it will tell you if someone tried to pick up your iPhone.

Note to iPod Touch users: You will need the microphone device addition to use audio recording on the this application.

Support: iknox@iwillapps.com
Status: Rejected
This Application violates Apples Privacy Policy. I could market it in a different direction, but I won't attempt to for some time.
Version: 1.0
Screenshots:

iKnox Home View

iKnox Home View


iKnox Settings View

iKnox Settings View


iKnox Log View

iKnox Log View

Author: admin Categories: Apps Tags: