Added LGPL standard comment, and copyright notices where necessary.
[wine/multimedia.git] / dlls / imagehlp / modify.c
blob25fef4499846de1d24551813c807a6ed96c5c58c
1 /*
2 * IMAGEHLP library
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
21 #include "winbase.h"
22 #include "winerror.h"
23 #include "windef.h"
24 #include "wine/debug.h"
25 #include "imagehlp.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);
53 return FALSE;
57 /***********************************************************************
58 * CheckSum (internal)
60 static WORD CalcCheckSum(
61 DWORD StartValue, LPVOID BaseAddress, DWORD WordCount)
63 LPWORD Ptr;
64 DWORD Sum;
65 DWORD i;
67 Sum = StartValue;
68 Ptr = (LPWORD)BaseAddress;
69 for (i = 0; i < WordCount; i++)
71 Sum += *Ptr;
72 if (HIWORD(Sum) != 0)
74 Sum = LOWORD(Sum) + HIWORD(Sum);
76 Ptr++;
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;
91 DWORD CalcSum;
92 DWORD HdrSum;
94 FIXME("(%p, %ld, %p, %p): stub\n",
95 BaseAddress, FileLength, HeaderSum, CheckSum
98 CalcSum = (DWORD)CalcCheckSum(0,
99 BaseAddress,
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);
111 else
113 CalcSum = ((LOWORD(CalcSum) - LOWORD(HdrSum)) & 0xFFFF) - 1;
116 /* fix high word of checksum */
117 if (LOWORD(CalcSum) >= HIWORD(HdrSum))
119 CalcSum -= HIWORD(HdrSum);
121 else
123 CalcSum = ((LOWORD(CalcSum) - HIWORD(HdrSum)) & 0xFFFF) - 1;
126 /* add file length */
127 CalcSum += FileLength;
129 *CheckSum = CalcSum;
130 *HeaderSum = Header->OptionalHeader.CheckSum;
132 return Header;
135 /***********************************************************************
136 * MapFileAndCheckSumA (IMAGEHLP.@)
138 DWORD WINAPI MapFileAndCheckSumA(
139 LPSTR Filename, LPDWORD HeaderSum, LPDWORD CheckSum)
141 HANDLE hFile;
142 HANDLE hMapping;
143 LPVOID BaseAddress;
144 DWORD FileLength;
146 TRACE("(%s, %p, %p): stub\n",
147 debugstr_a(Filename), HeaderSum, CheckSum
150 hFile = CreateFileA(Filename,
151 GENERIC_READ,
152 FILE_SHARE_READ | FILE_SHARE_WRITE,
153 NULL,
154 OPEN_EXISTING,
155 FILE_ATTRIBUTE_NORMAL,
157 if (hFile == INVALID_HANDLE_VALUE)
159 return CHECKSUM_OPEN_FAILURE;
162 hMapping = CreateFileMappingW(hFile,
163 NULL,
164 PAGE_READONLY,
167 NULL);
168 if (hMapping == 0)
170 CloseHandle(hFile);
171 return CHECKSUM_MAP_FAILURE;
174 BaseAddress = MapViewOfFile(hMapping,
175 FILE_MAP_READ,
179 if (hMapping == 0)
181 CloseHandle(hMapping);
182 CloseHandle(hFile);
183 return CHECKSUM_MAPVIEW_FAILURE;
186 FileLength = GetFileSize(hFile,
187 NULL);
189 CheckSumMappedFile(BaseAddress,
190 FileLength,
191 HeaderSum,
192 CheckSum);
194 UnmapViewOfFile(BaseAddress);
195 CloseHandle(hMapping);
196 CloseHandle(hFile);
198 return 0;
201 /***********************************************************************
202 * MapFileAndCheckSumW (IMAGEHLP.@)
204 DWORD WINAPI MapFileAndCheckSumW(
205 LPWSTR Filename, LPDWORD HeaderSum, LPDWORD CheckSum)
207 HANDLE hFile;
208 HANDLE hMapping;
209 LPVOID BaseAddress;
210 DWORD FileLength;
212 TRACE("(%s, %p, %p): stub\n",
213 debugstr_w(Filename), HeaderSum, CheckSum
216 hFile = CreateFileW(Filename,
217 GENERIC_READ,
218 FILE_SHARE_READ | FILE_SHARE_WRITE,
219 NULL,
220 OPEN_EXISTING,
221 FILE_ATTRIBUTE_NORMAL,
223 if (hFile == INVALID_HANDLE_VALUE)
225 return CHECKSUM_OPEN_FAILURE;
228 hMapping = CreateFileMappingW(hFile,
229 NULL,
230 PAGE_READONLY,
233 NULL);
234 if (hMapping == 0)
236 CloseHandle(hFile);
237 return CHECKSUM_MAP_FAILURE;
240 BaseAddress = MapViewOfFile(hMapping,
241 FILE_MAP_READ,
245 if (hMapping == 0)
247 CloseHandle(hMapping);
248 CloseHandle(hFile);
249 return CHECKSUM_MAPVIEW_FAILURE;
252 FileLength = GetFileSize(hFile,
253 NULL);
255 CheckSumMappedFile(BaseAddress,
256 FileLength,
257 HeaderSum,
258 CheckSum);
260 UnmapViewOfFile(BaseAddress);
261 CloseHandle(hMapping);
262 CloseHandle(hFile);
264 return 0;
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)
276 FIXME(
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);
283 return FALSE;
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);
296 return FALSE;
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);
320 return FALSE;
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);
335 return FALSE;
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);
350 return FALSE;