Enumeration* DeclarationContext::FindEnum(const std::string& Name, bool Create) { auto entries = split<std::string>(Name, "::"); if (entries.size() == 1) { auto foundEnum = std::find_if(Enums.begin(), Enums.end(), [&](Enumeration* _enum) { return _enum->Name == Name; }); if (foundEnum != Enums.end()) return *foundEnum; if (!Create) return nullptr; auto _enum = new Enumeration(); _enum->Name = Name; _enum->_Namespace = this; Enums.push_back(_enum); return _enum; } auto enumName = entries[entries.size() - 1]; std::vector<std::string> namespaces; std::copy_n(entries.begin(), entries.size() - 1, std::back_inserter(namespaces)); auto _namespace = FindNamespace(namespaces); if (!_namespace) return nullptr; return _namespace->FindEnum(enumName, Create); }
// // 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]; }