Author: abock
Date: 2007-09-19 14:12:39 -0400 (Wed, 19 Sep 2007)
New Revision: 86025

Added:
   trunk/ipod-sharp/tools/Hash58.cs
Modified:
   trunk/ipod-sharp/tools/Makefile.am
Log:
Added hash58 tool

Added: trunk/ipod-sharp/tools/Hash58.cs
===================================================================
--- trunk/ipod-sharp/tools/Hash58.cs    2007-09-19 17:21:31 UTC (rev 86024)
+++ trunk/ipod-sharp/tools/Hash58.cs    2007-09-19 18:12:39 UTC (rev 86025)
@@ -0,0 +1,57 @@
+using System;
+using System.IO;
+using System.Text;
+
+namespace IPod
+{
+    public static class Hash58Test
+    {
+        public static void Main(string [] args)
+        {
+            if(args.Length != 2) {
+                Console.WriteLine("Usage:");
+                Console.WriteLine("  mono hash58.exe iTunesDBPath 
Firewire-ID");
+                return;
+            }
+
+            string path = args[0];
+            string firewire_id = args[1];
+
+            byte [] hash = null;
+            byte [] original = new byte[20];
+
+            using(BinaryReader reader = new BinaryReader(File.Open(path, 
FileMode.Open))) {
+                byte [] contents = new byte[reader.BaseStream.Length];
+                reader.Read(contents, 0, contents.Length);
+                
+                Array.Copy(contents, 0x58, original, 0, 20);
+
+                Zero(contents, 0x18, 8);
+                Zero(contents, 0x32, 20);
+                Zero(contents, 0x58, 20);
+
+                hash = Hash58.GenerateHash(firewire_id, contents);
+            }
+
+            Console.WriteLine("Original Hash:  {0}", HashToString(original));
+            Console.WriteLine("Generated Hash: {0}", HashToString(hash));
+        }
+
+        private static string HashToString(byte [] buffer)
+        {
+            StringBuilder builder = new StringBuilder();
+            foreach(byte b in buffer) {
+                builder.AppendFormat("{0:X2}", b);
+            }
+            return builder.ToString();
+        }
+
+        private static void Zero(byte [] buffer, int index, int length)
+        {
+            for(int i = index; i < index + length; i++) {
+                buffer[i] = 0;
+            }
+        }
+    }
+}
+

Modified: trunk/ipod-sharp/tools/Makefile.am
===================================================================
--- trunk/ipod-sharp/tools/Makefile.am  2007-09-19 17:21:31 UTC (rev 86024)
+++ trunk/ipod-sharp/tools/Makefile.am  2007-09-19 18:12:39 UTC (rev 86025)
@@ -1,8 +1,13 @@
 MCS_FLAGS = -debug
 
-TOOLS = ipod-tool.exe dmg-iso-extract.exe ipod-firmware-extract.exe 
photo-adder.exe video-adder.exe
+TOOLS = hash58.exe ipod-tool.exe dmg-iso-extract.exe ipod-firmware-extract.exe 
photo-adder.exe video-adder.exe
 
-IPOD_TOOL_SOURCES = $(srcdir)/PodTool.cs
+HASH58_SRC = \
+       $(srcdir)/Hash58.cs \
+       $(top_srcdir)/src/Hash58.cs
+
+IPOD_TOOL_SRC = $(srcdir)/PodTool.cs
+
 DMG_ISO_EXTRACT_SRC = \
        $(srcdir)/DmgIsoExtract.cs \
        $(top_builddir)/src/Firmware/DmgImage.cs \
@@ -18,9 +23,12 @@
 
 all: $(TOOLS)
 
-ipod-tool.exe: $(IPOD_TOOL_SOURCES)
-       $(MCS) $(MCS_FLAGS) -r:$(top_builddir)/src/ipod-sharp.dll -target:exe 
-out:$@ $(IPOD_TOOL_SOURCES)
+hash58.exe: $(HASH58_SRC)
+       $(MCS) $(MCS_FLAGS) -target:exe -out:$@ $(HASH58_SRC)
 
+ipod-tool.exe: $(IPOD_TOOL_SRC)
+       $(MCS) $(MCS_FLAGS) -r:$(top_builddir)/src/ipod-sharp.dll -target:exe 
-out:$@ $(IPOD_TOOL_SRC)
+
 dmg-iso-extract.exe: $(DMG_ISO_EXTRACT_SRC)
        $(MCS) $(MCS_FLAGS) -r:ICSharpCode.SharpZipLib -target:exe -out:$@ 
$(DMG_ISO_EXTRACT_SRC)
 
@@ -33,7 +41,7 @@
 video-adder.exe: $(VIDEO_ADDER_SRC)
        $(MCS) $(MCS_FLAGS) -target:exe -out:$@ $(VIDEO_ADDER_SRC) 
-r:$(top_builddir)/src/ipod-sharp.dll -pkg:gtk-sharp-2.0
 
-EXTRA_DIST = $(IPOD_TOOL_SOURCES) $(DMG_ISO_EXTRACT_SRC) 
$(DMG_FIRMWARE_EXTRACT_SRC) $(PHOTO_ADDER_SRC) $(VIDEO_ADDER_SRC)
+EXTRA_DIST = $(HASH58_SRC) $(IPOD_TOOL_SRC) $(DMG_ISO_EXTRACT_SRC) 
$(DMG_FIRMWARE_EXTRACT_SRC) $(PHOTO_ADDER_SRC) $(VIDEO_ADDER_SRC)
 CLEANFILES = $(TOOLS) *.mdb
 MAINTAINERCLEANFILES = Makefile.in
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to