remove dependency on bin info from base reloc parser

This commit is contained in:
Nikita Smith
2024-12-09 15:24:18 -08:00
parent 723c950c01
commit db82b2ea63
2 changed files with 14 additions and 13 deletions
+13 -12
View File
@@ -778,18 +778,16 @@ pe_foff_from_voff(String8 data, PE_BinInfo *bin, U64 voff)
} }
internal PE_BaseRelocBlockList internal PE_BaseRelocBlockList
pe_base_reloc_block_list_from_bin(Arena *arena, String8 data, PE_BinInfo *bin) pe_base_reloc_block_list_from_data(Arena *arena, String8 raw_base_relocs)
{ {
PE_BaseRelocBlockList list = {0}; PE_BaseRelocBlockList list = {0};
Rng1U64 base_reloc_range = bin->data_dir_franges[PE_DataDirectoryIndex_BASE_RELOC]; for(U64 off = 0; off < raw_base_relocs.size;)
U64 range_dim = dim_1u64(base_reloc_range);
for(U64 off = base_reloc_range.min; off < range_dim;)
{ {
// rjf: read next entry // rjf: read next entry
U32 page_virt_off = 0; U32 page_virt_off = 0;
U32 block_size = 0; U32 block_size = 0;
off += str8_deserial_read_struct(data, off, &page_virt_off); off += str8_deserial_read_struct(raw_base_relocs, off, &page_virt_off);
off += str8_deserial_read_struct(data, off, &block_size); off += str8_deserial_read_struct(raw_base_relocs, off, &block_size);
// rjf: break on sentinel // rjf: break on sentinel
if(block_size == 0) if(block_size == 0)
@@ -802,13 +800,15 @@ pe_base_reloc_block_list_from_bin(Arena *arena, String8 data, PE_BinInfo *bin)
SLLQueuePush(list.first, list.last, node); SLLQueuePush(list.first, list.last, node);
list.count += 1; list.count += 1;
U64 entries_size = block_size - (sizeof(block_size) + sizeof(page_virt_off));
// rjf: fill block // rjf: fill block
PE_BaseRelocBlock *block = &node->v; PE_BaseRelocBlock *block = &node->v;
U64 entries_size = block_size - (sizeof(block_size) + sizeof(page_virt_off)); block->page_virt_off = page_virt_off;
block->page_virt_off = page_virt_off; block->entry_count = entries_size / sizeof(U16);
block->entry_count = entries_size / sizeof(U16); block->entries = push_array(arena, U16, block->entry_count);
block->entries = push_array(arena, U16, block->entry_count); U64 entry_read_size = str8_deserial_read_array(raw_base_relocs, off, &block->entries[0], block->entry_count);
off += str8_deserial_read_array(data, off, &block->entries[0], entries_size); Assert(entry_read_size == sizeof(block->entries[0]) * block->entry_count);
} }
return list; return list;
} }
@@ -822,7 +822,8 @@ pe_tls_rng_from_bin_base_vaddr(String8 data, PE_BinInfo *bin, U64 base_vaddr)
{ {
U64 addr_size = bit_size_from_arch(bin->arch)/8; U64 addr_size = bit_size_from_arch(bin->arch)/8;
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
PE_BaseRelocBlockList relocs = pe_base_reloc_block_list_from_bin(scratch.arena, data, bin); String8 raw_relocs = str8_substr(data, bin->data_dir_franges[PE_DataDirectoryIndex_BASE_RELOC]);
PE_BaseRelocBlockList relocs = pe_base_reloc_block_list_from_data(scratch.arena, raw_relocs);
for(PE_BaseRelocBlockNode *n = relocs.first; n != 0; n = n->next) for(PE_BaseRelocBlockNode *n = relocs.first; n != 0; n = n->next)
{ {
PE_BaseRelocBlock *block = &n->v; PE_BaseRelocBlock *block = &n->v;
+1 -1
View File
@@ -1051,7 +1051,7 @@ internal void * pe_ptr_from_voff(String8 data, PE_BinInfo *bin, U
internal U64 pe_section_num_from_voff(String8 data, PE_BinInfo *bin, U64 voff); internal U64 pe_section_num_from_voff(String8 data, PE_BinInfo *bin, U64 voff);
internal void * pe_ptr_from_section_num(String8 data, PE_BinInfo *bin, U64 n); internal void * pe_ptr_from_section_num(String8 data, PE_BinInfo *bin, U64 n);
internal U64 pe_foff_from_voff(String8 data, PE_BinInfo *bin, U64 voff); internal U64 pe_foff_from_voff(String8 data, PE_BinInfo *bin, U64 voff);
internal PE_BaseRelocBlockList pe_base_reloc_block_list_from_bin(Arena *arena, String8 data, PE_BinInfo *bin); internal PE_BaseRelocBlockList pe_base_reloc_block_list_from_data(Arena *arena, String8 raw_relocs);
internal Rng1U64 pe_tls_rng_from_bin_base_vaddr(String8 data, PE_BinInfo *bin, U64 base_vaddr); internal Rng1U64 pe_tls_rng_from_bin_base_vaddr(String8 data, PE_BinInfo *bin, U64 base_vaddr);
internal String8Array pe_get_entry_point_names(COFF_MachineType machine, PE_WindowsSubsystem subsystem, PE_ImageFileCharacteristics file_characteristics); internal String8Array pe_get_entry_point_names(COFF_MachineType machine, PE_WindowsSubsystem subsystem, PE_ImageFileCharacteristics file_characteristics);