Exemplo n.º 1
0
HGRIDITEM FindGridItem(HGRIDITEM hParent, ExprNode * expr, HWND hwndGridView)
{
	Symbol *sym;
	HGRIDITEM hItem = 0;
	Structure *parent;

	GVITEM gvitem = { 0, 0, 0, GVIF_PARAM };
	Type *t = TypeView_GetType(hwndGridView, hParent);

	if(IsStruct(t) == false)
		return 0;

	parent = BaseNode(t)->sptr;
	
	for(; expr; expr = expr->right)
	{
		// expr->left will always be EXPR_IDENTIFIER
		if((sym = LookupSymbol(parent->symbolTable, expr->left ? expr->left->str : expr->str)) == 0)
			return 0;	
		
		// look for the Type* node in the GridView
		gvitem.iSubItem = COLIDX_NAME;
		gvitem.mask     = GVIF_PARAM;
		gvitem.param    = (ULONG_PTR)sym->type;
		
		// this *should* succeed, but just in case...
		if((hItem = GridView2_FindChild(hwndGridView, hParent, &gvitem)) == 0)
			return 0;

		Type *base = BaseNode(sym->type);
		
		if(IsStruct(base) && expr->left)
		{
			//sptr   = base->sptr;
			parent	= base->sptr;
			hParent = hItem;
		}
		else if(expr->left == 0)
		{
			return hItem;
		}
		else
		{
			// lvalue is not a structure
			return 0;
		}
	}

	return 0;
}
Exemplo n.º 2
0
Enum * FindEnum(char *enumName)
{
	Symbol *sym;

	if((sym = LookupSymbol(globalTagSymbolList, enumName)) != 0)
	{
		if(sym->type && sym->type->ty == typeENUM)
			return sym->type->eptr;
	}

	if((sym = LookupSymbol(globalIdentifierList, enumName)) != 0)
	{
		Type *baseType = BaseNode(sym->type);
		if(baseType && baseType->ty == typeENUM)
			return baseType ->eptr;
	}

	return 0;
}
Exemplo n.º 3
0
bool CheckRecursion(Structure *parent, TypeDecl *child)
{
	Type *cbt = BaseNode(child->baseType);

	if(cbt->ty == typeSTRUCT || cbt->ty == typeUNION)
	{
		if(cbt->sptr == parent)
			return false;

		for(size_t i = 0; i < cbt->sptr->typeDeclList.size(); i++)
		{
			// check the children as well
			if(!CheckRecursion(parent, cbt->sptr->typeDeclList[i]))
				return false;
		}
	}

	return true;
}
Exemplo n.º 4
0
//
//	offset - offset to read data from for this item
//
size_w FmtData(HWND hwndGV, HGRIDITEM hRoot, Type *type, size_w dwOffset, TypeDecl *typeDecl)
{
	GVITEM gvitem = { 0 };

	Enum *eptr;
	TCHAR buf[200];
	double f;
	size_t i;
	
	DWORD  typeLenLookup[]			= { 0, 1, 2, 1, 2, 4, 8, 4, 8, 4, 2, 2, 4, 8 };
//	TCHAR *typeFmtLookupHex2[]		= { 0, TEXT("%#02x \'%c\'"), TEXT("%#04x '%lc\'"), TEXT("%#02x"), TEXT("%#04x"), TEXT("%#08x"), TEXT("%#0I64x"), TEXT("%#g"), TEXT("%#g") };
	TCHAR *typeFmtLookupHex[]		= { 0, TEXT("%02x \'%c\'"), TEXT("%04x '%lc\'"), TEXT("%02x"), TEXT("%04x"), TEXT("%08x"), TEXT("%0I64x"), TEXT("%#g"), TEXT("%#g") };
	TCHAR *typeFmtLookupSigned[]	= { 0, TEXT("%d \'%c\'"), TEXT("%d \'%lc\'"), TEXT("%d"), TEXT("%hd"), TEXT("%d"), TEXT("%I64d"), TEXT("%#g"), TEXT("%#g") };
	TCHAR *typeFmtLookupUnsigned[]	= { 0, TEXT("%u \'%c\'"), TEXT("%u \'%lc\'"), TEXT("%u"), TEXT("%hu"), TEXT("%u"), TEXT("%I64u"), TEXT("%#g"), TEXT("%#g") };

	TCHAR *fmt;

	bool displaySigned		= false;
	BOOL displayHex			= g_fDisplayHex;
	bool bigEndian			= false;
	TYPE baseType			= BaseType(type);
	bool displayEnum		= false;
	Enum *baseEnum			= 0;

	displaySigned = FindType(type, typeSIGNED) ? true : false;

	if(typeDecl)
	{
		ExprNode *expr;
		if(FindTag(typeDecl->tagList, TOK_ENDIAN, &expr))
		{
			if(strcmp(expr->str, "big") == 0)
				bigEndian = true;
		}

		if(FindTag(typeDecl->tagList, TOK_ENUM, &expr))
		{
			baseEnum = FindEnum(expr->str);
			displayEnum = true;
		}
	}

	if(displayHex)				fmt = typeFmtLookupHex[baseType];
	else if(displaySigned)		fmt = typeFmtLookupSigned[baseType];
	else						fmt = typeFmtLookupUnsigned[baseType];

	BYTE HexData[8];
	HWND hwndHV = GetActiveHexView(g_hwndMain);
	DWORD numread;
	
	numread = HexView_GetData(hwndHV, dwOffset, (BYTE *)&HexData, sizeof(HexData));

	DWORD dwLength = typeLenLookup[type->ty];

	if(numread < dwLength)
	{
		gvitem.pszText		= TEXT("");
		gvitem.iSubItem		= COLIDX_DATA;
		gvitem.state		= 0;
		gvitem.mask			= GVIF_TEXT | GVIF_STATE;
		GridView2_SetItem(hwndGV, hRoot, &gvitem);
		return typeLenLookup[type->ty];
	}

	if(bigEndian || g_fDisplayBigEndian)
		reverse(HexData, dwLength);

	if(FindType(type, typeDOSDATE)) baseType = type->ty;
	if(FindType(type, typeDOSTIME))	baseType = type->ty;
	if(FindType(type, typeFILETIME))baseType = type->ty;
	if(FindType(type, typeTIMET))	baseType = type->ty;

	if(displayEnum)
	{
		if(BaseType(type) == typeENUM)
			eptr = BaseNode(type)->eptr;
		else
			eptr = baseEnum;
		
		WORD *wptr = (WORD *)(&HexData[0]);

		_stprintf(buf, TEXT("%04x"), *wptr);

		for(i = 0; i < eptr->fieldList.size(); i++)
		{
			if(Evaluate(eptr->fieldList[i]->expr) == *wptr)
			{
				_stprintf(buf, TEXT("%hs"), eptr->fieldList[i]->name->name);
				break;
			}
		}

		gvitem.pszText		= buf;
		gvitem.iSubItem		= COLIDX_DATA;
		gvitem.state		= GVIS_DROPDOWN;
		gvitem.mask	= GVIF_TEXT | GVIF_STATE;
		GridView2_SetItem(hwndGV, hRoot, &gvitem);

		return SizeOf(type, 0, 0);
	}
	else
	{
		struct DOSDATE
		{
			WORD day	: 5;
			WORD month	: 4;
			WORD year	: 7;
		} *dosdate = (DOSDATE *)HexData;

		struct DOSTIME
		{
			WORD sec	: 5;
			WORD min	: 6;
			WORD hour	: 5;
		} *dostime = (DOSTIME *)HexData;

		FILETIME ft;
		SYSTEMTIME st;

		switch(baseType)
		{
		case typeDOSTIME:
			_stprintf(buf, TEXT("%02d:%02d:%02d"), dostime->hour, dostime->min, dostime->sec);
			break;

		case typeDOSDATE:
			_stprintf(buf, TEXT("%02d/%02d/%04d"), dosdate->day, dosdate->month, dosdate->year);
			break;

		case typeTIMET:
			UnixTimeToFileTime(*(time_t *)HexData, &ft);
			FileTimeToSystemTime((FILETIME *)HexData, &st);
			_stprintf(buf, TEXT("%02d/%02d/%04d %02d:%02d:%02d"), st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond);
			break;

		case typeFILETIME:
			FileTimeToSystemTime((FILETIME *)HexData, &st);
			_stprintf(buf, TEXT("%02d/%02d/%04d %02d:%02d:%02d"), st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond);
			break;

		case typeCHAR:		
			_stprintf(buf, fmt, HexData[0], HexData[0] < ' ' ? '.' : HexData[0]);
			break;
			
		case typeWCHAR: 
			_stprintf(buf, fmt, *(WCHAR *)(&HexData[0]));
			break;
			
		case typeBYTE:		
			_stprintf(buf, fmt, HexData[0]);
			break;
			
		case typeWORD:
			_stprintf(buf, fmt, *(UINT16 *)(&HexData[0]));			
			break;
			
		case typeDWORD:		
			_stprintf(buf, fmt, *(UINT32 *)(&HexData[0]));
			break;
			
		case typeQWORD:
			_stprintf(buf, fmt, *(UINT64 *)(&HexData[0]));
			break;
			
		case typeFLOAT:
			f = *(float *)(&HexData[0]);
			_stprintf(buf, fmt, f);
			break;
			
		case typeDOUBLE:
			f = *(double*)(&HexData[0]);
			_stprintf(buf, fmt, f);
			break;
			
		case typeENUM:
			eptr = BaseNode(type)->eptr;
			
			{
				WORD *wptr = (WORD *)(&HexData[0]);
				
				_stprintf(buf, TEXT("%04x"), *wptr);
				
				for(i = 0; i < eptr->fieldList.size(); i++)
				{
					if(Evaluate(eptr->fieldList[i]->expr) == *wptr)
					{
						_stprintf(buf, TEXT("%hs"), eptr->fieldList[i]->name->name);
						break;
					}
				}
			}
			
			gvitem.pszText		= buf;
			gvitem.iSubItem		= COLIDX_DATA;
			gvitem.state		= GVIS_DROPDOWN;
			gvitem.mask	= GVIF_TEXT | GVIF_STATE;
			GridView2_SetItem(hwndGV, hRoot, &gvitem);
			
			return 4;
		}
	}

	gvitem.pszText		= buf;
	gvitem.iSubItem		= COLIDX_DATA;
	gvitem.state		= 0;
	gvitem.mask	= GVIF_TEXT | GVIF_STATE | GVIF_COLOR;
	gvitem.color		= numread ? RGB(0,0,0) : RGB(128,128,128);

	GridView2_SetItem(hwndGV, hRoot, &gvitem);

	return typeLenLookup[type->ty];
}