Author: hpoussin Date: Sun Aug 6 22:37:39 2006 New Revision: 23504
URL: http://svn.reactos.org/svn/reactos?rev=23504&view=rev Log: Move code around files to be more like Wine. No code change.
Modified: trunk/reactos/dll/win32/imagehlp/access.c trunk/reactos/dll/win32/imagehlp/imagehlp.rbuild trunk/reactos/dll/win32/imagehlp/imagehlp_main.c trunk/reactos/dll/win32/imagehlp/integrity.c trunk/reactos/dll/win32/imagehlp/modify.c
Modified: trunk/reactos/dll/win32/imagehlp/access.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/imagehlp/access.c... ============================================================================== --- trunk/reactos/dll/win32/imagehlp/access.c (original) +++ trunk/reactos/dll/win32/imagehlp/access.c Sun Aug 6 22:37:39 2006 @@ -15,22 +15,398 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* INCLUDES ******************************************************************/ + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */
#include "precomp.h"
//#define NDEBUG #include <debug.h> - -/* DATA **********************************************************************/ +#define _WINNT_H +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(imagehlp); + +/*********************************************************************** + * Data + */
BOOLEAN DllListInitialized; LIST_ENTRY ImageLoadListHead;
-/* FUNCTIONS *****************************************************************/ +/*********************************************************************** + * GetImageConfigInformation (IMAGEHLP.@) + */ +BOOL IMAGEAPI GetImageConfigInformation( + PLOADED_IMAGE LoadedImage, + PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation) +{ + FIXME("(%p, %p): stub\n", + LoadedImage, ImageConfigInformation + ); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + +/*********************************************************************** + * GetImageUnusedHeaderBytes (IMAGEHLP.@) + */ +DWORD IMAGEAPI GetImageUnusedHeaderBytes( + PLOADED_IMAGE LoadedImage, + LPDWORD SizeUnusedHeaderBytes) +{ + SIZE_T FirstFreeByte; + PIMAGE_OPTIONAL_HEADER OptionalHeader = NULL; + PIMAGE_NT_HEADERS NtHeaders; + ULONG i; + + /* Read the NT Headers */ + NtHeaders = LoadedImage->FileHeader; + + /* Find the first free byte, which is after all the headers and sections */ + FirstFreeByte = (ULONG_PTR)NtHeaders - + (ULONG_PTR)LoadedImage->MappedAddress + + FIELD_OFFSET(IMAGE_NT_HEADERS, OptionalHeader) + + NtHeaders->FileHeader.SizeOfOptionalHeader + + NtHeaders->FileHeader.NumberOfSections * sizeof(IMAGE_SECTION_HEADER); + + /* Get the Optional Header */ + OptionalHeader = &LoadedImage->FileHeader->OptionalHeader; + + /* + * There is the possibilty that one of the Data Directories is in the PE Header + * itself, so we'll need to find such a case and add it to our PE used space + */ + for (i = 0; i < OptionalHeader->NumberOfRvaAndSizes; i++) + { + /* If the VA is less then the size of headers, then the data is inside the PE header */ + if (OptionalHeader->DataDirectory[i].VirtualAddress < + OptionalHeader->SizeOfHeaders) + { + /* However, make sure it's not 0, which means it doesnt actually exist */ + if (OptionalHeader->DataDirectory[i].VirtualAddress >= + FirstFreeByte) + { + /* Our first empty byte is after this Directory Data then */ + FirstFreeByte = OptionalHeader->DataDirectory[i].VirtualAddress + + OptionalHeader->DataDirectory[i].Size; + } + } + } + + /* Return the unused Header Bytes */ + *SizeUnusedHeaderBytes = OptionalHeader->SizeOfHeaders - (DWORD)FirstFreeByte; + + /* And return the first free byte*/ + return (DWORD)FirstFreeByte; +} + +/*********************************************************************** + * ImageLoad (IMAGEHLP.@) + */ +PLOADED_IMAGE IMAGEAPI ImageLoad(LPSTR DllName, LPSTR DllPath) +{ + PLIST_ENTRY Head, Next; + PLOADED_IMAGE LoadedImage; + CHAR Drive[_MAX_DRIVE], Dir[_MAX_DIR], Filename[_MAX_FNAME], Ext[_MAX_EXT]; + BOOL CompleteName = TRUE; + CHAR FullName[MAX_PATH]; + + /* Initialize the List Head */ + if (!DllListInitialized) + { + InitializeListHead(&ImageLoadListHead); + DllListInitialized = TRUE; + } + + /* Move to the Next DLL */ + Head = &ImageLoadListHead; + Next = Head->Flink; + DPRINT("Trying to find library: %s in current ListHead \n", DllName); + + /* Split the path */ + _splitpath(DllName, Drive, Dir, Filename, Ext); + + /* Check if we only got a name */ + if (!strlen(Drive) && !strlen(Dir)) CompleteName = FALSE; + + /* Check if we already Loaded it */ + while (Next != Head) + { + /* Get the Loaded Image Structure */ + LoadedImage = CONTAINING_RECORD(Next, LOADED_IMAGE, Links); + DPRINT("Found: %s in current ListHead \n", LoadedImage->ModuleName); + + /* Check if we didn't have a complete name */ + if (!CompleteName) + { + /* Split this module's name */ + _splitpath(LoadedImage->ModuleName, NULL, NULL, Filename, Ext); + + /* Use only the name and extension */ + strcpy(FullName, Filename); + strcat(FullName, Ext); + } + else + { + /* Use the full untouched name */ + strcpy(FullName, LoadedImage->ModuleName); + } + + /* Check if the Names Match */ + if (!_stricmp(DllName, FullName)) + { + DPRINT("Found it, returning it\n"); + return LoadedImage; + } + + /* Move to next Entry */ + Next = Next->Flink; + } + + /* Allocate memory for the Structure, and write the Module Name under */ + DPRINT("Didn't find it...allocating it for you now\n"); + LoadedImage = HeapAlloc(IMAGEHLP_hHeap, + 0, + sizeof(*LoadedImage) + strlen(DllName) + 1); + if (LoadedImage) + { + /* Module Name will be after structure */ + LoadedImage->ModuleName = (LPSTR)(LoadedImage + 1); + + /* Copy the Module Name */ + strcpy(LoadedImage->ModuleName, DllName); + + /* Now Load it */ + if (MapAndLoad(DllName, DllPath, LoadedImage, TRUE, TRUE)) + { + /* Add it to our list and return it */ + InsertTailList(&ImageLoadListHead, &LoadedImage->Links); + return LoadedImage; + } + + /* If we're here...there's been a failure */ + HeapFree(IMAGEHLP_hHeap, 0, LoadedImage); + LoadedImage = NULL; + } + return LoadedImage; +} + +/*********************************************************************** + * ImageUnload (IMAGEHLP.@) + */ +BOOL IMAGEAPI ImageUnload(PLOADED_IMAGE pLoadedImage) +{ + /* If the image list isn't empty, remove this entry */ + if (!IsListEmpty(&pLoadedImage->Links)) RemoveEntryList(&pLoadedImage->Links); + + /* Unmap and unload it */ + UnMapAndLoad(pLoadedImage); + + /* Free the structure */ + HeapFree(IMAGEHLP_hHeap, 0, pLoadedImage); + + /* Return success */ + return TRUE; +} + +/*********************************************************************** + * MapAndLoad (IMAGEHLP.@) + */ +BOOL IMAGEAPI MapAndLoad( + LPSTR ImageName, LPSTR DllPath, PLOADED_IMAGE pLoadedImage, + BOOL DotDll, BOOL ReadOnly) +{ + HANDLE hFile; + HANDLE hFileMapping; + ULONG Tried = 0; + UCHAR Buffer[MAX_PATH]; + LPSTR FilePart; + LPSTR FileToOpen; + PIMAGE_NT_HEADERS NtHeader; + + /* So we can add the DLL Path later */ + FileToOpen = ImageName; + + /* Assume failure */ + pLoadedImage->hFile = INVALID_HANDLE_VALUE; + + /* Start open loop */ + while (TRUE) + { + /* Get a handle to the file */ + hFile = CreateFileA(FileToOpen, + ReadOnly ? GENERIC_READ : + GENERIC_READ | GENERIC_WRITE, + ReadOnly ? FILE_SHARE_READ : + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + 0, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + /* Check if we already tried this once */ + if (!Tried) + { + /* We didn't do do a path search now */ + Tried = SearchPath(DllPath, + ImageName, + DotDll ? ".dll" : ".exe", + MAX_PATH, + Buffer, + &FilePart); + + /* Check if it was successful */ + if (Tried && (Tried < MAX_PATH)) + { + /* Change the filename to use, and try again */ + FileToOpen = Buffer; + continue; + } + } + + /* Fail */ + return FALSE; + } + + /* Success, break out */ + break; + } + + /* Create the File Mapping */ + hFileMapping = CreateFileMappingA(hFile, + NULL, + ReadOnly ? PAGE_READONLY : + PAGE_READWRITE, + 0, + 0, + NULL); + if (!hFileMapping) + { + /* Fail */ + SetLastError(GetLastError()); + CloseHandle(hFile); + return FALSE; + } + + /* Get a pointer to the file */ + pLoadedImage->MappedAddress = MapViewOfFile(hFileMapping, + ReadOnly ? FILE_MAP_READ : + FILE_MAP_WRITE, + 0, + 0, + 0); + + /* Close the handle to the map, we don't need it anymore */ + CloseHandle(hFileMapping); + + /* Write the image size */ + pLoadedImage->SizeOfImage = GetFileSize(hFile, NULL); + + /* Get the Nt Header */ + NtHeader = ImageNtHeader(pLoadedImage->MappedAddress); + + /* Allocate memory for the name and save it */ + pLoadedImage->ModuleName = HeapAlloc(IMAGEHLP_hHeap, + 0, + strlen(FileToOpen) + 16); + strcpy(pLoadedImage->ModuleName, FileToOpen); + + /* Save the NT Header */ + pLoadedImage->FileHeader = NtHeader; + + /* Save the section data */ + pLoadedImage->Sections = IMAGE_FIRST_SECTION(NtHeader); + pLoadedImage->NumberOfSections = NtHeader->FileHeader.NumberOfSections; + + /* Setup other data */ + pLoadedImage->SizeOfImage = NtHeader->OptionalHeader.SizeOfImage; + pLoadedImage->Characteristics = NtHeader->FileHeader.Characteristics; + pLoadedImage->LastRvaSection = pLoadedImage->Sections; + pLoadedImage->fSystemImage = FALSE; /* FIXME */ + pLoadedImage->fDOSImage = FALSE; /* FIXME */ + InitializeListHead(&pLoadedImage->Links); + + /* Check if it was read-only */ + if (ReadOnly) + { + /* It was, so close our handle and write it as invalid */ + CloseHandle(hFile); + pLoadedImage->hFile = INVALID_HANDLE_VALUE; + } + else + { + /* Write our file handle */ + pLoadedImage->hFile = hFile; + } + + /* Return Success */ + return TRUE; +} + +/*********************************************************************** + * SetImageConfigInformation (IMAGEHLP.@) + */ +BOOL IMAGEAPI SetImageConfigInformation( + PLOADED_IMAGE LoadedImage, + PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation) +{ + FIXME("(%p, %p): stub\n", + LoadedImage, ImageConfigInformation + ); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + +/*********************************************************************** + * UnMapAndLoad (IMAGEHLP.@) + */ +BOOL IMAGEAPI UnMapAndLoad(PLOADED_IMAGE Image) +{ + PIMAGE_NT_HEADERS NtHeader; + DWORD HeaderCheckSum, CheckSum; + + /* Check if the image was read-only */ + if (Image->hFile == INVALID_HANDLE_VALUE) + { + /* We'll only unmap the view */ + UnmapViewOfFile(Image->MappedAddress); + } + else + { + /* Calculate the checksum */ + CheckSumMappedFile(Image->MappedAddress, + Image->SizeOfImage, + &HeaderCheckSum, + &CheckSum); + + /* Get the NT Header */ + NtHeader = Image->FileHeader; + + /* Write the new checksum to it */ + NtHeader->OptionalHeader.CheckSum = CheckSum; + + /* Now flush and unmap the image */ + FlushViewOfFile(Image->MappedAddress, Image->SizeOfImage); + UnmapViewOfFile(Image->MappedAddress); + + /* Check if the size changed */ + if (Image->SizeOfImage != GetFileSize(Image->hFile, NULL)) + { + /* Update the file pointer */ + SetFilePointer(Image->hFile, Image->SizeOfImage, NULL, FILE_BEGIN); + SetEndOfFile(Image->hFile); + } + } + + /* Check if the image had a valid handle, and close it */ + if (Image->hFile != INVALID_HANDLE_VALUE) CloseHandle(Image->hFile); + + /* Return success */ + return TRUE; +}
PVOID IMAGEAPI @@ -116,73 +492,6 @@ }
/* - * @unimplemented - */ -BOOL -IMAGEAPI -GetImageConfigInformation(PLOADED_IMAGE LoadedImage, - PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation) -{ - UNIMPLEMENTED; - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; -} - -/* - * @implemented - */ -DWORD -IMAGEAPI -GetImageUnusedHeaderBytes(PLOADED_IMAGE LoadedImage, - LPDWORD SizeUnusedHeaderBytes) -{ - SIZE_T FirstFreeByte; - PIMAGE_OPTIONAL_HEADER OptionalHeader = NULL; - PIMAGE_NT_HEADERS NtHeaders; - ULONG i; - - /* Read the NT Headers */ - NtHeaders = LoadedImage->FileHeader; - - /* Find the first free byte, which is after all the headers and sections */ - FirstFreeByte = (ULONG_PTR)NtHeaders - - (ULONG_PTR)LoadedImage->MappedAddress + - FIELD_OFFSET(IMAGE_NT_HEADERS, OptionalHeader) + - NtHeaders->FileHeader.SizeOfOptionalHeader + - NtHeaders->FileHeader.NumberOfSections * sizeof(IMAGE_SECTION_HEADER); - - /* Get the Optional Header */ - OptionalHeader = &LoadedImage->FileHeader->OptionalHeader; - - /* - * There is the possibilty that one of the Data Directories is in the PE Header - * itself, so we'll need to find such a case and add it to our PE used space - */ - for (i = 0; i < OptionalHeader->NumberOfRvaAndSizes; i++) - { - /* If the VA is less then the size of headers, then the data is inside the PE header */ - if (OptionalHeader->DataDirectory[i].VirtualAddress < - OptionalHeader->SizeOfHeaders) - { - /* However, make sure it's not 0, which means it doesnt actually exist */ - if (OptionalHeader->DataDirectory[i].VirtualAddress >= - FirstFreeByte) - { - /* Our first empty byte is after this Directory Data then */ - FirstFreeByte = OptionalHeader->DataDirectory[i].VirtualAddress + - OptionalHeader->DataDirectory[i].Size; - } - } - } - - /* Return the unused Header Bytes */ - *SizeUnusedHeaderBytes = OptionalHeader->SizeOfHeaders - (DWORD)FirstFreeByte; - - /* And return the first free byte*/ - return (DWORD)FirstFreeByte; -} - -/* * @implemented */ PVOID @@ -233,100 +542,6 @@ /* * @implemented */ -PLOADED_IMAGE -IMAGEAPI -ImageLoad(LPSTR DllName, - LPSTR DllPath) -{ - PLIST_ENTRY Head, Next; - PLOADED_IMAGE LoadedImage; - CHAR Drive[_MAX_DRIVE], Dir[_MAX_DIR], Filename[_MAX_FNAME], Ext[_MAX_EXT]; - BOOL CompleteName = TRUE; - CHAR FullName[MAX_PATH]; - - /* Initialize the List Head */ - if (!DllListInitialized) - { - InitializeListHead(&ImageLoadListHead); - DllListInitialized = TRUE; - } - - /* Move to the Next DLL */ - Head = &ImageLoadListHead; - Next = Head->Flink; - DPRINT("Trying to find library: %s in current ListHead \n", DllName); - - /* Split the path */ - _splitpath(DllName, Drive, Dir, Filename, Ext); - - /* Check if we only got a name */ - if (!strlen(Drive) && !strlen(Dir)) CompleteName = FALSE; - - /* Check if we already Loaded it */ - while (Next != Head) - { - /* Get the Loaded Image Structure */ - LoadedImage = CONTAINING_RECORD(Next, LOADED_IMAGE, Links); - DPRINT("Found: %s in current ListHead \n", LoadedImage->ModuleName); - - /* Check if we didn't have a complete name */ - if (!CompleteName) - { - /* Split this module's name */ - _splitpath(LoadedImage->ModuleName, NULL, NULL, Filename, Ext); - - /* Use only the name and extension */ - strcpy(FullName, Filename); - strcat(FullName, Ext); - } - else - { - /* Use the full untouched name */ - strcpy(FullName, LoadedImage->ModuleName); - } - - /* Check if the Names Match */ - if (!_stricmp(DllName, FullName)) - { - DPRINT("Found it, returning it\n"); - return LoadedImage; - } - - /* Move to next Entry */ - Next = Next->Flink; - } - - /* Allocate memory for the Structure, and write the Module Name under */ - DPRINT("Didn't find it...allocating it for you now\n"); - LoadedImage = HeapAlloc(IMAGEHLP_hHeap, - 0, - sizeof(*LoadedImage) + strlen(DllName) + 1); - if (LoadedImage) - { - /* Module Name will be after structure */ - LoadedImage->ModuleName = (LPSTR)(LoadedImage + 1); - - /* Copy the Module Name */ - strcpy(LoadedImage->ModuleName, DllName); - - /* Now Load it */ - if (MapAndLoad(DllName, DllPath, LoadedImage, TRUE, TRUE)) - { - /* Add it to our list and return it */ - InsertTailList(&ImageLoadListHead, &LoadedImage->Links); - return LoadedImage; - } - - /* If we're here...there's been a failure */ - HeapFree(IMAGEHLP_hHeap, 0, LoadedImage); - LoadedImage = NULL; - } - return LoadedImage; -} - -/* - * @implemented - */ PIMAGE_SECTION_HEADER IMAGEAPI ImageRvaToSection(IN PIMAGE_NT_HEADERS NtHeaders, @@ -392,229 +607,6 @@ Section->PointerToRawData); }
-/* - * @implemented - */ -BOOL -IMAGEAPI -ImageUnload(PLOADED_IMAGE LoadedImage) -{ - /* If the image list isn't empty, remove this entry */ - if (!IsListEmpty(&LoadedImage->Links)) RemoveEntryList(&LoadedImage->Links); - - /* Unmap and unload it */ - UnMapAndLoad(LoadedImage); - - /* Free the structure */ - HeapFree(IMAGEHLP_hHeap, 0, LoadedImage); - - /* Return success */ - return TRUE; -} - -/* - * @implemented - */ -BOOL -IMAGEAPI -MapAndLoad(LPSTR ImageName, - LPSTR DllPath, - PLOADED_IMAGE LoadedImage, - BOOL DotDll, - BOOL ReadOnly) -{ - HANDLE hFile; - HANDLE hFileMapping; - ULONG Tried = 0; - UCHAR Buffer[MAX_PATH]; - LPSTR FilePart; - LPSTR FileToOpen; - PIMAGE_NT_HEADERS NtHeader; - - /* So we can add the DLL Path later */ - FileToOpen = ImageName; - - /* Assume failure */ - LoadedImage->hFile = INVALID_HANDLE_VALUE; - - /* Start open loop */ - while (TRUE) - { - /* Get a handle to the file */ - hFile = CreateFileA(FileToOpen, - ReadOnly ? GENERIC_READ : - GENERIC_READ | GENERIC_WRITE, - ReadOnly ? FILE_SHARE_READ : - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - 0, - NULL); - - if (hFile == INVALID_HANDLE_VALUE) - { - /* Check if we already tried this once */ - if (!Tried) - { - /* We didn't do do a path search now */ - Tried = SearchPath(DllPath, - ImageName, - DotDll ? ".dll" : ".exe", - MAX_PATH, - Buffer, - &FilePart); - - /* Check if it was successful */ - if (Tried && (Tried < MAX_PATH)) - { - /* Change the filename to use, and try again */ - FileToOpen = Buffer; - continue; - } - } - - /* Fail */ - return FALSE; - } - - /* Success, break out */ - break; - } - - /* Create the File Mapping */ - hFileMapping = CreateFileMappingA(hFile, - NULL, - ReadOnly ? PAGE_READONLY : - PAGE_READWRITE, - 0, - 0, - NULL); - if (!hFileMapping) - { - /* Fail */ - SetLastError(GetLastError()); - CloseHandle(hFile); - return FALSE; - } - - /* Get a pointer to the file */ - LoadedImage->MappedAddress = MapViewOfFile(hFileMapping, - ReadOnly ? FILE_MAP_READ : - FILE_MAP_WRITE, - 0, - 0, - 0); - - /* Close the handle to the map, we don't need it anymore */ - CloseHandle(hFileMapping); - - /* Write the image size */ - LoadedImage->SizeOfImage = GetFileSize(hFile, NULL); - - /* Get the Nt Header */ - NtHeader = ImageNtHeader(LoadedImage->MappedAddress); - - /* Allocate memory for the name and save it */ - LoadedImage->ModuleName = HeapAlloc(IMAGEHLP_hHeap, - 0, - strlen(FileToOpen) + 16); - strcpy(LoadedImage->ModuleName, FileToOpen); - - /* Save the NT Header */ - LoadedImage->FileHeader = NtHeader; - - /* Save the section data */ - LoadedImage->Sections = IMAGE_FIRST_SECTION(NtHeader); - LoadedImage->NumberOfSections = NtHeader->FileHeader.NumberOfSections; - - /* Setup other data */ - LoadedImage->SizeOfImage = NtHeader->OptionalHeader.SizeOfImage; - LoadedImage->Characteristics = NtHeader->FileHeader.Characteristics; - LoadedImage->LastRvaSection = LoadedImage->Sections; - LoadedImage->fSystemImage = FALSE; /* FIXME */ - LoadedImage->fDOSImage = FALSE; /* FIXME */ - InitializeListHead(&LoadedImage->Links); - - /* Check if it was read-only */ - if (ReadOnly) - { - /* It was, so close our handle and write it as invalid */ - CloseHandle(hFile); - LoadedImage->hFile = INVALID_HANDLE_VALUE; - } - else - { - /* Write our file handle */ - LoadedImage->hFile = hFile; - } - - /* Return Success */ - return TRUE; -} - -/* - * @unimplemented - */ -BOOL -IMAGEAPI -SetImageConfigInformation(PLOADED_IMAGE LoadedImage, - PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation) -{ - UNIMPLEMENTED; - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; -} - -/* - * @implemented - */ -BOOL -IMAGEAPI -UnMapAndLoad(PLOADED_IMAGE Image) -{ - PIMAGE_NT_HEADERS NtHeader; - DWORD HeaderCheckSum, CheckSum; - - /* Check if the image was read-only */ - if (Image->hFile == INVALID_HANDLE_VALUE) - { - /* We'll only unmap the view */ - UnmapViewOfFile(Image->MappedAddress); - } - else - { - /* Calculate the checksum */ - CheckSumMappedFile(Image->MappedAddress, - Image->SizeOfImage, - &HeaderCheckSum, - &CheckSum); - - /* Get the NT Header */ - NtHeader = Image->FileHeader; - - /* Write the new checksum to it */ - NtHeader->OptionalHeader.CheckSum = CheckSum; - - /* Now flush and unmap the image */ - FlushViewOfFile(Image->MappedAddress, Image->SizeOfImage); - UnmapViewOfFile(Image->MappedAddress); - - /* Check if the size changed */ - if (Image->SizeOfImage != GetFileSize(Image->hFile, NULL)) - { - /* Update the file pointer */ - SetFilePointer(Image->hFile, Image->SizeOfImage, NULL, FILE_BEGIN); - SetEndOfFile(Image->hFile); - } - } - - /* Check if the image had a valid handle, and close it */ - if (Image->hFile != INVALID_HANDLE_VALUE) CloseHandle(Image->hFile); - - /* Return success */ - return TRUE; -} - BOOL IMAGEAPI UnloadAllImages(VOID)
Modified: trunk/reactos/dll/win32/imagehlp/imagehlp.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/imagehlp/imagehlp... ============================================================================== --- trunk/reactos/dll/win32/imagehlp/imagehlp.rbuild (original) +++ trunk/reactos/dll/win32/imagehlp/imagehlp.rbuild Sun Aug 6 22:37:39 2006 @@ -5,6 +5,7 @@ <define name="_WIN32_WINNT">0x600</define> <define name="WINVER">0x0600</define> <define name="_IMAGEHLP_SOURCE_"></define> + <library>wine</library> <library>ntdll</library> <library>kernel32</library> <file>access.c</file>
Modified: trunk/reactos/dll/win32/imagehlp/imagehlp_main.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/imagehlp/imagehlp... ============================================================================== --- trunk/reactos/dll/win32/imagehlp/imagehlp_main.c (original) +++ trunk/reactos/dll/win32/imagehlp/imagehlp_main.c Sun Aug 6 22:37:39 2006 @@ -15,8 +15,9 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ +
/* INCLUDES ******************************************************************/ @@ -25,32 +26,31 @@
//#define NDEBUG #include <debug.h> +#define _WINNT_H +#include "wine/debug.h"
-/* DATA **********************************************************************/ +WINE_DEFAULT_DEBUG_CHANNEL(imagehlp);
+/**********************************************************************/ HANDLE IMAGEHLP_hHeap = NULL;
-/* FUNCTIONS *****************************************************************/ - -BOOL -IMAGEAPI -DllMain(HINSTANCE hinstDLL, - DWORD fdwReason, - LPVOID lpvReserved) +/*********************************************************************** + * DllMain (IMAGEHLP.init) + */ +BOOL IMAGEAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { - switch(fdwReason) + switch(fdwReason) { - case DLL_PROCESS_ATTACH: - DisableThreadLibraryCalls(hinstDLL); - IMAGEHLP_hHeap = HeapCreate(0, 0x10000, 0); - break; - case DLL_PROCESS_DETACH: - HeapDestroy(IMAGEHLP_hHeap); - IMAGEHLP_hHeap = NULL; - break; - default: - break; + case DLL_PROCESS_ATTACH: + DisableThreadLibraryCalls(hinstDLL); + IMAGEHLP_hHeap = HeapCreate(0, 0x10000, 0); + break; + case DLL_PROCESS_DETACH: + HeapDestroy(IMAGEHLP_hHeap); + IMAGEHLP_hHeap = NULL; + break; + default: + break; } - - return TRUE; + return TRUE; }
Modified: trunk/reactos/dll/win32/imagehlp/integrity.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/imagehlp/integrit... ============================================================================== --- trunk/reactos/dll/win32/imagehlp/integrity.c (original) +++ trunk/reactos/dll/win32/imagehlp/integrity.c Sun Aug 6 22:37:39 2006 @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
/* @@ -30,6 +30,10 @@
//#define NDEBUG #include <debug.h> +#define _WINNT_H +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(imagehlp);
/* FUNCTIONS *****************************************************************/
@@ -44,7 +48,8 @@ DWORD count; BOOL r; IMAGE_DATA_DIRECTORY *sd; - DPRINT("handle %p\n", handle ); + + TRACE("handle %p\n", handle );
/* read the DOS header */ count = SetFilePointer( handle, 0, NULL, FILE_BEGIN ); @@ -71,19 +76,21 @@ sd = &nt_hdr.OptionalHeader. DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY];
- DPRINT("size = %lx addr = %lx\n", sd->Size, sd->VirtualAddress); + TRACE("size = %lx addr = %lx\n", sd->Size, sd->VirtualAddress); *pdwSize = sd->Size; *pdwOfs = sd->VirtualAddress;
return TRUE; }
-static -BOOL -IMAGEHLP_GetCertificateOffset(HANDLE handle, - DWORD num, - DWORD *pdwOfs, - DWORD *pdwSize) +/*********************************************************************** + * IMAGEHLP_GetCertificateOffset (INTERNAL) + * + * Read a file's PE header, and return the offset and size of the + * security directory. + */ +static BOOL IMAGEHLP_GetCertificateOffset( HANDLE handle, DWORD num, + DWORD *pdwOfs, DWORD *pdwSize ) { DWORD size, count, offset, len, sd_VirtualAddr; BOOL r; @@ -124,7 +131,8 @@ *pdwOfs = sd_VirtualAddr + offset; *pdwSize = len;
- DPRINT("len = %lx addr = %lx\n", len, sd_VirtualAddr + offset); + TRACE("len = %lx addr = %lx\n", len, sd_VirtualAddr + offset); + return TRUE; }
@@ -167,28 +175,24 @@ return FALSE; }
-/* - * @unimplemented - */ -BOOL -IMAGEAPI -ImageEnumerateCertificates(HANDLE FileHandle, - WORD TypeFilter, - PDWORD CertificateCount, - PDWORD Indices, - DWORD IndexCount) +/*********************************************************************** + * ImageEnumerateCertificates (IMAGEHLP.@) + */ +BOOL IMAGEAPI ImageEnumerateCertificates( + HANDLE FileHandle, WORD TypeFilter, PDWORD CertificateCount, + PDWORD Indices, DWORD IndexCount) { DWORD size, count, offset, sd_VirtualAddr; WIN_CERTIFICATE hdr; const size_t cert_hdr_size = sizeof hdr - sizeof hdr.bCertificate; BOOL r;
- DPRINT("%p %hd %p %p %ld\n", + TRACE("%p %hd %p %p %ld\n", FileHandle, TypeFilter, CertificateCount, Indices, IndexCount);
if( Indices ) { - DPRINT1("Indicies not FileHandled!\n"); + FIXME("Indicies not handled!\n"); return FALSE; }
@@ -211,7 +215,8 @@ if( count != cert_hdr_size ) return FALSE;
- DPRINT("Size = %08lx id = %08hx\n", hdr.dwLength, hdr.wCertificateType ); + TRACE("Size = %08lx id = %08hx\n", + hdr.dwLength, hdr.wCertificateType );
/* check the certificate is not too big or too small */ if( hdr.dwLength < cert_hdr_size ) @@ -232,18 +237,18 @@ return TRUE; }
-/* - * @implemented - */ -BOOL -IMAGEAPI -ImageGetCertificateData(HANDLE handle, - DWORD Index, - LPWIN_CERTIFICATE Certificate, - PDWORD RequiredLength) +/*********************************************************************** + * ImageGetCertificateData (IMAGEHLP.@) + * + * FIXME: not sure that I'm dealing with the Index the right way + */ +BOOL IMAGEAPI ImageGetCertificateData( + HANDLE handle, DWORD Index, + LPWIN_CERTIFICATE Certificate, PDWORD RequiredLength) { DWORD r, offset, ofs, size, count; - DPRINT("%p %ld %p %p\n", handle, Index, Certificate, RequiredLength); + + TRACE("%p %ld %p %p\n", handle, Index, Certificate, RequiredLength);
if( !IMAGEHLP_GetCertificateOffset( handle, Index, &ofs, &size ) ) return FALSE; @@ -273,18 +278,16 @@ if( count != size ) return FALSE;
- DPRINT("OK\n"); - return TRUE; -} - -/* - * @unimplemented - */ -BOOL -IMAGEAPI -ImageGetCertificateHeader(HANDLE FileHandle, - DWORD CertificateIndex, - LPWIN_CERTIFICATE Certificateheader) + TRACE("OK\n"); + + return TRUE; +} + +/*********************************************************************** + * ImageGetCertificateHeader (IMAGEHLP.@) + */ +BOOL IMAGEAPI ImageGetCertificateHeader( + HANDLE FileHandle, DWORD CertificateIndex, LPWIN_CERTIFICATE Certificateheader) { DWORD r, offset, ofs, size, count; const size_t cert_hdr_size = sizeof *Certificateheader - @@ -308,36 +311,33 @@ if( count != cert_hdr_size ) return FALSE;
- DPRINT("OK\n"); - return TRUE; -} - -/* - * @unimplemented - */ -BOOL -IMAGEAPI -ImageGetDigestStream(HANDLE FileHandle, - DWORD DigestLevel, - DIGEST_FUNCTION DigestFunction, - DIGEST_HANDLE DigestHandle) -{ - UNIMPLEMENTED; - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; -} - -/* - * @unimplemented - */ -BOOL -IMAGEAPI -ImageRemoveCertificate(HANDLE FileHandle, - DWORD Index) -{ - UNIMPLEMENTED; - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; + TRACE("OK\n"); + + return TRUE; +} + +/*********************************************************************** + * ImageGetDigestStream (IMAGEHLP.@) + */ +BOOL IMAGEAPI ImageGetDigestStream( + HANDLE FileHandle, DWORD DigestLevel, + DIGEST_FUNCTION DigestFunction, DIGEST_HANDLE DigestHandle) +{ + FIXME("(%p, %ld, %p, %p): stub\n", + FileHandle, DigestLevel, DigestFunction, DigestHandle + ); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + +/*********************************************************************** + * ImageRemoveCertificate (IMAGEHLP.@) + */ +BOOL IMAGEAPI ImageRemoveCertificate(HANDLE FileHandle, DWORD Index) +{ + FIXME("(%p, %ld): stub\n", FileHandle, Index); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; }
@@ -392,137 +392,3 @@
return Header; } - -/* - * @implemented - */ -DWORD -IMAGEAPI -MapFileAndCheckSumA(LPSTR Filename, - LPDWORD HeaderSum, - LPDWORD CheckSum) -{ - HANDLE hFile; - HANDLE hMapping; - LPVOID BaseAddress; - DWORD FileLength; - - DPRINT("(%s, %p, %p): stub\n", Filename, HeaderSum, CheckSum); - - hFile = CreateFileA(Filename, - GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - 0); - if (hFile == INVALID_HANDLE_VALUE) - { - return CHECKSUM_OPEN_FAILURE; - } - - hMapping = CreateFileMappingW(hFile, - NULL, - PAGE_READONLY, - 0, - 0, - NULL); - if (hMapping == 0) - { - CloseHandle(hFile); - return CHECKSUM_MAP_FAILURE; - } - - BaseAddress = MapViewOfFile(hMapping, - FILE_MAP_READ, - 0, - 0, - 0); - if (hMapping == 0) - { - CloseHandle(hMapping); - CloseHandle(hFile); - return CHECKSUM_MAPVIEW_FAILURE; - } - - FileLength = GetFileSize(hFile, - NULL); - - CheckSumMappedFile(BaseAddress, - FileLength, - HeaderSum, - CheckSum); - - UnmapViewOfFile(BaseAddress); - CloseHandle(hMapping); - CloseHandle(hFile); - - return 0; -} - -/* - * @implemented - */ -DWORD -IMAGEAPI -MapFileAndCheckSumW(LPWSTR Filename, - LPDWORD HeaderSum, - LPDWORD CheckSum) -{ - HANDLE hFile; - HANDLE hMapping; - LPVOID BaseAddress; - DWORD FileLength; - - DPRINT("(%S, %p, %p): stub\n", Filename, HeaderSum, CheckSum); - - hFile = CreateFileW(Filename, - GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - 0); - if (hFile == INVALID_HANDLE_VALUE) - { - return CHECKSUM_OPEN_FAILURE; - } - - hMapping = CreateFileMappingW(hFile, - NULL, - PAGE_READONLY, - 0, - 0, - NULL); - if (hMapping == 0) - { - CloseHandle(hFile); - return CHECKSUM_MAP_FAILURE; - } - - BaseAddress = MapViewOfFile(hMapping, - FILE_MAP_READ, - 0, - 0, - 0); - if (hMapping == 0) - { - CloseHandle(hMapping); - CloseHandle(hFile); - return CHECKSUM_MAPVIEW_FAILURE; - } - - FileLength = GetFileSize(hFile, - NULL); - - CheckSumMappedFile(BaseAddress, - FileLength, - HeaderSum, - CheckSum); - - UnmapViewOfFile(BaseAddress); - CloseHandle(hMapping); - CloseHandle(hFile); - - return 0; -}
Modified: trunk/reactos/dll/win32/imagehlp/modify.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/imagehlp/modify.c... ============================================================================== --- trunk/reactos/dll/win32/imagehlp/modify.c (original) +++ trunk/reactos/dll/win32/imagehlp/modify.c Sun Aug 6 22:37:39 2006 @@ -1,8 +1,8 @@ /* - * IMAGEHLP library + * IMAGEHLP library * - * Copyright 1998 Patrik Stridvall - * Copyright 2005 Alex Ionescu + * Copyright 1998 Patrik Stridvall + * Copyright 2005 Alex Ionescu * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -16,24 +16,33 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ - -/* INCLUDES ******************************************************************/
#include "precomp.h"
//#define NDEBUG #include <debug.h> +#define _WINNT_H +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(imagehlp);
/* DATA **********************************************************************/
CHAR BoundLibraries[4096]; LPSTR BoundLibrariesPointer;
-/* FUNCTIONS *****************************************************************/ - -LPSTR +/*********************************************************************** + * BindImage (IMAGEHLP.@) + */ +BOOL WINAPI BindImage( + LPSTR ImageName, LPSTR DllPath, LPSTR SymbolPath) +{ + return BindImageEx(0, ImageName, DllPath, SymbolPath, NULL); +} + +static LPSTR IMAGEAPI BindpCaptureImportModuleName(LPSTR ModuleName) { @@ -68,128 +77,46 @@ return Name; }
-PIMAGE_BOUND_IMPORT_DESCRIPTOR + +static PIMPORT_DESCRIPTOR IMAGEAPI -BindpCreateNewImportSection(PIMPORT_DESCRIPTOR *BoundImportDescriptor, - PULONG BoundImportsSize) -{ - ULONG BoundLibraryNamesSize = 0, BoundImportTableSize = 0; - PBOUND_FORWARDER_REFS Forwarder, *NextForwarder; +BindpAddImportDescriptor(PIMPORT_DESCRIPTOR *BoundImportDescriptor, + PIMAGE_IMPORT_DESCRIPTOR ImportDescriptor, + LPSTR DllName, + PLOADED_IMAGE Image) +{ PIMPORT_DESCRIPTOR Descriptor, *NextDescriptor; - LPSTR BoundLibraryNames; - PIMAGE_BOUND_IMPORT_DESCRIPTOR BoundTableEntry, BoundTable; - PIMAGE_BOUND_FORWARDER_REF BoundForwarder; - - /* Zero the outoging size */ - *BoundImportsSize = 0; - - /* Loop the descriptors and forwarders to get the size */ + + /* Loop descriptors and check if this library has already been bound */ NextDescriptor = BoundImportDescriptor; while ((Descriptor = *NextDescriptor)) { - /* Add to the size of the Bound Import Table */ - BoundImportTableSize += sizeof(IMAGE_BOUND_IMPORT_DESCRIPTOR); - - /* Check Forwarders */ - NextForwarder = &Descriptor->Forwarders; - while ((Forwarder = *NextForwarder)) - { - /* Add to size of Bound Import Table */ - BoundImportTableSize += sizeof(IMAGE_BOUND_FORWARDER_REF); - - /* Next Forwarder */ - NextForwarder = &Forwarder->Next; - } - - /* Read Next Internal Descriptor */ + /* Compare the names and return the descriptor if found */ + if (!_stricmp(Descriptor->ModuleName, DllName)) return Descriptor; + + /* Move to the next one */ NextDescriptor = &Descriptor->Next; }
- /* Add Terminator for PE Loader*/ - BoundImportTableSize += sizeof(IMAGE_BOUND_IMPORT_DESCRIPTOR); - DPRINT("Table size: %lx\n", BoundImportTableSize); - - /* Name of Libraries Bound in Bound Import Table */ - BoundLibraryNamesSize = (ULONG)((ULONG_PTR)BoundLibrariesPointer - - (ULONG_PTR)BoundLibraries); - BoundLibrariesPointer = NULL; - - /* Size of the whole table, dword aligned */ - *BoundImportsSize = BoundImportTableSize + - ((BoundLibraryNamesSize + sizeof(ULONG) - 1) & - ~(sizeof(ULONG) - 1)); - - /* Allocate it */ - BoundTable = HeapAlloc(IMAGEHLP_hHeap, HEAP_ZERO_MEMORY, *BoundImportsSize); + /* Allocate a new descriptor */ + Descriptor = HeapAlloc(IMAGEHLP_hHeap, + HEAP_ZERO_MEMORY, + sizeof(IMPORT_DESCRIPTOR)); + + /* Set its Data and check if we have a valid loaded image */ + Descriptor->ModuleName = BindpCaptureImportModuleName(DllName); + *NextDescriptor = Descriptor; + if (Image) + { + /* Save the time stamp */ + Descriptor->TimeDateStamp = Image->FileHeader->FileHeader.TimeDateStamp; + }
- /* Pointer Library Names inside the Bound Import Table */ - BoundLibraryNames = (LPSTR)BoundTable + BoundImportTableSize; - - /* Copy the Library Names */ - RtlCopyMemory(BoundLibraryNames, BoundLibraries, BoundLibraryNamesSize); - - /* Now loop both tables */ - BoundTableEntry = BoundTable; - NextDescriptor = BoundImportDescriptor; - while ((Descriptor = *NextDescriptor)) - { - /* Copy the data */ - BoundTableEntry->TimeDateStamp = Descriptor->TimeDateStamp; - BoundTableEntry->OffsetModuleName = (USHORT)(BoundImportTableSize + - (Descriptor->ModuleName - - (ULONG_PTR)BoundLibraries)); - BoundTableEntry->NumberOfModuleForwarderRefs = Descriptor->ForwaderReferences; - - /* Now loop the forwarders */ - BoundForwarder = (PIMAGE_BOUND_FORWARDER_REF)BoundTableEntry + 1; - NextForwarder = &Descriptor->Forwarders; - while ((Forwarder = *NextForwarder)) - { - /* Copy the data */ - BoundForwarder->TimeDateStamp = Forwarder->TimeDateStamp; - BoundForwarder->OffsetModuleName = (USHORT)(BoundImportTableSize + - (Forwarder->ModuleName - - (ULONG_PTR)BoundLibraries)); - - /* Move to the next new forwarder, and move to the next entry */ - BoundForwarder++; - NextForwarder = &Forwarder->Next; - } - - /* Move to next Bound Import Table Entry */ - BoundTableEntry = (PIMAGE_BOUND_IMPORT_DESCRIPTOR)BoundForwarder; - - /* Move to the next descriptor */ - NextDescriptor = &Descriptor->Next; - } - - /* Loop the descriptors and forwarders to free them */ - NextDescriptor = BoundImportDescriptor; - while ((Descriptor = *NextDescriptor)) - { - /* Read next internal descriptor */ - *NextDescriptor = Descriptor->Next; - - /* Loop its forwarders */ - NextForwarder = &Descriptor->Forwarders; - while ((Forwarder = *NextForwarder)) - { - /* Next Forwarder */ - *NextForwarder = Forwarder->Next; - - /* Free it */ - HeapFree(IMAGEHLP_hHeap, 0, Forwarder); - } - - /* Free it */ - HeapFree(IMAGEHLP_hHeap, 0, Descriptor); - } - - /* Return the Bound Import Table */ - return BoundTable; -} - -PCHAR + /* Return the descriptor */ + return Descriptor; +} + +static PCHAR IMAGEAPI BindpAddForwarderReference(LPSTR ModuleName, LPSTR ImportName, @@ -370,7 +297,7 @@ return ForwarderString; }
-BOOL +static BOOL IMAGEAPI BindpLookupThunk(PIMAGE_THUNK_DATA Thunk, PLOADED_IMAGE Image, @@ -527,45 +454,128 @@ return TRUE; }
-PIMPORT_DESCRIPTOR +static PIMAGE_BOUND_IMPORT_DESCRIPTOR IMAGEAPI -BindpAddImportDescriptor(PIMPORT_DESCRIPTOR *BoundImportDescriptor, - PIMAGE_IMPORT_DESCRIPTOR ImportDescriptor, - LPSTR DllName, - PLOADED_IMAGE Image) -{ +BindpCreateNewImportSection(PIMPORT_DESCRIPTOR *BoundImportDescriptor, + PULONG BoundImportsSize) +{ + ULONG BoundLibraryNamesSize = 0, BoundImportTableSize = 0; + PBOUND_FORWARDER_REFS Forwarder, *NextForwarder; PIMPORT_DESCRIPTOR Descriptor, *NextDescriptor; - - /* Loop descriptors and check if this library has already been bound */ + LPSTR BoundLibraryNames; + PIMAGE_BOUND_IMPORT_DESCRIPTOR BoundTableEntry, BoundTable; + PIMAGE_BOUND_FORWARDER_REF BoundForwarder; + + /* Zero the outoging size */ + *BoundImportsSize = 0; + + /* Loop the descriptors and forwarders to get the size */ NextDescriptor = BoundImportDescriptor; while ((Descriptor = *NextDescriptor)) { - /* Compare the names and return the descriptor if found */ - if (!_stricmp(Descriptor->ModuleName, DllName)) return Descriptor; - - /* Move to the next one */ + /* Add to the size of the Bound Import Table */ + BoundImportTableSize += sizeof(IMAGE_BOUND_IMPORT_DESCRIPTOR); + + /* Check Forwarders */ + NextForwarder = &Descriptor->Forwarders; + while ((Forwarder = *NextForwarder)) + { + /* Add to size of Bound Import Table */ + BoundImportTableSize += sizeof(IMAGE_BOUND_FORWARDER_REF); + + /* Next Forwarder */ + NextForwarder = &Forwarder->Next; + } + + /* Read Next Internal Descriptor */ NextDescriptor = &Descriptor->Next; }
- /* Allocate a new descriptor */ - Descriptor = HeapAlloc(IMAGEHLP_hHeap, - HEAP_ZERO_MEMORY, - sizeof(IMPORT_DESCRIPTOR)); - - /* Set its Data and check if we have a valid loaded image */ - Descriptor->ModuleName = BindpCaptureImportModuleName(DllName); - *NextDescriptor = Descriptor; - if (Image) - { - /* Save the time stamp */ - Descriptor->TimeDateStamp = Image->FileHeader->FileHeader.TimeDateStamp; - } + /* Add Terminator for PE Loader*/ + BoundImportTableSize += sizeof(IMAGE_BOUND_IMPORT_DESCRIPTOR); + DPRINT("Table size: %lx\n", BoundImportTableSize); + + /* Name of Libraries Bound in Bound Import Table */ + BoundLibraryNamesSize = (ULONG)((ULONG_PTR)BoundLibrariesPointer - + (ULONG_PTR)BoundLibraries); + BoundLibrariesPointer = NULL; + + /* Size of the whole table, dword aligned */ + *BoundImportsSize = BoundImportTableSize + + ((BoundLibraryNamesSize + sizeof(ULONG) - 1) & + ~(sizeof(ULONG) - 1)); + + /* Allocate it */ + BoundTable = HeapAlloc(IMAGEHLP_hHeap, HEAP_ZERO_MEMORY, *BoundImportsSize);
- /* Return the descriptor */ - return Descriptor; -} - -VOID + /* Pointer Library Names inside the Bound Import Table */ + BoundLibraryNames = (LPSTR)BoundTable + BoundImportTableSize; + + /* Copy the Library Names */ + RtlCopyMemory(BoundLibraryNames, BoundLibraries, BoundLibraryNamesSize); + + /* Now loop both tables */ + BoundTableEntry = BoundTable; + NextDescriptor = BoundImportDescriptor; + while ((Descriptor = *NextDescriptor)) + { + /* Copy the data */ + BoundTableEntry->TimeDateStamp = Descriptor->TimeDateStamp; + BoundTableEntry->OffsetModuleName = (USHORT)(BoundImportTableSize + + (Descriptor->ModuleName - + (ULONG_PTR)BoundLibraries)); + BoundTableEntry->NumberOfModuleForwarderRefs = Descriptor->ForwaderReferences; + + /* Now loop the forwarders */ + BoundForwarder = (PIMAGE_BOUND_FORWARDER_REF)BoundTableEntry + 1; + NextForwarder = &Descriptor->Forwarders; + while ((Forwarder = *NextForwarder)) + { + /* Copy the data */ + BoundForwarder->TimeDateStamp = Forwarder->TimeDateStamp; + BoundForwarder->OffsetModuleName = (USHORT)(BoundImportTableSize + + (Forwarder->ModuleName - + (ULONG_PTR)BoundLibraries)); + + /* Move to the next new forwarder, and move to the next entry */ + BoundForwarder++; + NextForwarder = &Forwarder->Next; + } + + /* Move to next Bound Import Table Entry */ + BoundTableEntry = (PIMAGE_BOUND_IMPORT_DESCRIPTOR)BoundForwarder; + + /* Move to the next descriptor */ + NextDescriptor = &Descriptor->Next; + } + + /* Loop the descriptors and forwarders to free them */ + NextDescriptor = BoundImportDescriptor; + while ((Descriptor = *NextDescriptor)) + { + /* Read next internal descriptor */ + *NextDescriptor = Descriptor->Next; + + /* Loop its forwarders */ + NextForwarder = &Descriptor->Forwarders; + while ((Forwarder = *NextForwarder)) + { + /* Next Forwarder */ + *NextForwarder = Forwarder->Next; + + /* Free it */ + HeapFree(IMAGEHLP_hHeap, 0, Forwarder); + } + + /* Free it */ + HeapFree(IMAGEHLP_hHeap, 0, Descriptor); + } + + /* Return the Bound Import Table */ + return BoundTable; +} + +static VOID IMAGEAPI BindpWalkAndProcessImports(PLOADED_IMAGE File, LPSTR DllPath, @@ -864,16 +874,12 @@
}
-/* - * @implemented +/*********************************************************************** + * BindImageEx (IMAGEHLP.@) */ -BOOL -IMAGEAPI -BindImageEx(IN DWORD Flags, - IN LPSTR ImageName, - IN LPSTR DllPath, - IN LPSTR SymbolPath, - IN PIMAGEHLP_STATUS_ROUTINE StatusRoutine) +BOOL IMAGEAPI BindImageEx( + DWORD Flags, LPSTR ImageName, LPSTR DllPath, LPSTR SymbolPath, + PIMAGEHLP_STATUS_ROUTINE StatusRoutine) { LOADED_IMAGE FileData; PLOADED_IMAGE File; @@ -969,70 +975,7 @@ return TRUE; }
-/* - * @implemented - */ -BOOL -IMAGEAPI -BindImage(LPSTR ImageName, - LPSTR DllPath, - LPSTR SymbolPath) -{ - /* Call the newer API */ - return BindImageEx(0, - ImageName, - DllPath, - SymbolPath, - NULL); -} - -/* - * @unimplemented - */ -BOOL -IMAGEAPI -ReBaseImage(LPSTR CurrentImageName, - LPSTR SymbolPath, - BOOL fReBase, - BOOL fRebaseSysfileOk, - BOOL fGoingDown, - ULONG CheckImageSize, - ULONG *OldImageSize, - ULONG *OldImageBase, - ULONG *NewImageSize, - ULONG *NewImageBase, - ULONG TimeStamp) -{ - UNIMPLEMENTED; - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; -} - -/* - * @unimplemented - */ -VOID -IMAGEAPI -RemoveRelocations(PCHAR ImageName) -{ - UNIMPLEMENTED; - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); -} - -/* - * @unimplemented - */ -BOOL -IMAGEAPI -SplitSymbols(LPSTR ImageName, - LPSTR SymbolsPath, - LPSTR SymbolFilePath, - DWORD Flags) -{ - UNIMPLEMENTED; - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; -} +/* FUNCTIONS *****************************************************************/
/* * @implemented @@ -1058,3 +1001,221 @@ NULL, &FileTime)); } + +/*********************************************************************** + * MapFileAndCheckSumA (IMAGEHLP.@) + */ +DWORD IMAGEAPI MapFileAndCheckSumA( + LPSTR Filename, LPDWORD HeaderSum, LPDWORD CheckSum) +{ + HANDLE hFile; + HANDLE hMapping; + LPVOID BaseAddress; + DWORD FileLength; + + TRACE("(%s, %p, %p): stub\n", + debugstr_a(Filename), HeaderSum, CheckSum + ); + + hFile = CreateFileA(Filename, + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + 0); + if (hFile == INVALID_HANDLE_VALUE) + { + return CHECKSUM_OPEN_FAILURE; + } + + hMapping = CreateFileMappingW(hFile, + NULL, + PAGE_READONLY, + 0, + 0, + NULL); + if (hMapping == 0) + { + CloseHandle(hFile); + return CHECKSUM_MAP_FAILURE; + } + + BaseAddress = MapViewOfFile(hMapping, + FILE_MAP_READ, + 0, + 0, + 0); + if (hMapping == 0) + { + CloseHandle(hMapping); + CloseHandle(hFile); + return CHECKSUM_MAPVIEW_FAILURE; + } + + FileLength = GetFileSize(hFile, + NULL); + + CheckSumMappedFile(BaseAddress, + FileLength, + HeaderSum, + CheckSum); + + UnmapViewOfFile(BaseAddress); + CloseHandle(hMapping); + CloseHandle(hFile); + + return 0; +} + +/*********************************************************************** + * MapFileAndCheckSumW (IMAGEHLP.@) + */ +DWORD IMAGEAPI MapFileAndCheckSumW( + LPWSTR Filename, LPDWORD HeaderSum, LPDWORD CheckSum) +{ + HANDLE hFile; + HANDLE hMapping; + LPVOID BaseAddress; + DWORD FileLength; + + TRACE("(%s, %p, %p): stub\n", + debugstr_w(Filename), HeaderSum, CheckSum + ); + + hFile = CreateFileW(Filename, + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + 0); + if (hFile == INVALID_HANDLE_VALUE) + { + return CHECKSUM_OPEN_FAILURE; + } + + hMapping = CreateFileMappingW(hFile, + NULL, + PAGE_READONLY, + 0, + 0, + NULL); + if (hMapping == 0) + { + CloseHandle(hFile); + return CHECKSUM_MAP_FAILURE; + } + + BaseAddress = MapViewOfFile(hMapping, + FILE_MAP_READ, + 0, + 0, + 0); + if (hMapping == 0) + { + CloseHandle(hMapping); + CloseHandle(hFile); + return CHECKSUM_MAPVIEW_FAILURE; + } + + FileLength = GetFileSize(hFile, + NULL); + + CheckSumMappedFile(BaseAddress, + FileLength, + HeaderSum, + CheckSum); + + UnmapViewOfFile(BaseAddress); + CloseHandle(hMapping); + CloseHandle(hFile); + + return 0; +} + +/*********************************************************************** + * ReBaseImage (IMAGEHLP.@) + */ +BOOL IMAGEAPI ReBaseImage( + LPSTR CurrentImageName, LPSTR SymbolPath, BOOL fReBase, + BOOL fRebaseSysfileOk, BOOL fGoingDown, ULONG CheckImageSize, + ULONG *OldImageSize, ULONG *OldImageBase, ULONG *NewImageSize, + ULONG *NewImageBase, ULONG TimeStamp) +{ + FIXME( + "(%s, %s, %d, %d, %d, %ld, %p, %p, %p, %p, %ld): stub\n", + debugstr_a(CurrentImageName),debugstr_a(SymbolPath), fReBase, + fRebaseSysfileOk, fGoingDown, CheckImageSize, OldImageSize, + OldImageBase, NewImageSize, NewImageBase, TimeStamp + ); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + +/*********************************************************************** + * RemovePrivateCvSymbolic (IMAGEHLP.@) + */ +BOOL IMAGEAPI RemovePrivateCvSymbolic( + PCHAR DebugData, PCHAR *NewDebugData, ULONG *NewDebugSize) +{ + FIXME("(%p, %p, %p): stub\n", + DebugData, NewDebugData, NewDebugSize + ); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + +/*********************************************************************** + * RemoveRelocations (IMAGEHLP.@) + */ +VOID IMAGEAPI RemoveRelocations(PCHAR ImageName) +{ + FIXME("(%p): stub\n", ImageName); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); +} + +/*********************************************************************** + * SplitSymbols (IMAGEHLP.@) + */ +BOOL IMAGEAPI SplitSymbols( + LPSTR ImageName, LPSTR SymbolsPath, + LPSTR SymbolFilePath, DWORD Flags) +{ + FIXME("(%s, %s, %s, %ld): stub\n", + debugstr_a(ImageName), debugstr_a(SymbolsPath), + debugstr_a(SymbolFilePath), Flags + ); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + +/*********************************************************************** + * UpdateDebugInfoFile (IMAGEHLP.@) + */ +BOOL IMAGEAPI UpdateDebugInfoFile( + LPSTR ImageFileName, LPSTR SymbolPath, + LPSTR DebugFilePath, PIMAGE_NT_HEADERS NtHeaders) +{ + FIXME("(%s, %s, %s, %p): stub\n", + debugstr_a(ImageFileName), debugstr_a(SymbolPath), + debugstr_a(DebugFilePath), NtHeaders + ); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + +/*********************************************************************** + * UpdateDebugInfoFileEx (IMAGEHLP.@) + */ +BOOL IMAGEAPI UpdateDebugInfoFileEx( + LPSTR ImageFileName, LPSTR SymbolPath, LPSTR DebugFilePath, + PIMAGE_NT_HEADERS NtHeaders, DWORD OldChecksum) +{ + FIXME("(%s, %s, %s, %p, %ld): stub\n", + debugstr_a(ImageFileName), debugstr_a(SymbolPath), + debugstr_a(DebugFilePath), NtHeaders, OldChecksum + ); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +}