Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Subject: [PATCH] Fix battle.net
- ---
- dlls/ntdll/unix/loader.c | 12 ++++++++++++
- dlls/ntdll/unix/unix_private.h | 2 ++
- dlls/ntdll/unix/virtual.c | 18 ++++++++++++++++--
- 3 files changed, 30 insertions(+), 2 deletions(-)
- diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c
- index 803d80792136..8a1d96a0756f 100644
- --- a/dlls/ntdll/unix/loader.c
- +++ b/dlls/ntdll/unix/loader.c
- @@ -1797,6 +1797,17 @@ static ULONG_PTR get_image_address(void)
- return 0;
- }
- +BOOL simulate_writecopy;
- +
- +static void hacks_init(void){
- + const char *env_str;
- + env_str = getenv("WINE_SIMULATE_WRITECOPY");
- + if (env_str) simulate_writecopy = atoi(env_str);
- + else if (main_argc > 1 && (strstr(main_argv[1], "Battle.net.exe")))
- + simulate_writecopy = TRUE;
- +
- +}
- +
- /***********************************************************************
- * start_main_thread
- */
- @@ -1808,6 +1819,7 @@ static void start_main_thread(void)
- signal_alloc_thread( teb );
- dbg_init();
- startup_info_size = server_init_process();
- + hacks_init();
- virtual_map_user_shared_data();
- init_cpu_info();
- init_files();
- diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h
- index 07f2724eac70..3ec5ad9cfd35 100644
- --- a/dlls/ntdll/unix/unix_private.h
- +++ b/dlls/ntdll/unix/unix_private.h
- @@ -176,6 +176,8 @@ extern SYSTEM_CPU_INFORMATION cpu_info;
- extern struct ldt_copy __wine_ldt_copy;
- #endif
- +extern BOOL simulate_writecopy;
- +
- extern void init_environment(void);
- extern void init_startup_info(void);
- extern void *create_startup_info( const UNICODE_STRING *nt_image, ULONG process_flags,
- diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
- index 5bdeef4c1bc2..65b2fdc704d7 100644
- --- a/dlls/ntdll/unix/virtual.c
- +++ b/dlls/ntdll/unix/virtual.c
- @@ -122,6 +122,7 @@ struct file_view
- #define VPROT_GUARD 0x10
- #define VPROT_COMMITTED 0x20
- #define VPROT_WRITEWATCH 0x40
- +#define VPROT_COPIED 0x80
- /* per-mapping protection flags */
- #define VPROT_ARM64EC 0x0100 /* view may contain ARM64EC code */
- #define VPROT_SYSTEM 0x0200 /* system view (underlying mmap not under our control) */
- @@ -1092,7 +1093,8 @@ static const char *get_prot_str( BYTE prot )
- buffer[0] = (prot & VPROT_COMMITTED) ? 'c' : '-';
- buffer[1] = (prot & VPROT_GUARD) ? 'g' : ((prot & VPROT_WRITEWATCH) ? 'H' : '-');
- buffer[2] = (prot & VPROT_READ) ? 'r' : '-';
- - buffer[3] = (prot & VPROT_WRITECOPY) ? 'W' : ((prot & VPROT_WRITE) ? 'w' : '-');
- + buffer[3] = (prot & VPROT_WRITECOPY) ? (prot & VPROT_COPIED ? 'w' : 'W')
- + : ((prot & VPROT_WRITE) ? 'w' : '-');
- buffer[4] = (prot & VPROT_EXEC) ? 'x' : '-';
- buffer[5] = 0;
- return buffer;
- @@ -1621,7 +1623,10 @@ static NTSTATUS create_view( struct file_view **view_ret, void *base, size_t siz
- */
- static DWORD get_win32_prot( BYTE vprot, unsigned int map_prot )
- {
- - DWORD ret = VIRTUAL_Win32Flags[vprot & 0x0f];
- + DWORD ret;
- + if ((vprot & (VPROT_COPIED | VPROT_WRITECOPY)) == (VPROT_COPIED | VPROT_WRITECOPY))
- + vprot = (vprot & ~VPROT_WRITECOPY) | VPROT_WRITE;
- + ret = VIRTUAL_Win32Flags[vprot & 0x0f];
- if (vprot & VPROT_GUARD) ret |= PAGE_GUARD;
- if (map_prot & SEC_NOCACHE) ret |= PAGE_NOCACHE;
- return ret;
- @@ -4881,6 +4886,15 @@ NTSTATUS WINAPI NtProtectVirtualMemory( HANDLE process, PVOID *addr_ptr, SIZE_T
- {
- old = get_win32_prot( vprot, view->protect );
- status = set_protection( view, base, size, new_prot );
- + if (simulate_writecopy && status == STATUS_SUCCESS
- + && ((old == PAGE_WRITECOPY || old == PAGE_EXECUTE_WRITECOPY)))
- + {
- + TRACE("Setting VPROT_COPIED.\n");
- +
- + set_page_vprot_bits(base, size, VPROT_COPIED, 0);
- + vprot |= VPROT_COPIED;
- + old = get_win32_prot( vprot, view->protect );
- + }
- }
- else status = STATUS_NOT_COMMITTED;
- }
- --
- 2.43.0
Advertisement
Add Comment
Please, Sign In to add comment