ReactOS 0.4.17-dev-966-gf06eace
modify.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winternl.h"
#include "winerror.h"
#include "winver.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, const char *module, const char *dll_path, const char *symbol_path, PIMAGEHLP_STATUS_ROUTINE cb)
 
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 39 of file modify.c.

41{
42 return BindImageEx(0, ImageName, DllPath, SymbolPath, NULL);
43}
#define NULL
Definition: types.h:112
BOOL WINAPI BindImageEx(DWORD flags, const char *module, const char *dll_path, const char *symbol_path, PIMAGEHLP_STATUS_ROUTINE cb)
Definition: modify.c:48

Referenced by bind_image().

◆ BindImageEx()

BOOL WINAPI BindImageEx ( DWORD  flags,
const char *  module,
const char *  dll_path,
const char *  symbol_path,
PIMAGEHLP_STATUS_ROUTINE  cb 
)

Definition at line 48 of file modify.c.

50{
51 const IMAGE_IMPORT_DESCRIPTOR *import;
53 ULONG size;
54
55 TRACE("flags %#lx, module %s, dll_path %s, symbol_path %s, cb %p.\n",
56 flags, debugstr_a(module), debugstr_a(dll_path), debugstr_a(symbol_path), cb);
57
58 if (!(flags & BIND_NO_UPDATE))
59 FIXME("Image modification is not implemented.\n");
60 if (flags & ~BIND_NO_UPDATE)
61 FIXME("Ignoring flags %#lx.\n", flags);
62
63 if (!MapAndLoad(module, dll_path, &image, TRUE, TRUE))
64 return FALSE;
65
67 {
69 return TRUE; /* no imports */
70 }
71
72 if (image.FileHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR_MAGIC)
73 {
74 FIXME("Unhandled architecture %#x.\n", image.FileHeader->OptionalHeader.Magic);
76 return TRUE;
77 }
78
79 for (; import->Name && import->FirstThunk; ++import)
80 {
81 char full_path[MAX_PATH];
82 IMAGE_THUNK_DATA *thunk;
83 const char *dll_name;
84 DWORD thunk_rva;
85
86 if (!(dll_name = ImageRvaToVa(image.FileHeader, image.MappedAddress, import->Name, 0)))
87 {
88 ERR("Failed to get VA for import name RVA %#lx.\n", import->Name);
89 continue;
90 }
91
92 if (cb) cb(BindImportModule, module, dll_name, 0, 0);
93
94 if (!SearchPathA(dll_path, dll_name, 0, sizeof(full_path), full_path, 0))
95 {
96 ERR("Import %s was not found.\n", debugstr_a(dll_path));
97 continue;
98 }
99
100 thunk_rva = import->OriginalFirstThunk ? import->OriginalFirstThunk : import->FirstThunk;
101 if (!(thunk = ImageRvaToVa(image.FileHeader, image.MappedAddress, thunk_rva, 0)))
102 {
103 ERR("Failed to get VA for import thunk RVA %#lx.\n", thunk_rva);
104 continue;
105 }
106
107 for (; thunk->u1.Ordinal; ++thunk)
108 {
109 if (IMAGE_SNAP_BY_ORDINAL(thunk->u1.Ordinal))
110 {
111 /* FIXME: We apparently need to subtract the actual module's
112 * ordinal base. */
113 FIXME("Ordinal imports are not implemented.\n");
114 }
115 else
116 {
118
119 if (!(name = ImageRvaToVa(image.FileHeader, image.MappedAddress, thunk->u1.AddressOfData, 0)))
120 {
121 ERR("Failed to get VA for name RVA %#Ix.\n", (size_t)thunk->u1.AddressOfData);
122 continue;
123 }
124
125 if (cb) cb(BindImportProcedure, module, full_path, 0, (ULONG_PTR)name->Name);
126 }
127 }
128 }
129
131 return TRUE;
132}
#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 MAX_PATH
Definition: compat.h:34
BOOL WINAPI MapAndLoad(PCSTR pszImageName, PCSTR pszDllPath, PLOADED_IMAGE pLoadedImage, BOOL bDotDll, BOOL bReadOnly)
Definition: access.c:132
BOOL WINAPI UnMapAndLoad(PLOADED_IMAGE pLoadedImage)
Definition: access.c:227
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:1222
static MonoProfilerRuntimeShutdownBeginCallback cb
Definition: metahost.c:118
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
GLbitfield flags
Definition: glext.h:7161
#define BIND_NO_UPDATE
Definition: imagehlp.h:35
@ BindImportModule
Definition: imagehlp.h:105
@ BindImportProcedure
Definition: imagehlp.h:106
#define debugstr_a
Definition: kernel32.h:31
#define IMAGE_SNAP_BY_ORDINAL(Ordinal)
Definition: ntimage.h:567
#define IMAGE_NT_OPTIONAL_HDR_MAGIC
Definition: ntimage.h:387
PVOID WINAPI ImageDirectoryEntryToData(PVOID base, BOOLEAN image, USHORT dir, PULONG size)
Definition: pe_module.c:972
#define IMAGE_DIRECTORY_ENTRY_IMPORT
Definition: pedump.c:260
#define TRACE(s)
Definition: solgame.cpp:4
union _IMAGE_THUNK_DATA32::@2568 u1
Definition: image.c:84
Definition: name.c:39
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59

Referenced by BindImage(), and test_bind_image_ex().

◆ CalcCheckSum()

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

Definition at line 138 of file modify.c.

140{
141 LPWORD Ptr;
142 DWORD Sum;
143 DWORD i;
144
145 Sum = StartValue;
147 for (i = 0; i < WordCount; i++)
148 {
149 Sum += *Ptr;
150 if (HIWORD(Sum) != 0)
151 {
152 Sum = LOWORD(Sum) + HIWORD(Sum);
153 }
154 Ptr++;
155 }
156
157 return (WORD)(LOWORD(Sum) + HIWORD(Sum));
158}
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 _Pre_valid_ PVOID * BaseAddress
Definition: mmfuncs.h:408
#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 164 of file modify.c.

167{
169 DWORD CalcSum;
170 DWORD HdrSum;
171
172 TRACE("(%p, %ld, %p, %p)\n", BaseAddress, FileLength, HeaderSum, CheckSum);
173
174 CalcSum = CalcCheckSum(0, BaseAddress, (FileLength + 1) / sizeof(WORD));
176
177 if (!header)
178 return NULL;
179
180 *HeaderSum = HdrSum = header->OptionalHeader.CheckSum;
181
182 /* Subtract image checksum from calculated checksum. */
183 /* fix low word of checksum */
184 if (LOWORD(CalcSum) >= LOWORD(HdrSum))
185 {
186 CalcSum -= LOWORD(HdrSum);
187 }
188 else
189 {
190 CalcSum = ((LOWORD(CalcSum) - LOWORD(HdrSum)) & 0xFFFF) - 1;
191 }
192
193 /* fix high word of checksum */
194 if (LOWORD(CalcSum) >= HIWORD(HdrSum))
195 {
196 CalcSum -= HIWORD(HdrSum);
197 }
198 else
199 {
200 CalcSum = ((LOWORD(CalcSum) - HIWORD(HdrSum)) & 0xFFFF) - 1;
201 }
202
203 /* add file length */
204 CalcSum += FileLength;
205
206 *CheckSum = CalcSum;
207
208 return header;
209}
#define RtlImageNtHeader
Definition: compat.h:806
static WORD CalcCheckSum(DWORD StartValue, LPVOID BaseAddress, DWORD WordCount)
Definition: modify.c:138
_Out_ PNDIS_HANDLE _Out_ PUINT FileLength
Definition: ndis.h:3228

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

◆ MapFileAndCheckSumA()

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

Definition at line 214 of file modify.c.

216{
218 HANDLE hMapping;
221
222 TRACE("(%s, %p, %p): stub\n",
223 debugstr_a(Filename), HeaderSum, CheckSum
224 );
225
229 NULL,
232 0);
234 {
236 }
237
238 hMapping = CreateFileMappingW(hFile,
239 NULL,
241 0,
242 0,
243 NULL);
244 if (hMapping == 0)
245 {
248 }
249
250 BaseAddress = MapViewOfFile(hMapping,
252 0,
253 0,
254 0);
255 if (BaseAddress == 0)
256 {
257 CloseHandle(hMapping);
260 }
261
263 NULL);
264
267 HeaderSum,
268 CheckSum);
269
271 CloseHandle(hMapping);
273
274 return 0;
275}
#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:164
#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 280 of file modify.c.

282{
284 HANDLE hMapping;
287
288 TRACE("(%s, %p, %p): stub\n",
289 debugstr_w(Filename), HeaderSum, CheckSum
290 );
291
295 NULL,
298 0);
300 {
302 }
303
304 hMapping = CreateFileMappingW(hFile,
305 NULL,
307 0,
308 0,
309 NULL);
310 if (hMapping == 0)
311 {
314 }
315
316 BaseAddress = MapViewOfFile(hMapping,
318 0,
319 0,
320 0);
321 if (BaseAddress == 0)
322 {
323 CloseHandle(hMapping);
326 }
327
329 NULL);
330
333 HeaderSum,
334 CheckSum);
335
337 CloseHandle(hMapping);
339
340 return 0;
341}
#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 346 of file modify.c.

351{
352 FIXME(
353 "(%s, %s, %d, %d, %d, %ld, %p, %p, %p, %p, %ld): stub\n",
354 debugstr_a(CurrentImageName),debugstr_a(SymbolPath), fReBase,
355 fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize,
356 OldImageBase, NewImageSize, NewImageBase, TimeStamp
357 );
359 return FALSE;
360}
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define SetLastError(x)
Definition: compat.h:752

◆ RemovePrivateCvSymbolic()

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

Definition at line 365 of file modify.c.

367{
368 FIXME("(%p, %p, %p): stub\n",
369 DebugData, NewDebugData, NewDebugSize
370 );
372 return FALSE;
373}

◆ RemoveRelocations()

VOID WINAPI RemoveRelocations ( PCHAR  ImageName)

Definition at line 378 of file modify.c.

379{
380 FIXME("(%p): stub\n", ImageName);
382}

◆ SplitSymbols()

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

Definition at line 387 of file modify.c.

390{
391 FIXME("(%s, %s, %s, %ld): stub\n",
392 debugstr_a(ImageName), debugstr_a(SymbolsPath),
393 debugstr_a(SymbolFilePath), Flags
394 );
396 return FALSE;
397}
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245

◆ UpdateDebugInfoFile()

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

Definition at line 402 of file modify.c.

405{
406 FIXME("(%s, %s, %s, %p): stub\n",
407 debugstr_a(ImageFileName), debugstr_a(SymbolPath),
408 debugstr_a(DebugFilePath), NtHeaders
409 );
411 return FALSE;
412}

◆ UpdateDebugInfoFileEx()

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

Definition at line 417 of file modify.c.

420{
421 FIXME("(%s, %s, %s, %p, %ld): stub\n",
422 debugstr_a(ImageFileName), debugstr_a(SymbolPath),
423 debugstr_a(DebugFilePath), NtHeaders, OldChecksum
424 );
426 return FALSE;
427}

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( imagehlp  )