Try to copy codes from dmg2img, first decode dmg.