Tuesday, March 25, 2008

Decrypt the stored procedure, and etc

When you try to hide something from someone, people always have their own way to dig it out. Just like you thought 128-bit encryption is un-decryptable, especially on symmetric encryption , people still can know you initialization vector (IV) by de-compiling your source-code using deflector, if you did not obfuscate it (Oops, or even obfuscation is not safe too?). Then all your effort on encryption/information-hiding is wasted. Same goes to MSSQL 2000 built-in encryption for stored procedures (SPs/sprocs), etc.

The syntax for MSSQL 2000 built-in encryption on CREATE PROCEDURE is:

CREATE PROC [ EDURE ] procedure_name [ ; number ]
[ { @parameter data_type }
[ VARYING ] [ = default ] [ OUTPUT ]
] [ ,...n ]
AS sql_statement [ ...n ]

To decrypt it, for novice user, you can download the freeware (Unless you wanna pay the money for this software?) called "dSQLSRVD", just log in and find those SPs with checkboxes checked, highlight it and click "Save", you can get the content of the stored procedure you desire. Easy, huh?

For average developer, maybe you can go to this site (please take note this method seems have limitation on the size of nvarchar(4000), you might need to roll back if your encrypted SP is long), or this site, and try to come out your version of freeware, though you can find a ready-made workable sql script if through a thorough search.

Final piece, Windows applications is too common and thus make it too popular for developers to crack it. You better depend on your own.

p/s: In MSSQL 2005, there's few new features added,
1) EncryptByAsymKey
2) EncryptByCert
3) EncryptByKey
maybe it's worth for try.

Sunday, March 2, 2008

Resize the virtual harddisk size (2) : expand C-drive

From last week, I expanded the hard-disk size successfully. But I am not satisfied with the end result, what if I just want to expand the main primary partition (aka C drive), not adding another secondary partition?

I found the PartitionMagic and it seems able to do the job by merging the partitions, but it is not free. I need a free software to achieve that and I found GParted. Since it's used mainly for *nix environment, I knew it not gonna be user-friendly. There's not executable files for you to run it on Windows. Lucky, the liveCD is designed to solve this problem across the platform.

So, here are the steps to merge the partitions using GParted:

1) Capture the GParted liveCD iso image from the Virtual PC Console.

2) Reboot the OS.

3) After reboot, the Gnome Partition Editor will be loaded. Select the "GParted-liveCD Force VESA Driver" (If you have problem on "GParted-liveCD XXX (auto-configuration)", you better select this one, how do you know? Your screen will totally blank later.)"

4) You will be asked to key-in the keymap twice. Hit enter to proceed.

5) Now the main app will load. Since there is some reading problem on the PS/2 mouse, you would not be able to use the mouse. Quoted from Arcane Code:
"First, let me take a second to explain what the issue is. There was a bug in the kernel code that affected many different distros of Linux. Apparently the kernel was not finding PS/2 style mice. Some work has been done and now most PS/2 style mice are now being found.
Except, sadly for the ones being emulated. Both VMWare and VirtualPC emulate a PS/2 style mouse, and are not getting found by the kernel. Remember, it doesn’t matter what type of mouse you have hooked up to the host box (I have two mice, a Logitech MediaPlay and Microsoft Travel mouse, both USB). It only matters what the virtual machine is telling the guest OS (Ubuntu), which is PS/2 style mouse."
Now you have to go back to old day practice : using keyboard.

6) Press "Tab" key until the main drive is selected. You will know when the row is highlighted.

7) Now press "Alt-P" and "Down" arrow key to select the "Resize/Move" menu.

8) Leave the "Free Spacing Preceding" and key-in how much size you want to expand in "New Size" textbox. The "Resize/Move" button will be enabled once you made changes. Use "Tab" to move the focus to "Resize/Move" button and hit "Enter".

9) Use "Alt-E" and "Down" arrow key to select the "Apply All Operations". Partition merging will be started.

10) Once it's done, turn-off the Virtual PC and reboot.

11) This time, select "Boot partition #1 on the first hard drive". (You need to scroll down if you did not see it from the Gnome Partition Editor.

12) Windows will load and check for the disk consistency. Let it do the dirty job and it will reboot twice.

13) Eventually, the partition merge is done and now you will see the extra hard-disk space increase on the main primary partition. (You might need to release the iso image captured on step 1 after done)

Here's the link where you can capture the screen-shoot on VPC.