static void AppendDescriptors(u32 reg, Descriptors& descriptors) { if(IsBitSet(reg, 31)) // register contents are reserved return; for(int pos = 24; pos >= 0; pos -= 8) { const u8 descriptor = (u8)bits(reg, pos, pos+7); if(descriptor != 0) descriptors.push_back(descriptor); } }
SSIZE_T parse( BYTE *data, SIZE_T len, Descriptors &descriptors ) { SSIZE_T offset = 0; WORD compatibilityLen = RW(data,offset); if (!compatibilityLen) { // Ignore if not present return 2; } WORD descriptorCount = RW(data,offset); printf( "[dsmcc::compatiblity] Compatibility descriptor: dataLen=%ld, descLen=%d, count=%d\n", len, compatibilityLen, descriptorCount ); // Check if len is ok if (len < compatibilityLen) { printf( "[dsmcc::compatiblity] No data available to parse Compatibility descriptor: descLen=%ld, available=%d\n", len, compatibilityLen ); return compatibilityLen+2; } // Parse descriptors for (WORD desc=0; desc<descriptorCount; desc++) { Descriptor desc; desc.type = RB(data,offset); //BYTE dLen = RB(data,offset); offset += 1; desc.specifier = RDW(data,offset); desc.model = RW(data,offset); desc.version = RW(data,offset); // Parse sub descriptors BYTE subCount = RB(data,offset); for (BYTE sub=0; sub<subCount; sub++) { BYTE subType = RB(data,offset); BYTE subLen = RB(data,offset); // AdditionalInformation offset += subLen; printf( "[dsmcc::compatibility] Warning, subdescriptor not parsed: count=%d, type=%x, len=%x\n", subCount, subType, subLen ); } descriptors.push_back( desc ); } return compatibilityLen+2; }