library/src/ELF/ELF32/BP-ELFExtraction_mem.cc
// returns a linked list representing all of the program headers found in the
// file.
returns a linked list representing all of the program headers found in the
file.
returns a linked list representing all of the program headers found in the file .
P_ELF_PROGRAM_HEADER_LIST_32BIT ELF32_ExtractProgramHeaders_Mem(P_ELF_32BIT_LOOKUP_TABLE fullHeader, P_DEBUG_HANDLE dbgHandle, P_MEMORY_MAP memMap){
	if(fullHeader == NULL)
		return NULL;
	size_t phOffset = fullHeader->header->elfProgramHeaderOffset +  (size_t) memMap->lowAddr;;
	size_t phSize = fullHeader->header->elfProgramHeaderSize;
	size_t phEntries = fullHeader->header->elfNumberPHeaderEntries;
	size_t phCurrentOffset = phOffset;
	P_ELF_PROGRAM_HEADER_LIST_32BIT pHeaderList;
	if(phEntries > 0){
		pHeaderList = (P_ELF_PROGRAM_HEADER_LIST_32BIT) bpmalloc(sizeof(ELF_PROGRAM_HEADER_LIST_32BIT));
			memset(pHeaderList, 0x00, sizeof(ELF_PROGRAM_HEADER_LIST_32BIT));
		pHeaderList->first = pHeaderList;
	} else {
		return NULL;
	}
	for(;phEntries > 0; phEntries--){
		pHeaderList->header = (P_ELF_PROGRAM_HEADER_32BIT) DebugReadMemory(dbgHandle, (void *) phCurrentOffset, phSize);
		if(phEntries - 1 == 0){
			pHeaderList->next = NULL;
			break;
		} else {
			pHeaderList->next = (P_ELF_PROGRAM_HEADER_LIST_32BIT) bpmalloc(sizeof(ELF_PROGRAM_HEADER_LIST_32BIT));
				memset(pHeaderList->next, 0x00, sizeof(ELF_PROGRAM_HEADER_LIST_32BIT));
			pHeaderList->next->prev = pHeaderList;
			pHeaderList->next->first = pHeaderList->first;
			pHeaderList->next->next = NULL;
			pHeaderList = pHeaderList->next;
		}
		phCurrentOffset += phSize;
	}
	return pHeaderList->first;
}
P_ELF_PROGRAM_HEADER_LIST_32BIT ELF32_ExtractProgramHeaders_Mem ( P_ELF_32BIT_LOOKUP_TABLE fullHeader , P_DEBUG_HANDLE dbgHandle , P_MEMORY_MAP memMap ) { if ( fullHeader == NULL ) return NULL ; size_t phOffset = fullHeader -> header -> elfProgramHeaderOffset + ( size_t ) memMap -> lowAddr ; ; size_t phSize = fullHeader -> header -> elfProgramHeaderSize ; size_t phEntries = fullHeader -> header -> elfNumberPHeaderEntries ; size_t phCurrentOffset = phOffset ; P_ELF_PROGRAM_HEADER_LIST_32BIT pHeaderList ; if ( phEntries > 0 ) { pHeaderList = ( P_ELF_PROGRAM_HEADER_LIST_32BIT ) bpmalloc ( sizeof ( ELF_PROGRAM_HEADER_LIST_32BIT ) ) ; memset ( pHeaderList , 0x00 , sizeof ( ELF_PROGRAM_HEADER_LIST_32BIT ) ) ; pHeaderList -> first = pHeaderList ; } else { return NULL ; } for ( ; phEntries > 0 ; phEntries -- ) { pHeaderList -> header = ( P_ELF_PROGRAM_HEADER_32BIT ) DebugReadMemory ( dbgHandle , ( void * ) phCurrentOffset , phSize ) ; if ( phEntries - 1 == 0 ) { pHeaderList -> next = NULL ; break ; } else { pHeaderList -> next = ( P_ELF_PROGRAM_HEADER_LIST_32BIT ) bpmalloc ( sizeof ( ELF_PROGRAM_HEADER_LIST_32BIT ) ) ; memset ( pHeaderList -> next , 0x00 , sizeof ( ELF_PROGRAM_HEADER_LIST_32BIT ) ) ; pHeaderList -> next -> prev = pHeaderList ; pHeaderList -> next -> first = pHeaderList -> first ; pHeaderList -> next -> next = NULL ; pHeaderList = pHeaderList -> next ; } phCurrentOffset += phSize ; } return pHeaderList -> first ; }
returns a linked list representing all of the program headers found in the
file.
returns a linked list representing all of the program headers found in the file .
// if(elfFile == NULL) // 	return NULL; // Get the memory map offset (mem specific) // Rewind to assure position // rewind(elfFile); // create first structure // Create first element // Set first pointer, other pointers are null by memset // Create space for actual header: Should Be Unnecessary for Memory Reads // pHeaderList->header = (P_ELF_PROGRAM_HEADER_32BIT) bpmalloc(sizeof(ELF_PROGRAM_HEADER_32BIT)); //	memset(pHeaderList->header, 0x00, sizeof(ELF_PROGRAM_HEADER_32BIT)); // return Null if there are no program header entries // Loop through every entry, collecting and saving the structures // Seek to the current offset // fseek(elfFile, phCurrentOffset, SEEK_SET); // Copy in header // fread(pHeaderList->header, 1, phSize, elfFile); // Move list position // Create Next List // Reset Pointers // Move List Forward // Increment offset // Return first element