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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(imagehlp);
33 static WORD CalcCheckSum(DWORD StartValue, LPVOID BaseAddress, DWORD WordCount);
36 /***********************************************************************
37 * BindImage (IMAGEHLP.@)
39 BOOL WINAPI BindImage(
40 LPSTR ImageName, LPSTR DllPath, LPSTR SymbolPath)
42 return BindImageEx(0, ImageName, DllPath, SymbolPath, NULL);
45 /***********************************************************************
46 * BindImageEx (IMAGEHLP.@)
48 BOOL WINAPI BindImageEx(
49 DWORD Flags, LPSTR ImageName, LPSTR DllPath, LPSTR SymbolPath,
50 PIMAGEHLP_STATUS_ROUTINE StatusRoutine)
52 FIXME("(%ld, %s, %s, %s, %p): stub\n",
53 Flags, debugstr_a(ImageName), debugstr_a(DllPath),
54 debugstr_a(SymbolPath), StatusRoutine
56 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
61 /***********************************************************************
64 static WORD CalcCheckSum(
65 DWORD StartValue, LPVOID BaseAddress, DWORD WordCount)
72 Ptr = (LPWORD)BaseAddress;
73 for (i = 0; i < WordCount; i++)
78 Sum = LOWORD(Sum) + HIWORD(Sum);
83 return (WORD)(LOWORD(Sum) + HIWORD(Sum));
87 /***********************************************************************
88 * CheckSumMappedFile (IMAGEHLP.@)
90 PIMAGE_NT_HEADERS WINAPI CheckSumMappedFile(
91 LPVOID BaseAddress, DWORD FileLength,
92 LPDWORD HeaderSum, LPDWORD CheckSum)
94 PIMAGE_NT_HEADERS Header;
98 FIXME("(%p, %ld, %p, %p): stub\n",
99 BaseAddress, FileLength, HeaderSum, CheckSum
102 CalcSum = (DWORD)CalcCheckSum(0,
104 (FileLength + 1) / sizeof(WORD));
106 Header = RtlImageNtHeader(BaseAddress);
107 HdrSum = Header->OptionalHeader.CheckSum;
109 /* Subtract image checksum from calculated checksum. */
110 /* fix low word of checksum */
111 if (LOWORD(CalcSum) >= LOWORD(HdrSum))
113 CalcSum -= LOWORD(HdrSum);
117 CalcSum = ((LOWORD(CalcSum) - LOWORD(HdrSum)) & 0xFFFF) - 1;
120 /* fix high word of checksum */
121 if (LOWORD(CalcSum) >= HIWORD(HdrSum))
123 CalcSum -= HIWORD(HdrSum);
127 CalcSum = ((LOWORD(CalcSum) - HIWORD(HdrSum)) & 0xFFFF) - 1;
130 /* add file length */
131 CalcSum += FileLength;
134 *HeaderSum = Header->OptionalHeader.CheckSum;
139 /***********************************************************************
140 * MapFileAndCheckSumA (IMAGEHLP.@)
142 DWORD WINAPI MapFileAndCheckSumA(
143 LPSTR Filename, LPDWORD HeaderSum, LPDWORD CheckSum)
150 TRACE("(%s, %p, %p): stub\n",
151 debugstr_a(Filename), HeaderSum, CheckSum
154 hFile = CreateFileA(Filename,
156 FILE_SHARE_READ | FILE_SHARE_WRITE,
159 FILE_ATTRIBUTE_NORMAL,
161 if (hFile == INVALID_HANDLE_VALUE)
163 return CHECKSUM_OPEN_FAILURE;
166 hMapping = CreateFileMappingW(hFile,
175 return CHECKSUM_MAP_FAILURE;
178 BaseAddress = MapViewOfFile(hMapping,
185 CloseHandle(hMapping);
187 return CHECKSUM_MAPVIEW_FAILURE;
190 FileLength = GetFileSize(hFile,
193 CheckSumMappedFile(BaseAddress,
198 UnmapViewOfFile(BaseAddress);
199 CloseHandle(hMapping);
205 /***********************************************************************
206 * MapFileAndCheckSumW (IMAGEHLP.@)
208 DWORD WINAPI MapFileAndCheckSumW(
209 LPWSTR Filename, LPDWORD HeaderSum, LPDWORD CheckSum)
216 TRACE("(%s, %p, %p): stub\n",
217 debugstr_w(Filename), HeaderSum, CheckSum
220 hFile = CreateFileW(Filename,
222 FILE_SHARE_READ | FILE_SHARE_WRITE,
225 FILE_ATTRIBUTE_NORMAL,
227 if (hFile == INVALID_HANDLE_VALUE)
229 return CHECKSUM_OPEN_FAILURE;
232 hMapping = CreateFileMappingW(hFile,
241 return CHECKSUM_MAP_FAILURE;
244 BaseAddress = MapViewOfFile(hMapping,
251 CloseHandle(hMapping);
253 return CHECKSUM_MAPVIEW_FAILURE;
256 FileLength = GetFileSize(hFile,
259 CheckSumMappedFile(BaseAddress,
264 UnmapViewOfFile(BaseAddress);
265 CloseHandle(hMapping);
271 /***********************************************************************
272 * ReBaseImage (IMAGEHLP.@)
274 BOOL WINAPI ReBaseImage(
275 LPSTR CurrentImageName, LPSTR SymbolPath, BOOL fReBase,
276 BOOL fRebaseSysfileOk, BOOL fGoingDown, ULONG CheckImageSize,
277 ULONG *OldImageSize, ULONG *OldImageBase, ULONG *NewImageSize,
278 ULONG *NewImageBase, ULONG TimeStamp)
281 "(%s, %s, %d, %d, %d, %ld, %p, %p, %p, %p, %ld): stub\n",
282 debugstr_a(CurrentImageName),debugstr_a(SymbolPath), fReBase,
283 fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize,
284 OldImageBase, NewImageSize, NewImageBase, TimeStamp
286 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
290 /***********************************************************************
291 * RemovePrivateCvSymbolic (IMAGEHLP.@)
293 BOOL WINAPI RemovePrivateCvSymbolic(
294 PCHAR DebugData, PCHAR *NewDebugData, ULONG *NewDebugSize)
296 FIXME("(%p, %p, %p): stub\n",
297 DebugData, NewDebugData, NewDebugSize
299 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
303 /***********************************************************************
304 * RemoveRelocations (IMAGEHLP.@)
306 VOID WINAPI RemoveRelocations(PCHAR ImageName)
308 FIXME("(%p): stub\n", ImageName);
309 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
312 /***********************************************************************
313 * SplitSymbols (IMAGEHLP.@)
315 BOOL WINAPI SplitSymbols(
316 LPSTR ImageName, LPSTR SymbolsPath,
317 LPSTR SymbolFilePath, DWORD Flags)
319 FIXME("(%s, %s, %s, %ld): stub\n",
320 debugstr_a(ImageName), debugstr_a(SymbolsPath),
321 debugstr_a(SymbolFilePath), Flags
323 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
327 /***********************************************************************
328 * UpdateDebugInfoFile (IMAGEHLP.@)
330 BOOL WINAPI UpdateDebugInfoFile(
331 LPSTR ImageFileName, LPSTR SymbolPath,
332 LPSTR DebugFilePath, PIMAGE_NT_HEADERS NtHeaders)
334 FIXME("(%s, %s, %s, %p): stub\n",
335 debugstr_a(ImageFileName), debugstr_a(SymbolPath),
336 debugstr_a(DebugFilePath), NtHeaders
338 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
342 /***********************************************************************
343 * UpdateDebugInfoFileEx (IMAGEHLP.@)
345 BOOL WINAPI UpdateDebugInfoFileEx(
346 LPSTR ImageFileName, LPSTR SymbolPath, LPSTR DebugFilePath,
347 PIMAGE_NT_HEADERS NtHeaders, DWORD OldChecksum)
349 FIXME("(%s, %s, %s, %p, %ld): stub\n",
350 debugstr_a(ImageFileName), debugstr_a(SymbolPath),
351 debugstr_a(DebugFilePath), NtHeaders, OldChecksum
353 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);