@@ -259,7 +259,7 @@ QSharedPointer<const AnalyzerResult> KaitaiStruct::analyzeBits(
259
259
return AnalyzerResult::error (" Output analysis file doesn't contain a 'sections' specification" );
260
260
}
261
261
QList<RangeHighlight> highlights;
262
- QMap<QString, QPair<Range, QList<QString>>> labelMap ;
262
+ QMap<QString, QSharedPointer<KsField>> fieldMap ;
263
263
QList<QString> topLevel;
264
264
QJsonArray sections = outputObj.value (" sections" ).toArray ();
265
265
int sectionNum = 0 ;
@@ -269,32 +269,43 @@ QSharedPointer<const AnalyzerResult> KaitaiStruct::analyzeBits(
269
269
}
270
270
sectionNum++;
271
271
QJsonObject s = section.toObject ();
272
+
272
273
QString label = QString (" <%1>" ).arg (sectionNum);
273
274
if (s.contains (" label" ) && s.value (" label" ).isString ()) {
274
275
label = s.value (" label" ).toString ();
275
276
}
276
- if (!s.contains (" start" ) || !s.contains (" end" ) || !s.value (" start" ).isDouble () || !s.value (" end" ).isDouble ()) {
277
- labelMap.insert (label, {Range (), {}});
278
- }
279
- else {
277
+ auto field = QSharedPointer<KsField>(new KsField);
278
+ fieldMap.insert (label, field);
279
+ field->label = label;
280
+
281
+ if (s.contains (" start" ) && s.contains (" end" ) && s.value (" start" ).isDouble () && s.value (" end" ).isDouble ()) {
280
282
Range range (qint64 (s.value (" start" ).toDouble ())*8 , qint64 (s.value (" end" ).toDouble ())*8 - 1 );
281
- labelMap.insert (label, {range, {}});
283
+ field->range = range;
284
+ }
285
+
286
+ if (s.contains (" value" )) {
287
+ field->value = s.value (" value" ).toVariant ().toString ();
288
+ }
289
+
290
+ if (s.contains (" type" )) {
291
+ field->type = s.value (" type" ).toVariant ().toString ();
282
292
}
283
293
284
294
if (!s.contains (" parent" ) || s.value (" parent" ).toString ().isEmpty ()) {
285
295
topLevel.append (label);
286
296
}
287
- else if (labelMap .contains (s.value (" parent" ).toString ())) {
288
- labelMap [s.value (" parent" ).toString ()]. second .append (label);
297
+ else if (fieldMap .contains (s.value (" parent" ).toString ())) {
298
+ fieldMap [s.value (" parent" ).toString ()]-> children .append (label);
289
299
}
290
300
}
291
301
292
302
int colorIdx = 0 ;
293
303
for (auto label : topLevel) {
294
- highlights.append (makeHighlight (label, labelMap , colorIdx));
304
+ highlights.append (makeHighlight (label, fieldMap , colorIdx));
295
305
}
296
306
297
307
QSharedPointer<BitInfo> bitInfo = BitInfo::copyFromContainer (container);
308
+ bitInfo->clearHighlightCategory (KAITAI_STRUCT_CATEGORY);
298
309
bitInfo->addHighlights (highlights);
299
310
300
311
if (!kscOutput.isEmpty ()) {
@@ -307,30 +318,30 @@ QSharedPointer<const AnalyzerResult> KaitaiStruct::analyzeBits(
307
318
return AnalyzerResult::result (bitInfo, parameters);
308
319
}
309
320
310
- RangeHighlight KaitaiStruct::makeHighlight (QString label, const QMap<QString, QPair<Range, QList<QString>>> &rangeData , int &colorIdx)
321
+ RangeHighlight KaitaiStruct::makeHighlight (QString label, const QMap<QString, QSharedPointer<KsField>> &fieldData , int &colorIdx)
311
322
{
312
323
QList<QColor> colors = {
313
- QColor (100 , 220 , 100 , 85 ),
314
- QColor (100 , 0 , 255 , 50 ),
315
- QColor (0 , 150 , 230 , 100 ),
316
- QColor (200 , 140 , 0 , 100 ),
317
- QColor (250 , 50 , 0 , 100 )
324
+ QColor (100 , 220 , 100 , 200 ),
325
+ QColor (100 , 0 , 255 , 200 ),
326
+ QColor (0 , 150 , 230 , 200 ),
327
+ QColor (200 , 140 , 0 , 200 ),
328
+ QColor (250 , 50 , 0 , 200 )
318
329
};
319
- auto pair = rangeData .value (label);
320
- if (pair. second .isEmpty ()) {
321
- auto highlight = RangeHighlight (KAITAI_STRUCT_CATEGORY, label, pair. first , colors.at (colorIdx).rgba ());
330
+ auto field = fieldData .value (label);
331
+ if (field-> children .isEmpty ()) {
332
+ auto highlight = RangeHighlight (KAITAI_STRUCT_CATEGORY, label, field-> range , colors.at (colorIdx).rgba (), {}, {field-> type , field-> value } );
322
333
colorIdx = (colorIdx + 1 ) % colors.size ();
323
334
return highlight;
324
335
}
325
336
else {
326
337
int parentColorIndex = colorIdx;
327
338
colorIdx = 0 ;
328
339
QList<RangeHighlight> children;
329
- for (auto child : pair. second ) {
330
- children.append (makeHighlight (child, rangeData , colorIdx));
340
+ for (auto child : field-> children ) {
341
+ children.append (makeHighlight (child, fieldData , colorIdx));
331
342
}
332
343
colorIdx = parentColorIndex;
333
- auto highlight = RangeHighlight (KAITAI_STRUCT_CATEGORY, label, children, colors.at (colorIdx).rgba ());
344
+ auto highlight = RangeHighlight (KAITAI_STRUCT_CATEGORY, label, children, colors.at (colorIdx).rgba (), {field-> type } );
334
345
colorIdx = (colorIdx + 1 ) % colors.size ();
335
346
return highlight;
336
347
}
0 commit comments