//████████████████████████████████████████████████████████████████████████████ //██ ██ //██ DLLLOAD.C ██ //██ ██ //██ 32-bit DLL driver loader ██ //██ ██ //██ V1.00 of 16-Aug-92: Initial version for Watcom C ██ //██ V1.01 of 1-May-93: Zortech C++ v3.1 compatibility added ██ //██ V1.02 of 16-Nov-93: Metaware High C/C++ v3.1 compatibility added ██ //██ ██ //██ Project: 386FX Sound & Light(TM) ██ //██ Author: John Lemberger ██ //██ ██ //██ C source compatible with Watcom C386 v9.0 or later ██ //██ Zortech C++ v3.1 or later ██ //██ MetaWare High C/C++ v3.1 or later ██ //██ ██ //████████████████████████████████████████████████████████████████████████████ //██ ██ //██ Copyright (C) 1991-1993 Miles Design, Inc. ██ //██ ██ //██ Miles Design, Inc. ██ //██ 6702 Cat Creek Trail ██ //██ Austin, TX 78731 ██ //██ (512) 345-2642 / FAX (512) 338-9630 / BBS (512) 454-9990 ██ //██ ██ //████████████████████████████████████████████████████████████████████████████ #include #include #include #include #include #include #include #include #include #include "adeline.h" #include "lib_sys.h" // // Entry table types // #define UNUSED_ENTRY 0 #define BIT16_ENTRY 1 #define CALL_GATE 2 #define BIT32_ENTRY 3 #define FORWARDER_ENTRY 4 #define PARAMETER_TYPING 0x80 // // Fixup record source // #define BYTE_FIXUP 0x00 #define BIT16_SELECTOR 0x02 #define BIT16_POINTER 0x03 #define BIT16_OFFSET 0x05 #define BIT32_POINTER 0x06 #define BIT32_OFFSET 0x07 #define BIT32_RELATIVE 0x08 #define FIXUP_ALIAS 0x10 #define SRC_LIST_FLAG 0x20 // // Fixup record flags // #define INT_REF 0x00 #define IMP_REF_BY_ORD 0x01 #define IMP_REF_BY_NAME 0x02 #define INT_REF_ENTRY_TBL 0x03 #define ADDITIVE_FIXUP 0x04 #define BIT32_TARGET 0x10 #define BIT32_ADDITIVE 0x20 #define BIT16_OBJECT 0x40 #define BIT8_ORDINAL 0x80 typedef struct { ULONG lxbw; ULONG format_level; ULONG cpu_os_type; ULONG module_version; ULONG module_flags; ULONG module_num_of_pages; ULONG eip_object_num; ULONG eip; ULONG esp_object_num; ULONG esp; ULONG page_size; ULONG page_offset_shift; ULONG fixup_section_size; ULONG fixup_section_chksum; ULONG loader_section_size; ULONG loader_section_chksum; ULONG object_table_off; ULONG num_objects_in_module; ULONG object_page_table_off; ULONG object_iter_pages_off; ULONG resource_table_off; ULONG num_resource_table_entries; ULONG resident_name_table_off; ULONG entry_table_off; ULONG module_directives_off; ULONG num_module_directives; ULONG fixup_page_table_off; ULONG fixup_record_table_off; ULONG import_module_table_off; ULONG num_import_mod_entries; ULONG import_proc_table_off; ULONG per_page_chksum_off; ULONG data_pages_off; ULONG num_preload_pages; ULONG nonres_name_table_off; ULONG nonres_name_table_len; ULONG nonres_name_table_chksum; ULONG auto_ds_object_num; ULONG debug_info_off; ULONG debug_info_len; ULONG numinstance_preload; ULONG numinstance_demand; ULONG heapsize; } LX_header_struct; typedef struct { ULONG virtual_size; ULONG reloc_base_addr; ULONG object_flags; ULONG page_table_index; ULONG num_page_table_entries; ULONG reserved_space; } object_table_struct; typedef struct { ULONG page_data_offset; UWORD data_size; UWORD flags; } object_page_table_struct; typedef struct { UWORD type_id; UWORD name_id; ULONG resource_size; UWORD object; ULONG offset; } resource_table_struct; static LONG disk_err = 0; #undef min #define min(a,b) ((a) < (b) ? (a) : (b)) /**********************************************************/ static void *cdecl DLL_read(ULONG src, ULONG srcoff, ULONG flags, void *dest, ULONG length) { if (flags & DLLSRC_MEM) { memcpy(dest,(BYTE *) src+srcoff,length); return (void *) (srcoff+length); } else { lseek(src,(ULONG) srcoff,SEEK_SET); // get LX header offset read(src,dest,length); return (void *) (srcoff+length); } } /**********************************************************/ ULONG cdecl DLL_size(void *source, ULONG flags) { BYTE cword[]=" \0"; void *src_ptr; LX_header_struct LX_hdr; object_table_struct object_table; ULONG lx; ULONG i; ULONG LX_offset; ULONG module_size=0; if (flags & DLLSRC_MEM) lx=(ULONG) source; else { lx=open((BYTE *) source,O_RDONLY | O_BINARY); if (lx==-1) // error opening file? return 0; } // // Get LX header offset // src_ptr=DLL_read(lx, 0x03c, flags, &LX_offset, 4); // // Check for valid LX marker // src_ptr=DLL_read(lx,LX_offset, flags, cword, 2); if (strcmp(cword,"LX")) { // // Error: Invalid LX file // close(lx); return 0; } // // Read LX header (Tables not included) // src_ptr=DLL_read(lx,LX_offset, flags, &LX_hdr, sizeof(LX_hdr)); // // Read object table; calculate memory needed // src_ptr=(void *)(LX_offset+LX_hdr.object_table_off); for(i=0;i