wsdapi: Populate SOAP header structure.
[wine.git] / dlls / imagehlp / modify.c
blobdebccc00f88dc19ca8a2c387c25e2f7a1b7070c3
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 IMAGE_DOS_HEADER *dos = (IMAGE_DOS_HEADER *) BaseAddress;
93 PIMAGE_NT_HEADERS32 Header32;
94 PIMAGE_NT_HEADERS64 Header64;
95 DWORD *ChecksumFile;
96 DWORD CalcSum;
97 DWORD HdrSum;
99 TRACE("(%p, %d, %p, %p)\n",
100 BaseAddress, FileLength, HeaderSum, CheckSum
103 CalcSum = (DWORD)CalcCheckSum(0,
104 BaseAddress,
105 (FileLength + 1) / sizeof(WORD));
107 if (dos->e_magic != IMAGE_DOS_SIGNATURE)
108 return NULL;
110 Header32 = (IMAGE_NT_HEADERS32 *)((char *)dos + dos->e_lfanew);
112 if (Header32->Signature != IMAGE_NT_SIGNATURE)
113 return NULL;
115 if (Header32->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
116 ChecksumFile = &Header32->OptionalHeader.CheckSum;
117 else if (Header32->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
119 Header64 = (IMAGE_NT_HEADERS64 *)Header32;
120 ChecksumFile = &Header64->OptionalHeader.CheckSum;
122 else
123 return NULL;
125 HdrSum = *ChecksumFile;
127 /* Subtract image checksum from calculated checksum. */
128 /* fix low word of checksum */
129 if (LOWORD(CalcSum) >= LOWORD(HdrSum))
131 CalcSum -= LOWORD(HdrSum);
133 else
135 CalcSum = ((LOWORD(CalcSum) - LOWORD(HdrSum)) & 0xFFFF) - 1;
138 /* fix high word of checksum */
139 if (LOWORD(CalcSum) >= HIWORD(HdrSum))
141 CalcSum -= HIWORD(HdrSum);
143 else
145 CalcSum = ((LOWORD(CalcSum) - HIWORD(HdrSum)) & 0xFFFF) - 1;
148 /* add file length */
149 CalcSum += FileLength;
151 *CheckSum = CalcSum;
152 *HeaderSum = *ChecksumFile;
154 return (PIMAGE_NT_HEADERS) Header32;
157 /***********************************************************************
158 * MapFileAndCheckSumA (IMAGEHLP.@)
160 DWORD WINAPI MapFileAndCheckSumA(
161 PCSTR Filename, PDWORD HeaderSum, PDWORD CheckSum)
163 HANDLE hFile;
164 HANDLE hMapping;
165 LPVOID BaseAddress;
166 DWORD FileLength;
168 TRACE("(%s, %p, %p): stub\n",
169 debugstr_a(Filename), HeaderSum, CheckSum
172 hFile = CreateFileA(Filename,
173 GENERIC_READ,
174 FILE_SHARE_READ | FILE_SHARE_WRITE,
175 NULL,
176 OPEN_EXISTING,
177 FILE_ATTRIBUTE_NORMAL,
179 if (hFile == INVALID_HANDLE_VALUE)
181 return CHECKSUM_OPEN_FAILURE;
184 hMapping = CreateFileMappingW(hFile,
185 NULL,
186 PAGE_READONLY,
189 NULL);
190 if (hMapping == 0)
192 CloseHandle(hFile);
193 return CHECKSUM_MAP_FAILURE;
196 BaseAddress = MapViewOfFile(hMapping,
197 FILE_MAP_READ,
201 if (BaseAddress == 0)
203 CloseHandle(hMapping);
204 CloseHandle(hFile);
205 return CHECKSUM_MAPVIEW_FAILURE;
208 FileLength = GetFileSize(hFile,
209 NULL);
211 CheckSumMappedFile(BaseAddress,
212 FileLength,
213 HeaderSum,
214 CheckSum);
216 UnmapViewOfFile(BaseAddress);
217 CloseHandle(hMapping);
218 CloseHandle(hFile);
220 return 0;
223 /***********************************************************************
224 * MapFileAndCheckSumW (IMAGEHLP.@)
226 DWORD WINAPI MapFileAndCheckSumW(
227 PCWSTR Filename, PDWORD HeaderSum, PDWORD CheckSum)
229 HANDLE hFile;
230 HANDLE hMapping;
231 LPVOID BaseAddress;
232 DWORD FileLength;
234 TRACE("(%s, %p, %p): stub\n",
235 debugstr_w(Filename), HeaderSum, CheckSum
238 hFile = CreateFileW(Filename,
239 GENERIC_READ,
240 FILE_SHARE_READ | FILE_SHARE_WRITE,
241 NULL,
242 OPEN_EXISTING,
243 FILE_ATTRIBUTE_NORMAL,
245 if (hFile == INVALID_HANDLE_VALUE)
247 return CHECKSUM_OPEN_FAILURE;
250 hMapping = CreateFileMappingW(hFile,
251 NULL,
252 PAGE_READONLY,
255 NULL);
256 if (hMapping == 0)
258 CloseHandle(hFile);
259 return CHECKSUM_MAP_FAILURE;
262 BaseAddress = MapViewOfFile(hMapping,
263 FILE_MAP_READ,
267 if (BaseAddress == 0)
269 CloseHandle(hMapping);
270 CloseHandle(hFile);
271 return CHECKSUM_MAPVIEW_FAILURE;
274 FileLength = GetFileSize(hFile,
275 NULL);
277 CheckSumMappedFile(BaseAddress,
278 FileLength,
279 HeaderSum,
280 CheckSum);
282 UnmapViewOfFile(BaseAddress);
283 CloseHandle(hMapping);
284 CloseHandle(hFile);
286 return 0;
289 /***********************************************************************
290 * ReBaseImage (IMAGEHLP.@)
292 BOOL WINAPI ReBaseImage(
293 PCSTR CurrentImageName, PCSTR SymbolPath, BOOL fReBase,
294 BOOL fRebaseSysfileOk, BOOL fGoingDown, ULONG CheckImageSize,
295 ULONG *OldImageSize, ULONG_PTR *OldImageBase, ULONG *NewImageSize,
296 ULONG_PTR *NewImageBase, ULONG TimeStamp)
298 FIXME(
299 "(%s, %s, %d, %d, %d, %d, %p, %p, %p, %p, %d): stub\n",
300 debugstr_a(CurrentImageName),debugstr_a(SymbolPath), fReBase,
301 fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize,
302 OldImageBase, NewImageSize, NewImageBase, TimeStamp
304 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
305 return FALSE;
308 /***********************************************************************
309 * RemovePrivateCvSymbolic (IMAGEHLP.@)
311 BOOL WINAPI RemovePrivateCvSymbolic(
312 PCHAR DebugData, PCHAR *NewDebugData, ULONG *NewDebugSize)
314 FIXME("(%p, %p, %p): stub\n",
315 DebugData, NewDebugData, NewDebugSize
317 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
318 return FALSE;
321 /***********************************************************************
322 * RemoveRelocations (IMAGEHLP.@)
324 VOID WINAPI RemoveRelocations(PCHAR ImageName)
326 FIXME("(%p): stub\n", ImageName);
327 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
330 /***********************************************************************
331 * SplitSymbols (IMAGEHLP.@)
333 BOOL WINAPI SplitSymbols(
334 PSTR ImageName, PCSTR SymbolsPath,
335 PSTR SymbolFilePath, ULONG Flags)
337 FIXME("(%s, %s, %s, %d): stub\n",
338 debugstr_a(ImageName), debugstr_a(SymbolsPath),
339 debugstr_a(SymbolFilePath), Flags
341 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
342 return FALSE;
345 /***********************************************************************
346 * UpdateDebugInfoFile (IMAGEHLP.@)
348 BOOL WINAPI UpdateDebugInfoFile(
349 PCSTR ImageFileName, PCSTR SymbolPath,
350 PSTR DebugFilePath, PIMAGE_NT_HEADERS32 NtHeaders)
352 FIXME("(%s, %s, %s, %p): stub\n",
353 debugstr_a(ImageFileName), debugstr_a(SymbolPath),
354 debugstr_a(DebugFilePath), NtHeaders
356 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
357 return FALSE;
360 /***********************************************************************
361 * UpdateDebugInfoFileEx (IMAGEHLP.@)
363 BOOL WINAPI UpdateDebugInfoFileEx(
364 PCSTR ImageFileName, PCSTR SymbolPath, PSTR DebugFilePath,
365 PIMAGE_NT_HEADERS32 NtHeaders, DWORD OldChecksum)
367 FIXME("(%s, %s, %s, %p, %d): stub\n",
368 debugstr_a(ImageFileName), debugstr_a(SymbolPath),
369 debugstr_a(DebugFilePath), NtHeaders, OldChecksum
371 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
372 return FALSE;