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"); }
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(""); } } }
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); }