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
24 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(imagehlp
);
29 static WORD
CalcCheckSum(DWORD StartValue
, LPVOID BaseAddress
, DWORD WordCount
);
32 /***********************************************************************
33 * BindImage (IMAGEHLP.@)
35 BOOL WINAPI
BindImage(
36 LPSTR ImageName
, LPSTR DllPath
, LPSTR SymbolPath
)
38 return BindImageEx(0, ImageName
, DllPath
, SymbolPath
, NULL
);
41 /***********************************************************************
42 * BindImageEx (IMAGEHLP.@)
44 BOOL WINAPI
BindImageEx(
45 DWORD Flags
, LPSTR ImageName
, LPSTR DllPath
, LPSTR SymbolPath
,
46 PIMAGEHLP_STATUS_ROUTINE StatusRoutine
)
48 FIXME("(%ld, %s, %s, %s, %p): stub\n",
49 Flags
, debugstr_a(ImageName
), debugstr_a(DllPath
),
50 debugstr_a(SymbolPath
), StatusRoutine
52 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
57 /***********************************************************************
60 static WORD
CalcCheckSum(
61 DWORD StartValue
, LPVOID BaseAddress
, DWORD WordCount
)
68 Ptr
= (LPWORD
)BaseAddress
;
69 for (i
= 0; i
< WordCount
; i
++)
74 Sum
= LOWORD(Sum
) + HIWORD(Sum
);
79 return (WORD
)(LOWORD(Sum
) + HIWORD(Sum
));
83 /***********************************************************************
84 * CheckSumMappedFile (IMAGEHLP.@)
86 PIMAGE_NT_HEADERS WINAPI
CheckSumMappedFile(
87 LPVOID BaseAddress
, DWORD FileLength
,
88 LPDWORD HeaderSum
, LPDWORD CheckSum
)
90 PIMAGE_NT_HEADERS Header
;
94 FIXME("(%p, %ld, %p, %p): stub\n",
95 BaseAddress
, FileLength
, HeaderSum
, CheckSum
98 CalcSum
= (DWORD
)CalcCheckSum(0,
100 (FileLength
+ 1) / sizeof(WORD
));
102 Header
= ImageNtHeader(BaseAddress
);
103 HdrSum
= Header
->OptionalHeader
.CheckSum
;
105 /* Subtract image checksum from calculated checksum. */
106 /* fix low word of checksum */
107 if (LOWORD(CalcSum
) >= LOWORD(HdrSum
))
109 CalcSum
-= LOWORD(HdrSum
);
113 CalcSum
= ((LOWORD(CalcSum
) - LOWORD(HdrSum
)) & 0xFFFF) - 1;
116 /* fix high word of checksum */
117 if (LOWORD(CalcSum
) >= HIWORD(HdrSum
))
119 CalcSum
-= HIWORD(HdrSum
);
123 CalcSum
= ((LOWORD(CalcSum
) - HIWORD(HdrSum
)) & 0xFFFF) - 1;
126 /* add file length */
127 CalcSum
+= FileLength
;
130 *HeaderSum
= Header
->OptionalHeader
.CheckSum
;
135 /***********************************************************************
136 * MapFileAndCheckSumA (IMAGEHLP.@)
138 DWORD WINAPI
MapFileAndCheckSumA(
139 LPSTR Filename
, LPDWORD HeaderSum
, LPDWORD CheckSum
)
146 TRACE("(%s, %p, %p): stub\n",
147 debugstr_a(Filename
), HeaderSum
, CheckSum
150 hFile
= CreateFileA(Filename
,
152 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
155 FILE_ATTRIBUTE_NORMAL
,
157 if (hFile
== INVALID_HANDLE_VALUE
)
159 return CHECKSUM_OPEN_FAILURE
;
162 hMapping
= CreateFileMappingW(hFile
,
171 return CHECKSUM_MAP_FAILURE
;
174 BaseAddress
= MapViewOfFile(hMapping
,
181 CloseHandle(hMapping
);
183 return CHECKSUM_MAPVIEW_FAILURE
;
186 FileLength
= GetFileSize(hFile
,
189 CheckSumMappedFile(BaseAddress
,
194 UnmapViewOfFile(BaseAddress
);
195 CloseHandle(hMapping
);
201 /***********************************************************************
202 * MapFileAndCheckSumW (IMAGEHLP.@)
204 DWORD WINAPI
MapFileAndCheckSumW(
205 LPWSTR Filename
, LPDWORD HeaderSum
, LPDWORD CheckSum
)
212 TRACE("(%s, %p, %p): stub\n",
213 debugstr_w(Filename
), HeaderSum
, CheckSum
216 hFile
= CreateFileW(Filename
,
218 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
221 FILE_ATTRIBUTE_NORMAL
,
223 if (hFile
== INVALID_HANDLE_VALUE
)
225 return CHECKSUM_OPEN_FAILURE
;
228 hMapping
= CreateFileMappingW(hFile
,
237 return CHECKSUM_MAP_FAILURE
;
240 BaseAddress
= MapViewOfFile(hMapping
,
247 CloseHandle(hMapping
);
249 return CHECKSUM_MAPVIEW_FAILURE
;
252 FileLength
= GetFileSize(hFile
,
255 CheckSumMappedFile(BaseAddress
,
260 UnmapViewOfFile(BaseAddress
);
261 CloseHandle(hMapping
);
267 /***********************************************************************
268 * ReBaseImage (IMAGEHLP.@)
270 BOOL WINAPI
ReBaseImage(
271 LPSTR CurrentImageName
, LPSTR SymbolPath
, BOOL fReBase
,
272 BOOL fRebaseSysfileOk
, BOOL fGoingDown
, ULONG CheckImageSize
,
273 ULONG
*OldImageSize
, ULONG
*OldImageBase
, ULONG
*NewImageSize
,
274 ULONG
*NewImageBase
, ULONG TimeStamp
)
277 "(%s, %s, %d, %d, %d, %ld, %p, %p, %p, %p, %ld): stub\n",
278 debugstr_a(CurrentImageName
),debugstr_a(SymbolPath
), fReBase
,
279 fRebaseSysfileOk
, fGoingDown
, CheckImageSize
, OldImageSize
,
280 OldImageBase
, NewImageSize
, NewImageBase
, TimeStamp
282 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
286 /***********************************************************************
287 * RemovePrivateCvSymbolic (IMAGEHLP.@)
289 BOOL WINAPI
RemovePrivateCvSymbolic(
290 PCHAR DebugData
, PCHAR
*NewDebugData
, ULONG
*NewDebugSize
)
292 FIXME("(%p, %p, %p): stub\n",
293 DebugData
, NewDebugData
, NewDebugSize
295 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
299 /***********************************************************************
300 * RemoveRelocations (IMAGEHLP.@)
302 VOID WINAPI
RemoveRelocations(PCHAR ImageName
)
304 FIXME("(%p): stub\n", ImageName
);
305 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
308 /***********************************************************************
309 * SplitSymbols (IMAGEHLP.@)
311 BOOL WINAPI
SplitSymbols(
312 LPSTR ImageName
, LPSTR SymbolsPath
,
313 LPSTR SymbolFilePath
, DWORD Flags
)
315 FIXME("(%s, %s, %s, %ld): stub\n",
316 debugstr_a(ImageName
), debugstr_a(SymbolsPath
),
317 debugstr_a(SymbolFilePath
), Flags
319 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
323 /***********************************************************************
324 * UpdateDebugInfoFile (IMAGEHLP.@)
326 BOOL WINAPI
UpdateDebugInfoFile(
327 LPSTR ImageFileName
, LPSTR SymbolPath
,
328 LPSTR DebugFilePath
, PIMAGE_NT_HEADERS NtHeaders
)
330 FIXME("(%s, %s, %s, %p): stub\n",
331 debugstr_a(ImageFileName
), debugstr_a(SymbolPath
),
332 debugstr_a(DebugFilePath
), NtHeaders
334 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
338 /***********************************************************************
339 * UpdateDebugInfoFileEx (IMAGEHLP.@)
341 BOOL WINAPI
UpdateDebugInfoFileEx(
342 LPSTR ImageFileName
, LPSTR SymbolPath
, LPSTR DebugFilePath
,
343 PIMAGE_NT_HEADERS NtHeaders
, DWORD OldChecksum
)
345 FIXME("(%s, %s, %s, %p, %ld): stub\n",
346 debugstr_a(ImageFileName
), debugstr_a(SymbolPath
),
347 debugstr_a(DebugFilePath
), NtHeaders
, OldChecksum
349 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);