Fixed buffer overflow.
[wine/multimedia.git] / dlls / imagehlp / modify.c
blobf7df8de81d86a94f27f659e40b5dc8ca5a7b05cb
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 <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winreg.h"
26 #include "winternl.h"
27 #include "winerror.h"
28 #include "wine/debug.h"
29 #include "imagehlp.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);
57 return FALSE;
61 /***********************************************************************
62 * CheckSum (internal)
64 static WORD CalcCheckSum(
65 DWORD StartValue, LPVOID BaseAddress, DWORD WordCount)
67 LPWORD Ptr;
68 DWORD Sum;
69 DWORD i;
71 Sum = StartValue;
72 Ptr = (LPWORD)BaseAddress;
73 for (i = 0; i < WordCount; i++)
75 Sum += *Ptr;
76 if (HIWORD(Sum) != 0)
78 Sum = LOWORD(Sum) + HIWORD(Sum);
80 Ptr++;
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;
95 DWORD CalcSum;
96 DWORD HdrSum;
98 FIXME("(%p, %ld, %p, %p): stub\n",
99 BaseAddress, FileLength, HeaderSum, CheckSum
102 CalcSum = (DWORD)CalcCheckSum(0,
103 BaseAddress,
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);
115 else
117 CalcSum = ((LOWORD(CalcSum) - LOWORD(HdrSum)) & 0xFFFF) - 1;
120 /* fix high word of checksum */
121 if (LOWORD(CalcSum) >= HIWORD(HdrSum))
123 CalcSum -= HIWORD(HdrSum);
125 else
127 CalcSum = ((LOWORD(CalcSum) - HIWORD(HdrSum)) & 0xFFFF) - 1;
130 /* add file length */
131 CalcSum += FileLength;
133 *CheckSum = CalcSum;
134 *HeaderSum = Header->OptionalHeader.CheckSum;
136 return Header;
139 /***********************************************************************
140 * MapFileAndCheckSumA (IMAGEHLP.@)
142 DWORD WINAPI MapFileAndCheckSumA(
143 LPSTR Filename, LPDWORD HeaderSum, LPDWORD CheckSum)
145 HANDLE hFile;
146 HANDLE hMapping;
147 LPVOID BaseAddress;
148 DWORD FileLength;
150 TRACE("(%s, %p, %p): stub\n",
151 debugstr_a(Filename), HeaderSum, CheckSum
154 hFile = CreateFileA(Filename,
155 GENERIC_READ,
156 FILE_SHARE_READ | FILE_SHARE_WRITE,
157 NULL,
158 OPEN_EXISTING,
159 FILE_ATTRIBUTE_NORMAL,
161 if (hFile == INVALID_HANDLE_VALUE)
163 return CHECKSUM_OPEN_FAILURE;
166 hMapping = CreateFileMappingW(hFile,
167 NULL,
168 PAGE_READONLY,
171 NULL);
172 if (hMapping == 0)
174 CloseHandle(hFile);
175 return CHECKSUM_MAP_FAILURE;
178 BaseAddress = MapViewOfFile(hMapping,
179 FILE_MAP_READ,
183 if (hMapping == 0)
185 CloseHandle(hMapping);
186 CloseHandle(hFile);
187 return CHECKSUM_MAPVIEW_FAILURE;
190 FileLength = GetFileSize(hFile,
191 NULL);
193 CheckSumMappedFile(BaseAddress,
194 FileLength,
195 HeaderSum,
196 CheckSum);
198 UnmapViewOfFile(BaseAddress);
199 CloseHandle(hMapping);
200 CloseHandle(hFile);
202 return 0;
205 /***********************************************************************
206 * MapFileAndCheckSumW (IMAGEHLP.@)
208 DWORD WINAPI MapFileAndCheckSumW(
209 LPWSTR Filename, LPDWORD HeaderSum, LPDWORD CheckSum)
211 HANDLE hFile;
212 HANDLE hMapping;
213 LPVOID BaseAddress;
214 DWORD FileLength;
216 TRACE("(%s, %p, %p): stub\n",
217 debugstr_w(Filename), HeaderSum, CheckSum
220 hFile = CreateFileW(Filename,
221 GENERIC_READ,
222 FILE_SHARE_READ | FILE_SHARE_WRITE,
223 NULL,
224 OPEN_EXISTING,
225 FILE_ATTRIBUTE_NORMAL,
227 if (hFile == INVALID_HANDLE_VALUE)
229 return CHECKSUM_OPEN_FAILURE;
232 hMapping = CreateFileMappingW(hFile,
233 NULL,
234 PAGE_READONLY,
237 NULL);
238 if (hMapping == 0)
240 CloseHandle(hFile);
241 return CHECKSUM_MAP_FAILURE;
244 BaseAddress = MapViewOfFile(hMapping,
245 FILE_MAP_READ,
249 if (hMapping == 0)
251 CloseHandle(hMapping);
252 CloseHandle(hFile);
253 return CHECKSUM_MAPVIEW_FAILURE;
256 FileLength = GetFileSize(hFile,
257 NULL);
259 CheckSumMappedFile(BaseAddress,
260 FileLength,
261 HeaderSum,
262 CheckSum);
264 UnmapViewOfFile(BaseAddress);
265 CloseHandle(hMapping);
266 CloseHandle(hFile);
268 return 0;
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)
280 FIXME(
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);
287 return FALSE;
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);
300 return FALSE;
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);
324 return FALSE;
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);
339 return FALSE;
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);
354 return FALSE;