Git Product home page Git Product logo

darling-dmg's Introduction

darling-dmg

This project allows ordinary users to directly mount OS X disk images under Linux via FUSE. darling-dmg is part of Darling - http://www.darlinghq.org

Without darling-dmg, the only way to do this would be to manually extract the DMG file, become root and mount the HFS+ filesystem as root. This is slow, wasteful and may even crash your system. The project's author has seen the Linux HFS+ implementation cause kernel crashes.

Supported file types

  • DMG (UDIF) files containing an Apple Disk Image.
  • Apple Disk Images containing an HFS+/HFSX file system.
  • HFS+/HFSX file systems (incl. file systems embedded within HFS).

This means, darling-dmg can mount DMG files or unpacked DMG files or a single partition carved out of the latter.

Read only access only.

Build Requirements

Dependency Required version Notes
GCC/Clang >5 (GCC), >3 (Clang) Compiler with C++11 support
CMake 3.10 Build system
pkg-config Library-agnostic package detection
OpenSSL Base64 decoding
Bzip2 Decompression
Zlib Decompression
FUSE 2.x (not 3.x) Userspace filesystem support
libicu Unicode support
libxml2 XML (property list) parsing

darling-dmg requires a C++11-capable compiler, CMake >3.10 and make alongside the remaining dependencies mentioned above. Below are common ways to install library dependencies.

On Fedora (and derivatives):

sudo dnf install fuse-devel bzip2-devel libicu-devel libxml2-devel openssl-devel zlib-devel pkgconf

On Debian (and derivatives):

sudo apt-get install libfuse-dev libbz2-dev libicu-dev libxml2-dev libssl-dev libz-dev pkg-config

On Alpine Linux:

sudo apk add fuse-dev bzip2-dev icu-dev libxml2-dev openssl-dev zlib-dev pkgconf

Usage

darling-dmg <file-to-mount> <where-to-mount> [FUSE arguments]

Accessing resource forks

Resource forks are available via xattrs (extended attributes) or preferably under the name /original/filename#..namedfork#rsrc.

Reusability

Some people have had success with using darling-dmg as a library for their own use.

darling-dmg's People

Contributors

bugaevc avatar curioustommy avatar elielcohen avatar facekapow avatar fredericgermain avatar hintak avatar icebreaker avatar jief666 avatar kwvg avatar lubosd avatar mrolappe avatar stek29 avatar tomkoen avatar tpoechtrager avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

darling-dmg's Issues

HFS: invalid calculation of files size (zero)

Sometimes darling-dmg doesn't correctly report files size inside HFS file system. I think it's an important issue.

Code to reproduce: https://gist.github.com/sipx/4b9b1c9f9157eb1e6aa1
Output: https://gist.github.com/sipx/5601a729df06b06b1889

As you can see darling-dmg reports many files as zero-sized, but it's not correct - when you open this DMG with 7zip, it correctly displays sizes, and you can extract those files as well.
Screenshot with 7z: https://www.dropbox.com/s/k92ekdkyd732g85/7z_works_fine.png?dl=0

DMG to reproduce (5GB, I'm sorry - the only one I have at the moment):
https://www.dropbox.com/s/tpimco03g3276w1/OS%20X%20Yosemite%2010.10.2%20%28Installer%29.dmg?dl=0 (SHA-1: 9AA37847A20848634C7B15D49D078AC774FB8426, you can download this file from other places if you will google for this SHA-1)

darling-dmg issue with Fedora 25 (findLeafNode() crashing when in debug mode)

Hi !

I've been trying to get darling-dmg working under Fedora 25. I currently run into two issue :

  • darling-dmg, when normally run (darling-dmg mydmg.dmg /mnt/mountpoint), ends abruplty
  • trying to sort things in debug mode, I ran darling-dmg in debug mode and got a SIGSEGV. I compiled it again with debug info and ran it in GDB :
(gdb) run testimg.dmg /tmp/atvos -d
Starting program: /home/jeanthomas/Applications/darling-dmg/darling-dmg testimg.dmg /tmp/atvos -d
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Skipping partition of type Apple_partition_map
Using partition #1 of type Apple_HFS
Everything looks OK, disk mounted
Detaching after fork from child process 27709.
FUSE library version: 2.9.7
nullpath_ok: 0
nopath: 0
utime_omit_ok: 0
unique: 1, opcode: INIT (26), nodeid: 0, insize: 56, pid: 0
INIT: 7.26
flags=0x001ffffb
max_readahead=0x00020000
   INIT: 7.19
   flags=0x00000011
   max_readahead=0x00020000
   max_write=0x00020000
   max_background=0
   congestion_threshold=0
   unique: 1, success, outsize: 40
unique: 2, opcode: ACCESS (34), nodeid: 1, insize: 48, pid: 1891
   unique: 2, error: -38 (Function not implemented), outsize: 16
unique: 3, opcode: LOOKUP (1), nodeid: 1, insize: 47, pid: 1891
LOOKUP /.Trash
getattr /.Trash
hfs_getattr(/.Trash)
File not found: /.Trash
   unique: 3, error: -2 (No such file or directory), outsize: 16
unique: 4, opcode: LOOKUP (1), nodeid: 1, insize: 52, pid: 1891
LOOKUP /.Trash-1000
getattr /.Trash-1000
hfs_getattr(/.Trash-1000)
File not found: /.Trash-1000
   unique: 4, error: -2 (No such file or directory), outsize: 16
unique: 5, opcode: GETATTR (3), nodeid: 1, insize: 56, pid: 27725
getattr /
hfs_getattr(/)
   unique: 5, success, outsize: 120
unique: 6, opcode: OPENDIR (27), nodeid: 1, insize: 48, pid: 27741
   unique: 6, success, outsize: 32
unique: 7, opcode: READDIR (28), nodeid: 1, insize: 80, pid: 27741
readdir[0] from 0
hfs_readdir(/)
   unique: 7, success, outsize: 888
unique: 8, opcode: LOOKUP (1), nodeid: 1, insize: 53, pid: 27741
LOOKUP /Applications
getattr /Applications
hfs_getattr(/Applications)
   NODEID: 2
   unique: 8, success, outsize: 144
unique: 9, opcode: LOOKUP (1), nodeid: 1, insize: 51, pid: 27741
LOOKUP /Desktop DB
getattr /Desktop DB
hfs_getattr(/Desktop DB)
   NODEID: 3
   unique: 9, success, outsize: 144
unique: 10, opcode: GETXATTR (22), nodeid: 3, insize: 68, pid: 27741
getxattr /Desktop DB security.capability 20
hfs_getxattr(/Desktop DB, security.capability)

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff795cc1b in HFSBTree::findLeafNode (this=0x0, indexKey=0x7fffffffd3e0, comp=0x7ffff7968cba <HFSAttributeBTree::cnidAttrComparator(HFSBTree::Key const*, HFSBTree::Key const*)>, 
    wildcard=false) at /home/jeanthomas/Applications/darling-dmg/src/HFSBTree.cpp:45
45		return traverseTree(be(m_header.rootNode), indexKey, comp, wildcard);
(gdb) bt
#0  0x00007ffff795cc1b in HFSBTree::findLeafNode (this=0x0, indexKey=0x7fffffffd3e0, comp=0x7ffff7968cba <HFSAttributeBTree::cnidAttrComparator(HFSBTree::Key const*, HFSBTree::Key const*)>, 
    wildcard=false) at /home/jeanthomas/Applications/darling-dmg/src/HFSBTree.cpp:45
#1  0x00007ffff7968a3a in HFSAttributeBTree::getattr (this=0x0, cnid=19192, attrName="security.capability", dataOut=std::vector of length 0, capacity 0)
    at /home/jeanthomas/Applications/darling-dmg/src/HFSAttributeBTree.cpp:63
#2  0x00007ffff797ac2e in HFSHighLevelVolume::getXattr (this=0x6ec450, path="/Desktop DB", name="security.capability")
    at /home/jeanthomas/Applications/darling-dmg/src/HFSHighLevelVolume.cpp:257
#3  0x000000000040ee67 in <lambda()>::operator()(void) const (__closure=0x7f8b20) at /home/jeanthomas/Applications/darling-dmg/src/main-fuse.cpp:276
#4  0x000000000040ffb3 in std::_Function_handler<int(), hfs_getxattr(char const*, char const*, char*, size_t)::<lambda()> >::_M_invoke(const std::_Any_data &) (__functor=...)
    at /usr/include/c++/6.4.1/functional:1717
#5  0x000000000041136c in std::function<int ()>::operator()() const (this=0x7fffffffd990) at /usr/include/c++/6.4.1/functional:2127
#6  0x000000000040e194 in handle_exceptions(std::function<int ()>) (func=...) at /home/jeanthomas/Applications/darling-dmg/src/main-fuse.cpp:141
#7  0x000000000040f061 in hfs_getxattr (path=0x6ace00 "/Desktop DB", name=0x797b60 "security.capability", value=0x77f9a0 "Hk\v\366\377\177", vlen=20)
    at /home/jeanthomas/Applications/darling-dmg/src/main-fuse.cpp:283
#8  0x00007ffff7ba9fee in common_getxattr () from /lib64/libfuse.so.2
#9  0x00007ffff7baa0d7 in fuse_lib_getxattr () from /lib64/libfuse.so.2
#10 0x00007ffff7bb04c1 in fuse_ll_process_buf () from /lib64/libfuse.so.2
#11 0x00007ffff7bac86c in fuse_session_loop () from /lib64/libfuse.so.2
#12 0x00007ffff7ba4c18 in fuse_loop () from /lib64/libfuse.so.2
#13 0x00007ffff7bb5247 in fuse_main_common () from /lib64/libfuse.so.2
#14 0x000000000040d978 in main (argc=4, argv=0x7fffffffe088) at /home/jeanthomas/Applications/darling-dmg/src/main-fuse.cpp:70

CachedReader::nonCachedRead - Illegal range returned by adviseOptimalBlock()

When extracting a big (almost 5GB file InstallESD.dmg) cached reader fails with "Illegal range returned by adviseOptimalBlock()" exception.

Looks like these (pos) variables can go out of int32_t boundaries in CachedReader::read:

// Uncached blocks at the end of the requested range
const int32_t toRead = done - lastFetchPos;
const int32_t pos = offset + lastFetchPos;

Can't download links in https://www.darlinghq.org/build-instructions

Hi,

I've tried to download Debian and Ubuntu's pre-compiled packages but I'm always asked for username & password. Could you please do something about that?

I've also tried to rebuild the whole project in Ubuntu 16.04 but I've failed installing kernel modules as kernel headers are missing certs/signing_key.pem and certs/signing_key.x509 to sign the new modules.

Do you know how could I install the modules without recompiling the kernel?

Thanks a lot in advance for your support.

MAQ

Support of APFS (new Apple File System)

Would be happy to see someday support of new Apple FS

Apple File System supports nearly all of the features of HFS+, and offers improvements over HFS+, including 64-bit inode numbers, 1 nanosecond timestamp granularity, an expansive block allocator, support for sparse files, and a crash protection scheme.

Several files missing from mounted Xcode image

There are several files missing in

Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk
-> /usr/share/man/mann
-> /usr/share/man/man3

Full list: http://git.io/vL5y1

Xcode image:

Xcode_6.3.2.dmg, sha256: b19061ea1e4ba9f8290a616b72a9e91397209d71dba09fce5395a1bc6d8ac135

Support HFS+ compressed files & extended attributes

HFS+ itself offers support for compression. Data are available in additional file forks.

Extended attributes must be implemented first.

Resources:

Compression types:

  • 1 = uncompressed data in xattr
  • 3 = xattr has compressed data
  • 4 = resource fork has compressed data

Second bug in DMGPartition::readRun

count = std::min<int32_t>(count, be(run->sectorCount)*512 - offsetInSector);

should be changed to

count = std::min<uint64_t>((uint64_t)count, be(run->sectorCount)*512 - offsetInSector);

Because be(run->sectorCount)*512 can exceeed int32_t limits (I had a situation when it's 2 292 580 352), this will lead to count becoming negative.

crash: Wrong kind of BTree header

Just have encounted a DMG file (Apple Service Diagnostic 3S135.dmg, 3.55 GB) that throws this type of exception (in HFSBTree::HFSBTree) when constructing HFSExtentsOverflowBTree
After this, the app crashes in CachedReader::nonCachedRead
throw std::logic_error("Range returned by adviseOptimalBlock() is too large");

Implement caching

Currently, the catalog and attribute files are fully loaded into memory. This is very wasteful. Use an LRU cache instead.

Also add a separate LRU cache for other files.

Read dmg files without unmount.

Hi,

I'm working on a file scanner that also support macOS archive files (that runs under linux) and was wondering if there's any way to use darling-dmg to extract dmg file contexts (by merely parsing/decompressing the dmg file) without the need to mount its contents on filesystem.

thanks

Implement GPT support

There are DMG files which use GPT instead of Apple Disk Image. Implement support for them.

Example: https://dl.google.com/widevine/6.0.0.12607/WidevineMediaOptimizer.dmg

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>resource-fork</key>
        <dict>
                <key>blkx</key>
                <array>
                        <dict>
                                <key>Attributes</key>
                                <string>0x0050</string>
                                <key>CFName</key>
                                <string>Protective Master Boot Record (MBR : 0)</string>
                                <key>Data</key>
                                <data>
                                bWlzaAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAA
                                AAIIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAIAAAAgWGdwYQSAAAD7AQAAAAAAAAAAAAAAAAAAYmls
                                ZAAAAADQfI1p/38AAPnfGYv/fwAAIXmcz7SS2ywAAAAA
                                AAAAAAAAAAAAAAAABID//wAAAACIhI1p/38AAFB9jWn/
                                fwAA0HyNaf9/AACr5RmL/38AAASA//8AAAAAiISNaf9/
                                AAAAAAACgAAABQAAAAAAAAAAAAAAAAAAAAAAAAABAAAA
                                AAAAAAAAAAAAAAAAHf////8AAAAAAAAAAAAAAAEAAAAA
                                AAAAAAAAAAAAAAAdAAAAAAAAAAA=
                                </data>
                                <key>ID</key>
                                <string>-1</string>
                                <key>Name</key>
                                <string>Protective Master Boot Record (MBR : 0)</string>
                        </dict>
                        <dict>
                                <key>Attributes</key>
                                <string>0x0050</string>
                                <key>CFName</key>
                                <string>GPT Header (Primary GPT Header : 1)</string>
                                <key>Data</key>
                                <data>
                                bWlzaAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAA
                                AAIIAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAIAAAAgR43TUgSAAAD7AQAAAAAAAAAAAAAAAAAAYmls
                                ZAAAAADQfI1p/38AAPnfGYv/fwAAIXmcz7SS2ywAAAAA
                                AAAAAAAAAAAAAAAABID//wAAAACIhI1p/38AAFB9jWn/
                                fwAA0HyNaf9/AACr5RmL/38AAASA//8AAAAAiISNaf9/
                                AAAAAAACgAAABQAAAAAAAAAAAAAAAAAAAAAAAAABAAAA
                                AAAAAB0AAAAAAAAASf////8AAAAAAAAAAAAAAAEAAAAA
                                AAAAAAAAAAAAAABmAAAAAAAAAAA=
                                </data>
                                <key>ID</key>
                                <string>0</string>
                                <key>Name</key>
                                <string>GPT Header (Primary GPT Header : 1)</string>
                        </dict>
                        <dict>
                                <key>Attributes</key>
                                <string>0x0050</string>
                                <key>CFName</key>
                                <string>GPT Partition Data (Primary GPT Table : 2)</string>
                                <key>Data</key>
                                <data>
                                bWlzaAAAAAEAAAAAAAAAAgAAAAAAAAAgAAAAAAAAAAAA
                                AAIIAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAIAAAAg5ox0QQSAAAD7AQAAAAAAAAAAAAAAAAAAYmls
                                ZAAAAADQfI1p/38AAPnfGYv/fwAAIXmcz7SS2ywAAAAA
                                AAAAAAAAAAAAAAAABID//wAAAACIhI1p/38AAFB9jWn/
                                fwAA0HyNaf9/AACr5RmL/38AAASA//8AAAAAiISNaf9/
                                AAAAAAACgAAABQAAAAAAAAAAAAAAAAAAAAAAAAAgAAAA
                                AAAAAGYAAAAAAAAAcf////8AAAAAAAAAAAAAACAAAAAA
                                AAAAAAAAAAAAAADXAAAAAAAAAAA=
                                </data>
                                <key>ID</key>
                                <string>1</string>
                                <key>Name</key>
                                <string>GPT Partition Data (Primary GPT Table : 2)</string>
                        </dict>
                        <dict>
                                <key>Attributes</key>
                                <string>0x0050</string>
                                <key>CFName</key>
                                <string> (Apple_Free : 3)</string>
                                <key>Data</key>
                                <data>
                                bWlzaAAAAAEAAAAAAAAAIgAAAAAAAAAGAAAAAAAAAAAA
                                AAAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAIAAAAgAAAAAASAAAD7AQAAAAAAAAAAAAAAAAAAYmls
                                ZAAAAADQfI1p/38AAPnfGYv/fwAAIXmcz7SS2ywAAAAA
                                AAAAAAAAAAAAAAAABID//wAAAACIhI1p/38AAFB9jWn/
                                fwAA0HyNaf9/AACr5RmL/38AAASA//8AAAAAiISNaf9/
                                AAAAAAACAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAGAAAA
                                AAAAANcAAAAAAAAAAP////8AAAAAAAAAAAAAAAYAAAAA
                                AAAAAAAAAAAAAADXAAAAAAAAAAA=
                                </data>
                                <key>ID</key>
                                <string>2</string>
                                <key>Name</key>
                                <string> (Apple_Free : 3)</string>
                        </dict>
                        <dict>
                                <key>Attributes</key>
                                <string>0x0050</string>
                                <key>CFName</key>
                                <string>disk image (Apple_HFS : 4)</string>
                                <key>Data</key>
                                <data>
                                bWlzaAAAAAEAAAAAAAAAKAAAAAAAADxAAAAAAAAAAAAA
                                AAIIAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAIAAAAg/hVOXwSAAAD7AQAAAAAAAAAAAAAAAAAAYmls
                                ZAAAAADQfI1p/38AAPnfGYv/fwAAIXmcz7SS2ywAAAAA
                                AAAAAAAAAAAAAAAABID//wAAAACIhI1p/38AAFB9jWn/
                                fwAA0HyNaf9/AACr5RmL/38AAASA//8AAAAAiISNaf9/
                                AAAAAAAigAAABQAAAAAAAAAAAAAAAAAAAAAAAAIAAAAA
                                AAAAANcAAAAAAAGDbYAAAAUAAAAAAAAAAAAAAgAAAAAA
                                AAACAAAAAAAAAYREAAAAAAADlSyAAAAFAAAAAAAAAAAA
                                AAQAAAAAAAAAAgAAAAAAAAUZcAAAAAAAAEExgAAABQAA
                                AAAAAAAAAAAGAAAAAAAAAAIAAAAAAAAFWqEAAAAAAAAM
                                J4AAAAUAAAAAAAAAAAAACAAAAAAAAAACAAAAAAAABWbI
                                AAAAAAAAARWAAAAFAAAAAAAAAAAAAAoAAAAAAAAAAgAA
                                AAAAAAVn3QAAAAAAAHxHgAAABQAAAAAAAAAAAAAMAAAA
                                AAAAAAIAAAAAAAAF5CQAAAAAAAFZ0gAAAAEAAAAAAAAA
                                AAAADgAAAAAAAAACAAAAAAAABz32AAAAAAAEAACAAAAF
                                AAAAAAAAAAAAABAAAAAAAAAAAgAAAAAAAAs99gAAAAAA
                                AeWNgAAABQAAAAAAAAAAAAASAAAAAAAAAAIAAAAAAAAN
                                I4MAAAAAAAJiLYAAAAUAAAAAAAAAAAAAFAAAAAAAAAAC
                                AAAAAAAAD4WwAAAAAAADg8KAAAAFAAAAAAAAAAAAABYA
                                AAAAAAAAAgAAAAAAABMJcgAAAAAAAUJygAAABQAAAAAA
                                AAAAAAAYAAAAAAAAAAIAAAAAAAAUS+QAAAAAAAOAq4AA
                                AAUAAAAAAAAAAAAAGgAAAAAAAAACAAAAAAAAF8yPAAAA
                                AAACqVwAAAABAAAAAAAAAAAAABwAAAAAAAAAAgAAAAAA
                                ABp16wAAAAAABAAAAAAAAQAAAAAAAAAAAAAeAAAAAAAA
                                AAIAAAAAAAAedesAAAAAAAQAAAAAAAEAAAAAAAAAAAAA
                                IAAAAAAAAAACAAAAAAAAInXrAAAAAAAEAAAAAAABAAAA
                                AAAAAAAAACIAAAAAAAAAAgAAAAAAACZ16wAAAAAABAAA
                                AAAAAQAAAAAAAAAAAAAkAAAAAAAAAAIAAAAAAAAqdesA
                                AAAAAAQAAAAAAAEAAAAAAAAAAAAAJgAAAAAAAAACAAAA
                                AAAALnXrAAAAAAAEAAAAAAABAAAAAAAAAAAAACgAAAAA
                                AAAAAgAAAAAAADJ16wAAAAAABAAAAAAAAQAAAAAAAAAA
                                AAAqAAAAAAAAAAIAAAAAAAA2desAAAAAAAQAAAAAAAEA
                                AAAAAAAAAAAALAAAAAAAAAACAAAAAAAAOnXrAAAAAAAE
                                AAAAAAABAAAAAAAAAAAAAC4AAAAAAAAAAgAAAAAAAD51
                                6wAAAAAABAAAAAAAAQAAAAAAAAAAAAAwAAAAAAAAAAIA
                                AAAAAABCdesAAAAAAAQAAAAAAAEAAAAAAAAAAAAAMgAA
                                AAAAAAACAAAAAAAARnXrAAAAAAAEAAAAAAABAAAAAAAA
                                AAAAADQAAAAAAAAAAgAAAAAAAEp16wAAAAAABAAAAAAA
                                AQAAAAAAAAAAAAA2AAAAAAAAAAIAAAAAAABOdesAAAAA
                                AAQAAAAAAAEAAAAAAAAAAAAAOAAAAAAAAAACAAAAAAAA
                                UnXrAAAAAAAEAAAAAAABAAAAAAAAAAAAADoAAAAAAAAA
                                AVAAAAAAAFZ16wAAAAAAAqAAAAAAAgAAAAAAAAAAAAA7
                                UAAAAAAAAADuAAAAAABZFesAAAAAAAAAAIAAAAUAAAAA
                                AAAAAAAAPD4AAAAAAAAAAQAAAAAAWRXrAAAAAAAAAGQA
                                AAACAAAAAAAAAAAAADw/AAAAAAAAAAEAAAAAAFkWTwAA
                                AAAAAAAA/////wAAAAAAAAAAAAA8QAAAAAAAAAAAAAAA
                                AABZFk8AAAAAAAAAAA==
                                </data>
                                <key>ID</key>
                                <string>3</string>
                                <key>Name</key>
                                <string>disk image (Apple_HFS : 4)</string>
                        </dict>
                        <dict>
                                <key>Attributes</key>
                                <string>0x0050</string>
                                <key>CFName</key>
                                <string> (Apple_Free : 5)</string>
                                <key>Data</key>
                                <data>
                                bWlzaAAAAAEAAAAAAAA8aAAAAAAAAAADAAAAAAAAAAAA
                                AAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAIAAAAgAAAAAASAAAD7AQAAAAAAAAAAAAAAAAAAYmls
                                ZAAAAADQfI1p/38AAPnfGYv/fwAAIXmcz7SS2ywAAAAA
                                AAAAAAAAAAAAAAAABID//wAAAACIhI1p/38AAFB9jWn/
                                fwAA0HyNaf9/AACr5RmL/38AAASA//8AAAAAiISNaf9/
                                AAAAAAACAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAADAAAA
                                AABZFk8AAAAAAAAAAP////8AAAAAAAAAAAAAAAMAAAAA
                                AAAAAAAAAAAAWRZPAAAAAAAAAAA=
                                </data>
                                <key>ID</key>
                                <string>4</string>
                                <key>Name</key>
                                <string> (Apple_Free : 5)</string>
                        </dict>
                        <dict>
                                <key>Attributes</key>
                                <string>0x0050</string>
                                <key>CFName</key>
                                <string>GPT Partition Data (Backup GPT Table : 6)</string>
                                <key>Data</key>
                                <data>
                                bWlzaAAAAAEAAAAAAAA8awAAAAAAAAAgAAAAAAAAAAAA
                                AAIIAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAIAAAAg5ox0QQSAAAD7AQAAAAAAAAAAAAAAAAAAYmls
                                ZAAAAADQfI1p/38AAPnfGYv/fwAAIXmcz7SS2ywAAAAA
                                AAAAAAAAAAAAAAAABID//wAAAACIhI1p/38AAFB9jWn/
                                fwAA0HyNaf9/AACr5RmL/38AAASA//8AAAAAiISNaf9/
                                AAAAAAACgAAABQAAAAAAAAAAAAAAAAAAAAAAAAAgAAAA
                                AABZFk8AAAAAAAAAcf////8AAAAAAAAAAAAAACAAAAAA
                                AAAAAAAAAAAAWRbAAAAAAAAAAAA=
                                </data>
                                <key>ID</key>
                                <string>5</string>
                                <key>Name</key>
                                <string>GPT Partition Data (Backup GPT Table : 6)</string>
                        </dict>
                        <dict>
                                <key>Attributes</key>
                                <string>0x0050</string>
                                <key>CFName</key>
                                <string>GPT Header (Backup GPT Header : 7)</string>
                                <key>Data</key>
                                <data>
                                bWlzaAAAAAEAAAAAAAA8iwAAAAAAAAABAAAAAAAAAAAA
                                AAIIAAAABwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAIAAAAgzvTEnQSAAAD7AQAAAAAAAAAAAAAAAAAAYmls
                                ZAAAAADQfI1p/38AAPnfGYv/fwAAIXmcz7SS2ywAAAAA
                                AAAAAAAAAAAAAAAABID//wAAAACIhI1p/38AAFB9jWn/
                                fwAA0HyNaf9/AACr5RmL/38AAASA//8AAAAAiISNaf9/
                                AAAAAAACgAAABQAAAAAAAAAAAAAAAAAAAAAAAAABAAAA
                                AABZFsAAAAAAAAAAS/////8AAAAAAAAAAAAAAAEAAAAA
                                AAAAAAAAAAAAWRcLAAAAAAAAAAA=
                                </data>
                                <key>ID</key>
                                <string>6</string>
                                <key>Name</key>
                                <string>GPT Header (Backup GPT Header : 7)</string>
                        </dict>
                </array>
                <key>plst</key>
                <array>
                        <dict>
                                <key>Attributes</key>
                                <string>0x0050</string>
                                <key>Data</key>
                                <data>
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAQAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                AAAAAAAAAAAA
                                </data>
                                <key>ID</key>
                                <string>0</string>
                                <key>Name</key>
                                <string></string>
                        </dict>
                </array>
        </dict>
</dict>
</plist>

[Question] Build instructions

What kind of compilers and standard libraries are recommended to build this project?

Seems it's tested primarily under clang. Is GCC acceptable? I've successfully mounted Xcode_7.0.1.dmg on Arch Linux with GCC 5.2.0. I'm using libstdc++ from GCC 5.2.0, too. Is libc++ preferable?

fatal error: 'fuse.h' file not found .. on linuxmint 18.2

darling-dmg/src/main-fuse.h:5:10: fatal error: 'fuse.h' file not found
#include <fuse.h>

sudo apt-get install linux-libc-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
linux-libc-dev is already the newest version (4.4.0-92.115).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

But not work

Some files/folders are skipped from a DMG file

Hope you didn't delete the DMG file from #22

For example:
"System\Library\Frameworks\CoreServices.framework\Versions\A\Frameworks\AE.framework\Versions\A\Resources"
folder is skipped

HFSCatalogBTree::listDirectory :

// determine the CNID of the directory
rv = stat(path, &dir);
if (rv != 0) 
    return rv; // returns -2

Overall, about 600 MB of files/folders is not extracted from this DMG file.
Also there's "Overflow extents not found for given CNID" exception

Error make core.o on Ubuntu 16.04

[ 99%] Building C object src/launchd/src/CMakeFiles/launchd.dir/core.o
In file included from /home/o/Documents/osx/darling/src/launchd/src/core.c:86:
/home/o/Documents/osx/darling/platform-include/xpc/launchd.h:93:9: warning: 'XPC_SERVICE_RENDEZVOUS_TOKEN' macro redefined [-Wmacro-redefined]

define XPC_SERVICE_RENDEZVOUS_TOKEN "XPC service rendezvous token"

    ^

/home/o/Documents/osx/darling/platform-include/xpc/launchd.h:66:9: note: previous definition is here

define XPC_SERVICE_RENDEZVOUS_TOKEN "XPC_SERVICE_RENDEZVOUS_TOKEN"

    ^

/home/o/Documents/osx/darling/platform-include/xpc/launchd.h:95:9: warning: 'XPC_SERVICE_ENV_ATTACHED' macro redefined [-Wmacro-redefined]

define XPC_SERVICE_ENV_ATTACHED "XPC service env attached"

    ^

/home/o/Documents/osx/darling/platform-include/xpc/launchd.h:65:9: note: previous definition is here

define XPC_SERVICE_ENV_ATTACHED "XPC_SERVICE_ENV_ATTACHED"

    ^

/home/o/Documents/osx/darling/src/launchd/src/core.c:1306:22: warning: implicit declaration of function 'xpc_call_wakeup' is invalid in C99 [-Wimplicit-function-declaration]
kern_return_t kr = xpc_call_wakeup(jm->req_rport, jm->error);
^
/home/o/Documents/osx/darling/src/launchd/src/core.c:3653:27: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
j->last_exit_status = W_EXITCODE(-1, SIGSEGV);
^~~~~~~~~~~~~~~~~~~~~~~
/home/o/Documents/osx/darling/platform-include/sys/wait.h:158:37: note: expanded from macro 'W_EXITCODE'

define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))

                             ~~~~~ ^

/home/o/Documents/osx/darling/src/launchd/src/core.c:3662:28: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
j->last_exit_status = W_EXITCODE(-1, SIGSEGV);
^~~~~~~~~~~~~~~~~~~~~~~
/home/o/Documents/osx/darling/platform-include/sys/wait.h:158:37: note: expanded from macro 'W_EXITCODE'

define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))

                             ~~~~~ ^

/home/o/Documents/osx/darling/src/launchd/src/core.c:7629:23: warning: implicit declaration of function 'xpc_copy_entitlements_for_pid' is invalid in C99 [-Wimplicit-function-declaration]
ee->entitlements = xpc_copy_entitlements_for_pid(ldc->pid);
^
/home/o/Documents/osx/darling/src/launchd/src/core.c:7629:21: warning: incompatible integer to pointer conversion assigning to 'xpc_object_t' (aka 'void *') from 'int' [-Wint-conversion]
ee->entitlements = xpc_copy_entitlements_for_pid(ldc->pid);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/o/Documents/osx/darling/src/launchd/src/core.c:7669:22: warning: implicit declaration of function 'ld2xpc' is invalid in C99 [-Wimplicit-function-declaration]
xpc_object_t xobj = ld2xpc(obj);
^
/home/o/Documents/osx/darling/src/launchd/src/core.c:7669:15: warning: incompatible integer to pointer conversion initializing 'xpc_object_t' (aka 'void *') with an expression of type 'int' [-Wint-conversion]
xpc_object_t xobj = ld2xpc(obj);
^ ~~~~~~~~~~~
/home/o/Documents/osx/darling/src/launchd/src/core.c:8096:7: error: invalid application of 'typeof' to bit-field
if (!job_assumes(j, j->per_user)) {
^
/home/o/Documents/osx/darling/src/launchd/src/core.c:752:27: note: expanded from macro 'job_assumes'

define job_assumes(j, e) os_assumes_ctx(job_log_bug, j, (e))

                      ^

/home/o/Documents/osx/darling/platform-include/os/assumes.h:191:12: note: expanded from macro 'os_assumes_ctx'
typeof(e) _e = os_fastpath(e);
^
/home/o/Documents/osx/darling/src/launchd/src/core.c:8399:7: error: invalid application of 'typeof' to bit-field
if (job_assumes(j, j->weird_bootstrap)) {
^
/home/o/Documents/osx/darling/src/launchd/src/core.c:752:27: note: expanded from macro 'job_assumes'

define job_assumes(j, e) os_assumes_ctx(job_log_bug, j, (e))

                      ^

/home/o/Documents/osx/darling/platform-include/os/assumes.h:191:12: note: expanded from macro 'os_assumes_ctx'
typeof(e) _e = os_fastpath(e);
^
/home/o/Documents/osx/darling/src/launchd/src/core.c:8558:23: error: invalid application of 'typeof' to bit-field
if (msi->upfront && job_assumes(j, msi->recv)) {
^
/home/o/Documents/osx/darling/src/launchd/src/core.c:752:27: note: expanded from macro 'job_assumes'

define job_assumes(j, e) os_assumes_ctx(job_log_bug, j, (e))

                      ^

/home/o/Documents/osx/darling/platform-include/os/assumes.h:191:12: note: expanded from macro 'os_assumes_ctx'
typeof(e) _e = os_fastpath(e);
^
/home/o/Documents/osx/darling/src/launchd/src/core.c:10749:62: warning: implicit declaration of function 'xpc_strerror' is invalid in C99 [-Wimplicit-function-declaration]
job_log(j, LOG_ERR, "Failed to check in: 0x%x: %s", error, xpc_strerror(error));
^
/home/o/Documents/osx/darling/src/launchd/src/core.c:10749:62: warning: format specifies type 'char ' but the argument has type 'int' [-Wformat]
job_log(j, LOG_ERR, "Failed to check in: 0x%x: %s", error, xpc_strerror(error));
~~ ^~~~~~~~~~~~~~~~~~~
%d
/home/o/Documents/osx/darling/src/launchd/src/core.c:10757:3: warning: implicit declaration of function 'xpc_dictionary_set_mach_recv' is invalid in C99 [-Wimplicit-function-declaration]
xpc_dictionary_set_mach_recv(reply2, XPC_EVENT_ROUTINE_KEY_PORT, ms->port);
^
/home/o/Documents/osx/darling/src/launchd/src/core.c:10794:3: warning: implicit declaration of function 'xpc_dictionary_set_mach_send' is invalid in C99 [-Wimplicit-function-declaration]
xpc_dictionary_set_mach_send(reply2, XPC_EVENT_ROUTINE_KEY_PORT, ms->port);
^
/home/o/Documents/osx/darling/src/launchd/src/core.c:10798:113: warning: format specifies type 'char *' but the argument has type 'int' [-Wformat]
job_log(j, LOG_ERR, "Could not find event channel for stream/token: %s/%llu: 0x%x: %s", stream, token, error, xpc_strerror(error));
~~ ^~~~~~~~~~~~~~~~~~~
%d
/home/o/Documents/osx/darling/src/launchd/src/core.c:10919:2: warning: implicit declaration of function 'xpc_dictionary_get_audit_token' is invalid in C99 [-Wimplicit-function-declaration]
xpc_dictionary_get_audit_token(request, &token);
^
/home/o/Documents/osx/darling/src/launchd/src/core.c:10982:23: warning: implicit declaration of function 'xpc_copy_entitlement_for_token' is invalid in C99 [-Wimplicit-function-declaration]
xpc_object_t value = xpc_copy_entitlement_for_token(key, token);
^
/home/o/Documents/osx/darling/src/launchd/src/core.c:10982:15: warning: incompatible integer to pointer conversion initializing 'xpc_object_t' (aka 'void *') with an expression of type 'int' [-Wint-conversion]
xpc_object_t value = xpc_copy_entitlement_for_token(key, token);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/o/Documents/osx/darling/src/launchd/src/core.c:11129:15: warning: incompatible integer to pointer conversion initializing 'xpc_object_t' (aka 'void *') with an expression of type 'int' [-Wint-conversion]
xpc_object_t entitlement = xpc_copy_entitlement_for_token(XPC_SERVICE_ENTITLEMENT_ATTACH, token);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/o/Documents/osx/darling/src/launchd/src/core.c:11154:21: warning: implicit declaration of function 'xpc_dictionary_copy_mach_send' is invalid in C99 [-Wimplicit-function-declaration]
mach_port_t port = xpc_dictionary_copy_mach_send(request, XPC_PROCESS_ROUTINE_KEY_NEW_INSTANCE_PORT);
^
19 warnings and 3 errors generated.
src/launchd/src/CMakeFiles/launchd.dir/build.make:153 : la recette pour la cible « src/launchd/src/CMakeFiles/launchd.dir/core.o » a échouée
make[2]: *
* [src/launchd/src/CMakeFiles/launchd.dir/core.o] Erreur 1
CMakeFiles/Makefile2:23175 : la recette pour la cible « src/launchd/src/CMakeFiles/launchd.dir/all » a échouée
make[1]: *** [src/launchd/src/CMakeFiles/launchd.dir/all] Erreur 2
Makefile:149 : la recette pour la cible « all » a échouée
make: *** [all] Erreur 2
``

Strange HFSX files inside IPSW firmware

IPSW iOS firmware files contain number of DMG files, which are actually simple HFSX raw file system.
Examples:
https://www.dropbox.com/s/0zpx0b52thrfawm/058-97112-138.dmg?dl=0
https://www.dropbox.com/s/tcc0qhn27md1njp/058-97541-138.dmg?dl=0

The problem is that these files have special 27 bytes offset before actual HFS data:
sshot-2018-07-08- 15-25-12

7Zip is smart to handle such files, but in my code I have to do the following tweak:

ioReader->setStartOffset((ioReader->length() % 512));

Is it OK? Can this be implemented in the lib?

Thank you

Bug in DMGPartition::readRun

Hello,

Block type 2 (you call it RunType::Unknown but is must be RunType::Ignore, according to other sources of parsing DMG) must be used in the same way as RunType::ZeroFill

case Unknown:
case ZeroFill:
    //std::cout << "ZeroFill\n";
    memset(buf, 0, count);
    return count;

template class RecordIterator requires default constructor and copy constructor

The code is using std::lower_bound/std::upper_bound in HFSBTree.cpp:

auto it = std::lower_bound(node.begin(), node.end(), indexKey, [=](const Key* keyA, const Key* keyB) {
return comp(keyA, keyB) < 0;
});

Some implementations of std::lower_bound might require a default constructor for the class RecordIterator (as an example - Clang on Mac OS X 10.9), so your code won't compile without it.

BTW all iterators must be CopyConstructible, CopyAssignable, and Destructible according to the C++ standard

Crash in CacheZone::store

Now it crashes when extracting a big HFS partition (15 669 878 784 bytes) out of DMG file (5GB) to raw format

Crash happens on the line std::copy(data, data+bytes, entry.data.begin()); (Access violation while reading memory)

Seems to be a problem of big numbers

my code:

const std::vector<PartitionedDisk::Partition>&partitions = partitionedDisk->partitions();

uint64_t totalSize = 0;
for (int i = 0; i < partitions.size(); i++)
   totalSize += partitions[i].size;

for (int i = 0; i < partitions.size(); i++)
{
    const PartitionedDisk::Partition& part = partitions[i];

    partReader = partitionedDisk->readerForPartition(i);

    if (partReader)
        writeReaderToFile(partReader, &file_out);
}

Support ISO9660 files

Consider supporting ISO9660 files, since many .dmg files are in fact .iso files.

This is also quite useful for Darling's hdiutil in general.

linking error in Ubuntu 16.04

I am on Ubuntu 16.04 platform. I am trying to compile osxcross package which it clones and builds darling-dmg but in linking process I get the following errors :

libdmg.so: undefined reference to `icu_58::ByteSink::Flush()'
libdmg.so: undefined reference to `icu_58::UnicodeString::fromUTF8(icu_58::StringPiece)'
libdmg.so: undefined reference to `icu_58::ByteSink::GetAppendBuffer(int, int, char*, int, int*)'
libdmg.so: undefined reference to `icu_58::UnicodeString::extract(char*, int, UConverter*, UErrorCode&) const'
libdmg.so: undefined reference to `ucnv_close_58'
libdmg.so: undefined reference to `icu_58::UnicodeString::doCaseCompare(int, int, unsigned short const*, int, int, unsigned int) const'
libdmg.so: undefined reference to `vtable for icu_58::UnicodeString'
libdmg.so: undefined reference to `icu_58::UnicodeString::doCompare(int, int, unsigned short const*, int, int) const'
libdmg.so: undefined reference to `icu_58::UnicodeString::UnicodeString(char const*, int, UConverter*, UErrorCode&)'
libdmg.so: undefined reference to `icu_58::UnicodeString::toUTF8(icu_58::ByteSink&) const'
libdmg.so: undefined reference to `icu_58::ByteSink::~ByteSink()'
libdmg.so: undefined reference to `icu_58::UnicodeString::doEquals(icu_58::UnicodeString const&, int) const'
libdmg.so: undefined reference to `icu_58::UnicodeString::UnicodeString(char const*, int, char const*)'
libdmg.so: undefined reference to `typeinfo for icu_58::ByteSink'
libdmg.so: undefined reference to `icu_58::UMemory::operator delete(void*)'
libdmg.so: undefined reference to `ucnv_open_58'
libdmg.so: undefined reference to `icu_58::UnicodeString::~UnicodeString()'
libdmg.so: undefined reference to `icu_58::UnicodeString::moveFrom(icu_58::UnicodeString&)'

I installed libicu-dev in the repository (55.1.7) before I started compilation.
Would you help me fix it?
Thanks.
Kenn

GUID -> GPT_GUID

It's a very small issue, but still.
When compiling darling-dmg under Windows and Visual C++ compiler, GUID structure is already defined there in Windows SDK headers. So I have to rename to GUID (in gpt.h) into GPT_GUID.

struct GPT_GUID
{
    uint32_t data1;
    uint16_t data2, data3;
    uint8_t data4[8];
};

struct GPTPartition
{
    GPT_GUID typeGUID;
    GPT_GUID partitionGUID;
    uint64_t firstLBA, lastLBA;
    uint64_t flags;
    uint16_t name[36];
};

Why not to pull this for Windows users? Thanks

Global variable for HFSBTree cache

There's a global variable

CacheZone g_btreeZone

This cache zone is shared with multiple cache readers - "Attribute", "Catalog", "ExtentsOverflow".
This situation is not correct when one needs to deal with multiple DMG files - the cache becomes invalid after working with the first DMG file.

The current workaround is to make this variable static

CacheZone HFSBTree::g_btreeZone = CacheZone(6400);

And clear cache before opening new DMG file:

HFSBTree::g_btreeZone = CacheZone(6400);

Hard link

Hi,

Not an issue but a question.

I'd link to follow hard link, like os x does (while get xattr fro example).
The reference of a hard link is an inode number. Is there already a way to find file from its inode number ?

Thanks.

DMG with sightly different xml format.

Hi,

I've recently tried to dump the contents of the attached file on dmg parser and failed to locate any valid partitions. This dmg is openable by apple native command and contains ISO9660 which is currently not supported.

However, It seems like my problem start before revealing the partition type, and it's located in the xml section in the dmg file (also attached here). It seems like the xml doesn't contain the field CFName which the following arg is trying to capture in method DMGDisk::loadPartitionElements.

Perhaps anyone can explain if my analysis is correct, and how can I add support to this file as well (without the actual parsing of ISO partition) ?

iPhone Configuration Utility.dmg.zip

dmg_xml.txt

Remove old code from main-fuse.cpp

It's already in HFSHighLevelVolume.cpp:

static const char* RESOURCE_FORK_SUFFIX = "#..namedfork#rsrc";
static const char* XATTR_RESOURCE_FORK = "com.apple.ResourceFork";
static const char* XATTR_FINDER_INFO = "com.apple.FinderInfo";

HFSAttributeBTree::getattr crashes

leafNode = findLeafNode((Key*) &key, cnidAttrComparator);

if findLeafNode returns empty HFSBTreeNode then operator= will crash in initFromBuffer. I'd change the method code to

void initFromBuffer()
{
   if (m_descriptorData.size()) // required check!
   {
      m_descriptor = reinterpret_cast<BTNodeDescriptor*>(&m_descriptorData[0]);
      m_firstRecordOffset = reinterpret_cast<uint16_t*>(descPtr() + m_nodeSize - sizeof(uint16_t));
   }
}

Low performance

Hello,

Compiled your code to test extraction of DMG file on Win7.

The code is really great, but: I did a performance test when extracting a 5GB file from 'OS X 10.10.dmg'. It's 2.5-3 times slower than any other software (7zip) that can simply extract a DMG file.

I used different buffer sizes, from 1kb to 10 MB, the results are almost the same.

Profiler says that all the CPU time goes to BZ2_bzDecompress

Any thoughts?
Thanks

LZFSE is not supported

I think its because the compression of some section in the DMG is LZFSE

Darling [~/Documents]$ hdiutil attach 9bcf01399719755034c964549a6a3af38932e7eaf03febc8b3742306505ca8a9 
Skipping partition of type Apple_partition_map
Using partition #1 of type Apple_HFS
Error: Unexpected EOF from readRun

Possible reasons:
1) The file is corrupt.
2) The file is not really a DMG file, although it resembles one.
3) There is a bug in darling-dmg.

link to DMG
*do take care this dmg might contain a malware

Improve the code by separating file system layer

Since DMG is a container which can contain different file systems (ISO 9660 / UDF / HFS / APFS / FAT32 / NTFS), I'd recommend separating file system code to a new interface class, create a subfolder for HFS and move its code there. And add a possibility to add new file systems (APFS or ISO9660).

HFSCatalogBTree::stat is broken

Recent changes by @jief666 broke the code, newly introduced findHFSPlusCatalogFileOrFolderForParentIdAndName returns invalid data.

for (size_t i = 0; i < elems.size(); i++)
{
	std::string elem = elems[i];

	HFSCatalogNodeID parentID = last ? be(last->folder.folderID) : kHFSRootParentID;
	replaceChars(elem, ':', '/'); // Issue #36: / and : have swapped meaning in HFS+

	// old code
	HFSPlusCatalogKey desiredKey;

	desiredKey.nodeName.length = StringToUnichar(elem, desiredKey.nodeName.string, sizeof(desiredKey.nodeName.string));
	//desiredKey.nodeName.length = ustr.extract(0, ustr.length(), (char*) desiredKey.nodeName.string, "UTF-16BE") / 2;
	desiredKey.nodeName.length = htobe16(desiredKey.nodeName.length);

	desiredKey.parentID = htobe32(parentID);

	leafNode = findLeafNode((Key*)&desiredKey, isCaseSensitive() ? caseSensitiveComparator : caseInsensitiveComparator);
	if (leafNode.isInvalid())
		return -ENOENT;

	last = findRecordForParentAndName(leafNode, parentID, elem); 

	// new
	HFSPlusCatalogFileOrFolder *lastNewBroken = findHFSPlusCatalogFileOrFolderForParentIdAndName(parentID, elem);

compile error: 'ENOATTR' was not declared in this scope

Compiling under Ubuntu 16.04.5 LTS with gcc 5.4.0 results in following error.

./darling-dmg/src/main-fuse.cpp: In function ‘int handle_exceptions(std::function<int()>)’:
./darling-dmg/src/main-fuse.cpp:166:11: error: ‘ENOATTR’ was not declared in this scope
   return -ENOATTR;

I worked around this by adding the following code after the #include statements in main-fuse.cpp.

#ifndef ENOATTR
#define ENOATTR ENODATA
#endif

-EIO when listing a directory

Listing the following directory and many others in Xcode_7.2.dmg returns -EIO:

/Xcode.app/Contents/Developer/Documentation/DocSets/com.apple.adc.documentation.iOS.docset/Contents/Resources/Tokens/Swift/instctr/NEAppRule/

The whole subtree of instctr seems to be affected.

xcode_5.0.2.dmg fails to mount

darling-dmg fails to mount xcode_5.0.2.dmg with the following error:

Sector 0 has type 0x80000005, starts at byte 0, compressed length: 22, compressed offset: 0
Reading from offset 0 2 bytes
Run sector 0 run index=0
readRun(): runIndex = 0, offsetInSector = 0, count = 2
ZLIB decompressor supplying 22 bytes
Buffer is at 0x1db69c4
Processed: 6, total: 6
16 bytes left
status = 0
Decompressor returned 2
Sector 0 has type 0x2, starts at byte 0, compressed length: 0, compressed offset: 22
Reading from offset 0 512 bytes
Run sector 0 run index=0
readRun(): runIndex = 0, offsetInSector = 0, count = 512
ZLIB decompressor supplying 22 bytes
Buffer is at 0x1db69c4
Processed: 22, total: 22
0 bytes left
status = 1
Decompressor returned 512
Reading from offset 0 512 bytes
Run sector 0 run index=0
readRun(): runIndex = 0, offsetInSector = 0, count = 512
Error: Unexpected EOF from readRun

Issues with exceptions.h

I. You use constructors inheritance, it's great modern feature but is not supported by many compilers (Visual C++ 2013, clang 4.2)
Why not to make in the old way to allow the code be more portable:

class io_error : public std::runtime_error
{
public:
        //using std::runtime_error::runtime_error;
    io_error(const std::string& _Message) : std::runtime_error(_Message.c_str()) {}
};

II. The line
```
virtual const char* what() const override { return "No data available"; }


doesn't compile in older clang version:
/darling-dmg/exceptions.h:28:29: error: exception specification of overriding function is more lax than base version
and has to be changed to ```
    virtual const char* what() const throw() { return "No data available"; } ```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.