/*********************************************************** ** symbol_set - A public domain C modifier library ** by Allen Webster, "Mr. 4th", allenw@mr4th.com ** ** No warranty implied; use at your own risk ** ** Read symbol_set.intro.h to get started. */ #if SY__OS_WINDOWS #pragma pack(push,1) #define SY__DOS_MAGIC 0x5A4D typedef struct Sy__DosHeader{ Sy_U16 magic; Sy_U16 last_page_size; Sy_U16 page_count; Sy_U16 reloc_count; Sy_U16 paragraph_header_size; Sy_U16 min_paragraph; Sy_U16 max_paragraph; Sy_U16 init_ss; Sy_U16 init_sp; Sy_U16 checksum; Sy_U16 init_ip; Sy_U16 init_cs; Sy_U16 reloc_table_file_off; Sy_U16 overlay_number; Sy_U16 reserved[4]; Sy_U16 oem_id; Sy_U16 oem_info; Sy_U16 reserved2[10]; Sy_U32 coff_offset; } Sy__DosHeader; typedef struct Sy__CoffHeader{ Sy_U16 machine_type; Sy_U16 section_count; Sy_U32 time_stamp; Sy_U32 symbol_table_foff; Sy_U32 symbol_count; Sy_U16 optional_header_size; Sy_U16 flags; } Sy__CoffHeader; typedef struct Sy_CoffSection{ Sy_U8 name[8]; Sy_U32 vsize; Sy_U32 voff; Sy_U32 fsize; Sy_U32 foff; Sy_U32 relocations_foff; Sy_U32 line_numbers_foff; Sy_U16 relocation_count; Sy_U16 line_number_count; Sy_U32 flags; } Sy_CoffSection; #pragma pack(pop) void sy__section_init(char *name, Sy_U32 name_size, void **first_out, void **opl_out){ if (name_size <= 8){ extern Sy_U8 __ImageBase[]; Sy_U8 *base = __ImageBase; Sy__DosHeader *dos = (Sy__DosHeader*)base; if (dos_header->magic == SY__DOS_MAGIC){ Sy__CoffHeader *coff = (Sy__CoffHeader*)(base + dos->coff_offset); Sy_U32 sections_offset = (dos->coff_offset + sizeof(*coff) + coff->optional_header_size); Sy_U32 section_count = coff->section_count; Sy_CoffSection *section = (Sy_CoffSection*)(base + sections_offset); for (Sy_U32 i = 0; i < section_count; i += 1, section += 1){ int match = 1; for (Sy_U32 j = 0; j < 8; j += 1){ if (name[j] != section->name[j]){ match = 0; break; } if (name[j] == 0){ break; } } if (match){ *first_out = base + section->voff; *opl_out = base + section->voff + section->vsize; break; } } } } } #endif