| 1 | /* $Id: wprocess.cpp,v 1.55 1999-12-05 10:02:31 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Win32 process functions
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 7 | *
|
|---|
| 8 | *
|
|---|
| 9 | * NOTE: Even though Odin32 OS/2 apps don't switch FS selectors,
|
|---|
| 10 | * we still allocate a TEB to store misc information.
|
|---|
| 11 | *
|
|---|
| 12 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 13 | *
|
|---|
| 14 | */
|
|---|
| 15 | #include <odin.h>
|
|---|
| 16 | #include <odinwrap.h>
|
|---|
| 17 | #include <os2win.h>
|
|---|
| 18 | #include <stdio.h>
|
|---|
| 19 | #include <stdlib.h>
|
|---|
| 20 | #include <string.h>
|
|---|
| 21 |
|
|---|
| 22 | #include <unicode.h>
|
|---|
| 23 | #include <windllbase.h>
|
|---|
| 24 | #include <winexebase.h>
|
|---|
| 25 | #include <windllpeldr.h>
|
|---|
| 26 | #include <winfakepeldr.h>
|
|---|
| 27 |
|
|---|
| 28 | #ifdef __IBMCPP__
|
|---|
| 29 | #include <builtin.h>
|
|---|
| 30 | #endif
|
|---|
| 31 |
|
|---|
| 32 | #include "exceptutil.h"
|
|---|
| 33 | #include "oslibmisc.h"
|
|---|
| 34 |
|
|---|
| 35 | #include "console.h"
|
|---|
| 36 | #include "cio.h"
|
|---|
| 37 | #include "versionos2.h" /*PLF Wed 98-03-18 02:36:51*/
|
|---|
| 38 | #include <wprocess.h>
|
|---|
| 39 | #include "mmap.h"
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | ODINDEBUGCHANNEL(KERNEL32-WPROCESS)
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 | //******************************************************************************
|
|---|
| 46 | //******************************************************************************
|
|---|
| 47 | BOOL fFreeLibrary = FALSE;
|
|---|
| 48 | BOOL fIsOS2Image = FALSE; //TRUE -> Odin32 OS/2 application (not converted!)
|
|---|
| 49 | //FALSE -> otherwise
|
|---|
| 50 | //Process database
|
|---|
| 51 | PDB ProcessPDB = {0};
|
|---|
| 52 | USHORT ProcessTIBSel = 0;
|
|---|
| 53 | DWORD *TIBFlatPtr = 0;
|
|---|
| 54 |
|
|---|
| 55 | //******************************************************************************
|
|---|
| 56 | //******************************************************************************
|
|---|
| 57 | TEB *WIN32API GetThreadTEB()
|
|---|
| 58 | {
|
|---|
| 59 | if(TIBFlatPtr == NULL)
|
|---|
| 60 | return 0;
|
|---|
| 61 |
|
|---|
| 62 | return (TEB *)*TIBFlatPtr;
|
|---|
| 63 | }
|
|---|
| 64 | //******************************************************************************
|
|---|
| 65 | //******************************************************************************
|
|---|
| 66 | THDB *WIN32API GetThreadTHDB()
|
|---|
| 67 | {
|
|---|
| 68 | TEB *winteb;
|
|---|
| 69 | THDB *thdb;
|
|---|
| 70 |
|
|---|
| 71 | if(TIBFlatPtr == NULL)
|
|---|
| 72 | return 0;
|
|---|
| 73 |
|
|---|
| 74 | winteb = (TEB *)*TIBFlatPtr;
|
|---|
| 75 | if(winteb == NULL) {
|
|---|
| 76 | return NULL;
|
|---|
| 77 | }
|
|---|
| 78 | thdb = (THDB *)(winteb+1);
|
|---|
| 79 |
|
|---|
| 80 | return thdb;
|
|---|
| 81 | }
|
|---|
| 82 | //******************************************************************************
|
|---|
| 83 | // Set up the TIB selector and memory for the current thread
|
|---|
| 84 | //******************************************************************************
|
|---|
| 85 | TEB *InitializeTIB(BOOL fMainThread)
|
|---|
| 86 | {
|
|---|
| 87 | TEB *winteb;
|
|---|
| 88 | THDB *thdb;
|
|---|
| 89 |
|
|---|
| 90 | USHORT tibsel;
|
|---|
| 91 |
|
|---|
| 92 | //Allocate one dword to store the flat address of our TEB
|
|---|
| 93 | if(fMainThread) {
|
|---|
| 94 | TIBFlatPtr = (DWORD *)OSLibAllocThreadLocalMemory(1);
|
|---|
| 95 | if(TIBFlatPtr == 0) {
|
|---|
| 96 | dprintf(("InitializeTIB: local thread memory alloc failed!!"));
|
|---|
| 97 | DebugInt3();
|
|---|
| 98 | return NULL;
|
|---|
| 99 | }
|
|---|
| 100 | }
|
|---|
| 101 | if(OSLibAllocSel(PAGE_SIZE, &tibsel) == FALSE)
|
|---|
| 102 | {
|
|---|
| 103 | dprintf(("InitializeTIB: selector alloc failed!!"));
|
|---|
| 104 | DebugInt3();
|
|---|
| 105 | return NULL;
|
|---|
| 106 | }
|
|---|
| 107 | winteb = (TEB *)OSLibSelToFlat(tibsel);
|
|---|
| 108 | if(winteb == NULL)
|
|---|
| 109 | {
|
|---|
| 110 | dprintf(("InitializeTIB: DosSelToFlat failed!!"));
|
|---|
| 111 | DebugInt3();
|
|---|
| 112 | return NULL;
|
|---|
| 113 | }
|
|---|
| 114 | memset(winteb, 0, PAGE_SIZE);
|
|---|
| 115 | thdb = (THDB *)(winteb+1);
|
|---|
| 116 | *TIBFlatPtr = (DWORD)winteb;
|
|---|
| 117 |
|
|---|
| 118 | winteb->except = (PVOID)-1; /* 00 Head of exception handling chain */
|
|---|
| 119 | winteb->stack_top = (PVOID)OSLibGetTIB(TIB_STACKTOP); /* 04 Top of thread stack */
|
|---|
| 120 | winteb->stack_low = (PVOID)OSLibGetTIB(TIB_STACKLOW); /* 08 Stack low-water mark */
|
|---|
| 121 | winteb->htask16 = (USHORT)OSLibGetPIB(PIB_TASKHNDL); /* 0c Win16 task handle */
|
|---|
| 122 | winteb->stack_sel = getSS(); /* 0e 16-bit stack selector */
|
|---|
| 123 | winteb->self = winteb; /* 18 Pointer to this structure */
|
|---|
| 124 | winteb->flags = TEBF_WIN32; /* 1c Flags */
|
|---|
| 125 | winteb->queue = 0; /* 28 Message queue */
|
|---|
| 126 | winteb->tls_ptr = &thdb->tls_array[0]; /* 2c Pointer to TLS array */
|
|---|
| 127 | winteb->process = &ProcessPDB; /* 30 owning process (used by NT3.51 applets)*/
|
|---|
| 128 |
|
|---|
| 129 | memcpy(&thdb->teb, winteb, sizeof(TEB));
|
|---|
| 130 | thdb->process = &ProcessPDB;
|
|---|
| 131 | thdb->exit_code = 0x103; /* STILL_ACTIVE */
|
|---|
| 132 | thdb->teb_sel = tibsel;
|
|---|
| 133 | thdb->OrgTIBSel = GetFS();
|
|---|
| 134 | thdb->pWsockData = NULL;
|
|---|
| 135 |
|
|---|
| 136 | if(OSLibGetPIB(PIB_TASKTYPE) == TASKTYPE_PM)
|
|---|
| 137 | {
|
|---|
| 138 | thdb->flags = 0; //todo gui
|
|---|
| 139 | }
|
|---|
| 140 | else thdb->flags = 0; //todo textmode
|
|---|
| 141 |
|
|---|
| 142 | if(fMainThread)
|
|---|
| 143 | {
|
|---|
| 144 | //todo initialize PDB during process creation
|
|---|
| 145 | //todo: initialize TLS array if required
|
|---|
| 146 | //TLS in executable always TLS index 0?
|
|---|
| 147 | ProcessTIBSel = tibsel;
|
|---|
| 148 | ProcessPDB.exit_code = 0x103; /* STILL_ACTIVE */
|
|---|
| 149 | ProcessPDB.threads = 1;
|
|---|
| 150 | ProcessPDB.running_threads = 1;
|
|---|
| 151 | ProcessPDB.ring0_threads = 1;
|
|---|
| 152 | ProcessPDB.system_heap = GetProcessHeap();
|
|---|
| 153 | ProcessPDB.parent = 0;
|
|---|
| 154 | ProcessPDB.group = &ProcessPDB;
|
|---|
| 155 | ProcessPDB.priority = 8; /* Normal */
|
|---|
| 156 | ProcessPDB.heap = ProcessPDB.system_heap; /* will be changed later on */
|
|---|
| 157 | ProcessPDB.next = NULL;
|
|---|
| 158 | ProcessPDB.winver = 0xffff; /* to be determined */
|
|---|
| 159 | ProcessPDB.server_pid = (void *)GetCurrentProcessId();
|
|---|
| 160 |
|
|---|
| 161 | GetSystemTime(&ProcessPDB.creationTime);
|
|---|
| 162 |
|
|---|
| 163 | /* Initialize the critical section */
|
|---|
| 164 | InitializeCriticalSection( &ProcessPDB.crit_section );
|
|---|
| 165 | }
|
|---|
| 166 | dprintf(("InitializeTIB setup TEB with selector %x", tibsel));
|
|---|
| 167 | dprintf(("InitializeTIB: FS(%x):[0] = %x", GetFS(), QueryExceptionChain()));
|
|---|
| 168 | return winteb;
|
|---|
| 169 | }
|
|---|
| 170 | //******************************************************************************
|
|---|
| 171 | // Destroy the TIB selector and memory for the current thread
|
|---|
| 172 | //******************************************************************************
|
|---|
| 173 | void DestroyTIB()
|
|---|
| 174 | {
|
|---|
| 175 | SHORT orgtibsel;
|
|---|
| 176 | TEB *winteb;
|
|---|
| 177 | THDB *thdb;
|
|---|
| 178 |
|
|---|
| 179 | dprintf(("DestroyTIB: FS = %x", GetFS()));
|
|---|
| 180 | dprintf(("DestroyTIB: FS:[0] = %x", QueryExceptionChain()));
|
|---|
| 181 |
|
|---|
| 182 | winteb = (TEB *)*TIBFlatPtr;
|
|---|
| 183 | if(winteb) {
|
|---|
| 184 | thdb = (THDB *)(winteb+1);
|
|---|
| 185 | orgtibsel = thdb->OrgTIBSel;
|
|---|
| 186 |
|
|---|
| 187 | //Restore our original FS selector
|
|---|
| 188 | SetFS(orgtibsel);
|
|---|
| 189 |
|
|---|
| 190 | //And free our own
|
|---|
| 191 | OSLibFreeSel(thdb->teb_sel);
|
|---|
| 192 | }
|
|---|
| 193 | else dprintf(("Already destroyed TIB"));
|
|---|
| 194 |
|
|---|
| 195 | dprintf(("DestroyTIB: FS(%x):[0] = %x", GetFS(), QueryExceptionChain()));
|
|---|
| 196 | *TIBFlatPtr = 0;
|
|---|
| 197 | return;
|
|---|
| 198 | }
|
|---|
| 199 | /******************************************************************************/
|
|---|
| 200 | /******************************************************************************/
|
|---|
| 201 | void SetPDBInstance(HINSTANCE hInstance)
|
|---|
| 202 | {
|
|---|
| 203 | ProcessPDB.hInstance = hInstance;
|
|---|
| 204 | }
|
|---|
| 205 | /******************************************************************************/
|
|---|
| 206 | /******************************************************************************/
|
|---|
| 207 | void WIN32API RestoreOS2TIB()
|
|---|
| 208 | {
|
|---|
| 209 | SHORT orgtibsel;
|
|---|
| 210 | TEB *winteb;
|
|---|
| 211 | THDB *thdb;
|
|---|
| 212 |
|
|---|
| 213 | //If we're running an Odin32 OS/2 application (not converted!), then we
|
|---|
| 214 | //we don't switch FS selectors
|
|---|
| 215 | if(fIsOS2Image) {
|
|---|
| 216 | return;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | winteb = (TEB *)*TIBFlatPtr;
|
|---|
| 220 | if(winteb) {
|
|---|
| 221 | thdb = (THDB *)(winteb+1);
|
|---|
| 222 | orgtibsel = thdb->OrgTIBSel;
|
|---|
| 223 |
|
|---|
| 224 | //Restore our original FS selector
|
|---|
| 225 | SetFS(orgtibsel);
|
|---|
| 226 | }
|
|---|
| 227 | }
|
|---|
| 228 | /******************************************************************************/
|
|---|
| 229 | /******************************************************************************/
|
|---|
| 230 | USHORT WIN32API SetWin32TIB()
|
|---|
| 231 | {
|
|---|
| 232 | SHORT win32tibsel;
|
|---|
| 233 | TEB *winteb;
|
|---|
| 234 | THDB *thdb;
|
|---|
| 235 |
|
|---|
| 236 | //If we're running an Odin32 OS/2 application (not converted!), then we
|
|---|
| 237 | //we don't switch FS selectors
|
|---|
| 238 | if(fIsOS2Image) {
|
|---|
| 239 | return GetFS();
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | winteb = (TEB *)*TIBFlatPtr;
|
|---|
| 243 | if(winteb) {
|
|---|
| 244 | thdb = (THDB *)(winteb+1);
|
|---|
| 245 | win32tibsel = thdb->teb_sel;
|
|---|
| 246 |
|
|---|
| 247 | //Restore our win32 FS selector
|
|---|
| 248 | return SetReturnFS(win32tibsel);
|
|---|
| 249 | }
|
|---|
| 250 | else {
|
|---|
| 251 | //we didn't create this thread, so allocate a selector now
|
|---|
| 252 | //NOTE: Possible memory leak (i.e. DART threads in WINMM)
|
|---|
| 253 | winteb = InitializeTIB();
|
|---|
| 254 | if(winteb == NULL) {
|
|---|
| 255 | DebugInt3();
|
|---|
| 256 | return GetFS();
|
|---|
| 257 | }
|
|---|
| 258 | thdb = (THDB *)(winteb+1);
|
|---|
| 259 | win32tibsel = thdb->teb_sel;
|
|---|
| 260 |
|
|---|
| 261 | //Restore our win32 FS selector
|
|---|
| 262 | return SetReturnFS(win32tibsel);
|
|---|
| 263 | }
|
|---|
| 264 | // nested calls are OK, OS2ToWinCallback for instance
|
|---|
| 265 | //else DebugInt3();
|
|---|
| 266 |
|
|---|
| 267 | return GetFS();
|
|---|
| 268 | }
|
|---|
| 269 | //******************************************************************************
|
|---|
| 270 | //******************************************************************************
|
|---|
| 271 | void _System Win32DllExitList(ULONG reason)
|
|---|
| 272 | {
|
|---|
| 273 | dprintf(("Win32DllExitList %d\n", reason));
|
|---|
| 274 |
|
|---|
| 275 | if(WinExe) {
|
|---|
| 276 | delete(WinExe);
|
|---|
| 277 | WinExe = NULL;
|
|---|
| 278 | }
|
|---|
| 279 | return;
|
|---|
| 280 | }
|
|---|
| 281 | //******************************************************************************
|
|---|
| 282 | //******************************************************************************
|
|---|
| 283 | VOID WIN32API ExitProcess(DWORD exitcode)
|
|---|
| 284 | {
|
|---|
| 285 | dprintf(("KERNEL32: ExitProcess %d\n", exitcode));
|
|---|
| 286 | dprintf(("KERNEL32: ExitProcess FS = %x\n", GetFS()));
|
|---|
| 287 |
|
|---|
| 288 | SetOS2ExceptionChain(-1);
|
|---|
| 289 |
|
|---|
| 290 | Win32DllExitList(0);
|
|---|
| 291 |
|
|---|
| 292 | //Note: Needs to be done after Win32DllExitList (destruction of exe + dll objects)
|
|---|
| 293 | //Flush and delete all open memory mapped files
|
|---|
| 294 | Win32MemMap::deleteAll();
|
|---|
| 295 |
|
|---|
| 296 | //Restore original OS/2 TIB selector
|
|---|
| 297 | DestroyTIB();
|
|---|
| 298 | SetExceptionChain((ULONG)-1);
|
|---|
| 299 |
|
|---|
| 300 | //avoid crashes since win32 & OS/2 exception handler aren't identical
|
|---|
| 301 | //(terminate process generates two exceptions)
|
|---|
| 302 | /* @@@PH 1998/02/12 Added Console Support */
|
|---|
| 303 | if (iConsoleIsActive())
|
|---|
| 304 | iConsoleWaitClose();
|
|---|
| 305 |
|
|---|
| 306 | O32_ExitProcess(exitcode);
|
|---|
| 307 | }
|
|---|
| 308 | //******************************************************************************
|
|---|
| 309 | //******************************************************************************
|
|---|
| 310 | BOOL WIN32API FreeLibrary(HINSTANCE hinstance)
|
|---|
| 311 | {
|
|---|
| 312 | Win32DllBase *winmod;
|
|---|
| 313 | BOOL rc;
|
|---|
| 314 |
|
|---|
| 315 | dprintf(("FreeLibrary"));
|
|---|
| 316 | winmod = Win32DllBase::findModule(hinstance);
|
|---|
| 317 | if(winmod) {
|
|---|
| 318 | winmod->Release();
|
|---|
| 319 | return(TRUE);
|
|---|
| 320 | }
|
|---|
| 321 | dprintf(("KERNEL32: FreeLibrary %s %X\n", OSLibGetDllName(hinstance), hinstance));
|
|---|
| 322 |
|
|---|
| 323 | //TODO: Not thread safe
|
|---|
| 324 | fFreeLibrary = TRUE; //ditch dll
|
|---|
| 325 | rc = O32_FreeLibrary(hinstance);
|
|---|
| 326 | fFreeLibrary = FALSE;
|
|---|
| 327 | dprintf(("FreeLibrary returned %X\n", rc));
|
|---|
| 328 | return(TRUE);
|
|---|
| 329 | }
|
|---|
| 330 | /******************************************************************************/
|
|---|
| 331 | /******************************************************************************/
|
|---|
| 332 | static HINSTANCE iLoadLibraryA(LPCTSTR lpszLibFile, DWORD dwFlags)
|
|---|
| 333 | {
|
|---|
| 334 | char modname[CCHMAXPATH];
|
|---|
| 335 | HINSTANCE hDll;
|
|---|
| 336 | Win32DllBase *module;
|
|---|
| 337 |
|
|---|
| 338 | module = Win32DllBase::findModule((LPSTR)lpszLibFile);
|
|---|
| 339 | if(module) {
|
|---|
| 340 | module->AddRef();
|
|---|
| 341 | return module->getInstanceHandle();
|
|---|
| 342 | }
|
|---|
| 343 |
|
|---|
| 344 | strcpy(modname, lpszLibFile);
|
|---|
| 345 | strupr(modname);
|
|---|
| 346 | //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
|
|---|
| 347 | Win32DllBase::renameDll(modname);
|
|---|
| 348 |
|
|---|
| 349 | hDll = O32_LoadLibrary(modname);
|
|---|
| 350 | dprintf(("KERNEL32: iLoadLibraryA %s returned %X (%d)\n",
|
|---|
| 351 | lpszLibFile,
|
|---|
| 352 | hDll,
|
|---|
| 353 | GetLastError()));
|
|---|
| 354 | if(hDll)
|
|---|
| 355 | {
|
|---|
| 356 | return hDll; //converted dll or win32k took care of it
|
|---|
| 357 | }
|
|---|
| 358 |
|
|---|
| 359 | if(!strstr(modname, ".")) {
|
|---|
| 360 | strcat(modname,".DLL");
|
|---|
| 361 | }
|
|---|
| 362 |
|
|---|
| 363 | if(Win32ImageBase::isPEImage((char *)modname))
|
|---|
| 364 | {
|
|---|
| 365 | module = Win32DllBase::findModule((char *)modname);
|
|---|
| 366 | if(module) {//don't load it again
|
|---|
| 367 | module->AddRef();
|
|---|
| 368 | return module->getInstanceHandle();
|
|---|
| 369 | }
|
|---|
| 370 |
|
|---|
| 371 | Win32PeLdrDll *peldrDll = new Win32PeLdrDll((char *)modname);
|
|---|
| 372 | if(peldrDll == NULL)
|
|---|
| 373 | return(0);
|
|---|
| 374 |
|
|---|
| 375 | peldrDll->init(0);
|
|---|
| 376 | if(peldrDll->getError() != NO_ERROR) {
|
|---|
| 377 | dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile));
|
|---|
| 378 | delete(peldrDll);
|
|---|
| 379 | return(0);
|
|---|
| 380 | }
|
|---|
| 381 | if(dwFlags & DONT_RESOLVE_DLL_REFERENCES) {
|
|---|
| 382 | peldrDll->setNoEntryCalls();
|
|---|
| 383 | }
|
|---|
| 384 |
|
|---|
| 385 | if(peldrDll->attachProcess() == FALSE) {
|
|---|
| 386 | dprintf(("LoadLibary %s failed (::attachProcess)\n", lpszLibFile));
|
|---|
| 387 | delete(peldrDll);
|
|---|
| 388 | return(0);
|
|---|
| 389 | }
|
|---|
| 390 | peldrDll->AddRef();
|
|---|
| 391 | return peldrDll->getInstanceHandle();
|
|---|
| 392 | }
|
|---|
| 393 | else return(0);
|
|---|
| 394 | }
|
|---|
| 395 | //******************************************************************************
|
|---|
| 396 | //******************************************************************************
|
|---|
| 397 | HINSTANCE WIN32API LoadLibraryA(LPCTSTR lpszLibFile)
|
|---|
| 398 | {
|
|---|
| 399 | HINSTANCE hDll;
|
|---|
| 400 |
|
|---|
| 401 | dprintf(("KERNEL32: LoadLibraryA(%s)\n",
|
|---|
| 402 | lpszLibFile));
|
|---|
| 403 | dprintf(("KERNEL32: LoadLibrary %x FS = %x\n", GetCurrentThreadId(), GetFS()));
|
|---|
| 404 |
|
|---|
| 405 | hDll = iLoadLibraryA(lpszLibFile, 0);
|
|---|
| 406 | if (hDll == 0)
|
|---|
| 407 | {
|
|---|
| 408 | char * pszName;
|
|---|
| 409 |
|
|---|
| 410 | // remove path from the image name
|
|---|
| 411 | pszName = strrchr((char *)lpszLibFile,
|
|---|
| 412 | '\\');
|
|---|
| 413 | if (pszName != NULL)
|
|---|
| 414 | {
|
|---|
| 415 | pszName++; // skip backslash
|
|---|
| 416 |
|
|---|
| 417 | // now try again without fully qualified path
|
|---|
| 418 | hDll = iLoadLibraryA(pszName, 0);
|
|---|
| 419 | }
|
|---|
| 420 | }
|
|---|
| 421 |
|
|---|
| 422 | return hDll;
|
|---|
| 423 | }
|
|---|
| 424 | //******************************************************************************
|
|---|
| 425 | //******************************************************************************
|
|---|
| 426 | HINSTANCE WIN32API LoadLibraryExA(LPCTSTR lpszLibFile, HANDLE hFile, DWORD dwFlags)
|
|---|
| 427 | {
|
|---|
| 428 | HINSTANCE hDll;
|
|---|
| 429 |
|
|---|
| 430 | dprintf(("KERNEL32: LoadLibraryExA %s (%X)\n", lpszLibFile, dwFlags));
|
|---|
| 431 | hDll = iLoadLibraryA(lpszLibFile, dwFlags);
|
|---|
| 432 | if (hDll == 0)
|
|---|
| 433 | {
|
|---|
| 434 | char * pszName;
|
|---|
| 435 |
|
|---|
| 436 | // remove path from the image name
|
|---|
| 437 | pszName = strrchr((char *)lpszLibFile,
|
|---|
| 438 | '\\');
|
|---|
| 439 | if (pszName != NULL)
|
|---|
| 440 | {
|
|---|
| 441 | pszName++; // skip backslash
|
|---|
| 442 |
|
|---|
| 443 | // now try again without fully qualified path
|
|---|
| 444 | hDll = iLoadLibraryA(pszName, dwFlags);
|
|---|
| 445 | }
|
|---|
| 446 | }
|
|---|
| 447 |
|
|---|
| 448 | return hDll;
|
|---|
| 449 | }
|
|---|
| 450 | //******************************************************************************
|
|---|
| 451 | //******************************************************************************
|
|---|
| 452 | HINSTANCE WIN32API LoadLibraryW(LPCWSTR lpModule)
|
|---|
| 453 | {
|
|---|
| 454 | char *asciimodule;
|
|---|
| 455 | HINSTANCE rc;
|
|---|
| 456 |
|
|---|
| 457 | asciimodule = UnicodeToAsciiString((LPWSTR)lpModule);
|
|---|
| 458 | dprintf(("KERNEL32: OS2LoadLibraryW %s\n", asciimodule));
|
|---|
| 459 | rc = LoadLibraryA(asciimodule);
|
|---|
| 460 | free(asciimodule);
|
|---|
| 461 | return(rc);
|
|---|
| 462 | }
|
|---|
| 463 | //******************************************************************************
|
|---|
| 464 | //******************************************************************************
|
|---|
| 465 | HINSTANCE WIN32API LoadLibraryExW(LPCWSTR lpModule, HANDLE hFile, DWORD dwFlags)
|
|---|
| 466 | {
|
|---|
| 467 | char *asciimodule;
|
|---|
| 468 | HINSTANCE rc;
|
|---|
| 469 |
|
|---|
| 470 | asciimodule = UnicodeToAsciiString((LPWSTR)lpModule);
|
|---|
| 471 | dprintf(("KERNEL32: OS2LoadLibraryExW %s (%d)\n", asciimodule, dwFlags));
|
|---|
| 472 | rc = LoadLibraryExA(asciimodule, hFile, dwFlags);
|
|---|
| 473 | free(asciimodule);
|
|---|
| 474 | return(rc);
|
|---|
| 475 | }
|
|---|
| 476 | //******************************************************************************
|
|---|
| 477 | //******************************************************************************
|
|---|
| 478 | LPCSTR WIN32API GetCommandLineA()
|
|---|
| 479 | {
|
|---|
| 480 | LPTSTR cmdline = NULL;
|
|---|
| 481 |
|
|---|
| 482 | if(WinExe) {
|
|---|
| 483 | cmdline = WinExe->getCommandLine();
|
|---|
| 484 | }
|
|---|
| 485 | if(cmdline == NULL) //not used for converted exes
|
|---|
| 486 | cmdline = O32_GetCommandLine();
|
|---|
| 487 |
|
|---|
| 488 | dprintf(("KERNEL32: GetCommandLine %s\n", cmdline));
|
|---|
| 489 | dprintf(("KERNEL32: FS = %x\n", GetFS()));
|
|---|
| 490 | return(cmdline);
|
|---|
| 491 | }
|
|---|
| 492 | //******************************************************************************
|
|---|
| 493 | //******************************************************************************
|
|---|
| 494 | LPCWSTR WIN32API GetCommandLineW(void)
|
|---|
| 495 | {
|
|---|
| 496 | static WCHAR *UnicodeCmdLine = NULL;
|
|---|
| 497 | char *asciicmdline = NULL;
|
|---|
| 498 |
|
|---|
| 499 | dprintf(("KERNEL32: FS = %x\n", GetFS()));
|
|---|
| 500 |
|
|---|
| 501 | if(UnicodeCmdLine)
|
|---|
| 502 | return(UnicodeCmdLine); //already called before
|
|---|
| 503 |
|
|---|
| 504 | if(WinExe) {
|
|---|
| 505 | asciicmdline = WinExe->getCommandLine();
|
|---|
| 506 | }
|
|---|
| 507 | if(asciicmdline == NULL) //not used for converted exes
|
|---|
| 508 | asciicmdline = O32_GetCommandLine();
|
|---|
| 509 |
|
|---|
| 510 | if(asciicmdline) {
|
|---|
| 511 | UnicodeCmdLine = (WCHAR *)malloc(strlen(asciicmdline)*2 + 2);
|
|---|
| 512 | AsciiToUnicode(asciicmdline, UnicodeCmdLine);
|
|---|
| 513 | dprintf(("KERNEL32: OS2GetCommandLineW: %s\n", asciicmdline));
|
|---|
| 514 | return(UnicodeCmdLine);
|
|---|
| 515 | }
|
|---|
| 516 | dprintf(("KERNEL32: OS2GetCommandLineW: asciicmdline == NULL\n"));
|
|---|
| 517 | return NULL;
|
|---|
| 518 | }
|
|---|
| 519 | //******************************************************************************
|
|---|
| 520 | //******************************************************************************
|
|---|
| 521 | DWORD WIN32API GetModuleFileNameA(HMODULE hinstModule, LPTSTR lpszPath, DWORD cchPath)
|
|---|
| 522 | {
|
|---|
| 523 | DWORD rc;
|
|---|
| 524 | Win32ImageBase *module;
|
|---|
| 525 | char *fpath = NULL;
|
|---|
| 526 |
|
|---|
| 527 | dprintf(("GetModuleFileName %X", hinstModule));
|
|---|
| 528 | if(hinstModule == 0 || hinstModule == -1 || (WinExe && hinstModule == WinExe->getInstanceHandle())) {
|
|---|
| 529 | module = (Win32ImageBase *)WinExe;
|
|---|
| 530 | }
|
|---|
| 531 | else {
|
|---|
| 532 | module = (Win32ImageBase *)Win32DllBase::findModule(hinstModule);
|
|---|
| 533 | }
|
|---|
| 534 |
|
|---|
| 535 | if(module) {
|
|---|
| 536 | fpath = module->getFullPath();
|
|---|
| 537 | }
|
|---|
| 538 | if(fpath) {
|
|---|
| 539 | //SvL: 13-9-98: +1
|
|---|
| 540 | rc = min(strlen(fpath)+1, cchPath);
|
|---|
| 541 | strncpy(lpszPath, fpath, rc);
|
|---|
| 542 | }
|
|---|
| 543 | else rc = O32_GetModuleFileName(hinstModule, lpszPath, cchPath);
|
|---|
| 544 |
|
|---|
| 545 | if(rc) {
|
|---|
| 546 | dprintf(("KERNEL32: GetModuleFileName %s %d\n", lpszPath, hinstModule));
|
|---|
| 547 | }
|
|---|
| 548 | return(rc);
|
|---|
| 549 | }
|
|---|
| 550 | //******************************************************************************
|
|---|
| 551 | //******************************************************************************
|
|---|
| 552 | DWORD WIN32API GetModuleFileNameW(HMODULE hModule, LPWSTR lpFileName, DWORD nSize)
|
|---|
| 553 | {
|
|---|
| 554 | char *asciifilename = (char *)malloc(nSize+1);
|
|---|
| 555 | DWORD rc;
|
|---|
| 556 |
|
|---|
| 557 | dprintf(("KERNEL32: OSLibGetModuleFileNameW\n"));
|
|---|
| 558 | rc = GetModuleFileNameA(hModule, asciifilename, nSize);
|
|---|
| 559 | if(rc) AsciiToUnicode(asciifilename, lpFileName);
|
|---|
| 560 | free(asciifilename);
|
|---|
| 561 | return(rc);
|
|---|
| 562 | }
|
|---|
| 563 | //******************************************************************************
|
|---|
| 564 | //NOTE: GetModuleHandleA does NOT support files with multiple dots (i.e.
|
|---|
| 565 | // very.weird.exe)
|
|---|
| 566 | //******************************************************************************
|
|---|
| 567 | HANDLE WIN32API GetModuleHandleA(LPCTSTR lpszModule)
|
|---|
| 568 | {
|
|---|
| 569 | HANDLE hMod;
|
|---|
| 570 | Win32DllBase *windll;
|
|---|
| 571 | char szModule[CCHMAXPATH];
|
|---|
| 572 | BOOL fDllModule = FALSE;
|
|---|
| 573 |
|
|---|
| 574 | if(lpszModule == NULL) {
|
|---|
| 575 | if(WinExe)
|
|---|
| 576 | hMod = WinExe->getInstanceHandle();
|
|---|
| 577 | else hMod = -1;
|
|---|
| 578 | }
|
|---|
| 579 | else {
|
|---|
| 580 | strcpy(szModule, OSLibStripPath((char *)lpszModule));
|
|---|
| 581 | strupr(szModule);
|
|---|
| 582 | if(strstr(szModule, ".DLL")) {
|
|---|
| 583 | fDllModule = TRUE;
|
|---|
| 584 | }
|
|---|
| 585 | else {
|
|---|
| 586 | if(!strstr(szModule, ".")) {
|
|---|
| 587 | //if there's no extension or trainling dot, we
|
|---|
| 588 | //assume it's a dll (see Win32 SDK docs)
|
|---|
| 589 | fDllModule = TRUE;
|
|---|
| 590 | }
|
|---|
| 591 | }
|
|---|
| 592 | char *dot = strstr(szModule, ".");
|
|---|
| 593 | if(dot)
|
|---|
| 594 | *dot = 0;
|
|---|
| 595 |
|
|---|
| 596 | if(!fDllModule && WinExe && !strcmpi(szModule, WinExe->getModuleName())) {
|
|---|
| 597 | hMod = WinExe->getInstanceHandle();
|
|---|
| 598 | }
|
|---|
| 599 | else {
|
|---|
| 600 | windll = Win32DllBase::findModule(szModule);
|
|---|
| 601 | if(windll) {
|
|---|
| 602 | hMod = windll->getInstanceHandle();
|
|---|
| 603 | }
|
|---|
| 604 | else hMod = OSLibiGetModuleHandleA((char *)lpszModule);
|
|---|
| 605 | }
|
|---|
| 606 | }
|
|---|
| 607 |
|
|---|
| 608 | eprintf(("KERNEL32: GetModuleHandle %s returned %X\n", lpszModule, hMod));
|
|---|
| 609 | return(hMod);
|
|---|
| 610 | }
|
|---|
| 611 | //******************************************************************************
|
|---|
| 612 | //******************************************************************************
|
|---|
| 613 | HMODULE WIN32API GetModuleHandleW(LPCWSTR arg1)
|
|---|
| 614 | {
|
|---|
| 615 | HMODULE rc;
|
|---|
| 616 | char *astring;
|
|---|
| 617 |
|
|---|
| 618 | astring = UnicodeToAsciiString((LPWSTR)arg1);
|
|---|
| 619 | rc = GetModuleHandleA(astring);
|
|---|
| 620 | dprintf(("KERNEL32: OS2GetModuleHandleW %s returned %X\n", astring, rc));
|
|---|
| 621 | FreeAsciiString(astring);
|
|---|
| 622 | return(rc);
|
|---|
| 623 | }
|
|---|
| 624 | //******************************************************************************
|
|---|
| 625 | //******************************************************************************
|
|---|
| 626 | BOOL WINAPI CreateProcessA( LPCSTR lpApplicationName, LPSTR lpCommandLine,
|
|---|
| 627 | LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
|---|
| 628 | LPSECURITY_ATTRIBUTES lpThreadAttributes,
|
|---|
| 629 | BOOL bInheritHandles, DWORD dwCreationFlags,
|
|---|
| 630 | LPVOID lpEnvironment, LPCSTR lpCurrentDirectory,
|
|---|
| 631 | LPSTARTUPINFOA lpStartupInfo,
|
|---|
| 632 | LPPROCESS_INFORMATION lpProcessInfo )
|
|---|
| 633 | {
|
|---|
| 634 | BOOL rc;
|
|---|
| 635 | char *cmdline;
|
|---|
| 636 | BOOL fAllocStr = FALSE;
|
|---|
| 637 |
|
|---|
| 638 | dprintf(("KERNEL32: CreateProcessA %s cline:%s inherit:%d cFlags:%x Env:%x CurDir:%s StartupFlags:%x\n",
|
|---|
| 639 | lpApplicationName, lpCommandLine, bInheritHandles, dwCreationFlags,
|
|---|
| 640 | lpEnvironment, lpCurrentDirectory, lpStartupInfo));
|
|---|
| 641 |
|
|---|
| 642 | if(O32_CreateProcess(lpApplicationName, lpCommandLine, lpProcessAttributes,
|
|---|
| 643 | lpThreadAttributes, bInheritHandles, dwCreationFlags,
|
|---|
| 644 | lpEnvironment, lpCurrentDirectory, lpStartupInfo,
|
|---|
| 645 | lpProcessInfo) == TRUE)
|
|---|
| 646 | return(TRUE);
|
|---|
| 647 |
|
|---|
| 648 | //probably a win32 exe, so run it in the pe loader
|
|---|
| 649 | if(lpApplicationName) {
|
|---|
| 650 | if(lpCommandLine) {
|
|---|
| 651 | cmdline = (char *)malloc(strlen(lpApplicationName)+strlen(lpCommandLine) + 16);
|
|---|
| 652 | sprintf(cmdline, "PE.EXE %s %s", lpApplicationName, lpCommandLine);
|
|---|
| 653 | fAllocStr = TRUE;
|
|---|
| 654 | }
|
|---|
| 655 | else {
|
|---|
| 656 | cmdline = (char *)malloc(strlen(lpApplicationName) + 16);
|
|---|
| 657 | sprintf(cmdline, "PE.EXE %s", lpApplicationName);
|
|---|
| 658 | fAllocStr = TRUE;
|
|---|
| 659 | }
|
|---|
| 660 | }
|
|---|
| 661 | else {
|
|---|
| 662 | cmdline = (char *)malloc(strlen(lpCommandLine) + 16);
|
|---|
| 663 | sprintf(cmdline, "PE.EXE %s", lpCommandLine);
|
|---|
| 664 | fAllocStr = TRUE;
|
|---|
| 665 | }
|
|---|
| 666 | dprintf(("KERNEL32: CreateProcess %s\n", cmdline));
|
|---|
| 667 | rc = O32_CreateProcess("PE.EXE", (LPCSTR)cmdline,lpProcessAttributes,
|
|---|
| 668 | lpThreadAttributes, bInheritHandles, dwCreationFlags,
|
|---|
| 669 | lpEnvironment, lpCurrentDirectory, lpStartupInfo,
|
|---|
| 670 | lpProcessInfo);
|
|---|
| 671 | if(fAllocStr)
|
|---|
| 672 | free(cmdline);
|
|---|
| 673 |
|
|---|
| 674 | if(lpProcessInfo)
|
|---|
| 675 | dprintf(("KERNEL32: CreateProcess returned %d hPro:%x hThr:%x pid:%x tid:%x\n",
|
|---|
| 676 | rc, lpProcessInfo->hProcess, lpProcessInfo->hThread,
|
|---|
| 677 | lpProcessInfo->dwProcessId,lpProcessInfo->dwThreadId));
|
|---|
| 678 | else
|
|---|
| 679 | dprintf(("KERNEL32: CreateProcess returned %d\n", rc));
|
|---|
| 680 | return(rc);
|
|---|
| 681 | }
|
|---|
| 682 | //******************************************************************************
|
|---|
| 683 | //******************************************************************************
|
|---|
| 684 | BOOL WIN32API CreateProcessW(LPCWSTR arg1, LPWSTR arg2,
|
|---|
| 685 | PSECURITY_ATTRIBUTES arg3,
|
|---|
| 686 | PSECURITY_ATTRIBUTES arg4,
|
|---|
| 687 | BOOL arg5, DWORD arg6, PVOID arg7,
|
|---|
| 688 | LPCWSTR arg8, LPSTARTUPINFOW arg9,
|
|---|
| 689 | LPPROCESS_INFORMATION arg10)
|
|---|
| 690 | {
|
|---|
| 691 | BOOL rc;
|
|---|
| 692 | char *astring1, *astring2, *astring3;
|
|---|
| 693 |
|
|---|
| 694 | dprintf(("KERNEL32: OS2CreateProcessW DOESN't WORK"));
|
|---|
| 695 | astring1 = UnicodeToAsciiString((LPWSTR)arg1);
|
|---|
| 696 | astring2 = UnicodeToAsciiString(arg2);
|
|---|
| 697 | astring3 = UnicodeToAsciiString((LPWSTR)arg8);
|
|---|
| 698 | // NOTE: This will not work as is (needs UNICODE support)
|
|---|
| 699 | rc = CreateProcessA(astring1, astring2, arg3, arg4, arg5, arg6, arg7,
|
|---|
| 700 | astring3, (LPSTARTUPINFOA)arg9, arg10);
|
|---|
| 701 | FreeAsciiString(astring3);
|
|---|
| 702 | FreeAsciiString(astring2);
|
|---|
| 703 | FreeAsciiString(astring1);
|
|---|
| 704 | return(rc);
|
|---|
| 705 | }
|
|---|
| 706 | //******************************************************************************
|
|---|
| 707 | //******************************************************************************
|
|---|
| 708 | HINSTANCE WIN32API WinExec(LPCSTR lpCmdLine, UINT nCmdShow)
|
|---|
| 709 | {
|
|---|
| 710 | STARTUPINFOA startinfo = {0};
|
|---|
| 711 | PROCESS_INFORMATION procinfo;
|
|---|
| 712 |
|
|---|
| 713 | dprintf(("KERNEL32: WinExec %s\n", lpCmdLine));
|
|---|
| 714 | startinfo.dwFlags = nCmdShow;
|
|---|
| 715 | if(CreateProcessA(NULL, (LPSTR)lpCmdLine, NULL, NULL, FALSE, 0, NULL, NULL,
|
|---|
| 716 | &startinfo, &procinfo) == FALSE)
|
|---|
| 717 | {
|
|---|
| 718 | return 0;
|
|---|
| 719 | }
|
|---|
| 720 | return procinfo.hProcess; //correct?
|
|---|
| 721 | }
|
|---|
| 722 | //******************************************************************************
|
|---|
| 723 | //******************************************************************************
|
|---|
| 724 | FARPROC WIN32API GetProcAddress(HMODULE hModule, LPCSTR lpszProc)
|
|---|
| 725 | {
|
|---|
| 726 | Win32ImageBase *winmod;
|
|---|
| 727 | FARPROC proc;
|
|---|
| 728 | ULONG ulAPIOrdinal;
|
|---|
| 729 |
|
|---|
| 730 | if(hModule == 0 || hModule == -1 || (WinExe && hModule == WinExe->getInstanceHandle())) {
|
|---|
| 731 | winmod = WinExe;
|
|---|
| 732 | }
|
|---|
| 733 | else winmod = (Win32ImageBase *)Win32DllBase::findModule((HINSTANCE)hModule);
|
|---|
| 734 |
|
|---|
| 735 | if(winmod) {
|
|---|
| 736 | ulAPIOrdinal = (ULONG)lpszProc;
|
|---|
| 737 | if (ulAPIOrdinal <= 0x0000FFFF) {
|
|---|
| 738 | proc = (FARPROC)winmod->getApi((int)ulAPIOrdinal);
|
|---|
| 739 | }
|
|---|
| 740 | else proc = (FARPROC)winmod->getApi((char *)lpszProc);
|
|---|
| 741 | if(proc == 0) {
|
|---|
| 742 | SetLastError(ERROR_PROC_NOT_FOUND);
|
|---|
| 743 | }
|
|---|
| 744 | return proc;
|
|---|
| 745 | }
|
|---|
| 746 | proc = O32_GetProcAddress(hModule, lpszProc);
|
|---|
| 747 | if(HIWORD(lpszProc))
|
|---|
| 748 | dprintf(("KERNEL32: GetProcAddress %s from %X returned %X\n", lpszProc, hModule, proc));
|
|---|
| 749 | else dprintf(("KERNEL32: GetProcAddress %x from %X returned %X\n", lpszProc, hModule, proc));
|
|---|
| 750 | return(proc);
|
|---|
| 751 | }
|
|---|
| 752 | //******************************************************************************
|
|---|
| 753 | //Retrieve the version
|
|---|
| 754 | //******************************************************************************
|
|---|
| 755 | BOOL SYSTEM GetVersionStruct(char *lpszModName, char *verstruct, ULONG bufLength)
|
|---|
| 756 | {
|
|---|
| 757 | Win32ImageBase *winimage;
|
|---|
| 758 | Win32PeLdrRsrcImg *rsrcimg;
|
|---|
| 759 |
|
|---|
| 760 | dprintf(("GetVersionStruct of module %s", lpszModName));
|
|---|
| 761 | if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) {
|
|---|
| 762 | winimage = (Win32ImageBase *)WinExe;
|
|---|
| 763 | }
|
|---|
| 764 | else {
|
|---|
| 765 | winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
|
|---|
| 766 | if(winimage == NULL)
|
|---|
| 767 | {
|
|---|
| 768 | char modname[CCHMAXPATH];
|
|---|
| 769 |
|
|---|
| 770 | strcpy(modname, lpszModName);
|
|---|
| 771 | //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
|
|---|
| 772 | Win32DllBase::renameDll(modname);
|
|---|
| 773 |
|
|---|
| 774 | if(Win32ImageBase::isPEImage(modname) == FALSE)
|
|---|
| 775 | {
|
|---|
| 776 | HINSTANCE hInstance;
|
|---|
| 777 |
|
|---|
| 778 | //must be an LX dll, just load it (app will probably load it anyway)
|
|---|
| 779 | hInstance = LoadLibraryA(modname);
|
|---|
| 780 | if(hInstance == 0)
|
|---|
| 781 | return 0;
|
|---|
| 782 | winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
|
|---|
| 783 | if(winimage) {
|
|---|
| 784 | return winimage->getVersionStruct(verstruct, bufLength);
|
|---|
| 785 | }
|
|---|
| 786 | return 0;
|
|---|
| 787 | }
|
|---|
| 788 | //SvL: Try to load it
|
|---|
| 789 | rsrcimg = new Win32PeLdrRsrcImg(modname);
|
|---|
| 790 | if(rsrcimg == NULL)
|
|---|
| 791 | return 0;
|
|---|
| 792 |
|
|---|
| 793 | rsrcimg->init(0);
|
|---|
| 794 | if(rsrcimg->getError() != NO_ERROR)
|
|---|
| 795 | {
|
|---|
| 796 | dprintf(("GetVersionStruct can't load %s\n", modname));
|
|---|
| 797 | delete rsrcimg;
|
|---|
| 798 | return(FALSE);
|
|---|
| 799 | }
|
|---|
| 800 | BOOL rc = rsrcimg->getVersionStruct(verstruct, bufLength);
|
|---|
| 801 | delete rsrcimg;
|
|---|
| 802 | return rc;
|
|---|
| 803 | }
|
|---|
| 804 | }
|
|---|
| 805 | return winimage->getVersionStruct(verstruct, bufLength);
|
|---|
| 806 | }
|
|---|
| 807 | //******************************************************************************
|
|---|
| 808 | //******************************************************************************
|
|---|
| 809 | ULONG SYSTEM GetVersionSize(char *lpszModName)
|
|---|
| 810 | {
|
|---|
| 811 | Win32ImageBase *winimage;
|
|---|
| 812 | Win32PeLdrRsrcImg *rsrcimg;
|
|---|
| 813 |
|
|---|
| 814 | dprintf(("GetVersionSize of %s\n", lpszModName));
|
|---|
| 815 |
|
|---|
| 816 | if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) {
|
|---|
| 817 | winimage = (Win32ImageBase *)WinExe;
|
|---|
| 818 | }
|
|---|
| 819 | else {
|
|---|
| 820 | winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
|
|---|
| 821 | if(winimage == NULL)
|
|---|
| 822 | {
|
|---|
| 823 | char modname[CCHMAXPATH];
|
|---|
| 824 |
|
|---|
| 825 | strcpy(modname, lpszModName);
|
|---|
| 826 | //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
|
|---|
| 827 | Win32DllBase::renameDll(modname);
|
|---|
| 828 |
|
|---|
| 829 | if(Win32ImageBase::isPEImage(modname) == FALSE)
|
|---|
| 830 | {
|
|---|
| 831 | HINSTANCE hInstance;
|
|---|
| 832 |
|
|---|
| 833 | //must be an LX dll, just load it (app will probably load it anyway)
|
|---|
| 834 | hInstance = LoadLibraryA(modname);
|
|---|
| 835 | if(hInstance == 0)
|
|---|
| 836 | return 0;
|
|---|
| 837 | winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
|
|---|
| 838 | if(winimage) {
|
|---|
| 839 | return winimage->getVersionSize();
|
|---|
| 840 | }
|
|---|
| 841 | return 0;
|
|---|
| 842 | }
|
|---|
| 843 |
|
|---|
| 844 | //SvL: Try to load it
|
|---|
| 845 | rsrcimg = new Win32PeLdrRsrcImg(modname);
|
|---|
| 846 | if(rsrcimg == NULL)
|
|---|
| 847 | return 0;
|
|---|
| 848 |
|
|---|
| 849 | rsrcimg->init(0);
|
|---|
| 850 | if(rsrcimg->getError() != NO_ERROR)
|
|---|
| 851 | {
|
|---|
| 852 | dprintf(("GetVersionSize can't load %s\n", modname));
|
|---|
| 853 | delete rsrcimg;
|
|---|
| 854 | return(FALSE);
|
|---|
| 855 | }
|
|---|
| 856 | int size = rsrcimg->getVersionSize();
|
|---|
| 857 | delete rsrcimg;
|
|---|
| 858 | return size;
|
|---|
| 859 | }
|
|---|
| 860 | }
|
|---|
| 861 | return winimage->getVersionSize();
|
|---|
| 862 | }
|
|---|
| 863 | //******************************************************************************
|
|---|
| 864 | //TODO:What does this do exactly??
|
|---|
| 865 | //******************************************************************************
|
|---|
| 866 | ODINFUNCTION1(BOOL,DisableThreadLibraryCalls,HMODULE,hModule)
|
|---|
| 867 | {
|
|---|
| 868 | Win32DllBase *winmod;
|
|---|
| 869 | FARPROC proc;
|
|---|
| 870 | ULONG ulAPIOrdinal;
|
|---|
| 871 |
|
|---|
| 872 | winmod = Win32DllBase::findModule((HINSTANCE)hModule);
|
|---|
| 873 | if(winmod)
|
|---|
| 874 | {
|
|---|
| 875 | // don't call ATTACH/DETACH thread functions in DLL
|
|---|
| 876 | winmod->setThreadLibraryCalls(FALSE);
|
|---|
| 877 | return TRUE;
|
|---|
| 878 | }
|
|---|
| 879 | else
|
|---|
| 880 | {
|
|---|
| 881 | // raise error condition
|
|---|
| 882 | SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 883 | return FALSE;
|
|---|
| 884 | }
|
|---|
| 885 | }
|
|---|
| 886 | //******************************************************************************
|
|---|
| 887 | //******************************************************************************
|
|---|