xref: /reactos/dll/win32/mspatcha/mspatcha_main.c (revision 845faec4)
1 /*
2  * PatchAPI
3  *
4  * Copyright 2011 David Hedberg for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 #include "config.h"
22 
23 #include <stdarg.h>
24 
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winnls.h"
28 #include "patchapi.h"
29 #include "wine/debug.h"
30 
31 WINE_DEFAULT_DEBUG_CHANNEL(mspatcha);
32 
33 /*****************************************************
34  *    DllMain (MSPATCHA.@)
35  */
36 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
37 {
38     TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
39 
40     switch (fdwReason)
41     {
42         case DLL_WINE_PREATTACH:
43             return FALSE;    /* prefer native version */
44         case DLL_PROCESS_ATTACH:
45             DisableThreadLibraryCalls(hinstDLL);
46             break;
47     }
48 
49     return TRUE;
50 }
51 
52 static inline WCHAR *strdupAW( const char *src )
53 {
54     WCHAR *dst = NULL;
55     if (src)
56     {
57         int len = MultiByteToWideChar( CP_ACP, 0, src, -1, NULL, 0 );
58         if ((dst = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
59             MultiByteToWideChar( CP_ACP, 0, src, -1, dst, len );
60     }
61     return dst;
62 }
63 
64 /*****************************************************
65  *    ApplyPatchToFileA (MSPATCHA.1)
66  */
67 BOOL WINAPI ApplyPatchToFileA(LPCSTR patch_file, LPCSTR old_file, LPCSTR new_file, ULONG apply_flags)
68 {
69     BOOL ret;
70     WCHAR *patch_fileW, *new_fileW, *old_fileW = NULL;
71 
72     if (!(patch_fileW = strdupAW( patch_file ))) return FALSE;
73     if (old_file && !(old_fileW = strdupAW( old_file )))
74     {
75         HeapFree( GetProcessHeap(), 0, patch_fileW );
76         return FALSE;
77     }
78     if (!(new_fileW = strdupAW( new_file )))
79     {
80         HeapFree( GetProcessHeap(), 0, patch_fileW );
81         HeapFree( GetProcessHeap(), 0, old_fileW );
82         return FALSE;
83     }
84     ret = ApplyPatchToFileW( patch_fileW, old_fileW, new_fileW, apply_flags );
85     HeapFree( GetProcessHeap(), 0, patch_fileW );
86     HeapFree( GetProcessHeap(), 0, old_fileW );
87     HeapFree( GetProcessHeap(), 0, new_fileW );
88     return ret;
89 }
90 
91 /*****************************************************
92  *    ApplyPatchToFileW (MSPATCHA.6)
93  */
94 BOOL WINAPI ApplyPatchToFileW(LPCWSTR patch_file, LPCWSTR old_file, LPCWSTR new_file, ULONG apply_flags)
95 {
96     FIXME("stub - %s, %s, %s, %08x\n", debugstr_w(patch_file), debugstr_w(old_file),
97           debugstr_w(new_file), apply_flags);
98 
99     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
100     return FALSE;
101 }
102 
103 /*****************************************************
104  *    GetFilePatchSignatureA (MSPATCHA.7)
105  */
106 BOOL WINAPI GetFilePatchSignatureA(LPCSTR filename, ULONG flags, PVOID data, ULONG ignore_range_count,
107                                    PPATCH_IGNORE_RANGE ignore_range, ULONG retain_range_count,
108                                    PPATCH_RETAIN_RANGE retain_range, ULONG bufsize, LPSTR buffer)
109 {
110     FIXME("stub - %s, %x, %p, %u, %p, %u, %p, %u, %p\n", debugstr_a(filename), flags, data,
111           ignore_range_count, ignore_range, retain_range_count, retain_range, bufsize, buffer);
112     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
113     return FALSE;
114 }
115 
116 /*****************************************************
117  *    GetFilePatchSignatureW (MSPATCHA.9)
118  */
119 BOOL WINAPI GetFilePatchSignatureW(LPCWSTR filename, ULONG flags, PVOID data, ULONG ignore_range_count,
120                                    PPATCH_IGNORE_RANGE ignore_range, ULONG retain_range_count,
121                                    PPATCH_RETAIN_RANGE retain_range, ULONG bufsize, LPWSTR buffer)
122 {
123     FIXME("stub - %s, %x, %p, %u, %p, %u, %p, %u, %p\n", debugstr_w(filename), flags, data,
124           ignore_range_count, ignore_range, retain_range_count, retain_range, bufsize, buffer);
125     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
126     return FALSE;
127 }
128