1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
|
/* packet-rtmpt.c
* Routines for Real Time Messaging Protocol packet dissection
* metatech <metatech@flashmail.com>
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
/* This dissector is called RTMPT to avoid a conflict with
* the other RTMP protocol (Routing Table Maintenance Protocol) implemented in packet-atalk.c
* (RTMPT normally stands for RTMP-Tunnel via http)
*
* RTMP in a nutshell
*
* The protocol has very few "magic words" to facilitate detection,
* but rather has "magic lengths".
* This protocol has plenty of special cases and few general rules,
* especially regarding the lengths and the structures.
*
* Documentation:
* RTMP protocol description on Wiki of Red5 Open Source Flash Server at
*
* http://trac.red5.org/wiki/Codecs/RTMPSpecification
*
* and the pages to which it links:
*
* http://osflash.org/documentation/rtmp
* http://wiki.gnashdev.org/RTMP
* http://wiki.gnashdev.org/RTMP_Messages_Decoded
* http://www.acmewebworks.com/Downloads/openCS/TheAMF.pdf
* https://rtmp.veriskope.com/pdf/rtmp_specification_1.0.pdf
*
* It's also available from Adobe at
*
* https://www.adobe.com/devnet/rtmp.html
*
* For AMF, see:
*
* http://download.macromedia.com/pub/labs/amf/amf0_spec_121207.pdf
*
* for AMF0 and
*
* http://amf3cplusplus.googlecode.com/svn-history/r4/trunk/doc/amf3_spec_05_05_08.pdf
*
* for AMF3.
*
* For FLV, see:
*
* https://rtmp.veriskope.com/pdf/video_file_format_spec_v10.pdf
*
* For Enhanced RTMP, see:
*
* https://veovera.org/docs/enhanced/enhanced-rtmp-v2.pdf
*
* Default TCP port is 1935
*/
#include "config.h"
#define WS_LOG_DOMAIN "RTMPT"
#include <epan/packet.h>
#include <wsutil/pint.h>
#include <epan/prefs.h>
#include <epan/to_str.h>
#include <epan/expert.h>
#include "packet-tcp.h"
#define MAX_AMF_ITERATIONS 1000
void proto_register_rtmpt(void);
void proto_reg_handoff_rtmpt(void);
void proto_register_amf(void);
static int proto_rtmpt;
static int hf_rtmpt_handshake_c0;
static int hf_rtmpt_handshake_s0;
static int hf_rtmpt_handshake_c1;
static int hf_rtmpt_handshake_s1;
static int hf_rtmpt_handshake_c2;
static int hf_rtmpt_handshake_s2;
static int hf_rtmpt_header_format;
static int hf_rtmpt_header_csid;
static int hf_rtmpt_header_timestamp;
static int hf_rtmpt_header_timestamp_delta;
static int hf_rtmpt_header_body_size;
static int hf_rtmpt_header_typeid;
static int hf_rtmpt_header_streamid;
static int hf_rtmpt_header_ets;
static int hf_rtmpt_scm_chunksize;
static int hf_rtmpt_scm_csid;
static int hf_rtmpt_scm_seq;
static int hf_rtmpt_scm_was;
static int hf_rtmpt_scm_limittype;
static int hf_rtmpt_ucm_eventtype;
static int hf_rtmpt_function_call;
static int hf_rtmpt_function_response;
static int hf_rtmpt_audio_control;
static int hf_rtmpt_audio_multitrack_control;
static int hf_rtmpt_audio_is_ex_header;
static int hf_rtmpt_audio_format;
static int hf_rtmpt_audio_rate;
static int hf_rtmpt_audio_size;
static int hf_rtmpt_audio_type;
static int hf_rtmpt_audio_packet_type;
static int hf_rtmpt_audio_multitrack_type;
static int hf_rtmpt_audio_multitrack_packet_type;
static int hf_rtmpt_audio_fourcc;
static int hf_rtmpt_audio_track_id;
static int hf_rtmpt_audio_track_length;
static int hf_rtmpt_audio_data;
static int hf_rtmpt_video_control;
static int hf_rtmpt_video_multitrack_control;
static int hf_rtmpt_video_is_ex_header;
static int hf_rtmpt_video_type;
static int hf_rtmpt_video_command;
static int hf_rtmpt_video_format;
static int hf_rtmpt_video_packet_type;
static int hf_rtmpt_video_multitrack_type;
static int hf_rtmpt_video_multitrack_packet_type;
static int hf_rtmpt_video_fourcc;
static int hf_rtmpt_video_track_id;
static int hf_rtmpt_video_track_length;
static int hf_rtmpt_video_data;
static int hf_rtmpt_tag_type;
static int hf_rtmpt_tag_datasize;
static int hf_rtmpt_tag_timestamp;
static int hf_rtmpt_tag_ets;
static int hf_rtmpt_tag_streamid;
static int hf_rtmpt_tag_tagsize;
static expert_field ei_amf_loop;
static int ett_rtmpt;
static int ett_rtmpt_handshake;
static int ett_rtmpt_header;
static int ett_rtmpt_body;
static int ett_rtmpt_ucm;
static int ett_rtmpt_audio_control;
static int ett_rtmpt_video_control;
static int ett_rtmpt_audio_multitrack_control;
static int ett_rtmpt_audio_multitrack_track;
static int ett_rtmpt_video_multitrack_control;
static int ett_rtmpt_video_multitrack_track;
static int ett_rtmpt_tag;
static int ett_rtmpt_tag_data;
static dissector_handle_t amf_handle;
static dissector_handle_t rtmpt_tcp_handle;
static dissector_handle_t rtmpt_http_handle;
static bool rtmpt_desegment = true;
/* Native Bandwidth Detection (using the checkBandwidth(), onBWCheck(),
* onBWDone() calls) transmits a series of increasing size packets over
* the course of 2 seconds. On a fast link the largest packet can just
* exceed 256KB, but setting the limit there can cause massive memory
* usage, especially with fuzzed packets where the length value is bogus.
* Limit the initial allocation size and realloc if needed, i.e., in
* future frames if the bytes are actually there.
* This initial max allocation size can be reduced further if need be,
* but keep it at least 18 so that the headers fit without checking,
* See https://gitlab.com/wireshark/wireshark/-/issues/6898
*/
#define RTMPT_INIT_ALLOC_SIZE 32768
#define RTMP_PORT 1935 /* Not IANA registered */
#define RTMPT_MAGIC 0x03
#define RTMPT_HANDSHAKE_OFFSET_1 1
#define RTMPT_HANDSHAKE_OFFSET_2 1538
#define RTMPT_HANDSHAKE_OFFSET_3 3074
#define RTMPT_HANDSHAKE_LENGTH_1 1537
#define RTMPT_HANDSHAKE_LENGTH_2 3073
#define RTMPT_HANDSHAKE_LENGTH_3 1536
#define RTMPT_INITIAL_CHUNK_SIZE 128
static unsigned rtmpt_default_chunk_size = 128;
#define RTMPT_ID_MAX 65599
#define RTMPT_TYPE_HANDSHAKE_1 0x100001
#define RTMPT_TYPE_HANDSHAKE_2 0x100002
#define RTMPT_TYPE_HANDSHAKE_3 0x100003
#define RTMPT_TYPE_CHUNK_SIZE 0x01
#define RTMPT_TYPE_ABORT_MESSAGE 0x02
#define RTMPT_TYPE_ACKNOWLEDGEMENT 0x03
#define RTMPT_TYPE_UCM 0x04
#define RTMPT_TYPE_WINDOW 0x05
#define RTMPT_TYPE_PEER_BANDWIDTH 0x06
#define RTMPT_TYPE_AUDIO_DATA 0x08
#define RTMPT_TYPE_VIDEO_DATA 0x09
#define RTMPT_TYPE_DATA_AMF3 0x0F
#define RTMPT_TYPE_SHARED_AMF3 0x10
#define RTMPT_TYPE_COMMAND_AMF3 0x11
#define RTMPT_TYPE_DATA_AMF0 0x12
#define RTMPT_TYPE_SHARED_AMF0 0x13
#define RTMPT_TYPE_COMMAND_AMF0 0x14
#define RTMPT_TYPE_AGGREGATE 0x16
#define RTMPT_UCM_STREAM_BEGIN 0x00
#define RTMPT_UCM_STREAM_EOF 0x01
#define RTMPT_UCM_STREAM_DRY 0x02
#define RTMPT_UCM_SET_BUFFER 0x03
#define RTMPT_UCM_STREAM_ISRECORDED 0x04
#define RTMPT_UCM_PING_REQUEST 0x06
#define RTMPT_UCM_PING_RESPONSE 0x07
#define RTMPT_IS_EX_AUDIO_HEADER 0x90
#define RTMPT_IS_EX_VIDEO_HEADER 0x80
#define RTMPT_IS_PACKET_TYPE_METADATA 0x04
#define RTMPT_IS_FRAME_TYPE_COMMAND 0x05
#define RTMPT_IS_AUDIO_MULTITRACK 0x05
#define RTMPT_IS_VIDEO_MULTITRACK 0x06
#define RTMPT_IS_ONETRACK 0x00
#define RTMPT_IS_MANYTRACKSMANYCODECS 0x02
#define RTMPT_TEXT_RTMP_HEADER "RTMP Header"
#define RTMPT_TEXT_RTMP_BODY "RTMP Body"
static const value_string rtmpt_handshake_vals[] = {
{ RTMPT_TYPE_HANDSHAKE_1, "Handshake C0+C1" },
{ RTMPT_TYPE_HANDSHAKE_2, "Handshake S0+S1+S2" },
{ RTMPT_TYPE_HANDSHAKE_3, "Handshake C2" },
{ 0, NULL }
};
static const value_string rtmpt_opcode_vals[] = {
{ RTMPT_TYPE_CHUNK_SIZE, "Set Chunk Size" },
{ RTMPT_TYPE_ABORT_MESSAGE, "Abort Message" },
{ RTMPT_TYPE_ACKNOWLEDGEMENT, "Acknowledgement" },
{ RTMPT_TYPE_UCM, "User Control Message" },
{ RTMPT_TYPE_WINDOW, "Window Acknowledgement Size" },
{ RTMPT_TYPE_PEER_BANDWIDTH, "Set Peer Bandwidth" },
{ RTMPT_TYPE_AUDIO_DATA, "Audio Data" },
{ RTMPT_TYPE_VIDEO_DATA, "Video Data" },
{ RTMPT_TYPE_DATA_AMF3, "AMF3 Data" },
{ RTMPT_TYPE_SHARED_AMF3, "AMF3 Shared Object" },
{ RTMPT_TYPE_COMMAND_AMF3, "AMF3 Command" },
{ RTMPT_TYPE_DATA_AMF0, "AMF0 Data" },
{ RTMPT_TYPE_SHARED_AMF0, "AMF0 Shared Object" },
{ RTMPT_TYPE_COMMAND_AMF0, "AMF0 Command" },
{ RTMPT_TYPE_AGGREGATE, "Aggregate" },
{ 0, NULL }
};
static const value_string rtmpt_limit_vals[] = {
/* These are a complete guess, from the order of the documented
* options - the values aren't actually specified */
{ 0, "Hard" },
{ 1, "Soft" },
{ 2, "Dynamic" },
{ 0, NULL }
};
static const value_string rtmpt_ucm_vals[] = {
{ RTMPT_UCM_STREAM_BEGIN, "Stream Begin" },
{ RTMPT_UCM_STREAM_EOF, "Stream EOF" },
{ RTMPT_UCM_STREAM_DRY, "Stream Dry" },
{ RTMPT_UCM_SET_BUFFER, "Set Buffer Length" },
{ RTMPT_UCM_STREAM_ISRECORDED, "Stream Is Recorded" },
{ RTMPT_UCM_PING_REQUEST, "Ping Request" },
{ RTMPT_UCM_PING_RESPONSE, "Ping Response" },
{ 0, NULL }
};
static const value_string rtmpt_tag_vals[] = {
{ RTMPT_TYPE_AUDIO_DATA, "Audio Tag" },
{ RTMPT_TYPE_VIDEO_DATA, "Video Tag" },
{ RTMPT_TYPE_DATA_AMF0, "Script Tag" },
{ 0, NULL }
};
/* [Spec] https://github.com/runner365/read_book/blob/master/rtmp/rtmp_specification_1.0.pdf */
/* [DevG] http://help.adobe.com/en_US/flashmediaserver/devguide/index.html "working with Live Video" => Adding metadata to a live stream */
/* [SWF] https://github.com/blackears/raven/blob/master/proj/SWFParser/doc/swf_file_format_spec_v10.pdf */
static const value_string rtmpt_audio_codecs[] = {
{ 0, "Uncompressed" }, /* [DevG] */
{ 1, "ADPCM" }, /* [DevG] */
{ 2, "MP3" }, /* [DevG] */
{ 3, "Uncompressed, little-endian"}, /* [SWF] */
{ 4, "Nellymoser 16kHz" }, /* [SWF] */
{ 5, "Nellymoser 8kHz" }, /* [DevG] [SWF]*/
{ 6, "Nellymoser" }, /* [DevG] [SWF]*/
{ 7, "G711A" }, /* [Spec] */
{ 8, "G711U" }, /* [Spec] */
{ 9, "Nellymoser 16kHz" }, /* [Spec] */
{ 10, "HE-AAC" }, /* [DevG] */
{ 11, "SPEEX" }, /* [DevG] */
{ 0, NULL }
};
static const value_string rtmpt_audio_packet_types[] = {
{ 0, "PacketTypeSequenceStart" },
{ 1, "PacketTypeCodedFrames" },
{ 4, "PacketTypeMultichannelConfig" },
{ 5, "PacketTypeMultitrack" },
{ 0, NULL }
};
static const value_string rtmpt_av_multitrack_types[] = {
{ 0, "AvMultitrackTypeOneTrack" },
{ 1, "AvMultitrackTypeManyTracks" },
{ 2, "AvMultitrackTypeManyTracksManyCodecs" },
{ 0, NULL }
};
static const value_string rtmpt_audio_rates[] = {
{ 0, "5.5 kHz" },
{ 1, "11 kHz" },
{ 2, "22 kHz" },
{ 3, "44 kHz" },
{ 0, NULL }
};
static const value_string rtmpt_audio_sizes[] = {
{ 0, "8 bit" },
{ 1, "16 bit" },
{ 0, NULL }
};
static const value_string rtmpt_audio_types[] = {
{ 0, "mono" },
{ 1, "stereo" },
{ 0, NULL }
};
/* from FLV v10.1 section E.4.3.1 */
static const value_string rtmpt_video_types[] = {
{ 1, "keyframe" },
{ 2, "inter-frame" },
{ 3, "disposable inter-frame" },
{ 4, "generated key frame" },
{ 5, "video info/command frame" },
{ 0, NULL }
};
/* From Enhanced RTMP */
static const value_string rtmpt_video_commands[] = {
{ 0, "StartSeek" },
{ 1, "EndSeek" },
{ 0, NULL }
};
/* from FLV v10.1 section E.4.3.1 */
static const value_string rtmpt_video_codecs[] = {
{ 2, "Sorensen H.263" },
{ 3, "Screen video" },
{ 4, "On2 VP6" },
{ 5, "On2 VP6+alpha" },
{ 6, "Screen video version 2" },
{ 7, "H.264" },
{ 12, "H.265" },
{ 0, NULL }
};
/*
* https://raw.githubusercontent.com/veovera/enhanced-rtmp/main/enhanced-rtmp.pdf
*/
static const value_string rtmpt_video_packet_types[] = {
{ 0, "PacketTypeSequenceStart" },
{ 1, "PacketTypeCodedFrames" },
{ 2, "PacketTypeSequenceEnd" },
{ 3, "PacketTypeCodedFramesX" },
{ 4, "PacketTypeMetadata" },
{ 5, "PacketTypeMPEG2TSSequenceStart" },
{ 6, "PacketTypeMultitrack" },
{ 0, NULL }
};
static int proto_amf;
static int hf_amf_version;
static int hf_amf_header_count;
static int hf_amf_header_name;
static int hf_amf_header_must_understand;
static int hf_amf_header_length;
/* static int hf_amf_header_value_type; */
static int hf_amf_message_count;
static int hf_amf_message_target_uri;
static int hf_amf_message_response_uri;
static int hf_amf_message_length;
static int hf_amf_amf0_type;
static int hf_amf_amf3_type;
static int hf_amf_number;
static int hf_amf_integer;
static int hf_amf_boolean;
static int hf_amf_stringlength;
static int hf_amf_string;
static int hf_amf_string_reference;
static int hf_amf_object_reference;
static int hf_amf_date;
/* static int hf_amf_longstringlength; */
static int hf_amf_longstring;
static int hf_amf_xml_doc;
static int hf_amf_xmllength;
static int hf_amf_xml;
static int hf_amf_int64;
static int hf_amf_bytearraylength;
static int hf_amf_bytearray;
static int hf_amf_object;
static int hf_amf_traitcount;
static int hf_amf_classnamelength;
static int hf_amf_classname;
static int hf_amf_membernamelength;
static int hf_amf_membername;
static int hf_amf_trait_reference;
static int hf_amf_ecmaarray;
static int hf_amf_strictarray;
static int hf_amf_array;
static int hf_amf_arraylength;
static int hf_amf_arraydenselength;
static int hf_amf_end_of_object_marker;
static int hf_amf_end_of_associative_part;
static int hf_amf_end_of_dynamic_members;
static int ett_amf;
static int ett_amf_headers;
static int ett_amf_messages;
static int ett_amf_value;
static int ett_amf_property;
static int ett_amf_string;
static int ett_amf_array_element;
static int ett_amf_traits;
static int ett_amf_trait_member;
/* AMF0 type markers */
#define AMF0_NUMBER 0x00
#define AMF0_BOOLEAN 0x01
#define AMF0_STRING 0x02
#define AMF0_OBJECT 0x03
#define AMF0_MOVIECLIP 0x04
#define AMF0_NULL 0x05
#define AMF0_UNDEFINED 0x06
#define AMF0_REFERENCE 0x07
#define AMF0_ECMA_ARRAY 0x08
#define AMF0_END_OF_OBJECT 0x09
#define AMF0_STRICT_ARRAY 0x0A
#define AMF0_DATE 0x0B
#define AMF0_LONG_STRING 0x0C
#define AMF0_UNSUPPORTED 0x0D
#define AMF0_RECORDSET 0x0E
#define AMF0_XML 0x0F
#define AMF0_TYPED_OBJECT 0x10
#define AMF0_AMF3_MARKER 0x11
#define AMF0_INT64 0x22
/* AMF3 type markers */
#define AMF3_UNDEFINED 0x00
#define AMF3_NULL 0x01
#define AMF3_FALSE 0x02
#define AMF3_TRUE 0x03
#define AMF3_INTEGER 0x04
#define AMF3_DOUBLE 0x05
#define AMF3_STRING 0x06
#define AMF3_XML_DOC 0x07
#define AMF3_DATE 0x08
#define AMF3_ARRAY 0x09
#define AMF3_OBJECT 0x0A
#define AMF3_XML 0x0B
#define AMF3_BYTEARRAY 0x0C
static const value_string amf0_type_vals[] = {
{ AMF0_NUMBER, "Number" },
{ AMF0_BOOLEAN, "Boolean" },
{ AMF0_STRING, "String" },
{ AMF0_OBJECT, "Object" },
{ AMF0_MOVIECLIP, "Movie clip" },
{ AMF0_NULL, "Null" },
{ AMF0_UNDEFINED, "Undefined" },
{ AMF0_REFERENCE, "Reference" },
{ AMF0_ECMA_ARRAY, "ECMA array" },
{ AMF0_END_OF_OBJECT, "End of object" },
{ AMF0_STRICT_ARRAY, "Strict array" },
{ AMF0_DATE, "Date" },
{ AMF0_LONG_STRING, "Long string" },
{ AMF0_UNSUPPORTED, "Unsupported" },
{ AMF0_RECORDSET, "Record set" },
{ AMF0_XML, "XML" },
{ AMF0_TYPED_OBJECT, "Typed object" },
{ AMF0_AMF3_MARKER, "Switch to AMF3" },
{ AMF0_INT64, "Int64" },
{ 0, NULL }
};
static const value_string amf3_type_vals[] = {
{ AMF3_UNDEFINED, "Undefined" },
{ AMF3_NULL, "Null" },
{ AMF3_FALSE, "False" },
{ AMF3_TRUE, "True" },
{ AMF3_INTEGER, "Integer" },
{ AMF3_DOUBLE, "Double" },
{ AMF3_STRING, "String" },
{ AMF3_XML_DOC, "XML document" },
{ AMF3_DATE, "Date" },
{ AMF3_ARRAY, "Array" },
{ AMF3_OBJECT, "Object" },
{ AMF3_XML, "XML" },
{ AMF3_BYTEARRAY, "ByteArray" },
{ 0, NULL }
};
/* Holds the reassembled data for a packet during un-chunking
*/
/* XXX: Because we don't use the TCP dissector's built-in desegmentation,
* or the standard reassembly API, we don't get FT_FRAMENUM links for
* chunk fragments, and we don't mark depended upon frames for export.
* Ideally we'd use the standard API (mark pinfo->desegment_offset and
* pinfo->desegment_len for TCP, or use the reassembly API), or call
* mark_frame_as_depended_upon and add the FT_FRAMENUM fields ourselves.
* To do the latter, we should have a data structure indicating which
* frames contributed to the packet.
*/
typedef struct rtmpt_packet {
uint32_t seq;
uint32_t lastseq;
int resident;
union {
uint8_t *p;
uint32_t offset;
} data;
wmem_list_t *frames;
/* used during unchunking */
int alloc;
int want;
int have;
int chunkwant;
int chunkhave;
uint8_t bhlen;
uint8_t mhlen;
/* Chunk Basic Header */
uint8_t fmt; /* byte 0 */
uint32_t id; /* byte 0 */
/* Chunk Message Header (offsets assume bhlen == 1) */
uint32_t ts; /* bytes 1-3, or from ETS @ mhlen-4 if -1 */
uint32_t len; /* bytes 4-6 */
uint8_t cmd; /* byte 7 */
uint32_t src; /* bytes 8-11 */
uint32_t txid;
int isresponse;
int otherframe;
} rtmpt_packet_t;
/* Represents a header or a chunk that is split over two TCP
* segments
*/
typedef struct rtmpt_frag {
int ishdr;
uint32_t seq;
uint32_t lastseq;
int have;
int len;
union {
uint8_t d[18]; /* enough for a complete header (3 + 11 + 4) */
uint32_t id;
} saved;
} rtmpt_frag_t;
/* The full message header information for the last packet on a particular
* ID - used for defaulting short headers
*/
typedef struct rtmpt_id {
uint32_t ts; /* bytes 1-3 */
uint32_t tsd;
uint32_t len; /* bytes 4-6 */
uint32_t src; /* bytes 8-11 */
uint8_t cmd; /* byte 7 */
wmem_tree_t *packets;
} rtmpt_id_t;
/* Historical view of a whole TCP connection
*/
typedef struct rtmpt_conv {
wmem_tree_t *seqs[2];
wmem_tree_t *frags[2];
wmem_tree_t *ids[2];
wmem_tree_t *packets[2];
wmem_tree_t *chunksize[2];
wmem_tree_t *txids[2];
} rtmpt_conv_t;
static void
rtmpt_packet_mark_depended(void *data, void *user_data)
{
frame_data *fd = (frame_data *)user_data;
uint32_t frame_num = GPOINTER_TO_UINT(data);
mark_frame_as_depended_upon(fd, frame_num);
}
/* Header length helpers */
static int rtmpt_basic_header_length(int id)
{
switch (id & 0x3f) {
case 0: return 2;
case 1: return 3;
default: return 1;
}
}
static int rtmpt_message_header_length(int id)
{
switch ((id>>6) & 3) {
case 0: return 11;
case 1: return 7;
case 2: return 3;
default: return 0;
}
}
/* Lightweight access to AMF0 blobs - more complete dissection is done
* in dissect_rtmpt_body_command */
static uint32_t
rtmpt_get_amf_length(tvbuff_t *tvb, int offset, proto_item* pi)
{
uint8_t iObjType;
int remain = tvb_reported_length_remaining(tvb, offset);
uint32_t depth = 0;
uint32_t itemlen = 0;
uint32_t rv = 0;
unsigned iterations = MAX_AMF_ITERATIONS;
while (rv == 0 || depth > 0) {
if (--iterations == 0) {
expert_add_info(NULL, pi, &ei_amf_loop);
return 0;
}
if (depth > 0) {
if (remain-rv < 2)
return remain;
itemlen = tvb_get_ntohs(tvb, offset+rv) + 2;
if (remain-rv<itemlen+1)
return remain;
rv += itemlen;
}
if (remain-rv < 1)
return remain;
iObjType = tvb_get_uint8(tvb, offset+rv);
if (depth > 0 && itemlen == 2 && iObjType == AMF0_END_OF_OBJECT) {
rv++;
depth--;
continue;
}
switch (iObjType) {
case AMF0_NUMBER:
itemlen = 9;
break;
case AMF0_BOOLEAN:
itemlen = 2;
break;
case AMF0_STRING:
if (remain-rv < 3)
return remain;
itemlen = tvb_get_ntohs(tvb, offset+rv+1) + 3;
break;
case AMF0_NULL:
case AMF0_UNDEFINED:
case AMF0_UNSUPPORTED:
itemlen = 1;
break;
case AMF0_DATE:
itemlen = 11;
break;
case AMF0_LONG_STRING:
case AMF0_XML:
if (remain-rv < 5)
return remain;
itemlen = tvb_get_ntohl(tvb, offset+rv+1) + 5;
break;
case AMF0_INT64:
itemlen = 9;
break;
case AMF0_OBJECT:
itemlen = 1;
depth++;
break;
case AMF0_ECMA_ARRAY:
itemlen = 5;
depth++;
break;
default:
return remain;
}
if (remain-rv < itemlen)
return remain;
rv += itemlen;
}
return rv;
}
static char *
rtmpt_get_amf_param(tvbuff_t *tvb, int offset, proto_item* pi, int param, const char *prop)
{
uint32_t remain = tvb_reported_length_remaining(tvb, offset);
uint32_t itemlen;
uint32_t iStringLength;
while (remain > 0 && param > 0) {
itemlen = rtmpt_get_amf_length(tvb, offset, pi);
if (itemlen == 0)
break;
offset += itemlen;
remain -= itemlen;
param--;
}
if (remain > 0 && param == 0) {
uint8_t iObjType = tvb_get_uint8(tvb, offset);
if (!prop && iObjType == AMF0_STRING && remain >= 3) {
iStringLength = tvb_get_ntohs(tvb, offset+1);
if (remain >= iStringLength+3) {
return tvb_get_string_enc(wmem_packet_scope(), tvb, offset+3, iStringLength, ENC_ASCII);
}
}
if (prop && iObjType == AMF0_OBJECT) {
offset++;
remain--;
while (remain > 2) {
uint32_t iPropLength = tvb_get_ntohs(tvb, offset);
if (remain < 2+iPropLength+3)
break;
if (tvb_strneql(tvb, offset+2, prop, strlen(prop)) == 0) {
if (tvb_get_uint8(tvb, offset+2+iPropLength) != AMF0_STRING)
break;
iStringLength = tvb_get_ntohs(tvb, offset+2+iPropLength+1);
if (remain < 2+iPropLength+3+iStringLength)
break;
return tvb_get_string_enc(wmem_packet_scope(), tvb, offset+2+iPropLength+3, iStringLength, ENC_ASCII);
}
itemlen = rtmpt_get_amf_length(tvb, offset+2+iPropLength, pi);
if (itemlen == 0)
break;
offset += 2+iPropLength+itemlen;
remain -= 2+iPropLength+itemlen;
}
}
}
return NULL;
}
static uint32_t
rtmpt_get_amf_txid(tvbuff_t *tvb, int offset, proto_item* pi)
{
uint32_t remain = tvb_reported_length_remaining(tvb, offset);
if (remain > 0) {
uint32_t itemlen = rtmpt_get_amf_length(tvb, offset, pi);
if (itemlen == 0 || remain < itemlen)
return 0;
offset += itemlen;
remain -= itemlen;
}
if (remain >= 9) {
uint8_t iObjType = tvb_get_uint8(tvb, offset);
if (iObjType == AMF0_NUMBER) {
return (uint32_t)tvb_get_ntohieee_double(tvb, offset+1);
}
}
return 0;
}
/* Generate a useful description for various packet types */
static char *
rtmpt_get_packet_desc(tvbuff_t *tvb, uint32_t offset, proto_item* pi, uint32_t remain, rtmpt_conv_t *rconv, int cdir,
rtmpt_packet_t *tp, bool *deschasopcode)
{
if (tp->cmd == RTMPT_TYPE_CHUNK_SIZE || tp->cmd == RTMPT_TYPE_ABORT_MESSAGE ||
tp->cmd == RTMPT_TYPE_ACKNOWLEDGEMENT || tp->cmd == RTMPT_TYPE_WINDOW) {
if (tp->len >= 4 && remain >= 4) {
*deschasopcode = true;
return wmem_strdup_printf(wmem_packet_scope(), "%s %d",
val_to_str(tp->cmd, rtmpt_opcode_vals, "Unknown (0x%01x)"),
tvb_get_ntohl(tvb, offset));
}
} else if (tp->cmd == RTMPT_TYPE_PEER_BANDWIDTH) {
if (tp->len >= 5 && remain >= 5) {
*deschasopcode = true;
return wmem_strdup_printf(wmem_packet_scope(), "%s %d,%s",
val_to_str(tp->cmd, rtmpt_opcode_vals, "Unknown (0x%01x)"),
tvb_get_ntohl(tvb, offset),
val_to_str(tvb_get_uint8(tvb, offset+4), rtmpt_limit_vals, "Unknown (%d)"));
}
} else if (tp->cmd == RTMPT_TYPE_UCM) {
uint16_t iUCM = -1;
const char *sFunc;
const char *sParam = "";
if (tp->len < 2 || remain < 2)
return NULL;
iUCM = tvb_get_ntohs(tvb, offset);
sFunc = try_val_to_str(iUCM, rtmpt_ucm_vals);
if (sFunc == NULL) {
*deschasopcode = true;
sFunc = wmem_strdup_printf(wmem_packet_scope(), "User Control Message 0x%01x", iUCM);
}
if (iUCM == RTMPT_UCM_STREAM_BEGIN || iUCM == RTMPT_UCM_STREAM_EOF ||
iUCM == RTMPT_UCM_STREAM_DRY || iUCM == RTMPT_UCM_STREAM_ISRECORDED) {
if (tp->len >= 6 && remain >= 6) {
sParam = wmem_strdup_printf(wmem_packet_scope(), " %d", tvb_get_ntohl(tvb, offset+2));
}
} else if (iUCM == RTMPT_UCM_SET_BUFFER) {
if (tp->len >= 10 && remain >= 10) {
sParam = wmem_strdup_printf(wmem_packet_scope(), " %d,%dms",
tvb_get_ntohl(tvb, offset+2),
tvb_get_ntohl(tvb, offset+6));
}
}
return wmem_strdup_printf(wmem_packet_scope(), "%s%s", sFunc, sParam);
} else if (tp->cmd == RTMPT_TYPE_COMMAND_AMF0 || tp->cmd == RTMPT_TYPE_COMMAND_AMF3 ||
tp->cmd == RTMPT_TYPE_DATA_AMF0 || tp->cmd == RTMPT_TYPE_DATA_AMF3) {
uint32_t slen = 0;
uint32_t soff = 0;
char *sFunc = NULL;
char *sParam = NULL;
if (tp->cmd == RTMPT_TYPE_COMMAND_AMF3 || tp->cmd == RTMPT_TYPE_DATA_AMF3) {
soff = 1;
}
if (tp->len >= 3+soff && remain >= 3+soff) {
slen = tvb_get_ntohs(tvb, offset+1+soff);
}
if (slen > 0) {
sFunc = tvb_get_string_enc(wmem_packet_scope(), tvb, offset+3+soff, slen, ENC_ASCII);
ws_debug("got function call '%s'", sFunc);
if (strcmp(sFunc, "connect") == 0) {
sParam = rtmpt_get_amf_param(tvb, offset+soff, pi, 2, "app");
} else if (strcmp(sFunc, "play") == 0) {
sParam = rtmpt_get_amf_param(tvb, offset+soff, pi, 3, NULL);
} else if (strcmp(sFunc, "play2") == 0) {
sParam = rtmpt_get_amf_param(tvb, offset+soff, pi, 3, "streamName");
} else if (strcmp(sFunc, "releaseStream") == 0) {
sParam = rtmpt_get_amf_param(tvb, offset+soff, pi, 3, NULL);
} else if (strcmp(sFunc, "FCPublish") == 0) {
sParam = rtmpt_get_amf_param(tvb, offset+soff, pi, 3, NULL);
} else if (strcmp(sFunc, "publish") == 0) {
sParam = rtmpt_get_amf_param(tvb, offset+soff, pi, 3, NULL);
} else if (strcmp(sFunc, "onStatus") == 0) {
if (tp->cmd == RTMPT_TYPE_COMMAND_AMF0 || tp->cmd == RTMPT_TYPE_COMMAND_AMF3) {
sParam = rtmpt_get_amf_param(tvb, offset+soff, pi, 3, "code");
} else {
sParam = rtmpt_get_amf_param(tvb, offset+soff, pi, 1, "code");
}
} else if (strcmp(sFunc, "onPlayStatus") == 0) {
sParam = rtmpt_get_amf_param(tvb, offset+soff, pi, 1, "code");
} else if (strcmp(sFunc, "_result") == 0) {
sParam = rtmpt_get_amf_param(tvb, offset+soff, pi, 3, "code");
tp->isresponse = true;
} else if (strcmp(sFunc, "_error") == 0) {
sParam = rtmpt_get_amf_param(tvb, offset+soff, pi, 3, "code");
tp->isresponse = true;
}
if (tp->txid != 0 && tp->otherframe == 0) {
tp->otherframe = GPOINTER_TO_INT(wmem_tree_lookup32(rconv->txids[cdir^1], tp->txid));
if (tp->otherframe) {
ws_debug("got otherframe=%d", tp->otherframe);
}
}
}
if (sFunc) {
if (sParam) {
return wmem_strdup_printf(wmem_packet_scope(), "%s('%s')", sFunc, sParam);
} else {
return wmem_strdup_printf(wmem_packet_scope(), "%s()", sFunc);
}
}
}
return NULL;
}
/* Tree dissection helpers for various packet body forms */
static void
dissect_rtmpt_body_scm(tvbuff_t *tvb, int offset, proto_tree *rtmpt_tree, unsigned scm)
{
switch (scm) {
case RTMPT_TYPE_CHUNK_SIZE:
proto_tree_add_item(rtmpt_tree, hf_rtmpt_scm_chunksize, tvb, offset, 4, ENC_BIG_ENDIAN);
break;
case RTMPT_TYPE_ABORT_MESSAGE:
proto_tree_add_item(rtmpt_tree, hf_rtmpt_scm_csid, tvb, offset, 4, ENC_BIG_ENDIAN);
break;
case RTMPT_TYPE_ACKNOWLEDGEMENT:
proto_tree_add_item(rtmpt_tree, hf_rtmpt_scm_seq, tvb, offset, 4, ENC_BIG_ENDIAN);
break;
case RTMPT_TYPE_UCM:
proto_tree_add_item(rtmpt_tree, hf_rtmpt_ucm_eventtype, tvb, offset, 2, ENC_BIG_ENDIAN);
break;
case RTMPT_TYPE_WINDOW:
proto_tree_add_item(rtmpt_tree, hf_rtmpt_scm_was, tvb, offset, 4, ENC_BIG_ENDIAN);
break;
case RTMPT_TYPE_PEER_BANDWIDTH:
proto_tree_add_item(rtmpt_tree, hf_rtmpt_scm_was, tvb, offset, 4, ENC_BIG_ENDIAN);
proto_tree_add_item(rtmpt_tree, hf_rtmpt_scm_limittype, tvb, offset+4, 1, ENC_BIG_ENDIAN);
break;
}
}
static int
dissect_amf0_value_type(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_tree *tree, bool *amf3_encoding, proto_item *parent_ti);
/*
* A "property list" is a sequence of name/value pairs, terminated by
* and "end of object" indicator. AMF0 "object"s and "ECMA array"s
* are encoded as property lists.
*/
static int
// NOLINTNEXTLINE(misc-no-recursion)
dissect_amf0_property_list(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_tree *tree, unsigned *countp, bool *amf3_encoding)
{
proto_item *prop_ti;
proto_tree *prop_tree;
proto_tree *name_tree;
unsigned iStringLength;
char *iStringValue;
unsigned count = 0;
/*
* XXX - at least as I read "3.1 AVM+ Type Marker" in the AMF0
* specification, the AVM+ Type Marker only affects "the following
* Object". For now, we have a single "AMF3 encoding" flag, and
* set it when we see the type marker, and never clear it.
*/
for (;;) {
/* UTF-8: property name */
iStringLength = tvb_get_ntohs(tvb, offset);
if (iStringLength == 0 &&
tvb_get_uint8(tvb, offset + 2) == AMF0_END_OF_OBJECT)
break;
count++;
iStringValue = tvb_get_string_enc(pinfo->pool, tvb, offset + 2, iStringLength, ENC_ASCII);
prop_tree = proto_tree_add_subtree_format(tree, tvb, offset, -1,
ett_amf_property, &prop_ti, "Property '%s'",
iStringValue);
name_tree = proto_tree_add_subtree_format(prop_tree, tvb,
offset, 2+iStringLength,
ett_amf_string, NULL, "Name: %s", iStringValue);
proto_tree_add_uint(name_tree, hf_amf_stringlength, tvb, offset, 2, iStringLength);
offset += 2;
proto_tree_add_item(name_tree, hf_amf_string, tvb, offset, iStringLength, ENC_UTF_8);
offset += iStringLength;
/* value-type: property value */
offset = dissect_amf0_value_type(tvb, pinfo, offset, prop_tree, amf3_encoding, prop_ti);
proto_item_set_end(prop_ti, tvb, offset);
}
proto_tree_add_item(tree, hf_amf_end_of_object_marker, tvb, offset, 3, ENC_NA);
offset += 3;
*countp = count;
return offset;
}
static int
// NOLINTNEXTLINE(misc-no-recursion)
dissect_amf0_value_type(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_tree *tree, bool *amf3_encoding, proto_item *parent_ti)
{
uint8_t iObjType;
proto_item *ti;
proto_tree *val_tree;
int iValueOffset = offset;
uint32_t iIntegerValue;
double iDoubleValue;
bool iBooleanValue;
unsigned iStringLength;
char *iStringValue;
unsigned iArrayLength;
unsigned i;
nstime_t t;
int64_t iInteger64Value;
unsigned count;
iObjType = tvb_get_uint8(tvb, offset);
if (parent_ti != NULL)
proto_item_append_text(parent_ti, " %s",
val_to_str_const(iObjType, amf0_type_vals, "Unknown"));
switch (iObjType) {
case AMF0_OBJECT:
/*
* For object types, make the top-level protocol tree
* item a field for that type.
*/
ti = proto_tree_add_item(tree, hf_amf_object, tvb, offset, -1, ENC_NA);
val_tree = proto_item_add_subtree(ti, ett_amf_value);
break;
case AMF0_ECMA_ARRAY:
/*
* For ECMA array types, make the top-level protocol tree
* item a field for that type.
*/
ti = proto_tree_add_item(tree, hf_amf_ecmaarray, tvb, offset, -1, ENC_NA);
val_tree = proto_item_add_subtree(ti, ett_amf_value);
break;
case AMF0_STRICT_ARRAY:
/*
* For strict array types, make the top-level protocol tree
* item a field for that type.
*/
ti = proto_tree_add_item(tree, hf_amf_strictarray, tvb, offset, -1, ENC_NA);
val_tree = proto_item_add_subtree(ti, ett_amf_value);
break;
default:
/*
* For all other types, make it just a text item; the
* field for that type will be used for the value.
*/
val_tree = proto_tree_add_subtree(tree, tvb, offset, -1, ett_amf_value, &ti,
val_to_str_const(iObjType, amf0_type_vals, "Unknown"));
break;
}
proto_tree_add_uint(val_tree, hf_amf_amf0_type, tvb, iValueOffset, 1, iObjType);
iValueOffset++;
increment_dissection_depth(pinfo);
switch (iObjType) {
case AMF0_NUMBER:
iDoubleValue = tvb_get_ntohieee_double(tvb, iValueOffset);
proto_tree_add_double(val_tree, hf_amf_number, tvb, iValueOffset, 8, iDoubleValue);
iValueOffset += 8;
proto_item_append_text(ti, " %." G_STRINGIFY(DBL_DIG) "g", iDoubleValue);
if (parent_ti != NULL)
proto_item_append_text(parent_ti, " %." G_STRINGIFY(DBL_DIG) "g", iDoubleValue);
break;
case AMF0_BOOLEAN:
iBooleanValue = tvb_get_uint8(tvb, iValueOffset);
proto_tree_add_boolean(val_tree, hf_amf_boolean, tvb, iValueOffset, 1, iBooleanValue);
iValueOffset += 1;
proto_item_append_text(ti, iBooleanValue ? " true" : " false");
if (parent_ti != NULL)
proto_item_append_text(parent_ti, iBooleanValue ? " true" : " false");
break;
case AMF0_STRING:
iStringLength = tvb_get_ntohs(tvb, iValueOffset);
proto_tree_add_uint(val_tree, hf_amf_stringlength, tvb, iValueOffset, 2, iStringLength);
iValueOffset += 2;
iStringValue = tvb_get_string_enc(pinfo->pool, tvb, iValueOffset, iStringLength, ENC_UTF_8|ENC_NA);
if (iStringLength != 0)
proto_tree_add_string(val_tree, hf_amf_string, tvb, iValueOffset, iStringLength, iStringValue);
iValueOffset += iStringLength;
proto_item_append_text(ti, " '%s'", iStringValue);
if (parent_ti != NULL)
proto_item_append_text(parent_ti, " '%s'", iStringValue);
break;
case AMF0_OBJECT:
iValueOffset = dissect_amf0_property_list(tvb, pinfo, iValueOffset, val_tree, &count, amf3_encoding);
proto_item_append_text(ti, " (%u items)", count);
break;
case AMF0_NULL:
case AMF0_UNDEFINED:
break;
case AMF0_REFERENCE:
iIntegerValue = tvb_get_ntohs(tvb, iValueOffset);
proto_tree_add_uint(val_tree, hf_amf_object_reference, tvb, iValueOffset, 2, iIntegerValue);
iValueOffset += 2;
proto_item_append_text(ti, " %d", iIntegerValue);
break;
case AMF0_ECMA_ARRAY:
/*
* Counted list type, with end marker. The count appears to be
* more of a hint than a rule, and is sometimes sent as 0 or
* invalid.
*
* Basically the same as OBJECT but with the extra count field.
* There being many strange encoders/metadata injectors out
* there, sometimes you see a valid count and no end marker.
* Figuring out which you've got for a deeply nested structure
* is non-trivial.
*/
iArrayLength = tvb_get_ntohl(tvb, iValueOffset);
proto_tree_add_uint(val_tree, hf_amf_arraylength, tvb, iValueOffset, 4, iArrayLength);
iValueOffset += 4;
iValueOffset = dissect_amf0_property_list(tvb, pinfo, iValueOffset, val_tree, &count, amf3_encoding);
proto_item_append_text(ti, " (%u items)", count);
break;
case AMF0_END_OF_OBJECT:
proto_tree_add_item(tree, hf_amf_end_of_object_marker, tvb, iValueOffset, 3, ENC_NA);
iValueOffset += 3;
break;
case AMF0_STRICT_ARRAY:
/*
* Counted list type, without end marker. Number of values
* is determined by count, values are assumed to form a
* [0..N-1] numbered array and are presented as plain AMF
* types, not OBJECT or ECMA_ARRAY style named properties.
*/
iArrayLength = tvb_get_ntohl(tvb, iValueOffset);
proto_tree_add_uint(val_tree, hf_amf_arraylength, tvb, iValueOffset, 4, iArrayLength);
iValueOffset += 4;
for (i = 0; i < iArrayLength; i++)
iValueOffset = dissect_amf0_value_type(tvb, pinfo, iValueOffset, val_tree, amf3_encoding, NULL);
proto_item_append_text(ti, " (%u items)", iArrayLength);
break;
case AMF0_DATE:
iDoubleValue = tvb_get_ntohieee_double(tvb, iValueOffset);
t.secs = (time_t)(iDoubleValue/1000);
t.nsecs = (int)((iDoubleValue - 1000*(double)t.secs) * 1000000);
proto_tree_add_time(val_tree, hf_amf_date, tvb, iValueOffset, 8, &t);
iValueOffset += 8;
proto_item_append_text(ti, " %s", abs_time_to_str(pinfo->pool, &t, ABSOLUTE_TIME_LOCAL, true));
if (parent_ti != NULL)
proto_item_append_text(parent_ti, " %s", abs_time_to_str(pinfo->pool, &t, ABSOLUTE_TIME_LOCAL, true));
/* time-zone */
iValueOffset += 2;
break;
case AMF0_LONG_STRING:
case AMF0_XML: /* same representation */
iStringLength = tvb_get_ntohl(tvb, iValueOffset);
proto_tree_add_uint(val_tree, hf_amf_stringlength, tvb, iValueOffset, 2, iStringLength);
iValueOffset += 4;
iStringValue = tvb_get_string_enc(pinfo->pool, tvb, iValueOffset, iStringLength, ENC_UTF_8|ENC_NA);
if (iStringLength != 0)
proto_tree_add_string(val_tree, (iObjType == AMF0_XML) ? hf_amf_xml_doc : hf_amf_longstring, tvb, iValueOffset, iStringLength, iStringValue);
iValueOffset += iStringLength;
proto_item_append_text(ti, " '%s'", iStringValue);
if (parent_ti != NULL)
proto_item_append_text(parent_ti, " '%s'", iStringValue);
break;
case AMF0_UNSUPPORTED:
break;
case AMF0_TYPED_OBJECT:
/* class-name */
iStringLength = tvb_get_ntohs(tvb, iValueOffset);
proto_tree_add_uint(val_tree, hf_amf_stringlength, tvb, iValueOffset, 2, iStringLength);
iValueOffset += 2;
iStringValue = tvb_get_string_enc(pinfo->pool, tvb, iValueOffset, iStringLength, ENC_UTF_8|ENC_NA);
proto_tree_add_string(val_tree, hf_amf_string, tvb, iValueOffset, iStringLength, iStringValue);
iValueOffset += iStringLength;
iValueOffset = dissect_amf0_property_list(tvb, pinfo, iValueOffset, val_tree, &count, amf3_encoding);
break;
case AMF0_AMF3_MARKER:
*amf3_encoding = true;
break;
case AMF0_INT64:
iInteger64Value = tvb_get_ntoh64(tvb, iValueOffset);
proto_tree_add_int64(val_tree, hf_amf_int64, tvb, iValueOffset, 8, iInteger64Value);
iValueOffset += 8;
proto_item_append_text(ti," %" PRId64, iInteger64Value);
if (parent_ti != NULL)
proto_item_append_text(parent_ti," %" PRId64, iInteger64Value);
break;
default:
/*
* If we can't determine the length, don't carry on;
* just skip to the end of the tvbuff.
*/
iValueOffset = tvb_reported_length(tvb);
break;
}
decrement_dissection_depth(pinfo);
proto_item_set_end(ti, tvb, iValueOffset);
return iValueOffset;
}
static uint32_t
amf_get_u29(tvbuff_t *tvb, int offset, unsigned *lenp)
{
unsigned len = 0;
uint8_t iByte;
uint32_t iValue;
iByte = tvb_get_uint8(tvb, offset);
iValue = (iByte & 0x7F);
offset++;
len++;
if (!(iByte & 0x80)) {
/* 1 byte value */
*lenp = len;
return iValue;
}
iByte = tvb_get_uint8(tvb, offset);
iValue = (iValue << 7) | (iByte & 0x7F);
offset++;
len++;
if (!(iByte & 0x80)) {
/* 2 byte value */
*lenp = len;
return iValue;
}
iByte = tvb_get_uint8(tvb, offset);
iValue = (iValue << 7) | (iByte & 0x7F);
offset++;
len++;
if (!(iByte & 0x80)) {
/* 3 byte value */
*lenp = len;
return iValue;
}
iByte = tvb_get_uint8(tvb, offset);
iValue = (iValue << 8) | iByte;
len++;
*lenp = len;
return iValue;
}
static int
// NOLINTNEXTLINE(misc-no-recursion)
dissect_amf3_value_type(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_tree *tree, proto_item *parent_ti)
{
uint8_t iObjType;
proto_item *ti;
proto_tree *val_tree;
int iValueOffset = offset;
unsigned iValueLength;
uint32_t iIntegerValue;
double iDoubleValue;
unsigned iStringLength;
char *iStringValue;
unsigned iArrayLength;
proto_item *subval_ti;
proto_tree *subval_tree;
unsigned i;
bool iTypeIsDynamic;
unsigned iTraitCount;
proto_item *traits_ti;
proto_tree *traits_tree;
proto_tree *name_tree;
proto_tree *member_tree;
uint8_t *iByteArrayValue;
iObjType = tvb_get_uint8(tvb, offset);
if (parent_ti != NULL)
proto_item_append_text(parent_ti, " %s",
val_to_str_const(iObjType, amf3_type_vals, "Unknown"));
switch (iObjType) {
case AMF3_ARRAY:
/*
* For array types, make the top-level protocol tree
* item a field for that type.
*/
ti = proto_tree_add_item(tree, hf_amf_array, tvb, offset, -1, ENC_NA);
val_tree = proto_item_add_subtree(ti, ett_amf_value);
break;
case AMF3_OBJECT:
/*
* For object types, make the top-level protocol tree
* item a field for that type.
*/
ti = proto_tree_add_item(tree, hf_amf_object, tvb, offset, -1, ENC_NA);
val_tree = proto_item_add_subtree(ti, ett_amf_value);
break;
default:
/*
* For all other types, make it just a text item; the
* field for that type will be used for the value.
*/
val_tree = proto_tree_add_subtree(tree, tvb, offset, -1, ett_amf_value, &ti,
val_to_str_const(iObjType, amf3_type_vals, "Unknown"));
break;
}
proto_tree_add_uint(val_tree, hf_amf_amf3_type, tvb, iValueOffset, 1, iObjType);
iValueOffset++;
increment_dissection_depth(pinfo);
switch (iObjType) {
case AMF3_UNDEFINED:
case AMF3_NULL:
break;
case AMF3_FALSE:
proto_tree_add_boolean(val_tree, hf_amf_boolean, tvb, 0, 0, false);
proto_item_append_text(ti, " false");
break;
case AMF3_TRUE:
proto_tree_add_boolean(val_tree, hf_amf_boolean, tvb, 0, 0, true);
proto_item_append_text(ti, " true");
break;
case AMF3_INTEGER:
/* XXX - signed or unsigned? */
iIntegerValue = amf_get_u29(tvb, iValueOffset, &iValueLength);
proto_tree_add_uint(val_tree, hf_amf_integer, tvb, iValueOffset, iValueLength, iIntegerValue);
proto_item_append_text(ti, " %u", iIntegerValue);
if (parent_ti != NULL)
proto_item_append_text(parent_ti, " %u", iIntegerValue);
iValueOffset += iValueLength;
break;
case AMF3_DOUBLE:
iDoubleValue = tvb_get_ntohieee_double(tvb, iValueOffset);
proto_tree_add_double(val_tree, hf_amf_number, tvb, iValueOffset, 8, iDoubleValue);
iValueOffset += 8;
proto_item_append_text(ti, " %." G_STRINGIFY(DBL_DIG) "g", iDoubleValue);
if (parent_ti != NULL)
proto_item_append_text(parent_ti, " %." G_STRINGIFY(DBL_DIG) "g", iDoubleValue);
break;
case AMF3_STRING:
iIntegerValue = amf_get_u29(tvb, iValueOffset, &iValueLength);
if (iIntegerValue & 0x00000001) {
/* the upper 28 bits of the integer value is a string length */
iStringLength = iIntegerValue >> 1;
proto_tree_add_uint(val_tree, hf_amf_stringlength, tvb, iValueOffset, iValueLength, iStringLength);
iValueOffset += iValueLength;
iStringValue = tvb_get_string_enc(pinfo->pool, tvb, iValueOffset, iStringLength, ENC_UTF_8|ENC_NA);
if (iStringLength != 0)
proto_tree_add_string(val_tree, hf_amf_string, tvb, iValueOffset, iStringLength, iStringValue);
iValueOffset += iStringLength;
proto_item_append_text(ti, " '%s'", iStringValue);
if (parent_ti != NULL)
proto_item_append_text(parent_ti, " '%s'", iStringValue);
} else {
/* the upper 28 bits of the integer value are a string reference index */
proto_tree_add_uint(val_tree, hf_amf_string_reference, tvb, iValueOffset, iValueLength, iIntegerValue >> 1);
iValueOffset += iValueLength;
proto_item_append_text(ti, " reference %u", iIntegerValue >> 1);
if (parent_ti != NULL)
proto_item_append_text(parent_ti, " reference %u", iIntegerValue >> 1);
}
break;
case AMF3_DATE:
iIntegerValue = amf_get_u29(tvb, iValueOffset, &iValueLength);
if (iIntegerValue & 0x00000001) {
/*
* The upper 28 bits of the integer value are
* ignored; what follows is a double
* containing milliseconds since the Epoch.
*/
nstime_t t;
iValueOffset += iValueLength;
iDoubleValue = tvb_get_ntohieee_double(tvb, iValueOffset);
t.secs = (time_t)(iDoubleValue/1000);
t.nsecs = (int)((iDoubleValue - 1000*(double)t.secs) * 1000000);
proto_tree_add_time(val_tree, hf_amf_date, tvb, iValueOffset, 8, &t);
iValueOffset += 8;
proto_item_append_text(ti, "%s", abs_time_to_str(pinfo->pool, &t, ABSOLUTE_TIME_LOCAL, true));
if (parent_ti != NULL)
proto_item_append_text(parent_ti, "%s", abs_time_to_str(pinfo->pool, &t, ABSOLUTE_TIME_LOCAL, true));
} else {
/* the upper 28 bits of the integer value are an object reference index */
proto_tree_add_uint(val_tree, hf_amf_object_reference, tvb, iValueOffset, iValueLength, iIntegerValue >> 1);
iValueOffset += iValueLength;
proto_item_append_text(ti, " object reference %u", iIntegerValue >> 1);
if (parent_ti != NULL)
proto_item_append_text(parent_ti, " object reference %u", iIntegerValue >> 1);
}
break;
case AMF3_ARRAY:
iIntegerValue = amf_get_u29(tvb, iValueOffset, &iValueLength);
if (iIntegerValue & 0x00000001) {
/*
* The upper 28 bits of the integer value are
* a count of the number of elements in
* the dense portion of the array.
*/
iArrayLength = iIntegerValue >> 1;
proto_tree_add_uint(val_tree, hf_amf_arraydenselength, tvb, iValueOffset, iValueLength, iArrayLength);
iValueOffset += iValueLength;
/*
* The AMF3 spec bit on the Array type is slightly
* confusingly written, but seems to be saying that
* the associative portion of the array follows the
* size of the dense portion of the array, and the
* dense portion of the array follows the associative
* portion.
*
* Dissect the associative portion.
*/
for (;;) {
/* Fetch the name */
iIntegerValue = amf_get_u29(tvb, iValueOffset, &iValueLength);
if (iIntegerValue & 0x00000001) {
/* the upper 28 bits of the integer value is a string length */
iStringLength = iIntegerValue >> 1;
if (iStringLength == 0) {
/* null name marks the end of the associative part */
proto_tree_add_item(val_tree, hf_amf_end_of_associative_part, tvb, iValueOffset, iValueLength, ENC_NA);
iValueOffset += iValueLength;
break;
}
iStringValue = tvb_get_string_enc(pinfo->pool, tvb, iValueOffset+iValueLength, iStringLength, ENC_UTF_8|ENC_NA);
subval_tree = proto_tree_add_subtree(val_tree, tvb, iValueOffset, iStringLength,
ett_amf_array_element, &subval_ti, iStringValue);
proto_tree_add_uint(subval_tree, hf_amf_stringlength, tvb, iValueOffset, iValueLength, iStringLength);
iValueOffset += iValueLength;
proto_tree_add_string(subval_tree, hf_amf_string, tvb, iValueOffset, iStringLength, iStringValue);
} else {
/* the upper 28 bits of the integer value are a string reference index */
subval_tree = proto_tree_add_subtree_format(val_tree, tvb, iValueOffset, iValueLength,
ett_amf_array_element, &subval_ti, "Reference %u:", iIntegerValue >> 1);
proto_tree_add_uint(subval_tree, hf_amf_string_reference, tvb, iValueOffset, iValueLength, iIntegerValue >> 1);
}
/* Fetch the value */
iObjType = tvb_get_uint8(tvb, offset);
proto_item_append_text(subval_ti, "%s",
val_to_str_const(iObjType, amf3_type_vals, "Unknown"));
iValueOffset = dissect_amf3_value_type(tvb, pinfo, iValueOffset, subval_tree, subval_ti);
}
/*
* Dissect the dense portion.
*/
for (i = 0; i < iArrayLength; i++)
iValueOffset = dissect_amf3_value_type(tvb, pinfo, iValueOffset, val_tree, NULL);
proto_item_set_end(ti, tvb, iValueOffset);
} else {
/* the upper 28 bits of the integer value are an object reference index */
proto_tree_add_uint(val_tree, hf_amf_object_reference, tvb, iValueOffset, iValueLength, iIntegerValue >> 1);
proto_item_append_text(ti, " reference %u", iIntegerValue >> 1);
if (parent_ti != NULL)
proto_item_append_text(parent_ti, " reference %u", iIntegerValue >> 1);
}
break;
case AMF3_OBJECT:
iIntegerValue = amf_get_u29(tvb, iValueOffset, &iValueLength);
if (iIntegerValue & 0x00000001) {
if (iIntegerValue & 0x00000002) {
if (iIntegerValue & 0x00000004) {
/*
* U29O-traits-ext; the rest of
* iIntegerValue is not significant,
* and, worse, we have idea what
* follows the class name, or even
* how many bytes follow the class
* name - that's by convention between
* the client and server.
*/
iValueOffset += iValueLength;
} else {
/*
* U29O-traits; the 0x00000008 bit
* specifies whether the type is
* dynamic.
*/
iTypeIsDynamic = (iIntegerValue & 0x00000008) ? true : false;
iTraitCount = iIntegerValue >> 4;
proto_tree_add_uint(val_tree, hf_amf_traitcount, tvb, iValueOffset, iValueLength, iTraitCount);
iValueOffset += iValueLength;
iIntegerValue = amf_get_u29(tvb, iValueOffset, &iValueLength);
if (iIntegerValue & 0x00000001) {
/* the upper 28 bits of the integer value is a string length */
iStringLength = iIntegerValue >> 1;
iStringValue = tvb_get_string_enc(pinfo->pool, tvb, iValueOffset+iValueLength, iStringLength, ENC_UTF_8|ENC_NA);
traits_tree = proto_tree_add_subtree_format(val_tree, tvb, iValueOffset, -1,
ett_amf_traits, &traits_ti, "Traits for class %s (%u member names)", iStringValue, iTraitCount);
name_tree = proto_tree_add_subtree_format(traits_tree, tvb,
iValueOffset,
iValueLength+iStringLength,
ett_amf_string, NULL, "Class name: %s",
iStringValue);
proto_tree_add_uint(name_tree, hf_amf_classnamelength, tvb, iValueOffset, iValueLength, iStringLength);
iValueOffset += iValueLength;
proto_tree_add_string(name_tree, hf_amf_classname, tvb, iValueOffset, iStringLength, iStringValue);
iValueOffset += iStringLength;
} else {
/* the upper 28 bits of the integer value are a string reference index */
traits_tree = proto_tree_add_subtree_format(val_tree, tvb, iValueOffset, iValueLength,
ett_amf_traits, &traits_ti, "Traits for class (reference %u for name)", iIntegerValue >> 1);
proto_tree_add_uint(traits_tree, hf_amf_string_reference, tvb, iValueOffset, iValueLength, iIntegerValue >> 1);
iValueOffset += iValueLength;
}
for (i = 0; i < iTraitCount; i++) {
iIntegerValue = amf_get_u29(tvb, iValueOffset, &iValueLength);
if (iIntegerValue & 0x00000001) {
/* the upper 28 bits of the integer value is a string length */
iStringLength = iIntegerValue >> 1;
iStringValue = tvb_get_string_enc(pinfo->pool, tvb, iValueOffset+iValueLength, iStringLength, ENC_UTF_8|ENC_NA);
member_tree = proto_tree_add_subtree_format(traits_tree, tvb, iValueOffset, iValueLength+iStringLength,
ett_amf_trait_member, NULL, "Member '%s'", iStringValue);
proto_tree_add_uint(member_tree, hf_amf_membernamelength, tvb, iValueOffset, iValueLength, iStringLength);
iValueOffset += iValueLength;
proto_tree_add_string(member_tree, hf_amf_membername, tvb, iValueOffset, iStringLength, iStringValue);
iValueOffset += iStringLength;
} else {
/* the upper 28 bits of the integer value are a string reference index */
proto_tree_add_uint(traits_tree, hf_amf_string_reference, tvb, iValueOffset, iValueLength, iIntegerValue >> 1);
iValueOffset += iValueLength;
}
}
for (i = 0; i < iTraitCount; i++)
iValueOffset = dissect_amf3_value_type(tvb, pinfo, iValueOffset, traits_tree, NULL);
if (iTypeIsDynamic) {
for (;;) {
/* Fetch the name */
iIntegerValue = amf_get_u29(tvb, iValueOffset, &iValueLength);
if (iIntegerValue & 0x00000001) {
/* the upper 28 bits of the integer value is a string length */
iStringLength = iIntegerValue >> 1;
if (iStringLength == 0) {
/* null name marks the end of the associative part */
proto_tree_add_item(traits_tree, hf_amf_end_of_dynamic_members, tvb, iValueOffset, iValueLength, ENC_NA);
iValueOffset += iValueLength;
break;
}
iStringValue = tvb_get_string_enc(pinfo->pool, tvb, iValueOffset+iValueLength, iStringLength, ENC_UTF_8|ENC_NA);
subval_tree = proto_tree_add_subtree_format(traits_tree, tvb, iValueOffset, -1,
ett_amf_array_element, &subval_ti, "%s:", iStringValue);
name_tree = proto_tree_add_subtree_format(subval_tree, tvb,
iValueOffset,
iValueLength+iStringLength,
ett_amf_string, NULL, "Member name: %s",
iStringValue);
proto_tree_add_uint(name_tree, hf_amf_membernamelength, tvb, iValueOffset, iValueLength, iStringLength);
iValueOffset += iValueLength;
proto_tree_add_string(name_tree, hf_amf_membername, tvb, iValueOffset, iStringLength, iStringValue);
iValueOffset += iStringLength;
} else {
/* the upper 28 bits of the integer value are a string reference index */
subval_tree = proto_tree_add_subtree_format(traits_tree, tvb, iValueOffset, iValueLength,
ett_amf_array_element, &subval_ti, "Reference %u:", iIntegerValue >> 1);
proto_tree_add_uint(subval_tree, hf_amf_string_reference, tvb, iValueOffset, iValueLength, iIntegerValue >> 1);
iValueOffset += iValueLength;
}
/* Fetch the value */
iValueOffset = dissect_amf3_value_type(tvb, pinfo, iValueOffset, subval_tree, subval_ti);
proto_item_set_end(subval_ti, tvb, iValueOffset);
}
}
proto_item_set_end(traits_ti, tvb, iValueOffset);
}
} else {
/*
* U29O-traits-ref; the upper 27 bits of
* the integer value are a traits reference
* index.
*/
proto_tree_add_uint(val_tree, hf_amf_trait_reference, tvb, iValueOffset, iValueLength, iIntegerValue >> 2);
iValueOffset += iValueLength;
}
} else {
/*
* U29O-ref; the upper 28 bits of the integer value
* are an object reference index.
*/
proto_tree_add_uint(val_tree, hf_amf_object_reference, tvb, iValueOffset, iValueLength, iIntegerValue >> 1);
proto_item_append_text(ti, " reference %u", iIntegerValue >> 1);
if (parent_ti != NULL)
proto_item_append_text(parent_ti, " reference %u", iIntegerValue >> 1);
}
break;
case AMF3_XML:
iIntegerValue = amf_get_u29(tvb, iValueOffset, &iValueLength);
if (iIntegerValue & 0x00000001) {
/*
* The upper 28 bits of the integer value are
* a count of the number of bytes in the
* XML string.
*/
iStringLength = iIntegerValue >> 1;
proto_tree_add_uint(val_tree, hf_amf_xmllength, tvb, iValueOffset, iValueLength, iStringLength);
iValueOffset += iValueLength;
proto_tree_add_item(val_tree, hf_amf_xml, tvb, iValueOffset, iStringLength, ENC_UTF_8);
} else {
/* the upper 28 bits of the integer value are a string reference index */
proto_tree_add_uint(val_tree, hf_amf_object_reference, tvb, iValueOffset, iValueLength, iIntegerValue >> 1);
proto_item_append_text(ti, " reference %u", iIntegerValue >> 1);
if (parent_ti != NULL)
proto_item_append_text(parent_ti, " reference %u", iIntegerValue >> 1);
}
break;
case AMF3_BYTEARRAY:
iIntegerValue = amf_get_u29(tvb, iValueOffset, &iValueLength);
if (iIntegerValue & 0x00000001) {
/*
* The upper 28 bits of the integer value are
* a count of the number of bytes in the
* byte array.
*/
iArrayLength = iIntegerValue >> 1;
proto_tree_add_uint(val_tree, hf_amf_bytearraylength, tvb, iValueOffset, iValueLength, iArrayLength);
iValueOffset += iValueLength;
iByteArrayValue = (uint8_t *)tvb_memdup(pinfo->pool, tvb, iValueOffset, iArrayLength);
proto_tree_add_bytes(val_tree, hf_amf_bytearray, tvb, iValueOffset, iArrayLength, iByteArrayValue);
proto_item_append_text(ti, " %s", bytes_to_str(pinfo->pool, iByteArrayValue, iArrayLength));
if (parent_ti != NULL)
proto_item_append_text(parent_ti, " %s", bytes_to_str(pinfo->pool, iByteArrayValue, iArrayLength));
} else {
/* the upper 28 bits of the integer value are a object reference index */
proto_tree_add_uint(val_tree, hf_amf_object_reference, tvb, iValueOffset, iValueLength, iIntegerValue >> 1);
proto_item_append_text(ti, " reference %u", iIntegerValue >> 1);
if (parent_ti != NULL)
proto_item_append_text(parent_ti, " reference %u", iIntegerValue >> 1);
}
break;
default:
/*
* If we can't determine the length, don't carry on;
* just skip to the end of the tvbuff.
*/
iValueOffset = tvb_reported_length(tvb);
break;
}
decrement_dissection_depth(pinfo);
proto_item_set_end(ti, tvb, iValueOffset);
return iValueOffset;
}
static int
dissect_rtmpt_body_command(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_tree *rtmpt_tree, bool amf3)
{
bool amf3_encoding = false;
if (amf3) {
/* Looks like for the AMF3 variants we get a 0 byte here,
* followed by AMF0 encoding - I've never seen actual AMF3
* encoding used, which is completely different. I speculate
* that if the byte is AMF0_AMF3_MARKER then the rest
* will be in AMF3. For now, assume AMF0 only. */
offset++;
}
while (tvb_reported_length_remaining(tvb, offset) > 0)
{
if (amf3_encoding)
offset = dissect_amf3_value_type(tvb, pinfo, offset, rtmpt_tree, NULL);
else
offset = dissect_amf0_value_type(tvb, pinfo, offset, rtmpt_tree, &amf3_encoding, NULL);
}
return offset;
}
static void
dissect_rtmpt_body_audio(tvbuff_t *tvb, int offset, proto_tree *rtmpt_tree)
{
uint8_t iCtl;
uint8_t iAudioMultitrackCtl;
uint8_t iAudioTrackId;
uint32_t iAudioTrackLength;
proto_item *ai;
proto_tree *at;
bool isAudioMultitrack = false;
bool isOneTrack = false;
bool isManyTracksManyCodecs = false;
bool processAudioBody = true;
iCtl = tvb_get_uint8(tvb, offset);
if ((iCtl & RTMPT_IS_EX_AUDIO_HEADER) == RTMPT_IS_EX_AUDIO_HEADER) {
ai = proto_tree_add_uint_format(rtmpt_tree, hf_rtmpt_audio_packet_type, tvb, offset, 1, iCtl,
"Control: 0x%02x (%s)", iCtl,
val_to_str_const((iCtl & 0xf), rtmpt_audio_packet_types, "Reserved audio packet type"));
at = proto_item_add_subtree(ai, ett_rtmpt_audio_control);
proto_tree_add_uint(at, hf_rtmpt_audio_is_ex_header, tvb, offset, 1, iCtl);
proto_tree_add_uint(at, hf_rtmpt_audio_packet_type, tvb, offset, 1, iCtl);
offset += 1;
isAudioMultitrack = (iCtl & 0xf) == RTMPT_IS_AUDIO_MULTITRACK;
if (isAudioMultitrack) {
iAudioMultitrackCtl = tvb_get_uint8(tvb, offset);
ai = proto_tree_add_uint_format(rtmpt_tree, hf_rtmpt_audio_multitrack_control, tvb, offset, 1, iAudioMultitrackCtl,
"Audio Multitrack Control: 0x%02x (%s %s)", iAudioMultitrackCtl,
val_to_str_const((iAudioMultitrackCtl & 0x0f), rtmpt_av_multitrack_types, "Reserved av multitrack type"),
val_to_str_const((iAudioMultitrackCtl & 0xf0) >> 4, rtmpt_audio_packet_types, "Reserved audio packet type"));
at = proto_item_add_subtree(ai, ett_rtmpt_audio_multitrack_control);
proto_tree_add_uint(at, hf_rtmpt_audio_multitrack_packet_type, tvb, offset, 1, iAudioMultitrackCtl);
proto_tree_add_uint(at, hf_rtmpt_audio_multitrack_type, tvb, offset, 1, iAudioMultitrackCtl);
offset += 1;
isOneTrack = (iAudioMultitrackCtl & 0x0f) == RTMPT_IS_ONETRACK;
isManyTracksManyCodecs = (iAudioMultitrackCtl & 0x0f) == RTMPT_IS_MANYTRACKSMANYCODECS;
if (!isManyTracksManyCodecs) {
proto_tree_add_item(rtmpt_tree, hf_rtmpt_audio_fourcc, tvb, offset, 4, ENC_ASCII);
offset += 4;
}
} else {
proto_tree_add_item(rtmpt_tree, hf_rtmpt_audio_fourcc, tvb, offset, 4, ENC_ASCII);
offset += 4;
}
while(processAudioBody && tvb_reported_length_remaining(tvb, offset) > 0) {
if (isAudioMultitrack) {
iAudioTrackId = tvb_get_uint8(tvb, offset);
ai = proto_tree_add_uint(rtmpt_tree, hf_rtmpt_audio_track_id, tvb, offset, 1, iAudioTrackId);
at = proto_item_add_subtree(ai, ett_rtmpt_audio_multitrack_track);
offset += 1;
if (isManyTracksManyCodecs) {
proto_tree_add_item(at, hf_rtmpt_audio_fourcc, tvb, offset, 4, ENC_ASCII);
offset += 4;
}
if (!isOneTrack) {
iAudioTrackLength = tvb_get_uint24(tvb, offset, ENC_BIG_ENDIAN);
proto_tree_add_uint(at, hf_rtmpt_audio_track_length, tvb, offset, 3, iAudioTrackLength);
offset += 3;
proto_tree_add_item(at, hf_rtmpt_audio_data, tvb, offset, -1, ENC_NA);
offset += iAudioTrackLength;
} else {
proto_tree_add_item(at, hf_rtmpt_audio_data, tvb, offset, -1, ENC_NA);
processAudioBody = false;
}
} else {
proto_tree_add_item(rtmpt_tree, hf_rtmpt_audio_data, tvb, offset, -1, ENC_NA);
processAudioBody = false;
}
}
} else {
ai = proto_tree_add_uint_format(rtmpt_tree, hf_rtmpt_audio_control, tvb, offset, 1, iCtl,
"Control: 0x%02x (%s %s %s %s)", iCtl,
val_to_str_const((iCtl & 0xf0) >> 4, rtmpt_audio_codecs, "Unknown codec"),
val_to_str_const((iCtl & 0x0c) >> 2, rtmpt_audio_rates, "Unknown rate"),
val_to_str_const((iCtl & 0x02) >> 1, rtmpt_audio_sizes, "Unknown sample size"),
val_to_str_const(iCtl & 0x01, rtmpt_audio_types, "Unknown channel count"));
at = proto_item_add_subtree(ai, ett_rtmpt_audio_control);
proto_tree_add_uint(at, hf_rtmpt_audio_format, tvb, offset, 1, iCtl);
proto_tree_add_uint(at, hf_rtmpt_audio_rate, tvb, offset, 1, iCtl);
proto_tree_add_uint(at, hf_rtmpt_audio_size, tvb, offset, 1, iCtl);
proto_tree_add_uint(at, hf_rtmpt_audio_type, tvb, offset, 1, iCtl);
proto_tree_add_item(rtmpt_tree, hf_rtmpt_audio_data, tvb, offset + 1, -1, ENC_NA);
}
}
static void
dissect_rtmpt_body_video(tvbuff_t *tvb, int offset, proto_tree *rtmpt_tree)
{
uint8_t iCtl;
uint8_t iMultitrackCtl;
uint8_t iVideoFrameType;
uint8_t iVideoPacketType;
uint8_t iAvMultitrackType;
uint32_t iVideoTrackLength;
proto_item *vi;
proto_tree *vt;
bool isVideoMultitrack = false;
bool isOneTrack = false;
bool isManyTracksManyCodecs = false;
bool processVideoBody = true;
iCtl = tvb_get_uint8(tvb, offset);
iVideoFrameType = (iCtl & 0x70) >> 4;
/*
* https://veovera.org/docs/enhanced/enhanced-rtmp-v2.pdf
*/
if (iCtl & RTMPT_IS_EX_VIDEO_HEADER) {
iVideoPacketType = iCtl & 0x0f;
isVideoMultitrack = iVideoPacketType == RTMPT_IS_VIDEO_MULTITRACK;
vi = proto_tree_add_uint_format(rtmpt_tree, hf_rtmpt_video_control, tvb, offset, 1, iCtl,
"Control: 0x%02x (%s %s)", iCtl,
val_to_str_const(iVideoFrameType, rtmpt_video_types, "Reserved frame type"),
val_to_str_const(iVideoPacketType, rtmpt_video_packet_types, "Reserved packet type"));
vt = proto_item_add_subtree(vi, ett_rtmpt_video_control);
proto_tree_add_item(vt, hf_rtmpt_video_is_ex_header, tvb, offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(vt, hf_rtmpt_video_type, tvb, offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(vt, hf_rtmpt_video_packet_type, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
if (iVideoPacketType != RTMPT_IS_PACKET_TYPE_METADATA && iVideoFrameType == RTMPT_IS_FRAME_TYPE_COMMAND) {
proto_tree_add_item(vt, hf_rtmpt_video_command, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
processVideoBody = false;
} else if (isVideoMultitrack) {
iMultitrackCtl = tvb_get_uint8(tvb, offset);
iAvMultitrackType = (iMultitrackCtl >> 4) & 0xf;
vi = proto_tree_add_uint_format(rtmpt_tree, hf_rtmpt_video_multitrack_control, tvb, offset, 1, iMultitrackCtl,
"Video Multitrack Control: 0x%02x (%s %s)", iMultitrackCtl,
val_to_str_const(iAvMultitrackType, rtmpt_av_multitrack_types, "Reserved av multitrack type"),
val_to_str_const(iMultitrackCtl & 0xf, rtmpt_video_packet_types, "Reserved video packet type"));
vt = proto_item_add_subtree(vi, ett_rtmpt_video_multitrack_control);
proto_tree_add_item(vt, hf_rtmpt_video_multitrack_type, tvb, offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(vt, hf_rtmpt_video_multitrack_packet_type, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
isOneTrack = (iAvMultitrackType & 0x0f) == RTMPT_IS_ONETRACK;
isManyTracksManyCodecs = (iAvMultitrackType & 0x0f) == RTMPT_IS_MANYTRACKSMANYCODECS;
if (!isManyTracksManyCodecs) {
proto_tree_add_item(rtmpt_tree, hf_rtmpt_video_fourcc, tvb, offset, 4, ENC_ASCII);
offset += 4;
}
} else {
proto_tree_add_item(rtmpt_tree, hf_rtmpt_video_fourcc, tvb, offset, 4, ENC_ASCII);
offset += 4;
}
while (processVideoBody && tvb_reported_length_remaining(tvb, offset) > 0){
if (isVideoMultitrack) {
vi = proto_tree_add_item(rtmpt_tree, hf_rtmpt_video_track_id, tvb, offset, 1, ENC_BIG_ENDIAN);
vt = proto_item_add_subtree(vi, ett_rtmpt_video_multitrack_track);
if (isManyTracksManyCodecs) {
proto_tree_add_item(vt, hf_rtmpt_video_fourcc, tvb, offset, 4, ENC_ASCII);
offset += 4;
}
offset += 1;
if (!isOneTrack) {
iVideoTrackLength = tvb_get_uint24(tvb, offset, ENC_BIG_ENDIAN);
proto_tree_add_item(vt, hf_rtmpt_video_track_length, tvb, offset, 3, ENC_BIG_ENDIAN);
offset += 3;
proto_tree_add_item(vt, hf_rtmpt_video_data, tvb, offset, iVideoTrackLength, ENC_NA);
offset += iVideoTrackLength;
} else {
proto_tree_add_item(vt, hf_rtmpt_video_data, tvb, offset, -1, ENC_NA);
processVideoBody = false;
}
} else {
proto_tree_add_item(rtmpt_tree, hf_rtmpt_video_data, tvb, offset, -1, ENC_NA);
processVideoBody = false;
}
}
} else {
vi = proto_tree_add_uint_format(rtmpt_tree, hf_rtmpt_video_control, tvb, offset, 1, iCtl,
"Control: 0x%02x (%s %s)", iCtl,
val_to_str_const(iVideoFrameType, rtmpt_video_types, "Reserved frame type"),
val_to_str_const(iCtl & 0x0f, rtmpt_video_codecs, "Unknown codec"));
vt = proto_item_add_subtree(vi, ett_rtmpt_video_control);
proto_tree_add_item(vt, hf_rtmpt_video_type, tvb, offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(vt, hf_rtmpt_video_format, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
if (iVideoFrameType == RTMPT_IS_FRAME_TYPE_COMMAND) {
proto_tree_add_item(vt, hf_rtmpt_video_command, tvb, offset, 1, ENC_BIG_ENDIAN);
} else {
proto_tree_add_item(rtmpt_tree, hf_rtmpt_video_data, tvb, offset, -1, ENC_NA);
}
}
}
static void
dissect_rtmpt_body_aggregate(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_tree *rtmpt_tree)
{
proto_tree *tag_tree;
proto_tree *data_tree;
while (tvb_reported_length_remaining(tvb, offset) > 0) {
uint8_t iTagType;
unsigned iDataSize;
iTagType = tvb_get_uint8(tvb, offset + 0);
iDataSize = tvb_get_ntoh24(tvb, offset + 1);
tag_tree = proto_tree_add_subtree(rtmpt_tree, tvb, offset, 11+iDataSize+4, ett_rtmpt_tag, NULL,
val_to_str_const(iTagType, rtmpt_tag_vals, "Unknown Tag"));
proto_tree_add_item(tag_tree, hf_rtmpt_tag_type, tvb, offset+0, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(tag_tree, hf_rtmpt_tag_datasize, tvb, offset+1, 3, ENC_BIG_ENDIAN);
proto_tree_add_item(tag_tree, hf_rtmpt_tag_timestamp, tvb, offset+4, 3, ENC_BIG_ENDIAN);
proto_tree_add_item(tag_tree, hf_rtmpt_tag_ets, tvb, offset+7, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(tag_tree, hf_rtmpt_tag_streamid, tvb, offset+8, 3, ENC_BIG_ENDIAN);
data_tree = proto_tree_add_subtree(tag_tree, tvb, offset+11, iDataSize, ett_rtmpt_tag_data, NULL, "Data");
switch (iTagType) {
case 8:
dissect_rtmpt_body_audio(tvb, offset + 11, data_tree);
break;
case 9:
dissect_rtmpt_body_video(tvb, offset + 11, data_tree);
break;
case 18:
dissect_rtmpt_body_command(tvb, pinfo, offset + 11, data_tree, false);
break;
default:
break;
}
proto_tree_add_item(tag_tree, hf_rtmpt_tag_tagsize, tvb, offset+11+iDataSize, 4, ENC_BIG_ENDIAN);
offset += 11 + iDataSize + 4;
}
}
/* The main dissector for unchunked packets */
static void
dissect_rtmpt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, rtmpt_conv_t *rconv, int cdir, rtmpt_packet_t *tp)
{
int offset = 0;
char *sDesc = NULL;
bool deschasopcode = false;
bool haveETS = false;
uint32_t iBodyOffset = 0;
uint32_t iBodyRemain = 0;
col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTMP");
ws_debug("Dissect: frame=%u visited=%d len=%d tree=%p",
pinfo->num, pinfo->fd->visited,
tvb_reported_length_remaining(tvb, offset), tree);
/* Clear any previous data in Info column (RTMP packets are protected by a "fence") */
col_clear(pinfo->cinfo, COL_INFO);
if (tvb_reported_length_remaining(tvb, offset) < 1) return;
if (tp->id <= RTMPT_ID_MAX) {
if (tp->fmt < 3
&& tvb_reported_length_remaining(tvb, offset) >= tp->bhlen+3
&& tvb_get_ntoh24(tvb, offset+tp->bhlen) == 0xffffff) {
haveETS = true;
}
iBodyOffset = offset + tp->bhlen + tp->mhlen;
iBodyRemain = tvb_reported_length_remaining(tvb, iBodyOffset);
if (tp->cmd == RTMPT_TYPE_CHUNK_SIZE && tp->len >= 4 && iBodyRemain >= 4) {
int32_t newchunksize = tvb_get_ntohl(tvb, iBodyOffset);
if (newchunksize > 0) {
wmem_tree_insert32(rconv->chunksize[cdir], tp->lastseq, GINT_TO_POINTER(newchunksize));
}
}
if (tp->cmd == RTMPT_TYPE_COMMAND_AMF0 || tp->cmd == RTMPT_TYPE_COMMAND_AMF3 ||
tp->cmd == RTMPT_TYPE_DATA_AMF0 || tp->cmd == RTMPT_TYPE_DATA_AMF3) {
uint32_t soff = 0;
if (tp->cmd == RTMPT_TYPE_COMMAND_AMF3 || tp->cmd == RTMPT_TYPE_DATA_AMF3) {
soff = 1;
}
tp->txid = rtmpt_get_amf_txid(tvb, iBodyOffset+soff, tree);
if (tp->txid != 0 && !PINFO_FD_VISITED(pinfo)) {
ws_debug("got txid=%d", tp->txid);
wmem_tree_insert32(rconv->txids[cdir], tp->txid, GINT_TO_POINTER(pinfo->num));
}
}
} else if (tp->id == RTMPT_TYPE_HANDSHAKE_2 || tp->id == RTMPT_TYPE_HANDSHAKE_3) {
uint32_t newchunksize = RTMPT_INITIAL_CHUNK_SIZE;
wmem_tree_insert32(rconv->chunksize[cdir], tp->lastseq, GINT_TO_POINTER(newchunksize));
}
if (tp->id <= RTMPT_ID_MAX)
{
sDesc = rtmpt_get_packet_desc(tvb, iBodyOffset, tree, iBodyRemain, rconv, cdir, tp, &deschasopcode);
}
if (tp->id>RTMPT_ID_MAX) {
col_append_sep_str(pinfo->cinfo, COL_INFO, "|",
val_to_str(tp->id, rtmpt_handshake_vals, "Unknown (0x%01x)"));
col_set_fence(pinfo->cinfo, COL_INFO);
} else if (sDesc) {
col_append_sep_str(pinfo->cinfo, COL_INFO, "|", sDesc);
col_set_fence(pinfo->cinfo, COL_INFO);
} else {
col_append_sep_str(pinfo->cinfo, COL_INFO, "|",
val_to_str(tp->cmd, rtmpt_opcode_vals, "Unknown (0x%01x)"));
col_set_fence(pinfo->cinfo, COL_INFO);
}
if (tree)
{
proto_tree *rtmpt_tree = NULL;
proto_tree *rtmptroot_tree = NULL;
proto_item *ti;
ti = proto_tree_add_item(tree, proto_rtmpt, tvb, offset, -1, ENC_NA);
if (tp->id > RTMPT_ID_MAX) {
/* Dissect handshake */
proto_item_append_text(ti, " (%s)",
val_to_str(tp->id, rtmpt_handshake_vals, "Unknown (0x%01x)"));
rtmptroot_tree = proto_item_add_subtree(ti, ett_rtmpt);
rtmpt_tree = proto_tree_add_subtree(rtmptroot_tree, tvb, offset, -1, ett_rtmpt_handshake, NULL,
val_to_str(tp->id, rtmpt_handshake_vals, "Unknown (0x%01x)"));
if (tp->id == RTMPT_TYPE_HANDSHAKE_1)
{
proto_tree_add_item(rtmpt_tree, hf_rtmpt_handshake_c0, tvb, 0, 1, ENC_NA);
proto_tree_add_item(rtmpt_tree, hf_rtmpt_handshake_c1, tvb, 1, 1536, ENC_NA);
}
else if (tp->id == RTMPT_TYPE_HANDSHAKE_2)
{
proto_tree_add_item(rtmpt_tree, hf_rtmpt_handshake_s0, tvb, 0, 1, ENC_NA);
proto_tree_add_item(rtmpt_tree, hf_rtmpt_handshake_s1, tvb, 1, 1536, ENC_NA);
proto_tree_add_item(rtmpt_tree, hf_rtmpt_handshake_s2, tvb, 1537, 1536, ENC_NA);
}
else if (tp->id == RTMPT_TYPE_HANDSHAKE_3)
{
proto_tree_add_item(rtmpt_tree, hf_rtmpt_handshake_c2, tvb, 0, 1536, ENC_NA);
}
return;
}
if (sDesc && deschasopcode) {
proto_item_append_text(ti, " (%s)", sDesc);
} else if (sDesc) {
proto_item_append_text(ti, " (%s %s)",
val_to_str(tp->cmd, rtmpt_opcode_vals, "Unknown (0x%01x)"), sDesc);
} else {
proto_item_append_text(ti, " (%s)",
val_to_str(tp->cmd, rtmpt_opcode_vals, "Unknown (0x%01x)"));
}
rtmptroot_tree = proto_item_add_subtree(ti, ett_rtmpt);
/* Function call/response matching */
if (tp->otherframe != 0) {
proto_tree_add_uint(rtmptroot_tree,
tp->isresponse ? hf_rtmpt_function_response : hf_rtmpt_function_call,
tvb, offset, tp->bhlen+tp->mhlen+tp->len,
tp->otherframe);
}
/* Dissect header fields */
rtmpt_tree = proto_tree_add_subtree(rtmptroot_tree, tvb, offset, tp->bhlen+tp->mhlen, ett_rtmpt_header, NULL, RTMPT_TEXT_RTMP_HEADER);
/* proto_item_append_text(ti, " (%s)", val_to_str(tp->cmd, rtmpt_opcode_vals, "Unknown (0x%01x)")); */
if (tp->fmt <= 3) proto_tree_add_item(rtmpt_tree, hf_rtmpt_header_format, tvb, offset + 0, 1, ENC_BIG_ENDIAN);
if (tp->fmt <= 3) proto_tree_add_item(rtmpt_tree, hf_rtmpt_header_csid, tvb, offset + 0, tp->bhlen, ENC_BIG_ENDIAN);
if (tp->fmt <= 2) {
if (tp->fmt > 0) {
proto_tree_add_item(rtmpt_tree, hf_rtmpt_header_timestamp_delta, tvb, offset + tp->bhlen, 3, ENC_BIG_ENDIAN);
} else {
proto_tree_add_item(rtmpt_tree, hf_rtmpt_header_timestamp, tvb, offset + tp->bhlen, 3, ENC_BIG_ENDIAN);
}
if (haveETS) {
proto_tree_add_item(rtmpt_tree, hf_rtmpt_header_ets, tvb, offset + tp->bhlen + tp->mhlen - 4, 4, ENC_BIG_ENDIAN);
}
}
if ((tp->fmt>0 && !haveETS) || tp->fmt == 3) {
proto_tree_add_uint_format_value(rtmpt_tree, hf_rtmpt_header_timestamp, tvb, offset + tp->bhlen, 0, tp->ts, "%d (calculated)", tp->ts);
}
if (tp->fmt <= 1) proto_tree_add_item(rtmpt_tree, hf_rtmpt_header_body_size, tvb, offset + tp->bhlen + 3, 3, ENC_BIG_ENDIAN);
if (tp->fmt <= 1) proto_tree_add_item(rtmpt_tree, hf_rtmpt_header_typeid, tvb, offset + tp->bhlen + 6, 1, ENC_BIG_ENDIAN);
if (tp->fmt <= 0) proto_tree_add_item(rtmpt_tree, hf_rtmpt_header_streamid, tvb, offset + tp->bhlen + 7, 4, ENC_LITTLE_ENDIAN);
/* Dissect body */
if (tp->len == 0) return;
offset = iBodyOffset;
rtmpt_tree = proto_tree_add_subtree(rtmptroot_tree, tvb, offset, -1, ett_rtmpt_body, NULL, RTMPT_TEXT_RTMP_BODY);
switch (tp->cmd) {
case RTMPT_TYPE_CHUNK_SIZE:
case RTMPT_TYPE_ABORT_MESSAGE:
case RTMPT_TYPE_ACKNOWLEDGEMENT:
case RTMPT_TYPE_UCM:
case RTMPT_TYPE_WINDOW:
case RTMPT_TYPE_PEER_BANDWIDTH:
dissect_rtmpt_body_scm(tvb, offset, rtmpt_tree, tp->cmd);
break;
case RTMPT_TYPE_COMMAND_AMF0:
case RTMPT_TYPE_DATA_AMF0:
dissect_rtmpt_body_command(tvb, pinfo, offset, rtmpt_tree, false);
break;
case RTMPT_TYPE_COMMAND_AMF3:
case RTMPT_TYPE_DATA_AMF3:
dissect_rtmpt_body_command(tvb, pinfo, offset, rtmpt_tree, true);
break;
case RTMPT_TYPE_AUDIO_DATA:
dissect_rtmpt_body_audio(tvb, offset, rtmpt_tree);
break;
case RTMPT_TYPE_VIDEO_DATA:
dissect_rtmpt_body_video(tvb, offset, rtmpt_tree);
break;
case RTMPT_TYPE_AGGREGATE:
dissect_rtmpt_body_aggregate(tvb, pinfo, offset, rtmpt_tree);
break;
}
}
}
/* Unchunk a data stream into individual RTMP packets */
static void
dissect_rtmpt_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, rtmpt_conv_t *rconv, int cdir, uint32_t seq, uint32_t lastackseq)
{
int offset = 0;
int remain;
int want;
uint8_t header_type;
int basic_hlen;
int message_hlen;
uint32_t id;
uint32_t ts = 0;
uint32_t tsd = 0;
int body_len;
uint8_t cmd;
uint32_t src;
int chunk_size;
rtmpt_frag_t *tf;
rtmpt_id_t *ti;
rtmpt_packet_t *tp;
tvbuff_t *pktbuf;
remain = tvb_reported_length(tvb);
if (!remain)
return;
ws_debug("Segment: cdir=%d seq=%d-%d", cdir, seq, seq+remain-1);
if (pinfo->fd->visited) {
/* Already done the work, so just dump the existing state */
/* XXX: If there's bogus sequence numbers and the
* tcp.analyze_sequence_numbers pref is true, we can't actually
* assume that we processed this frame the first time around,
* since the TCP dissector might not have given it to us.
*/
wmem_stack_t *packets;
/* List all RTMP packets terminating in this TCP segment, from end to beginning */
packets = wmem_stack_new(pinfo->pool);
wmem_stack_push(packets, 0);
tp = (rtmpt_packet_t *)wmem_tree_lookup32_le(rconv->packets[cdir], seq+remain-1);
while (tp && GE_SEQ(tp->lastseq, seq)) {
/* Sequence numbers can wrap around (especially with
* tcp.relative_sequence_numbers false), so use the
* wrap around aware comparison from packet-tcp.h
*/
wmem_stack_push(packets, tp);
if (tp->seq == 0) {
// reached first segment.
/* XXX: Assuming tcp.relative_sequence_numbers
* is true, that is, since on TCP we just
* reuse the sequence numbers from tcpinfo.
*/
break;
}
if (tp->seq > tp->lastseq) {
/* XXX: There are some problems with sequence
* numbers that wraparound in the middle of
* a segment and using wmem_tree_lookup32_le
* below. Break out here to guarantee that there
* is a limit to the tree lookups and we don't
* have infinite loops. Really a lot of this
* code should be rewritten to deal with
* sequence numbers that wrap around (especially
* (SYN packets with altered sequence numbers
* and out of order packets.)
*/
break;
}
tp = (rtmpt_packet_t *)wmem_tree_lookup32_le(rconv->packets[cdir], tp->seq-1);
}
/* Dissect the generated list in reverse order (beginning to end) */
while ((tp=(rtmpt_packet_t *)wmem_stack_pop(packets)) != NULL) {
if (tp->resident) {
pktbuf = tvb_new_child_real_data(tvb, tp->data.p, tp->have, tp->have);
add_new_data_source(pinfo, pktbuf, "Unchunked RTMP");
} else {
pktbuf = tvb_new_subset_length(tvb, tp->data.offset, tp->have);
}
dissect_rtmpt(pktbuf, pinfo, tree, rconv, cdir, tp);
}
return;
}
while (remain>0) {
tf = NULL;
ti = NULL;
tp = NULL;
/* Check for outstanding fragmented headers/chunks first */
if (offset == 0) {
tf = (rtmpt_frag_t *)wmem_tree_lookup32_le(rconv->frags[cdir], seq+offset-1);
if (tf) {
/* May need to reassemble cross-TCP-segment fragments */
ws_noisy(" tf seq=%d lseq=%d h=%d l=%d", tf->seq, tf->lastseq, tf->have, tf->len);
if (tf->have >= tf->len || seq+offset < tf->seq || seq+offset > tf->lastseq+tf->len-tf->have) {
tf = NULL;
} else if (!tf->ishdr) {
ti = (rtmpt_id_t *)wmem_tree_lookup32(rconv->ids[cdir], tf->saved.id);
if (ti) {
tp = (rtmpt_packet_t *)wmem_tree_lookup32_le(ti->packets, seq+offset-1);
}
if (tp && tp->chunkwant) {
goto unchunk;
}
tf = NULL;
ti = NULL;
tp = NULL;
}
if (tf) {
/* The preceding segment contained an incomplete chunk header */
want = tf->len - tf->have;
if (remain<want)
want = remain;
tvb_memcpy(tvb, tf->saved.d+tf->have, offset, want);
id = tf->saved.d[0];
header_type = (id>>6) & 3;
basic_hlen = rtmpt_basic_header_length(id);
if ((header_type < 3) && (tf->have < (basic_hlen+3)) && (tf->have+want >= (basic_hlen+3))) {
if (pntoh24(tf->saved.d+basic_hlen) == 0xffffff) {
tf->len += 4;
}
}
tf->have += want;
tf->lastseq = seq+want-1;
remain -= want;
offset += want;
if (tf->have < tf->len) {
return;
}
}
}
}
if (!tf) {
/* No preceding data, get header data starting at current position */
id = tvb_get_uint8(tvb, offset);
if (id == RTMPT_MAGIC && seq+offset == RTMPT_HANDSHAKE_OFFSET_1) {
header_type = 4;
basic_hlen = 1;
message_hlen = 0;
id = lastackseq == 1 ? RTMPT_TYPE_HANDSHAKE_1 : RTMPT_TYPE_HANDSHAKE_2;
} else if (seq+offset == RTMPT_HANDSHAKE_OFFSET_2) {
header_type = 4;
basic_hlen = 0;
message_hlen = 0;
id = RTMPT_TYPE_HANDSHAKE_3;
} else {
header_type = (id>>6) & 3;
basic_hlen = rtmpt_basic_header_length(id);
message_hlen = rtmpt_message_header_length(id);
if ((header_type < 3) && (remain >= (basic_hlen+3))) {
if (tvb_get_ntoh24(tvb, offset+basic_hlen) == 0xffffff) {
message_hlen += 4;
}
}
if (remain < (basic_hlen+message_hlen)) {
/* Ran out of packet mid-header, save and try again next time */
tf = wmem_new(wmem_file_scope(), rtmpt_frag_t);
tf->ishdr = 1;
tf->seq = seq + offset;
tf->lastseq = tf->seq + remain - 1;
tf->len = basic_hlen + message_hlen;
tvb_memcpy(tvb, tf->saved.d, offset, remain);
tf->have = remain;
wmem_tree_insert32(rconv->frags[cdir], seq+offset, tf);
return;
}
id = id & 0x3f;
if (id == 0)
id = tvb_get_uint8(tvb, offset+1) + 64;
else if (id == 1)
id = tvb_get_letohs(tvb, offset+1) + 64;
}
} else {
/* Use reassembled header data */
id = tf->saved.d[0];
header_type = (id>>6) & 3;
basic_hlen = rtmpt_basic_header_length(id);
message_hlen = tf->len - basic_hlen;
id = id & 0x3f;
if (id == 0)
id = tf->saved.d[1] + 64;
else if (id == 1)
id = pletoh16(tf->saved.d+1) + 64;
}
/* Calculate header values, defaulting from previous packets with same id */
if (id <= RTMPT_ID_MAX)
ti = (rtmpt_id_t *)wmem_tree_lookup32(rconv->ids[cdir], id);
if (ti)
tp = (rtmpt_packet_t *)wmem_tree_lookup32_le(ti->packets, seq+offset-1);
if (header_type == 0)
src = tf ? pntoh32(tf->saved.d+basic_hlen+7) : tvb_get_ntohl(tvb, offset+basic_hlen+7);
else if (ti)
src = ti->src;
else src = 0;
if (header_type < 2)
cmd = tf ? tf->saved.d[basic_hlen+6] : tvb_get_uint8(tvb, offset+basic_hlen+6);
else if (ti)
cmd = ti->cmd;
else
cmd = 0;
/* Calculate chunk_size now as a last-resort default payload length */
if (id > RTMPT_ID_MAX) {
if (id == RTMPT_TYPE_HANDSHAKE_1)
chunk_size = body_len = 1536;
else if (id == RTMPT_TYPE_HANDSHAKE_2)
chunk_size = body_len = 3072;
else /* if (id == RTMPT_TYPE_HANDSHAKE_3) */
chunk_size = body_len = 1536;
} else {
chunk_size = GPOINTER_TO_INT(wmem_tree_lookup32_le(rconv->chunksize[cdir], seq+offset-1));
if (!chunk_size) {
chunk_size = ((int)rtmpt_default_chunk_size > 0) ? rtmpt_default_chunk_size : INT_MAX;
}
if (header_type < 2)
body_len = tf ? pntoh24(tf->saved.d+basic_hlen+3) : tvb_get_ntoh24(tvb, offset+basic_hlen+3);
else if (ti)
body_len = ti->len;
else
body_len = chunk_size;
}
if (!ti || !tp || header_type<3 || tp->have == tp->want || tp->chunkhave != tp->chunkwant) {
/* Start a new packet if:
* no previous packet with same id
* not a short 1-byte header
* previous packet with same id was complete
* previous incomplete chunk not handled by fragment handler
*/
ws_noisy("New packet cdir=%d seq=%d ti=%p tp=%p header_type=%d header_len=%d id=%d tph=%d tpw=%d len=%d cs=%d",
cdir, seq+offset,
ti, tp, header_type, basic_hlen+message_hlen, id, tp?tp->have:0, tp?tp->want:0, body_len, chunk_size);
if (!ti) {
ti = wmem_new(wmem_file_scope(), rtmpt_id_t);
ti->packets = wmem_tree_new(wmem_file_scope());
ti->ts = 0;
ti->tsd = 0;
wmem_tree_insert32(rconv->ids[cdir], id, ti);
}
if (header_type == 0) {
ts = tf ? pntoh24(tf->saved.d+basic_hlen) : tvb_get_ntoh24(tvb, offset+basic_hlen);
if (ts == 0xffffff) {
ts = tf ? pntoh32(tf->saved.d+basic_hlen+11) : tvb_get_ntohl(tvb, offset+basic_hlen+11);
}
tsd = ts - ti->ts;
} else if (header_type < 3) {
tsd = tf ? pntoh24(tf->saved.d+basic_hlen) : tvb_get_ntoh24(tvb, offset+basic_hlen);
if (tsd == 0xffffff) {
ts = tf ? pntoh32(tf->saved.d+basic_hlen+message_hlen-4) : tvb_get_ntohl(tvb, offset+basic_hlen+message_hlen-4);
tsd = ti->tsd; /* questionable */
} else {
ts = ti->ts + tsd;
}
} else {
ts = ti->ts + ti->tsd;
tsd = ti->tsd;
}
/* create a new packet structure */
tp = wmem_new(wmem_file_scope(), rtmpt_packet_t);
tp->seq = tp->lastseq = tf ? tf->seq : seq+offset;
tp->have = 0;
tp->want = basic_hlen + message_hlen + body_len;
tp->chunkwant = 0;
tp->chunkhave = 0;
tp->bhlen = basic_hlen;
tp->mhlen = message_hlen;
tp->fmt = header_type;
tp->id = id;
tp->ts = ts;
tp->len = body_len;
if (id > RTMPT_ID_MAX)
tp->cmd = id;
else
tp->cmd = cmd & 0x7f;
tp->src = src;
tp->txid = 0;
tp->isresponse = false;
tp->otherframe = 0;
tp->frames = wmem_list_new(wmem_file_scope());
wmem_list_prepend(tp->frames, GUINT_TO_POINTER(pinfo->num));
/* Save the header information for future defaulting needs */
ti->ts = ts;
ti->tsd = tsd;
ti->len = body_len;
ti->cmd = cmd;
ti->src = src;
/* store against the id only until unchunking is complete */
wmem_tree_insert32(ti->packets, tp->seq, tp);
if (!tf && body_len <= chunk_size && tp->want <= remain) {
/* The easy case - a whole packet contiguous and fully within this segment */
tp->resident = false;
tp->data.offset = offset;
tp->lastseq = seq+offset+tp->want-1;
tp->have = tp->want;
wmem_tree_insert32(rconv->packets[cdir], tp->lastseq, tp);
pktbuf = tvb_new_subset_length(tvb, tp->data.offset, tp->have);
dissect_rtmpt(pktbuf, pinfo, tree, rconv, cdir, tp);
offset += tp->want;
remain -= tp->want;
continue;
} else {
/* Some more reassembly required */
tp->resident = true;
/* tp->want is how much data we think we want.
* If it's a really big number, we don't want
* to allocate it all at once, due to memory
* exhaustion on fuzzed data (#6898).
* RTMPT_INIT_ALLOC_SIZE should always be larger
* than basic_hlen + message_hlen.
*/
tp->alloc = MIN(tp->want, RTMPT_INIT_ALLOC_SIZE);
tp->data.p = (uint8_t *)wmem_alloc(wmem_file_scope(), tp->alloc);
if (tf && tf->ishdr) {
memcpy(tp->data.p, tf->saved.d, tf->len);
} else {
tvb_memcpy(tvb, tp->data.p, offset, basic_hlen+message_hlen);
offset += basic_hlen + message_hlen;
remain -= basic_hlen + message_hlen;
}
tp->lastseq = seq+offset-1;
tp->have = basic_hlen + message_hlen;
if (tp->have == tp->want) {
wmem_tree_insert32(rconv->packets[cdir], tp->lastseq, tp);
pktbuf = tvb_new_child_real_data(tvb, tp->data.p, tp->have, tp->have);
add_new_data_source(pinfo, pktbuf, "Unchunked RTMP");
dissect_rtmpt(pktbuf, pinfo, tree, rconv, cdir, tp);
continue;
}
tp->chunkwant = chunk_size;
if (tp->chunkwant > tp->want-tp->have)
tp->chunkwant = tp->want - tp->have;
}
} else {
if (header_type == 3 && tp->resident && tp->have > tp->bhlen + 3
&& pntoh24(tp->data.p+tp->bhlen) == 0xffffff) {
/* Header type 3 resends the extended time stamp if the last message on the chunk
* stream had an extended timestamp.
* See: https://gitlab.com/wireshark/wireshark/-/issues/15718
*/
message_hlen += 4;
}
ws_noisy("Old packet cdir=%d seq=%d ti=%p tp=%p header_len=%d id=%d tph=%d tpw=%d len=%d cs=%d",
cdir, seq+offset,
ti, tp, basic_hlen+message_hlen, id, tp?tp->have:0, tp?tp->want:0, body_len, chunk_size);
tp->chunkwant = chunk_size;
if (tp->chunkwant > tp->want-tp->have)
tp->chunkwant = tp->want - tp->have;
offset += basic_hlen + message_hlen;
remain -= basic_hlen + message_hlen;
}
tf = NULL;
/* Last case to deal with is unchunking the packet body */
unchunk:
want = tp->chunkwant - tp->chunkhave;
if (want > remain)
want = remain;
ws_noisy(" cw=%d ch=%d r=%d w=%d", tp->chunkwant, tp->chunkhave, remain, want);
/* message length is a 3 byte number, never overflows an int */
if (tp->alloc < tp->have + want) {
/* tp->want - how much data is supposedly in the entire
* unchunked packet, according to the header. Up to a
* 24-bit integer. Actually allocating this amount can
* cause memory exhaustion on fuzzed data.
* want - how much more data we are going to copy from the
* current tvbuff. No more than necessary to finish the
* current chunk, or what's actually in the tvbuff.
* Allocating this amount shouldn't cause memory exhaustion
* because it's present in the frame.
*
* We should have calculated those values so that the
* following assertion is true.
*/
DISSECTOR_ASSERT_CMPINT(tp->have + want, <=, tp->want);
tp->alloc = MAX(tp->alloc*2, tp->have + want);
tp->alloc = MIN(tp->alloc, tp->want);
tp->data.p = wmem_realloc(wmem_file_scope(), tp->data.p, tp->alloc);
}
tvb_memcpy(tvb, tp->data.p+tp->have, offset, want);
wmem_list_frame_t *frame_head = wmem_list_head(tp->frames);
if (wmem_list_frame_data(frame_head) != GUINT_TO_POINTER(pinfo->num)) {
wmem_list_prepend(tp->frames, GUINT_TO_POINTER(pinfo->num));
}
if (tf) {
tf->have += want;
tf->lastseq = seq+offset+want-1;
}
tp->lastseq = seq+offset+want-1;
tp->have += want;
tp->chunkhave += want;
offset += want;
remain -= want;
if (tp->chunkhave == tp->chunkwant) {
/* Chunk is complete - wait for next header */
tp->chunkhave = 0;
tp->chunkwant = 0;
}
if (tp->have == tp->want) {
/* Whole packet is complete */
wmem_tree_insert32(rconv->packets[cdir], tp->lastseq, tp);
wmem_list_foreach(tp->frames, rtmpt_packet_mark_depended, pinfo->fd);
pktbuf = tvb_new_child_real_data(tvb, tp->data.p, tp->have, tp->have);
add_new_data_source(pinfo, pktbuf, "Unchunked RTMP");
dissect_rtmpt(pktbuf, pinfo, tree, rconv, cdir, tp);
} else if (tp->chunkhave < tp->chunkwant) {
/* Chunk is split across segment boundary */
rtmpt_frag_t *tf2 = wmem_new(wmem_file_scope(), rtmpt_frag_t);
tf2->ishdr = 0;
tf2->seq = seq + offset - want;
tf2->lastseq = tf2->seq + remain - 1 + want;
tf2->have = tp->chunkhave;
tf2->len = tp->chunkwant;
tf2->saved.id = tp->id;
ws_noisy(" inserting tf @ %d", seq+offset-want-1);
wmem_tree_insert32(rconv->frags[cdir], seq+offset-want-1, tf2);
}
}
}
static rtmpt_conv_t *
rtmpt_init_rconv(conversation_t *conv)
{
rtmpt_conv_t *rconv = wmem_new(wmem_file_scope(), rtmpt_conv_t);
conversation_add_proto_data(conv, proto_rtmpt, rconv);
rconv->seqs[0] = wmem_tree_new(wmem_file_scope());
rconv->seqs[1] = wmem_tree_new(wmem_file_scope());
rconv->frags[0] = wmem_tree_new(wmem_file_scope());
rconv->frags[1] = wmem_tree_new(wmem_file_scope());
rconv->ids[0] = wmem_tree_new(wmem_file_scope());
rconv->ids[1] = wmem_tree_new(wmem_file_scope());
rconv->packets[0] = wmem_tree_new(wmem_file_scope());
rconv->packets[1] = wmem_tree_new(wmem_file_scope());
rconv->chunksize[0] = wmem_tree_new(wmem_file_scope());
rconv->chunksize[1] = wmem_tree_new(wmem_file_scope());
rconv->txids[0] = wmem_tree_new(wmem_file_scope());
rconv->txids[1] = wmem_tree_new(wmem_file_scope());
return rconv;
}
static int
dissect_rtmpt_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
{
conversation_t *conv;
rtmpt_conv_t *rconv;
int cdir;
struct tcpinfo *tcpinfo;
/* Reject the packet if data is NULL */
if (data == NULL) {
return 0;
}
tcpinfo = (struct tcpinfo*)data;
conv = find_or_create_conversation(pinfo);
rconv = (rtmpt_conv_t*)conversation_get_proto_data(conv, proto_rtmpt);
if (!rconv) {
rconv = rtmpt_init_rconv(conv);
}
cdir = (addresses_equal(conversation_key_addr1(conv->key_ptr), &pinfo->src) &&
addresses_equal(conversation_key_addr2(conv->key_ptr), &pinfo->dst) &&
conversation_key_port1(conv->key_ptr) == pinfo->srcport &&
conversation_key_port2(conv->key_ptr) == pinfo->destport) ? 0 : 1;
dissect_rtmpt_common(tvb, pinfo, tree, rconv, cdir, tcpinfo->seq, tcpinfo->lastackseq);
return tvb_reported_length(tvb);
}
static int
dissect_rtmpt_http(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
conversation_t *conv;
rtmpt_conv_t *rconv;
int cdir;
uint32_t seq;
uint32_t lastackseq;
uint32_t offset;
int remain;
offset = 0;
remain = tvb_reported_length_remaining(tvb, 0);
/*
* Request flow:
*
* POST /open/1
* request body is a single non-RTMP byte
* response contains a client ID <cid> followed by NL
* POST /send/<cid>/<seq>
* <seq> starts at 0 after open and increments on each
* subsequent post
* request body is pure RTMP data
* response is a single non-RTMP byte followed by RTMP data
* POST /idle/<cid>/<seq>
* request contains a single non-RTMP byte
* response is a single non-RTMP byte followed by RTMP data
* POST /close/<cid>/<seq>
* request and response contain a single non-RTMP byte
*
* Ideally here we'd know:
*
* 1) Whether this is was a HTTP request or response
* (this gives us cdir directly)
* 2) The requested URL (for both cases)
* (this tells us the type of framing bytes present,
* so whether there are any real bytes present). We
* could also use the client ID to identify the
* conversation, since each POST is likely to be on
* a different TCP connection, and there could be
* multiple simultaneous sessions from a single
* client (which we don't deal with here.)
*
* As it is, we currently have to just guess, and are
* likely easily confused.
*/
cdir = pinfo->srcport == pinfo->match_uint;
if (cdir) {
conv = find_conversation(pinfo->num, &pinfo->dst, &pinfo->src, conversation_pt_to_conversation_type(pinfo->ptype), 0, pinfo->srcport, 0);
if (!conv) {
ws_debug("RTMPT new conversation");
conv = conversation_new(pinfo->num, &pinfo->dst, &pinfo->src, conversation_pt_to_conversation_type(pinfo->ptype), 0, pinfo->srcport, 0);
}
} else {
conv = find_conversation(pinfo->num, &pinfo->src, &pinfo->dst, conversation_pt_to_conversation_type(pinfo->ptype), 0, pinfo->destport, 0);
if (!conv) {
ws_debug("RTMPT new conversation");
conv = conversation_new(pinfo->num, &pinfo->src, &pinfo->dst, conversation_pt_to_conversation_type(pinfo->ptype), 0, pinfo->destport, 0);
}
}
rconv = (rtmpt_conv_t*)conversation_get_proto_data(conv, proto_rtmpt);
if (!rconv) {
rconv = rtmpt_init_rconv(conv);
}
/* Work out a TCP-like sequence numbers for the tunneled data stream.
* If we've seen the packet before we'll have stored the seq of our
* last byte against the frame number - since we know how big we are
* we can work out the seq of our first byte. If this is the first
* time, we use the stored seq of the last byte of the previous frame
* plus one. If there is no previous frame then we must be at seq=1!
* (This is per-conversation and per-direction, of course.) */
lastackseq = GPOINTER_TO_INT(wmem_tree_lookup32_le(rconv->seqs[cdir ^ 1], pinfo->num))+1;
if (cdir == 1 && lastackseq < 2 && remain == 17) {
/* Session startup: the client makes an /open/ request and
* the server responds with a 16 bytes client
* identifier followed by a newline */
offset += 17;
remain -= 17;
} else if (cdir || remain == 1) {
/* All other server responses start with one byte which
* is not part of the RTMP stream. Client /idle/ requests
* contain a single byte also not part of the stream. We
* must discard these */
offset++;
remain--;
}
seq = GPOINTER_TO_INT(wmem_tree_lookup32(rconv->seqs[cdir], pinfo->num));
if (seq == 0) {
seq = GPOINTER_TO_INT(wmem_tree_lookup32_le(rconv->seqs[cdir], pinfo->num));
seq += remain;
wmem_tree_insert32(rconv->seqs[cdir], pinfo->num, GINT_TO_POINTER(seq));
}
seq -= remain-1;
ws_debug("RTMPT f=%d cdir=%d seq=%d lastackseq=%d len=%d", pinfo->num, cdir, seq, lastackseq, remain);
if (remain < 1)
return offset;
if (offset > 0) {
tvbuff_t *tvbrtmp = tvb_new_subset_length(tvb, offset, remain);
dissect_rtmpt_common(tvbrtmp, pinfo, tree, rconv, cdir, seq, lastackseq);
} else {
dissect_rtmpt_common(tvb, pinfo, tree, rconv, cdir, seq, lastackseq);
}
return tvb_captured_length(tvb);
}
static bool
dissect_rtmpt_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
conversation_t *conversation;
if (tvb_reported_length(tvb) >= 12)
{
/* To avoid a too high rate of false positive, this heuristics only matches the protocol
from the first server response packet and not from the client request packets before.
Therefore it is necessary to a "Decode as" to properly decode the first packets */
struct tcpinfo *tcpinfo = (struct tcpinfo *)data;
if (tcpinfo->lastackseq == RTMPT_HANDSHAKE_OFFSET_2
&& tcpinfo->seq == RTMPT_HANDSHAKE_OFFSET_1
&& tvb_get_uint8(tvb, 0) == RTMPT_MAGIC)
{
/* Register this dissector for this conversation */
conversation = find_or_create_conversation(pinfo);
conversation_set_dissector(conversation, rtmpt_tcp_handle);
/* Dissect the packet */
dissect_rtmpt_tcp(tvb, pinfo, tree, data);
return true;
}
}
return false;
}
static int
dissect_amf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
proto_item *ti;
proto_tree *amf_tree, *headers_tree, *messages_tree;
int offset;
unsigned header_count, message_count, i;
unsigned string_length;
unsigned header_length, message_length;
bool amf3_encoding = false;
/*
* XXX - is "application/x-amf" just AMF3?
*/
ti = proto_tree_add_item(tree, proto_amf, tvb, 0, -1, ENC_NA);
amf_tree = proto_item_add_subtree(ti, ett_amf);
offset = 0;
proto_tree_add_item(amf_tree, hf_amf_version, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
header_count = tvb_get_ntohs(tvb, offset);
proto_tree_add_item(amf_tree, hf_amf_header_count, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
if (header_count != 0) {
headers_tree = proto_tree_add_subtree(amf_tree, tvb, offset, -1, ett_amf_headers, NULL, "Headers");
for (i = 0; i < header_count; i++) {
string_length = tvb_get_ntohs(tvb, offset);
proto_tree_add_item(headers_tree, hf_amf_header_name, tvb, offset, 2, ENC_UTF_8|ENC_BIG_ENDIAN);
offset += 2 + string_length;
proto_tree_add_item(headers_tree, hf_amf_header_must_understand, tvb, offset, 1, ENC_NA);
offset += 1;
header_length = tvb_get_ntohl(tvb, offset);
if (header_length == 0xFFFFFFFF)
proto_tree_add_uint_format_value(headers_tree, hf_amf_header_length, tvb, offset, 4, header_length, "Unknown");
else
proto_tree_add_item(headers_tree, hf_amf_header_length, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
if (amf3_encoding)
offset = dissect_amf3_value_type(tvb, pinfo, offset, headers_tree, NULL);
else
offset = dissect_amf0_value_type(tvb, pinfo, offset, headers_tree, &amf3_encoding, NULL);
}
}
message_count = tvb_get_ntohs(tvb, offset);
proto_tree_add_item(amf_tree, hf_amf_message_count, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
if (message_count != 0) {
messages_tree = proto_tree_add_subtree(amf_tree, tvb, offset, -1, ett_amf_messages, NULL, "Messages");
for (i = 0; i < message_count; i++) {
string_length = tvb_get_ntohs(tvb, offset);
proto_tree_add_item(messages_tree, hf_amf_message_target_uri, tvb, offset, 2, ENC_UTF_8|ENC_BIG_ENDIAN);
offset += 2 + string_length;
string_length = tvb_get_ntohs(tvb, offset);
proto_tree_add_item(messages_tree, hf_amf_message_response_uri, tvb, offset, 2, ENC_UTF_8|ENC_BIG_ENDIAN);
offset += 2 + string_length;
message_length = tvb_get_ntohl(tvb, offset);
if (message_length == 0xFFFFFFFF)
proto_tree_add_uint_format_value(messages_tree, hf_amf_message_length, tvb, offset, 4, message_length, "Unknown");
else
proto_tree_add_item(messages_tree, hf_amf_message_length, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
offset = dissect_rtmpt_body_command(tvb, pinfo, offset, messages_tree, false);
}
}
return tvb_captured_length(tvb);
}
void
proto_register_rtmpt(void)
{
static hf_register_info hf[] = {
/* RTMP Handshake data */
{ &hf_rtmpt_handshake_c0,
{ "Protocol version", "rtmpt.handshake.c0", FT_BYTES, BASE_NONE,
NULL, 0x0, "RTMPT Handshake C0", HFILL }},
{ &hf_rtmpt_handshake_s0,
{ "Protocol version", "rtmpt.handshake.s0", FT_BYTES, BASE_NONE,
NULL, 0x0, "RTMPT Handshake S0", HFILL }},
{ &hf_rtmpt_handshake_c1,
{ "Handshake data", "rtmpt.handshake.c1", FT_BYTES, BASE_NONE,
NULL, 0x0, "RTMPT Handshake C1", HFILL }},
{ &hf_rtmpt_handshake_s1,
{ "Handshake data", "rtmpt.handshake.s1", FT_BYTES, BASE_NONE,
NULL, 0x0, "RTMPT Handshake S1", HFILL }},
{ &hf_rtmpt_handshake_c2,
{ "Handshake data", "rtmpt.handshake.c2", FT_BYTES, BASE_NONE,
NULL, 0x0, "RTMPT Handshake C2", HFILL }},
{ &hf_rtmpt_handshake_s2,
{ "Handshake data", "rtmpt.handshake.s2", FT_BYTES, BASE_NONE,
NULL, 0x0, "RTMPT Handshake S2", HFILL }},
/* RTMP chunk/packet header */
{ &hf_rtmpt_header_format,
{ "Format", "rtmpt.header.format", FT_UINT8, BASE_DEC,
NULL, 0xC0, "RTMPT Basic Header format", HFILL }},
{ &hf_rtmpt_header_csid,
{ "Chunk Stream ID", "rtmpt.header.csid", FT_UINT8, BASE_DEC,
NULL, 0x3F, "RTMPT Basic Header chunk stream ID", HFILL }},
{ &hf_rtmpt_header_timestamp,
{ "Timestamp", "rtmpt.header.timestamp", FT_UINT24, BASE_DEC,
NULL, 0x0, "RTMPT Message Header timestamp", HFILL }},
{ &hf_rtmpt_header_timestamp_delta,
{ "Timestamp delta", "rtmpt.header.timestampdelta", FT_UINT24, BASE_DEC,
NULL, 0x0, "RTMPT Message Header timestamp delta", HFILL }},
{ &hf_rtmpt_header_body_size,
{ "Body size", "rtmpt.header.bodysize", FT_UINT24, BASE_DEC,
NULL, 0x0, "RTMPT Message Header body size", HFILL }},
{ &hf_rtmpt_header_typeid,
{ "Type ID", "rtmpt.header.typeid", FT_UINT8, BASE_HEX,
VALS(rtmpt_opcode_vals), 0x0, "RTMPT Message Header type ID", HFILL }},
{ &hf_rtmpt_header_streamid,
{ "Stream ID", "rtmpt.header.streamid", FT_UINT32, BASE_DEC,
NULL, 0x0, "RTMPT Header stream ID", HFILL }},
{ &hf_rtmpt_header_ets,
{ "Extended timestamp", "rtmpt.header.ets", FT_UINT24, BASE_DEC,
NULL, 0x0, "RTMPT Message Header extended timestamp", HFILL }},
/* Stream Control Messages */
{ &hf_rtmpt_scm_chunksize,
{ "Chunk size", "rtmpt.scm.chunksize", FT_UINT32, BASE_DEC,
NULL, 0x0, "RTMPT SCM chunk size", HFILL }},
{ &hf_rtmpt_scm_csid,
{ "Chunk stream ID", "rtmpt.scm.csid", FT_UINT32, BASE_DEC,
NULL, 0x0, "RTMPT SCM chunk stream ID", HFILL }},
{ &hf_rtmpt_scm_seq,
{ "Sequence number", "rtmpt.scm.seq", FT_UINT32, BASE_DEC,
NULL, 0x0, "RTMPT SCM acknowledgement sequence number", HFILL }},
{ &hf_rtmpt_scm_was,
{ "Window acknowledgement size", "rtmpt.scm.was", FT_UINT32, BASE_DEC,
NULL, 0x0, "RTMPT SCM window acknowledgement size", HFILL }},
{ &hf_rtmpt_scm_limittype,
{ "Limit type", "rtmpt.scm.limittype", FT_UINT8, BASE_DEC,
VALS(rtmpt_limit_vals), 0x0, "RTMPT SCM window acknowledgement size", HFILL }},
/* User Control Messages */
{ &hf_rtmpt_ucm_eventtype,
{ "Event type", "rtmpt.ucm.eventtype", FT_UINT16, BASE_DEC,
VALS(rtmpt_ucm_vals), 0x0, "RTMPT UCM event type", HFILL }},
/* Frame links */
{ &hf_rtmpt_function_call,
{ "Response to this call in frame", "rtmpt.function.call", FT_FRAMENUM, BASE_NONE,
NULL, 0x0, "RTMPT function call", HFILL }},
{ &hf_rtmpt_function_response,
{ "Call for this response in frame", "rtmpt.function.response", FT_FRAMENUM, BASE_NONE,
NULL, 0x0, "RTMPT function response", HFILL }},
/* Audio packets */
{ &hf_rtmpt_audio_control,
{ "Control", "rtmpt.audio.control", FT_UINT8, BASE_HEX,
NULL, 0x0, NULL, HFILL }},
{ &hf_rtmpt_audio_is_ex_header,
{ "IsExAudioHeader", "rtmpt.audio.is_ex_header", FT_UINT8, BASE_DEC,
NULL, 0x90, "RTMPT IsExHeader flag introduced in enhanced RTMP", HFILL } },
{ &hf_rtmpt_audio_multitrack_control,
{ "Audio multitrack control", "rtmpt.audio.multitrack.control", FT_UINT8, BASE_HEX,
NULL, 0x0, NULL, HFILL } },
{ &hf_rtmpt_audio_multitrack_type,
{ "Audio multitrack type", "rtmpt.audio.multitrack.type", FT_UINT8, BASE_HEX,
VALS(rtmpt_av_multitrack_types), 0x0f, NULL, HFILL } },
{ &hf_rtmpt_audio_multitrack_packet_type,
{ "Audio multitrack packet type", "rtmpt.audio.multitrack.track.packet_type", FT_UINT8, BASE_HEX,
VALS(rtmpt_audio_packet_types), 0xf0, NULL, HFILL } },
{ &hf_rtmpt_audio_packet_type,
{ "Audio packet type", "rtmpt.audio.packet_type", FT_UINT8, BASE_HEX,
VALS(rtmpt_audio_packet_types), 0x0f, NULL, HFILL } },
{ &hf_rtmpt_audio_fourcc,
{ "FourCC", "rtmpt.audio.fourcc", FT_STRING, BASE_NONE,
NULL, 0x0, NULL, HFILL } },
{ &hf_rtmpt_audio_track_id,
{ "Track ID", "rtmpt.audio.multitrack.track.id", FT_UINT8, BASE_DEC,
NULL, 0x0, NULL, HFILL } },
{ &hf_rtmpt_audio_track_length,
{ "Track length", "rtmpt.audio.multitrack.track.length", FT_UINT24, BASE_DEC,
NULL, 0x0, NULL, HFILL } },
{ &hf_rtmpt_audio_format,
{ "Format", "rtmpt.audio.format", FT_UINT8, BASE_DEC,
VALS(rtmpt_audio_codecs), 0xf0, NULL, HFILL }},
{ &hf_rtmpt_audio_rate,
{ "Sample rate", "rtmpt.audio.rate", FT_UINT8, BASE_DEC,
VALS(rtmpt_audio_rates), 0x0c, NULL, HFILL }},
{ &hf_rtmpt_audio_size,
{ "Sample size", "rtmpt.audio.size", FT_UINT8, BASE_DEC,
VALS(rtmpt_audio_sizes), 0x02, NULL, HFILL }},
{ &hf_rtmpt_audio_type,
{ "Channels", "rtmpt.audio.type", FT_UINT8, BASE_DEC,
VALS(rtmpt_audio_types), 0x01, NULL, HFILL }},
{ &hf_rtmpt_audio_data,
{ "Audio data", "rtmpt.audio.data", FT_BYTES, BASE_NONE,
NULL, 0x0, NULL, HFILL }},
/* Video packets */
{ &hf_rtmpt_video_control,
{ "Control", "rtmpt.video.control", FT_UINT8, BASE_HEX,
NULL, 0x0, NULL, HFILL }},
{ &hf_rtmpt_video_multitrack_control,
{ "Video multitrack control", "rtmpt.video.multitrack.control", FT_UINT8, BASE_HEX,
NULL, 0x0, NULL, HFILL }},
{ &hf_rtmpt_video_is_ex_header,
{ "IsExVideoHeader", "rtmpt.video.is_ex_header", FT_UINT8, BASE_DEC,
NULL, 0x80, "RTMPT IsExHeader flag introduced in enhanced RTMP", HFILL }},
{ &hf_rtmpt_video_type,
{ "Video type", "rtmpt.video.type", FT_UINT8, BASE_DEC,
VALS(rtmpt_video_types), 0x70, NULL, HFILL }},
{ &hf_rtmpt_video_command,
{ "Video command", "rtmpt.video.command", FT_UINT8, BASE_DEC,
VALS(rtmpt_video_commands), 0x0, NULL, HFILL}},
{ &hf_rtmpt_video_format,
{ "Format", "rtmpt.video.format", FT_UINT8, BASE_DEC,
VALS(rtmpt_video_codecs), 0x0f, NULL, HFILL }},
{ &hf_rtmpt_video_packet_type,
{ "Video packet type", "rtmpt.video.packet_type", FT_UINT8, BASE_DEC,
VALS(rtmpt_video_packet_types), 0x0f, NULL, HFILL }},
{ &hf_rtmpt_video_multitrack_type,
{ "Video multitrack type", "rtmpt.video.multitrack.type", FT_UINT8, BASE_DEC,
VALS(rtmpt_av_multitrack_types), 0xf0, NULL, HFILL } },
{ &hf_rtmpt_video_multitrack_packet_type,
{ "Video multitrack packet type", "rtmpt.video.multitrack.packet_type", FT_UINT8, BASE_DEC,
VALS(rtmpt_video_packet_types), 0x0f, NULL, HFILL } },
{ &hf_rtmpt_video_fourcc,
{ "FourCC", "rtmpt.video.fourcc", FT_STRING, BASE_NONE,
NULL, 0x0, NULL, HFILL }},
{ &hf_rtmpt_video_track_id,
{ "Track ID", "rtmpt.video.multitrack.track.id", FT_UINT8, BASE_DEC,
NULL, 0x0, NULL, HFILL } },
{ &hf_rtmpt_video_track_length,
{ "Track length", "rtmpt.video.multitrack.track.length", FT_UINT24, BASE_DEC,
NULL, 0x0, NULL, HFILL } },
{ &hf_rtmpt_video_data,
{ "Video data", "rtmpt.video.data", FT_BYTES, BASE_NONE,
NULL, 0x0, NULL, HFILL }},
/* Aggregate packets */
{ &hf_rtmpt_tag_type,
{ "Type", "rtmpt.tag.type", FT_UINT8, BASE_DEC,
VALS(rtmpt_tag_vals), 0x0, "RTMPT Aggregate tag type", HFILL }},
{ &hf_rtmpt_tag_datasize,
{ "Data size", "rtmpt.tag.datasize", FT_UINT24, BASE_DEC,
NULL, 0x0, "RTMPT Aggregate tag data size", HFILL }},
{ &hf_rtmpt_tag_timestamp,
{ "Timestamp", "rtmpt.tag.timestamp", FT_UINT24, BASE_DEC,
NULL, 0x0, "RTMPT Aggregate tag timestamp", HFILL }},
{ &hf_rtmpt_tag_ets,
{ "Timestamp Extended", "rtmpt.tag.ets", FT_UINT8, BASE_DEC,
NULL, 0x0, "RTMPT Aggregate tag timestamp extended", HFILL }},
{ &hf_rtmpt_tag_streamid,
{ "Stream ID", "rtmpt.tag.streamid", FT_UINT24, BASE_DEC,
NULL, 0x0, "RTMPT Aggregate tag stream ID", HFILL }},
{ &hf_rtmpt_tag_tagsize,
{ "Previous tag size", "rtmpt.tag.tagsize", FT_UINT32, BASE_DEC,
NULL, 0x0, "RTMPT Aggregate previous tag size", HFILL }}
};
static int *ett[] = {
&ett_rtmpt,
&ett_rtmpt_handshake,
&ett_rtmpt_header,
&ett_rtmpt_body,
&ett_rtmpt_ucm,
&ett_rtmpt_audio_control,
&ett_rtmpt_video_control,
&ett_rtmpt_audio_multitrack_control,
&ett_rtmpt_audio_multitrack_track,
&ett_rtmpt_video_multitrack_control,
&ett_rtmpt_video_multitrack_track,
&ett_rtmpt_tag,
&ett_rtmpt_tag_data
};
module_t *rtmpt_module;
proto_rtmpt = proto_register_protocol("Real Time Messaging Protocol", "RTMPT", "rtmpt");
proto_register_field_array(proto_rtmpt, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
rtmpt_tcp_handle = register_dissector("rtmpt.tcp", dissect_rtmpt_tcp, proto_rtmpt);
rtmpt_http_handle = register_dissector("rtmpt.http", dissect_rtmpt_http, proto_rtmpt);
rtmpt_module = prefs_register_protocol(proto_rtmpt, NULL);
/* XXX: This desegment preference doesn't do anything */
prefs_register_bool_preference(rtmpt_module, "desegment",
"Reassemble RTMPT messages spanning multiple TCP segments",
"Whether the RTMPT dissector should reassemble messages spanning multiple TCP segments."
" To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\""
" in the TCP protocol settings.",
&rtmpt_desegment);
prefs_register_obsolete_preference(rtmpt_module, "max_packet_size");
prefs_register_uint_preference(rtmpt_module, "default_chunk_size",
"Default chunk size",
"Chunk size to use for connections where the initial handshake is missing,"
" i.e. are already in progress at the beginning of the capture file.",
10, &rtmpt_default_chunk_size);
}
void
proto_register_amf(void)
{
static hf_register_info hf[] = {
{ &hf_amf_version,
{ "AMF version", "amf.version", FT_UINT16, BASE_DEC,
NULL, 0x0, NULL, HFILL }},
{ &hf_amf_header_count,
{ "Header count", "amf.header_count", FT_UINT16, BASE_DEC,
NULL, 0x0, NULL, HFILL }},
{ &hf_amf_header_name,
{ "Name", "amf.header.name", FT_UINT_STRING, BASE_NONE,
NULL, 0x0, NULL, HFILL }},
{ &hf_amf_header_must_understand,
{ "Must understand", "amf.header.must_understand", FT_BOOLEAN, BASE_NONE,
NULL, 0x0, NULL, HFILL }},
{ &hf_amf_header_length,
{ "Length", "amf.header.length", FT_UINT32, BASE_DEC,
NULL, 0x0, NULL, HFILL }},
#if 0
{ &hf_amf_header_value_type,
{ "Value type", "amf.header.value_type", FT_UINT32, BASE_HEX,
VALS(rtmpt_type_vals), 0x0, NULL, HFILL }},
#endif
{ &hf_amf_message_count,
{ "Message count", "amf.message_count", FT_UINT16, BASE_DEC,
NULL, 0x0, NULL, HFILL }},
{ &hf_amf_message_target_uri,
{ "Target URI", "amf.message.target_uri", FT_UINT_STRING, BASE_NONE,
NULL, 0x0, NULL, HFILL }},
{ &hf_amf_message_response_uri,
{ "Response URI", "amf.message.response_uri", FT_UINT_STRING, BASE_NONE,
NULL, 0x0, NULL, HFILL }},
{ &hf_amf_message_length,
{ "Length", "amf.message.length", FT_UINT32, BASE_DEC,
NULL, 0x0, NULL, HFILL }},
/* AMF basic types */
{ &hf_amf_amf0_type,
{ "AMF0 type", "amf.amf0_type", FT_UINT8, BASE_HEX,
VALS(amf0_type_vals), 0x0, NULL, HFILL }},
{ &hf_amf_amf3_type,
{ "AMF3 type", "amf.amf3_type", FT_UINT8, BASE_HEX,
VALS(amf3_type_vals), 0x0, NULL, HFILL }},
{ &hf_amf_number,
{ "Number", "amf.number", FT_DOUBLE, BASE_NONE,
NULL, 0x0, "AMF number", HFILL }},
{ &hf_amf_integer,
{ "Integer", "amf.integer", FT_UINT32, BASE_DEC,
NULL, 0x0, "RTMPT AMF3 integer", HFILL }},
{ &hf_amf_boolean,
{ "Boolean", "amf.boolean", FT_BOOLEAN, BASE_NONE,
NULL, 0x0, "AMF boolean", HFILL }},
{ &hf_amf_stringlength,
{ "String length", "amf.stringlength", FT_UINT32, BASE_DEC,
NULL, 0x0, "AMF string length", HFILL }},
{ &hf_amf_string,
{ "String", "amf.string", FT_STRING, BASE_NONE,
NULL, 0x0, "AMF string", HFILL }},
{ &hf_amf_string_reference,
{ "String reference", "amf.string_reference", FT_UINT32, BASE_DEC,
NULL, 0x0, "RTMPT AMF3 string reference", HFILL }},
{ &hf_amf_object_reference,
{ "Object reference", "amf.object_reference", FT_UINT32, BASE_DEC,
NULL, 0x0, "AMF object reference", HFILL }},
{ &hf_amf_date,
{ "Date", "amf.date", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
NULL, 0x0, "AMF date", HFILL }},
#if 0
{ &hf_amf_longstringlength,
{ "String length", "amf.longstringlength", FT_UINT32, BASE_DEC,
NULL, 0x0, "AMF long string length", HFILL }},
#endif
{ &hf_amf_longstring,
{ "Long string", "amf.longstring", FT_STRING, BASE_NONE,
NULL, 0x0, "AMF long string", HFILL }},
{ &hf_amf_xml_doc,
{ "XML document", "amf.xml_doc", FT_STRING, BASE_NONE,
NULL, 0x0, "AMF XML document", HFILL }},
{ &hf_amf_xmllength,
{ "XML text length", "amf.xmllength", FT_UINT32, BASE_DEC,
NULL, 0x0, "AMF E4X XML length", HFILL }},
{ &hf_amf_xml,
{ "XML", "amf.xml", FT_STRING, BASE_NONE,
NULL, 0x0, "AMF E4X XML", HFILL }},
{ &hf_amf_int64,
{ "Int64", "amf.int64", FT_INT64, BASE_DEC,
NULL, 0x0, "AMF int64", HFILL }},
{ &hf_amf_bytearraylength,
{ "ByteArray length", "amf.bytearraylength", FT_UINT32, BASE_DEC,
NULL, 0x0, "RTMPT AMF3 ByteArray length", HFILL }},
{ &hf_amf_bytearray,
{ "ByteArray", "amf.bytearray", FT_BYTES, BASE_NONE,
NULL, 0x0, "RTMPT AMF3 ByteArray", HFILL }},
/* AMF object types and subfields of the object types */
{ &hf_amf_object,
{ "Object", "amf.object", FT_NONE, BASE_NONE,
NULL, 0x0, "AMF object", HFILL }},
{ &hf_amf_traitcount,
{ "Trait count", "amf.traitcount", FT_UINT32, BASE_DEC,
NULL, 0x0, "AMF count of traits for an object", HFILL }},
{ &hf_amf_classnamelength,
{ "Class name length", "amf.classnamelength", FT_UINT32, BASE_DEC,
NULL, 0x0, "AMF class name length", HFILL }},
{ &hf_amf_classname,
{ "Class name", "amf.classname", FT_STRING, BASE_NONE,
NULL, 0x0, "AMF class name", HFILL }},
{ &hf_amf_membernamelength,
{ "Member name length", "amf.membernamelength", FT_UINT32, BASE_DEC,
NULL, 0x0, "AMF member name length", HFILL }},
{ &hf_amf_membername,
{ "Member name", "amf.membername", FT_STRING, BASE_NONE,
NULL, 0x0, "AMF member name", HFILL }},
{ &hf_amf_trait_reference,
{ "Trait reference", "amf.trait_reference", FT_UINT32, BASE_DEC,
NULL, 0x0, "AMF trait reference", HFILL }},
{ &hf_amf_ecmaarray,
{ "ECMA array", "amf.ecmaarray", FT_NONE, BASE_NONE,
NULL, 0x0, "AMF ECMA array", HFILL }},
{ &hf_amf_strictarray,
{ "Strict array", "amf.strictarray", FT_NONE, BASE_NONE,
NULL, 0x0, "AMF strict array", HFILL }},
{ &hf_amf_array,
{ "Array", "amf.array", FT_NONE, BASE_NONE,
NULL, 0x0, "RTMPT AMF3 array", HFILL }},
{ &hf_amf_arraylength,
{ "Array length", "amf.arraylength", FT_UINT32, BASE_DEC,
NULL, 0x0, "AMF array length", HFILL }},
{ &hf_amf_arraydenselength,
{ "Length of dense portion", "amf.arraydenselength", FT_UINT32, BASE_DEC,
NULL, 0x0, "AMF length of dense portion of array", HFILL }},
{ &hf_amf_end_of_object_marker,
{ "End Of Object Marker", "amf.end_of_object_marker", FT_NONE, BASE_NONE,
NULL, 0x0, NULL, HFILL }},
{ &hf_amf_end_of_associative_part,
{ "End of associative part", "amf.end_of_associative_part", FT_NONE, BASE_NONE,
NULL, 0x0, NULL, HFILL }},
{ &hf_amf_end_of_dynamic_members,
{ "End Of dynamic members", "amf.end_of_dynamic_members", FT_NONE, BASE_NONE,
NULL, 0x0, NULL, HFILL }},
};
static ei_register_info ei[] = {
{ &ei_amf_loop, { "amf.loop", PI_MALFORMED, PI_ERROR, "Loop in AMF dissection", EXPFILL }}
};
static int *ett[] = {
&ett_amf,
&ett_amf_headers,
&ett_amf_messages,
&ett_amf_value,
&ett_amf_property,
&ett_amf_string,
&ett_amf_array_element,
&ett_amf_traits,
&ett_amf_trait_member,
};
expert_module_t* expert_amf;
proto_amf = proto_register_protocol("Action Message Format", "AMF", "amf");
proto_register_field_array(proto_amf, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
expert_amf = expert_register_protocol(proto_amf);
expert_register_field_array(expert_amf, ei, array_length(ei));
amf_handle = register_dissector("amf", dissect_amf, proto_amf);
}
void
proto_reg_handoff_rtmpt(void)
{
heur_dissector_add("tcp", dissect_rtmpt_heur, "RTMPT over TCP", "rtmpt_tcp", proto_rtmpt, HEURISTIC_DISABLE);
dissector_add_uint_with_preference("tcp.port", RTMP_PORT, rtmpt_tcp_handle);
dissector_add_string("media_type", "application/x-fcs", rtmpt_http_handle);
dissector_add_string("media_type", "application/x-amf", amf_handle);
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 8
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=8 tabstop=8 expandtab:
* :indentSize=8:tabSize=8:noTabs=true:
*/
|