// Methods /// <summary> /// Creates a new file integrity. /// </summary> /// <param name="path">The specified path.</param> public void Create(string path) { var header = new FileIntegrityHeader() { Tag = FileIntegrity.FileTag, Version = FileIntegrity.FileVersion }; Scan(Environment.CurrentDirectory); header.EntryCount = EntryCount; using (var writer = new BinaryWriter(File.Open(FileIntegrity.FileName, FileMode.Create, FileAccess.Write))) { writer.WriteStructure<FileIntegrityHeader>(header); foreach (var entry in Entries) { writer.Write(entry.FileNameLen); writer.Write(entry.FileName.ToCharArray(), 0, entry.FileNameLen); writer.Write(entry.LastModifiedTime); writer.Write(entry.Size); writer.Write(entry.Checksum); } } }
internal void InternalWrite(BinaryWriter writer) { writer.WriteStructure(_header); for (int i = 0; i < _header.entryCount; i++) { _subEntries[i].InternalWrite(writer); } writer.AlignPosition(16); for (int i = 0; i < _header.entryCount; i++) { if (i > 1 && _subEntries[i].Flags.HasFlagUnchecked(RecordFlags.DirectoryRecord)) { _subEntries[i].DirectoryListing.InternalWrite(writer); } } }
internal void InternalWrite(BinaryWriter writer) { writer.WriteStructure(_header); }
private void WriteMetaData(Workspace workspace, BinaryWriter sectionWriter) { // write metadata header sectionWriter.WriteStructure(workspace.NewNetHeader.MetaDataHeader._reader.metadataHeader1); sectionWriter.Write(Encoding.ASCII.GetBytes(workspace.NewNetHeader.MetaDataHeader.VersionString)); sectionWriter.WriteStructure(workspace.NewNetHeader.MetaDataHeader._reader.metadataHeader2); // write metadata stream headers foreach (MetaDataStream stream in workspace.NewNetHeader.MetaDataStreams) { sectionWriter.WriteStructure(stream._streamHeader); sectionWriter.Write(Encoding.ASCII.GetBytes(stream.Name)); sectionWriter.Write(new byte[Align(stream.Name.Length + 1, 4)]); } // write metadata streams foreach (MetaDataStream stream in workspace.NewNetHeader.MetaDataStreams) { sectionWriter.Write(stream._mainStream.ToArray()); } }
private Section CreateTextSection(Workspace workspace) { Section section; using (MemoryStream sectionStream = new MemoryStream()) { using (BinaryWriter sectionWriter = new BinaryWriter(sectionStream)) { // write import address dir space. sectionWriter.Write(new byte[8]); // write .net header sectionWriter.WriteStructure(workspace.NewNetHeader._rawHeader); // write method bodies sectionWriter.Write(workspace.MethodBodyTable.Stream.ToArray()); // write resources dir sectionWriter.Write(Constructor.OriginalAssembly.NETHeader.ResourcesDirectory.GetBytes()); // write metadata WriteMetaData(workspace, sectionWriter); // write import dir } section = new Section(".text", 0, sectionStream.ToArray()); } return section; }