gdiplus: Implemented GdipIsEmptyClip with tests.
[wine.git] / dlls / imagehlp / modify.c
blob02636bd2322e1bc5dcaf34095844c219cda17e22
1 /*
2 * IMAGEHLP library
4 * Copyright 1998 Patrik Stridvall
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.
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.
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
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winternl.h"
26 #include "winerror.h"
27 #include "wine/debug.h"
28 #include "imagehlp.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(imagehlp);
32 static WORD CalcCheckSum(DWORD StartValue, LPVOID BaseAddress, DWORD WordCount);
35 /***********************************************************************
36 * BindImage (IMAGEHLP.@)
38 BOOL WINAPI BindImage(
39 PCSTR ImageName, PCSTR DllPath, PCSTR SymbolPath)
41 return BindImageEx(0, ImageName, DllPath, SymbolPath, NULL);
44 /***********************************************************************
45 * BindImageEx (IMAGEHLP.@)
47 BOOL WINAPI BindImageEx(
48 DWORD Flags, PCSTR ImageName, PCSTR DllPath, PCSTR SymbolPath,
49 PIMAGEHLP_STATUS_ROUTINE StatusRoutine)
51 FIXME("(%d, %s, %s, %s, %p): stub\n",
52 Flags, debugstr_a(ImageName), debugstr_a(DllPath),
53 debugstr_a(SymbolPath), StatusRoutine
55 return TRUE;
59 /***********************************************************************
60 * CheckSum (internal)
62 static WORD CalcCheckSum(
63 DWORD StartValue, LPVOID BaseAddress, DWORD WordCount)
65 LPWORD Ptr;
66 DWORD Sum;
67 DWORD i;
69 Sum = StartValue;
70 Ptr = (LPWORD)BaseAddress;
71 for (i = 0; i < WordCount; i++)
73 Sum += *Ptr;
74 if (HIWORD(Sum) != 0)
76 Sum = LOWORD(Sum) + HIWORD(Sum);
78 Ptr++;
81 return (WORD)(LOWORD(Sum) + HIWORD(Sum));
85 /***********************************************************************
86 * CheckSumMappedFile (IMAGEHLP.@)
88 PIMAGE_NT_HEADERS WINAPI CheckSumMappedFile(
89 LPVOID BaseAddress, DWORD FileLength,
90 LPDWORD HeaderSum, LPDWORD CheckSum)
92 PIMAGE_NT_HEADERS Header;
93 DWORD CalcSum;
94 DWORD HdrSum;
96 FIXME("(%p, %d, %p, %p): stub\n",
97 BaseAddress, FileLength, HeaderSum, CheckSum
100 CalcSum = (DWORD)CalcCheckSum(0,
101 BaseAddress,
102 (FileLength + 1) / sizeof(WORD));
104 Header = RtlImageNtHeader(BaseAddress);
105 HdrSum = Header->OptionalHeader.CheckSum;
107 /* Subtract image checksum from calculated checksum. */
108 /* fix low word of checksum */
109 if (LOWORD(CalcSum) >= LOWORD(HdrSum))
111 CalcSum -= LOWORD(HdrSum);
113 else
115 CalcSum = ((LOWORD(CalcSum) - LOWORD(HdrSum)) & 0xFFFF) - 1;
118 /* fix high word of checksum */
119 if (LOWORD(CalcSum) >= HIWORD(HdrSum))
121 CalcSum -= HIWORD(HdrSum);
123 else
125 CalcSum = ((LOWORD(CalcSum) - HIWORD(HdrSum)) & 0xFFFF) - 1;
128 /* add file length */
129 CalcSum += FileLength;
131 *CheckSum = CalcSum;
132 *HeaderSum = Header->OptionalHeader.CheckSum;
134 return Header;
137 /***********************************************************************
138 * MapFileAndCheckSumA (IMAGEHLP.@)
140 DWORD WINAPI MapFileAndCheckSumA(
141 PCSTR Filename, PDWORD HeaderSum, PDWORD CheckSum)
143 HANDLE hFile;
144 HANDLE hMapping;
145 LPVOID BaseAddress;
146 DWORD FileLength;
148 TRACE("(%s, %p, %p): stub\n",
149 debugstr_a(Filename), HeaderSum, CheckSum
152 hFile = CreateFileA(Filename,
153 GENERIC_READ,
154 FILE_SHARE_READ | FILE_SHARE_WRITE,
155 NULL,
156 OPEN_EXISTING,
157 FILE_ATTRIBUTE_NORMAL,
159 if (hFile == INVALID_HANDLE_VALUE)
161 return CHECKSUM_OPEN_FAILURE;
164 hMapping = CreateFileMappingW(hFile,
165 NULL,
166 PAGE_READONLY,
169 NULL);
170 if (hMapping == 0)
172 CloseHandle(hFile);
173 return CHECKSUM_MAP_FAILURE;
176 BaseAddress = MapViewOfFile(hMapping,
177 FILE_MAP_READ,
181 if (BaseAddress == 0)
183 CloseHandle(hMapping);
184 CloseHandle(hFile);
185 return CHECKSUM_MAPVIEW_FAILURE;
188 FileLength = GetFileSize(hFile,
189 NULL);
191 CheckSumMappedFile(BaseAddress,
192 FileLength,
193 HeaderSum,
194 CheckSum);
196 UnmapViewOfFile(BaseAddress);
197 CloseHandle(hMapping);
198 CloseHandle(hFile);
200 return 0;
203 /***********************************************************************
204 * MapFileAndCheckSumW (IMAGEHLP.@)
206 DWORD WINAPI MapFileAndCheckSumW(
207 PCWSTR Filename, PDWORD HeaderSum, PDWORD CheckSum)
209 HANDLE hFile;
210 HANDLE hMapping;
211 LPVOID BaseAddress;
212 DWORD FileLength;
214 TRACE("(%s, %p, %p): stub\n",
215 debugstr_w(Filename), HeaderSum, CheckSum
218 hFile = CreateFileW(Filename,
219 GENERIC_READ,
220 FILE_SHARE_READ | FILE_SHARE_WRITE,
221 NULL,
222 OPEN_EXISTING,
223 FILE_ATTRIBUTE_NORMAL,
225 if (hFile == INVALID_HANDLE_VALUE)
227 return CHECKSUM_OPEN_FAILURE;
230 hMapping = CreateFileMappingW(hFile,
231 NULL,
232 PAGE_READONLY,
235 NULL);
236 if (hMapping == 0)
238 CloseHandle(hFile);
239 return CHECKSUM_MAP_FAILURE;
242 BaseAddress = MapViewOfFile(hMapping,
243 FILE_MAP_READ,
247 if (BaseAddress == 0)
249 CloseHandle(hMapping);
250 CloseHandle(hFile);
251 return CHECKSUM_MAPVIEW_FAILURE;
254 FileLength = GetFileSize(hFile,
255 NULL);
257 CheckSumMappedFile(BaseAddress,
258 FileLength,
259 HeaderSum,
260 CheckSum);
262 UnmapViewOfFile(BaseAddress);
263 CloseHandle(hMapping);
264 CloseHandle(hFile);
266 return 0;
269 /***********************************************************************
270 * ReBaseImage (IMAGEHLP.@)
272 BOOL WINAPI ReBaseImage(
273 PCSTR CurrentImageName, PCSTR SymbolPath, BOOL fReBase,
274 BOOL fRebaseSysfileOk, BOOL fGoingDown, ULONG CheckImageSize,
275 ULONG *OldImageSize, ULONG_PTR *OldImageBase, ULONG *NewImageSize,
276 ULONG_PTR *NewImageBase, ULONG TimeStamp)
278 FIXME(
279 "(%s, %s, %d, %d, %d, %d, %p, %p, %p, %p, %d): stub\n",
280 debugstr_a(CurrentImageName),debugstr_a(SymbolPath), fReBase,
281 fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize,
282 OldImageBase, NewImageSize, NewImageBase, TimeStamp
284 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
285 return FALSE;
288 /***********************************************************************
289 * RemovePrivateCvSymbolic (IMAGEHLP.@)
291 BOOL WINAPI RemovePrivateCvSymbolic(
292 PCHAR DebugData, PCHAR *NewDebugData, ULONG *NewDebugSize)
294 FIXME("(%p, %p, %p): stub\n",
295 DebugData, NewDebugData, NewDebugSize
297 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
298 return FALSE;
301 /***********************************************************************
302 * RemoveRelocations (IMAGEHLP.@)
304 VOID WINAPI RemoveRelocations(PCHAR ImageName)
306 FIXME("(%p): stub\n", ImageName);
307 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
310 /***********************************************************************
311 * SplitSymbols (IMAGEHLP.@)
313 BOOL WINAPI SplitSymbols(
314 PSTR ImageName, PCSTR SymbolsPath,
315 PSTR SymbolFilePath, ULONG Flags)
317 FIXME("(%s, %s, %s, %d): stub\n",
318 debugstr_a(ImageName), debugstr_a(SymbolsPath),
319 debugstr_a(SymbolFilePath), Flags
321 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
322 return FALSE;
325 /***********************************************************************
326 * UpdateDebugInfoFile (IMAGEHLP.@)
328 BOOL WINAPI UpdateDebugInfoFile(
329 PCSTR ImageFileName, PCSTR SymbolPath,
330 PSTR DebugFilePath, PIMAGE_NT_HEADERS32 NtHeaders)
332 FIXME("(%s, %s, %s, %p): stub\n",
333 debugstr_a(ImageFileName), debugstr_a(SymbolPath),
334 debugstr_a(DebugFilePath), NtHeaders
336 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
337 return FALSE;
340 /***********************************************************************
341 * UpdateDebugInfoFileEx (IMAGEHLP.@)
343 BOOL WINAPI UpdateDebugInfoFileEx(
344 PCSTR ImageFileName, PCSTR SymbolPath, PSTR DebugFilePath,
345 PIMAGE_NT_HEADERS32 NtHeaders, DWORD OldChecksum)
347 FIXME("(%s, %s, %s, %p, %d): stub\n",
348 debugstr_a(ImageFileName), debugstr_a(SymbolPath),
349 debugstr_a(DebugFilePath), NtHeaders, OldChecksum
351 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
352 return FALSE;