Commit ae719405 authored by Alexandre Julliard's avatar Alexandre Julliard

PE_LoadImage: removed version parameter, set last error correctly.

parent d27624be
...@@ -38,7 +38,7 @@ extern DWORD PE_SizeofResource(HMODULE,HRSRC); ...@@ -38,7 +38,7 @@ extern DWORD PE_SizeofResource(HMODULE,HRSRC);
extern struct _wine_modref *PE_LoadLibraryExA(LPCSTR, DWORD); extern struct _wine_modref *PE_LoadLibraryExA(LPCSTR, DWORD);
extern void PE_UnloadLibrary(struct _wine_modref *); extern void PE_UnloadLibrary(struct _wine_modref *);
extern HGLOBAL PE_LoadResource(struct _wine_modref *wm,HRSRC); extern HGLOBAL PE_LoadResource(struct _wine_modref *wm,HRSRC);
extern HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, WORD *version ); extern HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename );
extern struct _wine_modref *PE_CreateModule( HMODULE hModule, LPCSTR filename, extern struct _wine_modref *PE_CreateModule( HMODULE hModule, LPCSTR filename,
DWORD flags, BOOL builtin ); DWORD flags, BOOL builtin );
extern BOOL PE_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmd_line, LPCSTR env, extern BOOL PE_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmd_line, LPCSTR env,
......
...@@ -468,7 +468,7 @@ static void do_relocations( unsigned int load_addr, IMAGE_BASE_RELOCATION *r ) ...@@ -468,7 +468,7 @@ static void do_relocations( unsigned int load_addr, IMAGE_BASE_RELOCATION *r )
* BUT we have to map the whole image anyway, for Win32 programs sometimes * BUT we have to map the whole image anyway, for Win32 programs sometimes
* want to access them. (HMODULE32 point to the start of it) * want to access them. (HMODULE32 point to the start of it)
*/ */
HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, WORD *version ) HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename )
{ {
HMODULE hModule; HMODULE hModule;
HANDLE mapping; HANDLE mapping;
...@@ -505,6 +505,7 @@ HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, WORD *version ) ...@@ -505,6 +505,7 @@ HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, WORD *version )
if ( *(WORD*)hModule !=IMAGE_DOS_SIGNATURE) if ( *(WORD*)hModule !=IMAGE_DOS_SIGNATURE)
{ {
WARN("%s image doesn't have DOS signature, but 0x%04x\n", filename,*(WORD*)hModule); WARN("%s image doesn't have DOS signature, but 0x%04x\n", filename,*(WORD*)hModule);
SetLastError( ERROR_BAD_EXE_FORMAT );
goto error; goto error;
} }
...@@ -514,6 +515,7 @@ HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, WORD *version ) ...@@ -514,6 +515,7 @@ HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, WORD *version )
if ( nt->Signature != IMAGE_NT_SIGNATURE ) if ( nt->Signature != IMAGE_NT_SIGNATURE )
{ {
WARN("%s image doesn't have PE signature, but 0x%08lx\n", filename, nt->Signature ); WARN("%s image doesn't have PE signature, but 0x%08lx\n", filename, nt->Signature );
SetLastError( ERROR_BAD_EXE_FORMAT );
goto error; goto error;
} }
...@@ -533,6 +535,7 @@ HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, WORD *version ) ...@@ -533,6 +535,7 @@ HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, WORD *version )
default: MESSAGE("Unknown-%04x", nt->FileHeader.Machine); break; default: MESSAGE("Unknown-%04x", nt->FileHeader.Machine); break;
} }
MESSAGE(")\n"); MESSAGE(")\n");
SetLastError( ERROR_BAD_EXE_FORMAT );
goto error; goto error;
} }
...@@ -555,6 +558,7 @@ HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, WORD *version ) ...@@ -555,6 +558,7 @@ HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, WORD *version )
ERR("PE module is too small (header: %d, filesize: %d), " ERR("PE module is too small (header: %d, filesize: %d), "
"probably truncated download?\n", "probably truncated download?\n",
rawsize, file_size ); rawsize, file_size );
SetLastError( ERROR_BAD_EXE_FORMAT );
goto error; goto error;
} }
...@@ -616,6 +620,7 @@ HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, WORD *version ) ...@@ -616,6 +620,7 @@ HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, WORD *version )
filename, filename,
(nt->FileHeader.Characteristics&IMAGE_FILE_RELOCS_STRIPPED)? (nt->FileHeader.Characteristics&IMAGE_FILE_RELOCS_STRIPPED)?
"stripped during link" : "unknown reason" ); "stripped during link" : "unknown reason" );
SetLastError( ERROR_BAD_EXE_FORMAT );
goto error; goto error;
} }
...@@ -699,10 +704,6 @@ HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, WORD *version ) ...@@ -699,10 +704,6 @@ HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, WORD *version )
if ( reloc ) if ( reloc )
do_relocations( load_addr, (IMAGE_BASE_RELOCATION *)RVA(reloc) ); do_relocations( load_addr, (IMAGE_BASE_RELOCATION *)RVA(reloc) );
/* Get expected OS / Subsystem version */
*version = ( (nt->OptionalHeader.MajorSubsystemVersion & 0xff) << 8 )
| (nt->OptionalHeader.MinorSubsystemVersion & 0xff);
/* We don't need the orignal mapping any more */ /* We don't need the orignal mapping any more */
UnmapViewOfFile( (LPVOID)hModule ); UnmapViewOfFile( (LPVOID)hModule );
return (HMODULE)load_addr; return (HMODULE)load_addr;
...@@ -919,7 +920,6 @@ WINE_MODREF *PE_LoadLibraryExA (LPCSTR name, DWORD flags) ...@@ -919,7 +920,6 @@ WINE_MODREF *PE_LoadLibraryExA (LPCSTR name, DWORD flags)
WINE_MODREF *wm; WINE_MODREF *wm;
char filename[256]; char filename[256];
HANDLE hFile; HANDLE hFile;
WORD version = 0;
/* Search for and open PE file */ /* Search for and open PE file */
if ( SearchPathA( NULL, name, ".DLL", if ( SearchPathA( NULL, name, ".DLL",
...@@ -930,11 +930,10 @@ WINE_MODREF *PE_LoadLibraryExA (LPCSTR name, DWORD flags) ...@@ -930,11 +930,10 @@ WINE_MODREF *PE_LoadLibraryExA (LPCSTR name, DWORD flags)
if ( hFile == INVALID_HANDLE_VALUE ) return NULL; if ( hFile == INVALID_HANDLE_VALUE ) return NULL;
/* Load PE module */ /* Load PE module */
hModule32 = PE_LoadImage( hFile, filename, &version ); hModule32 = PE_LoadImage( hFile, filename );
if (!hModule32) if (!hModule32)
{ {
CloseHandle( hFile ); CloseHandle( hFile );
SetLastError( ERROR_OUTOFMEMORY ); /* Not entirely right, but good enough */
return NULL; return NULL;
} }
...@@ -993,13 +992,12 @@ BOOL PE_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmd_line, LPCSTR en ...@@ -993,13 +992,12 @@ BOOL PE_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmd_line, LPCSTR en
BOOL inherit, DWORD flags, LPSTARTUPINFOA startup, BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
LPPROCESS_INFORMATION info ) LPPROCESS_INFORMATION info )
{ {
WORD version = 0;
HMODULE16 hModule16; HMODULE16 hModule16;
HMODULE hModule32; HMODULE hModule32;
NE_MODULE *pModule; NE_MODULE *pModule;
/* Load file */ /* Load file */
if ( (hModule32 = PE_LoadImage( hFile, filename, &version )) < 32 ) if ( (hModule32 = PE_LoadImage( hFile, filename )) < 32 )
{ {
SetLastError( hModule32 ); SetLastError( hModule32 );
return FALSE; return FALSE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment