/* create the fake dll destination file */ static HANDLE create_dest_file( const WCHAR *name ) { /* first check for an existing file */ HANDLE h = CreateFileW( name, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL ); if (h != INVALID_HANDLE_VALUE) { if (!is_fake_dll( h )) { TRACE( "%s is not a fake dll, not overwriting it\n", debugstr_w(name) ); CloseHandle( h ); return 0; } /* truncate the file */ SetFilePointer( h, 0, NULL, FILE_BEGIN ); SetEndOfFile( h ); } else { if (GetLastError() == ERROR_PATH_NOT_FOUND) create_directories( name ); h = CreateFileW( name, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL ); if (h == INVALID_HANDLE_VALUE) ERR( "failed to create %s (error=%u)\n", debugstr_w(name), GetLastError() ); } return h; }
/*********************************************************************** * create_fake_dll */ BOOL create_fake_dll( const WCHAR *name, const WCHAR *source ) { HANDLE h; HMODULE module; BOOL ret; /* check for empty name which means to only create the directory */ if (name[strlenW(name) - 1] == '\\') { create_directories( name ); return TRUE; } /* first check for an existing file */ h = CreateFileW( name, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL ); if (h != INVALID_HANDLE_VALUE) { if (!is_fake_dll( h )) { TRACE( "%s is not a fake dll, not overwriting it\n", debugstr_w(name) ); CloseHandle( h ); return TRUE; } /* truncate the file */ SetFilePointer( h, 0, NULL, FILE_BEGIN ); SetEndOfFile( h ); } else { if (GetLastError() == ERROR_PATH_NOT_FOUND) create_directories( name ); h = CreateFileW( name, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL ); if (h == INVALID_HANDLE_VALUE) { ERR( "failed to create %s (error=%u)\n", debugstr_w(name), GetLastError() ); return FALSE; } } module = LoadLibraryW( source ); ret = build_fake_dll( h, module ); CloseHandle( h ); if (module) FreeLibrary( module ); if (!ret) DeleteFileW( name ); return ret; }
/*********************************************************************** * create_fake_dll */ BOOL create_fake_dll( const WCHAR *name, const WCHAR *source ) { HANDLE h; HMODULE module; BOOL ret; /* first check for an existing file */ h = CreateFileW( name, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL ); if (h != INVALID_HANDLE_VALUE) { if (!is_fake_dll( h )) { TRACE( "%s is not a fake dll, not overwriting it\n", debugstr_w(name) ); CloseHandle( h ); return TRUE; } /* truncate the file */ SetFilePointer( h, 0, NULL, FILE_BEGIN ); SetEndOfFile( h ); } else { h = CreateFileW( name, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL ); if (h == INVALID_HANDLE_VALUE) { WARN( "failed to create %s\n", debugstr_w(name) ); return FALSE; } } module = LoadLibraryW( source ); ret = build_fake_dll( h, module ); CloseHandle( h ); if (module) FreeLibrary( module ); if (!ret) DeleteFileW( name ); return ret; }