Author: abock
Date: 2006-06-10 11:21:43 -0400 (Sat, 10 Jun 2006)
New Revision: 61616
Added:
trunk/ipod-sharp/src/Firmware/
trunk/ipod-sharp/src/Firmware/CpioArchive.cs
trunk/ipod-sharp/src/Firmware/DmgImage.cs
trunk/ipod-sharp/src/Firmware/DmgPartition.cs
trunk/ipod-sharp/src/Firmware/Makefile.am
Removed:
trunk/ipod-sharp/src/DmgImage.cs
trunk/ipod-sharp/src/DmgPartition.cs
Modified:
trunk/ipod-sharp/ChangeLog
trunk/ipod-sharp/configure.ac
trunk/ipod-sharp/ipod-sharp.mdp
trunk/ipod-sharp/src/Makefile.am
trunk/ipod-sharp/tools/Makefile.am
Log:
2006-06-10 Aaron Bockover <[EMAIL PROTECTED]>
* src/Dmg*.cs: Moved to src/Firmware
* src/Firmware/Makefile.am: Added new ipod-sharp-firmware.dll assembly
* src/Firmware/CpioArchive.cs: New class to read and extract files from
CPIO archives in the ASCII header format
* configure.ac: Generate src/Firmware/Makefile
* src/Makefile.am: Added Firmware to SUBDIRS
* tools/Makefile.am: Updated build to reflect renamed files
* ipod-sharp.mdp: Updated MonoDevelop project
Modified: trunk/ipod-sharp/ChangeLog
===================================================================
--- trunk/ipod-sharp/ChangeLog 2006-06-10 13:34:28 UTC (rev 61615)
+++ trunk/ipod-sharp/ChangeLog 2006-06-10 15:21:43 UTC (rev 61616)
@@ -1,3 +1,20 @@
+2006-06-10 Aaron Bockover <[EMAIL PROTECTED]>
+
+ * src/Dmg*.cs: Moved to src/Firmware
+
+ * src/Firmware/Makefile.am: Added new ipod-sharp-firmware.dll assembly
+
+ * src/Firmware/CpioArchive.cs: New class to read and extract files from
+ CPIO archives in the ASCII header format
+
+ * configure.ac: Generate src/Firmware/Makefile
+
+ * src/Makefile.am: Added Firmware to SUBDIRS
+
+ * tools/Makefile.am: Updated build to reflect renamed files
+
+ * ipod-sharp.mdp: Updated MonoDevelop project
+
2006-06-09 Aaron Bockover <[EMAIL PROTECTED]>
* {Makefile.am,*/Makefile.am}: Added MAINTAINERCLEANFILES to keep
Modified: trunk/ipod-sharp/configure.ac
===================================================================
--- trunk/ipod-sharp/configure.ac 2006-06-10 13:34:28 UTC (rev 61615)
+++ trunk/ipod-sharp/configure.ac 2006-06-10 15:21:43 UTC (rev 61616)
@@ -71,6 +71,7 @@
ipod-sharp.pc
ipod-sharp-ui.pc
src/Makefile
+src/Firmware/Makefile
ui/Makefile
tools/Makefile
tests/Makefile
Modified: trunk/ipod-sharp/ipod-sharp.mdp
===================================================================
--- trunk/ipod-sharp/ipod-sharp.mdp 2006-06-10 13:34:28 UTC (rev 61615)
+++ trunk/ipod-sharp/ipod-sharp.mdp 2006-06-10 15:21:43 UTC (rev 61616)
@@ -35,13 +35,16 @@
<File name="./src/Track.cs" subtype="Code" buildaction="Compile" />
<File name="./src/TrackDatabase.cs" subtype="Code" buildaction="Compile" />
<File name="./src/Utility.cs" subtype="Code" buildaction="Compile" />
- <File name="./src/DmgImage.cs" subtype="Code" buildaction="Compile" />
- <File name="./src/DmgPartition.cs" subtype="Code" buildaction="Compile" />
<File name="./tools/DmgIsoExtract.cs" subtype="Code" buildaction="Compile"
/>
<File name="./tools/PodTool.cs" subtype="Code" buildaction="Compile" />
+ <File name="./src/Firmware" subtype="Directory" buildaction="Compile" />
+ <File name="./src/Firmware/CpioArchive.cs" subtype="Code"
buildaction="Compile" />
+ <File name="./src/Firmware/DmgPartition.cs" subtype="Code"
buildaction="Compile" />
+ <File name="./src/Firmware/DmgImage.cs" subtype="Code"
buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="glib-sharp,
Version=2.8.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<ProjectReference type="Gac" localcopy="True" refto="Mono.Posix,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
+ <ProjectReference type="Gac" localcopy="True"
refto="ICSharpCode.SharpZipLib, Version=0.84.0.0, Culture=neutral,
PublicKeyToken=1b03e6acf1164f73" />
</References>
</Project>
\ No newline at end of file
Deleted: trunk/ipod-sharp/src/DmgImage.cs
===================================================================
--- trunk/ipod-sharp/src/DmgImage.cs 2006-06-10 13:34:28 UTC (rev 61615)
+++ trunk/ipod-sharp/src/DmgImage.cs 2006-06-10 15:21:43 UTC (rev 61616)
@@ -1,113 +0,0 @@
-//
-// DmgImage.cs: Parses DMG partitions from a DMG image
-// to build an HFS+ ISO image suitable for mounting
-//
-// Authors:
-// Aaron Bockover ([EMAIL PROTECTED])
-//
-// (C) 2006 Aaron Bockover
-//
-
-using System;
-using System.IO;
-using System.Net;
-using System.Text;
-using System.Xml;
-using System.Collections;
-
-namespace Dmg
-{
- public class Image : IEnumerable
- {
- private static readonly long PLIST_START = 0x1e0;
- private static readonly long PLIST_END = 0x128;
-
- private Stream dmg_stream;
- private BinaryReader dmg_reader;
- private XmlDocument plist_doc;
-
- private ArrayList partitions = new ArrayList();
-
- public Image(Stream dmgStream)
- {
- dmg_stream = dmgStream;
- dmg_reader = new BinaryReader(dmg_stream);
-
- ReadImage();
- }
-
- public void SavePartitionsXml(Stream stream)
- {
- plist_doc.Save(stream);
- }
-
- public void Extract(Stream isoStream)
- {
- long out_offset = 0;
- foreach(Partition partition in partitions) {
- partition.Extract(dmg_stream, isoStream, ref out_offset);
- }
- }
-
- public IEnumerator GetEnumerator()
- {
- return partitions.GetEnumerator();
- }
-
- private void ReadImage()
- {
- long plist_address = LocateVerifyPlist();
- ExtractPlistXmlDocument(plist_address);
- XmlNode partitions_node = LocatePartitionsNode(plist_doc);
-
- foreach(XmlNode partition_node in partitions_node) {
- partitions.Add(new Partition(partition_node));
- }
- }
-
- private long LocateVerifyPlist()
- {
- dmg_stream.Seek(-PLIST_START, SeekOrigin.End);
- long address = dmg_reader.ReadInt64();
- dmg_stream.Seek(-PLIST_END, SeekOrigin.End);
- if(dmg_reader.ReadInt64() != address) {
- throw new IOException("Could not verify plist addresses");
- }
-
- return IPAddress.HostToNetworkOrder(address);
- }
-
- private void ExtractPlistXmlDocument(long address)
- {
- dmg_stream.Seek(address, SeekOrigin.Begin);
- byte [] tail_bytes = dmg_reader.ReadBytes((int)(dmg_stream.Length
- address));
-
- string raw_xml = Encoding.UTF8.GetString(tail_bytes);
- raw_xml = raw_xml.Substring(0, raw_xml.LastIndexOf("</plist>") +
8);
-
- plist_doc = new XmlDocument();
- plist_doc.LoadXml(raw_xml);
- }
-
- private XmlNode LocatePartitionsNode(XmlDocument plistDoc)
- {
- foreach(XmlNode key_node in
plistDoc.SelectNodes("/plist/dict/key")) {
- if(key_node.InnerText != "resource-fork") {
- continue;
- }
-
- XmlNode dict_node = key_node.NextSibling;
-
- foreach(XmlNode node in dict_node.ChildNodes) {
- if(node.Name == "key" && node.InnerText == "blkx") {
- return node.NextSibling;
- }
- }
-
- break;
- }
-
- throw new ApplicationException("Could not read partition table
from plist");
- }
- }
-}
Deleted: trunk/ipod-sharp/src/DmgPartition.cs
===================================================================
--- trunk/ipod-sharp/src/DmgPartition.cs 2006-06-10 13:34:28 UTC (rev
61615)
+++ trunk/ipod-sharp/src/DmgPartition.cs 2006-06-10 15:21:43 UTC (rev
61616)
@@ -1,201 +0,0 @@
-//
-// DmgPartition.cs: Parses a DMG partition from the image
-// plist XML and can perform data extraction for generating
-// an HFS+ ISO image partition
-//
-// Authors:
-// Aaron Bockover ([EMAIL PROTECTED])
-//
-// (C) 2006 Aaron Bockover
-//
-
-using System;
-using System.IO;
-using System.Net;
-using System.Text;
-using System.Xml;
-using System.Collections;
-using ICSharpCode.SharpZipLib.Zip.Compression;
-
-namespace Dmg
-{
- public class Partition
- {
- private enum BlockType : uint
- {
- Copy = 0x00000001,
- Zero = 0x00000002,
- End = 0xffffffff,
- Zlib = 0x80000005,
- Unknown = 0x7ffffffe
- }
-
- private Hashtable table = new Hashtable();
-
- private Partition()
- {
- }
-
- internal Partition(XmlNode node)
- {
- ParsePartition(node);
- }
-
- private void ParsePartition(XmlNode node)
- {
- foreach(XmlNode key_node in node.SelectNodes("key")) {
- XmlNode value_node = key_node.NextSibling;
- if(value_node == null) {
- continue;
- }
-
- object value = ParseValue(value_node);
- if(value != null) {
- table.Add(key_node.InnerText.ToLower(), value);
- }
- }
- }
-
- private object ParseValue(XmlNode node)
- {
- if(node.Name == "string") {
- return node.InnerText.Trim();
- } else if(node.Name == "data") {
- return Convert.FromBase64String(node.InnerText);
- }
-
- return null;
- }
-
- internal void Extract(Stream dmgStream, Stream isoStream, ref long
lastOutOffset)
- {
- MemoryStream stream = new MemoryStream(Data);
- BinaryReader reader = new BinaryReader(stream);
-
- byte [] temp = new byte[0x40000];
- byte [] otemp = new byte[0x40000];
- byte [] zeroblock = new byte[4096];
-
- int offset = 0xcc;
- long total_size = 0;
- long block_count = 0;
-
- BlockType block_type = BlockType.Zero;
-
- while(block_type != BlockType.End) {
- stream.Seek(offset, SeekOrigin.Begin);
- block_type = (BlockType)EndianSwap(reader.ReadInt32());
-
- stream.Seek(offset + 12, SeekOrigin.Begin);
- long out_offset = EndianSwap(reader.ReadInt32()) * 0x200;
-
- stream.Seek(offset + 20, SeekOrigin.Begin);
- long out_size = EndianSwap(reader.ReadInt32()) * 0x200;
-
- stream.Seek(offset + 28, SeekOrigin.Begin);
- long in_offset = EndianSwap(reader.ReadInt32());
-
- stream.Seek(offset + 36, SeekOrigin.Begin);
- long in_size = EndianSwap(reader.ReadInt32());
-
- out_offset += lastOutOffset;
-
- if(block_type == BlockType.Zlib) {
- dmgStream.Seek(in_offset, SeekOrigin.Begin);
- if(temp.Length < in_size) {
- temp = new byte[in_size];
- }
-
- long total_bytes_read = 0;
- while(total_bytes_read < in_size) {
- total_bytes_read += dmgStream.Read(temp, 0,
- Math.Min((int)(in_size - total_bytes_read),
temp.Length));
- }
-
- Inflater inflater = new Inflater();
- inflater.SetInput(temp, 0, (int)total_bytes_read);
-
- if(otemp.Length < out_size + 4) {
- otemp = new byte[out_size + 4];
- }
-
- inflater.Inflate(otemp);
- if(inflater.RemainingInput > 0) {
- throw new ApplicationException("Could not inflate
entire block");
- }
-
- isoStream.Write(otemp, 0, (int)out_size);
- } else if(block_type == BlockType.Copy) {
- dmgStream.Seek(in_offset, SeekOrigin.Begin);
-
- int bytes_read = dmgStream.Read(temp, 0,
Math.Min((int)in_size, temp.Length));
- long total_bytes_read = bytes_read;
-
- while(bytes_read != -1) {
- isoStream.Write(temp, 0, bytes_read);
- if(total_bytes_read >= in_size) {
- break;
- }
-
- bytes_read = dmgStream.Read(temp, 0,
- Math.Min((int)(in_size - total_bytes_read),
temp.Length));
-
- if(bytes_read > 0) {
- total_bytes_read += bytes_read;
- }
- }
- } else if(block_type == BlockType.Zero) {
- long zero_block_count = out_size / zeroblock.Length;
-
- for(int i = 0; i < zero_block_count; ++i) {
- isoStream.Write(zeroblock, 0, zeroblock.Length);
- }
-
- isoStream.Write(zeroblock, 0, (int)(out_size %
zeroblock.Length));
- } else if(block_type == BlockType.End) {
- lastOutOffset = out_offset;
- }
-
- offset += 0x28;
- block_count++;
- total_size += out_size;
- }
- }
-
- private static int EndianSwap(int input)
- {
- return IPAddress.HostToNetworkOrder(input);
- }
-
- public object this[string key] {
- get { return table[key]; }
- }
-
- public string ID {
- get { return table["id"] as string; }
- }
-
- public string Name {
- get { return table["name"] as string; }
- }
-
- public string Attributes {
- get { return table["attributes"] as string; }
- }
-
- public int AttributesNumeric {
- get {
- if(Attributes.StartsWith("0x")) {
- return Int32.Parse(Attributes.Substring(2),
- System.Globalization.NumberStyles.AllowHexSpecifier);
- }
-
- return 0;
- }
- }
-
- public byte [] Data {
- get { return table["data"] as byte []; }
- }
- }
-}
Added: trunk/ipod-sharp/src/Firmware/CpioArchive.cs
===================================================================
--- trunk/ipod-sharp/src/Firmware/CpioArchive.cs 2006-06-10 13:34:28 UTC
(rev 61615)
+++ trunk/ipod-sharp/src/Firmware/CpioArchive.cs 2006-06-10 15:21:43 UTC
(rev 61616)
@@ -0,0 +1,207 @@
+//
+// CpioArchive.cs: Reads/Extracts files from an ASCII CPIO Archive
+//
+// Authors:
+// Aaron Bockover ([EMAIL PROTECTED])
+//
+// (C) 2006 Aaron Bockover
+//
+// NOTE: Currently, attributes like mode, uid, gid, and
+// mtime are ignored when extracting entries.
+//
+//
+// CPIO ASCII File Entry Header
+//
+// Field Width Field Name Meaning
+// --------------------------------------------------------------
+// 6 magic magic number "070707"
+// 6 dev device where file resides
+// 6 ino I-number of file
+// 6 mode file mode
+// 6 uid owner user ID
+// 6 gid owner group ID
+// 6 nlink number of links to file
+// 6 rdev device major/minor for special file
+// 11 mtime modify time of file
+// 6 namesize length of file name
+// 11 filesize length of file to follow
+//
+
+using System;
+using System.IO;
+using System.Text;
+using System.Collections;
+
+namespace IPod.Firmware
+{
+ public static class CpioTest
+ {
+ /*public static void Main(string [] args)
+ {
+ // extract all iPod firmware from iPodUpdater Archive.pax
+ CpioArchive archive = new CpioArchive(args[0]);
+ foreach(CpioFileEntry entry in archive) {
+ string filename = Path.GetFileName(entry.FileName);
+ if(filename.StartsWith("Firmware-")) {
+ archive.ExtractEntry(entry, filename);
+ }
+ }
+ }*/
+ }
+
+ public struct CpioFileEntry
+ {
+ internal short dev;
+ internal short ino;
+ internal short mode;
+ internal short uid;
+ internal short gid;
+ internal short nlink;
+ internal short rdev;
+ internal int mtime;
+ internal short namesize;
+ internal int filesize;
+ internal string filename;
+ internal long cpio_offset;
+
+ public short Device { get { return dev; } }
+ public short Inumber { get { return ino; } }
+ public short Uid { get { return uid; } }
+ public short Gid { get { return gid; } }
+ public short Nlinks { get { return nlink; } }
+ public int Mtime { get { return mtime; } }
+ public int FileSize { get { return filesize; } }
+ public string FileName { get { return filename; } }
+ }
+
+ public class CpioArchive : IEnumerable
+ {
+ private Stream stream;
+ private BinaryReader reader;
+ private long total_size = 0;
+ private ArrayList entries = new ArrayList();
+
+ public CpioArchive(string cpioFile) : this(new FileStream(cpioFile,
FileMode.Open))
+ {
+ }
+
+ public CpioArchive(Stream cpioStream)
+ {
+ stream = cpioStream;
+ reader = new BinaryReader(stream);
+
+ ReadCpioEntries();
+ }
+
+ public void ExtractEntry(CpioFileEntry entry, string outFile)
+ {
+ ExtractEntry(entry, new FileStream(outFile, FileMode.Create));
+ }
+
+ public void ExtractEntry(CpioFileEntry entry, Stream outStream)
+ {
+ stream.Seek(entry.cpio_offset, SeekOrigin.Begin);
+
+ byte [] block = new byte[4096];
+ int blocks = entry.filesize / block.Length;
+ int remainder = entry.filesize % block.Length;
+
+ for(int i = 0; i < blocks; i++) {
+ stream.Read(block, 0, block.Length);
+ outStream.Write(block, 0, block.Length);
+ }
+
+ if(remainder > 0) {
+ stream.Read(block, 0, remainder);
+ outStream.Write(block, 0, remainder);
+ }
+ }
+
+ public IEnumerator GetEnumerator()
+ {
+ return entries.GetEnumerator();
+ }
+
+ private void ReadCpioEntries()
+ {
+ stream.Seek(0, SeekOrigin.Begin);
+
+ while(true) {
+ CpioFileEntry entry = ReadFileEntry();
+
+ if(entry.filesize == 0 && entry.filename == "TRAILER!!!") {
+ break;
+ }
+
+ entries.Add(entry);
+ total_size += entry.filesize;
+
+ stream.Seek(entry.filesize, SeekOrigin.Current);
+ }
+
+ stream.Seek(0, SeekOrigin.Begin);
+ }
+
+ private static int FromOctal(string number)
+ {
+ int result = 0;
+
+ foreach(char digit in number) {
+ if('0' <= digit && digit <= '7') {
+ result = 8 * result + (digit - '0');
+ } else {
+ throw new FormatException();
+ }
+ }
+
+ return result;
+ }
+
+ private short ReadFileEntryFieldShort()
+ {
+ string value = Encoding.ASCII.GetString(reader.ReadBytes(6));
+ return (short)FromOctal(value);
+ }
+
+ private int ReadFileEntryFieldInt()
+ {
+ string value = Encoding.ASCII.GetString(reader.ReadBytes(11));
+ return FromOctal(value);
+ }
+
+ private CpioFileEntry ReadFileEntry()
+ {
+ if(Encoding.ASCII.GetString(reader.ReadBytes(6)) != "070707") {
+ throw new IOException("Invalid CPIO file header. Expected
magic number field 070707.");
+ }
+
+ CpioFileEntry entry = new CpioFileEntry();
+
+ entry.dev = ReadFileEntryFieldShort();
+ entry.ino = ReadFileEntryFieldShort();
+ entry.mode = ReadFileEntryFieldShort();
+ entry.uid = ReadFileEntryFieldShort();
+ entry.gid = ReadFileEntryFieldShort();
+ entry.nlink = ReadFileEntryFieldShort();
+ entry.rdev = ReadFileEntryFieldShort();
+ entry.mtime = ReadFileEntryFieldInt();
+ entry.namesize = ReadFileEntryFieldShort();
+ entry.filesize = ReadFileEntryFieldInt();
+
+ entry.filename =
Encoding.UTF8.GetString(reader.ReadBytes(entry.namesize - 1));
+ reader.ReadByte();
+
+ entry.cpio_offset = stream.Position;
+
+ return entry;
+ }
+
+ public long TotalSize {
+ get { return total_size; }
+ }
+
+ public int FileCount {
+ get { return entries.Count; }
+ }
+ }
+}
Copied: trunk/ipod-sharp/src/Firmware/DmgImage.cs (from rev 61609,
trunk/ipod-sharp/src/DmgImage.cs)
Copied: trunk/ipod-sharp/src/Firmware/DmgPartition.cs (from rev 61609,
trunk/ipod-sharp/src/DmgPartition.cs)
Added: trunk/ipod-sharp/src/Firmware/Makefile.am
===================================================================
--- trunk/ipod-sharp/src/Firmware/Makefile.am 2006-06-10 13:34:28 UTC (rev
61615)
+++ trunk/ipod-sharp/src/Firmware/Makefile.am 2006-06-10 15:21:43 UTC (rev
61616)
@@ -0,0 +1,21 @@
+MCS_FLAGS = -debug
+ASSEMBLY = ipod-sharp-firmware.dll
+
+ipoddir = $(prefix)/lib/ipod-sharp
+ipod_DATA = $(ASSEMBLY)
+
+ASSEMBLY_SOURCES = \
+ $(srcdir)/DmgImage.cs \
+ $(srcdir)/DmgPartition.cs \
+ $(srcdir)/CpioArchive.cs
+
+all: $(ASSEMBLY)
+
+$(ASSEMBLY): $(ASSEMBLY_SOURCES)
+ $(MCS) $(MCS_FLAGS) -keyfile:$(top_srcdir)/ipod-sharp.snk
-target:library -out:$@ $(ASSEMBLY_SOURCES) -r:ICSharpCode.SharpZipLib
-r:Mono.Posix
+
+EXTRA_DIST = $(ASSEMBLY_SOURCES)
+
+CLEANFILES = $(ASSEMBLY) *.mdb
+MAINTAINERCLEANFILES = Makefile.in
+
Modified: trunk/ipod-sharp/src/Makefile.am
===================================================================
--- trunk/ipod-sharp/src/Makefile.am 2006-06-10 13:34:28 UTC (rev 61615)
+++ trunk/ipod-sharp/src/Makefile.am 2006-06-10 15:21:43 UTC (rev 61616)
@@ -1,3 +1,4 @@
+SUBDIRS = Firmware
DOC_UPDATER = @MONODOCER@ -delete
DOC_ASSEMBLER = @MDASSEMBLER@ --out ipod-sharp-docs --ecma
@@ -28,9 +29,7 @@
$(srcdir)/Track.cs \
$(srcdir)/TrackDatabase.cs \
$(srcdir)/Utility.cs \
- $(srcdir)/ShuffleTrackDatabase.cs \
- $(srcdir)/DmgImage.cs \
- $(srcdir)/DmgPartition.cs
+ $(srcdir)/ShuffleTrackDatabase.cs
ASSEMBLY_RESOURCES =
@@ -64,6 +63,6 @@
$(srcdir)/en/*/*.xml \
ipod-sharp-docs.source
-CLEANFILES = $(ASSEMBLY)
+CLEANFILES = $(ASSEMBLY) *.mdb
MAINTAINERCLEANFILES = Makefile.in
Modified: trunk/ipod-sharp/tools/Makefile.am
===================================================================
--- trunk/ipod-sharp/tools/Makefile.am 2006-06-10 13:34:28 UTC (rev 61615)
+++ trunk/ipod-sharp/tools/Makefile.am 2006-06-10 15:21:43 UTC (rev 61616)
@@ -5,7 +5,7 @@
IPOD_TOOL_SOURCES = $(srcdir)/PodTool.cs
DMG_ISO_EXTRACT_SRC = \
$(srcdir)/DmgIsoExtract.cs \
- $(top_builddir)/src/Dmg*.cs
+ $(top_builddir)/src/Firmware/Dmg*.cs
all: $(TOOLS)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches