Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenfrommem.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS kernel 00004 * FILE: lib/rossym/frommem.c 00005 * PURPOSE: Creating rossym info from an in-memory image 00006 * 00007 * PROGRAMMERS: Ge van Geldorp (gvg@reactos.com) 00008 */ 00009 00010 #define NTOSAPI 00011 #include <ntddk.h> 00012 #include <reactos/rossym.h> 00013 #include "rossympriv.h" 00014 #include <ntimage.h> 00015 00016 #define NDEBUG 00017 #include <debug.h> 00018 00019 BOOLEAN 00020 RosSymCreateFromMem(PVOID ImageStart, ULONG_PTR ImageSize, PROSSYM_INFO *RosSymInfo) 00021 { 00022 PIMAGE_DOS_HEADER DosHeader; 00023 PIMAGE_NT_HEADERS NtHeaders; 00024 PIMAGE_SECTION_HEADER SectionHeader; 00025 ULONG SectionIndex; 00026 BOOLEAN RosSymSectionFound = FALSE; 00027 CHAR SectionName[IMAGE_SIZEOF_SHORT_NAME]; 00028 00029 /* Check if MZ header is valid */ 00030 DosHeader = (PIMAGE_DOS_HEADER) ImageStart; 00031 if (ImageSize < sizeof(IMAGE_DOS_HEADER) 00032 || ! ROSSYM_IS_VALID_DOS_HEADER(DosHeader)) 00033 { 00034 DPRINT1("Image doesn't have a valid DOS header\n"); 00035 return FALSE; 00036 } 00037 00038 /* Locate NT header */ 00039 NtHeaders = (PIMAGE_NT_HEADERS)((char *) ImageStart + DosHeader->e_lfanew); 00040 if (ImageSize < DosHeader->e_lfanew + sizeof(IMAGE_NT_HEADERS) 00041 || ! ROSSYM_IS_VALID_NT_HEADERS(NtHeaders)) 00042 { 00043 DPRINT1("Image doesn't have a valid PE header\n"); 00044 return FALSE; 00045 } 00046 00047 /* Search for the section header */ 00048 SectionHeader = IMAGE_FIRST_SECTION(NtHeaders); 00049 if (ImageSize < (ULONG_PTR)((char *) (SectionHeader + NtHeaders->FileHeader.NumberOfSections) 00050 - (char *) ImageStart)) 00051 { 00052 DPRINT1("Image doesn't have valid section headers\n"); 00053 return FALSE; 00054 } 00055 strncpy(SectionName, ROSSYM_SECTION_NAME, IMAGE_SIZEOF_SHORT_NAME); 00056 for (SectionIndex = 0; SectionIndex < NtHeaders->FileHeader.NumberOfSections; SectionIndex++) 00057 { 00058 if (0 == memcmp(SectionName, SectionHeader->Name, IMAGE_SIZEOF_SHORT_NAME)) 00059 { 00060 RosSymSectionFound = TRUE; 00061 break; 00062 } 00063 SectionHeader++; 00064 } 00065 00066 if (!RosSymSectionFound) 00067 { 00068 DPRINT("No %s section found\n", ROSSYM_SECTION_NAME); 00069 return FALSE; 00070 } 00071 00072 /* Locate the section itself */ 00073 if (ImageSize < SectionHeader->PointerToRawData + SectionHeader->SizeOfRawData 00074 || SectionHeader->SizeOfRawData < sizeof(ROSSYM_HEADER)) 00075 { 00076 DPRINT("Invalid %s section\n", ROSSYM_SECTION_NAME); 00077 return FALSE; 00078 } 00079 00080 if (SectionHeader->VirtualAddress + SectionHeader->Misc.VirtualSize > ImageSize) 00081 { 00082 DPRINT("Bad %s section virtual size!\n", ROSSYM_SECTION_NAME); 00083 return FALSE; 00084 } 00085 00086 /* Load it */ 00087 return RosSymCreateFromRaw((char *) ImageStart + SectionHeader->VirtualAddress, 00088 SectionHeader->SizeOfRawData, RosSymInfo); 00089 } 00090 00091 /* EOF */ Generated on Mon May 28 2012 04:36:11 for ReactOS by
1.7.6.1
|