Running OSX through VirtualBox within Windows 7 environment running Bootcamp

I have a great MacBook Pro with awesome retina display, but I mostly run Windows 7 on it through bootcamp. Given that I often have to make iOS related tests, and that switching back and forth between OSX and Windows 7 was quite painful, I decided to try to run OSX as a virtual OS within Windows instead of Windows as a virtual OS within OSX.

If you want to do the same here are the simple things you need to do

1. Open regedit to export a backup of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\AppleHFS and HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\AppleMNT
2. Keep regedit opened and delete HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\AppleHFS and HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\AppleMNT
3. Reboot and make sure the OSX drive is not visible anymore as D: drive
4. Run in command line “C:\Program Files\Oracle\VirtualBox\VBoxManage.exe” internalcommands createrawvmdk -filename c:\RawAppleDisk.vmdk -rawdisk \\.\PhysicalDrive0
5. Open VirtualBox, create a new type “Mac OS X” with version “Mac OS X (64-bit)” virtual machine.
6. When asked to create a drive, select “Use an existing virtual hard drive file” and click the orange folder button, select the RawAppleDisk.vmdk that you created in step #4, it should be at the root of C: but you can move it anywhere you like before adding it to the virtual machine.

Et voila! Now your virtual machine should boot and run OS X as a virtual OS within Windows 7 running native on genuine Apple hardware :)

You can learn more about VirtualBox guest limitations for OSX here. And how to change the guest screen resolution here.

Extracting Javascript From PDF, and Replacing Javascript Into PDF

Not being able to find easy to use tools to extract the javascript code contained in a pdf file in plaintext, nor tools to update the javascript in a pdf without changing anything else. I wrote those two small command line java tools using the excellent iText library.

PDF2JS will extract the javascript from the pdf passed as argument. On windows an example way to use it is: “java -jar pdf2js.jar myinput.pdf”, and it will output the javascript in

JS2PDF will replace the javascript in the input pdf file, and write the result into the output pdf file. On windows and example way to use it is: “java -jar js2pdf.jar original.pdf javascript.js output.pdf”, the file output.pdf will contain the updated javascript.

For those interested the very simple code for each tool is provided within the archives.

Also if the pdf file you are working with has usage restrictions, make sure you remove them using the excellent qpdf with the following command line: qpdf –decrypt protected.pdf output_unprotected.pdf