| 1 | /** | 
|---|
| 2 | * File:   lx.h | 
|---|
| 3 | * Desc:   Decleration of the classs LXHeaderSuper, LXHeader and LXFile. | 
|---|
| 4 | * Author: Sander van Leeuwen, reorganized by knut st. osmundsen | 
|---|
| 5 | */ | 
|---|
| 6 |  | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef __LX_H__ | 
|---|
| 9 | #define __LX_H__ | 
|---|
| 10 | /* * * * * * */ | 
|---|
| 11 | /* includes  */ | 
|---|
| 12 | /* * * * * * */ | 
|---|
| 13 | /* types used in exe386 which is not usual elsewhere in OS/2 */ | 
|---|
| 14 | #ifndef __EXE386__ | 
|---|
| 15 | #define DWORD    ULONG | 
|---|
| 16 | #define LPVOID   VOID * | 
|---|
| 17 | #define WORD     USHORT | 
|---|
| 18 | #define UNALIGNED | 
|---|
| 19 | #define PDWORD   DWORD * | 
|---|
| 20 | #define PWORD    WORD * | 
|---|
| 21 | #define NTAPI | 
|---|
| 22 | #define BOOLEAN  ULONG | 
|---|
| 23 | #define WCHAR    USHORT | 
|---|
| 24 | #define HANDLE   ULONG | 
|---|
| 25 | #include <exe386.h> | 
|---|
| 26 | #endif | 
|---|
| 27 |  | 
|---|
| 28 |  | 
|---|
| 29 | /* * * * * * * * * * * * */ | 
|---|
| 30 | /* some "usefull" MACROS */ | 
|---|
| 31 | /* * * * * * * * * * * * */ | 
|---|
| 32 | #define ZERO(a)      (memset(&a, 0, sizeof(a))) | 
|---|
| 33 | #define ZEROstac(a)  (memset(__StackToFlat(&a), 0, sizeof(a))) | 
|---|
| 34 |  | 
|---|
| 35 | #ifndef max | 
|---|
| 36 | #define max(a,b)  (((a) > (b)) ? (a) : (b)) | 
|---|
| 37 | #endif | 
|---|
| 38 |  | 
|---|
| 39 | #ifndef min | 
|---|
| 40 | #define min(a,b)  (((a) < (b)) ? (a) : (b)) | 
|---|
| 41 | #endif | 
|---|
| 42 |  | 
|---|
| 43 | #ifndef minnotnull | 
|---|
| 44 | #define minnotnull(a , b) ((a)==0 ? (b) : ((b)==0 ? (a) : min(a,b))) | 
|---|
| 45 | #endif | 
|---|
| 46 |  | 
|---|
| 47 |  | 
|---|
| 48 |  | 
|---|
| 49 | /* * * * * */ | 
|---|
| 50 | /* Defines */ | 
|---|
| 51 | /* * * * * */ | 
|---|
| 52 | /* Some constants */ | 
|---|
| 53 | #define LXHEADER_OFFSET           0x80 | 
|---|
| 54 | #define PAGE_SIZE                 4096 | 
|---|
| 55 | #define PAGE_SHIFT                  12 | 
|---|
| 56 |  | 
|---|
| 57 | /* System type: gui or text - SetModuleType */ | 
|---|
| 58 | #define SYSTEM_CHARACTER             0 | 
|---|
| 59 | #define SYSTEM_GUI                   1 | 
|---|
| 60 |  | 
|---|
| 61 | /* Sectiontypes  */ | 
|---|
| 62 | #define SECTION_CODE            0x0001 | 
|---|
| 63 | #define SECTION_INITDATA        0x0002 | 
|---|
| 64 | #define SECTION_UNINITDATA      0x0004 | 
|---|
| 65 | #define SECTION_READONLYDATA    0x0008 | 
|---|
| 66 | #define SECTION_IMPORT          0x0010 | 
|---|
| 67 | #define SECTION_STACK           0x0020 | 
|---|
| 68 | #define SECTION_RESOURCE_ORG    0x0040 | 
|---|
| 69 | #define SECTION_RESOURCE        0x0080 | 
|---|
| 70 | #define SECTION_COMBINEDDATA    0x0100 | 
|---|
| 71 | #define SECTION_TIBFIX          0x0200 | 
|---|
| 72 |  | 
|---|
| 73 | /* limits for arrays */ | 
|---|
| 74 | #define MAX_SECTION                 64  /*PLF Mon  98-02-09 23:47:16*/ | 
|---|
| 75 | #define MAX_IMPORT                4096  //this should do for most bloated apps | 
|---|
| 76 | #define MAX_RESOURCE              4096 | 
|---|
| 77 |  | 
|---|
| 78 | /* Ordinals for exported calls from kernel32 which are used in TIBEXE/DLL code */ | 
|---|
| 79 | #define ORD_REGISTERRESOURCEINFO  1203 | 
|---|
| 80 | #define ORD_KERNEL32DLLEXITLIST   1208 | 
|---|
| 81 | #define ORD_REGISTERDLL           1209 | 
|---|
| 82 |  | 
|---|
| 83 |  | 
|---|
| 84 | /* * * * * * * * * * * */ | 
|---|
| 85 | /* TIB Section defines */ | 
|---|
| 86 | /* * * * * * * * * * * */ | 
|---|
| 87 | #define EXE_OFF_ENTRYFIX    (1+19+2+10) | 
|---|
| 88 | #define EXE_OFF_TIBCALL     (EXE_OFF_ENTRYFIX-1) | 
|---|
| 89 | #define EXE_OFF_NAMETABLE   (3+2+10) | 
|---|
| 90 | //SvL: 18-7-'98: offsets for internal pe2lx version & version resource id | 
|---|
| 91 | #define EXE_OFF_PE2LXVER    (5) | 
|---|
| 92 | #define EXE_OFF_VERRESID    (10) | 
|---|
| 93 | #define EXE_TIBSIZE         sizeof(achEXETIBFix) | 
|---|
| 94 | #define EXE_OFF_KERIMP      (EXE_OFF_NAMETABLE+10) | 
|---|
| 95 |  | 
|---|
| 96 | #define DLL_OFF_ENTRYFIX    (15+28+10) | 
|---|
| 97 | //#define DLL_OFF_ENTRYFIX   (16+28+10) | 
|---|
| 98 | #define DLL_OFF_TIBCALL     (DLL_OFF_ENTRYFIX-1) | 
|---|
| 99 | //SvL: 18-7-'98: offsets for internal pe2lx version & version resource id | 
|---|
| 100 | #define DLL_OFF_PE2LXVER    (12) | 
|---|
| 101 | #define DLL_OFF_VERRESID    (17) | 
|---|
| 102 | #define DLL_OFF_NAMETABLE   (12+10) | 
|---|
| 103 | //#define DLL_OFF_NAMETABLE   12+1+10 | 
|---|
| 104 | #define DLL_TIBSIZE         sizeof(achDLLTIBFix) | 
|---|
| 105 | #define DLL_OFF_KERIMP      (DLL_OFF_NAMETABLE+10) | 
|---|
| 106 | #define DLL_OFF_KERIMP2     (sizeof(achDLLTIBFix)-5) | 
|---|
| 107 |  | 
|---|
| 108 | #define SIZE_TIBCALL         5 | 
|---|
| 109 |  | 
|---|
| 110 | #define EXTRA_FIXUPS         2  //extra kernel32 imports | 
|---|
| 111 |  | 
|---|
| 112 | /* Size of code arrays - icc didn't like to have extern arrays without a fixed */ | 
|---|
| 113 | #define DOSHEADER_SIZE 128 | 
|---|
| 114 | #define EXETIBFIX_SIZE  37 | 
|---|
| 115 | #define DLLTIBFIX_SIZE  68 | 
|---|
| 116 | extern unsigned char achDosHeader[DOSHEADER_SIZE]; | 
|---|
| 117 | extern unsigned char achEXETIBFix[EXETIBFIX_SIZE]; | 
|---|
| 118 | extern unsigned char achDLLTIBFix[DLLTIBFIX_SIZE]; | 
|---|
| 119 |  | 
|---|
| 120 | /* header file need for RING0 */ | 
|---|
| 121 | #ifdef RING0 | 
|---|
| 122 | #include <OS2Krnl.h> | 
|---|
| 123 | #endif | 
|---|
| 124 |  | 
|---|
| 125 |  | 
|---|
| 126 | /* KSO: Rawdata for use in Section is different between LXFile and LXHdr */ | 
|---|
| 127 | #ifndef RING0 | 
|---|
| 128 | typedef char *RAWDATA; | 
|---|
| 129 | #else | 
|---|
| 130 | typedef unsigned long int RAWDATA; | 
|---|
| 131 | #endif | 
|---|
| 132 |  | 
|---|
| 133 |  | 
|---|
| 134 | /** | 
|---|
| 135 | * Section struct used for storing PE section. | 
|---|
| 136 | */ | 
|---|
| 137 | typedef struct | 
|---|
| 138 | { | 
|---|
| 139 | RAWDATA rawdata; | 
|---|
| 140 | #ifdef RING0 | 
|---|
| 141 | ULONG  lxoffset;  //file offset in the generated LX file    (w/ TIBFix) | 
|---|
| 142 | #endif | 
|---|
| 143 | int    rawsize; | 
|---|
| 144 | int    virtualsize; | 
|---|
| 145 | int    curoff; | 
|---|
| 146 | int    type; | 
|---|
| 147 | int    address; | 
|---|
| 148 | int    endaddress; | 
|---|
| 149 | int    nrpages; | 
|---|
| 150 | int    nrinvalidpages; | 
|---|
| 151 | BOOL   fProcessed; | 
|---|
| 152 | BOOL   fInvalid; | 
|---|
| 153 | } Section; | 
|---|
| 154 |  | 
|---|
| 155 |  | 
|---|
| 156 |  | 
|---|
| 157 | /** | 
|---|
| 158 | * Used with section aligning. | 
|---|
| 159 | */ | 
|---|
| 160 | typedef struct | 
|---|
| 161 | { | 
|---|
| 162 | int    size; | 
|---|
| 163 | int    flags; | 
|---|
| 164 | } DataPage; | 
|---|
| 165 |  | 
|---|
| 166 |  | 
|---|
| 167 |  | 
|---|
| 168 | #pragma pack(1) | 
|---|
| 169 | //also defined in USER32\NAMEID.H! | 
|---|
| 170 | #define RESID_CONVERTEDNAMES    63*1024 | 
|---|
| 171 | typedef struct | 
|---|
| 172 | { | 
|---|
| 173 | int    id; | 
|---|
| 174 | char   name[1]; | 
|---|
| 175 | } NameId; | 
|---|
| 176 |  | 
|---|
| 177 |  | 
|---|
| 178 | /** | 
|---|
| 179 | * Name import fixup - intermediate | 
|---|
| 180 | */ | 
|---|
| 181 | typedef struct | 
|---|
| 182 | { | 
|---|
| 183 | unsigned char       nr_stype;       /* Source type - field shared with new_rlc */ | 
|---|
| 184 | unsigned char       nr_flags;       /* Flag byte - field shared with new_rlc */ | 
|---|
| 185 | short               r32_soff;       /* Source offset */ | 
|---|
| 186 | unsigned short      r32_objmod;     /* Target object number or Module ordinal */ | 
|---|
| 187 | unsigned short      proc;           /* Procedure name offset */ | 
|---|
| 188 | unsigned short      srcpage; | 
|---|
| 189 | } namefixup; | 
|---|
| 190 |  | 
|---|
| 191 |  | 
|---|
| 192 | /** | 
|---|
| 193 | * Name import fixup - really used in LX-files | 
|---|
| 194 | */ | 
|---|
| 195 | typedef struct | 
|---|
| 196 | { | 
|---|
| 197 | unsigned char       nr_stype;       /* Source type - field shared with new_rlc */ | 
|---|
| 198 | unsigned char       nr_flags;       /* Flag byte - field shared with new_rlc */ | 
|---|
| 199 | short               r32_soff;       /* Source offset */ | 
|---|
| 200 | unsigned short      r32_objmod;     /* Target object number or Module ordinal */ | 
|---|
| 201 | unsigned short      proc;           /* Procedure name offset */ | 
|---|
| 202 | } realnamefixup; | 
|---|
| 203 |  | 
|---|
| 204 |  | 
|---|
| 205 | /** | 
|---|
| 206 | * Ordinal Import Fixup - intermediate | 
|---|
| 207 | */ | 
|---|
| 208 | typedef struct | 
|---|
| 209 | { | 
|---|
| 210 | unsigned char       nr_stype;       /* Source type - field shared with new_rlc */ | 
|---|
| 211 | unsigned char       nr_flags;       /* Flag byte - field shared with new_rlc */ | 
|---|
| 212 | short               r32_soff;       /* Source offset */ | 
|---|
| 213 | unsigned short      r32_objmod;     /* Target object number or Module ordinal */ | 
|---|
| 214 | unsigned short      ord;            /* Ordinal */ | 
|---|
| 215 | unsigned short      srcpage; | 
|---|
| 216 | } ordfixup; | 
|---|
| 217 |  | 
|---|
| 218 |  | 
|---|
| 219 | /** | 
|---|
| 220 | * Ordinal Import Fixup - really used in LX-files | 
|---|
| 221 | */ | 
|---|
| 222 | typedef struct | 
|---|
| 223 | { | 
|---|
| 224 | unsigned char       nr_stype;       /* Source type - field shared with new_rlc */ | 
|---|
| 225 | unsigned char       nr_flags;       /* Flag byte - field shared with new_rlc */ | 
|---|
| 226 | short               r32_soff;       /* Source offset */ | 
|---|
| 227 | unsigned short      r32_objmod;     /* Target object number or Module ordinal */ | 
|---|
| 228 | unsigned short      ord;            /* Ordinal */ | 
|---|
| 229 | } realordfixup; | 
|---|
| 230 |  | 
|---|
| 231 |  | 
|---|
| 232 | /** | 
|---|
| 233 | * Internal 32-bit Offset Fixup - intermediate | 
|---|
| 234 | */ | 
|---|
| 235 | typedef struct | 
|---|
| 236 | { | 
|---|
| 237 | unsigned char       nr_stype;       /* Source type - field shared with new_rlc */ | 
|---|
| 238 | unsigned char       nr_flags;       /* Flag byte - field shared with new_rlc */ | 
|---|
| 239 | short               r32_soff;       /* Source offset */ | 
|---|
| 240 | unsigned short      targetobj; | 
|---|
| 241 | unsigned long       targetaddr; | 
|---|
| 242 | unsigned short      srcobj; | 
|---|
| 243 | unsigned short      srcpage; | 
|---|
| 244 | } intfixup; | 
|---|
| 245 |  | 
|---|
| 246 |  | 
|---|
| 247 | /** | 
|---|
| 248 | * Internal 32-bit Offset Fixup - really used in LX-files | 
|---|
| 249 | */ | 
|---|
| 250 | typedef struct | 
|---|
| 251 | { | 
|---|
| 252 | unsigned char       nr_stype;       /* Source type - field shared with new_rlc */ | 
|---|
| 253 | unsigned char       nr_flags;       /* Flag byte - field shared with new_rlc */ | 
|---|
| 254 | short               r32_soff;       /* Source offset */ | 
|---|
| 255 | unsigned short      targetobj; | 
|---|
| 256 | unsigned long       targetaddr; | 
|---|
| 257 | } realintfixup; | 
|---|
| 258 |  | 
|---|
| 259 |  | 
|---|
| 260 | /** | 
|---|
| 261 | * Export Bundle - format of exports | 
|---|
| 262 | */ | 
|---|
| 263 | typedef struct | 
|---|
| 264 | { | 
|---|
| 265 | unsigned char       b32_cnt;        /* Number of entries in this bundle */ | 
|---|
| 266 | unsigned char       b32_type;       /* Bundle type */ | 
|---|
| 267 | unsigned short      b32_obj;        /* Object number */ | 
|---|
| 268 |  | 
|---|
| 269 | unsigned char       e32_flags;      /* Entry point flags */ | 
|---|
| 270 | unsigned long       e32_offset;     /* 16-bit/32-bit offset entry */ | 
|---|
| 271 | } exportbundle; | 
|---|
| 272 |  | 
|---|
| 273 |  | 
|---|
| 274 | /** | 
|---|
| 275 | * Forward Bundle - used to forward exports | 
|---|
| 276 | */ | 
|---|
| 277 | typedef struct | 
|---|
| 278 | { | 
|---|
| 279 | unsigned char       b32_cnt;        /* Number of entries in this bundle */ | 
|---|
| 280 | unsigned char       b32_type;       /* Bundle type */ | 
|---|
| 281 | unsigned short      b32_obj;        /* Object number */ | 
|---|
| 282 |  | 
|---|
| 283 | unsigned char       e32_flags;      /* Entry point flags */ | 
|---|
| 284 | unsigned short      modord;         /* Module ordinal number */ | 
|---|
| 285 | unsigned long       value;          /* Proc name offset or ordinal */ | 
|---|
| 286 | } forwardbundle; | 
|---|
| 287 |  | 
|---|
| 288 | #pragma pack() | 
|---|
| 289 |  | 
|---|
| 290 |  | 
|---|
| 291 |  | 
|---|
| 292 |  | 
|---|
| 293 | /** | 
|---|
| 294 | * @prop     Toplevel class for LX files. | 
|---|
| 295 | * @purpose  Generate LX-files. | 
|---|
| 296 | * @desc     .... | 
|---|
| 297 | * @author   Sander van Leeuwen, modified by knut st. osmundsen | 
|---|
| 298 | */ | 
|---|
| 299 | class LXHeaderSuper | 
|---|
| 300 | { | 
|---|
| 301 |  | 
|---|
| 302 | public: | 
|---|
| 303 | /** @cat Constructor/Destructor */ | 
|---|
| 304 | LXHeaderSuper(); | 
|---|
| 305 | ~LXHeaderSuper(); | 
|---|
| 306 |  | 
|---|
| 307 | /** @cat Public Methods */ | 
|---|
| 308 | /** dummy text */ | 
|---|
| 309 | BOOL SetEntryAddress(int vaEntryPoint); | 
|---|
| 310 | void SetEntryPoint(int address) { EntryAddress = address; }; //absolute virtual address | 
|---|
| 311 | void SetExeType(BOOL IsEXE); | 
|---|
| 312 | void SetNoFixups(); | 
|---|
| 313 | void SetStackSize(int size); | 
|---|
| 314 | BOOL SetResourceSize(int size); | 
|---|
| 315 | BOOL SetNrResources(int cnt); | 
|---|
| 316 | void StoreSection(RAWDATA rawdata, int rawsize, int virtualsize, int address, int type); | 
|---|
| 317 | BOOL AlignSections(PIMAGE_OPTIONAL_HEADER pOH); | 
|---|
| 318 | BOOL StoreImportByName(char *modname, int idxmod, char *name, int offset); | 
|---|
| 319 | BOOL StoreImportByOrd(int idxmod, int ordinal, int offset); | 
|---|
| 320 | BOOL StoreImportModules(char *modules, int nrmod); | 
|---|
| 321 | void SetNoNameImports(); | 
|---|
| 322 |  | 
|---|
| 323 | void SetModuleType(int type); | 
|---|
| 324 | void AddOff32Fixup(int address); | 
|---|
| 325 | BOOL SetNrOff32Fixups(int nr); | 
|---|
| 326 | BOOL AddNameExport(int address, char *name, int ordinal); | 
|---|
| 327 | BOOL AddOrdExport(int address, int ordinal); | 
|---|
| 328 | BOOL SetNrExtFixups(int nr); | 
|---|
| 329 | BOOL AddForwarder(char *name, int ordinal, char *forward); | 
|---|
| 330 |  | 
|---|
| 331 | int  GetPageNoByVA(int vaAddress); | 
|---|
| 332 | void SetModuleName(char *filename); | 
|---|
| 333 |  | 
|---|
| 334 | BOOL SetNrSections(int cSections); | 
|---|
| 335 | BOOL CreateTIBSection(PIMAGE_OPTIONAL_HEADER pOH); | 
|---|
| 336 |  | 
|---|
| 337 |  | 
|---|
| 338 | /** @cat Resource Procedures */ | 
|---|
| 339 | BOOL StoreResource(int id, int type, int size, char *resourcedata); | 
|---|
| 340 | BOOL StoreWin32Resource(int id, int type, int size, char *resourcedata); | 
|---|
| 341 | int  ConvertNametoId(char *nameid); | 
|---|
| 342 | BOOL SaveConvertedNames(); | 
|---|
| 343 | BOOL StoreResourceId(int id); | 
|---|
| 344 | int  GetUniqueId(); | 
|---|
| 345 | //SvL: 18-7-'98: Set version resource id | 
|---|
| 346 | void SetVersionResourceId(int id) { VersionResourceId = id; }; | 
|---|
| 347 |  | 
|---|
| 348 | void SetTLSAddress(ULONG dwTlsAddress)       { tlsAddress = dwTlsAddress; }; | 
|---|
| 349 | void SetTLSIndexAddress(ULONG dwTlsIndexAddr)    { tlsIndexAddr = dwTlsIndexAddr; }; | 
|---|
| 350 | void SetTLSInitSize(ULONG dwTlsSize)     { tlsInitSize = dwTlsSize; }; | 
|---|
| 351 | void SetTLSTotalSize(ULONG dwTlsSize)        { tlsTotalSize = dwTlsSize; }; | 
|---|
| 352 | void SetTLSCallBackAddr(ULONG dwTlsCallBackAddr) { tlsCallBackAddr = dwTlsCallBackAddr; }; | 
|---|
| 353 |  | 
|---|
| 354 | void AddExtraFixups(); | 
|---|
| 355 |  | 
|---|
| 356 | protected: | 
|---|
| 357 | /** @cat Protected Procedures */ | 
|---|
| 358 | BOOL IsSystemModule(char *mod, int size); | 
|---|
| 359 | int  FindName(char *table, int index); | 
|---|
| 360 | char *StripPath(char *path); | 
|---|
| 361 | char *StripExtension(char *fname); | 
|---|
| 362 | void UpCase(char *mixedcase); | 
|---|
| 363 |  | 
|---|
| 364 | BOOL StoreAndSortImport(namefixup *newfrec); | 
|---|
| 365 |  | 
|---|
| 366 | int  GetNrPages(); | 
|---|
| 367 | int  GetNrObjects(); | 
|---|
| 368 | int  GetNrObjects2(); | 
|---|
| 369 | int  GetSection(int type); | 
|---|
| 370 | int  GetOriginalSectionIdxByVA(int vaAddress); | 
|---|
| 371 | int  GetSectionIdxByVA(int vaAddress); | 
|---|
| 372 | int  GetObjectNoByVA(int vaAddress); | 
|---|
| 373 | int  GetTIBSectionIdx(); | 
|---|
| 374 | int  GetTIBObjectNo(); | 
|---|
| 375 |  | 
|---|
| 376 | /** UNUSED!*/ | 
|---|
| 377 | int  GetSectionLEAddress(int address); | 
|---|
| 378 |  | 
|---|
| 379 | /** @cat Protected Data */ | 
|---|
| 380 | BOOL           IsEXE, fConsole; | 
|---|
| 381 | ULONG          EntryAddress; | 
|---|
| 382 | Section       *PESection;   //KSO: PESection is now dynamic | 
|---|
| 383 | int            cPESections; //KSO: PESection is now dynamic | 
|---|
| 384 | Section        ResSection; | 
|---|
| 385 | DataPage      *datapage; | 
|---|
| 386 |  | 
|---|
| 387 | char          *impmodules; | 
|---|
| 388 | char          *impnames, *impnameoff; | 
|---|
| 389 | int            impmodulesize, impnamesize; | 
|---|
| 390 | int            fFlags; | 
|---|
| 391 | int            StackSize; | 
|---|
| 392 | int            nrsections; | 
|---|
| 393 |  | 
|---|
| 394 | namefixup     *impfixuprec; | 
|---|
| 395 | int            nrimpfixups; | 
|---|
| 396 | int            nrofimpfixups; //available in impfixuprec | 
|---|
| 397 |  | 
|---|
| 398 | intfixup      *intfixuprec; | 
|---|
| 399 | int            nrintfixups; | 
|---|
| 400 | int            nrofintfixups; //available in intfixuprec | 
|---|
| 401 |  | 
|---|
| 402 | rsrc32        *os2resource; | 
|---|
| 403 | int            nrresources; | 
|---|
| 404 | int            curresource; | 
|---|
| 405 | NameId        *cvtname, *curcvtname; | 
|---|
| 406 | int            nrcvtnames; | 
|---|
| 407 | int           *resids; | 
|---|
| 408 | int            nrids; | 
|---|
| 409 | int            nrofids; | 
|---|
| 410 | int            cvtnametableid; | 
|---|
| 411 | int            orgrestableid; | 
|---|
| 412 | ULONG         *orgrestable; | 
|---|
| 413 | int            nrorgres; | 
|---|
| 414 |  | 
|---|
| 415 | char           *exports, *curexport; | 
|---|
| 416 | int            exportsize; | 
|---|
| 417 | int            nrexports; | 
|---|
| 418 | exportbundle   *expbundle, *curexpb; | 
|---|
| 419 |  | 
|---|
| 420 | char           modulename[132]; | 
|---|
| 421 |  | 
|---|
| 422 | struct e32_exe LXHdr; | 
|---|
| 423 |  | 
|---|
| 424 | static int     uniqueId; | 
|---|
| 425 |  | 
|---|
| 426 | int            kernel32Object; | 
|---|
| 427 |  | 
|---|
| 428 | //SvL: 18-7-'98: Version resource id | 
|---|
| 429 | ULONG          VersionResourceId; | 
|---|
| 430 |  | 
|---|
| 431 | ULONG     tlsAddress;         //address of TLS data | 
|---|
| 432 | ULONG     tlsIndexAddr;       //address of DWORD that receives the TLS index | 
|---|
| 433 | ULONG     tlsInitSize;        //size of initialized TLS memory block | 
|---|
| 434 | ULONG     tlsTotalSize;       //size of TLS memory block | 
|---|
| 435 | ULONG     tlsCallBackAddr;    //ptr to TLS callback array | 
|---|
| 436 |  | 
|---|
| 437 |  | 
|---|
| 438 | unsigned char  *szTIBFix; | 
|---|
| 439 | int            TIBSize; | 
|---|
| 440 | int            TIBOffEntry; | 
|---|
| 441 | int            TIBOffCall; | 
|---|
| 442 | int            TIBOffName; | 
|---|
| 443 | int            TIBOffKerImport; | 
|---|
| 444 | //SvL: 18-7-'98: Internal pe2lx version and version resource id offsets | 
|---|
| 445 | int            TIBOffPe2lxVer; | 
|---|
| 446 | int            TIBOffVerResId; | 
|---|
| 447 |  | 
|---|
| 448 |  | 
|---|
| 449 | /* prev statics */ | 
|---|
| 450 | int lastord; | 
|---|
| 451 | BOOL fFirstIcon; | 
|---|
| 452 | }; | 
|---|
| 453 |  | 
|---|
| 454 |  | 
|---|
| 455 | #ifndef RING0 | 
|---|
| 456 |  | 
|---|
| 457 |  | 
|---|
| 458 | class LXHeader : public LXHeaderSuper | 
|---|
| 459 | { | 
|---|
| 460 | public: | 
|---|
| 461 | LXHeader(); | 
|---|
| 462 | ~LXHeader(); | 
|---|
| 463 | BOOL SaveNewExeFile(char *filename); | 
|---|
| 464 | void SetFileBase(char *p) { pBaseFile = p;} | 
|---|
| 465 |  | 
|---|
| 466 |  | 
|---|
| 467 | protected: | 
|---|
| 468 | char *pBaseFile; | 
|---|
| 469 | }; | 
|---|
| 470 |  | 
|---|
| 471 | extern LXHeader OS2Exe; | 
|---|
| 472 |  | 
|---|
| 473 |  | 
|---|
| 474 | #else | 
|---|
| 475 |  | 
|---|
| 476 |  | 
|---|
| 477 |  | 
|---|
| 478 | /* signature and file header struct */ | 
|---|
| 479 | typedef struct | 
|---|
| 480 | { | 
|---|
| 481 | DWORD Signature; | 
|---|
| 482 | IMAGE_FILE_HEADER FileHeader; | 
|---|
| 483 | } IMAGE_SIG_FILE_HEADER, *PIMAGE_SIG_FILE_HEADER; | 
|---|
| 484 |  | 
|---|
| 485 |  | 
|---|
| 486 |  | 
|---|
| 487 |  | 
|---|
| 488 | /** | 
|---|
| 489 | * @prop     Convert PE files to LX files. | 
|---|
| 490 | * @purpose  Convert PE files to LX files for use with win32k in RING0. | 
|---|
| 491 | * @desc     Initially designed to be used with win32k, but may be used in | 
|---|
| 492 | *           other programs. The init function analyses a given PE-file, builds | 
|---|
| 493 | *           a (virtual) LX-file from it and waits from read request of data from | 
|---|
| 494 | *           the virtual LX file. | 
|---|
| 495 | * @author   knut st. osmundsen | 
|---|
| 496 | */ | 
|---|
| 497 | class LXFile : public LXHeaderSuper | 
|---|
| 498 | { | 
|---|
| 499 | public: | 
|---|
| 500 | LXFile(); | 
|---|
| 501 | ~LXFile(); | 
|---|
| 502 |  | 
|---|
| 503 | /** @cat Public Methods */ | 
|---|
| 504 | BOOL   init(SFN hFile, PIMAGE_SIG_FILE_HEADER pHdr, ULONG PEOffset); | 
|---|
| 505 | ULONG  read(ULONG ulOffset, PVOID pBuffer, ULONG ulBytesToRead, PULONG ulBytesRead, ULONG ulFlag); | 
|---|
| 506 |  | 
|---|
| 507 | /** @cat Public Helper Functions */ | 
|---|
| 508 | int    queryMemoryUsage(); | 
|---|
| 509 | BOOL   queryIsModuleName(const char *szFilename); | 
|---|
| 510 | ULONG  queryFileSize(); | 
|---|
| 511 |  | 
|---|
| 512 | /** @cat Static Methods */ | 
|---|
| 513 | static BOOL isPEFile(PIMAGE_SIG_FILE_HEADER pHdr); | 
|---|
| 514 | static void buildQAppTypeHeader(struct e32_exe *pHdr); | 
|---|
| 515 |  | 
|---|
| 516 | /** @cat New/Delete Operators */ | 
|---|
| 517 | #ifndef __DEBUG_ALLOC__ | 
|---|
| 518 | void *operator new(/*size_t*/unsigned int a); | 
|---|
| 519 | void operator delete(void *p); | 
|---|
| 520 | #else | 
|---|
| 521 | void *operator new(size_t a, const char *file, unsigned int line); | 
|---|
| 522 | void operator delete(void *p, const char *file, unsigned int line); | 
|---|
| 523 | #endif | 
|---|
| 524 |  | 
|---|
| 525 |  | 
|---|
| 526 | protected: | 
|---|
| 527 | /** @cat Process Methods */ | 
|---|
| 528 | BOOL ProcessFixups   (PIMAGE_SECTION_HEADER pSectionTable); | 
|---|
| 529 | BOOL ProcessExports  (PIMAGE_SECTION_HEADER pSectionTable); | 
|---|
| 530 | BOOL ProcessImports  (PIMAGE_SECTION_HEADER pSectionTable); | 
|---|
| 531 | BOOL ProcessResources(PIMAGE_SECTION_HEADER pSectionTable); | 
|---|
| 532 | BOOL PrepareLX(); | 
|---|
| 533 |  | 
|---|
| 534 | /** @cat Helper Functions */ | 
|---|
| 535 | BOOL  PEIsImportDataSection(PIMAGE_SECTION_HEADER psh); | 
|---|
| 536 | DWORD PEImageDirectoryOffset (PIMAGE_SECTION_HEADER psh, DWORD dwIMAGE_DIRECTORY); | 
|---|
| 537 | PIMAGE_SECTION_HEADER PEGetSectionHdrByImageDir(PIMAGE_SECTION_HEADER psh, DWORD dwIMAGE_DIRECTORY); | 
|---|
| 538 | PIMAGE_SECTION_HEADER PEGetSectionHdrByName(IMAGE_SECTION_HEADER *psh, char *szSection); | 
|---|
| 539 | PIMAGE_SECTION_HEADER PEGetSectionHdrByRVA(IMAGE_SECTION_HEADER *psh, ULONG rva); | 
|---|
| 540 | PVOID PEReadSection(PIMAGE_SECTION_HEADER pSH); | 
|---|
| 541 | int  PEGetNumberOfResources(PIMAGE_RESOURCE_DIRECTORY prdRoot); | 
|---|
| 542 | BOOL StoreIdResSubDir(PIMAGE_RESOURCE_DIRECTORY prdType, int level, PIMAGE_RESOURCE_DIRECTORY prdRoot, int VirtualAddress, int type, int id); | 
|---|
| 543 | BOOL ProcessResSubDir(PIMAGE_RESOURCE_DIRECTORY prdType, int level, PIMAGE_RESOURCE_DIRECTORY prdRoot, int VirtualAddress, int type, int id); | 
|---|
| 544 | int  AddOff32Fixup(int address, char *pPage); | 
|---|
| 545 | int  AddOff32FinishCrossPageFixup(void); | 
|---|
| 546 | int  ReadPageByAddress(ULONG address, void *pPage); | 
|---|
| 547 | void AdjustTIB(); | 
|---|
| 548 |  | 
|---|
| 549 |  | 
|---|
| 550 | private: | 
|---|
| 551 | /** @cat Privat Datamembers */ | 
|---|
| 552 | int inited; | 
|---|
| 553 | IMAGE_NT_HEADERS PEHdrs; | 
|---|
| 554 | ULONG   ulPEOffset;                    /* file offset of PE signature */ | 
|---|
| 555 | SFN     hFile;                         /* file handle */ | 
|---|
| 556 | ULONG nSections; | 
|---|
| 557 |  | 
|---|
| 558 | /* fixup stuff */ | 
|---|
| 559 | intfixup  crossedpage; | 
|---|
| 560 | BOOL      fCrossed; | 
|---|
| 561 | int       crossedpageaddress; | 
|---|
| 562 |  | 
|---|
| 563 | /* LX converted stuff */ | 
|---|
| 564 | struct o32_obj *pObjectTable; | 
|---|
| 565 | struct o32_map *pObjectPageTable; | 
|---|
| 566 | //info: struct rsrc32 *pResourceTable = os2resource | 
|---|
| 567 | //info: if (Exe){ | 
|---|
| 568 | //         pResidentNameTable = modulename; // (NB. two blanks) | 
|---|
| 569 | //         pEntryTable = '\0'; | 
|---|
| 570 | //      }else{ | 
|---|
| 571 | //         pResidentNameTable = exports; | 
|---|
| 572 | //         pEntryTable = expbundle; | 
|---|
| 573 | //      } | 
|---|
| 574 | int *pFixupTable; | 
|---|
| 575 | realintfixup  *pFixupRecordTable;  //size = LXHdr.e32_fixupsize - sizeof(FixupTable) //((nrpages+1)*sizeof(int)) | 
|---|
| 576 | //info: pImportModuleNameTable = impmodules;  //size impmodulesize | 
|---|
| 577 | //info: pImportProcedureNameTable = impnames; //size impnamesize | 
|---|
| 578 | //info: rawdata begins here. | 
|---|
| 579 | ULONG TIBEntry; | 
|---|
| 580 | //ULONG ul | 
|---|
| 581 | ULONG ulResourceOffset; | 
|---|
| 582 | //info: resources after here. | 
|---|
| 583 | }; | 
|---|
| 584 |  | 
|---|
| 585 | #endif | 
|---|
| 586 |  | 
|---|
| 587 | #endif | 
|---|