ReactOS 0.4.16-dev-117-g38f21f9
modify.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winternl.h"
#include "winerror.h"
#include "wine/debug.h"
#include "imagehlp.h"
Include dependency graph for modify.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (imagehlp)
 
static WORD CalcCheckSum (DWORD StartValue, LPVOID BaseAddress, DWORD WordCount)
 
BOOL WINAPI BindImage (PCSTR ImageName, PCSTR DllPath, PCSTR SymbolPath)
 
BOOL WINAPI BindImageEx (DWORD Flags, PCSTR ImageName, PCSTR DllPath, PCSTR SymbolPath, PIMAGEHLP_STATUS_ROUTINE StatusRoutine)
 
PIMAGE_NT_HEADERS WINAPI CheckSumMappedFile (LPVOID BaseAddress, DWORD FileLength, LPDWORD HeaderSum, LPDWORD CheckSum)
 
DWORD WINAPI MapFileAndCheckSumA (PCSTR Filename, PDWORD HeaderSum, PDWORD CheckSum)
 
DWORD WINAPI MapFileAndCheckSumW (PCWSTR Filename, PDWORD HeaderSum, PDWORD CheckSum)
 
BOOL WINAPI ReBaseImage (PCSTR CurrentImageName, PCSTR SymbolPath, BOOL fReBase, BOOL fRebaseSysfileOk, BOOL fGoingDown, ULONG CheckImageSize, ULONG *OldImageSize, ULONG_PTR *OldImageBase, ULONG *NewImageSize, ULONG_PTR *NewImageBase, ULONG TimeStamp)
 
BOOL WINAPI RemovePrivateCvSymbolic (PCHAR DebugData, PCHAR *NewDebugData, ULONG *NewDebugSize)
 
VOID WINAPI RemoveRelocations (PCHAR ImageName)
 
BOOL WINAPI SplitSymbols (PSTR ImageName, PCSTR SymbolsPath, PSTR SymbolFilePath, ULONG Flags)
 
BOOL WINAPI UpdateDebugInfoFile (PCSTR ImageFileName, PCSTR SymbolPath, PSTR DebugFilePath, PIMAGE_NT_HEADERS32 NtHeaders)
 
BOOL WINAPI UpdateDebugInfoFileEx (PCSTR ImageFileName, PCSTR SymbolPath, PSTR DebugFilePath, PIMAGE_NT_HEADERS32 NtHeaders, DWORD OldChecksum)
 

Function Documentation

◆ BindImage()

BOOL WINAPI BindImage ( PCSTR  ImageName,
PCSTR  DllPath,
PCSTR  SymbolPath 
)

Definition at line 40 of file modify.c.

42{
44}
#define NULL
Definition: types.h:112
BOOL WINAPI BindImageEx(DWORD Flags, PCSTR ImageName, PCSTR DllPath, PCSTR SymbolPath, PIMAGEHLP_STATUS_ROUTINE StatusRoutine)
Definition: modify.c:67
static const char const char * DllPath
Definition: image.c:34
static const char * ImageName
Definition: image.c:34
static const char const char const char * SymbolPath
Definition: image.c:35

Referenced by bind_image().

◆ BindImageEx()

BOOL WINAPI BindImageEx ( DWORD  Flags,
PCSTR  ImageName,
PCSTR  DllPath,
PCSTR  SymbolPath,
PIMAGEHLP_STATUS_ROUTINE  StatusRoutine 
)

Definition at line 67 of file modify.c.

70{
71 LOADED_IMAGE loaded_image;
72 const IMAGE_IMPORT_DESCRIPTOR *import_desc;
73 ULONG size;
74
75 FIXME("(%d, %s, %s, %s, %p): semi-stub\n",
78 );
79
80 if (!(MapAndLoad(ImageName, DllPath, &loaded_image, TRUE, TRUE))) return FALSE;
81
82 if (!(import_desc = RtlImageDirectoryEntryToData((HMODULE)loaded_image.MappedAddress, FALSE,
84 {
85 UnMapAndLoad(&loaded_image);
86 return TRUE; /* No imported modules means nothing to bind, so we're done. */
87 }
88
89 /* FIXME: Does native imagehlp support both 32-bit and 64-bit PE executables? */
90#ifdef _WIN64
92#else
94#endif
95 {
96 FIXME("Wrong architecture in PE header, unable to enumerate imports\n");
97 UnMapAndLoad(&loaded_image);
98 return TRUE;
99 }
100
101 for (; import_desc->Name && import_desc->FirstThunk; ++import_desc)
102 {
104 char dll_fullname[MAX_PATH];
105 const char *dll_name;
106
107 if (!(dll_name = ImageRvaToVa(loaded_image.FileHeader, loaded_image.MappedAddress,
108 import_desc->Name, 0)))
109 {
110 UnMapAndLoad(&loaded_image);
112 return FALSE;
113 }
114
115 if (StatusRoutine)
116 StatusRoutine(BindImportModule, ImageName, dll_name, 0, 0);
117
118 if (!SearchPathA(DllPath, dll_name, 0, sizeof(dll_fullname), dll_fullname, 0))
119 {
120 UnMapAndLoad(&loaded_image);
122 return FALSE;
123 }
124
125 if (!(thunk = ImageRvaToVa(loaded_image.FileHeader, loaded_image.MappedAddress,
126 import_desc->OriginalFirstThunk ? import_desc->OriginalFirstThunk :
127 import_desc->FirstThunk, 0)))
128 {
129 ERR("Can't grab thunk data of %s, going to next imported DLL\n", dll_name);
130 continue;
131 }
132
133 for (; thunk->u1.Ordinal; ++thunk)
134 {
135 /* Ignoring ordinal imports for now */
136 if(!IMAGE_SNAP_BY_ORDINAL(thunk->u1.Ordinal))
137 {
139
140 if (!(iibn = ImageRvaToVa(loaded_image.FileHeader, loaded_image.MappedAddress,
141 thunk->u1.AddressOfData, 0)))
142 {
143 ERR("Can't grab import by name info, skipping to next ordinal\n");
144 continue;
145 }
146
147 if (StatusRoutine)
148 StatusRoutine(BindImportProcedure, ImageName, dll_fullname, 0, (ULONG_PTR)iibn->Name);
149 }
150 }
151 }
152
153 UnMapAndLoad(&loaded_image);
154 return TRUE;
155}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define ERR(fmt,...)
Definition: precomp.h:57
PVOID WINAPI ImageRvaToVa(_In_ PIMAGE_NT_HEADERS, _In_ PVOID, _In_ ULONG, _In_opt_ PIMAGE_SECTION_HEADER *)
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define SetLastError(x)
Definition: compat.h:752
#define RtlImageDirectoryEntryToData
Definition: compat.h:809
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI MapAndLoad(PCSTR pszImageName, PCSTR pszDllPath, PLOADED_IMAGE pLoadedImage, BOOL bDotDll, BOOL bReadOnly)
Definition: access.c:131
BOOL WINAPI UnMapAndLoad(PLOADED_IMAGE pLoadedImage)
Definition: access.c:228
DWORD WINAPI SearchPathA(IN LPCSTR lpPath OPTIONAL, IN LPCSTR lpFileName, IN LPCSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPSTR lpBuffer, OUT LPSTR *lpFilePart OPTIONAL)
Definition: path.c:1123
GLsizeiptr size
Definition: glext.h:5919
@ BindImportModule
Definition: imagehlp.h:105
@ BindImportProcedure
Definition: imagehlp.h:106
#define debugstr_a
Definition: kernel32.h:31
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static const char const char const char PIMAGEHLP_STATUS_ROUTINE StatusRoutine
Definition: image.c:35
#define IMAGE_SNAP_BY_ORDINAL(Ordinal)
Definition: ntimage.h:567
#define IMAGE_NT_OPTIONAL_HDR32_MAGIC
Definition: ntimage.h:376
#define IMAGE_NT_OPTIONAL_HDR64_MAGIC
Definition: ntimage.h:377
#define IMAGE_DIRECTORY_ENTRY_IMPORT
Definition: pedump.c:260
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
PUCHAR MappedAddress
Definition: dbghelp.h:101
PIMAGE_NT_HEADERS32 FileHeader
Definition: dbghelp.h:105
Definition: cproxy.c:248
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define ERROR_INVALID_ACCESS
Definition: winerror.h:115
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by BindImage().

◆ CalcCheckSum()

static WORD CalcCheckSum ( DWORD  StartValue,
LPVOID  BaseAddress,
DWORD  WordCount 
)
static

Definition at line 161 of file modify.c.

163{
164 LPWORD Ptr;
165 DWORD Sum;
166 DWORD i;
167
168 Sum = StartValue;
170 for (i = 0; i < WordCount; i++)
171 {
172 Sum += *Ptr;
173 if (HIWORD(Sum) != 0)
174 {
175 Sum = LOWORD(Sum) + HIWORD(Sum);
176 }
177 Ptr++;
178 }
179
180 return (WORD)(LOWORD(Sum) + HIWORD(Sum));
181}
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define LOWORD(l)
Definition: pedump.c:82
uint16_t * LPWORD
Definition: typedefs.h:56
#define HIWORD(l)
Definition: typedefs.h:247

Referenced by CheckSumMappedFile().

◆ CheckSumMappedFile()

PIMAGE_NT_HEADERS WINAPI CheckSumMappedFile ( LPVOID  BaseAddress,
DWORD  FileLength,
LPDWORD  HeaderSum,
LPDWORD  CheckSum 
)

Definition at line 187 of file modify.c.

190{
192 DWORD CalcSum;
193 DWORD HdrSum;
194
195 TRACE("(%p, %d, %p, %p)\n", BaseAddress, FileLength, HeaderSum, CheckSum);
196
197 CalcSum = CalcCheckSum(0, BaseAddress, (FileLength + 1) / sizeof(WORD));
199
200 if (!header)
201 return NULL;
202
203 *HeaderSum = HdrSum = header->OptionalHeader.CheckSum;
204
205 /* Subtract image checksum from calculated checksum. */
206 /* fix low word of checksum */
207 if (LOWORD(CalcSum) >= LOWORD(HdrSum))
208 {
209 CalcSum -= LOWORD(HdrSum);
210 }
211 else
212 {
213 CalcSum = ((LOWORD(CalcSum) - LOWORD(HdrSum)) & 0xFFFF) - 1;
214 }
215
216 /* fix high word of checksum */
217 if (LOWORD(CalcSum) >= HIWORD(HdrSum))
218 {
219 CalcSum -= HIWORD(HdrSum);
220 }
221 else
222 {
223 CalcSum = ((LOWORD(CalcSum) - HIWORD(HdrSum)) & 0xFFFF) - 1;
224 }
225
226 /* add file length */
227 CalcSum += FileLength;
228
229 *CheckSum = CalcSum;
230
231 return header;
232}
#define RtlImageNtHeader
Definition: compat.h:806
static WORD CalcCheckSum(DWORD StartValue, LPVOID BaseAddress, DWORD WordCount)
Definition: modify.c:161
_Out_ PNDIS_HANDLE _Out_ PUINT FileLength
Definition: ndis.h:3228
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by IMAGEHLP_RecalculateChecksum(), MapFileAndCheckSumA(), and MapFileAndCheckSumW().

◆ MapFileAndCheckSumA()

DWORD WINAPI MapFileAndCheckSumA ( PCSTR  Filename,
PDWORD  HeaderSum,
PDWORD  CheckSum 
)

Definition at line 237 of file modify.c.

239{
241 HANDLE hMapping;
244
245 TRACE("(%s, %p, %p): stub\n",
246 debugstr_a(Filename), HeaderSum, CheckSum
247 );
248
252 NULL,
255 0);
257 {
259 }
260
261 hMapping = CreateFileMappingW(hFile,
262 NULL,
264 0,
265 0,
266 NULL);
267 if (hMapping == 0)
268 {
271 }
272
273 BaseAddress = MapViewOfFile(hMapping,
275 0,
276 0,
277 0);
278 if (BaseAddress == 0)
279 {
280 CloseHandle(hMapping);
283 }
284
286 NULL);
287
290 HeaderSum,
291 CheckSum);
292
294 CloseHandle(hMapping);
296
297 return 0;
298}
#define CloseHandle
Definition: compat.h:739
#define PAGE_READONLY
Definition: compat.h:138
#define UnmapViewOfFile
Definition: compat.h:746
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:744
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define GENERIC_READ
Definition: compat.h:135
#define FILE_MAP_READ
Definition: compat.h:776
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define MapViewOfFile
Definition: compat.h:745
#define FILE_SHARE_READ
Definition: compat.h:136
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
Definition: fatprocs.h:940
PIMAGE_NT_HEADERS WINAPI CheckSumMappedFile(LPVOID BaseAddress, DWORD FileLength, LPDWORD HeaderSum, LPDWORD CheckSum)
Definition: modify.c:187
#define CHECKSUM_MAPVIEW_FAILURE
Definition: imagehlp.h:51
#define CHECKSUM_OPEN_FAILURE
Definition: imagehlp.h:49
#define CHECKSUM_MAP_FAILURE
Definition: imagehlp.h:50
_In_ HANDLE hFile
Definition: mswsock.h:90
#define FILE_SHARE_WRITE
Definition: nt_native.h:681

◆ MapFileAndCheckSumW()

DWORD WINAPI MapFileAndCheckSumW ( PCWSTR  Filename,
PDWORD  HeaderSum,
PDWORD  CheckSum 
)

Definition at line 303 of file modify.c.

305{
307 HANDLE hMapping;
310
311 TRACE("(%s, %p, %p): stub\n",
312 debugstr_w(Filename), HeaderSum, CheckSum
313 );
314
318 NULL,
321 0);
323 {
325 }
326
327 hMapping = CreateFileMappingW(hFile,
328 NULL,
330 0,
331 0,
332 NULL);
333 if (hMapping == 0)
334 {
337 }
338
339 BaseAddress = MapViewOfFile(hMapping,
341 0,
342 0,
343 0);
344 if (BaseAddress == 0)
345 {
346 CloseHandle(hMapping);
349 }
350
352 NULL);
353
356 HeaderSum,
357 CheckSum);
358
360 CloseHandle(hMapping);
362
363 return 0;
364}
#define CreateFileW
Definition: compat.h:741
#define debugstr_w
Definition: kernel32.h:32

◆ ReBaseImage()

BOOL WINAPI ReBaseImage ( PCSTR  CurrentImageName,
PCSTR  SymbolPath,
BOOL  fReBase,
BOOL  fRebaseSysfileOk,
BOOL  fGoingDown,
ULONG  CheckImageSize,
ULONG OldImageSize,
ULONG_PTR OldImageBase,
ULONG NewImageSize,
ULONG_PTR NewImageBase,
ULONG  TimeStamp 
)

Definition at line 369 of file modify.c.

374{
375 FIXME(
376 "(%s, %s, %d, %d, %d, %d, %p, %p, %p, %p, %d): stub\n",
377 debugstr_a(CurrentImageName),debugstr_a(SymbolPath), fReBase,
378 fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize,
379 OldImageBase, NewImageSize, NewImageBase, TimeStamp
380 );
382 return FALSE;
383}
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102

◆ RemovePrivateCvSymbolic()

BOOL WINAPI RemovePrivateCvSymbolic ( PCHAR  DebugData,
PCHAR NewDebugData,
ULONG NewDebugSize 
)

Definition at line 388 of file modify.c.

390{
391 FIXME("(%p, %p, %p): stub\n",
392 DebugData, NewDebugData, NewDebugSize
393 );
395 return FALSE;
396}

◆ RemoveRelocations()

VOID WINAPI RemoveRelocations ( PCHAR  ImageName)

Definition at line 401 of file modify.c.

402{
403 FIXME("(%p): stub\n", ImageName);
405}

◆ SplitSymbols()

BOOL WINAPI SplitSymbols ( PSTR  ImageName,
PCSTR  SymbolsPath,
PSTR  SymbolFilePath,
ULONG  Flags 
)

Definition at line 410 of file modify.c.

413{
414 FIXME("(%s, %s, %s, %d): stub\n",
415 debugstr_a(ImageName), debugstr_a(SymbolsPath),
416 debugstr_a(SymbolFilePath), Flags
417 );
419 return FALSE;
420}

◆ UpdateDebugInfoFile()

BOOL WINAPI UpdateDebugInfoFile ( PCSTR  ImageFileName,
PCSTR  SymbolPath,
PSTR  DebugFilePath,
PIMAGE_NT_HEADERS32  NtHeaders 
)

Definition at line 425 of file modify.c.

428{
429 FIXME("(%s, %s, %s, %p): stub\n",
430 debugstr_a(ImageFileName), debugstr_a(SymbolPath),
431 debugstr_a(DebugFilePath), NtHeaders
432 );
434 return FALSE;
435}

◆ UpdateDebugInfoFileEx()

BOOL WINAPI UpdateDebugInfoFileEx ( PCSTR  ImageFileName,
PCSTR  SymbolPath,
PSTR  DebugFilePath,
PIMAGE_NT_HEADERS32  NtHeaders,
DWORD  OldChecksum 
)

Definition at line 440 of file modify.c.

443{
444 FIXME("(%s, %s, %s, %p, %d): stub\n",
445 debugstr_a(ImageFileName), debugstr_a(SymbolPath),
446 debugstr_a(DebugFilePath), NtHeaders, OldChecksum
447 );
449 return FALSE;
450}

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( imagehlp  )