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
27 #include "wine/debug.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
59 /***********************************************************************
62 static WORD CalcCheckSum(
63 DWORD StartValue, LPVOID BaseAddress, DWORD WordCount)
70 Ptr = (LPWORD)BaseAddress;
71 for (i = 0; i < WordCount; i++)
76 Sum = LOWORD(Sum) + HIWORD(Sum);
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;
96 FIXME("(%p, %d, %p, %p): stub\n",
97 BaseAddress, FileLength, HeaderSum, CheckSum
100 CalcSum = (DWORD)CalcCheckSum(0,
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);
115 CalcSum = ((LOWORD(CalcSum) - LOWORD(HdrSum)) & 0xFFFF) - 1;
118 /* fix high word of checksum */
119 if (LOWORD(CalcSum) >= HIWORD(HdrSum))
121 CalcSum -= HIWORD(HdrSum);
125 CalcSum = ((LOWORD(CalcSum) - HIWORD(HdrSum)) & 0xFFFF) - 1;
128 /* add file length */
129 CalcSum += FileLength;
132 *HeaderSum = Header->OptionalHeader.CheckSum;
137 /***********************************************************************
138 * MapFileAndCheckSumA (IMAGEHLP.@)
140 DWORD WINAPI MapFileAndCheckSumA(
141 PCSTR Filename, PDWORD HeaderSum, PDWORD CheckSum)
148 TRACE("(%s, %p, %p): stub\n",
149 debugstr_a(Filename), HeaderSum, CheckSum
152 hFile = CreateFileA(Filename,
154 FILE_SHARE_READ | FILE_SHARE_WRITE,
157 FILE_ATTRIBUTE_NORMAL,
159 if (hFile == INVALID_HANDLE_VALUE)
161 return CHECKSUM_OPEN_FAILURE;
164 hMapping = CreateFileMappingW(hFile,
173 return CHECKSUM_MAP_FAILURE;
176 BaseAddress = MapViewOfFile(hMapping,
181 if (BaseAddress == 0)
183 CloseHandle(hMapping);
185 return CHECKSUM_MAPVIEW_FAILURE;
188 FileLength = GetFileSize(hFile,
191 CheckSumMappedFile(BaseAddress,
196 UnmapViewOfFile(BaseAddress);
197 CloseHandle(hMapping);
203 /***********************************************************************
204 * MapFileAndCheckSumW (IMAGEHLP.@)
206 DWORD WINAPI MapFileAndCheckSumW(
207 PCWSTR Filename, PDWORD HeaderSum, PDWORD CheckSum)
214 TRACE("(%s, %p, %p): stub\n",
215 debugstr_w(Filename), HeaderSum, CheckSum
218 hFile = CreateFileW(Filename,
220 FILE_SHARE_READ | FILE_SHARE_WRITE,
223 FILE_ATTRIBUTE_NORMAL,
225 if (hFile == INVALID_HANDLE_VALUE)
227 return CHECKSUM_OPEN_FAILURE;
230 hMapping = CreateFileMappingW(hFile,
239 return CHECKSUM_MAP_FAILURE;
242 BaseAddress = MapViewOfFile(hMapping,
247 if (BaseAddress == 0)
249 CloseHandle(hMapping);
251 return CHECKSUM_MAPVIEW_FAILURE;
254 FileLength = GetFileSize(hFile,
257 CheckSumMappedFile(BaseAddress,
262 UnmapViewOfFile(BaseAddress);
263 CloseHandle(hMapping);
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)
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);
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);
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);
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);
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);