private static void writeRprcHeader(EndianBinaryWriter writer, uint section_count) { // RPRC header contents: // char magic[4] = { 'R', 'P', 'R', 'C' }; // u32 version; // u32 header_len; // char header[...] = { header_len bytes of unformatted, textual header }; char[] magic = {'R', 'P', 'R', 'C'}; uint version = 1; // TODO: confirm with SDO // use text header to record section count uint length = 4; uint header = section_count; // TODO: add more text header contents? // write header to file writer.Write(magic); writer.Write(version); writer.Write(length); writer.Write(header); }
private static void writeSection(EndianBinaryWriter writer, ObjectSection section, byte[] contents) { // RPRC section contents: // u32 type; // u64 da; // u32 len; // u8 content[...] = { len bytes of binary data }; uint type = 1; // 1: TEXT, 2: DATA (TODO use both?) ulong addr = section.loadAddr; uint size = (uint)section.size; // write section to file writer.Write(type); writer.Write(addr); writer.Write(size); writer.Write(contents); }
private static void writeEntrypoint(EndianBinaryWriter writer, ulong entrypoint) { // RPRC section contents: // u32 type; // u64 da; // u32 len; // u8 content[...] = { len bytes of binary data }; // RPRC resource contents (inside section contents): // u32 type; // u64 da; // u32 len; // u32 reserved; // u8 name[48]; uint section_type = 0; // 0: RESOURCE ulong section_addr = entrypoint; uint section_size = 4 + 8 + 4 + 4 + 48; uint resource_type = 5; // 5: RSC_BOOTADDR ulong resource_addr = entrypoint; uint resource_size = 48; uint resource_rsvd = 0; char[] resource_name = newResourceName("Entrypoint"); // write section + resource to file writer.Write(section_type); writer.Write(section_addr); writer.Write(section_size); writer.Write(resource_type); writer.Write(resource_addr); writer.Write(resource_size); writer.Write(resource_rsvd); writer.Write(resource_name); }