Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DLOga-0002bW-UT for qemu-devel@nongnu.org; Tue, 12 Apr 2005 12:56:27 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DLOgR-0002ZS-0r for qemu-devel@nongnu.org; Tue, 12 Apr 2005 12:56:20 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DLOgJ-0002Lt-3N for qemu-devel@nongnu.org; Tue, 12 Apr 2005 12:56:07 -0400 Received: from [217.65.98.56] (helo=shiva.galaktik.hu) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DLP96-0002OM-8M for qemu-devel@nongnu.org; Tue, 12 Apr 2005 13:25:53 -0400 Received: from [10.0.0.201] (helo=caprice.artificis.hu) by shiva.galaktik.hu with esmtp (Exim 3.35 #1 (Debian)) id 1DLQoJ-0003Wf-00 for ; Tue, 12 Apr 2005 21:12:31 +0200 Date: Tue, 12 Apr 2005 19:28:41 +0200 From: Alex Beregszaszi Message-Id: <20050412192841.03d16475@caprice.artificis.hu> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart=_Tue__12_Apr_2005_19_28_41_+0200_vysBy+r8q8368iZu" Subject: [Qemu-devel] [PATCH] Better .dmg autodetection Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --Multipart=_Tue__12_Apr_2005_19_28_41_+0200_vysBy+r8q8368iZu Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Hi, There are quiet lot fake dmg files floating around. These are just raw images containing the Apple partition map and HFS partitions. I hardened the autodetection of dmg files with more sanity checks. Real dmg files are likely to be zlib compressed, and the header is placed at the end. So the first sector of the file is used to be zlib data. There are 3 parts of the detection: * first look if the first byte means zlib data (CFM byte, compression and format flags, the compression is ought to be 8, while the flags should be less then 8), also if it validates, look if the filename ends in .dmg * check wether it is Apple partition map, the magic bytes are ER * last check if the filename ends in .dmg -- Alex Beregszaszi e-mail: alex@fsn.hu Free Software Network cell: +36 70 3144424 --Multipart=_Tue__12_Apr_2005_19_28_41_+0200_vysBy+r8q8368iZu Content-Type: text/x-diff; name="block-dmg.detection.diff" Content-Disposition: attachment; filename="block-dmg.detection.diff" Content-Transfer-Encoding: 7bit Index: block-dmg.c =================================================================== RCS file: /cvsroot/qemu/qemu/block-dmg.c,v retrieving revision 1.2 diff -u -r1.2 block-dmg.c --- block-dmg.c 3 Jan 2005 23:39:08 -0000 1.2 +++ block-dmg.c 12 Apr 2005 17:25:09 -0000 @@ -52,6 +52,16 @@ static int dmg_probe(const uint8_t *buf, int buf_size, const char *filename) { int len=strlen(filename); + + // Zlib CMF (4 bits CM, 4 bits flags) + if (((buf[0] & 0xf) == 8) && ((buf[0]&0xf0)<=7) && + (len>4 && !strcmp(filename+len-4,".dmg")) ) + return 50; + + // Hopefully found Apple Partition map... + if ((buf[0] == 'E') && (buf[1] == 'R')) + return 0; + if(len>4 && !strcmp(filename+len-4,".dmg")) return 2; return 0; --Multipart=_Tue__12_Apr_2005_19_28_41_+0200_vysBy+r8q8368iZu--