Esempio n. 1
0
        public int auth_client(byte[] givenusername)
        {
            int kdnr = 0;

            for(kdnr=0;kdnr<kundendb.Length;kdnr++)
            {

                MD5 uname = new MD5CryptoServiceProvider();
                ASCIIEncoding uname_md5_encoding=new ASCIIEncoding();
                byte[] uname_md5 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                uname_md5 = uname.ComputeHash(uname_md5_encoding.GetBytes(kundendb[kdnr].usr));
                uname.Clear();

                //ASCIIEncoding crc32_encoding = new ASCIIEncoding();
                CRC32 crc = new CRC32(0xedb88320); // equivalent to new CRC32(CRC32.DefaultPolynomial);
                byte[] uname_crc32 = { 0, 0, 0, 0 };
                uname_crc32 = crc.ComputeHash(uname_md5);
                crc.Clear();

                if((givenusername[0]==uname_crc32[0]) && (givenusername[1]==uname_crc32[1]) &&(givenusername[2]==uname_crc32[2]) &&(givenusername[3]==uname_crc32[3]))
                    {
                        return kdnr;
                    }

            }

            return -1; //lets return the "kundennummer" of the right viewer
        }
		public static byte[] GetChecksum(Stream stream)
		{
			CRC32 crc = new CRC32();
			return BitConverter.GetBytes(crc.GetCrc32(stream));

			//MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
			//return md5.ComputeHash(stream);
		}
Esempio n. 3
0
        public void CRCHash()
        {
            //test the CRC32 algorithm
            CRC32 a1 = new CRC32();
            CRC32 a2 = new CRC32();

            IncrementalTest(a1, a2);
        }
Esempio n. 4
0
        public void RangeTest()
        {
            byte[] sample = new byte[10000];
            const int delta = 19;
            new System.Random().NextBytes(sample);

            byte[] sample2 = new byte[10];
            for(int i=0; i<10; i++)
            {
                sample2[i] = sample[i+delta];
            }

            CRC32 expected = new CRC32();
            expected.ComputeHash(sample2, 0, 10);

            CRC32 actual = new CRC32();
            actual.ComputeHash(sample, delta, 10);

            Assert.AreEqual(BitConverter.ToString(expected.Hash), BitConverter.ToString(actual.Hash));
        }
Esempio n. 5
0
        public void MethodsTest()
        {
            byte[] sample = new byte[10000];
            new System.Random().NextBytes(sample);

            CRC32 a1 = new CRC32();
            CRC32 a2 = new CRC32();
            CRC32 a3 = new CRC32();
            CRC32 a4 = new CRC32();

            //method1
            byte[] a1Hash = a1.ComputeHash(sample);
            //method2
            a2.TransformFinalBlock(sample, 0, 10000);
            byte[] a2Hash = a2.Hash;
            //method3
            for(int i=0; i<10000; i+=1000)
            {
                a3.TransformBlock(sample, i, 1000, sample, i);
            }
            a3.TransformFinalBlock(sample, 0, 0);
            byte[] a3Hash = a3.Hash;
            //method4
            for(int i=0; i<10000; i+=1000)
            {
                if (i == 9000)
                    a4.TransformFinalBlock(sample, i, 1000);
                else
                    a4.TransformBlock(sample, i, 1000, sample, i);
            }
            byte[] a4Hash = a4.Hash;

            Assert.AreEqual(BitConverter.ToString(a1Hash), BitConverter.ToString(a2Hash), "Method a2 failed");
            Assert.AreEqual(BitConverter.ToString(a1Hash), BitConverter.ToString(a3Hash), "Method a3 failed");
            Assert.AreEqual(BitConverter.ToString(a1Hash), BitConverter.ToString(a4Hash), "Method a4 failed");
        }
Esempio n. 6
0
        public void TestCRC32Table()
        {
            //from #ziplib:
            uint[] CrcTable = new uint[] {
                0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419,
                0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4,
                0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07,
                0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
                0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856,
                0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,
                0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4,
                0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
                0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3,
                0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A,
                0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599,
                0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
                0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190,
                0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,
                0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E,
                0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
                0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED,
                0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950,
                0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3,
                0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
                0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A,
                0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5,
                0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010,
                0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
                0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17,
                0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6,
                0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615,
                0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
                0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344,
                0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
                0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A,
                0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
                0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1,
                0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C,
                0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF,
                0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
                0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE,
                0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31,
                0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C,
                0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
                0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B,
                0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
                0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1,
                0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
                0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278,
                0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7,
                0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66,
                0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
                0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605,
                0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8,
                0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B,
                0x2D02EF8D
            };

            CRC32 crc = new CRC32();
            uint[] ourTable = crc.CurrentTable;

            for (int i=0; i<CrcTable.Length; i++)
            {
                Assert.AreEqual(CrcTable[i], ourTable[i], "Tables did not match at element " + i.ToString());
            }
        }
Esempio n. 7
0
        public int validate_request(byte[] message)
        {
            int i=0;

            switch(message[0])
            {
                case 0:
                {
                    byte length = message[1];
                    byte[] datacrc = new byte[4];
                    byte[] data = new byte[length];

                    Array.Copy(message,4,datacrc,0,4);
                    Array.Copy(message,20,data,0,length);

                    CRC32 crc = new CRC32(0xedb88320);
                    byte[] data_crc32 = crc.ComputeHash(data);

                    for(i=0;i<4;i++)
                    {
                        if(datacrc[i]!=data_crc32[i])
                        {
                            return -1; //crc not correct - data broken !
                        }
                    }

                    return 1; // data is ok, we can proceed ...
                }
                case 2:
                {
                    return 0; //not implemented yet
                }
            }
            return -1;
        }
Esempio n. 8
0
        public byte[] generate_cwanswer(byte[] checksum, byte[] message, byte[] cw, string key)
        {
            byte[] cwanswer = new byte[48];
            byte[] cryptedanswer = new byte[52];
            MemoryStream ms = new MemoryStream();

            CRC32 crc = new CRC32(0xedb88320); // equivalent to new CRC32(CRC32.DefaultPolynomial);
            byte[] cw_crc32 = crc.ComputeHash(cw);

            //Array.Copy(checksum,0,cwanswer,0,4);

            Array.Copy(message,0,cwanswer,0,20);
            Array.Copy(cw_crc32,0,cwanswer,4,4);
            Array.Copy(cw,0,cwanswer,20,16);
            cwanswer[0] = 0x01;
            cwanswer[1] = 0x10;
            cwanswer[2] = 0x32;
            cwanswer[3] = 0x84;

            for(int i=0;i<12;i++)
                cwanswer[i+36] = 0xFF;

            MD5 passwd = new MD5CryptoServiceProvider();
            ASCIIEncoding passwd_md5_encoding=new ASCIIEncoding();
            byte[] passwd_md5 = passwd.ComputeHash(passwd_md5_encoding.GetBytes(key));

            RijndaelManaged aes = new RijndaelManaged();
            aes.Mode = CipherMode.ECB;
            aes.BlockSize = 128;
            aes.KeySize = 128; //128-Bit AES En/Decryption
            aes.Key = passwd_md5;

            CryptoStream cs = new CryptoStream(ms, aes.CreateEncryptor(), CryptoStreamMode.Write);
            cs.Write(cwanswer, 0, 48);
            aes.Clear();

            byte[] cryptedData = ms.ToArray();

            Array.Copy(cryptedData,0,cryptedanswer,4,48);
            Array.Copy(checksum,0,cryptedanswer,0,4);

            return cryptedanswer;
        }
Esempio n. 9
0
        public static HashAlgorithm ToHashAlgorithm(int hashTypeId)
        {
            HashAlgorithm algorithm;
            switch (hashTypeId)
            {
                case 0: // sfv - CRC32
                    algorithm = new CRC32();
                    break;
                case 1: // md5
                    algorithm = MD5.Create();
                    break;
                case 2:
                case 3: // sha or sha1
                    algorithm = new SHA1CryptoServiceProvider();
                    break;
                case 4: // sha256
                    algorithm = new SHA256Managed();
                    break;
                case 5: // sha384
                    algorithm = new SHA384Managed();
                    break;
                case 6: // sha512
                    algorithm = new SHA512Managed();
                    break;
                default:
                    throw new ArgumentException(@"Unrecognized algorithm index", "hashTypeId");
            }

            return algorithm;
        }
Esempio n. 10
0
        public static HashAlgorithm ToHashAlgorithm(string hashType)
        {
            if (hashType == null)
            {
                throw new ArgumentNullException("hashType");
            }

            HashAlgorithm algorithm;
            switch (hashType.ToLowerInvariant())
            {
                case "sfv": // sfv - CRC32
                    algorithm = new CRC32();
                    break;
                case "md5": // md5
                    algorithm = MD5.Create();
                    break;
                case "sha":
                case "sha1": // sha or sha1
                    algorithm = new SHA1CryptoServiceProvider();
                    break;
                case "sha256": // sha256
                    algorithm = new SHA256Managed();
                    break;
                case "sha384": // sha384
                    algorithm = new SHA384Managed();
                    break;
                case "sha512": // sha512
                    algorithm = new SHA512Managed();
                    break;
                default:
                    throw new ArgumentException(@"Unsupported hash algorithm", "hashType");
            }

            return algorithm;
        }
Esempio n. 11
0
 public void MakeOneTorrentFromFolder()
 {
     long num = 0;
     long num6 = 0;
     long num8 = 0;
     long num9 = 0;
     long num12 = 0;
     string[] strArray = Directory.GetFiles(this.FileNameToMake.Text, "*", SearchOption.AllDirectories);
     if (Strings.Right(this.FileNameToMake.Text, 1) != @"\")
     {
         this.FileNameToMake.Text = this.FileNameToMake.Text + @"\";
     }
     TorrentDictionary dictionary2 = new TorrentDictionary();
     TorrentList list = new TorrentList();
     ArrayList list2 = new ArrayList();
     this.OptionalHashProgress.Maximum = strArray.GetLength(0) * CountMultiplier;
     foreach (string str10 in strArray)
     {
         if (this.IsFileCleared(str10))
         {
             FileStream stream;
             byte[] hash;
             IEnumerator enumerator = null;
             TorrentDictionary dictionary3 = new TorrentDictionary();
             TorrentNumber number2 = new TorrentNumber();
             TorrentList list3 = new TorrentList();
             ArrayList list4 = new ArrayList();
             TorrentString str11 = new TorrentString();
             number2.Value = FileSystem.FileLen(str10);
             num12 += FileSystem.FileLen(str10);
             if (this.AutomaticPieceSize.Checked)
             {
                 num += number2.Value;
             }
             Array array = Strings.Right(str10, Strings.Len(str10) - Strings.Len(this.FileNameToMake.Text)).Split(new char[] { '\\' });
             try
             {
                 enumerator = array.GetEnumerator();
                 while (enumerator.MoveNext())
                 {
                     string str13 = Conversions.ToString(enumerator.Current);
                     if (str13 != "")
                     {
                         TorrentString str14 = new TorrentString {
                             Value = str13
                         };
                         list4.Add(str14);
                     }
                 }
             }
             finally
             {
                 if (enumerator is IDisposable)
                 {
                     (enumerator as IDisposable).Dispose();
                 }
             }
             list3.Value = list4;
             dictionary3.Add("length", number2);
             dictionary3.Add("path", list3);
             StringBuilder builder = new StringBuilder();
             HashChanger changer = new HashChanger();
             if (number2.Value < 0x100000000L)
             {
                 if (this.IncludeTiger.Checked)
                 {
                     string str16 = "";
                     this.TigerHash = new ThexThreaded();
                     TorrentString str15 = new TorrentString();
                     hash = this.TigerHash.GetTTH_Value(str10);
                     Application.DoEvents();
                     int index = 0;
                     foreach (byte num13 in hash)
                     {
                         str16 = str16 + Encoding.Default.GetString(hash, index, 1);
                         index++;
                     }
                     str15.Value = str16;
                     str16 = "";
                     hash = null;
                     this.OptionalHashProgress.Value++;
                     dictionary3.Add("tiger", str15);
                 }
                 GC.Collect();
             }
             else
             {
                 this.OptionalHashProgress.Value++;
             }
             if (this.IncludeSHA1.Checked)
             {
                 TorrentString str17 = new TorrentString();
                 stream = new FileStream(str10, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                 this.sha1.ComputeHash(stream);
                 stream.Close();
                 Application.DoEvents();
                 hash = this.sha1.Hash;
                 changer.bytehash = this.sha1.Hash;
                 str17.Value = changer.rawhash;
                 builder.Remove(0, builder.Length);
                 hash = null;
                 this.OptionalHashProgress.Value++;
                 dictionary3.Add("sha1", str17);
                 GC.Collect();
             }
             if (this.IncludeMD5.Checked)
             {
                 TorrentString str19 = new TorrentString();
                 stream = new FileStream(str10, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                 builder = new StringBuilder();
                 this.md5.ComputeHash(stream);
                 Application.DoEvents();
                 stream.Close();
                 foreach (byte num13 in this.md5.Hash)
                 {
                     builder.AppendFormat("{0:x2}", num13);
                 }
                 str19.Value = builder.ToString();
                 builder.Remove(0, builder.Length);
                 hash = null;
                 this.OptionalHashProgress.Value++;
                 dictionary3.Add("md5sum", str19);
                 GC.Collect();
             }
             if (this.IncludeCRC32.Checked)
             {
                 TorrentString str20 = new TorrentString();
                 CRC32 crc = new CRC32();
                 int num15 = 0;
                 stream = new FileStream(str10, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                 Stream stream2 = stream;
                 stream = (FileStream) stream2;
                 num15 = crc.GetCrc32(ref stream2);
                 stream.Close();
                 Application.DoEvents();
                 str20.Value = string.Format("{0:X8}", num15);
                 this.OptionalHashProgress.Value++;
                 dictionary3.Add("crc32", str20);
                 GC.Collect();
             }
             if (this.IncludeED2K.Checked)
             {
                 string str21 = "";
                 string str22 = "";
                 TorrentString str23 = new TorrentString();
                 this.GetED2KHash(str10, ref str22, ref str21);
                 this.OptionalHashProgress.Value++;
                 str23.Value = str21;
                 dictionary3.Add("ed2k", str23);
                 GC.Collect();
             }
             list2.Add(dictionary3);
         }
         else
         {
             this.OptionalHashProgress.Maximum -= CountMultiplier;
         }
     }
     if (this.AutomaticPieceSize.Checked)
     {
         num9 = this.getautopiecesize(num);
     }
     else
     {
         num9 = Conversions.ToInteger(this.PieceSize.Text);
     }
     list.Value = list2;
     TorrentNumber number = new TorrentNumber {
         Value = num9
     };
     dictionary2.Add("files", list);
     dictionary2.Add("piece length", number);
     long upperBound = strArray.GetUpperBound(0);
     long num2 = 0L;
     long num3 = 0L;
     byte[] buffer = new byte[((int) num9) + 1];
     byte[] bytes = new byte[0x15];
     while (true)
     {
         if (this.IsFileCleared(strArray[(int) num2]))
         {
             this.FileHandling = File.Open(strArray[(int) num2], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
             if (GenerateVerbose)
             {
                 Interaction.MsgBox("Current File: " + strArray[(int) num2] + "\n File offset for Piece 0 of this file: " + Conversions.ToString(num3), MsgBoxStyle.OkOnly, null);
             }
             break;
         }
         num2 += 1L;
     }
     Label_062B:
     Thread.Sleep(10);
     Application.DoEvents();
     this.TorrentProgress.Value = (int) Math.Round((double) ((((double) num3) / ((double) num12)) * 100.0));
     byte[] buffer4 = new byte[((int) (num9 - 1L)) + 1];
     Label_0668:
     num6 = this.FileHandling.Read(buffer4, (int) num8, (int) (num9 - num8));
     num8 += num6;
     if (!((num2 <= upperBound) & (num8 < num9)))
     {
         string str3 = "";
         byte[] buffer5 = new byte[((int) (num8 - 1L)) + 1];
         long num27 = num8 - 1L;
         for (long i = 0L; i <= num27; i += 1L)
         {
             buffer5[(int) i] = buffer4[(int) i];
         }
         buffer4 = null;
         bytes = this.sha1.ComputeHash(buffer5);
         int num17 = 0;
         do
         {
             str3 = str3 + Encoding.Default.GetString(bytes, num17, 1);
             num17++;
         }
         while (num17 <= 0x13);
         bytes = null;
         num3 += num8;
         num8 = 0L;
         GC.Collect();
         if (num3 >= num12)
         {
             this.FileHandling.Close();
             if (GenerateVerbose)
             {
                 Interaction.MsgBox("Size of files hashed: " + Conversions.ToString(num3) + " Size of files compared: " + Conversions.ToString(num12) + "\nNow Generating .torrent file", MsgBoxStyle.OkOnly, null);
             }
             this.TorrentProgress.Value = 100;
             string path = Strings.Left(this.FileNameToMake.Text, Strings.Len(this.FileNameToMake.Text) - 1) + ".torrent";
             TorrentString str9 = new TorrentString {
                 Value = str3
             };
             dictionary2.Add("pieces", str9);
             int num5 = Strings.Left(this.FileNameToMake.Text, Strings.Len(this.FileNameToMake.Text) - 1).LastIndexOf(@"\");
             int num4 = Strings.Len(this.FileNameToMake.Text) - num5;
             string str8 = Strings.Right(Strings.Left(this.FileNameToMake.Text, Strings.Len(this.FileNameToMake.Text) - 1), num4 - 2);
             TorrentString str7 = new TorrentString {
                 Value = str8
             };
             TorrentDictionary dictionary = new TorrentDictionary();
             TorrentString str4 = new TorrentString();
             dictionary2.Add("name", str7);
             str4.Value = this.AnnounceURL.Text;
             if (UseWSAConfig)
             {
                 ArrayList returnarray = new ArrayList();
                 TorrentList list6 = new TorrentList();
                 int webSeedData = TorrentGenFamily.GetWebSeedData(returnarray);
                 list6.Value = returnarray;
                 if (webSeedData >= 1)
                 {
                     dictionary.Add("httpseeds", list6);
                 }
             }
             TorrentString str2 = new TorrentString {
                 Value = "Torrent Generated by VB.Net TorrentGen - Written by DWKnight"
             };
             dictionary.Add("created by", str2);
             TorrentString str = new TorrentString();
             if (Strings.Trim(this.TorrentComment.Text) != "")
             {
                 str.Value = Strings.Trim(this.TorrentComment.Text);
                 dictionary.Add("comment", str);
             }
             if (this.AnnounceURL.Text != "")
             {
                 dictionary.Add("announce", str4);
             }
             if (this.PrivateTorrent.Checked)
             {
                 TorrentNumber number3 = new TorrentNumber {
                     Value = 1L
                 };
                 dictionary2["private"] = number3;
             }
             dictionary.Add("info", dictionary2);
             TorrentString str5 = new TorrentString {
                 Value = "UTF8"
             };
             dictionary.Add("encoding", str5);
             if (this.MultiTrackerEnabled.Checked)
             {
                 this.CheckMultitTrackerTiers();
                 dictionary.Add("announce-list", MultiTrackerGenerator.MultiTrackerTiers);
             }
             if (File.Exists(path))
             {
                 FileSystem.Kill(path);
             }
             int fileNumber = FileSystem.FreeFile();
             FileSystem.FileOpen(fileNumber, path, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.LockReadWrite, -1);
             FileSystem.FilePut(fileNumber, dictionary.BEncoded, -1L, false);
             FileSystem.FileClose(new int[] { fileNumber });
             GC.Collect();
             if (this.MakeExternals.Checked)
             {
                 string str26 = "";
                 string str28 = "";
                 string str29 = "";
                 string str30 = "";
                 string str32 = "";
                 string str34 = "";
                 IEnumerator enumerator2 = null;
                 string expression = Strings.Left(this.FileNameToMake.Text, Strings.Len(this.FileNameToMake.Text) - 1);
                 string str27 = expression + ".md5";
                 string str31 = expression + ".sha1";
                 string str25 = expression + ".ed2k";
                 string str33 = expression + ".tiger";
                 string[] strArray2 = Strings.Split(expression, @"\", -1, CompareMethod.Binary);
                 strArray2[strArray2.GetUpperBound(0)] = Strings.Replace(strArray2[strArray2.GetUpperBound(0)], " ", ".", 1, -1, CompareMethod.Binary);
                 strArray2[strArray2.GetUpperBound(0)] = Strings.Replace(strArray2[strArray2.GetUpperBound(0)], "_", ".", 1, -1, CompareMethod.Binary);
                 foreach (string str35 in strArray2)
                 {
                     str29 = str29 + @"\" + str35;
                 }
                 str29 = Strings.Mid(str29, 2, Strings.Len(str29) - 1) + ".sfv";
                 LinkGeneration generation = new LinkGeneration();
                 HashChanger changer2 = new HashChanger();
                 try
                 {
                     enumerator2 = list2.GetEnumerator();
                     while (enumerator2.MoveNext())
                     {
                         IEnumerator enumerator3 = null;
                         TorrentDictionary current = (TorrentDictionary) enumerator2.Current;
                         generation = new LinkGeneration();
                         TorrentString str36 = new TorrentString();
                         try
                         {
                             enumerator3 = ((IEnumerable) NewLateBinding.LateGet(current["path"], null, "value", new object[0], null, null, null)).GetEnumerator();
                             while (enumerator3.MoveNext())
                             {
                                 TorrentString str37 = (TorrentString) enumerator3.Current;
                                 str36 = str37;
                             }
                         }
                         finally
                         {
                             if (enumerator3 is IDisposable)
                             {
                                 (enumerator3 as IDisposable).Dispose();
                             }
                         }
                         if (this.IncludeMD5.Checked)
                         {
                             TorrentString str38 = new TorrentString();
                             str38 = (TorrentString) current["md5sum"];
                             str28 = str28 + str36.Value + " " + str38.Value + "\r\n";
                         }
                         if (this.IncludeSHA1.Checked)
                         {
                             changer2 = new HashChanger {
                                 rawhash = Conversions.ToString(NewLateBinding.LateGet(current["sha1"], null, "value", new object[0], null, null, null))
                             };
                             str32 = str32 + str36.Value + " " + changer2.hexhash + "\r\n";
                         }
                         if (this.IncludeTiger.Checked && current.Contains("tiger"))
                         {
                             changer2 = new HashChanger {
                                 rawhash = Conversions.ToString(NewLateBinding.LateGet(current["tiger"], null, "value", new object[0], null, null, null))
                             };
                             str34 = str34 + str36.Value + " " + changer2.base32 + "\r\n";
                         }
                         if (this.IncludeCRC32.Checked)
                         {
                             str30 = Conversions.ToString(Operators.AddObject(Operators.AddObject(Operators.AddObject(str30 + str36.Value + " ", NewLateBinding.LateGet(current["crc32"], null, "value", new object[0], null, null, null)), '\r'), '\n'));
                         }
                         if (this.IncludeED2K.Checked)
                         {
                             generation.ED2KRaw = Conversions.ToString(NewLateBinding.LateGet(current["ed2k"], null, "Value", new object[0], null, null, null));
                             generation.FileSize = Conversions.ToLong(NewLateBinding.LateGet(current["length"], null, "Value", new object[0], null, null, null));
                             generation.FileName = str36.Value;
                             str26 = str26 + generation.ClassicED2KLink + "\r\n";
                             str26 = str26 + str36.Value + " " + generation.ED2KHex + "\r\n";
                         }
                         GC.Collect();
                     }
                 }
                 finally
                 {
                     if (enumerator2 is IDisposable)
                     {
                         (enumerator2 as IDisposable).Dispose();
                     }
                 }
                 if (this.IncludeMD5.Checked)
                 {
                     if (File.Exists(str27))
                     {
                         FileSystem.Kill(str27);
                     }
                     int num19 = FileSystem.FreeFile();
                     FileSystem.FileOpen(num19, str27, OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
                     FileSystem.Print(num19, new object[] { str28 });
                     FileSystem.FileClose(new int[] { num19 });
                 }
                 if (this.IncludeTiger.Checked)
                 {
                     if (File.Exists(str33))
                     {
                         FileSystem.Kill(str33);
                     }
                     int num20 = FileSystem.FreeFile();
                     FileSystem.FileOpen(num20, str33, OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
                     FileSystem.Print(num20, new object[] { str34 });
                     FileSystem.FileClose(new int[] { num20 });
                 }
                 if (this.IncludeSHA1.Checked)
                 {
                     if (File.Exists(str31))
                     {
                         FileSystem.Kill(str31);
                     }
                     int num21 = FileSystem.FreeFile();
                     FileSystem.FileOpen(num21, str31, OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
                     FileSystem.Print(num21, new object[] { str32 });
                     FileSystem.FileClose(new int[] { num21 });
                 }
                 if (this.IncludeED2K.Checked)
                 {
                     if (File.Exists(str25))
                     {
                         FileSystem.Kill(str25);
                     }
                     int num22 = FileSystem.FreeFile();
                     FileSystem.FileOpen(num22, str25, OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
                     FileSystem.Print(num22, new object[] { str26 });
                     FileSystem.FileClose(new int[] { num22 });
                 }
                 if (this.IncludeCRC32.Checked)
                 {
                     if (File.Exists(str29))
                     {
                         FileSystem.Kill(str29);
                     }
                     int num23 = FileSystem.FreeFile();
                     FileSystem.FileOpen(num23, str29, OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
                     FileSystem.Print(num23, new object[] { str30 });
                     FileSystem.FileClose(new int[] { num23 });
                 }
             }
             GC.Collect();
             return;
         }
         goto Label_062B;
     }
     num2 += 1L;
     while (true)
     {
         if (num2 > strArray.GetUpperBound(0))
         {
             goto Label_0668;
         }
         if (this.IsFileCleared(strArray[(int) num2]))
         {
             break;
         }
         num2 += 1L;
     }
     this.FileHandling.Close();
     this.FileHandling = File.Open(strArray[(int) num2], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
     if (GenerateVerbose)
     {
         Interaction.MsgBox("Current File: " + strArray[(int) num2] + "\n File offset for Piece 0 of this file: " + Conversions.ToString(num3), MsgBoxStyle.OkOnly, null);
     }
     goto Label_0668;
 }
Esempio n. 12
0
 public void MakeTorrentFromFile(string NameOfFile)
 {
     FileStream stream;
     string str6 = "";
     string hexhash = "";
     string str13 = "";
     string str14 = "";
     long filesize = FileSystem.FileLen(NameOfFile);
     TorrentString str10 = new TorrentString();
     TorrentString str7 = new TorrentString();
     TorrentString str5 = new TorrentString();
     TorrentString str4 = new TorrentString();
     TorrentString str12 = new TorrentString();
     StringBuilder builder = new StringBuilder();
     HashChanger changer = new HashChanger();
     this.OptionalHashProgress.Maximum = CountMultiplier;
     this.OptionalHashProgress.Value = 0;
     if (filesize < 0x100000000L)
     {
         if (this.IncludeTiger.Checked)
         {
             this.TigerHash = new ThexThreaded();
             changer = new HashChanger {
                 bytehash = this.TigerHash.GetTTH_Value(NameOfFile)
             };
             Application.DoEvents();
             str12.Value = changer.rawhash;
             str13 = changer.base32;
             this.OptionalHashProgress.Value++;
         }
     }
     else
     {
         this.OptionalHashProgress.Value++;
     }
     if (this.IncludeSHA1.Checked)
     {
         changer = new HashChanger();
         stream = new FileStream(NameOfFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
         this.sha1.ComputeHash(stream);
         stream.Close();
         Application.DoEvents();
         changer.bytehash = this.sha1.Hash;
         str10.Value = changer.rawhash;
         hexhash = changer.hexhash;
         this.OptionalHashProgress.Value++;
     }
     if (this.IncludeMD5.Checked)
     {
         changer = new HashChanger();
         stream = new FileStream(NameOfFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
         this.md5.ComputeHash(stream);
         stream.Close();
         changer.bytehash = this.md5.Hash;
         Application.DoEvents();
         str7.Value = changer.hexhash;
         this.OptionalHashProgress.Value++;
     }
     if (this.IncludeCRC32.Checked)
     {
         CRC32 crc = new CRC32();
         int num7 = 0;
         stream = new FileStream(NameOfFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
         Stream stream2 = stream;
         stream = (FileStream) stream2;
         num7 = crc.GetCrc32(ref stream2);
         stream.Close();
         str4.Value = string.Format("{0:X8}", num7);
         Application.DoEvents();
         this.OptionalHashProgress.Value++;
     }
     if (this.IncludeED2K.Checked)
     {
         string str3 = "";
         this.GetED2KHash(NameOfFile, ref str6, ref str3);
         this.OptionalHashProgress.Value++;
         str5.Value = str3;
     }
     this.FileHandling = File.Open(NameOfFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
     byte[] bytes = new byte[0x15];
     if (this.AutomaticPieceSize.Checked)
     {
         this.piecesizetouse = this.getautopiecesize(filesize);
     }
     else
     {
         this.piecesizetouse = Conversions.ToInteger(this.PieceSize.Text);
     }
     long num3 = 0L;
     this.FileHandling.Seek(0L, SeekOrigin.Begin);
     while (num3 < filesize)
     {
         this.TorrentProgress.Value = (int) Math.Round((double) ((((double) num3) / ((double) filesize)) * 100.0));
         Application.DoEvents();
         byte[] array = new byte[((int) this.piecesizetouse) + 1];
         long num5 = this.FileHandling.Read(array, 0, (int) this.piecesizetouse);
         byte[] buffer = new byte[((int) (num5 - 1L)) + 1];
         long num16 = num5 - 1L;
         for (long i = 0L; i <= num16; i += 1L)
         {
             buffer[(int) i] = array[(int) i];
         }
         bytes = this.sha1.ComputeHash(buffer);
         int index = 0;
         do
         {
             str14 = str14 + Encoding.Default.GetString(bytes, index, 1);
             index++;
         }
         while (index <= 0x13);
         num3 += this.piecesizetouse;
         buffer = null;
         array = null;
         Thread.Sleep(10);
         GC.Collect();
     }
     this.TorrentProgress.Value = 100;
     this.FileHandling.Close();
     TorrentString str20 = new TorrentString();
     int length = NameOfFile.LastIndexOf(@"\");
     int num = Strings.Len(NameOfFile) - length;
     string str8 = Strings.Right(NameOfFile, num - 1);
     string str9 = Strings.Left(NameOfFile, length);
     TorrentString str19 = new TorrentString {
         Value = str8
     };
     TorrentString str17 = new TorrentString();
     TorrentNumber number = new TorrentNumber {
         Value = filesize
     };
     TorrentNumber number2 = new TorrentNumber {
         Value = this.piecesizetouse
     };
     str20.Value = str14;
     str17.Value = "UTF8";
     TorrentDictionary dictionary2 = new TorrentDictionary();
     TorrentDictionary dictionary = new TorrentDictionary();
     TorrentString str16 = new TorrentString {
         Value = this.AnnounceURL.Text
     };
     dictionary.Add("length", number);
     dictionary.Add("name", str19);
     dictionary.Add("pieces", str20);
     dictionary.Add("piece length", number2);
     if (this.MultiTrackerEnabled.Checked)
     {
         this.CheckMultitTrackerTiers();
         dictionary2.Add("announce-list", MultiTrackerGenerator.MultiTrackerTiers);
     }
     if (this.IncludeSHA1.Checked)
     {
         dictionary.Add("sha1", str10);
     }
     if (this.IncludeMD5.Checked)
     {
         dictionary.Add("md5sum", str7);
     }
     if (this.IncludeCRC32.Checked)
     {
         dictionary.Add("crc32", str4);
     }
     if (this.IncludeED2K.Checked)
     {
         dictionary.Add("ed2k", str5);
     }
     if (this.IncludeTiger.Checked)
     {
         dictionary.Add("tiger", str12);
     }
     if (UseWSAConfig)
     {
         ArrayList returnarray = new ArrayList();
         TorrentList list2 = new TorrentList();
         int webSeedData = TorrentGenFamily.GetWebSeedData(returnarray);
         list2.Value = returnarray;
         if (webSeedData >= 1)
         {
             dictionary2.Add("httpseeds", list2);
         }
     }
     TorrentString str2 = new TorrentString {
         Value = "Torrent Generated by VB.Net TorrentGen - Written by DWKnight"
     };
     dictionary2.Add("created by", str2);
     TorrentString str = new TorrentString();
     if (Strings.Trim(this.TorrentComment.Text) != "")
     {
         str.Value = Strings.Trim(this.TorrentComment.Text);
         dictionary2.Add("comment", str);
     }
     if (this.PrivateTorrent.Checked)
     {
         TorrentNumber number3 = new TorrentNumber {
             Value = 1L
         };
         dictionary["private"] = number3;
     }
     dictionary2.Add("info", dictionary);
     if (this.AnnounceURL.Text != "")
     {
         dictionary2.Add("announce", str16);
     }
     dictionary2.Add("encoding", str17);
     int fileNumber = FileSystem.FreeFile();
     string fileName = NameOfFile + ".torrent";
     FileSystem.FileOpen(fileNumber, fileName, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.LockReadWrite, -1);
     FileSystem.FilePut(fileNumber, dictionary2.BEncoded, -1L, false);
     FileSystem.FileClose(new int[] { fileNumber });
     bytes = null;
     if (this.MakeExternals.Checked)
     {
         if (this.IncludeSHA1.Checked)
         {
             int num11 = FileSystem.FreeFile();
             FileSystem.FileOpen(num11, NameOfFile + ".sha1", OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
             FileSystem.PrintLine(num11, new object[] { str19.Value + " " + hexhash });
             FileSystem.FileClose(new int[] { num11 });
         }
         if ((filesize <= 0x118940000L) && this.IncludeTiger.Checked)
         {
             int num12 = FileSystem.FreeFile();
             FileSystem.FileOpen(num12, NameOfFile + ".tiger", OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
             FileSystem.PrintLine(num12, new object[] { str19.Value + " " + str13 });
             FileSystem.FileClose(new int[] { num12 });
         }
         if (this.IncludeMD5.Checked)
         {
             int num13 = FileSystem.FreeFile();
             FileSystem.FileOpen(num13, NameOfFile + ".md5", OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
             FileSystem.PrintLine(num13, new object[] { str19.Value + " " + str7.Value });
             FileSystem.FileClose(new int[] { num13 });
         }
         if (this.IncludeCRC32.Checked)
         {
             int num14 = FileSystem.FreeFile();
             FileSystem.FileOpen(num14, NameOfFile + ".sfv", OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
             FileSystem.PrintLine(num14, new object[] { str19.Value + " " + str4.Value });
             FileSystem.FileClose(new int[] { num14 });
         }
         if (this.IncludeED2K.Checked)
         {
             LinkGeneration generation = new LinkGeneration {
                 FileName = str19.Value,
                 FileSize = number.Value,
                 ED2KHex = str6
             };
             int num15 = FileSystem.FreeFile();
             FileSystem.FileOpen(num15, NameOfFile + ".ed2k", OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1);
             FileSystem.PrintLine(num15, new object[] { generation.ClassicED2KLink });
             FileSystem.PrintLine(num15, new object[] { str19.Value + " " + generation.ED2KHex + "\r\n" });
             FileSystem.FileClose(new int[] { num15 });
         }
     }
     GC.Collect();
 }