Remotely Control iPhone via SSH and VNC

This is an issue I spent far too much time time on. I stumbled upon a great new game, Threes, and had become consumed with the internal workings – how the game chooses what card to produce, where to place it, etc. In order to get some real data to work with I needed to complete a multitude of games, all while keeping track of which cards were produced and where. This is the type of menial task I have no patience for and I quickly began to seek a method to do this automatically.

I had a jailbroken phone – something you will need to do have if you are interested in any of the methods I am about to describe. This method is 99.9% effective and, if something goes wrong, you can completely fix it by restoring through iTunes. Unlocking your phone is dangerous – it has the possibility of leading to a “bricked” iPhone. Jailbreaking is not unlocking. If you’re interested in jailbreaking check out evasi0n – the latest version of their tool is working on iOS 7.0.6.

With that out of the way, here’s what you’ll need and why:

  • OpenSSH: SSH is ubiquitous method of remotely accessing another system through the command line. This is how we’ll interact with the iPhone and send it the commands we want.
  • SimulateTouch: This package allows you to (you guessed it) send touch events to your iPhone using command line tools.
  • Optional Veency: This is a VNC server that runs on the iPhone. VNC is another tool that allows you to remotely access devices. However, unlike SSH, it allows you to see the screen of the remote device and send things like touch and keyboard events. But I thought we were using SimulateTouch to send touch events? Yes, that’s right. Though Veency can be used this way as well I’ve found it to be far less reliable than the SimulateTouch library. Sometimes the commands I send are just lost in the ether.
  • Optional Activator: This allows you to set up a handful (read: a ton) of custom gestures and actions that can do anything from launch applications to disable WiFi to restart your iPhone. It also, conveniently, has a command line interface which can be used to activate any of its abilities via SSH – no gestures needed.

That’s it for the software! Everything I just listed can be downloaded, for free, through Cydia. Cydia is installed automatically when you jailbreak and is the de facto way of installing 3rd party software.

So, now that we have all these tools – how do we use them?! I’m a big python buff so all of my examples are going to be in python. You can use any language you like, but you’ll have to interpret the mysterious code I provide you.

Before I start with examples, here’s the biggest pitfall of our setup:

We don’t have a way to view the current screen in applications that run at 30 FPS or more. Veency simply can’t keep up and provides a distorted display. I’ll explain how I’ve been getting around this in my examples below.

Connecting via SSH:

I’m using Spur as my SSH interface. You can use whatever you want. We use the username ‘root’ because we want full access to the iPhone filesystem. The default SSH_PASSWORD is ‘alpine’ (and has been forever) – I recommend you change this as it is somewhat of a security issue.

Connecting via VNC:

Here I’m using the vncDoTool. Again, use what you want. You can set up the VNC_PASSWORD in the Veency settings.

Sending Touch Events:

The SimulateTouch library makes this dead simple. My example above shows how to make a swipe in any direction. You provide the X,Y coordinates of the start position and the end position. The last two commands are the duration of the swipe and the orientation of the device (1 = portrait).

Taking a ScreenShot:

My first example instructs Activator to take a screenshot. My second example uses VNC to hold down the power button, press the home button, and release the power button – all in quick succession. As you probably know, this is the built in way to take screenshots in iOS. These screenshots will be stored in your camera roll.

Accessing the ScreenShot:

This is a little more complicated. What we’re doing is listing the files in our screenshot directory by their creation time (yours may not be 108APPLE but it will be in the same DCIM directory). We grab the first of these files and assume (correctly) that it’s the screenshot we just took. We then open this file with SSH – this effectively stores the image in memory. Then we use python to open a file for writing – this is where we’ll store the screenshot. We use shutil to copy the screenshot from memory to the file location we opened. Finally, we close out both of our file streams.

In the second to last command I delete the screenshot file. Unfortunately, Apple has made their screenshot system ridiculously complicated. If you navigate to your Camera Roll you’ll find your image is still there. Click on it and a blank screen will be loaded. We’ve deleted the image file it’s trying to load but haven’t gotten rid of the image reference or the associated thumbnail that was created. I haven’t found a way around this.

The final command stores our image into the program memory so I can use it elsewhere without having to read the file from disk each time.

Well, this concludes this fairly verbose tutorial. If you have any questions I’ll do my best to answer them in the comments. I’ll leave you with close to 1000 lines of Python code for you to peruse. This is the code I came up with for automating the gameplay of the addictive and beautiful new game Threes.

 

Programmatically Add Default UITextField

I haven’t posted anything in a while, but I’ve been programming much more often and figured I’d share some answers to questions that had me stuck for a while. Now, if you’ve ever tried to add a UITextField purely through code you’ve probably noticed that what you get is a blank area that you can double-tap and add text to. When you add it using Interface Builder you get this pretty rectangle with rounded edges – what gives?

Well, I have no idea what gives. But what I do know is how to use a whole bunch of extra code to fix it. Here’s some nicely commented code that shows what I’m talking about:

That method will return a nicely formatted UITextField. It may not look precisely like the one you get from IB, but I challenge you to get it closer. If you don’t want any placeholder text just send nil or edit the method to take no instance variables.

Windows 8 Lightscribe Disc Image

I couldn’t find any decent Lightscribe templates for a Windows 8 disk so I whipped one up myself using a mashup of others’ work. Enjoy!


The creator of the Windows 7 image this is based off has a Deviant Art account.

I was unable to find the creator of the Windows 8 logo I used in the image. Creator, if you stumble upon my website feel free to shoot me an email for recognition.

Download Windows 8 LightScribe Template (Version 1.0)
Downloaded 3388 time(s)

The Inception Button on Cydia

I received an email earlier today asking if I could get the Inception Button onto Cydia seeing as Apple has the preposterous idea that such an application provides “limited functionality” (rather than limitless functionality). I figured, why not, I’d give it a go.

After some time on IRC channels with the creator of Theos and several other helpful and knowledgeable folks I’ve managed to bring the barebones version of the Inception Button to Cydia! I’d like to thank Allen of Planet-iPhones for hosting the application. Anyone who is jailbroken should be able to install the Inception Button via the default community sources.





Automatically Delete iTunes Duplicate Songs with iDupeNuke

UPDATE: I’m finding more and more bugs as I use this. I wouldn’t recommend using it in its current state.

The various methods by which I accumulate my music often leave me with duplicate songs in my iTunes library. Having been fed up with the task of manually removing these files I decided to create a utility to do it for me. The project took me quite a bit further into the night than I anticipated however I was able to come out with an end product I’m happy to call a 0.1 Beta.

The utility is written in Java so it should, in theory, be compatible on both Windows and OS X. That being said, the only testing I’ve done has been on a Windows 7 machine and it was quite minimal. With the latest version of Java installed you can instruct iDupeNuke to remove duplicate songs in iTunes with the following code

java -jar iDupeNuke.jar

The program should proceed to analyze and neutralize any duplicate songs in your iTunes library.

I welcome suggestions, bug reports, and generic comments as I plan to expand this project and implement some sort of GUI. I hate Swing – if anyone has a recommended alternative I’m all ears.

Download iDupeNuke (Version 0.1b)
Downloaded 746 time(s)

WakeMate Reviews

Visit WakeMate Reviews

With the release of the WakeMate I decided to pull together a site to provide prospective customers with current information and reviews on the intriguing device. In addition to providing information, the site encourages people who already own a WakeMate to submit their own thoughts, comments, suggestions, and reviews.

Please feel free to post your thoughts or suggestions on the new site either in the comments here or via the WakeMate Review site itself.

The State of the Tablet Market: Q1 2011

Since the launch of the iPad in 2010 the tablet market has been developing in an interesting way. Apple had been ingenious in the years leading up to the iPad with iPhone sales consistently breaking records and defining the industry standard for the last few years. As hardware and software makers began to keep stride with the iPhones and release plethoras of Android phones along with a smattering of new BlackBerries, WebOS phones, and Windows 7 Phones Apple was able to rush the iPad to the market with a tried and tested software interface.

The iPad was a logical step that hardly anyone saw coming and even fewer people imagined could be successful. Steve Jobs recently revealed that the iPad was the idea in the first place and he rushed to make a phone out of it. The timing of the entire thing was gorgeous – not only was it able to beat the JooJoo to market (which many people thought would be a real contender) it became the clear choice for a tablet. To this day the only other real contenders are Linux or Android tablets or Windows 7 tablets. The Windows 7 tablets are a mess because, as touch friendly as that OS is, it’s not good enough to be thrown on a tablet willy nilly. The Android tablets suffer from the reverse issue – an inappropriate upscaling of a mobile OS.

Some may argue the iPad suffers from this same problem but the truth is the iPad is an entirely different experience than the iPhone. Things will start to get interesting as we see how Chrome OS might adapt on a tablet and what HP can do with WebOS (I predict a change reminiscent of iOS -> iPad OS) to make it work on a tablet.

The iPad 2 will be coming out soon likely with two cameras and the highest resolution screen on a tablet device which will push the market further in Apple’s direction and force some much needed innovation. We’re not far at all from components powerful enough that a MacBook Air-esque device will be able to boot into a more iPad-esque OS (if Apple pulls this off they’ll probably manage it without a noticeable reboot time… very doable with solid state storage) to be used as a more mobile tablet while retaining the full power of OS X either when in a docking station or on your lap as a laptop rather than in your palm as a tablet.

As it stands things are going to get very interesting in the next year and the trend shows no sign of slowing. If it doesn’t go without saying I would definitely recommend waiting until the iPad 2 at the very earliest for those of you in the market for a tablet. If you don’t like the direction Apple is heading the next best thing (disregarding any CES hooplah) is the Color Nook which runs a crippled version of Android but, in my opinion, has the right idea on the hardware front (at least until color e-ink becomes a reality).

I’ll also mention that the software developers of tablet and phone operating systems alike have to do some serious work on the notifications front before Apple plugs their obvious hole. Right now Android does it best with the pull down bar (and I think WebOS did pretty good) but there is a fine balance between user control, automation, intrusiveness, and unobtrusiveness that Apple has been searching for behind the scenes for the last few years (and slowly working towards – multitasking implementation, anyone?) and they’re bound to stumble upon it soon.

Apologies for the rough article, I’m not in a proofreading mood.

Apache Derby and Java in Mac OS X

In order to work with Apache Derby in Mac OS X you will first need the .jar files. They can be downloaded from Apache’s site here. The current release comes in several flavors:

  • bin distribution – contains the documentation, javadoc, and jar files for Derby.
  • lib distribution – contains only the jar files for Derby.
  • lib-debug distribution – contains jar files for Derby with source line numbers.
  • src distribution – contains the Derby source tree at the point which the binaries were built.

Download whichever fits your needs – the only essential files are the jar files. Execute the following line in terminal to set a DERBY_HOME variable.

export DERBY_HOME=”Insert the location of your downloaded directory”

You can then enter the next line of code into terminal to set your classpath to include DERBY_HOME (and the two needed jar files) and the root directory.

export CLASSPATH=”$DERBY_HOME/lib/derbytools.jar:.:$DERBY_HOME/lib/derby.jar:$CLASSPATH”

The Inception Button for iPhone/iPod Touch

UPDATE 4: I’ve release the Inception Button to Cydia – Enjoy!

UPDATE 3: I’ve changed my focus to Android. I’m not leaving this behind, though – I’m sure I’ll get fed up with programming Java for Android at some point and switch back to some smooth Objective-C and Cocoa Touch.

UPDATE 2: Per Cameron’s request (sorta) I’m gonna try to get this sucker into the App Store. Stand by.

UPDATE: Bad news – the app was denied due to its limited functionality. I also am planning to move on to my next project (a game hopefully running on OpenGL) rather than adding “functionality” to this Inception Button. If anyone really cares I’ll do so but I do not plan on it. Sorry people.

I have recently started to learn the basics of Objective-C and Cocoa Touch in order to create iPhone/iPod Touch applications. Earlier today I submitted “The Inception Button” to the App Store. This simple application emulates the flash application found here: http://inception.davepedu.com/. I plan to upgrade this application to add retina display support, possibly game center support, and any requested features.

I will update this post and likely post again when the application is live in the App Store. Feel free to leave suggestions on the iTunes Store comments area or on my site here. I’ve also included screenshots of the application running on my iPhone 4 along with the build in xCode. Oh and the application is 100% free and ad-free… I’m not sure what I’ll do as I add more and more but there will always be a free version.

The sound clip used for the app is available for download below as well.

Download Inception Sound (Version 1.0)
Downloaded 4436 time(s)