public int PacAddon(string[] files, uint tgtver, uint pkgver, string tgtName) { try { ipfTgtVer = tgtver; ipfPkgVer = pkgver; ipfTgtName = tgtName; lstFileTab.Clear(); foreach (var x in files) { string dPath = Path.GetDirectoryName(x) + "\\"; var dFiles = Directory.EnumerateFiles(x, "*", SearchOption.AllDirectories); foreach (var fPath in dFiles) { var fti = new FileTableInf(); fti.filePath = fPath; fti.archNm = "addon_d.ipf"; fti.fileNm = fPath.Remove(0, dPath.Length == 1 ? 0 : dPath.Length).Replace("\\", "/"); //Print(fti.archNm + " | " +fti.fileNm); lstFileTab.Add(fti); } } if (lstFileTab.Count < 1) { Print("構成対象のファイルが存在しません"); return(-1); } return(Packing()); } catch (Exception ex) { Print("例外発生!!"); Print(ex.ToString()); } return(-9999); }
private int Ext1File(FileStream fs, FileTableInf fti, string tgtDir) { //Print("生成:"+fti.archNm+"/"+System.IO.Path.GetDirectoryName(fti.fileNm)); if (!Directory.Exists(tgtDir + "/" + fti.archNm + "/" + Path.GetDirectoryName(fti.fileNm))) { Directory.CreateDirectory(tgtDir + "/" + fti.archNm + "/" + Path.GetDirectoryName(fti.fileNm)); } using (FileStream fw = File.Create(tgtDir + "/" + fti.archNm + "/" + fti.fileNm)) { byte[] tmpBuf = new byte[fti.compLen]; ReadFile(fs, tmpBuf, fti.dataPos, fti.compLen); if (fti.compLen == fti.deplLen) { nonCompExtnt.Add(Path.GetExtension(fti.fileNm)); fw.Write(tmpBuf, 0, fti.compLen); return(0); } IpfCrypt ic = new IpfCrypt(); //DumpBuf(tmpBuf, 32); ic.DecryptBuf(tmpBuf); //DumpBuf(tmpBuf, 32); using (Stream memStrm = new MemoryStream(tmpBuf)) { using (var deflStrm = new DeflateStream(memStrm, CompressionMode.Decompress)) { byte[] readBuf = new byte[4096]; int readSize = 0; for (int readPos = 0; ; readPos += readSize) { readSize = deflStrm.Read(readBuf, 0, readBuf.Length); if (readSize == 0) { break; } fw.Write(readBuf, 0, readSize); } } } } return(0); }
private int CheckIpf(FileStream fs, StreamWriter sw) { if (fs.Length < 44) { ExPrint("IPFサイズ不足 (最低44バイト)", sw); return(-1); } if (fs.Length > Int32.MaxValue) { ExPrint("IPFサイズ超過 (最大" + Int32.MaxValue + "バイト)", sw); return(-2); } ipfLen = (int)fs.Length; // ファイルのサイズ ExPrint("IPFフッタ解析", sw); byte[] tmpBuf = new byte[24]; ReadFile(fs, tmpBuf, ipfLen - 24, 24); if ((tmpBuf[12] != 0x50) || (tmpBuf[13] != 0x4B) || (tmpBuf[14] != 0x05) || (tmpBuf[15] != 0x06)) { ExPrint("IPFフッタ不正", sw); return(-3); } ipfFileCnt = tmpBuf[0] + (tmpBuf[1] * 0x100); ipfFileTblPos = tmpBuf[2] + (tmpBuf[3] * 0x100) + (tmpBuf[4] * 0x10000) + (tmpBuf[5] * 0x1000000); ipfFileFtrPos = tmpBuf[8] + (tmpBuf[9] * 0x100) + (tmpBuf[10] * 0x10000) + (tmpBuf[11] * 0x1000000); ipfTgtVer = tmpBuf[16] + (tmpBuf[17] * 0x100U) + (tmpBuf[18] * 0x10000U) + (tmpBuf[19] * 0x1000000U); ipfPkgVer = tmpBuf[20] + (tmpBuf[21] * 0x100U) + (tmpBuf[22] * 0x10000U) + (tmpBuf[23] * 0x1000000U); ExPrint(" ファイル数:" + ipfFileCnt + " [0x" + ipfFileCnt.ToString("X4") + "]", sw); ExPrint(" TargetVer:[" + ipfTgtVer + "] PackageVer:[" + ipfPkgVer + "]", sw); if (ipfFileTblPos > ipfLen - 24 || ipfFileTblPos < 0) { ExPrint("IPFフッタ不正 IPF内テーブル始", sw); return(-4); } if (ipfFileFtrPos > ipfLen - 24 || ipfFileFtrPos < 0) { ExPrint("IPFフッタ不正 IPF内フッタ位置", sw); return(-5); } int tmpPos = ipfFileTblPos; for (int i = 0; i < ipfFileCnt; i++) { //Print("IPFテーブル解析 "+(i+1)); if (tmpPos < 0) { ExPrint("IPFテーブル不正 開始位置", sw); return(-6); } FileTableInf fti = new FileTableInf(); tmpBuf = new byte[24]; ReadFile(fs, tmpBuf, tmpPos, 20); int archNmLen = tmpBuf[18] + (tmpBuf[19] * 0x100); int fileNmLen = tmpBuf[0] + (tmpBuf[1] * 0x100); fti.fileCrc = (uint)(tmpBuf[2] + (tmpBuf[3] * 0x100) + (tmpBuf[4] * 0x10000)) + ((uint)tmpBuf[5] * 0x1000000U); fti.compLen = tmpBuf[6] + (tmpBuf[7] * 0x100) + (tmpBuf[8] * 0x10000) + (tmpBuf[9] * 0x1000000); fti.deplLen = tmpBuf[10] + (tmpBuf[11] * 0x100) + (tmpBuf[12] * 0x10000) + (tmpBuf[13] * 0x1000000); fti.dataPos = tmpBuf[14] + (tmpBuf[15] * 0x100) + (tmpBuf[16] * 0x10000) + (tmpBuf[17] * 0x1000000); tmpBuf = new byte[archNmLen]; ReadFile(fs, tmpBuf, tmpPos + 20, archNmLen); fti.archNm = Encoding.UTF8.GetString(tmpBuf); tmpBuf = new byte[fileNmLen]; ReadFile(fs, tmpBuf, tmpPos + 20 + archNmLen, fileNmLen); fti.fileNm = Encoding.UTF8.GetString(tmpBuf); //Print(" ファイル名:"+fti.archNm+" | "+fti.fileNm+" ファイル位置:"+fti.dataPos+" [0x"+fti.dataPos.ToString("X8")+"] 圧縮サイズ :"+fti.compLen+" [0x"+fti.compLen.ToString("X8")+"]"); //Print(" CRC:"+fti.fileCrc.ToString("X8")); lstFileTab.Add(fti); tmpPos += 20 + fileNmLen + archNmLen; } return(0); }