Visual Studio 2012 - Update 2

After long time in CTP, Visual Studio 2012 finally got its second update.

Quite a lot of changes touch agile workflows and this alone will make it worthwhile. Unlike update 1, there are actually quite a few changes related to development so this is definitely update to install.

Update is cumulative so you don’t need anything other than base Visual Studio 2012 installation. Go forth and download.

PS: My favorite new feature is grouping of unit tests by class name and possibility to add them in playlists.

PPS: Feature that I wish I had is new Code Map. Unfortunately it is not available on Visual Studio 2012 Professional and below. :(

From One to Two Processors in Windows XP

I used to have physical machine running XP that could not be upgraded (don’t let me start about reasons… :/). Since having old machine around gets annoying quite quickly, I used Sysinternals disk2vhd in order to have it work in VirtualBox. And it worked flawlessly. Or so I thought.

Few days ago I tried to run a bit higher load on this virtual machine and I was surprised to learn that only single processor was used regardless of two virtual ones that were available. Task manager simply reported one processor while it was clear from Device Manager that there were two available. This curiosity probably had lot to do with detected Advanced Configuration and Power Interface (ACPI) PC which actually has no multiprocessor support.

When I checked boot.ini its content was:

[boot loader]
timeout=3
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect /KERNEL=ntkrpuni.exe /HAL=halacpi.dll

Notice how there uniprocessor HAL is forced by using /KERNEL=ntkrpuni.exe /HAL=halacpi.dll. This happens when you use disk2vhd to do physical to virtual conversion. In order to make it more compatible, it will restrict it to single processor. To have any chance of detecting second processor you must remove both /KERNEL and /HAL arguments completely.

Next step is to actually replace HAL. Official way of doing this is Windows recovery but there is also a possibility of using devcon.exe command-line tool. Its example code page lists Forcibly update the HAL as example 44. This sounds exactly as something we would need.

Procedure is simple:

> devcon sethwid @ROOT\ACPI_HAL\0000 := +acpiapic_mp !acpipic_up
ROOT\ACPI_HAL\0000 : acpiapic_mp
Modified 1 hardware ID(s).

> devcon update c:\WINDOWS\inf\hal.inf acpiapic_mp
Updating drivers for acpiapic_mp from c:\WINDOWS\inf\hal.inf.
Drivers updated successfully.

If everything went ok, you will need to restart. And then restart once more when asked to. After second boot your Windows XP system will (hopefully) use both processors.

PS: If you ever want to get back to using single processor, it is even simpler - just re-add /KERNEL=ntkrpuni.exe /HAL=halacpi.dll to your boot.ini entry.

PPS: Do not forget to backup your virtual machine before doing this stuff.

Gone

Illustration

Every restart I get familiar UAC prompt. And it is not a Microsoft’s fault for once. No, this is torture by Oracle ™.

Java updater is a perfect example of how things SHOULD NOT be done. For start we have uploader that requires account elevation for simple task of downloading newest update. All other programs can do the same with lowly user credentials.

Things get even worse if you are actually using Java while update is being done. As it is usual with installers, this one will require restart. But only to start whole process from scratch instead of completing it. If you have Java program starting with system, whole thing turns into exercise of futility.

Just to remind you that morons are all around, this thing will also pop up after restart even if there is no update pending. It would be shame to skip annoying user. Solution is simple.

Just disable this idiotic thing.

Not Java mind you. Java is nice programming language that is still not completely ruined by Oracle. Just kill updater. Security wise this is not smartest thing you can do. But you know what? I don’t care. It is only decision that sane person can make after being subjected to this.

PS: And don’t let me get started about Oracle’s practice of installing junk (yes, Ask toolbar, you are junk) with its runtime.

Crypt-compatible Passwords in C#

For hashing passwords I usually use SHA-256 PBKDF2. No project I ever made needed anything better than this. There is only one problem with this hashing function - it is not really compatible with anything.

Kinda unofficial standard for password hashing is an Unix crypt function. You can recognize its passwords by following format: $id$salt$hash. It was originally used for hashing user password on *nix systems but with time it became common format for other usages also.

After scouring Internet to find C# implementation I decided to code it myself. It seems that C# porting stopped for everybody with MD-5 variant of crypt. While that lowest common format supported quite a few use cases, I wanted to use a bit newer SHA-512 based hashing. It should have been just an hour of coding. Eventually it took me almost eight to get it working.

Few things took me by surprise during development. I was surprised how many pointless steps were in SHA-256/512 hash creation. Best example would be base-64 implementation that not only uses incompatible character set but it also shuffles bytes around before encoding. These steps don’t add any security nor they serve to slow attacker.

Lack of proper specification for MD-5 hash was annoying more than anything else. For most of part I used just specification for SHA-256/512 combined with reference implementation in C. Yes, it wasn’t mission impossible, but lack of description for something that is part of every Unix/Linux system for more than decade is an annoyance at best.

Sample supporting MD-5 ($1$), Apache MD-5 ($apr1$), SHA-256 ($5$) and SHA-512 ($6$) password generation is available for download.

PS: If you are interested in test cases for it, you can check Medo.dll repository.

Naughty ArgumentException

Writing a function you probably write following checks as a reflex:

void DoSomething(string argument) {
    if (argument == null) {
        throw new ArgumentNullException("argument", "No nulls allowed!");
    }
    if (argument == string.Empty) {
        throw new ArgumentOutOfRangeException("argument", "No empty strings!");
    }
    if (Environment.Foo && (argument == "bar")) {
        throw new ArgumentException("argument", "Something else!");
    }
    ...
}

Yep, there is an error in third “throwing”. For some unknown reason ArgumentException needs parameters in a different order. Correct statement would be:

    ...
        throw new ArgumentException("Something else!", "argument");
    ...
}

What will happen if you mess it up?

Well, nothing much. Exception will still be thrown and your code should be fine. You will see wrong exception text but any stacktrace will probably lead you to correct spot in code.

But it looks ugly.