/// <summary> /// 处理filehash /// 保存列表文件并且发送列表 /// </summary> /// <param name="package"></param> /// <param name="write"></param> /// <returns></returns> private bool FileHashHandle(PackagePlugin package, BinaryWriter toClientWriter, BinaryWriter toServerWriter) { if (LocalData == null) { using (MemoryStream ms = new MemoryStream(package.ChannelData, 1, package.ChannelData.Length - 1)) { using (BinaryReader br = new BinaryReader(ms)) { // 0-2: gziplength // 2-~: data ushort gzipLength = br.ReadUInt16BE(); byte[] gzipdata = br.ReadBytes(gzipLength); // 0: salt // 1-~: hashlist byte[] unzipdata = GzipUtil.Decompress(gzipdata); byte[] hashs = new byte[unzipdata.Length - 1]; Array.Copy(unzipdata, 1, hashs, 0, hashs.Length); CatAntiCheatData local = new CatAntiCheatData { Version = version, FileHashBytes = hashs }; SerializeUtil.SerializeToFile(fileName, local); } } Console.WriteLine($"[CatAntiCheat]本地文件[{fileName}]不存在, 创建完成"); } LocalData = SerializeUtil.DeserializeFromFile <CatAntiCheatData>(fileName); return(false); }
public static bool PeriodSeparationIsSharp(Archive archive) { bool inboundSeparationIsSharp; bool outboundSeparationIsSharp; addml archiveExtraction = SerializeUtil.DeserializeFromFile <addml>(archive.AddmlXmlUnit.File); try { dataObject archiveExtractionElement = archiveExtraction.dataset[0].dataObjects.dataObject[0]; property infoElement = archiveExtractionElement.properties[0]; property additionalInfoElement = infoElement.properties[1]; property periodProperty = additionalInfoElement.properties.FirstOrDefault(p => p.name == "periode"); property inboundSeparationProperty = periodProperty.properties[0]; property outboundSeparationProperty = periodProperty.properties[1]; inboundSeparationIsSharp = inboundSeparationProperty.value.Equals("skarpt"); outboundSeparationIsSharp = outboundSeparationProperty.value.Equals("skarpt"); } catch { string exceptionMessage = string.Format(Resources.ExceptionMessages.PeriodSeparationParseError, ArkadeConstants.ArkivuttrekkXmlFileName); throw new ArkadeException(exceptionMessage); } return(inboundSeparationIsSharp && outboundSeparationIsSharp); }
public static bool FileIsDescribed(string fileName, Archive archive) { addml archiveExtraction = SerializeUtil.DeserializeFromFile <addml>(archive.AddmlFile); try { dataObject archiveExtractionElement = archiveExtraction.dataset[0].dataObjects.dataObject[0]; dataObject fileElement = archiveExtractionElement.dataObjects.dataObject.FirstOrDefault( d => d.name == Path.GetFileNameWithoutExtension(fileName) ); return(fileElement != null); } catch { string exceptionMessage = string.Format( Resources.ExceptionMessages.FileDescriptionParseError, fileName, ArkadeConstants.ArkivuttrekkXmlFileName ); throw new ArkadeException(exceptionMessage); } }
protected override void Test(ArchiveExtraction archive) { var structure = SerializeUtil.DeserializeFromFile <addml>(archive.GetStructureDescriptionFileName()); foreach (var entry in structure.dataset[0].dataObjects.dataObject) { foreach (var currentObject in entry.dataObjects.dataObject) { foreach (var fileProperty in currentObject.properties.Where(s => s.name == "file")) { var filename = archive.WorkingDirectory + Path.DirectorySeparatorChar + GetFilenameFromProperty(fileProperty); var checksumAlgorithm = GetChecksumAlgorithmFromProperty(fileProperty); var checksumValue = GetChecksumValueFromProperty(fileProperty); var generatedChecksum = GenerateChecksumForFile(filename, checksumAlgorithm); var checksumsAreEqual = string.Equals(generatedChecksum, checksumValue, StringComparison.InvariantCultureIgnoreCase); var testResult = CreateTestResult(checksumsAreEqual, generatedChecksum, checksumValue, filename, checksumAlgorithm); TestResults.Add(testResult); } } } }
public CatAntiCheatPlugin() { if (File.Exists(fileName)) { LocalData = SerializeUtil.DeserializeFromFile <CatAntiCheatData>(fileName); } }
public override void Test(Archive archive) { var structure = SerializeUtil.DeserializeFromFile <addml>(archive.AddmlFile.FullName); foreach (var entry in structure.dataset[0].dataObjects.dataObject) { foreach (var currentObject in entry.dataObjects.dataObject) { foreach (var fileProperty in currentObject.properties.Where(s => s.name == "file")) { string fileName = GetFileNameFromProperty(fileProperty); var fullPathToFile = archive.WorkingDirectory.Content().DirectoryInfo().FullName + Path.DirectorySeparatorChar + fileName; var checksumAlgorithm = GetChecksumAlgorithmFromProperty(fileProperty); var checksumValue = GetChecksumValueFromProperty(fileProperty); var generatedChecksum = GenerateChecksumForFile(fullPathToFile, checksumAlgorithm); var checksumsAreEqual = string.Equals(generatedChecksum, checksumValue, StringComparison.InvariantCultureIgnoreCase); var testResult = CreateTestResult(checksumsAreEqual, generatedChecksum, checksumValue, fileName, checksumAlgorithm); _testResults.Add(testResult); } } } }
public ArchiveDetails(Archive archive) { try { _addml = SerializeUtil.DeserializeFromFile <addml>(archive.AddmlXmlUnit.File); } catch (Exception exception) { throw new ArkadeException($"Error reading addml xml: {exception.Message}"); } }
private static bool DocumentationStatesDisposalResolutions(Archive archive) { var archiveExtractionXml = SerializeUtil.DeserializeFromFile <addml>(archive.AddmlXmlUnit.File); dataObject archiveExtractionElement = archiveExtractionXml.dataset[0].dataObjects.dataObject[0]; property infoElement = archiveExtractionElement.properties[0]; property additionalInfoElement = infoElement.properties[1]; property documentCountProperty = additionalInfoElement.properties.FirstOrDefault(p => p.name == "inneholderDokumenterSomSkalKasseres"); return(documentCountProperty != null && bool.Parse(documentCountProperty.value)); }
private static bool DocumentationStatesRestrictions(Archive archive) { var archiveExtractionXml = SerializeUtil.DeserializeFromFile <addml>(archive.AddmlFile); dataObject archiveExtractionElement = archiveExtractionXml.dataset[0].dataObjects.dataObject[0]; property infoElement = archiveExtractionElement.properties[0]; property additionalInfoElement = infoElement.properties[1]; property documentCountProperty = additionalInfoElement.properties.FirstOrDefault(p => p.name == "inneholderSkjermetInformasjon"); return(documentCountProperty != null && bool.Parse(documentCountProperty.value)); }
private static bool DisposalsAreDocumented(Archive archive) { var archiveExtractionXml = SerializeUtil.DeserializeFromFile <addml>(archive.AddmlFile); dataObject archiveExtractionElement = archiveExtractionXml.dataset[0].dataObjects.dataObject[0]; property infoElement = archiveExtractionElement.properties[0]; property additionalInfoElement = infoElement.properties[1]; property documentCountProperty = additionalInfoElement.properties.FirstOrDefault(p => p.name == "omfatterDokumenterSomErKassert"); return(documentCountProperty != null && bool.Parse(documentCountProperty.value)); }
public static addml GetAddmlObject(string addmlXmlFileName, Archive archive) { string addmlXmlFile = archive.WorkingDirectory.Content().WithFile(addmlXmlFileName).FullName; try { return(SerializeUtil.DeserializeFromFile <addml>(addmlXmlFile)); } catch (Exception) { return(null); } }
private int GetDocumentedNumberOfFolders() { addml addml = SerializeUtil.DeserializeFromFile <addml>(_archive.AddmlXmlUnit.File); string numberOfFolders = addml.dataset[0].dataObjects.dataObject[0] .dataObjects.dataObject[0].properties.FirstOrDefault( p => p.name == "info").properties.Where( p => p.name == "numberOfOccurrences").FirstOrDefault( p => p.value.Equals("mappe")).properties.FirstOrDefault( p => p.name.Equals("value")) .value; return(int.Parse(numberOfFolders)); }
private static bool DocumentationStatesDisposalResolutions(Archive archive) { string archiveExtractionXmlFile = archive.WorkingDirectory.Content().WithFile(ArkadeConstants.ArkivuttrekkXmlFileName).FullName; var archiveExtractionXml = SerializeUtil.DeserializeFromFile <addml>(archiveExtractionXmlFile); dataObject archiveExtractionElement = archiveExtractionXml.dataset[0].dataObjects.dataObject[0]; property infoElement = archiveExtractionElement.properties[0]; property additionalInfoElement = infoElement.properties[1]; property documentCountProperty = additionalInfoElement.properties.FirstOrDefault(p => p.name == "inneholderDokumenterSomSkalKasseres"); return(documentCountProperty != null && bool.Parse(documentCountProperty.value)); }
private static addml GetAddmlObject(string addmlXmlFileName, Archive archive) { string addmlXmlFile = archive.WorkingDirectory.Content().WithFile(addmlXmlFileName).FullName; try { return(SerializeUtil.DeserializeFromFile <addml>(addmlXmlFile)); } catch (Exception) { _filesNotFound.Add(addmlXmlFileName); return(null); } // TODO: Check for file existance to distinguish file not found error from deserialize error }
private static int GetDocumentedFileCount(Archive archive) { var archiveExtractionXml = SerializeUtil.DeserializeFromFile <addml>(archive.AddmlXmlUnit.File); dataObject archiveExtractionElement = archiveExtractionXml.dataset[0].dataObjects.dataObject[0]; property infoElement = archiveExtractionElement.properties[0]; property additionalInfoElement = infoElement.properties[1]; property documentCountProperty = additionalInfoElement.properties.FirstOrDefault(p => p.name == "antallDokumentfiler"); return(int.Parse(documentCountProperty.value)); // Throws exception if documentCountProperty is null or value could not be parsed // TODO: Add "antallDokumentfiler" to ArcadeConstants? }
public static ArchiveMetadata Load(string diasMetsFile) { var mets = SerializeUtil.DeserializeFromFile <mets>(diasMetsFile); var archiveMetadata = new ArchiveMetadata(); LoadMetsElementAttributes(archiveMetadata, mets); if (mets.metsHdr != null) { LoadMetsHdr(archiveMetadata, mets.metsHdr); } MetadataLoader.HandleLabelPlaceholder(archiveMetadata); return(archiveMetadata); }
public static ArchiveMetadata Load(string diasMetsFile) { var mets = SerializeUtil.DeserializeFromFile <mets>(diasMetsFile); var archiveMetadata = new ArchiveMetadata(); if (mets.metsHdr != null) { LoadMetsHdr(archiveMetadata, mets.metsHdr); } if (mets.amdSec != null) { LoadAmdSec(archiveMetadata, mets.amdSec); } return(archiveMetadata); }
/// <summary> /// 如果本地存在modlist文件, 就发送本地文件的, 如果不存在就创建文件 /// </summary> /// <param name="package"></param> /// <param name="write"></param> /// <returns></returns> public override bool CTSPluginMessageHandle(PackagePlugin package, BinaryWriter toClientWriter, BinaryWriter toServerWriter) { // 确定是modlist if (package.ChannelData.Length > 0 && package.ChannelData[0] == 2) { // 如果不存在, 就创建并保存文件 if (!File.Exists(fileName)) { Console.WriteLine($"[公共][{fileName}]不存在, 创建文件成功!"); SerializeUtil.SerializeToFile(fileName, package); } // 读取文件内容并发送给服务端 PackagePlugin local = SerializeUtil.DeserializeFromFile <PackagePlugin>(fileName); toServerWriter.Write(local.OriginData); // 丢掉客户端发来的数据 return(true); } return(false); }
/// <summary> /// 发送假数据给服务端 /// </summary> /// <param name="channelName"></param> private void SendMd5List(string channelName, BinaryWriter toServerWriter) { List <string> localMd5List = SerializeUtil.DeserializeFromFile <List <string> >(fileName); byte[] md5sNBTByteArray = ASACUtil.GetMd5NBTByteArray(false, localMd5List, Salt, Global.IsVersion1_12_2); MemoryStream channelDataStream = new MemoryStream(); using (BinaryWriter bw = new BinaryWriter(channelDataStream)) { bw.Write((byte)1); //如果是1.12, 这里不需要写入长度 if (!Global.IsVersion1_12_2) { bw.WriteUInt16BE((UInt16)md5sNBTByteArray.Length); } bw.Write(md5sNBTByteArray); } byte[] channelData = channelDataStream.ToArray(); PackagePlugin newPackage = new PackagePlugin(CTSPluginPackageId, channelName, channelData, Global.IsVersion1_12_2); toServerWriter.Write(newPackage.OriginData); }
public ArchiveDetails(Archive archive) { _addml = SerializeUtil.DeserializeFromFile <addml>(archive.AddmlFile); }