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 #include <ntdef.h> 11 #include <reactos/rossym.h> 12 #include "rossympriv.h" 13 14 #define NDEBUG 15 #include <debug.h> 16 17 BOOLEAN 18 RosSymCreateFromRaw(PVOID RawData, ULONG_PTR DataSize, PROSSYM_INFO *RosSymInfo) 19 { 20 PROSSYM_HEADER RosSymHeader; 21 22 RosSymHeader = (PROSSYM_HEADER) RawData; 23 if (RosSymHeader->SymbolsOffset < sizeof(ROSSYM_HEADER) 24 || RosSymHeader->StringsOffset < RosSymHeader->SymbolsOffset + RosSymHeader->SymbolsLength 25 || DataSize < RosSymHeader->StringsOffset + RosSymHeader->StringsLength 26 || 0 != (RosSymHeader->SymbolsLength % sizeof(ROSSYM_ENTRY))) 27 { 28 DPRINT1("Invalid ROSSYM_HEADER\n"); 29 return FALSE; 30 } 31 32 /* Copy */ 33 *RosSymInfo = RosSymAllocMem(sizeof(ROSSYM_INFO) + RosSymHeader->SymbolsLength 34 + RosSymHeader->StringsLength + 1); 35 if (NULL == *RosSymInfo) 36 { 37 DPRINT1("Failed to allocate memory for rossym\n"); 38 return FALSE; 39 } 40 (*RosSymInfo)->Symbols = (PROSSYM_ENTRY)((char *) *RosSymInfo + sizeof(ROSSYM_INFO)); 41 (*RosSymInfo)->SymbolsCount = RosSymHeader->SymbolsLength / sizeof(ROSSYM_ENTRY); 42 (*RosSymInfo)->Strings = (PCHAR) *RosSymInfo + sizeof(ROSSYM_INFO) + RosSymHeader->SymbolsLength; 43 (*RosSymInfo)->StringsLength = RosSymHeader->StringsLength; 44 memcpy((*RosSymInfo)->Symbols, (char *) RosSymHeader + RosSymHeader->SymbolsOffset, 45 RosSymHeader->SymbolsLength); 46 memcpy((*RosSymInfo)->Strings, (char *) RosSymHeader + RosSymHeader->StringsOffset, 47 RosSymHeader->StringsLength); 48 /* Make sure the last string is null terminated, we allocated an extra byte for that */ 49 (*RosSymInfo)->Strings[(*RosSymInfo)->StringsLength] = '\0'; 50 51 return TRUE; 52 } 53 54 /* EOF */ 55