public string makeedat(String inFile) { String strAppDir = Path.GetDirectoryName( Assembly.GetExecutingAssembly().GetName().CodeBase); string path = strAppDir.Replace("file:\\", ""); byte[] CID = Encoding.UTF8.GetBytes(inFile); byte[] contentID = new byte[48]; byte[] contentID2 = new byte[inFile.Length]; ConversionUtils.arraycopy(CID, 0, contentID, 0, CID.Length); ConversionUtils.arraycopy(CID, 0, contentID2, 0, inFile.Length); string cid3 = Encoding.UTF8.GetString(contentID2); if (path != null) { outFile = path + "/edats/" + inFile + ".edat"; } else { outFile = "edats/" + inFile + ".edat"; } FileStream dat = File.Open(inFile + ".dat", FileMode.Create); dat.Write(pad, 0, 0x10); dat.Write(contentID, 0, contentID.Length); dat.Close(); String input = inFile + ".dat"; DirectoryInfo di = Directory.CreateDirectory(path + "/edats"); byte[] flags = ConversionUtils.getByteArray("0C"); byte[] type = ConversionUtils.getByteArray("00"); byte[] version = ConversionUtils.getByteArray("02"); byte[] devKLic = ConversionUtils.getByteArray("72F990788F9CFF745725F08E4C128387"); byte[] keyFromRif = null; EDAT instance = new EDAT(); instance.encryptFile(input, outFile, devKLic, keyFromRif, contentID, flags, type, version); if (File.Exists(inFile + ".dat")) { File.Delete(inFile + ".dat"); } return(inFile + ".edat"); }
private int encryptData(FileStream ii, FileStream o, NPD npd, EDATData data, byte[] rifkey) { int num = (int)(((data.getFileLen() + data.getBlockSize()) - 1) / data.getBlockSize()); byte[] dest = new byte[num * 0x10]; byte[] buffer2 = new byte[ii.Length + 15L]; for (int i = 0; i < num; i++) { long offset = i * data.getBlockSize(); ii.Seek(offset, SeekOrigin.Begin); int length = (int)data.getBlockSize(); if (i == (num - 1)) { length = (int)(data.getFileLen() % new BigInteger(data.getBlockSize())); } int num5 = length; length = (length + 15) & -16; byte[] buffer3 = new byte[length]; byte[] buffer4 = new byte[length]; for (int j = num5; j > 0; j -= ii.Read(buffer4, num5 - j, j)) { } for (int k = num5; k < length; k++) { buffer4[k] = 0; } byte[] buffer5 = new byte[0x10]; byte[] buffer6 = new byte[0x10]; byte[] buffer7 = this.calculateBlockKey(i, npd); ToolsImpl.aesecbEncrypt(rifkey, buffer7, 0, buffer5, 0, buffer7.Length); ConversionUtils.arraycopy(buffer5, 0, buffer6, 0L, buffer5.Length); int cryptoFlag = 2; int hashFlag = 2; AppLoaderReverse reverse = new AppLoaderReverse(); byte[] iv = npd.getDigest(); byte[] generatedHash = new byte[0x10]; reverse.doAll(hashFlag, cryptoFlag, buffer4, 0, buffer3, 0, buffer4.Length, buffer5, iv, buffer6, generatedHash, 0); ConversionUtils.arraycopy(buffer3, 0, buffer2, offset, length); ConversionUtils.arraycopy(generatedHash, 0, dest, (long)(i * 0x10), 0x10); } byte[] buffer = ConversionUtils.getByteArray("4D6164652062792052325220546F6F6C"); o.Write(dest, 0, dest.Length); o.Write(buffer2, 0, buffer2.Length - 15); o.Write(buffer, 0, buffer.Length); return(STATUS_OK); }
public string makeedat(string inFile, string outFile) { if (!File.Exists(inFile)) { Console.WriteLine(inFile + " not found"); return(inFile); } string str2 = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Replace(@"file:\", ""); StreamReader reader = new StreamReader(inFile); string c = reader.ReadToEnd(); if (c.Contains("HG\0\0")) { if (c.Contains("Library")) { byte[] buffer = new byte[c.Length]; string str5 = this.GetSubstringByString("HG\0\0", "Library", c).Replace("HG\0\0", ""); int index = 0; index = str5.IndexOf("\0"); int num2 = str5.Length - index; int length = str5.Length - num2; reader.Close(); string s = str5.Replace("\0", ""); if (length > 0x23) { byte[] bytes = Encoding.UTF8.GetBytes(s); byte[] dest = new byte[0x30]; byte[] buffer4 = new byte[length]; ConversionUtils.arraycopy(bytes, 0, dest, 0L, bytes.Length); ConversionUtils.arraycopy(bytes, 0, buffer4, 0L, length); string str7 = Encoding.UTF8.GetString(buffer4); if (str2 != null) { outFile = str2 + "/edats/" + str7 + ".edat"; } else { outFile = "edats/" + str7 + ".edat"; } FileStream stream = File.Open(str7 + ".dat", FileMode.Create); stream.Write(pad, 0, 0x10); stream.Write(dest, 0, dest.Length); stream.Close(); string str8 = str7 + ".dat"; DirectoryInfo info = Directory.CreateDirectory(str2 + "/edats"); byte[] flags = ConversionUtils.getByteArray("0C"); byte[] type = ConversionUtils.getByteArray("00"); byte[] version = ConversionUtils.getByteArray("02"); byte[] devKLic = ConversionUtils.getByteArray("72F990788F9CFF745725F08E4C128387"); byte[] keyFromRif = null; new EDAT().encryptFile(str8, outFile, devKLic, keyFromRif, dest, flags, type, version); if (File.Exists(str7 + ".dat")) { File.Delete(str7 + ".dat"); } if (str8.EndsWith(".Dec")) { File.Delete(str8); } return(str7 + ".edat"); } Console.WriteLine("Content_ID not found."); return(""); } Console.WriteLine("Content_ID not found."); return(""); } Console.WriteLine("Content_ID not found."); return(""); }
private int encryptData(FileStream ii, FileStream o, NPD npd, EDATData data, byte[] rifkey) { int numBlocks = (int)((data.getFileLen() + data.getBlockSize() - 1) / data.getBlockSize()); byte[] expectedHashForFile = new byte[numBlocks * 0x10]; byte[] encryptedDataForFile = new byte[ii.Length + 0xF]; // File Format: // ALL HASHES // Encrypted Data for (int i = 0; i < numBlocks; i++) { long offset; int len; offset = i * data.getBlockSize(); ii.Seek(offset, SeekOrigin.Begin); len = (int)(data.getBlockSize()); if (i == numBlocks - 1) { len = (int)(data.getFileLen() % (new BigInteger(data.getBlockSize()))); } int realLen = len; len = (int)((uint)(len + 0x0F) & 0xFFFFFFF0); byte[] encryptedData = new byte[len]; byte[] decryptedData = new byte[len]; int toRead = realLen; while (toRead > 0) { toRead -= ii.Read(decryptedData, realLen - toRead, toRead); } for (int ai = realLen; ai < len; ai++) { decryptedData[ai] = 0x00; } byte[] key = new byte[0x10]; byte[] hash = new byte[0x10]; byte[] blockKey = calculateBlockKey(i, npd); ToolsImpl.aesecbEncrypt(rifkey, blockKey, 0, key, 0, blockKey.Length); ConversionUtils.arraycopy(key, 0, hash, 0, key.Length); int cryptoFlag = 0x2; int hashFlag = 0x02; AppLoaderReverse a = new AppLoaderReverse(); byte[] iv = npd.getDigest(); byte[] generatedHash = new byte[0x10]; a.doAll(hashFlag, cryptoFlag, decryptedData, 0, encryptedData, 0, decryptedData.Length, key, iv, hash, generatedHash, 0); ConversionUtils.arraycopy(encryptedData, 0, encryptedDataForFile, offset, len); ConversionUtils.arraycopy(generatedHash, 0, expectedHashForFile, i * 0x10, 0x10); } byte[] EDATAVersion = ConversionUtils.getByteArray("4D6164652062792052325220546F6F6C"); o.Write(expectedHashForFile, 0, expectedHashForFile.Length); o.Write(encryptedDataForFile, 0, encryptedDataForFile.Length - 0xf); o.Write(EDATAVersion, 0, EDATAVersion.Length); return(STATUS_OK); }
public string makeedat(String inFile, String outFile) { if (!File.Exists(inFile)) { Console.WriteLine(inFile + " not found"); return(inFile); } else { String strAppDir = Path.GetDirectoryName( Assembly.GetExecutingAssembly().GetName().CodeBase); string path = strAppDir.Replace("file:\\", ""); StreamReader sfoFile = new StreamReader(inFile); string pkgname1 = GetSubstringByString("temp/", "/PARAM.SFO", inFile); string pkgname = pkgname1.Replace("temp/", ""); // FileStream sfoFile = File.Open(inFile, FileMode.Open); string ciddat = sfoFile.ReadToEnd(); if (ciddat.Contains("HG\0\0")) { if (ciddat.Contains("Library")) { byte[] result = new byte[ciddat.Length]; string cid4 = GetSubstringByString("HG\0\0", "Library", ciddat); string cid5 = cid4.Replace("HG\0\0", ""); int found = 0; found = cid5.IndexOf("\0"); int cid1 = cid5.Length - found; int cid2 = cid5.Length - cid1; sfoFile.Close(); string cid = cid5.Replace("\0", ""); //byte[] contentID = ciddat; if (cid2 > 35) { byte[] CID = Encoding.UTF8.GetBytes(cid); byte[] contentID = new byte[48]; byte[] contentID2 = new byte[cid2]; ConversionUtils.arraycopy(CID, 0, contentID, 0, CID.Length); ConversionUtils.arraycopy(CID, 0, contentID2, 0, cid2); string cid3 = Encoding.UTF8.GetString(contentID2); if (path != null) { outFile = path + "/edats/" + cid3 + ".edat"; } else { outFile = "edats/" + cid3 + ".edat"; } FileStream dat = File.Open(cid3 + ".dat", FileMode.Create); // byte[] pad = new byte[0x10]; // Random rand = new Random(); // rand.NextBytes(pad); dat.Write(pad, 0, 0x10); dat.Write(contentID, 0, contentID.Length); dat.Close(); String input = cid3 + ".dat"; DirectoryInfo di = Directory.CreateDirectory(path + "/edats"); byte[] flags = ConversionUtils.getByteArray("0C"); byte[] type = ConversionUtils.getByteArray("00"); byte[] version = ConversionUtils.getByteArray("02"); byte[] devKLic = ConversionUtils.getByteArray("72F990788F9CFF745725F08E4C128387"); byte[] keyFromRif = null; EDAT instance = new EDAT(); instance.encryptFile(input, outFile, devKLic, keyFromRif, contentID, flags, type, version); if (File.Exists(cid3 + ".dat")) { File.Delete(cid3 + ".dat"); } if (input.EndsWith(".Dec")) { File.Delete(input); } System.IO.StreamWriter file = new System.IO.StreamWriter("C00 list.txt", true); file.WriteLine(pkgname, true); file.Close(); return(cid3 + ".edat"); } else { Console.WriteLine("Content_ID not found."); sfoFile.Close(); return(""); } } else { Console.WriteLine("Content_ID not found."); sfoFile.Close(); return(""); } } else { Console.WriteLine("Content_ID not found."); sfoFile.Close(); return(""); } } }