1 /* 2 * COPYRIGHT: See COPYING in the top level directory 3 * PROJECT: ReactOS kernel 4 * FILE: lib/rossym/frommem.c 5 * PURPOSE: Creating rossym info from an in-memory image 6 * 7 * PROGRAMMERS: Ge van Geldorp (gvg@reactos.com) 8 */ 9 10 #define NTOSAPI 11 #include <ntdef.h> 12 #include <reactos/rossym.h> 13 #include "rossympriv.h" 14 15 #define NDEBUG 16 #include <debug.h> 17 18 BOOLEAN 19 RosSymCreateFromRaw(PVOID RawData, ULONG_PTR DataSize, PROSSYM_INFO *RosSymInfo) 20 { 21 PROSSYM_HEADER RosSymHeader; 22 23 RosSymHeader = (PROSSYM_HEADER) RawData; 24 if (RosSymHeader->SymbolsOffset < sizeof(ROSSYM_HEADER) 25 || RosSymHeader->StringsOffset < RosSymHeader->SymbolsOffset + RosSymHeader->SymbolsLength 26 || DataSize < RosSymHeader->StringsOffset + RosSymHeader->StringsLength 27 || 0 != (RosSymHeader->SymbolsLength % sizeof(ROSSYM_ENTRY))) 28 { 29 DPRINT1("Invalid ROSSYM_HEADER\n"); 30 return FALSE; 31 } 32 33 /* Copy */ 34 *RosSymInfo = RosSymAllocMem(sizeof(ROSSYM_INFO) + RosSymHeader->SymbolsLength 35 + RosSymHeader->StringsLength + 1); 36 if (NULL == *RosSymInfo) 37 { 38 DPRINT1("Failed to allocate memory for rossym\n"); 39 return FALSE; 40 } 41 (*RosSymInfo)->Symbols = (PROSSYM_ENTRY)((char *) *RosSymInfo + sizeof(ROSSYM_INFO)); 42 (*RosSymInfo)->SymbolsCount = RosSymHeader->SymbolsLength / sizeof(ROSSYM_ENTRY); 43 (*RosSymInfo)->Strings = (PCHAR) *RosSymInfo + sizeof(ROSSYM_INFO) + RosSymHeader->SymbolsLength; 44 (*RosSymInfo)->StringsLength = RosSymHeader->StringsLength; 45 memcpy((*RosSymInfo)->Symbols, (char *) RosSymHeader + RosSymHeader->SymbolsOffset, 46 RosSymHeader->SymbolsLength); 47 memcpy((*RosSymInfo)->Strings, (char *) RosSymHeader + RosSymHeader->StringsOffset, 48 RosSymHeader->StringsLength); 49 /* Make sure the last string is null terminated, we allocated an extra byte for that */ 50 (*RosSymInfo)->Strings[(*RosSymInfo)->StringsLength] = '\0'; 51 52 return TRUE; 53 } 54 55 /* EOF */ 56