How to open a DMG file in Windows?

So for some reason or another you need to get something from a DMG file and there isn’t a Mac in the vicinity. It is possible, and you don’t need to pay $50 for something like MacDrive.

For the super lazy and non-koder types you can use dmg2iso to create an ISO from the DMG file. Then mount the ISO with some windows ISO mounting software.

I didn’t do this. I downloaded the source to dmg2img and read the README. Yes, I actually read README files, why do you think they’re named so? This pointed me in the direction of libdmg-hfsplus.

People looking for a more professional tool should take a look to the libdmg library and related utilities at

http://github.com/planetbeing/libdmg-hfsplus/tree/master

http://www.shanemcc.co.uk/libdmg/

(the libdmg code is still reported to be experimental, though, and it is also much bigger than dmg2img.)

Build the Tools

Download the latest version of libdmg-hfsplus , the git enlightened can execute:

git clone git://github.com/planetbeing/libdmg-hfsplus.git

libdmg-hfsplus uses CMake so make sure you have cmake installed. You can either install the cygwin package or get the latest Windows version. I recommend the cygwin version since that’s what I used.

Execute these commands in the root libdmg-hfsplus directory:

cmake ./
make

Now you’ve built the tools you need to cut through DMG files like butter.

  • dmg.exe
  • hdutil.exe
  • hfsplus.exe

Copy the exe files somewhere that is in your path (~/bin for example).

Use the Tools

To test this out you’re gonna need a DMG file. You can download the DMG file I used here. It’s zipped up so you should probably unzip it.

Of the three executable files you built the only one you really need to use is hdutil. Here is the command to list the contents of a DMG file.

hdutil SunFlowerPublic-0.7.dmg ls

The ls command will also take a parameter which will let you explore the contents of the DMG file system.

hdutil SunFlowerPublic-0.7.dmg ls /SunFlower.app/Contents

The extract command wants two arguments. The first is the location of the file in the DMG file. The second is where to put the file on your machine.

hdutil SunFlowerPublic-0.7.dmg extract /DMG_backgroundPro.png local.png

Use the extractall command to pull out everything in one fell swoop.

hdutil SunFlowerPublic-0.7.dmg extractall

Finally the easiest way to extract the DMG to a clean directory is to create a new directory and call the extractall command from that location.

mkdir explodedDMG
cd explodedDMG
hdutil ../SunFlowerPublic-0.7.dmg extractall

The core code of libdmg-hfsplus appears to be system independent so this should all work with Linux also.

Kode on!

References:

Comments are closed.