5 April 2009

Sony Ericsson Theme File Format

Recently I wanted to pimp my Sony Ericsson mobile and add some nice themes (.thm files). There were plenty of them around and I just downloaded a collection of some hundred free ones. Unfortunately most came without a preview image and going through these on my mobile to find nice ones was painstaking and slow: I had to activate each of them, return to the standby mode, check out the main image, return to the theme manager, and start over again. What I needed was some kind of theme browser. I did not trust the Sony Ericsson Themes Creator application to provide browsing and did not bother installing it.

Sony Ericsson G705 - Keypad As being a hard core developer I had a look into the THM files. I STFW but could not find any resources explaining the file format. So I explored it a bit myself. Here is what I found together with some Ruby code.

Sony Ericsson Theme File (.THM) Format
The file contains several files concatenated together with some kind of header before the data.
  • At 0x0000 a null-terminated string with the name of the original file. Remaining bytes are all null. This is read with name = data[ofs..ofs+0x63].strip.
  • At 0x0064 several null-or-blank-terminated strings containing octal numbers. The number fields may contain blanks which are treated as separators as well. Parse them with
    numbers = data[ofs+0x64..ofs+0x100].
      scan(/[0-7]+/).
      collect { |n| n.to_i(8) }
  • The only important number is the fourth (body_len = numbers[3]), which is the length of the data body in bytes. If this number is not positive then the file is corrupt.
  • At 0x0101 there is most of the time the string ustar and at 0x0129 nogroup, but we do not need them.
  • At 0x0200 starts the data: body = data[ofs+0x200...ofs+0x200+body_len].
  • After 0x0200+body_len the space is filled with nulls until the next address continuing a zero low-byte. We just skip them until data[ofs] != 0.
  • Repeat these steps until EOF.
Usually the first item in the theme file is called Theme.xml. This is an XML configuration file and looks something like
<Sony_Ericsson_theme version="4.5">
  <Background Color="0xb5f8fd"/>
  <Background_image Source="desktop.png"/>
  <Desktop Color="0xb5f8fd"/>
Sometimes it's not called in this way, but any XML file will do. The Color looks like a regular HTML Colour Code. The Source is a reference to an image stored inside the theme file. The important image types are
  • Standby_image - main image.
  • Desktop_image - background in the menu.
  • Popup_image - background of popup.
  • There are a lot more, but often these three images are reused in smaller themes.
Knowing the standby image name, it is possible to extract it to the file-system (File.open(filename,'wb') {|io| io.write body}). Then browsing these preview images with some image utility and deleting unwanted ones is a piece of cake. The whole Ruby program is here. Have fun!

3 comments:

José said...

You know, the .thm files are actually plain old .tar files. You can open them with any decent decompression program (in Windows, I personally use IZArc)

Once open, you get that XML file you saw plus (possibly) a bunch of .png, .jpg .gif, or .swf files. It's really nothing special.

José said...

Oh, and btw... see if this link works for you: Themes Developer guide

Peter Kofler said...

Thanks José, knowing that it's a TAR would have saved me some work. (But know I know I reverse engineered tar format ;-) I'm wondering why the chose such an old file format...