Code Painters The Art of Coding

29Mar/120

Why RS232 uses negative voltage when idle?

Have you ever asked yourself this question? I've found it answered in April issue (261) of Circuit Cellar, in Test Your EQ section. The answer is quite intriguing.

First of all, DTL and TTL logic families were the most popular when RS232 was developed. In both DTL and TTL input current is significantly lower in the high state (a TTL input is equivalent to NPN transistor's emitter), so it makes perfect sense to use high state when idle to minimize the power consumption in the logic part.

The second part of the story is more funny. Why is high state represented by negative voltage on the line? This is because copper wires exposed to moisture are less likely to corrode if the voltage is negative. Indeed, it's the anode (positive electrode in electrolytic cell) where the oxidation happens. Beautiful explanation, isn't it?

22Mar/120

How to make Stanza work on iOS 4

Stanza is my personal preference when it comes to ePub readers for iPad. Good performance, very comfortable user interface and, last but not least, it's free! Unfortunately, after upgrading to version 3.2 it doesn't work any more on iOS 4.x and I don't want to upgrade my jailbroken iPad yet.. But hey, there's a relatively easy workaround. All you need is a jailbroken iDevice and a hex editor. Continue reading…

Tagged as: , , No Comments
17Feb/120

Why java.nio is a better idea for Android

In my recent Android project I've encountered totally unexpected, low-level problems with TCP sockets. The problem occurs when you try to interrupt a blocking socket I/O by closing the socket. It is expected for the blocked operation to throw a SocketError exception immediately when the socket is closed from another thread (that's the only way to interrupt blocking socket operation, actually - Thread.interrupt() doesn't abort blocked I/O). Continue reading…

15Feb/120

Flashing LPC1342/43 from Linux

The LPC1342/43 bootloader code is a great feature, allowing for firmware upgrades over USB with no additional hardware (given USB socket is there). Simply pull PIO0_1 low, reset the chip and it enumerates as a mass storage USB device. Copy over the firmware binary and you're done. Cool, isn't it? At least in theory, as my first attempt to flash the MCU using my Linux box simply failed - the firmware got corrupted. Continue reading…

17Jan/120

How to obtain GTalk Android ID

While googling around, I've stumbled upon an interesting project - Android Market API. This project is clearly a result of some Android reverse engineering work, still it's hosted on Google Code site. Funny, isn't it? Oh, by the way - the Android Market protocol uses Google's Protocol Buffers with HTTP as a transport layer.

Anyway, to play with the API you need a Google account (obviously), but also a sort of device identifier referred to as "Android ID". Funny enough, this is not the Android ID which can be obtained using android.provider.Settings.Secure class etc., the right ID can be obtained by "dialing" *#*#8255#*#* - look for Device ID, remove `android-` prefix.

But is there a way to retrieve this ID programmatically? It required a bit of hacking to reveal, but here's the recipe:

	private static final Uri URI = Uri
			.parse("content://com.google.android.gsf.gservices");
	private static final String ID_KEY = "android_id";

	String getAndroidId(Context ctx) {
		String[] params = { ID_KEY };
		Cursor c = ctx.getContentResolver()
				.query(URI, null, null, params, null);

		if (!c.moveToFirst() || c.getColumnCount() < 2)
			return null;

		try {
			return Long.toHexString(Long.parseLong(c.getString(1)));
		} catch (NumberFormatException e) {
			return null;
		}
	}

This code requires extra com.google.android.providers.gsf.permission.READ_GSERVICES permission, be sure to add the following line to your AndroidManifest.xml:

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

That's it!

13Feb/116

Reverse engineering Android applications – part I

Have you ever wondered how difficult or easy is it to reverse engineer an Android application? The task is surprisingly easy with all the tools available these days. Let's try to reverse engineer a sample open-source application available for download from Android Market - Barcode Scanner. For all the experiments I've used my HTC Desire. Continue reading…

15Jan/110

Android MediaPlayer and short WAV files

I've recently observed an interesting issue with MediaPlayer on HTC Desire and Legend (I had no chance yet to check other phones) - it refuses to play a short, otherwise perfectly valid 22050Hz linear PCM 16-bit WAV file. Strictly speaking, there's no error reported or any exception visible in logs, but also there is no sound played.

The only exceptional thing about the WAV files we used is the length, the files are about 80ms each - short beeps to play as a button press feedback. To solve the problem it was necessary to append a period of silence to each file, to make it at least 200ms long.

I can guess the reason - perhaps the media player implementation disables the decoder right after injecting the last chunk of data, not waiting for this very last chunk to decode?

20Nov/1057

Android emulator patch for configurable IMEI, IMSI and SIM card serial number

My post about hacking the emulator's IMEI number gained a lot of interest, hence I've decided to prepare a patch which makes IMEI, IMSI and SIM card serial configurable on a per-AVD basis. It's necessary to recompile the emulator with the patch applied, so setup your build environment as a first step. I suggest using Ubuntu 10.10 and following the Android compilation hints. Continue reading…

Tagged as: , 57 Comments
16Nov/100

Cherokee SIGSEGV fix accepted

It seems that my patch for the Cherokee redirect handler's SIGSEGV problem has been accepted. That's exactly what I love about open-source software - instead of waiting for the software vendor to fix the problem I can do the correction myself. Just released Cherokee 1.0.9 doesn't contain the fix yet, though, it's going to be included in the next release.

3Nov/100

Mac OS hint – color picker

Mac OS X is equipped with a decent color picker dialog, but unfortunately it can be used only from within some host graphic application - there's no standalone color picker. This ColorPicker utility comes to the rescue. Next thing to install is Hex Color Picker, which displays the current color as a hexadecimal number, ready for copy & paste into HTML or CSS file. Now it's perfect, isn't it?

Tagged as: No Comments