private void WriteElfHeader() { //e_ident // EI_MAG0 to EI_MAG3 output.Write(new byte[] { 0x7f, (byte)'E', (byte)'L', (byte)'F' }); // EI_CLASS if (is64bit) { output.WriteByte(2); // ELFCLASS64 } else { output.WriteByte(1); // ELFCLASS32 } // EI_DATA output.WriteByte(1); // ELFDATA2LSB // EI_VERSION output.WriteByte(1); // EV_CURRENT // EI_PAD output.Write(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }); Require.Equals(16, output.Length); //e_type output.WriteInt16(2); //ET_EXEC //e_machine if (is64bit) { output.WriteInt16(62); //EM_X86_64 } else { output.WriteInt16(3); // EM_386 } //e_version output.WriteInt32(1); // EV_CURRENT //e_entry output.WriteNumber(entryPoint.MemoryLocation); if (is64bit) { Require.Equals(32, output.Length); } else { Require.Equals(28, output.Length); } //e_phoff programHeaderTable_fo = output.InsertNumberToken(); //e_shoff sectionHeaderTable_fo = output.InsertNumberToken(); if (is64bit) { Require.Equals(48, output.Length); } else { Require.Equals(36, output.Length); } //e_flags output.WriteInt32(0); //e_ehsize WordToken elfHeaderSize = output.InsertWordToken(); //e_phentsize output.WriteInt16(ProgramHeaderTableEntrySize); //e_phnum output.WriteInt16(ProgramHeaderEntryCount); //e_shentsize output.WriteInt16(SectionHeaderEntrySize); //e_shnum output.WriteInt16(SectionHeaderEntryCount); // e_shstrndx output.WriteInt16(StringHeaderSectionIndex); elfHeaderSize.SetValue(output.Length); Require.Equals(SizeOfElfHeader, output.Length); }
private void WriteVersionHeader() { Region resourceHeader = writer.AllocateRegion(".rsrc"); // Resouce Directory Table resourceHeader.WriteInt32(0); //Characteristics resourceHeader.WriteInt32(0); // TimeDateStamp resourceHeader.WriteInt16(0); // mayor version resourceHeader.WriteInt16(0); // minor verson resourceHeader.WriteInt16(0); // number of named entries resourceHeader.WriteInt16(1); // number of id'ed entries // Resource Directory Entry resourceHeader.WriteInt32(0x10); // ID (VERSION) resourceHeader.WriteInt32(0x80000018); //pointer to next directory // Resouce Directory Table resourceHeader.WriteInt32(0); //Characteristics resourceHeader.WriteInt32(0); // TimeDateStamp resourceHeader.WriteInt16(0); // mayor version resourceHeader.WriteInt16(0); // minor verson resourceHeader.WriteInt16(0); // number of named entries resourceHeader.WriteInt16(1); // number of id'ed entries // Resource Directory Entry resourceHeader.WriteInt32(1); // ID (1) resourceHeader.WriteInt32(0x80000030); //pointer to next directory // Resouce Directory Table resourceHeader.WriteInt32(0); //Characteristics resourceHeader.WriteInt32(0); // TimeDateStamp resourceHeader.WriteInt16(0); // mayor version resourceHeader.WriteInt16(0); // minor verson resourceHeader.WriteInt16(0); // number of named entries resourceHeader.WriteInt16(1); // number of id'ed entries // Resource Directory Entry resourceHeader.WriteInt32(0); // ID resourceHeader.WriteInt32(0x48); //pointer to leaf // Resource Data Entry resourceHeader.WritePlaceholderRelative(resourceHeader.CurrentLocation.Increment(0x10)); IntToken SizeOfResourceBody1 = resourceHeader.InsertIntToken(); resourceHeader.WriteInt32(0); // codepage (default unicode) resourceHeader.WriteInt32(0); // reserved long RelativeSizeOfHeader = resourceHeader.CurrentLocation.Offset; // struct VS_VERSIONINFO { WordToken SizeOfResourceBody2 = resourceHeader.InsertWordToken(); // wLength resourceHeader.WriteInt16(0x34); // wValueLength resourceHeader.WriteInt16(0); // wType resourceHeader.WriteAsUtf16NullTerminated2("VS_VERSION_INFO"); resourceHeader.WriteInt16(0); // padding1 // struct VS_FIXEDFILEINFO { resourceHeader.WriteInt32(0xFEEF04BD); // dwSignature resourceHeader.WriteInt32(0x00010000); // dwStrucVersion resourceHeader.WriteInt32(0x00010000); // dwFileVersionMS resourceHeader.WriteInt32(0x00000000); // dwFileVersionLS resourceHeader.WriteInt32(0x00010000); // dwProductVersionMS resourceHeader.WriteInt32(0x00000000); // dwProductVersionLS resourceHeader.WriteInt32(0x3f); // dwFileFlagsMask; resourceHeader.WriteInt32(0); // dwFileFlags; resourceHeader.WriteInt32(4); // dwFileOS; resourceHeader.WriteInt32(1); // dwFileType resourceHeader.WriteInt32(0); // dwFileSubtype resourceHeader.WriteInt32(0); // dwFileDateMS resourceHeader.WriteInt32(0); // dwFileDateLS // rest of //struct VS_VERSIONINFO { // WORD Padding2[]; //WORD Children[]; WordToken varFileInfo = WriteEntry(resourceHeader, 0, 1, "VarFileInfo"); WordToken translation = WriteEntry(resourceHeader, 4, 0, "Translation"); resourceHeader.WriteInt32(0x04B00000); // codepage unicode translation.SetDistanceSinceTaken(); varFileInfo.SetDistanceSinceTaken(); WordToken varStringFileInfo = WriteEntry(resourceHeader, 0, 1, "StringFileInfo"); WordToken varVersion = WriteEntry(resourceHeader, 0, 1, "000004b0"); WriteEntry2(resourceHeader, "FileDescription", "Something compiled by Bart's compiler."); WriteEntry2(resourceHeader, "FileVersion", "1.0.0.0"); WriteEntry2(resourceHeader, "InternalName", moduleName + ".exe"); WriteEntry2(resourceHeader, "LegalCopyright", " "); WriteEntry2(resourceHeader, "OriginalFilename", moduleName + ".exe"); WriteEntry2(resourceHeader, "ProductName", moduleName); WriteEntry2(resourceHeader, "ProductVersion", "1.0.0.0"); varVersion.SetDistanceSinceTaken(); varStringFileInfo.SetDistanceSinceTaken(); RelativeSizeOfHeader = resourceHeader.CurrentLocation.Offset - RelativeSizeOfHeader; SizeOfResourceBody1.SetValue((int)RelativeSizeOfHeader); SizeOfResourceBody2.SetValue((int)RelativeSizeOfHeader); }