1) You need root
2) You need Terminal Emulator (free from the market)
Open the Terminal Emulator app and type:
strings -n 8 /dev/block/mmcblk0p7 [enter]
you will then get loads of codes and other stuff.
Look for your IMEI number and the unlock code will be above. If u get just a date then sorry you cant get the unlock code Write the unlock code down and put a sim that normally wouldnt work into your phone and power it on. then enter your unlock code u just wrote down
look at the piccy below the unlock code is marked with the arrow.
This will only work with Sim LOCKED devices. as mine is already sim unlocked by htc i cant unlock mine and i get a weird code. but my friends unlocked fine with his code I take NO responsibility if u break or damage your device. this is for educational purpose only
the code may not exist in a factory-unlocked phone (only a carrier-locked one).