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 IMAGE_DOS_HEADER *dos = (IMAGE_DOS_HEADER *) BaseAddress;
93 PIMAGE_NT_HEADERS32 Header32;
94 PIMAGE_NT_HEADERS64 Header64;
99 TRACE("(%p, %d, %p, %p)\n",
100 BaseAddress, FileLength, HeaderSum, CheckSum
103 CalcSum = (DWORD)CalcCheckSum(0,
105 (FileLength + 1) / sizeof(WORD));
107 if (dos->e_magic != IMAGE_DOS_SIGNATURE)
110 Header32 = (IMAGE_NT_HEADERS32 *)((char *)dos + dos->e_lfanew);
112 if (Header32->Signature != IMAGE_NT_SIGNATURE)
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;
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);
135 CalcSum = ((LOWORD(CalcSum) - LOWORD(HdrSum)) & 0xFFFF) - 1;
138 /* fix high word of checksum */
139 if (LOWORD(CalcSum) >= HIWORD(HdrSum))
141 CalcSum -= HIWORD(HdrSum);
145 CalcSum = ((LOWORD(CalcSum) - HIWORD(HdrSum)) & 0xFFFF) - 1;
148 /* add file length */
149 CalcSum += FileLength;
152 *HeaderSum = *ChecksumFile;
154 return (PIMAGE_NT_HEADERS) Header32;
157 /***********************************************************************
158 * MapFileAndCheckSumA (IMAGEHLP.@)
160 DWORD WINAPI MapFileAndCheckSumA(
161 PCSTR Filename, PDWORD HeaderSum, PDWORD CheckSum)
168 TRACE("(%s, %p, %p): stub\n",
169 debugstr_a(Filename), HeaderSum, CheckSum
172 hFile = CreateFileA(Filename,
174 FILE_SHARE_READ | FILE_SHARE_WRITE,
177 FILE_ATTRIBUTE_NORMAL,
179 if (hFile == INVALID_HANDLE_VALUE)
181 return CHECKSUM_OPEN_FAILURE;
184 hMapping = CreateFileMappingW(hFile,
193 return CHECKSUM_MAP_FAILURE;
196 BaseAddress = MapViewOfFile(hMapping,
201 if (BaseAddress == 0)
203 CloseHandle(hMapping);
205 return CHECKSUM_MAPVIEW_FAILURE;
208 FileLength = GetFileSize(hFile,
211 CheckSumMappedFile(BaseAddress,
216 UnmapViewOfFile(BaseAddress);
217 CloseHandle(hMapping);
223 /***********************************************************************
224 * MapFileAndCheckSumW (IMAGEHLP.@)
226 DWORD WINAPI MapFileAndCheckSumW(
227 PCWSTR Filename, PDWORD HeaderSum, PDWORD CheckSum)
234 TRACE("(%s, %p, %p): stub\n",
235 debugstr_w(Filename), HeaderSum, CheckSum
238 hFile = CreateFileW(Filename,
240 FILE_SHARE_READ | FILE_SHARE_WRITE,
243 FILE_ATTRIBUTE_NORMAL,
245 if (hFile == INVALID_HANDLE_VALUE)
247 return CHECKSUM_OPEN_FAILURE;
250 hMapping = CreateFileMappingW(hFile,
259 return CHECKSUM_MAP_FAILURE;
262 BaseAddress = MapViewOfFile(hMapping,
267 if (BaseAddress == 0)
269 CloseHandle(hMapping);
271 return CHECKSUM_MAPVIEW_FAILURE;
274 FileLength = GetFileSize(hFile,
277 CheckSumMappedFile(BaseAddress,
282 UnmapViewOfFile(BaseAddress);
283 CloseHandle(hMapping);
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)
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);
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);
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);
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);
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);