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
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("(%d, %s, %s, %s, %p): stub\n",
53 Flags
, debugstr_a(ImageName
), debugstr_a(DllPath
),
54 debugstr_a(SymbolPath
), StatusRoutine
60 /***********************************************************************
63 static WORD
CalcCheckSum(
64 DWORD StartValue
, LPVOID BaseAddress
, DWORD WordCount
)
71 Ptr
= (LPWORD
)BaseAddress
;
72 for (i
= 0; i
< WordCount
; i
++)
77 Sum
= LOWORD(Sum
) + HIWORD(Sum
);
82 return (WORD
)(LOWORD(Sum
) + HIWORD(Sum
));
86 /***********************************************************************
87 * CheckSumMappedFile (IMAGEHLP.@)
89 PIMAGE_NT_HEADERS WINAPI
CheckSumMappedFile(
90 LPVOID BaseAddress
, DWORD FileLength
,
91 LPDWORD HeaderSum
, LPDWORD CheckSum
)
93 PIMAGE_NT_HEADERS Header
;
97 FIXME("(%p, %d, %p, %p): stub\n",
98 BaseAddress
, FileLength
, HeaderSum
, CheckSum
101 CalcSum
= (DWORD
)CalcCheckSum(0,
103 (FileLength
+ 1) / sizeof(WORD
));
105 Header
= RtlImageNtHeader(BaseAddress
);
106 HdrSum
= Header
->OptionalHeader
.CheckSum
;
108 /* Subtract image checksum from calculated checksum. */
109 /* fix low word of checksum */
110 if (LOWORD(CalcSum
) >= LOWORD(HdrSum
))
112 CalcSum
-= LOWORD(HdrSum
);
116 CalcSum
= ((LOWORD(CalcSum
) - LOWORD(HdrSum
)) & 0xFFFF) - 1;
119 /* fix high word of checksum */
120 if (LOWORD(CalcSum
) >= HIWORD(HdrSum
))
122 CalcSum
-= HIWORD(HdrSum
);
126 CalcSum
= ((LOWORD(CalcSum
) - HIWORD(HdrSum
)) & 0xFFFF) - 1;
129 /* add file length */
130 CalcSum
+= FileLength
;
133 *HeaderSum
= Header
->OptionalHeader
.CheckSum
;
138 /***********************************************************************
139 * MapFileAndCheckSumA (IMAGEHLP.@)
141 DWORD WINAPI
MapFileAndCheckSumA(
142 LPSTR Filename
, LPDWORD HeaderSum
, LPDWORD CheckSum
)
149 TRACE("(%s, %p, %p): stub\n",
150 debugstr_a(Filename
), HeaderSum
, CheckSum
153 hFile
= CreateFileA(Filename
,
155 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
158 FILE_ATTRIBUTE_NORMAL
,
160 if (hFile
== INVALID_HANDLE_VALUE
)
162 return CHECKSUM_OPEN_FAILURE
;
165 hMapping
= CreateFileMappingW(hFile
,
174 return CHECKSUM_MAP_FAILURE
;
177 BaseAddress
= MapViewOfFile(hMapping
,
182 if (BaseAddress
== 0)
184 CloseHandle(hMapping
);
186 return CHECKSUM_MAPVIEW_FAILURE
;
189 FileLength
= GetFileSize(hFile
,
192 CheckSumMappedFile(BaseAddress
,
197 UnmapViewOfFile(BaseAddress
);
198 CloseHandle(hMapping
);
204 /***********************************************************************
205 * MapFileAndCheckSumW (IMAGEHLP.@)
207 DWORD WINAPI
MapFileAndCheckSumW(
208 LPWSTR Filename
, LPDWORD HeaderSum
, LPDWORD CheckSum
)
215 TRACE("(%s, %p, %p): stub\n",
216 debugstr_w(Filename
), HeaderSum
, CheckSum
219 hFile
= CreateFileW(Filename
,
221 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
224 FILE_ATTRIBUTE_NORMAL
,
226 if (hFile
== INVALID_HANDLE_VALUE
)
228 return CHECKSUM_OPEN_FAILURE
;
231 hMapping
= CreateFileMappingW(hFile
,
240 return CHECKSUM_MAP_FAILURE
;
243 BaseAddress
= MapViewOfFile(hMapping
,
248 if (BaseAddress
== 0)
250 CloseHandle(hMapping
);
252 return CHECKSUM_MAPVIEW_FAILURE
;
255 FileLength
= GetFileSize(hFile
,
258 CheckSumMappedFile(BaseAddress
,
263 UnmapViewOfFile(BaseAddress
);
264 CloseHandle(hMapping
);
270 /***********************************************************************
271 * ReBaseImage (IMAGEHLP.@)
273 BOOL WINAPI
ReBaseImage(
274 LPSTR CurrentImageName
, LPSTR SymbolPath
, BOOL fReBase
,
275 BOOL fRebaseSysfileOk
, BOOL fGoingDown
, ULONG CheckImageSize
,
276 ULONG
*OldImageSize
, ULONG
*OldImageBase
, ULONG
*NewImageSize
,
277 ULONG
*NewImageBase
, ULONG TimeStamp
)
280 "(%s, %s, %d, %d, %d, %d, %p, %p, %p, %p, %d): stub\n",
281 debugstr_a(CurrentImageName
),debugstr_a(SymbolPath
), fReBase
,
282 fRebaseSysfileOk
, fGoingDown
, CheckImageSize
, OldImageSize
,
283 OldImageBase
, NewImageSize
, NewImageBase
, TimeStamp
285 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
289 /***********************************************************************
290 * RemovePrivateCvSymbolic (IMAGEHLP.@)
292 BOOL WINAPI
RemovePrivateCvSymbolic(
293 PCHAR DebugData
, PCHAR
*NewDebugData
, ULONG
*NewDebugSize
)
295 FIXME("(%p, %p, %p): stub\n",
296 DebugData
, NewDebugData
, NewDebugSize
298 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
302 /***********************************************************************
303 * RemoveRelocations (IMAGEHLP.@)
305 VOID WINAPI
RemoveRelocations(PCHAR ImageName
)
307 FIXME("(%p): stub\n", ImageName
);
308 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
311 /***********************************************************************
312 * SplitSymbols (IMAGEHLP.@)
314 BOOL WINAPI
SplitSymbols(
315 LPSTR ImageName
, LPSTR SymbolsPath
,
316 LPSTR SymbolFilePath
, DWORD Flags
)
318 FIXME("(%s, %s, %s, %d): stub\n",
319 debugstr_a(ImageName
), debugstr_a(SymbolsPath
),
320 debugstr_a(SymbolFilePath
), Flags
322 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
326 /***********************************************************************
327 * UpdateDebugInfoFile (IMAGEHLP.@)
329 BOOL WINAPI
UpdateDebugInfoFile(
330 LPSTR ImageFileName
, LPSTR SymbolPath
,
331 LPSTR DebugFilePath
, PIMAGE_NT_HEADERS NtHeaders
)
333 FIXME("(%s, %s, %s, %p): stub\n",
334 debugstr_a(ImageFileName
), debugstr_a(SymbolPath
),
335 debugstr_a(DebugFilePath
), NtHeaders
337 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
341 /***********************************************************************
342 * UpdateDebugInfoFileEx (IMAGEHLP.@)
344 BOOL WINAPI
UpdateDebugInfoFileEx(
345 LPSTR ImageFileName
, LPSTR SymbolPath
, LPSTR DebugFilePath
,
346 PIMAGE_NT_HEADERS NtHeaders
, DWORD OldChecksum
)
348 FIXME("(%s, %s, %s, %p, %d): stub\n",
349 debugstr_a(ImageFileName
), debugstr_a(SymbolPath
),
350 debugstr_a(DebugFilePath
), NtHeaders
, OldChecksum
352 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);