Exemple #1
0
R_API size_t read_i32_leb128 (const ut8* p, const ut8* max, st32* out_value) {
	if (p < max && !(p[0] & 0x80)) {
		ut32 result = LEB128_1 (ut32);
		*out_value = SIGN_EXTEND (ut32, result, 6);
		return 1;
	} else if (p + 1 < max && !(p[1] & 0x80)) {
		ut32 result = LEB128_2 (ut32);
		*out_value = SIGN_EXTEND (ut32, result, 13);
		return 2;
	} else if (p + 2 < max && !(p[2] & 0x80)) {
		ut32 result = LEB128_3 (ut32);
		*out_value = SIGN_EXTEND (ut32, result, 20);
		return 3;
	} else if (p + 3 < max && !(p[3] & 0x80)) {
		ut32 result = LEB128_4 (ut32);
		*out_value = SIGN_EXTEND (ut32, result, 27);
		return 4;
	} else if (p+4 < max && !(p[4] & 0x80)) {
		/* the top bits should be a sign-extension of the sign bit */
		bool sign_bit_set = (p[4] & 0x8);
		int top_bits = p[4] & 0xf0;
		if ((sign_bit_set && top_bits != 0x70) || (!sign_bit_set && top_bits != 0)) {
			return 0;
		}
		ut32 result = LEB128_5 (ut32);
		*out_value = result;
		return 5;
	} else {
		/* past the end */
		return 0;
	}
}
Exemple #2
0
HRESULT Kernel::GetDispatcherInfo(ULONG32 ObjectAddress)
{
	DISPATCHER_HEADER WaitObject;
	HRESULT hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(ObjectAddress), &WaitObject, sizeof(WaitObject), NULL);


	printf("        Obj %08x Type %d Size %d SignalState %d \n", 
				ObjectAddress,
				WaitObject.Type,
				WaitObject.Size,
				WaitObject.SignalState);

	ULONG32 handle = 0;
	hr = GetHandleFromObjectAddress(ObjectAddress, _KProcess, handle);

	printf("        Obj Handle 0x%x \n", handle);
	
	wchar_t name[1024];
	name[0] = '\0';
	hr = GetObjectName(SIGN_EXTEND(ObjectAddress),name, 1024);

	wprintf(L"        Obj Name   %s \n\n", name);

	_pCurrentSnapshot->AddObject(SIGN_EXTEND(ObjectAddress), 
								 WaitObject.Type,
								 WaitObject.Size,
								 WaitObject.SignalState, 
								 name);


	return hr;

}
Exemple #3
0
HRESULT Kernel::GetOffsetFromOSProcessId(ULONG32 OSProcessId, ULONG64& Offset)
{
	ULONG64 CurrentKProcess = 0;
	HRESULT hr = g_ExtSystem->GetCurrentProcessDataOffset(&CurrentKProcess);	

	ULONG32 ObjectTableAddress = 0;
	ULONG32 StartTableAddress  = 0;
	LIST_ENTRY TableList;
	hr = g_ExtData2->ReadVirtual(CurrentKProcess + _pOffsets[OffsetId_KProcess_ObjectTable], &ObjectTableAddress, sizeof(ObjectTableAddress), NULL);
	hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(ObjectTableAddress + _pOffsets[OffsetId_HANDLE_TABLE_HandleTableList]), &TableList, sizeof(TableList), NULL);	
	StartTableAddress = ObjectTableAddress;

	do
	{
		ULONG32 UniqueProcessId = 0;
		hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(ObjectTableAddress + _pOffsets[OffsetId_HANDLE_TABLE_UniqueProcessId]), &UniqueProcessId, sizeof(UniqueProcessId), NULL);

		if(UniqueProcessId==OSProcessId)
		{
			ULONG32 QuotaProcess = 0;
			hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(ObjectTableAddress + _pOffsets[OffsetId_HANDLE_TABLE_QuotaProcess]), &QuotaProcess, sizeof(QuotaProcess), NULL);
			Offset = SIGN_EXTEND(QuotaProcess);
			return S_OK;
		}

		hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(ObjectTableAddress + _pOffsets[OffsetId_HANDLE_TABLE_HandleTableList]), &TableList, sizeof(TableList), NULL);	
		ObjectTableAddress = (ULONG32)TableList.Flink - _pOffsets[OffsetId_HANDLE_TABLE_HandleTableList];

	}
	while(StartTableAddress != ObjectTableAddress);
	Offset = 0;
	return E_INVALIDARG;
}
Exemple #4
0
void Processor::Movsx_0FBE(const Instruction *inst)
{
    /**
     * MOVSX r32, r/m8
     */
	if (inst->Main.Prefix.OperandSize) {
		u8 val2 = ReadOperand8(inst, inst->Main.Argument2,NULL);
		WriteOperand16(inst, inst->Main.Argument1, 0, SIGN_EXTEND(8, 16, val2));
	} else {
		u8 val2 = ReadOperand8(inst, inst->Main.Argument2, NULL);
		WriteOperand32(inst, inst->Main.Argument1, 0, SIGN_EXTEND(8, 32, val2));
	}  
    
}
Exemple #5
0
unsigned int
__canonicalize_funcptr_for_compare (fptr_t fptr)
{
  static unsigned int fixup_plabel[2] __attribute__((used));
  fixup_t fixup;
  unsigned int *got, *iptr, *plabel;
  int i;

  /* -1 and page 0 are special.  -1 is used in crtend to mark the end of
     a list of function pointers.  Also return immediately if the plabel
     bit is not set in the function pointer.  In this case, the function
     pointer points directly to the function.  */
  if ((int) fptr == -1 || (unsigned int) fptr < 4096 || !((int) fptr & 2))
    return (unsigned int) fptr;

  /* The function pointer points to a function descriptor (plabel).  If
     the plabel hasn't been resolved, the first word of the plabel points
     to the entry of the PLT stub just before the global offset table.
     The second word in the plabel contains the relocation offset for the
     function.  */
  plabel = (unsigned int *) ((unsigned int) fptr & ~3);
  got = (unsigned int *) (plabel[0] + GOT_FROM_PLT_STUB);

  /* Return the address of the function if the plabel has been resolved.  */
  if (got !=  &_GLOBAL_OFFSET_TABLE_)
    return plabel[0];

  /* Find the first "bl" branch in the offset search list.  This is a
     call to _dl_fixup or a magic branch to fixup at the beginning of the
     trampoline template.  The fixup function does the actual runtime
     resolution of function descriptors.  We only look for "bl" branches
     with a 17-bit pc-relative displacement.  */
  for (i = 0; i < NOFFSETS; i++)
    {
      iptr = (unsigned int *) (got[-2] + fixup_branch_offset[i]);
      if ((*iptr & 0xfc00e000) == 0xe8000000)
	break;
    }

  /* This should not happen... */
  if (i == NOFFSETS)
    return ~0;

  /* Extract the 17-bit displacement from the instruction.  */
  iptr += SIGN_EXTEND (GET_FIELD (*iptr, 19, 28) |
		       GET_FIELD (*iptr, 29, 29) << 10 |
		       GET_FIELD (*iptr, 11, 15) << 11 |
		       GET_FIELD (*iptr, 31, 31) << 16, 17);

  /* Build a plabel for an indirect call to _dl_fixup.  */
  fixup_plabel[0] = (unsigned int) iptr + 8;	/* address of fixup */
  fixup_plabel[1] = got[-1];			/* ltp for fixup */
  fixup = (fixup_t) ((int) fixup_plabel | 3);

  /* Call fixup to resolve the function address.  got[1] contains the
     link_map pointer and plabel[1] the relocation offset.  */
  fixup ((struct link_map *) got[1], plabel[1]);

  return plabel[0];
}
Exemple #6
0
PyObject * wipe_ReadPhysical(PyObject * self, PyObject * args)
{
	ULONG ulOffset;
	ULONG ulSize;
	PBYTE pbBuf;
	ULONG cbBytesRead;
	PyObject * ptRet = NULL;

	if (!PyArg_ParseTuple(args, "kk", &ulOffset, &ulSize))
	{
		return NULL;
	}

	pbBuf = HeapAlloc(GetProcessHeap(), 0, ulSize);
	if (NULL == pbBuf)
	{
		// need to raise proper error
		return NULL;
	}

	ReadPhysical(SIGN_EXTEND(ulOffset), pbBuf, ulSize, &cbBytesRead);
	
	ptRet  = Py_BuildValue("s#", pbBuf, cbBytesRead);

	HeapFree(GetProcessHeap(), 0, pbBuf);
	pbBuf = NULL;

	return ptRet ;

}
Exemple #7
0
R_API size_t read_i64_leb128 (const ut8* p, const ut8* max, st64* out_value) {
	if (p < max && !(p[0] & 0x80)) {
		ut64 result = LEB128_1 (ut64);
		*out_value = SIGN_EXTEND (ut64, result, 6);
		return 1;
	} else if (p + 1 < max && !(p[1] & 0x80)) {
		ut64 result = LEB128_2(ut64);
		*out_value = SIGN_EXTEND (ut64, result, 13);
		return 2;
	} else if (p + 2 < max && !(p[2] & 0x80)) {
		ut64 result = LEB128_3 (ut64);
		*out_value = SIGN_EXTEND (ut64, result, 20);
		return 3;
	} else if (p + 3 < max && !(p[3] & 0x80)) {
		ut64 result = LEB128_4 (ut64);
		*out_value = SIGN_EXTEND (ut64, result, 27);
		return 4;
	} else if (p + 4 < max && !(p[4] & 0x80)) {
		ut64 result = LEB128_5 (ut64);
		*out_value = SIGN_EXTEND (ut64, result, 34);
		return 5;
	} else if (p + 5 < max && !(p[5] & 0x80)) {
		ut64 result = LEB128_6 (ut64);
		*out_value = SIGN_EXTEND (ut64, result, 41);
		return 6;
	} else if (p + 6 < max && !(p[6] & 0x80)) {
		ut64 result = LEB128_7 (ut64);
		*out_value = SIGN_EXTEND (ut64, result, 48);
		return 7;
	} else if (p + 7 < max && !(p[7] & 0x80)) {
		ut64 result = LEB128_8 (ut64);
		*out_value = SIGN_EXTEND (ut64, result, 55);
		return 8;
	} else if (p + 8 < max && !(p[8] & 0x80)) {
		ut64 result = LEB128_9 (ut64);
		*out_value = SIGN_EXTEND (ut64, result, 62);
		return 9;
	} else if (p + 9 < max && !(p[9] & 0x80)) {
		/* the top bits should be a sign-extension of the sign bit */
		bool sign_bit_set = (p[9] & 0x1);
		int top_bits = p[9] & 0xfe;
		if ((sign_bit_set && top_bits != 0x7e) || (!sign_bit_set && top_bits != 0)) {
			return 0;	
		}
		ut64 result = LEB128_10 (ut64);
		*out_value = result;
		return 10;
	} else {
		/* past the end */
		return 0;
	}
}
Exemple #8
0
void Processor::Jmp_EB(const Instruction *inst)
{
    /**
     * JMP rel8
     */
    u32 rel = SIGN_EXTEND(8, 32, inst->Aux.op1.immediate);
    EIP += rel;
    
}
Exemple #9
0
ULONG64 RegPtrGet(PDEBUG_VALUE Register)
{
    if (g_bIs64)
    {
        return Register->I64;
    }

    return SIGN_EXTEND(Register->I32);
}
Exemple #10
0
void Processor::Movsx_0FBF(const Instruction *inst)
{
    /*
     * MOVSX r32, r/m16
     */
    if (inst->Main.Prefix.OperandSize) NOT_IMPLEMENTED();

    u16 val2 = ReadOperand16(inst, inst->Main.Argument2, NULL);
    WriteOperand32(inst, inst->Main.Argument1, 0, SIGN_EXTEND(16, 32, val2));
    
}
/* Read in the common cie/fde prefix, including reading
 * the cie-value which shows which this is: cie or fde.
 * */
int
dwarf_read_cie_fde_prefix(Dwarf_Debug dbg,
			  Dwarf_Small * frame_ptr_in,
			  Dwarf_Small * section_ptr_in,
			  Dwarf_Unsigned section_index_in,
			  Dwarf_Unsigned section_length_in,
			  struct cie_fde_prefix_s *data_out,
			  Dwarf_Error * error)
{
    Dwarf_Unsigned length = 0;
    int local_length_size = 0;
    int local_extension_size = 0;
    Dwarf_Small *frame_ptr = frame_ptr_in;
    Dwarf_Small *cie_ptr_addr = 0;
    Dwarf_Unsigned cie_id = 0;

    /* READ_AREA_LENGTH updates frame_ptr for consumed bytes */
    READ_AREA_LENGTH(dbg, length, Dwarf_Unsigned,
		     frame_ptr, local_length_size,
		     local_extension_size);

    if (length % local_length_size != 0) {
	_dwarf_error(dbg, error, DW_DLE_DEBUG_FRAME_LENGTH_BAD);
	return (DW_DLV_ERROR);
    }

    if (length == 0) {
	/* nul bytes at end of section, seen at end of egcs eh_frame
	   sections (in a.out). Take this as meaning no more CIE/FDE
	   data. We should be very close to end of section. */
	return DW_DLV_NO_ENTRY;
    }

    cie_ptr_addr = frame_ptr;
    READ_UNALIGNED(dbg, cie_id, Dwarf_Unsigned,
		   frame_ptr, local_length_size);
    SIGN_EXTEND(cie_id, local_length_size);
    frame_ptr += local_length_size;

    data_out->cf_start_addr = frame_ptr_in;
    data_out->cf_addr_after_prefix = frame_ptr;

    data_out->cf_length = length;
    data_out->cf_local_length_size = local_length_size;
    data_out->cf_local_extension_size = local_extension_size;
    data_out->cf_cie_id = cie_id;
    data_out->cf_cie_id_addr = cie_ptr_addr;
    data_out->cf_section_ptr = section_ptr_in;
    data_out->cf_section_index = section_index_in;
    data_out->cf_section_length = section_length_in;
    return DW_DLV_OK;
}
Exemple #12
0
HRESULT Kernel::ProcessMutantList(ULONG32 EThreadAddress)
{
	printf("\n    Mutants Owned\n\n");

	ULONG32 MutanListHeadAddress = EThreadAddress + _pOffsets[OffsetId_EThread_MutantListHead];
	ULONG32 MutantAdrress = MutanListHeadAddress;
	LIST_ENTRY MutantEntry;
	HRESULT hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(MutantAdrress), &MutantEntry, sizeof(MutantEntry), NULL);
	MutantAdrress = (ULONG32)MutantEntry.Flink;

	while(MutanListHeadAddress != MutantAdrress)
	{
		ULONG32 ObjectAddress = MutantAdrress - _pOffsets[OffsetId_EThread_MutantListHead];

		_pCurrentSnapshot->AddOwnedObject(SIGN_EXTEND(ObjectAddress), SIGN_EXTEND(EThreadAddress));

		hr = GetDispatcherInfo(ObjectAddress);

		HRESULT Hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(MutantEntry.Flink), &MutantEntry, sizeof(MutantEntry), NULL);
		MutantAdrress = (ULONG32)MutantEntry.Flink;
	}
	return hr;
}
Exemple #13
0
HRESULT Kernel::ProcessWaitList(ULONG32 EThreadAddress)
{
	ULONG32 KThreadWaitBlocListkAddress = EThreadAddress + _pOffsets[OffsetId_EThread_WaitBlockList];
	ULONG32 HeadWaitBlockListAddress = 0;
	HRESULT hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(KThreadWaitBlocListkAddress), &HeadWaitBlockListAddress, sizeof(HeadWaitBlockListAddress), NULL);
	ULONG32 WaitBlockAddress = HeadWaitBlockListAddress;
	KWAIT_BLOCK WaitBlock;
	hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(HeadWaitBlockListAddress), &WaitBlock, sizeof(WaitBlock), NULL);

	printf("\n    Wait Blocks\n\n");
	while(true)
	{
		printf("    WB %08x T %08x Obj %08x Key %d Type %d \n\n", 
			WaitBlockAddress,
			WaitBlock.KThread,
			WaitBlock.Object,
			WaitBlock.WaitKey,
			WaitBlock.WaitType);

		_pCurrentSnapshot->AddWaitBlock(SIGN_EXTEND(WaitBlockAddress),
										WaitBlock.KThread,
										(ULONG64)WaitBlock.Object,
										WaitBlock.WaitKey,
										WaitBlock.WaitType); 

		GetDispatcherInfo((ULONG32)WaitBlock.Object);
		

		WaitBlockAddress = (ULONG32)WaitBlock.NextWaitBlock;
		if(HeadWaitBlockListAddress == WaitBlockAddress)
		{
			break;
		}
		hr =  g_ExtData2->ReadVirtual(SIGN_EXTEND(WaitBlockAddress), &WaitBlock, sizeof(WaitBlock), NULL);
	}
	return hr;
}
Exemple #14
0
PyObject * wipe_WritePhysical(PyObject * self, PyObject * args)
{
	ULONG ulOffset;
	PBYTE pbBuf;
	ULONG cbBufSize;
	ULONG cbBytesWritten = 0;

	if (!PyArg_ParseTuple(args, "ks#", &ulOffset, &pbBuf, &cbBufSize))
	{
		return NULL;
	}

	WritePhysical(SIGN_EXTEND(ulOffset), pbBuf, cbBufSize, &cbBytesWritten);
	return Py_BuildValue("k", cbBytesWritten);
}
Exemple #15
0
HRESULT Kernel::ProcessThreadWaitList()
{
	LIST_ENTRY ThreadListHead;
	ULONG32 ListHeadAddress = (ULONG32)_KProcess + _pOffsets[OffSetId_KProcess_ThreadListHead];
	HRESULT hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(ListHeadAddress), &ThreadListHead, sizeof(ThreadListHead), NULL);

	ULONG32 NextEntryAddress = (ULONG32)ThreadListHead.Flink;
	LIST_ENTRY NextEntry;

	while(NextEntryAddress != ListHeadAddress)
	{
		printf("\n");
		ULONG32 EThreadAddress = NextEntryAddress - _pOffsets[OffsetId_EThread_ThreadListEntry];

		hr = GetDispatcherInfo(EThreadAddress);
		hr = GetThreadInfo(EThreadAddress);
		hr = ProcessWaitList(EThreadAddress);
		hr = ProcessMutantList(EThreadAddress);
		hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(NextEntryAddress), &NextEntry, sizeof(NextEntry), NULL);

		NextEntryAddress = (ULONG32)NextEntry.Flink;
	}
	return hr;
}
Exemple #16
0
// TODO: Directory Names
HRESULT Kernel::GetObjectName(ULONG64 ObjectAddress, WCHAR* buffer, int size)
{
	BYTE NameOffset = 0;
	
	ULONG64 NameOffsetAddress = ObjectAddress + offset_OBJECT_Header + offset_OBJECT_HEADER_NameInfoOffset;
	HRESULT hr = g_ExtData2->ReadVirtual(NameOffsetAddress, &NameOffset, sizeof(NameOffset), NULL);

	if(NameOffset !=0)
	{
		ULONG64 ObjectNameAddress = ObjectAddress + offset_OBJECT_Header - NameOffset;
		ULONG32 DirectoryAddress = 0;
		hr = g_ExtData2->ReadVirtual(ObjectNameAddress, &DirectoryAddress, sizeof(DirectoryAddress), NULL);

		ULONG64 UnicodeStringAddress = ObjectNameAddress + 0x4;
		ULONG64 StringLengthAddress  = UnicodeStringAddress;
		ULONG64 MaxStringLengthAddress  = UnicodeStringAddress + 0x2;
		ULONG64 BufferPointerAddress  = UnicodeStringAddress + 0x4;

		short len = 0;
		short maxLen = 0;
		DWORD bufferPtr = 0;

		hr = g_ExtData2->ReadVirtual(StringLengthAddress, &len, sizeof(len), NULL);
		hr = g_ExtData2->ReadVirtual(MaxStringLengthAddress, &maxLen, sizeof(maxLen), NULL);
		hr = g_ExtData2->ReadVirtual(BufferPointerAddress, &bufferPtr, sizeof(bufferPtr), NULL);

		if(size<len)
		{
			len = size - 2;
		}
		if(len>0)
		{
			hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(bufferPtr), buffer, len  + 2, NULL);
		}
		else if(DirectoryAddress !=0)
		{
			//itow(DirectoryAddress, buffer, 10);
		}
	}
	return hr;
}
Exemple #17
0
HRESULT Kernel::ProcessHandles()
{
	ULONG32 ObjectTableAddress = 0;
	HRESULT hr = g_ExtData2->ReadVirtual(_KProcess + _pOffsets[OffsetId_KProcess_ObjectTable], &ObjectTableAddress, sizeof(ObjectTableAddress), NULL);

	bool winxpormore = true;
	if(winxpormore)
	{
		ULONG TableCode = 0;
		hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(ObjectTableAddress + _pOffsets[OffsetId_HANDLE_TABLE_TableCode]), &TableCode, sizeof(TableCode), NULL);	
		ULONG TableLevel = (ULONG)(TableCode & 3);
		TableCode -= TableLevel;
		
		const int TableSize = 0x200;
		const int cbSizeOfHandleTableEntry = 0x8;
		const int offsetObject = 0x18;
		PCHAR Level1, Level2, Level3;
		switch(TableLevel)
		{
			case 0:
			{
				for(int i=0;i<TableSize;++i)
				{
					Level1 = (PCHAR)TableCode;
					ULONG32 Entry = (ULONG32)&Level1[i*cbSizeOfHandleTableEntry];
					ULONG32 CurrentObjectAddress = 0;
					hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(Entry) , &CurrentObjectAddress, sizeof(CurrentObjectAddress), NULL);	
					if(CurrentObjectAddress)
					{
						CurrentObjectAddress &= ~3;
						CurrentObjectAddress += offsetObject;
						printf("%x    %x \n", (i << 0x2), CurrentObjectAddress);
						_pCurrentSnapshot->AddHandle(SIGN_EXTEND(CurrentObjectAddress), (HANDLE)(i << 0x2));
					}
				}
				break;
			}
			case 1:
			{
				ULONG32 Level1Table[TableSize];
				hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(TableCode) , &Level1Table, sizeof(Level1Table), NULL);
				for(int i=0;i<TableSize;++i)
				{
					ULONG32 Table2Address = Level1Table[i];
					if(Table2Address>0)
					{
						Level2 = (PCHAR)Table2Address;
						for(int j=0;j<TableSize;++j)
						{
							ULONG32 Entry = (ULONG32)&Level2[j*cbSizeOfHandleTableEntry];
							ULONG32 CurrentObjectAddress = 0;
							hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(Entry) , &CurrentObjectAddress, sizeof(CurrentObjectAddress), NULL);	
							if(CurrentObjectAddress)
							{	
								_pCurrentSnapshot->AddHandle(SIGN_EXTEND(CurrentObjectAddress+offsetObject), (HANDLE)((i << 0x2) | (j << 0xA)));
							}
						}
					}

				}
				break;
			}
			case 2:
			{
				ULONG32 Level1Table[TableSize];
				hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(TableCode) , &Level1Table, sizeof(Level1Table), NULL);
				for(int i=0;i<TableSize;++i)
				{
					ULONG32 Table2Address = Level1Table[i];
					if(Table2Address>0)
					{
						ULONG32 Level2Table[TableSize];
						hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(Table2Address) , &Level2Table, sizeof(Level2Table), NULL);
						for(int j=0;j<TableSize;++j)
						{
							ULONG32 Table3Address = Level2Table[i];
							if(Table3Address>0)
							{
								Level3 = (PCHAR)Table3Address;
								for(int k=0;k<TableSize;++k)
								{
									ULONG32 Entry = (ULONG32)&Level3[k*cbSizeOfHandleTableEntry];
									ULONG32 CurrentObjectAddress = 0;
									hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(Entry) , &CurrentObjectAddress, sizeof(CurrentObjectAddress), NULL);	
									if(CurrentObjectAddress)
									{
										_pCurrentSnapshot->AddHandle(SIGN_EXTEND(CurrentObjectAddress+offsetObject), (HANDLE)((i << 0x2) | (j << 0xA) | (k << 0x12)));
									}
								}
							}
						}
					}
				}
				break;
			}
		}
	}
	return hr;
}
int
dwarf_create_fde_from_after_start(Dwarf_Debug dbg,
				  struct cie_fde_prefix_s *prefix,
				  Dwarf_Small * frame_ptr,
				  int use_gnu_cie_calc,
				  Dwarf_Cie cie_ptr_in,
				  Dwarf_Fde * fde_ptr_out,
				  Dwarf_Error * error)
{
    Dwarf_Fde new_fde = 0;
    Dwarf_Cie cieptr = cie_ptr_in;
    Dwarf_Small *saved_frame_ptr = 0;

    Dwarf_Small *initloc = frame_ptr;
    Dwarf_Signed offset_into_exception_tables
	/* must be min dwarf_sfixed in size */
	= (Dwarf_Signed) DW_DLX_NO_EH_OFFSET;
    Dwarf_Small *fde_aug_data = 0;
    Dwarf_Unsigned fde_aug_data_len = 0;
    Dwarf_Addr cie_base_offset = prefix->cf_cie_id;
    Dwarf_Addr initial_location = 0;	/* must be min de_pointer_size
					   bytes in size */
    Dwarf_Addr address_range = 0;	/* must be min de_pointer_size
					   bytes in size */

    enum Dwarf_augmentation_type augt = cieptr->ci_augmentation_type;

    if (augt == aug_gcc_eh_z) {
	/* If z augmentation this is eh_frame, and initial_location and 
	   address_range in the FDE are read according to the CIE
	   augmentation string instructions.  */

	{
	    Dwarf_Small *fp_updated = 0;
	    int res = res = read_encoded_ptr(dbg, frame_ptr,
					     cieptr->
					     ci_gnu_fde_begin_encoding,
					     &initial_location,
					     &fp_updated);

	    if (res != DW_DLV_OK) {
		_dwarf_error(dbg, error,
			     DW_DLE_FRAME_AUGMENTATION_UNKNOWN);
		return DW_DLV_ERROR;
	    }
	    frame_ptr = fp_updated;
	    res = read_encoded_ptr(dbg, frame_ptr,
				   cieptr->ci_gnu_fde_begin_encoding,
				   &address_range, &fp_updated);
	    if (res != DW_DLV_OK) {
		_dwarf_error(dbg, error,
			     DW_DLE_FRAME_AUGMENTATION_UNKNOWN);
		return DW_DLV_ERROR;
	    }
	    frame_ptr = fp_updated;
	}
	{
	    Dwarf_Unsigned adlen = 0;

	    DECODE_LEB128_UWORD(frame_ptr, adlen);
	    fde_aug_data_len = adlen;
	    fde_aug_data = frame_ptr;
	    frame_ptr += adlen;
	}

    } else {
	READ_UNALIGNED(dbg, initial_location, Dwarf_Addr,
		       frame_ptr, dbg->de_pointer_size);
	frame_ptr += dbg->de_pointer_size;

	READ_UNALIGNED(dbg, address_range, Dwarf_Addr,
		       frame_ptr, dbg->de_pointer_size);
	frame_ptr += dbg->de_pointer_size;
    }





    switch (augt) {
    case aug_irix_mti_v1:
    case aug_empty_string:
	break;
    case aug_irix_exception_table:{
	    Dwarf_Unsigned lreg = 0;
	    Dwarf_Word length_of_augmented_fields = 0;

	    DECODE_LEB128_UWORD(frame_ptr, lreg);
	    length_of_augmented_fields = (Dwarf_Word) lreg;

	    saved_frame_ptr = frame_ptr;
	    /* The first word is an offset into exception tables.
	       Defined as a 32bit offset even for CC -64. */
	    READ_UNALIGNED(dbg, offset_into_exception_tables,
			   Dwarf_Addr, frame_ptr, sizeof(Dwarf_sfixed));
	    SIGN_EXTEND(offset_into_exception_tables,
			sizeof(Dwarf_sfixed));
	    frame_ptr = saved_frame_ptr + length_of_augmented_fields;
	}
	break;
    case aug_eh:{
	    Dwarf_Unsigned eh_table_value = 0;

	    if (!use_gnu_cie_calc) {
		/* This should be impossible. */
		_dwarf_error(dbg, error,
			     DW_DLE_FRAME_AUGMENTATION_UNKNOWN);
		return DW_DLV_ERROR;
	    }

	    /* gnu eh fde case. we do not need to do anything */
	     /*REFERENCED*/	/* Not used in this instance of the
				   macro */
		READ_UNALIGNED(dbg, eh_table_value,
			       Dwarf_Unsigned, frame_ptr,
			       dbg->de_pointer_size);
	    frame_ptr += dbg->de_pointer_size;
	}
	break;

    case aug_gcc_eh_z:{
	    /* The Augmentation Data Length is here, followed by the
	       Augmentation Data bytes themselves. */
	}
	break;
    }				/* End switch on augmentation type */
    new_fde = (Dwarf_Fde) _dwarf_get_alloc(dbg, DW_DLA_FDE, 1);
    if (new_fde == NULL) {
	_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
	return (DW_DLV_ERROR);
    }

    new_fde->fd_length = prefix->cf_length;
    new_fde->fd_length_size = prefix->cf_local_length_size;
    new_fde->fd_extension_size = prefix->cf_local_extension_size;
    new_fde->fd_cie_offset = cie_base_offset;
    new_fde->fd_cie_index = cieptr->ci_index;
    new_fde->fd_cie = cieptr;
    new_fde->fd_initial_location = initial_location;
    new_fde->fd_initial_loc_pos = initloc;
    new_fde->fd_address_range = address_range;
    new_fde->fd_fde_start = prefix->cf_start_addr;
    new_fde->fd_fde_instr_start = frame_ptr;
    new_fde->fd_dbg = dbg;
    new_fde->fd_offset_into_exception_tables =
	offset_into_exception_tables;

    new_fde->fd_section_ptr = prefix->cf_section_ptr;
    new_fde->fd_section_index = prefix->cf_section_index;
    new_fde->fd_section_length = prefix->cf_section_length;

    new_fde->fd_gnu_eh_augmentation_bytes = fde_aug_data;
    new_fde->fd_gnu_eh_augmentation_len = fde_aug_data_len;

    *fde_ptr_out = new_fde;
    return DW_DLV_OK;
}
/* Given augmentation character (the encoding) giving the
address format, read the address from input_field
and return an incremented value 1 past the input bytes of the
address.
Push the address read back thru the *addr pointer.
See LSB (Linux Standar Base)  exception handling documents. 
*/
static int
read_encoded_ptr(Dwarf_Debug dbg,
		 Dwarf_Small * input_field,
		 int gnu_encoding,
		 Dwarf_Unsigned * addr,
		 Dwarf_Small ** input_field_updated)
{
    Dwarf_Word length = 0;
    int value_type = gnu_encoding & 0xf;

    if (gnu_encoding == 0xff) {
	/* There is no data here. */

	*addr = 0;
	*input_field_updated = input_field;
	/* Should we return DW_DLV_NO_ENTRY? */
	return DW_DLV_OK;
    }
    switch (value_type) {
    case DW_EH_PE_absptr:{
	    /* value_type is zero. Treat as pointer size of the object. 
	     */
	    Dwarf_Unsigned ret_value = 0;

	    READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
			   input_field, dbg->de_pointer_size);
	    *addr = ret_value;
	    *input_field_updated = input_field + dbg->de_pointer_size;
	}
	break;
    case DW_EH_PE_uleb128:{
	    Dwarf_Unsigned val = _dwarf_decode_u_leb128(input_field,
							&length);

	    *addr = val;
	    *input_field_updated = input_field + length;
	}
	break;
    case DW_EH_PE_udata2:{
	    Dwarf_Unsigned ret_value = 0;

	    READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
			   input_field, 2);
	    *addr = ret_value;
	    *input_field_updated = input_field + 2;
	}
	break;

    case DW_EH_PE_udata4:{

	    Dwarf_Unsigned ret_value = 0;

	    /* ASSERT: sizeof(Dwarf_ufixed) == 4 */
	    READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
			   input_field, sizeof(Dwarf_ufixed));
	    *addr = ret_value;
	    *input_field_updated = input_field + sizeof(Dwarf_ufixed);
	}
	break;

    case DW_EH_PE_udata8:{
	    Dwarf_Unsigned ret_value = 0;

	    /* ASSERT: sizeof(Dwarf_Unsigned) == 8 */
	    READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
			   input_field, sizeof(Dwarf_Unsigned));
	    *addr = ret_value;
	    *input_field_updated = input_field + sizeof(Dwarf_Unsigned);
	}
	break;

    case DW_EH_PE_sleb128:{
	    Dwarf_Signed val = _dwarf_decode_s_leb128(input_field,
						      &length);

	    *addr = (Dwarf_Unsigned) val;
	    *input_field_updated = input_field + length;
	}
	break;
    case DW_EH_PE_sdata2:{
	    Dwarf_Unsigned val = 0;

	    READ_UNALIGNED(dbg, val, Dwarf_Unsigned, input_field, 2);
	    SIGN_EXTEND(val, 2);
	    *addr = (Dwarf_Unsigned) val;
	    *input_field_updated = input_field + 2;
	}
	break;

    case DW_EH_PE_sdata4:{
	    Dwarf_Unsigned val = 0;

	    /* ASSERT: sizeof(Dwarf_ufixed) == 4 */
	    READ_UNALIGNED(dbg, val,
			   Dwarf_Unsigned, input_field,
			   sizeof(Dwarf_ufixed));
	    SIGN_EXTEND(val, sizeof(Dwarf_ufixed));
	    *addr = (Dwarf_Unsigned) val;
	    *input_field_updated = input_field + sizeof(Dwarf_ufixed);
	}
	break;
    case DW_EH_PE_sdata8:{
	    Dwarf_Unsigned val = 0;

	    /* ASSERT: sizeof(Dwarf_Unsigned) == 8 */
	    READ_UNALIGNED(dbg, val,
			   Dwarf_Unsigned, input_field,
			   sizeof(Dwarf_Unsigned));
	    *addr = (Dwarf_Unsigned) val;
	    *input_field_updated = input_field + sizeof(Dwarf_Unsigned);
	}
	break;
    default:
	return DW_DLV_ERROR;

    };

    return DW_DLV_OK;
}
Exemple #20
0
/*  Return DW_DLV_NO_ENTRY when at the end of
    the ops for this block (a single Dwarf_Loccesc
    and multiple Dwarf_Locs will eventually result
    from calling this till DW_DLV_NO_ENTRY).

    All op reader code should call this to
    extract operator fields. For any
    DWARF version.
*/
static int
_dwarf_read_loc_expr_op(Dwarf_Debug dbg,
    Dwarf_Block_c * loc_block,
    /* Caller: Start numbering at 0. */
    Dwarf_Signed opnumber,

    /* 2 for DWARF 2 etc. */
    Dwarf_Half version_stamp,
    Dwarf_Half offset_size, /* 4 or 8 */
    Dwarf_Half address_size, /* 2,4, 8  */
    Dwarf_Signed startoffset_in, /* offset in block,
        not section offset */

    /* nextoffset_out so caller knows next entry startoffset */
    Dwarf_Unsigned *nextoffset_out,

    /*  The values picked up. */
    Dwarf_Loc_c curr_loc,
    Dwarf_Error * error)
{
    Dwarf_Small *loc_ptr = 0;
    Dwarf_Unsigned loc_len = 0;
    Dwarf_Unsigned offset = startoffset_in;
    Dwarf_Unsigned operand1 = 0;
    Dwarf_Unsigned operand2 = 0;
    Dwarf_Unsigned operand3 = 0;
    Dwarf_Small atom = 0;
    Dwarf_Word leb128_length = 0;

    loc_len = loc_block->bl_len;
    loc_ptr = loc_block->bl_data + offset;

    if (offset == loc_len) {
        return DW_DLV_NO_ENTRY;
    }

    memset(curr_loc,0,sizeof(*curr_loc));

    curr_loc->lr_opnumber = opnumber;
    curr_loc->lr_offset = offset;

    atom = *(Dwarf_Small *) loc_ptr;
    loc_ptr++;
    offset++;
    curr_loc->lr_atom = atom;
    switch (atom) {

    case DW_OP_reg0:
    case DW_OP_reg1:
    case DW_OP_reg2:
    case DW_OP_reg3:
    case DW_OP_reg4:
    case DW_OP_reg5:
    case DW_OP_reg6:
    case DW_OP_reg7:
    case DW_OP_reg8:
    case DW_OP_reg9:
    case DW_OP_reg10:
    case DW_OP_reg11:
    case DW_OP_reg12:
    case DW_OP_reg13:
    case DW_OP_reg14:
    case DW_OP_reg15:
    case DW_OP_reg16:
    case DW_OP_reg17:
    case DW_OP_reg18:
    case DW_OP_reg19:
    case DW_OP_reg20:
    case DW_OP_reg21:
    case DW_OP_reg22:
    case DW_OP_reg23:
    case DW_OP_reg24:
    case DW_OP_reg25:
    case DW_OP_reg26:
    case DW_OP_reg27:
    case DW_OP_reg28:
    case DW_OP_reg29:
    case DW_OP_reg30:
    case DW_OP_reg31:
        break;

    case DW_OP_regx:
        operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;
        break;

    case DW_OP_lit0:
    case DW_OP_lit1:
    case DW_OP_lit2:
    case DW_OP_lit3:
    case DW_OP_lit4:
    case DW_OP_lit5:
    case DW_OP_lit6:
    case DW_OP_lit7:
    case DW_OP_lit8:
    case DW_OP_lit9:
    case DW_OP_lit10:
    case DW_OP_lit11:
    case DW_OP_lit12:
    case DW_OP_lit13:
    case DW_OP_lit14:
    case DW_OP_lit15:
    case DW_OP_lit16:
    case DW_OP_lit17:
    case DW_OP_lit18:
    case DW_OP_lit19:
    case DW_OP_lit20:
    case DW_OP_lit21:
    case DW_OP_lit22:
    case DW_OP_lit23:
    case DW_OP_lit24:
    case DW_OP_lit25:
    case DW_OP_lit26:
    case DW_OP_lit27:
    case DW_OP_lit28:
    case DW_OP_lit29:
    case DW_OP_lit30:
    case DW_OP_lit31:
        operand1 = atom - DW_OP_lit0;
        break;

    case DW_OP_addr:
        READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned,
            loc_ptr, address_size);
        loc_ptr += address_size;
        offset += address_size;
        break;

    case DW_OP_const1u:
        operand1 = *(Dwarf_Small *) loc_ptr;
        loc_ptr = loc_ptr + 1;
        offset = offset + 1;
        break;

    case DW_OP_const1s:
        operand1 = *(Dwarf_Sbyte *) loc_ptr;
        SIGN_EXTEND(operand1,1);
        loc_ptr = loc_ptr + 1;
        offset = offset + 1;
        break;

    case DW_OP_const2u:
        READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2);
        loc_ptr = loc_ptr + 2;
        offset = offset + 2;
        break;

    case DW_OP_const2s:
        READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2);
        SIGN_EXTEND(operand1,2);
        loc_ptr = loc_ptr + 2;
        offset = offset + 2;
        break;

    case DW_OP_const4u:
        READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4);
        loc_ptr = loc_ptr + 4;
        offset = offset + 4;
        break;

    case DW_OP_const4s:
        READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4);
        SIGN_EXTEND(operand1,4);
        loc_ptr = loc_ptr + 4;
        offset = offset + 4;
        break;

    case DW_OP_const8u:
        READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 8);
        loc_ptr = loc_ptr + 8;
        offset = offset + 8;
        break;

    case DW_OP_const8s:
        READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 8);
        loc_ptr = loc_ptr + 8;
        offset = offset + 8;
        break;

    case DW_OP_constu:
        operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;
        break;

    case DW_OP_consts:
        operand1 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;
        break;

    case DW_OP_fbreg:
        operand1 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;
        break;

    case DW_OP_breg0:
    case DW_OP_breg1:
    case DW_OP_breg2:
    case DW_OP_breg3:
    case DW_OP_breg4:
    case DW_OP_breg5:
    case DW_OP_breg6:
    case DW_OP_breg7:
    case DW_OP_breg8:
    case DW_OP_breg9:
    case DW_OP_breg10:
    case DW_OP_breg11:
    case DW_OP_breg12:
    case DW_OP_breg13:
    case DW_OP_breg14:
    case DW_OP_breg15:
    case DW_OP_breg16:
    case DW_OP_breg17:
    case DW_OP_breg18:
    case DW_OP_breg19:
    case DW_OP_breg20:
    case DW_OP_breg21:
    case DW_OP_breg22:
    case DW_OP_breg23:
    case DW_OP_breg24:
    case DW_OP_breg25:
    case DW_OP_breg26:
    case DW_OP_breg27:
    case DW_OP_breg28:
    case DW_OP_breg29:
    case DW_OP_breg30:
    case DW_OP_breg31:
        operand1 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;
        break;

    case DW_OP_bregx:
        /* uleb reg num followed by sleb offset */
        operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;

        operand2 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;
        break;

    case DW_OP_dup:
    case DW_OP_drop:
        break;

    case DW_OP_pick:
        operand1 = *(Dwarf_Small *) loc_ptr;
        loc_ptr = loc_ptr + 1;
        offset = offset + 1;
        break;

    case DW_OP_over:
    case DW_OP_swap:
    case DW_OP_rot:
    case DW_OP_deref:
        break;

    case DW_OP_deref_size:
        operand1 = *(Dwarf_Small *) loc_ptr;
        loc_ptr = loc_ptr + 1;
        offset = offset + 1;
        break;

    case DW_OP_xderef:
        break;

    case DW_OP_xderef_type:        /* DWARF5 */
        operand1 = *(Dwarf_Small *) loc_ptr;
        loc_ptr = loc_ptr + 1;
        offset = offset + 1;
        operand2 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;

        break;

    case DW_OP_xderef_size:
        operand1 = *(Dwarf_Small *) loc_ptr;
        loc_ptr = loc_ptr + 1;
        offset = offset + 1;
        break;

    case DW_OP_abs:
    case DW_OP_and:
    case DW_OP_div:
    case DW_OP_minus:
    case DW_OP_mod:
    case DW_OP_mul:
    case DW_OP_neg:
    case DW_OP_not:
    case DW_OP_or:
    case DW_OP_plus:
        break;

    case DW_OP_plus_uconst:
        operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;
        break;

    case DW_OP_shl:
    case DW_OP_shr:
    case DW_OP_shra:
    case DW_OP_xor:
        break;

    case DW_OP_le:
    case DW_OP_ge:
    case DW_OP_eq:
    case DW_OP_lt:
    case DW_OP_gt:
    case DW_OP_ne:
        break;

    case DW_OP_skip:
    case DW_OP_bra:
        READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2);
        loc_ptr = loc_ptr + 2;
        offset = offset + 2;
        break;

    case DW_OP_piece:
        operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;
        break;

    case DW_OP_nop:
        break;
    case DW_OP_push_object_address: /* DWARF3 */
        break;
    case DW_OP_call2:       /* DWARF3 */
        READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2);
        loc_ptr = loc_ptr + 2;
        offset = offset + 2;
        break;

    case DW_OP_call4:       /* DWARF3 */
        READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4);
        loc_ptr = loc_ptr + 4;
        offset = offset + 4;
        break;
    case DW_OP_call_ref:    /* DWARF3 */
        READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr,
            offset_size);
        loc_ptr = loc_ptr + offset_size;
        offset = offset + offset_size;
        break;

    case DW_OP_form_tls_address:    /* DWARF3f */
        break;
    case DW_OP_call_frame_cfa:      /* DWARF3f */
        break;
    case DW_OP_bit_piece:   /* DWARF3f */
        /* uleb size in bits followed by uleb offset in bits */
        operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;

        operand2 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;
        break;

        /*  The operator means: push the currently computed
            (by the operations encountered so far in this
            expression) onto the expression stack as the offset
            in thread-local-storage of the variable. */
    case DW_OP_GNU_push_tls_address: /* 0xe0  */
        /* Believed to have no operands. */
        /* Unimplemented in gdb 7.5.1 ? */
        break;
    case DW_OP_deref_type:     /* DWARF5 */
    case DW_OP_GNU_deref_type: /* 0xf6 */
        operand1 = *(Dwarf_Small *) loc_ptr;
        loc_ptr = loc_ptr + 1;
        offset = offset + 1;

        /* die offset (uleb128). */
        operand2 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;
        break;

    case DW_OP_implicit_value: /* DWARF4 0xa0 */
        /*  uleb length of value bytes followed by that
            number of bytes of the value. */
        operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;

        /*  Second operand is block of 'operand1' bytes of stuff. */
        /*  This using the second operand as a pointer
            is quite ugly. */
        /*  This gets an ugly compiler warning. Sorry. */
        operand2 = (Dwarf_Unsigned)loc_ptr;
        offset = offset + operand1;
        loc_ptr = loc_ptr + operand1;
        break;
    case DW_OP_stack_value:  /* DWARF4 */
        break;
    case DW_OP_GNU_uninit:            /* 0xf0 */
        /*  Unimplemented in gdb 7.5.1  */
        /*  Carolyn Tice: Follws a DW_OP_reg or DW_OP_regx
            and marks the reg as being uninitialized. */
        break;
    case DW_OP_GNU_encoded_addr: {      /*  0xf1 */
        /*  Richard Henderson: The operand is an absolute
            address.  The first byte of the value
            is an encoding length: 0 2 4 or 8.  If zero
            it means the following is address-size.
            The address then follows immediately for
            that number of bytes. */
        int length = 0;
            int reares = read_encoded_addr(loc_ptr,dbg,&operand1,
                &length,error);
            if (reares != DW_DLV_OK) {
                return reares;
            }
            loc_ptr += length;
            offset  += length;
        }
        break;
    case DW_OP_implicit_pointer:       /* DWARF5 */
    case DW_OP_GNU_implicit_pointer:{  /* 0xf2 */
        /*  Jakub Jelinek: The value is an optimized-out
            pointer value. Represented as
            an offset_size DIE offset
            (a simple unsigned integer) in DWARF3,4
            followed by a signed leb128 offset.
            For DWARF2, it is actually pointer size
            (address size).
            http://www.dwarfstd.org/ShowIssue.php?issue=100831.1 */
        Dwarf_Small iplen = offset_size;
        if (version_stamp == DW_CU_VERSION2 /* 2 */ ) {
            iplen = address_size;
        }
        READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr,
            iplen);
        loc_ptr = loc_ptr + iplen;
        offset = offset + iplen;

        operand2 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;
        }

        break;
    case DW_OP_entry_value:       /* DWARF5 */
    case DW_OP_GNU_entry_value:       /* 0xf3 */
        /*  Jakub Jelinek: A register reused really soon,
            but the value is unchanged.  So to represent
            that value we have a uleb128 size followed
            by a DWARF expression block that size.
            http://www.dwarfstd.org/ShowIssue.php?issue=100909.1 */

        /*  uleb length of value bytes followed by that
            number of bytes of the value. */
        operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;

        /*  Second operand is block of 'operand1' bytes of stuff. */
        /*  This using the second operand as a pointer
            is quite ugly. */
        /*  This gets an ugly compiler warning. Sorry. */
        operand2 = (Dwarf_Unsigned)loc_ptr;
        offset = offset + operand1;
        loc_ptr = loc_ptr + operand1;
        break;
    case DW_OP_const_type:           /* DWARF5 */
    case DW_OP_GNU_const_type:       /* 0xf4 */
        {
        /* die offset as uleb. */
        operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;

        /*  Next byte is size of following data block.  */
        operand2 = *loc_ptr;
        loc_ptr = loc_ptr + 1;
        offset = offset + 1;

        /*  Operand 3 points to a value in the block of size
            just gotten as operand2. */
        /*  This gets an ugly compiler warning. Sorry. */
        operand3 = (Dwarf_Unsigned) loc_ptr;
        loc_ptr = loc_ptr + operand2;
        offset = offset + operand2;
        }
        break;

    case DW_OP_regval_type:           /* DWARF5 */
    case DW_OP_GNU_regval_type:       /* 0xf5 */
        /* reg num uleb*/
        operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;
        /* cu die off uleb*/
        operand2 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;
        break;
    case DW_OP_convert:           /* DWARF5 */
    case DW_OP_GNU_convert:       /* 0xf7 */
    case DW_OP_reinterpret:       /* DWARF5 */
    case DW_OP_GNU_reinterpret:       /* 0xf9 */
        /* die offset  or zero */
        operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;
        break;
    case DW_OP_GNU_parameter_ref :       /* 0xfa */
        /* 4 byte unsigned int */
        READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4);
        loc_ptr = loc_ptr + 4;
        offset = offset + 4;
        break;
    case DW_OP_addrx :           /* DWARF5 */
    case DW_OP_GNU_addr_index :  /* 0xfb DebugFission */
        /*  Index into .debug_addr. The value in .debug_addr
            is an address. */
        operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;
        break;
    case DW_OP_constx :          /* DWARF5 */
    case DW_OP_GNU_const_index : /* 0xfc DebugFission */
        /*  Index into .debug_addr. The value in .debug_addr
            is a constant that fits in an address. */
        operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
        loc_ptr = loc_ptr + leb128_length;
        offset = offset + leb128_length;
        break;
    default:
        _dwarf_error(dbg, error, DW_DLE_LOC_EXPR_BAD);
        return DW_DLV_ERROR;
    }

    /* If offset == loc_len this would be normal end-of-expression. */
    if (offset > loc_len) {
        /*  We stepped past the end of the expression.
            This has to be a compiler bug.
            Operators missing their values cannot be detected
            as such except at the end of an expression (like this).
            The results would be wrong if returned.
        */
        _dwarf_error(dbg, error, DW_DLE_LOC_BAD_TERMINATION);
        return DW_DLV_ERROR;
    }
    curr_loc->lr_atom = atom;
    curr_loc->lr_number =  operand1;
    curr_loc->lr_number2 = operand2;
    curr_loc->lr_number3 = operand3;
    *nextoffset_out = offset;
    return DW_DLV_OK;
}
Exemple #21
0
int interp_control() {
    uint32_t opcode = GET_OPCODE(if_id.inst);
    uint32_t address;
    switch (opcode) {

    case OPCODE_R :
        id_ex.reg_write     = true;
        id_ex.reg_dst       = GET_RD(if_id.inst);
        id_ex.rt            = GET_RT(if_id.inst);
        id_ex.rs_value      = regs[GET_RS(if_id.inst)];
        id_ex.rt_value      = regs[id_ex.rt];
        id_ex.funct         = GET_FUNCT(if_id.inst);
        id_ex.shamt         = GET_SHAMT(if_id.inst);
        if (id_ex.funct == FUNCT_JR) {
            id_ex.jump        = true;
            id_ex.jump_target = id_ex.rs_value;
        }
        break;

    case OPCODE_BEQ :
        id_ex.branch        = true;
        id_ex.beq           = true;
        id_ex.rt            = GET_RT(if_id.inst);
        id_ex.rs_value      = regs[GET_RS(if_id.inst)];
        id_ex.rt_value      = regs[id_ex.rt];
        id_ex.sign_ext_imm  = SIGN_EXTEND(GET_IMM(if_id.inst));
        // INSTRUKTOR 0: no reason to updates fields that you dont use
        id_ex.funct         = FUNCT_SUB;
        break;

    case OPCODE_BNE :
        id_ex.branch        = true;
        id_ex.beq           = false;
        id_ex.rt            = GET_RT(if_id.inst);
        id_ex.rs_value      = regs[GET_RS(if_id.inst)];
        id_ex.rt_value      = regs[id_ex.rt];
        id_ex.sign_ext_imm  = SIGN_EXTEND(GET_IMM(if_id.inst));
        id_ex.funct         = FUNCT_SUB;
        break;

    case OPCODE_LW :
        id_ex.mem_read      = true;
        id_ex.reg_write     = true;
        id_ex.alu_src       = true;
        id_ex.mem_to_reg    = true;
        id_ex.reg_dst       = GET_RT(if_id.inst);
        id_ex.rt            = GET_RT(if_id.inst);
        id_ex.rs_value      = regs[GET_RS(if_id.inst)];
        id_ex.rt_value      = regs[id_ex.rt];
        id_ex.sign_ext_imm  = SIGN_EXTEND(GET_IMM(if_id.inst));
        id_ex.funct         = FUNCT_ADD;
        break;

    case OPCODE_SW :
        id_ex.mem_write     = true;
        id_ex.alu_src       = true;
        id_ex.rt            = GET_RT(if_id.inst);
        id_ex.rs_value      = regs[GET_RS(if_id.inst)];
        id_ex.rt_value      = regs[id_ex.rt];
        id_ex.sign_ext_imm  = SIGN_EXTEND(GET_IMM(if_id.inst));
        id_ex.funct         = FUNCT_ADD;
        break;

    case OPCODE_J :
        id_ex.jump          = true;
        address             = GET_ADDRESS(if_id.inst);
        id_ex.jump_target   = (if_id.next_pc & MS_4B) | (address << 2);
        break;

    case OPCODE_JAL :
        id_ex.reg_write     = true;
        id_ex.jump          = true;
        address             = GET_ADDRESS(if_id.inst);
        id_ex.jump_target   = (if_id.next_pc & MS_4B) | (address << 2);
        id_ex.rs_value      = 0;
        id_ex.rt_value      = if_id.next_pc;
        id_ex.reg_dst       = 31;
        id_ex.funct         = FUNCT_ADD;
        break;

    // INSTRUKTOR -2: Make cases for all I-type and J-type instructions
    default:
        printf("ERROR: Unknown opcode in interp_control()\n");
        return ERROR_UNKNOWN_OPCODE;
    }
    return 0;
}
Exemple #22
0
void PopulateOperandsCat1(InstructionLine *InsWord)
{
	int kk;
	switch(InsWord->Opcode)
	{
		case J:		InsWord->Ops.rs = DUMMY_REGISTER;
				InsWord->Ops.rt = DUMMY_REGISTER;
				InsWord->Ops.rd = DUMMY_REGISTER;
				InsWord->Ops.constant = DUMMY_REGISTER;
	
				MASKING(InsWord->InsNumberFrmt,26,1);
				InsWord->Ops.offset = OFFSET_ADJ(wavVals.decodeVal);
			break;		
		case JR:	InsWord->Ops.rt = DUMMY_REGISTER;
				InsWord->Ops.rd = DUMMY_REGISTER;
				InsWord->Ops.constant = DUMMY_REGISTER;
	
				MASKING(InsWord->InsNumberFrmt,26,22);
				InsWord->Ops.rs = wavVals.decodeVal;
			break;
		case BEQ:	InsWord->Ops.rd = DUMMY_REGISTER;
				InsWord->Ops.constant = DUMMY_REGISTER;
	
				MASKING(InsWord->InsNumberFrmt,26,22);
				InsWord->Ops.rs = wavVals.decodeVal;
				MASKING(InsWord->InsNumberFrmt,21,17);
				InsWord->Ops.rt = wavVals.decodeVal;
				MASKING(InsWord->InsNumberFrmt,16,1);
				InsWord->Ops.offset = SIGN_EXTEND(OFFSET_ADJ(wavVals.decodeVal),18);
			break;
		case BLTZ:
		case BGTZ:	InsWord->Ops.rt = DUMMY_REGISTER;
				InsWord->Ops.rd = DUMMY_REGISTER;
				InsWord->Ops.constant = DUMMY_REGISTER;

				MASKING(InsWord->InsNumberFrmt,26,22);
				InsWord->Ops.rs = wavVals.decodeVal;
				MASKING(InsWord->InsNumberFrmt,16,1);
				InsWord->Ops.offset = SIGN_EXTEND(OFFSET_ADJ(wavVals.decodeVal),18);
			break;
		case BREAK:	
			break;
		case SW:
		case LW:	InsWord->Ops.rs = DUMMY_REGISTER;
				InsWord->Ops.rd = DUMMY_REGISTER;
				
				MASKING(InsWord->InsNumberFrmt,26,22);
				InsWord->Ops.constant = wavVals.decodeVal;
				MASKING(InsWord->InsNumberFrmt,21,17);
				InsWord->Ops.rt = wavVals.decodeVal;
				MASKING(InsWord->InsNumberFrmt,16,1);
				InsWord->Ops.offset = SIGN_EXTEND(wavVals.decodeVal,18); //OFFSET_ADJ not required
			break;
		case SLL:	
		case SRL:
		case SRA:	InsWord->Ops.rs = DUMMY_REGISTER;

				MASKING(InsWord->InsNumberFrmt,21,17);
                                InsWord->Ops.rt = wavVals.decodeVal;
                                MASKING(InsWord->InsNumberFrmt,16,12);
                                InsWord->Ops.rd = wavVals.decodeVal;
                                MASKING(InsWord->InsNumberFrmt,11,7);
                                InsWord->Ops.constant = wavVals.decodeVal;
			break;
		case NOP:
			break;
		default:
			/* -- To-do -- 
	               	 Error Handling 
                	*/
			break;
	}
}
Exemple #23
0
//------------------------------------------------------------------------
// Decodes an instruction "w" into cmd structure
bool decode_instruction(uint32 w, insn_t &cmd)
{
#define PARSE_L12 (((w & 1) << 11) | (w >> 21))
#define PARSE_R1  (w & 0x1F)
#define PARSE_R2  ((w & 0xF800) >> 11)

  typedef struct
  {
    int itype;
    int flags;
  } itype_flags_t;
  // If an instruction deals with displacement it should
  // initialize this pointer to the operand location.
  // At the end we will transform the operand to o_mem
  // if we know how to resolve its address
  op_t *displ_op = NULL;

  do
  {
    uint32 op;

    //
    // Format I
    //
    op = (w & 0x7E0) >> 5; // Take bit5->bit10
    if ( op <= 0xF )
    {
      static const int inst_1[] =
      {
        /* MOV reg1, reg2 */ NEC850_MOV,             /* NOT reg1, reg2 */ NEC850_NOT,
        /* DIVH  reg1, reg2 */ NEC850_DIVH,          /* JMP [reg1] */ NEC850_JMP,
        /* SATSUBR reg1, reg2 */ NEC850_SATSUBR,     /* SATSUB reg1, reg2 */ NEC850_SATSUB,
        /* SATADD reg1, reg2 */ NEC850_SATADD,       /* MULH reg1, reg2 */ NEC850_MULH,
        /* OR reg1, reg2 */ NEC850_OR,               /* XOR reg1, reg2 */ NEC850_XOR,
        /* AND reg1, reg2 */ NEC850_AND,             /* TST reg1, reg2 */ NEC850_TST,
        /* SUBR reg1, reg2 */ NEC850_SUBR,           /* SUB reg1, reg2 */ NEC850_SUB,
        /* ADD reg1, reg2 */ NEC850_ADD,             /* CMP reg1, reg2 */ NEC850_CMP
      };

      //
      // NOP, Equivalent to MOV R, r (where R=r=0)
      if ( w == 0 )
      {
        cmd.itype    = NEC850_NOP;
        cmd.Op1.type = o_void;
        cmd.Op1.dtyp = dt_void;
        break;
      }

      if ( is_v850e )
      {
        if ( w == 0xF840 )
        {
          cmd.itype = NEC850_DBTRAP;
          break;
        }
      }
      uint16 r1 = PARSE_R1;
      uint16 r2 = PARSE_R2;

      cmd.itype     = inst_1[op];
      cmd.Op1.reg   = r1;
      cmd.Op1.type  = o_reg;
      cmd.Op1.dtyp  = dt_dword;

      if ( is_v850e )
      {
        if ( r2 == 0 )
        {
          if ( cmd.itype == NEC850_DIVH )
          {
            cmd.itype = NEC850_SWITCH;
            break;
          }
          else if ( cmd.itype == NEC850_SATSUBR )
          {
            cmd.itype = NEC850_ZXB;
            break;
          }
          else if ( cmd.itype == NEC850_SATSUB )
          {
            cmd.itype = NEC850_SXB;
            break;
          }
          else if ( cmd.itype == NEC850_SATADD )
          {
            cmd.itype = NEC850_ZXH;
            break;
          }
          else if ( cmd.itype == NEC850_MULH )
          {
            cmd.itype = NEC850_SXH;
            break;
          }
        }
        // case when r2 != 0
        else
        {
          // SLD.BU / SLD.HU
          if ( cmd.itype == NEC850_JMP )
          {
            bool   sld_hu = (w >> 4) & 1;
            uint32 addr = w & 0xF;

            if ( sld_hu )
            {
              cmd.itype       = NEC850_SLD_HU;
              cmd.Op1.dtyp    = dt_word;
              addr          <<= 1;
            }
            else
            {
              cmd.itype       = NEC850_SLD_BU;
              cmd.Op1.dtyp    = dt_byte;
            }

            cmd.Op1.type      = o_displ;
            displ_op          = &cmd.Op1;
            cmd.Op1.reg       = rEP;
            cmd.Op1.addr      = addr;
            cmd.Op1.specflag1 = N850F_USEBRACKETS;

            cmd.Op2.type      = o_reg;
            cmd.Op2.reg       = r2;
            cmd.Op2.dtyp      = dt_dword;

            break;
          }
        }
      }
      if ( cmd.itype == NEC850_JMP && r2 == 0 )
      {
        cmd.Op1.specflag1 = N850F_USEBRACKETS;
      }
      else
      {
        cmd.Op2.reg   = r2;
        cmd.Op2.type  = o_reg;
        cmd.Op2.dtyp  = dt_dword;
      }
      break;
    }
    // Format II
    else if ( op >= 0x10 && op <= 0x17 )
    {
      // flag used for sign extension
      static const itype_flags_t inst_2[] =
      {
        { NEC850_MOV,    1 }, /* MOV imm5, reg2 */
        { NEC850_SATADD, 1},  /* SATADD imm5, reg2 */
        { NEC850_ADD,    1 }, /* ADD imm5, reg2 */
        { NEC850_CMP,    1 }, /* CMP imm5, reg2 */
        { NEC850_SHR,    0 }, /* SHR imm5, reg2 */
        { NEC850_SAR,    0 }, /* SAR imm5, reg2 */
        { NEC850_SHL,    0 }, /* SHL imm5, reg2 */
        { NEC850_MULH,   1 }, /* MULH imm5, reg2 */
      };
      op -= 0x10;

      cmd.itype = inst_2[op].itype;
      uint16 r2 = PARSE_R2;

      if ( is_v850e )
      {
        //
        // CALLT
        //
        if ( r2 == 0 && (cmd.itype == NEC850_SATADD || cmd.itype == NEC850_MOV) )
        {
          cmd.itype     = NEC850_CALLT;
          cmd.Op1.dtyp  = dt_byte;
          cmd.Op1.type  = o_imm;
          cmd.Op1.value = w & 0x3F;
          break;
        }
      }

      sval_t v = PARSE_R1;
      if ( inst_2[op].flags == 1 )
      {
        SIGN_EXTEND(sval_t, v, 5);
        cmd.Op1.specflag1 |= N850F_OUTSIGNED;
      }

      cmd.Op1.type  = o_imm;
      cmd.Op1.value = v;
      cmd.Op1.dtyp  = dt_byte;

      cmd.Op2.type  = o_reg;
      cmd.Op2.reg   = r2;
      cmd.Op2.dtyp  = dt_dword;

      // ADD imm, reg -> reg = reg + imm
      if ( cmd.itype == NEC850_ADD && r2 == rSP)
        cmd.auxpref |= N850F_SP;
      break;
    }
    // Format VI
    else if ( op >= 0x30 && op <= 0x37 )
    {
      static const itype_flags_t inst_6[] =
      {
        { NEC850_ADDI,      1 }, /* ADDI imm16, reg1, reg2 */
        { NEC850_MOVEA,     1 }, /* MOVEA imm16, reg1, reg2 */
        { NEC850_MOVHI,     0 }, /* MOVHI imm16, reg1, reg2 */
        { NEC850_SATSUBI,   1 }, /* SATSUBI imm16, reg1, reg2 */
        { NEC850_ORI,       0 }, /* ORI imm16, reg1, reg2 */
        { NEC850_XORI,      0 }, /* XORI imm16, reg1, reg2 */
        { NEC850_ANDI,      0 }, /* ANDI imm16, reg1, reg2 */
        { NEC850_MULHI,     0 }, /* MULHI  imm16, reg1, reg2 */
      };
      op -= 0x30;
      cmd.itype = inst_6[op].itype;

      uint16 r1     = PARSE_R1;
      uint16 r2     = PARSE_R2;
      uint32 imm    = w >> 16;

      //
      // V850E instructions
      if ( is_v850e && r2 == 0 )
      {
        // MOV imm32, R
        if ( cmd.itype == NEC850_MOVEA )
        {
          imm            |= ua_next_word() << 16;
          cmd.Op1.type    = o_imm;
          cmd.Op1.dtyp    = dt_dword;
          cmd.Op1.value   = imm;
          cmd.itype       = NEC850_MOV;

          cmd.Op2.type   = o_reg;
          cmd.Op2.reg    = r1;
          cmd.Op2.dtyp   = dt_dword;
          break;
        }
        // DISPOSE imm5, list12 (reg1 == 0)
        // DISPOSE imm5, list12, [reg1]
        else if ( cmd.itype == NEC850_SATSUBI || cmd.itype == NEC850_MOVHI )
        {
          uint16 r1 = (w >> 16) & 0x1F;
          uint16 L  = PARSE_L12;

          cmd.auxpref   |= N850F_SP; // SP reference

          cmd.Op1.value  = (w & 0x3E) >> 1;
          cmd.Op1.type   = o_imm;
          cmd.Op1.dtyp   = dt_byte;

          cmd.Op2.value  = L;
          cmd.Op2.type   = o_reglist;
          cmd.Op2.dtyp   = dt_word;

          if ( r1 != 0 )
          {
            cmd.Op3.dtyp = dt_dword;
            cmd.Op3.type = o_reg;
            cmd.Op3.reg  = r1;
            cmd.Op3.specflag1 = N850F_USEBRACKETS;

            cmd.itype = NEC850_DISPOSE_r;
          }
          else
          {
            cmd.itype = NEC850_DISPOSE_r0;
          }
          break;
        }
      }
      bool is_signed     = inst_6[op].flags == 1;
      cmd.Op1.type       = o_imm;
      cmd.Op1.dtyp       = dt_dword;
      cmd.Op1.value      = is_signed ? sval_t(int16(imm)) : imm;
      cmd.Op1.specflag1 |= N850F_OUTSIGNED;

      cmd.Op2.type       = o_reg;
      cmd.Op2.reg        = r1;
      cmd.Op2.dtyp       = dt_dword;

      cmd.Op3.type       = o_reg;
      cmd.Op3.reg        = r2;
      cmd.Op3.dtyp       = dt_dword;

      // (ADDI|MOVEA) imm, sp, sp -> sp = sp + imm
      if ( (cmd.itype == NEC850_ADDI || cmd.itype == NEC850_MOVEA)
        && ((r1 == rSP) && (r2 == rSP)) )
      {
        cmd.auxpref |= N850F_SP;
      }
      break;
    }
Exemple #24
0
HRESULT Kernel::GetHandleFromObjectAddress(ULONG32 ObjectAddress, ULONG64 KProcess, ULONG32& Handle)
{
	ULONG32 ObjectTableAddress = 0;
	HRESULT hr = g_ExtData2->ReadVirtual(KProcess + _pOffsets[OffsetId_KProcess_ObjectTable], &ObjectTableAddress, sizeof(ObjectTableAddress), NULL);

	bool winxpormore = true;
	if(winxpormore)
	{
		ULONG TableCode = 0;
		hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(ObjectTableAddress + _pOffsets[OffsetId_HANDLE_TABLE_TableCode]), &TableCode, sizeof(TableCode), NULL);	
		ULONG TableLevel = (ULONG)(TableCode & 3);
		TableCode -= TableLevel;
		
		const int TableSize = 0x200;
		const int cbSizeOfHandleTableEntry = 0x8;
		PCHAR Level1, Level2, Level3;
		switch(TableLevel)
		{
			case 0:
			{
				for(int i=0;i<TableSize;++i)
				{
					Level1 = (PCHAR)TableCode;
					ULONG32 Entry = (ULONG32)&Level1[i*cbSizeOfHandleTableEntry];
					ULONG32 CurrentObjectAddress = 0;
					hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(Entry) , &CurrentObjectAddress, sizeof(CurrentObjectAddress), NULL);	
					if(CurrentObjectAddress-1+0x18 == ObjectAddress)
					{
						Handle = i << 0x2;
						return S_OK;
					}
				}
				break;
			}
			case 1:
			{
				ULONG32 Level1Table[TableSize];
				hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(TableCode) , &Level1Table, sizeof(Level1Table), NULL);
				for(int i=0;i<TableSize;++i)
				{
					ULONG32 Table2Address = Level1Table[i];
					if(Table2Address>0)
					{
						Level2 = (PCHAR)Table2Address;
						for(int j=0;j<TableSize;++j)
						{
							ULONG32 Entry = (ULONG32)&Level2[j*cbSizeOfHandleTableEntry];
							ULONG32 CurrentObjectAddress = 0;
							hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(Entry) , &CurrentObjectAddress, sizeof(CurrentObjectAddress), NULL);	
							if(CurrentObjectAddress-1+0x18 == ObjectAddress)
							{
								Handle = (i << 0x2) | (j << 0xA); 
								return S_OK;
							}
						}
					}
				}
				break;
			}
			case 2:
			{
				ULONG32 Level1Table[TableSize];
				hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(TableCode) , &Level1Table, sizeof(Level1Table), NULL);
				for(int i=0;i<TableSize;++i)
				{
					ULONG32 Table2Address = Level1Table[i];
					if(Table2Address>0)
					{
						ULONG32 Level2Table[TableSize];
						hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(Table2Address) , &Level2Table, sizeof(Level2Table), NULL);
						for(int j=0;j<TableSize;++j)
						{
							ULONG32 Table3Address = Level2Table[i];
							if(Table3Address>0)
							{
								Level3 = (PCHAR)Table3Address;
								for(int k=0;k<TableSize;++k)
								{
									ULONG32 Entry = (ULONG32)&Level3[k*cbSizeOfHandleTableEntry];
									ULONG32 CurrentObjectAddress = 0;
									hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(Entry) , &CurrentObjectAddress, sizeof(CurrentObjectAddress), NULL);	
									if(CurrentObjectAddress-1+0x18 == ObjectAddress)
									{
										Handle = (i << 0x2) | (j << 0xA) | (k << 0x12) ;
										return S_OK;
									}
								}
							}
						}
					}
				}
				break;
			}
		}
	}
	return hr;
}
Exemple #25
0
/*  Given a Dwarf_Block that represents a location expression,
    this function returns a pointer to a Dwarf_Locdesc struct 
    that has its ld_cents field set to the number of location 
    operators in the block, and its ld_s field pointing to a 
    contiguous block of Dwarf_Loc structs.  However, the 
    ld_lopc and ld_hipc values are uninitialized.  Returns 
    NULL on error.  This function assumes that the length of 
    the block is greater than 0.  Zero length location expressions 
    to represent variables that have been optimized away are 
    handled in the calling function.
*/
static Dwarf_Locdesc *
_dwarf_get_locdesc(Dwarf_Debug dbg,
    Dwarf_Block * loc_block,
    Dwarf_Half address_size,
    Dwarf_Addr lowpc,
    Dwarf_Addr highpc, 
    Dwarf_Error * error)
{
    /* Size of the block containing the location expression. */
    Dwarf_Unsigned loc_len = 0;

    /* Sweeps the block containing the location expression. */
    Dwarf_Small *loc_ptr = 0;

    /* Offset of current operator from start of block. */
    Dwarf_Unsigned offset = 0;

    /* Used to chain the Dwarf_Loc_Chain_s structs. */
    Dwarf_Loc_Chain curr_loc = NULL;
    Dwarf_Loc_Chain prev_loc = NULL;
    Dwarf_Loc_Chain head_loc = NULL;

    /* Count of the number of location operators. */
    Dwarf_Unsigned op_count = 0;

    /* Contiguous block of Dwarf_Loc's for Dwarf_Locdesc. */
    Dwarf_Loc *block_loc = 0;

    /* Dwarf_Locdesc pointer to be returned. */
    Dwarf_Locdesc *locdesc = 0;

    Dwarf_Word leb128_length = 0;
    Dwarf_Unsigned i = 0;

    /* ***** BEGIN CODE ***** */

    loc_len = loc_block->bl_len;
    loc_ptr = loc_block->bl_data;

    offset = 0;
    op_count = 0;
    while (offset < loc_len) {
        Dwarf_Unsigned operand1 = 0;
        Dwarf_Unsigned operand2 = 0;
        Dwarf_Small atom = 0;

        op_count++;
        atom = *(Dwarf_Small *) loc_ptr;
        loc_ptr++;
        offset++;
        curr_loc =
            (Dwarf_Loc_Chain) _dwarf_get_alloc(dbg, DW_DLA_LOC_CHAIN,
                1);
        if (curr_loc == NULL) {
            /*  Some memory may leak here.  */
            _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
            return (NULL);
        }
        curr_loc->lc_offset = offset;
        curr_loc->lc_atom = atom;
        switch (atom) {

        case DW_OP_reg0:
        case DW_OP_reg1:
        case DW_OP_reg2:
        case DW_OP_reg3:
        case DW_OP_reg4:
        case DW_OP_reg5:
        case DW_OP_reg6:
        case DW_OP_reg7:
        case DW_OP_reg8:
        case DW_OP_reg9:
        case DW_OP_reg10:
        case DW_OP_reg11:
        case DW_OP_reg12:
        case DW_OP_reg13:
        case DW_OP_reg14:
        case DW_OP_reg15:
        case DW_OP_reg16:
        case DW_OP_reg17:
        case DW_OP_reg18:
        case DW_OP_reg19:
        case DW_OP_reg20:
        case DW_OP_reg21:
        case DW_OP_reg22:
        case DW_OP_reg23:
        case DW_OP_reg24:
        case DW_OP_reg25:
        case DW_OP_reg26:
        case DW_OP_reg27:
        case DW_OP_reg28:
        case DW_OP_reg29:
        case DW_OP_reg30:
        case DW_OP_reg31:
            break;

        case DW_OP_regx:
            operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

        case DW_OP_lit0:
        case DW_OP_lit1:
        case DW_OP_lit2:
        case DW_OP_lit3:
        case DW_OP_lit4:
        case DW_OP_lit5:
        case DW_OP_lit6:
        case DW_OP_lit7:
        case DW_OP_lit8:
        case DW_OP_lit9:
        case DW_OP_lit10:
        case DW_OP_lit11:
        case DW_OP_lit12:
        case DW_OP_lit13:
        case DW_OP_lit14:
        case DW_OP_lit15:
        case DW_OP_lit16:
        case DW_OP_lit17:
        case DW_OP_lit18:
        case DW_OP_lit19:
        case DW_OP_lit20:
        case DW_OP_lit21:
        case DW_OP_lit22:
        case DW_OP_lit23:
        case DW_OP_lit24:
        case DW_OP_lit25:
        case DW_OP_lit26:
        case DW_OP_lit27:
        case DW_OP_lit28:
        case DW_OP_lit29:
        case DW_OP_lit30:
        case DW_OP_lit31:
            operand1 = atom - DW_OP_lit0;
            break;

        case DW_OP_addr:
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned,
                loc_ptr, address_size);
            loc_ptr += address_size;
            offset += address_size;
            break;

        case DW_OP_const1u:
            operand1 = *(Dwarf_Small *) loc_ptr;
            loc_ptr = loc_ptr + 1;
            offset = offset + 1;
            break;

        case DW_OP_const1s:
            operand1 = *(Dwarf_Sbyte *) loc_ptr;
            SIGN_EXTEND(operand1,1);
            loc_ptr = loc_ptr + 1;
            offset = offset + 1;
            break;

        case DW_OP_const2u:
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2);
            loc_ptr = loc_ptr + 2;
            offset = offset + 2;
            break;

        case DW_OP_const2s:
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2);
            SIGN_EXTEND(operand1,2);
            loc_ptr = loc_ptr + 2;
            offset = offset + 2;
            break;

        case DW_OP_const4u:
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4);
            loc_ptr = loc_ptr + 4;
            offset = offset + 4;
            break;

        case DW_OP_const4s:
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4);
            SIGN_EXTEND(operand1,4);
            loc_ptr = loc_ptr + 4;
            offset = offset + 4;
            break;

        case DW_OP_const8u:
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 8);
            loc_ptr = loc_ptr + 8;
            offset = offset + 8;
            break;

        case DW_OP_const8s:
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 8);
            loc_ptr = loc_ptr + 8;
            offset = offset + 8;
            break;

        case DW_OP_constu:
            operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

        case DW_OP_consts:
            operand1 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

        case DW_OP_fbreg:
            operand1 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

        case DW_OP_breg0:
        case DW_OP_breg1:
        case DW_OP_breg2:
        case DW_OP_breg3:
        case DW_OP_breg4:
        case DW_OP_breg5:
        case DW_OP_breg6:
        case DW_OP_breg7:
        case DW_OP_breg8:
        case DW_OP_breg9:
        case DW_OP_breg10:
        case DW_OP_breg11:
        case DW_OP_breg12:
        case DW_OP_breg13:
        case DW_OP_breg14:
        case DW_OP_breg15:
        case DW_OP_breg16:
        case DW_OP_breg17:
        case DW_OP_breg18:
        case DW_OP_breg19:
        case DW_OP_breg20:
        case DW_OP_breg21:
        case DW_OP_breg22:
        case DW_OP_breg23:
        case DW_OP_breg24:
        case DW_OP_breg25:
        case DW_OP_breg26:
        case DW_OP_breg27:
        case DW_OP_breg28:
        case DW_OP_breg29:
        case DW_OP_breg30:
        case DW_OP_breg31:
            operand1 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

        case DW_OP_bregx:
            /* uleb reg num followed by sleb offset */
            operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;

            operand2 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

        case DW_OP_dup:
        case DW_OP_drop:
            break;

        case DW_OP_pick:
            operand1 = *(Dwarf_Small *) loc_ptr;
            loc_ptr = loc_ptr + 1;
            offset = offset + 1;
            break;

        case DW_OP_over:
        case DW_OP_swap:
        case DW_OP_rot:
        case DW_OP_deref:
            break;

        case DW_OP_deref_size:
            operand1 = *(Dwarf_Small *) loc_ptr;
            loc_ptr = loc_ptr + 1;
            offset = offset + 1;
            break;

        case DW_OP_xderef:
            break;

        case DW_OP_xderef_size:
            operand1 = *(Dwarf_Small *) loc_ptr;
            loc_ptr = loc_ptr + 1;
            offset = offset + 1;
            break;

        case DW_OP_abs:
        case DW_OP_and:
        case DW_OP_div:
        case DW_OP_minus:
        case DW_OP_mod:
        case DW_OP_mul:
        case DW_OP_neg:
        case DW_OP_not:
        case DW_OP_or:
        case DW_OP_plus:
            break;

        case DW_OP_plus_uconst:
            operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

        case DW_OP_shl:
        case DW_OP_shr:
        case DW_OP_shra:
        case DW_OP_xor:
            break;

        case DW_OP_le:
        case DW_OP_ge:
        case DW_OP_eq:
        case DW_OP_lt:
        case DW_OP_gt:
        case DW_OP_ne:
            break;

        case DW_OP_skip:
        case DW_OP_bra:
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2);
            loc_ptr = loc_ptr + 2;
            offset = offset + 2;
            break;

        case DW_OP_piece:
            operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

        case DW_OP_nop:
            break;
        case DW_OP_push_object_address: /* DWARF3 */
            break;
        case DW_OP_call2:       /* DWARF3 */
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2);
            loc_ptr = loc_ptr + 2;
            offset = offset + 2;
            break;

        case DW_OP_call4:       /* DWARF3 */
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4);
            loc_ptr = loc_ptr + 4;
            offset = offset + 4;
            break;
        case DW_OP_call_ref:    /* DWARF3 */
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr,
                dbg->de_length_size);
            loc_ptr = loc_ptr + dbg->de_length_size;
            offset = offset + dbg->de_length_size;
            break;

        case DW_OP_form_tls_address:    /* DWARF3f */
            break;
        case DW_OP_call_frame_cfa:      /* DWARF3f */
            break;
        case DW_OP_bit_piece:   /* DWARF3f */
            /* uleb size in bits followed by uleb offset in bits */
            operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;

            operand2 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

            /*  The operator means: push the currently computed 
                (by the operations encountered so far in this
                expression) onto the expression stack as the offset
                in thread-local-storage of the variable. */
        case DW_OP_GNU_push_tls_address:
            break;

        case DW_OP_implicit_value: /* DWARF4 */
            /*  uleb length of value bytes followed by that
                number of bytes of the value. */
            operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;

            /*  Second operand is block of 'operand1' bytes of stuff. */
            /*  This using the second operand as a pointer
                is quite ugly. */
            /*  This gets an ugly compiler warning. Sorry. */
            operand2 = (Dwarf_Unsigned)loc_ptr; 
            offset = offset + operand1;
            loc_ptr = loc_ptr + operand1;
            break;
        case DW_OP_stack_value:  /* DWARF4 */
            break;
        case DW_OP_GNU_uninit:            /*  0xf0  GNU */
            /*  Carolyn Tice: Follws a DW_OP_reg or DW_OP_regx
                and marks the reg as being uninitialized. */
            break;
        case DW_OP_GNU_encoded_addr: {      /*  0xf1  GNU */
            /*  Richard Henderson: The operand is an absolute
                address.  The first byte of the value
                is an encoding length: 0 2 4 or 8.  If zero
                it means the following is address-size.
                The address then follows immediately for
                that number of bytes. */
                int length = 0;
                int reares = read_encoded_addr(loc_ptr,dbg,&operand1,
                   &length,error);
                if(reares != DW_DLV_OK) {
                    /*  Oops. The caller will notice and
                        will issue DW_DLV_ERROR. */
                    return NULL;
                }
                loc_ptr += length;
                offset  += length;
            }
            break;
        case DW_OP_GNU_implicit_pointer:  /*  0xf2  GNU */
            /*  Jakub Jelinek: The value is an optimized-out
                pointer value. Represented as
                an offset_size (address_size) DIE offset
                (as simple unsigned integer) followed by
                a signed leb128 offset. 
                http://www.dwarfstd.org/ShowIssue.php?issue=100831.1 */
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr,
                dbg->de_length_size);
            loc_ptr = loc_ptr + dbg->de_length_size;
            offset = offset + dbg->de_length_size;

            operand2 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;

            break;
        case DW_OP_GNU_entry_value:       /*  0xf3  GNU */
            /*  Jakub Jelinek: A register reused really soon,
                but the value is unchanged.  So to represent
                that value we have a uleb128 size followed
                by a DWARF expression block that size.
                http://www.dwarfstd.org/ShowIssue.php?issue=100909.1 */

            /*  uleb length of value bytes followed by that
                number of bytes of the value. */
            operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;

            /*  Second operand is block of 'operand1' bytes of stuff. */
            /*  This using the second operand as a pointer
                is quite ugly. */
            /*  This gets an ugly compiler warning. Sorry. */
            operand2 = (Dwarf_Unsigned)loc_ptr;
            offset = offset + operand1;
            loc_ptr = loc_ptr + operand1;
            break;

        default:
            /*  Some memory does leak here.  */

            _dwarf_error(dbg, error, DW_DLE_LOC_EXPR_BAD);
            return (NULL);
        }

        /* If offset == loc_len this would be normal end-of-expression. */
        if (offset > loc_len) {
            /*  We stepped past the end of the expression.
                This has to be a compiler bug.
                Operators missing their values cannot be detected
                as such except at the end of an expression (like this).
                The results would be wrong if returned.
                Some memory may leak here.
            */
            _dwarf_error(dbg, error, DW_DLE_LOC_BAD_TERMINATION);
            return (NULL);
        }

        curr_loc->lc_number = operand1;
        curr_loc->lc_number2 = operand2;

        if (head_loc == NULL)
            head_loc = prev_loc = curr_loc;
        else {
            prev_loc->lc_next = curr_loc;
            prev_loc = curr_loc;
        }
    }

    block_loc =
        (Dwarf_Loc *) _dwarf_get_alloc(dbg, DW_DLA_LOC_BLOCK, op_count);
    if (block_loc == NULL) {
        /*  Some memory does leak here.  */
        _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
        return (NULL);
    }

    curr_loc = head_loc;
    for (i = 0; i < op_count; i++) {
        (block_loc + i)->lr_atom = curr_loc->lc_atom;
        (block_loc + i)->lr_number = curr_loc->lc_number;
        (block_loc + i)->lr_number2 = curr_loc->lc_number2;
        (block_loc + i)->lr_offset = curr_loc->lc_offset;

        prev_loc = curr_loc;
        curr_loc = curr_loc->lc_next;
        dwarf_dealloc(dbg, prev_loc, DW_DLA_LOC_CHAIN);
    }

    locdesc =
        (Dwarf_Locdesc *) _dwarf_get_alloc(dbg, DW_DLA_LOCDESC, 1);
    if (locdesc == NULL) {
        _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
        return (NULL);
    }

    locdesc->ld_cents = op_count;
    locdesc->ld_s = block_loc;
    locdesc->ld_from_loclist = loc_block->bl_from_loclist;
    locdesc->ld_section_offset = loc_block->bl_section_offset;
    locdesc->ld_lopc = lowpc;
    locdesc->ld_hipc = highpc;

    return (locdesc);
}
Exemple #26
0
HRESULT Kernel::GetThreadInfo(ULONG32 EThreadAddress)
{
	ULONG32 EThreadClientIdAddress = EThreadAddress + _pOffsets[OffsetId_EThread_ClientId];
	CLIENT_ID ClientId;
	HRESULT hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(EThreadClientIdAddress), &ClientId, sizeof(ClientId), NULL);

	printf("Thread %08x, Client Id %04x.%04x \n", EThreadAddress, ClientId.UniqueProcess, ClientId.UniqueThread);

	ULONG32 WinThread32Address;
	hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(EThreadAddress + _pOffsets[OffsetId_EThread_Win32Thread]), &WinThread32Address, sizeof(WinThread32Address), NULL);

	printf("    Win32Thread %x \n", WinThread32Address);

	if(WinThread32Address)
	{
		ULONG32 HwndListAddress	= 0;
		
		hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(WinThread32Address + offset_Win32thread_HwndList), &HwndListAddress, sizeof(HwndListAddress), NULL);
		printf("    HwndListAddress %x \n", HwndListAddress);
		if(HwndListAddress)
		{ 
			ULONG32 WinThread32BackAddress = 0;
			HWND hWnd = 0;
			do
			{
				hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(HwndListAddress + offset_HWNDLIST_Handle), &hWnd, sizeof(hWnd), NULL);
				hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(HwndListAddress + offset_HWNDLIST_Win32Thread), &WinThread32BackAddress, sizeof(WinThread32BackAddress), NULL);

				printf("  List %x  Hwnd %x \n", HwndListAddress, hWnd);

				_pCurrentSnapshot->AddHandle(SIGN_EXTEND(HwndListAddress), (HANDLE)hWnd);
				_pCurrentSnapshot->AddOwnedObject(SIGN_EXTEND(HwndListAddress), SIGN_EXTEND(EThreadAddress));
				// TODO: Get the Window Name
				_pCurrentSnapshot->AddObject(SIGN_EXTEND(HwndListAddress), 99, 99, 0, L"HWND");

				hr = g_ExtData2->ReadVirtual(SIGN_EXTEND(HwndListAddress + offset_HWNDLIST_Next), &HwndListAddress, sizeof(HwndListAddress), NULL);

			}while(HwndListAddress && (WinThread32BackAddress==WinThread32Address));
		}
	}
	_pCurrentSnapshot->AddThread(SIGN_EXTEND(EThreadAddress), ClientId.UniqueThread);
	return hr;
}
Exemple #27
0
/* Gibt das Programm aus */
void printProgram(unsigned int *code){
  int zeile, index, anzahlArgumente;
  
  zeile = (code[programCounter]&0xFF000000)>>24;



  
  if(zeile==HALT){
    /* ganze Zeile ueberpruefen um festzustellen, ob es wirklich ein HALT ist,
       oder ob es eine .addr der VMT ist*/
    if((code[programCounter]&0xFFFFFFFF) == 0){
        printf("0x%08x: halt\n",programCounter);
    }else{
        printf("0x%08x: ???\n",programCounter);
    }
  }else if(zeile==PUSHC){
    printf("0x%08x: pushc %5d\n", programCounter, (SIGN_EXTEND(code[programCounter]&0x00FFFFFF)));
  }else if(zeile==ADD){
    printf("0x%08x: add\n",programCounter);
  }else if(zeile==SUB){
    printf("0x%08x: sub\n",programCounter);
  }else if(zeile==MUL){
    printf("0x%08x: mul\n",programCounter);
  }else if(zeile==DIV){
    printf("0x%08x: div\n",programCounter);
  }else if(zeile==MOD){
    printf("0x%08x: mod\n",programCounter);
  }else if(zeile==RDINT){
    printf("0x%08x: rdint\n",programCounter);
  }else if(zeile==WRINT){
    printf("0x%08x: wrint\n",programCounter);
  }else if(zeile==ASF){
    printf("0x%08x: asf %7d\n",programCounter,(SIGN_EXTEND(code[programCounter]&0x00FFFFFF)));
  }else if(zeile==RSF){
    printf("0x%08x: rsf\n",programCounter);
  }else if(zeile==PUSHL){
    printf("0x%08x: pushl %5d\n",programCounter,(SIGN_EXTEND(code[programCounter]&0x00FFFFFF)));
  }else if(zeile==POPL){
    printf("0x%08x: popl %6d\n",programCounter,(SIGN_EXTEND(code[programCounter]&0x00FFFFFF)));
  }else if(zeile==EQ){
    printf("0x%08x: eq \n",programCounter);
  }else if(zeile==NE){
    printf("0x%08x: ne \n",programCounter);
  }else if(zeile==LT){
    printf("0x%08x: lt \n",programCounter);
  }else if(zeile==LE){
    printf("0x%08x: le \n",programCounter);
  }else if(zeile==GT){
    printf("0x%08x: gt \n",programCounter);
  }else if(zeile==GE){
    printf("0x%08x: ge \n",programCounter);
  }else if(zeile==JMP){
    printf("0x%08x: jmp %2d\n",programCounter,(SIGN_EXTEND(code[programCounter]&0x00FFFFFF)));
  }else if(zeile==BRF){
    printf("0x%08x: brf %2d\n",programCounter,(SIGN_EXTEND(code[programCounter]&0x00FFFFFF)));
  }else if(zeile==BRT){
    printf("0x%08x: brt %2d\n",programCounter,(SIGN_EXTEND(code[programCounter]&0x00FFFFFF)));
  }else if(zeile==CALL){
    printf("0x%08x: call %2d\n",programCounter,(SIGN_EXTEND(code[programCounter]&0x00FFFFFF)));
  }else if(zeile==RET){
    printf("0x%08x: ret\n",programCounter);
  }else if(zeile==DROP){
    printf("0x%08x: drop %2d\n",programCounter,(SIGN_EXTEND(code[programCounter]&0x00FFFFFF)));
  }else if(zeile==PUSHR){
    printf("0x%08x: pushr\n",programCounter);
  }else if(zeile==POPR){
    printf("0x%08x: popr\n",programCounter);
  }else if(zeile==DUP){
    printf("0x%08x: dup\n",programCounter);
  }else if(zeile==NEW){
    printf("0x%08x: new %2d\n",programCounter,(SIGN_EXTEND(code[programCounter]&0x00FFFFFF)));
  }else if(zeile==GETF){
    printf("0x%08x: getf %2d\n",programCounter,(SIGN_EXTEND(code[programCounter]&0x00FFFFFF)));
  }else if(zeile==PUTF){
    printf("0x%08x: putf %2d\n",programCounter,(SIGN_EXTEND(code[programCounter]&0x00FFFFFF)));
  }else if(zeile==NEWA){
    printf("0x%08x: newa\n",programCounter);
  }else if(zeile==GETLA){
    printf("0x%08x: getla\n",programCounter);
  }else if(zeile==GETFA){
    printf("0x%08x: getfa\n",programCounter);
  }else if(zeile==PUTFA){
    printf("0x%08x: putfa\n",programCounter);
  }else if(zeile==PUSHN){
    printf("0x%08x: pushn\n",programCounter);
  }else if(zeile==REFEQ){
    printf("0x%08x: refeq\n",programCounter);
  }else if(zeile==REFNE){
    printf("0x%08x: refne\n",programCounter);
  }else if(zeile==VMCALL){
    anzahlArgumente = (code[programCounter]&0x00FF0000)>>16;
    index = (code[programCounter]&0x0000FFFF);
    printf("0x%08x: vmcall %2d,%2d\n", programCounter, anzahlArgumente, index);
  }
Exemple #28
0
/*
    Given a Dwarf_Block that represents a location expression,
    this function returns a pointer to a Dwarf_Locdesc struct 
    that has its ld_cents field set to the number of location 
    operators in the block, and its ld_s field pointing to a 
    contiguous block of Dwarf_Loc structs.  However, the 
    ld_lopc and ld_hipc values are uninitialized.  Returns 
    NULL on error.  This function assumes that the length of 
    the block is greater than 0.  Zero length location expressions 
    to represent variables that have been optimized away are 
    handled in the calling function.
*/
static Dwarf_Locdesc *
_dwarf_get_locdesc(Dwarf_Debug dbg,
    Dwarf_Block * loc_block,
    Dwarf_Half address_size,
    Dwarf_Addr lowpc,
    Dwarf_Addr highpc, 
    Dwarf_Error * error)
{
    /* Size of the block containing the location expression. */
    Dwarf_Unsigned loc_len = 0;

    /* Sweeps the block containing the location expression. */
    Dwarf_Small *loc_ptr = 0;

    /* Current location operator. */
    Dwarf_Small atom = 0;

    /* Offset of current operator from start of block. */
    Dwarf_Unsigned offset = 0;

    /* Operands of current location operator. */
    Dwarf_Unsigned operand1, operand2;

    /* Used to chain the Dwarf_Loc_Chain_s structs. */
    Dwarf_Loc_Chain curr_loc = NULL;
    Dwarf_Loc_Chain prev_loc = NULL;
    Dwarf_Loc_Chain head_loc = NULL;

    /* Count of the number of location operators. */
    Dwarf_Unsigned op_count = 0;

    /* Contiguous block of Dwarf_Loc's for Dwarf_Locdesc. */
    Dwarf_Loc *block_loc = 0;

    /* Dwarf_Locdesc pointer to be returned. */
    Dwarf_Locdesc *locdesc = 0;

    Dwarf_Word leb128_length = 0;
    Dwarf_Unsigned i = 0;

    /* ***** BEGIN CODE ***** */

    loc_len = loc_block->bl_len;
    loc_ptr = loc_block->bl_data;

    offset = 0;
    op_count = 0;
    while (offset < loc_len) {

        operand1 = 0;
        operand2 = 0;
        op_count++;

        atom = *(Dwarf_Small *) loc_ptr;
        loc_ptr++;
        offset++;

        curr_loc =
            (Dwarf_Loc_Chain) _dwarf_get_alloc(dbg, DW_DLA_LOC_CHAIN,
                                               1);
        if (curr_loc == NULL) {
            _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
            return (NULL);
        }
        curr_loc->lc_offset = offset;
        curr_loc->lc_atom = atom;
        switch (atom) {

        case DW_OP_reg0:
        case DW_OP_reg1:
        case DW_OP_reg2:
        case DW_OP_reg3:
        case DW_OP_reg4:
        case DW_OP_reg5:
        case DW_OP_reg6:
        case DW_OP_reg7:
        case DW_OP_reg8:
        case DW_OP_reg9:
        case DW_OP_reg10:
        case DW_OP_reg11:
        case DW_OP_reg12:
        case DW_OP_reg13:
        case DW_OP_reg14:
        case DW_OP_reg15:
        case DW_OP_reg16:
        case DW_OP_reg17:
        case DW_OP_reg18:
        case DW_OP_reg19:
        case DW_OP_reg20:
        case DW_OP_reg21:
        case DW_OP_reg22:
        case DW_OP_reg23:
        case DW_OP_reg24:
        case DW_OP_reg25:
        case DW_OP_reg26:
        case DW_OP_reg27:
        case DW_OP_reg28:
        case DW_OP_reg29:
        case DW_OP_reg30:
        case DW_OP_reg31:
            break;

        case DW_OP_regx:
            operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

        case DW_OP_lit0:
        case DW_OP_lit1:
        case DW_OP_lit2:
        case DW_OP_lit3:
        case DW_OP_lit4:
        case DW_OP_lit5:
        case DW_OP_lit6:
        case DW_OP_lit7:
        case DW_OP_lit8:
        case DW_OP_lit9:
        case DW_OP_lit10:
        case DW_OP_lit11:
        case DW_OP_lit12:
        case DW_OP_lit13:
        case DW_OP_lit14:
        case DW_OP_lit15:
        case DW_OP_lit16:
        case DW_OP_lit17:
        case DW_OP_lit18:
        case DW_OP_lit19:
        case DW_OP_lit20:
        case DW_OP_lit21:
        case DW_OP_lit22:
        case DW_OP_lit23:
        case DW_OP_lit24:
        case DW_OP_lit25:
        case DW_OP_lit26:
        case DW_OP_lit27:
        case DW_OP_lit28:
        case DW_OP_lit29:
        case DW_OP_lit30:
        case DW_OP_lit31:
            operand1 = atom - DW_OP_lit0;
            break;

        case DW_OP_addr:
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned,
                           loc_ptr, address_size);
            loc_ptr += address_size;
            offset += address_size;
            break;

        case DW_OP_const1u:
            operand1 = *(Dwarf_Small *) loc_ptr;
            loc_ptr = loc_ptr + 1;
            offset = offset + 1;
            break;

        case DW_OP_const1s:
            operand1 = *(Dwarf_Sbyte *) loc_ptr;
            SIGN_EXTEND(operand1,1);
            loc_ptr = loc_ptr + 1;
            offset = offset + 1;
            break;

        case DW_OP_const2u:
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2);
            loc_ptr = loc_ptr + 2;
            offset = offset + 2;
            break;

        case DW_OP_const2s:
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2);
            SIGN_EXTEND(operand1,2);
            loc_ptr = loc_ptr + 2;
            offset = offset + 2;
            break;

        case DW_OP_const4u:
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4);
            loc_ptr = loc_ptr + 4;
            offset = offset + 4;
            break;

        case DW_OP_const4s:
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4);
            SIGN_EXTEND(operand1,4);
            loc_ptr = loc_ptr + 4;
            offset = offset + 4;
            break;

        case DW_OP_const8u:
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 8);
            loc_ptr = loc_ptr + 8;
            offset = offset + 8;
            break;

        case DW_OP_const8s:
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 8);
            loc_ptr = loc_ptr + 8;
            offset = offset + 8;
            break;

        case DW_OP_constu:
            operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

        case DW_OP_consts:
            operand1 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

        case DW_OP_fbreg:
            operand1 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

        case DW_OP_breg0:
        case DW_OP_breg1:
        case DW_OP_breg2:
        case DW_OP_breg3:
        case DW_OP_breg4:
        case DW_OP_breg5:
        case DW_OP_breg6:
        case DW_OP_breg7:
        case DW_OP_breg8:
        case DW_OP_breg9:
        case DW_OP_breg10:
        case DW_OP_breg11:
        case DW_OP_breg12:
        case DW_OP_breg13:
        case DW_OP_breg14:
        case DW_OP_breg15:
        case DW_OP_breg16:
        case DW_OP_breg17:
        case DW_OP_breg18:
        case DW_OP_breg19:
        case DW_OP_breg20:
        case DW_OP_breg21:
        case DW_OP_breg22:
        case DW_OP_breg23:
        case DW_OP_breg24:
        case DW_OP_breg25:
        case DW_OP_breg26:
        case DW_OP_breg27:
        case DW_OP_breg28:
        case DW_OP_breg29:
        case DW_OP_breg30:
        case DW_OP_breg31:
            operand1 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

        case DW_OP_bregx:
            /* uleb reg num followed by sleb offset */
            operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;

            operand2 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

        case DW_OP_dup:
        case DW_OP_drop:
            break;

        case DW_OP_pick:
            operand1 = *(Dwarf_Small *) loc_ptr;
            loc_ptr = loc_ptr + 1;
            offset = offset + 1;
            break;

        case DW_OP_over:
        case DW_OP_swap:
        case DW_OP_rot:
        case DW_OP_deref:
            break;

        case DW_OP_deref_size:
            operand1 = *(Dwarf_Small *) loc_ptr;
            loc_ptr = loc_ptr + 1;
            offset = offset + 1;
            break;

        case DW_OP_xderef:
            break;

        case DW_OP_xderef_size:
            operand1 = *(Dwarf_Small *) loc_ptr;
            loc_ptr = loc_ptr + 1;
            offset = offset + 1;
            break;

        case DW_OP_abs:
        case DW_OP_and:
        case DW_OP_div:
        case DW_OP_minus:
        case DW_OP_mod:
        case DW_OP_mul:
        case DW_OP_neg:
        case DW_OP_not:
        case DW_OP_or:
        case DW_OP_plus:
            break;

        case DW_OP_plus_uconst:
            operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

        case DW_OP_shl:
        case DW_OP_shr:
        case DW_OP_shra:
        case DW_OP_xor:
            break;

        case DW_OP_le:
        case DW_OP_ge:
        case DW_OP_eq:
        case DW_OP_lt:
        case DW_OP_gt:
        case DW_OP_ne:
            break;

        case DW_OP_skip:
        case DW_OP_bra:
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2);
            loc_ptr = loc_ptr + 2;
            offset = offset + 2;
            break;

        case DW_OP_piece:
            operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;

        case DW_OP_nop:
            break;
        case DW_OP_push_object_address: /* DWARF3 */
            break;
        case DW_OP_call2:       /* DWARF3 */
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2);
            loc_ptr = loc_ptr + 2;
            offset = offset + 2;
            break;

        case DW_OP_call4:       /* DWARF3 */
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4);
            loc_ptr = loc_ptr + 4;
            offset = offset + 4;
            break;
        case DW_OP_call_ref:    /* DWARF3 */
            READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr,
                           dbg->de_length_size);
            loc_ptr = loc_ptr + dbg->de_length_size;
            offset = offset + dbg->de_length_size;
            break;

        case DW_OP_form_tls_address:    /* DWARF3f */
            break;
        case DW_OP_call_frame_cfa:      /* DWARF3f */
            break;
        case DW_OP_bit_piece:   /* DWARF3f */
            /* uleb size in bits followed by uleb offset in bits */
            operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;

            operand2 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;
            break;
        case DW_OP_implicit_value: /* DWARF4 */
            /* uleb length of value bytes followed by that
               number of bytes of the value. */
            operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
            loc_ptr = loc_ptr + leb128_length;
            offset = offset + leb128_length;

            /* Second operand is block of 'operand1' bytes of stuff. */
            /* This using the second operand as a pointer
               is quite ugly. */
            /* This gets an ugly compiler warning. Sorry. */
            operand2 = (Dwarf_Unsigned)(uintptr_t)loc_ptr; 
            offset = offset + operand1;
            loc_ptr = loc_ptr + operand1;
            break;
        case DW_OP_stack_value:  /* DWARF4 */
            break;


        default:
            _dwarf_error(dbg, error, DW_DLE_LOC_EXPR_BAD);
            return (NULL);
        }


        curr_loc->lc_number = operand1;
        curr_loc->lc_number2 = operand2;

        if (head_loc == NULL)
            head_loc = prev_loc = curr_loc;
        else {
            prev_loc->lc_next = curr_loc;
            prev_loc = curr_loc;
        }
    }

    block_loc =
        (Dwarf_Loc *) _dwarf_get_alloc(dbg, DW_DLA_LOC_BLOCK, op_count);
    if (block_loc == NULL) {
        _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
        return (NULL);
    }

    curr_loc = head_loc;
    for (i = 0; i < op_count; i++) {
        (block_loc + i)->lr_atom = curr_loc->lc_atom;
        (block_loc + i)->lr_number = curr_loc->lc_number;
        (block_loc + i)->lr_number2 = curr_loc->lc_number2;
        (block_loc + i)->lr_offset = curr_loc->lc_offset;

        prev_loc = curr_loc;
        curr_loc = curr_loc->lc_next;
        dwarf_dealloc(dbg, prev_loc, DW_DLA_LOC_CHAIN);
    }

    locdesc =
        (Dwarf_Locdesc *) _dwarf_get_alloc(dbg, DW_DLA_LOCDESC, 1);
    if (locdesc == NULL) {
        _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
        return (NULL);
    }

    locdesc->ld_cents = op_count;
    locdesc->ld_s = block_loc;
    locdesc->ld_from_loclist = loc_block->bl_from_loclist;
    locdesc->ld_section_offset = loc_block->bl_section_offset;
    locdesc->ld_lopc = lowpc;
    locdesc->ld_hipc = highpc;

    return (locdesc);
}