Guest User

Untitled

a guest
Dec 11th, 2023
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.03 KB | Gaming | 0 0
  1. Subject: [PATCH] Fix battle.net
  2.  
  3. ---
  4. dlls/ntdll/unix/loader.c       | 12 ++++++++++++
  5.  dlls/ntdll/unix/unix_private.h |  2 ++
  6.  dlls/ntdll/unix/virtual.c      | 18 ++++++++++++++++--
  7.  3 files changed, 30 insertions(+), 2 deletions(-)
  8.  
  9. diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c
  10. index 803d80792136..8a1d96a0756f 100644
  11. --- a/dlls/ntdll/unix/loader.c
  12. +++ b/dlls/ntdll/unix/loader.c
  13. @@ -1797,6 +1797,17 @@ static ULONG_PTR get_image_address(void)
  14.      return 0;
  15.  }
  16.  
  17. +BOOL simulate_writecopy;
  18. +
  19. +static void hacks_init(void){
  20. +    const char *env_str;
  21. +    env_str = getenv("WINE_SIMULATE_WRITECOPY");
  22. +    if (env_str) simulate_writecopy = atoi(env_str);
  23. +    else if (main_argc > 1 && (strstr(main_argv[1], "Battle.net.exe")))
  24. +        simulate_writecopy = TRUE;
  25. +
  26. +}
  27. +
  28.  /***********************************************************************
  29.   *           start_main_thread
  30.   */
  31. @@ -1808,6 +1819,7 @@ static void start_main_thread(void)
  32.      signal_alloc_thread( teb );
  33.      dbg_init();
  34.      startup_info_size = server_init_process();
  35. +    hacks_init();
  36.      virtual_map_user_shared_data();
  37.      init_cpu_info();
  38.      init_files();
  39. diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h
  40. index 07f2724eac70..3ec5ad9cfd35 100644
  41. --- a/dlls/ntdll/unix/unix_private.h
  42. +++ b/dlls/ntdll/unix/unix_private.h
  43. @@ -176,6 +176,8 @@ extern SYSTEM_CPU_INFORMATION cpu_info;
  44.  extern struct ldt_copy __wine_ldt_copy;
  45.  #endif
  46.  
  47. +extern BOOL simulate_writecopy;
  48. +
  49.  extern void init_environment(void);
  50.  extern void init_startup_info(void);
  51.  extern void *create_startup_info( const UNICODE_STRING *nt_image, ULONG process_flags,
  52. diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
  53. index 5bdeef4c1bc2..65b2fdc704d7 100644
  54. --- a/dlls/ntdll/unix/virtual.c
  55. +++ b/dlls/ntdll/unix/virtual.c
  56. @@ -122,6 +122,7 @@ struct file_view
  57.  #define VPROT_GUARD      0x10
  58.  #define VPROT_COMMITTED  0x20
  59.  #define VPROT_WRITEWATCH 0x40
  60. +#define VPROT_COPIED     0x80
  61.  /* per-mapping protection flags */
  62.  #define VPROT_ARM64EC          0x0100  /* view may contain ARM64EC code */
  63.  #define VPROT_SYSTEM           0x0200  /* system view (underlying mmap not under our control) */
  64. @@ -1092,7 +1093,8 @@ static const char *get_prot_str( BYTE prot )
  65.      buffer[0] = (prot & VPROT_COMMITTED) ? 'c' : '-';
  66.      buffer[1] = (prot & VPROT_GUARD) ? 'g' : ((prot & VPROT_WRITEWATCH) ? 'H' : '-');
  67.      buffer[2] = (prot & VPROT_READ) ? 'r' : '-';
  68. -    buffer[3] = (prot & VPROT_WRITECOPY) ? 'W' : ((prot & VPROT_WRITE) ? 'w' : '-');
  69. +    buffer[3] = (prot & VPROT_WRITECOPY) ? (prot & VPROT_COPIED ? 'w' : 'W')
  70. +        : ((prot & VPROT_WRITE) ? 'w' : '-');
  71.      buffer[4] = (prot & VPROT_EXEC) ? 'x' : '-';
  72.      buffer[5] = 0;
  73.      return buffer;
  74. @@ -1621,7 +1623,10 @@ static NTSTATUS create_view( struct file_view **view_ret, void *base, size_t siz
  75.   */
  76.  static DWORD get_win32_prot( BYTE vprot, unsigned int map_prot )
  77.  {
  78. -    DWORD ret = VIRTUAL_Win32Flags[vprot & 0x0f];
  79. +    DWORD ret;
  80. +    if ((vprot & (VPROT_COPIED | VPROT_WRITECOPY)) == (VPROT_COPIED | VPROT_WRITECOPY))
  81. +        vprot = (vprot & ~VPROT_WRITECOPY) | VPROT_WRITE;
  82. +    ret = VIRTUAL_Win32Flags[vprot & 0x0f];
  83.      if (vprot & VPROT_GUARD) ret |= PAGE_GUARD;
  84.      if (map_prot & SEC_NOCACHE) ret |= PAGE_NOCACHE;
  85.      return ret;
  86. @@ -4881,6 +4886,15 @@ NTSTATUS WINAPI NtProtectVirtualMemory( HANDLE process, PVOID *addr_ptr, SIZE_T
  87.          {
  88.              old = get_win32_prot( vprot, view->protect );
  89.              status = set_protection( view, base, size, new_prot );
  90. +            if (simulate_writecopy && status == STATUS_SUCCESS
  91. +                && ((old == PAGE_WRITECOPY || old == PAGE_EXECUTE_WRITECOPY)))
  92. +            {
  93. +                TRACE("Setting VPROT_COPIED.\n");
  94. +
  95. +                set_page_vprot_bits(base, size, VPROT_COPIED, 0);
  96. +                vprot |= VPROT_COPIED;
  97. +                old = get_win32_prot( vprot, view->protect );
  98. +            }
  99.          }
  100.          else status = STATUS_NOT_COMMITTED;
  101.      }
  102. --
  103. 2.43.0
  104.  
Advertisement
Add Comment
Please, Sign In to add comment