library/src/blockclass/BP-BlockClass.cc
// updates the various different debugger relevant
// data: (memory maps, registers, stack, heap etc)
updates the various different debugger relevant
data: (memory maps, registers, stack, heap etc)
updates the various different debugger relevant data : ( memory maps registers stack heap etc )
int Block::DbgRefreshData()
{
	if (!dbgHandle)
		return ERR_DBG_CANNOT_REFRESH_DATA;
	if (dbgHandle->memory != NULL)
	{
		dbgHandle->memory = NULL;
	}
	if (dbgHandle->stack)
	{
		dbgHandle->stack = NULL;
	}
	if (dbgHandle->heap != NULL)
	{
		dbgHandle->heap = NULL;
	}
	dbgHandle->eax = 0;
	dbgHandle->ebx = 0;
	dbgHandle->ecx = 0;
	dbgHandle->edx = 0;
	dbgHandle->esp = 0;
	dbgHandle->ebp = 0;
	dbgHandle->esi = 0;
	dbgHandle->eip = 0;
	dbgHandle->edi = 0;
	dbgHandle->__cs = 0;
	dbgHandle->cs = 0;
	dbgHandle->__ds = 0;
	dbgHandle->ds = 0;
	dbgHandle->__es = 0;
	dbgHandle->es = 0;
	dbgHandle->__fs = 0;
	dbgHandle->fs = 0;
	dbgHandle->__gs = 0;
	dbgHandle->gs = 0;
	dbgHandle->__ss = 0;
	dbgHandle->gs = 0;
	if (DebugGetRegisters(dbgHandle) != ERR_SUCCESS)
	{
		printf("\n Failed to retrieve new registers.");
	}
	if (GetMemMap(dbgHandle) != ERR_SUCCESS)
	{
		printf("\n Failed to retrieve memory mapping.");
	}
	else
	{
		if (DebugGetHeapFromMapping(dbgHandle) != ERR_SUCCESS)
		{
		}
		if (DebugGetStackFromMapping(dbgHandle) != ERR_SUCCESS)
		{
		}
	}
	if (instructionTable == NULL)
	{
		instructionTable = X86_32_GetX86InstructionTable();
	}
	if (syscallLookup == NULL)
	{
		syscallLookup = DebugGetLinuxSyscallLookupTable();
	}
	size_t elfReadSize = 0;
	unsigned char *elfInstReadBuff = NULL;
	if (dbgHandle->memory != NULL)
	{
		elf = ELF32_ExtractHeaderListAll_Mem(dbgHandle);
		if (elf == NULL)
			printf("\n ERROR: Elf header not retrieved from dbgHandle. ");
		if (elf != NULL)
		{
			if (elf->first != NULL)
			{
				for (elf = elf->first; elf != NULL; elf = elf->next)
				{
					if (elf->header != NULL)
					{
						elfReadSize = (size_t ) elf->header->memMap->highAddr - (size_t ) elf->header->memMap->lowAddr;
						if (elf->next == NULL)
						{
							elf = elf->first;
							break;
						}
					}
				}
			}
		}
	}
	return ERR_SUCCESS;
}
int Block :: DbgRefreshData ( ) { if ( ! dbgHandle ) return ERR_DBG_CANNOT_REFRESH_DATA ; if ( dbgHandle -> memory != NULL ) { dbgHandle -> memory = NULL ; } if ( dbgHandle -> stack ) { dbgHandle -> stack = NULL ; } if ( dbgHandle -> heap != NULL ) { dbgHandle -> heap = NULL ; } dbgHandle -> eax = 0 ; dbgHandle -> ebx = 0 ; dbgHandle -> ecx = 0 ; dbgHandle -> edx = 0 ; dbgHandle -> esp = 0 ; dbgHandle -> ebp = 0 ; dbgHandle -> esi = 0 ; dbgHandle -> eip = 0 ; dbgHandle -> edi = 0 ; dbgHandle -> __cs = 0 ; dbgHandle -> cs = 0 ; dbgHandle -> __ds = 0 ; dbgHandle -> ds = 0 ; dbgHandle -> __es = 0 ; dbgHandle -> es = 0 ; dbgHandle -> __fs = 0 ; dbgHandle -> fs = 0 ; dbgHandle -> __gs = 0 ; dbgHandle -> gs = 0 ; dbgHandle -> __ss = 0 ; dbgHandle -> gs = 0 ; if ( DebugGetRegisters ( dbgHandle ) != ERR_SUCCESS ) { printf ( " \n " ) ; } if ( GetMemMap ( dbgHandle ) != ERR_SUCCESS ) { printf ( " \n " ) ; } else { if ( DebugGetHeapFromMapping ( dbgHandle ) != ERR_SUCCESS ) { } if ( DebugGetStackFromMapping ( dbgHandle ) != ERR_SUCCESS ) { } } if ( instructionTable == NULL ) { instructionTable = X86_32_GetX86InstructionTable ( ) ; } if ( syscallLookup == NULL ) { syscallLookup = DebugGetLinuxSyscallLookupTable ( ) ; } size_t elfReadSize = 0 ; unsigned char * elfInstReadBuff = NULL ; if ( dbgHandle -> memory != NULL ) { elf = ELF32_ExtractHeaderListAll_Mem ( dbgHandle ) ; if ( elf == NULL ) printf ( " \n " ) ; if ( elf != NULL ) { if ( elf -> first != NULL ) { for ( elf = elf -> first ; elf != NULL ; elf = elf -> next ) { if ( elf -> header != NULL ) { elfReadSize = ( size_t ) elf -> header -> memMap -> highAddr - ( size_t ) elf -> header -> memMap -> lowAddr ; if ( elf -> next == NULL ) { elf = elf -> first ; break ; } } } } } } return ERR_SUCCESS ; }
updates the various different debugger relevant
data: (memory maps, registers, stack, heap etc)
updates the various different debugger relevant data : ( memory maps registers stack heap etc )
// ensure we have a debug handle // bpfree existing memory structures // bpfree memory list // bpfree stack list // bpfree heap list // reset all registers to zero // reset segment registers // registers first // then memory map // Then relevant elf headers from memory // walk elf list and decode instructions from pages // Decode instructions // elfInstReadBuff = DbgReadMemory((void *) elf->header->memMap->highAddr, elfReadSize); // printf("\nelf->header->memMap->lowAddr: %p, buff: %p, readlength: %i", elf->header->memMap->lowAddr, elfInstReadBuff, elfReadSize); // elf->header->decodedInstructions = (void *) X86_32_DecodeInstructions(instructionTable, (unsigned char *) elfInstReadBuff, elfReadSize, (void *) elf->header->memMap->lowAddr); // Conditional exit point, resets elf pointer to first. // on break. // return indicating success