Sunday, June 20, 2010

Bit of Hex Education

So I've started my Virtua Tennis Savegame editor, so in order to follow, I need to teach you about hex. So firstly, the easy stuff.

If you want to get properly confused, go to the Wiki Page but here's a nicer one:

Hex is base 16, i.e. numbers go from 1-16, we usually deal with base 10, (since that's the number of fingers we have), but hex is from 0 to 15, inclusive, so we get our 16.

Also instead of having 10 to 15, we have A-F, (aside, why A-F, why not A-Z and we get even more numbers?).

So therefore, lets take 29 in denary

Binary = 11101

Hex = 1D

So easier to store and easier to read, if that was just denary, the most we could store is 100 values from 00-99, in hex, we can store 00-FF which is 256 values.

Next thing to know is Endianness, so Big endian and Little Endian and Most Significant and Least Significant bit.

In a big endian systems, the most significant bit is the furthest to the right, go back to our 29 in binary.

16 8 4 2 1
1 1 1 0 1

So in this instance, the most significant bit is the bit in the 16's column and least significant bit is the 1's column. This is how everyone learns binary.

The Virtua Tennis Savegame is stored in LSB, so therefore in this case it'd be.

1 2 4 8 16
1 0 1 1 1

So once we figure out the values, you'll need to swap the values backwards in order to make the change, but since we are doing it in hex it'll be like this.

Hex = 0A 01

Big Endian = 0A 01 = 2561
Little Endian = 01 0A = 266

The reason I think it's stored in Little Endian is because the PC Port, was just emulated, from the Dreamcast version which runs in Little Endian.

So there's my Hex Education, I'm sure I'm missing stuff. This is just a tasty for when we start hacking the file.

Saturday, June 19, 2010

Fixing N95 8GB keypad and save yourself money!

Problem: My N95 8GB keypad stopped working and just broke into pieces, cost for some one to fix it, £30-£40.

I'm a cheap bloke, so I decided to fix it, this is how I did it!

Firstly, I looked for a new case this is called "housing", so ebay time.

Ebay search for N95 8GB

It took about 3 weeks for the delivery and it was about £3.50 and from Hong Kong! (How do they make money?) I bought a White one to make it look sexy.

It should come with the Torx 4/5/6 tools, for you to dismantle your phone, i.e. the for the screws that look like stars.

This is probably the best video

I just did it myself, I then found I needed to get a new membrane for £8

Ebay search for N95 8GB Membrane

I then replaced it, so for under £15 I managed to fix my keypad, get a new case and learn how my phone goes together.

This post is shorter but it took me a while to find what I needed and get replacements and keep my phone working till I get my HTC Desire!!

Wednesday, June 16, 2010

Getting HTC Desire working with ADB

Got an HTC Desire, I tried installing the Drivers with the Android SDK, it wouldn't work, I first had to enable USB Debugging.

Settings -> Applications -> Development -> USB Debugging

Plugging it in, it wanted to install ADB (Android Debug Bridge)I first tried updating the .inf file

;HTC Desire
%SingleAdbInterface% = USB_Install, USB\VID_0BB4&PID_0C87
%CompositeAdbInterface% = USB_Install, USB\VID_0BB4&PID_0C87&MI_01

This made it install. Yay!
But, running adb devices in the tools folder of the SDK showed it wasn't working.

I then looked on HTC Site for Drivers and found the HTC Sync here:

Downloaded installed it and then removed the Device and added it again.
adb devices then showed it and Eclipse then saw it.

Friday, June 04, 2010

Bitmap Serialize

So I've been tasked to fix a database full of pictures that weren't displayed, no matter what I tried, the Image (Stored as a byte array) was always invalid.

So I thought I'll save the file and see if I can get an image fixer on it, I just used a FileStream opened it and wrote to it

var fileStream = new FileStream("output.dat", System.IO.FileMode.Create);
fileStream.Write(bytes, 0, bytes.Length);

Upon opening the file, I was expected to see something beginning with "Exif" or "JPG" or something, but what I saw was even better.

System.Drawing, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

A, ha!! The actual Bitmap object was being saved, not the actual Image, therefore I put together a bit of code to get me the Image and put it back as the Image for my code to work correctly. In this case, I could fix it, but if I couldn't I'd have to have a bit of a legacy converter for it.

public static Bitmap BitmapObjectToBitmap(byte[] data)
using (var ms = new MemoryStream(data))
var bf = new BinaryFormatter();
Bitmap bitmap = (Bitmap)bf.Deserialize(ms);
return bitmap;

Then the working code for the Image to Byte Array

public static byte[] ImageToByteArray(Image image, ImageFormat format)
using (var ms = new MemoryStream())

var bm = new Bitmap(image);
bm.Save(ms, format);
return ms.ToArray();


Comments welcome!!

Transfer Data between two SQL Server's

Everyone probably knows this, but hey ho.

I needed some data from one of my tables in one server to be inserted into another, here is the simplez SQL to do it.

insert into Server1.Database.dbo.Table(Col1,Col2,Col3)
select Col1,Col2,Col3
from Server2.Database.dbo.Table

thanks to @duncansmart just a bit more info, I'm running on 2008 R2, on previous systems you may need to run

Execute sp_addlinkedserver Server1

To link in the other Server