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 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854
|
#!/usr/bin/env python3
"""
This application is designed to decode timestamps into human-readable date/times and vice-versa
Additional information regarding the source of the timestamp formats and associated equations
is provided in the REFERENCES.md file at https://github.com/digitalsleuth/time_decode.
"""
from datetime import datetime as dt, timedelta, timezone
import struct
from string import hexdigits, ascii_lowercase
import argparse
import inspect
import math
import re
import sys
import os
import base64
import uuid
import traceback
import warnings
import csv
from calendar import monthrange, IllegalMonthError
from typing import NamedTuple
from zoneinfo import ZoneInfo as tzone
from zoneinfo import available_timezones
import juliandate as jd
from colorama import init
import blackboxprotobuf
from blackboxprotobuf.lib.exceptions import DecoderException
from ulid import ULID
from prettytable import PrettyTable, TableStyle
from PyQt6.QtCore import (
QRect,
Qt,
QMetaObject,
QCoreApplication,
QDate,
QSize,
)
from PyQt6.QtGui import (
QAction,
QPixmap,
QIcon,
QFont,
QKeySequence,
QColor,
)
from PyQt6.QtWidgets import (
QWidget,
QVBoxLayout,
QHBoxLayout,
QGridLayout,
QLabel,
QLineEdit,
QDateTimeEdit,
QComboBox,
QPushButton,
QRadioButton,
QApplication,
QMenu,
QMessageBox,
QTableWidget,
QTableWidgetItem,
QSizePolicy,
QMainWindow,
QStyle,
QFileDialog,
)
warnings.filterwarnings("ignore", category=DeprecationWarning)
init(autoreset=True)
__author__ = "Corey Forman (digitalsleuth)"
__date__ = "2026-01-21"
__version__ = "10.3.1"
__description__ = "Python 3 Date Time Conversion Tool"
__fmt__ = "%Y-%m-%d %H:%M:%S.%f"
__red__ = "\033[1;31m"
__clr__ = "\033[1;m"
__source__ = "https://github.com/digitalsleuth/time_decode"
__appname__ = f"Time Decode v{__version__}"
class NewWindow(QWidget):
"""This class sets the structure for a new window"""
def __init__(self, parent=None):
"""Sets up the new window table and context menu"""
super().__init__(parent)
if parent:
self.setPalette(parent.palette())
self.setFont(parent.font())
self.setStyleSheet("background-color: white;")
layout = QVBoxLayout(self)
self.window_label = QLabel(self)
self.output_table = QTableWidget(self)
self.output_table.setSizePolicy(
QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding
)
self.output_table.setStyleSheet(
"border: none; selection-background-color: #1644b9;"
)
self.output_table.setVerticalScrollBarPolicy(
Qt.ScrollBarPolicy.ScrollBarAsNeeded
)
self.context_menu = ContextMenu(self.output_table)
self.output_table.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
self.output_table.customContextMenuRequested.connect(
self.context_menu.show_context_menu
)
layout.addWidget(self.output_table)
layout.addWidget(self.window_label)
self.stylesheet = TimeDecodeGui.stylesheet
self.setLayout(layout)
def key_press_event(self, event):
"""Sets the Ctrl+C KeyPress for the window"""
if event.matches(QKeySequence.StandardKey.Copy):
self.context_menu.copy()
else:
super().key_press_event(event)
class CsvWindow(QWidget):
"""This class sets the structure for a new window"""
def __init__(
self,
ts_formats: QComboBox,
time_zones: QComboBox,
dt_formats: QComboBox,
parent=None,
):
"""Sets up the new window table and context menu"""
super().__init__(parent)
if parent:
self.setPalette(parent.palette())
self.setFont(parent.font())
self.window_label = QLabel(self)
self.output_table = QTableWidget(self)
self.ts_formats = QComboBox(self)
self.time_zones = QComboBox(self)
self.dt_formats = QComboBox(self)
for i in range(ts_formats.count()):
self.ts_formats.addItem(ts_formats.itemText(i), ts_formats.itemData(i))
for i in range(time_zones.count()):
self.time_zones.addItem(time_zones.itemText(i), time_zones.itemData(i))
for i in range(dt_formats.count()):
self.dt_formats.addItem(dt_formats.itemText(i), dt_formats.itemData(i))
self.output_table.setSizePolicy(
QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding
)
self.output_table.setVerticalScrollBarPolicy(
Qt.ScrollBarPolicy.ScrollBarAsNeeded
)
class AboutWindow(QWidget):
"""Sets the structure for the About window"""
def __init__(self):
super().__init__()
layout = QGridLayout()
self.about_label = QLabel()
self.url_label = QLabel()
self.logo_label = QLabel()
spacer = QLabel()
layout.addWidget(self.about_label, 0, 0)
layout.addWidget(spacer, 0, 1)
layout.addWidget(self.url_label, 1, 0)
layout.addWidget(self.logo_label, 0, 2)
self.setStyleSheet("background-color: white; color: black;")
self.setFixedHeight(100)
self.setFixedWidth(350)
self.setLayout(layout)
class ContextMenu:
"""Shows a context menu for a QTableWidget"""
def __init__(self, tbl_widget):
"""Associate the tbl_widget variable"""
self.tbl_widget = tbl_widget
def show_context_menu(self, pos):
"""Sets the context menu structure and style"""
stylesheet = TimeDecodeGui.stylesheet
context_menu = QMenu(self.tbl_widget)
copy_event = context_menu.addAction("Copy")
copy_event.setShortcut(QKeySequence("Ctrl+C"))
copy_event.setShortcutVisibleInContextMenu(True)
context_menu.setStyleSheet(stylesheet)
copy_event.triggered.connect(self.copy)
context_menu.exec(self.tbl_widget.mapToGlobal(pos))
def copy(self):
"""Sets up the Copy option for the context menu"""
selected = self.tbl_widget.selectedItems()
if selected:
clipboard = QApplication.clipboard()
text = (
"\n".join(
[
"\t".join(
[
item.text()
for item in self.tbl_widget.selectedItems()
if item.row() == row
]
)
for row in range(self.tbl_widget.rowCount())
]
)
).rstrip()
text = text.lstrip()
clipboard.setText(text)
class UiMainWindow:
"""Sets the structure for the main user interface"""
def __init__(self):
super().__init__()
self.window_width = 490
self.window_height = 130
self.text_font = QFont()
self.text_font.setPointSize(9)
self.results = {}
self.examples_window = None
self.new_window = None
self.timestamp_text = None
self.date_time = None
self.now_button = None
self.update_button = None
self.button_layout = None
self.calendar_buttons = None
self.timestamp_formats = None
self.time_zone_offsets = None
self.output_table = None
self.context_menu = None
self.guess_button = None
self.to_all_button = None
self.encode_radio = None
self.decode_radio = None
self.go_button = None
self.new_window_button = None
self.menu_bar = None
self.file_menu = None
self.exit_action = None
self.view_menu = None
self.view_action = None
self.help_menu = None
self.about_action = None
self.msg_box = None
self.about_window = None
self.logo = None
self.timestamp_count_label = None
self.dt_format_combo = None
self.decode_from_file_button = None
self.selected_header = None
self.csv_path = None
self.csv_content_window = None
self.csv_go_button = None
self.csv_decode_action = None
self.select_new_csv = None
self.csv_close_button = None
self.screen_layout = QApplication.primaryScreen().availableGeometry()
self.center_x = (self.screen_layout.width() // 2) - (self.window_width // 2)
self.center_y = (self.screen_layout.height() // 2) - (self.window_height // 2)
def setup_ui(self, main_window):
"""Sets up the core UI"""
if not main_window.objectName():
main_window.setObjectName(__appname__)
main_window.setFixedWidth(self.window_width)
main_window.setMinimumHeight(self.window_height)
main_window.setStyleSheet(main_window.stylesheet)
main_window.setSizePolicy(
QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding
)
main_window.setWindowFlags(
main_window.windowFlags() & ~Qt.WindowType.WindowMaximizeButtonHint
)
main_window.move(self.center_x, self.center_y)
self.timestamp_text = QLineEdit(main_window)
self.timestamp_text.setObjectName("timestamp_text")
self.timestamp_text.setGeometry(QRect(10, 30, 225, 22))
self.timestamp_text.setHidden(False)
self.timestamp_text.setEnabled(True)
self.timestamp_text.setStyleSheet(main_window.stylesheet)
self.timestamp_text.setFont(self.text_font)
self.timestamp_text.setToolTip(
"Enter your timestamp. To verify your timestamp format, select 'View -> Examples'."
)
utc_time = dt.now(timezone.utc)
self.date_time = QDateTimeEdit(main_window)
self.date_time.setObjectName("date_time")
self.date_time.setDisplayFormat("yyyy-MM-dd HH:mm:ss.zzz")
self.date_time.setGeometry(QRect(10, 30, 225, 22))
self.date_time.setDateTime(utc_time)
self.date_time.setCalendarPopup(True)
self.date_time.calendarWidget().setFixedHeight(220)
self.date_time.calendarWidget().setGridVisible(True)
self.date_time.setHidden(True)
self.date_time.setEnabled(False)
self.date_time.setStyleSheet(main_window.stylesheet)
self.date_time.calendarWidget().setStyleSheet(
"alternate-background-color: #EAF6FF; background-color: white; color: black;"
)
self.date_time.setFont(self.text_font)
self.date_time.calendarWidget().setFont(self.text_font)
self.date_time.setToolTip(
"Enter your date/time as 'YYYY-mm-dd HH:MM:SS.fff' and only 3 digits for milliseconds."
)
self.now_button = QPushButton("&Now", clicked=self.set_now)
self.now_button.setFont(self.text_font)
self.update_button = QPushButton(
"&Update Time Zones", clicked=self.update_timezones
)
self.update_button.setFont(self.text_font)
self.button_layout = QHBoxLayout()
self.button_layout.addWidget(self.now_button)
self.button_layout.addWidget(self.update_button)
self.calendar_buttons = self.date_time.calendarWidget().layout()
self.calendar_buttons.addLayout(self.button_layout)
self.timestamp_formats = QComboBox(main_window)
self.timestamp_formats.setObjectName("timestamp_formats")
self.timestamp_formats.setGeometry(QRect(10, 60, 225, 22))
self.timestamp_formats.setStyleSheet(
"combobox-popup: 0; background-color: white; color: black;"
)
self.timestamp_formats.view().setVerticalScrollBarPolicy(
Qt.ScrollBarPolicy.ScrollBarAsNeeded
)
self.timestamp_formats.setFont(self.text_font)
types = {}
for _, this_type in ts_types.items():
types[this_type[0]] = this_type[1]
types = dict(sorted(types.items(), key=lambda item: item[0].casefold()))
for k, v in enumerate(types.items()):
self.timestamp_formats.addItem(v[0])
self.timestamp_formats.setItemData(k, v[1], Qt.ItemDataRole.ToolTipRole)
self.time_zone_offsets = QComboBox(main_window)
self.time_zone_offsets.setObjectName("time_zone_offsets")
self.time_zone_offsets.setGeometry(QRect(10, 90, 305, 22))
self.time_zone_offsets.setStyleSheet(
"combobox-popup: 0; background-color: white; color: black;"
)
self.time_zone_offsets.view().setVerticalScrollBarPolicy(
Qt.ScrollBarPolicy.ScrollBarAsNeeded
)
self.time_zone_offsets.setFont(self.text_font)
try:
dt_obj = dt.fromisoformat(self.date_time.text()).replace(
tzinfo=timezone.utc
)
except ValueError:
dt_obj = dt.strptime(self.date_time.text(), __fmt__).replace(
tzinfo=timezone.utc
)
ts_offsets = common_timezone_offsets(dt_obj)
for k, v in enumerate(ts_offsets):
self.time_zone_offsets.addItem(f"{v[0]} {v[1]}")
self.time_zone_offsets.setItemData(k, v[1], Qt.ItemDataRole.ToolTipRole)
self.time_zone_offsets.setEnabled(True)
self.time_zone_offsets.setHidden(False)
tz_tooltip = (
"Time Zones in the drop-down box are displayed based on the current date/time.\n"
"The actual UTC Offset (whether observing DST or not) will be calculated\naccordingly"
" when generating output.\n\n"
"For example: Europe/Amsterdam time zone is UTC+01:00 before 29 March 2026 at 2AM,\n"
"then it is UTC+02:00 until 29 October 2026 at 3AM.\n\n"
"If YOUR current date/time falls between these two times, the time zone will display "
"UTC+02:00.\n"
"Otherwise, it will display UTC+01:00.\n\nThe output will adjust based on the date/time"
" value provided or determined."
)
self.time_zone_offsets.setToolTip(tz_tooltip)
self.output_table = QTableWidget(main_window)
self.output_table.setSizePolicy(
QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding
)
self.output_table.setGeometry(QRect(10, 120, 440, 22))
self.output_table.setStyleSheet(
"border: none; background-color: white; color: black; font-size: 10;"
)
self.output_table.setVisible(False)
self.output_table.setVerticalScrollBarPolicy(
Qt.ScrollBarPolicy.ScrollBarAlwaysOn
)
self.output_table.setHorizontalScrollBarPolicy(
Qt.ScrollBarPolicy.ScrollBarAlwaysOff
)
self.context_menu = ContextMenu(self.output_table)
self.output_table.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
self.output_table.customContextMenuRequested.connect(
self.context_menu.show_context_menu
)
self.output_table.setFont(self.text_font)
self.guess_button = QPushButton(main_window)
self.guess_button.setObjectName("guess_button")
self.guess_button.setEnabled(True)
self.guess_button.setHidden(False)
self.guess_button.setGeometry(QRect(245, 30, 70, 22))
self.guess_button.setStyleSheet("background-color: white; color: black;")
self.guess_button.setFont(self.text_font)
self.guess_button.clicked.connect(self.guess_decode)
self.guess_button.setToolTip(
"Run the current timestamp through all functions to 'Guess' the format."
)
self.to_all_button = QPushButton(main_window)
self.to_all_button.setObjectName("to_all_button")
self.to_all_button.setEnabled(False)
self.to_all_button.setHidden(True)
self.to_all_button.setGeometry(QRect(245, 30, 70, 22))
self.to_all_button.setStyleSheet("background-color: white; color: black;")
self.to_all_button.setFont(self.text_font)
self.to_all_button.clicked.connect(self.encode_toall)
self.to_all_button.setToolTip(
"Convert the selected date/time value to all timestamp formats."
)
self.encode_radio = QRadioButton(main_window)
self.encode_radio.setObjectName("encode_radio")
self.encode_radio.setGeometry(QRect(400, 30, 72, 20))
self.encode_radio.setStyleSheet("background-color: white; color: black;")
self.encode_radio.setFont(self.text_font)
self.encode_radio.toggled.connect(self._encode_select)
self.decode_radio = QRadioButton(main_window)
self.decode_radio.setObjectName("decode_radio")
self.decode_radio.setGeometry(QRect(325, 30, 72, 20))
self.decode_radio.setChecked(True)
self.decode_radio.setStyleSheet("background-color: white; color: black;")
self.decode_radio.setFont(self.text_font)
self.decode_radio.toggled.connect(self._decode_select)
self.decode_from_file_button = QPushButton(main_window)
self.decode_from_file_button.setObjectName("decode_from_file_button")
self.decode_from_file_button.setEnabled(True)
self.decode_from_file_button.setHidden(False)
self.decode_from_file_button.setGeometry(QRect(322, 60, 72, 22))
self.decode_from_file_button.setStyleSheet(
"background-color: white; color: black;"
)
self.decode_from_file_button.setFont(self.text_font)
self.decode_from_file_button.clicked.connect(self.csv_decode)
self.decode_from_file_button.setToolTip(
"Decode timestamps from a CSV/TXT file."
)
self.dt_format_combo = QComboBox(main_window)
self.dt_format_combo.setObjectName("dt_format_combo")
self.dt_format_combo.setEnabled(True)
self.dt_format_combo.setHidden(False)
self.dt_format_combo.setFont(self.text_font)
self.dt_format_combo.setGeometry(QRect(400, 60, 70, 22))
for k, v in enumerate(date_formats.items()):
self.dt_format_combo.addItem(f"{v[0]}")
self.dt_format_combo.setItemData(
k, v[1].replace("%", ""), Qt.ItemDataRole.ToolTipRole
)
self.dt_format_combo.setStyleSheet("background-color: white; color: black;")
self.dt_format_combo.setToolTip("Choose your desired date/time format.")
self.go_button = QPushButton(main_window)
self.go_button.setObjectName("go_button")
self.go_button.setGeometry(QRect(245, 60, 70, 22))
self.go_button.setStyleSheet("background-color: white; color: black;")
self.go_button.setFont(self.text_font)
self.go_button.clicked.connect(self.go_function)
self.go_button.setToolTip("Convert to/from the timestamp selected to the left.")
new_window_pixmap = QStyle.StandardPixmap.SP_ArrowUp
icon = main_window.style().standardIcon(new_window_pixmap)
self.new_window_button = QPushButton(main_window)
self.new_window_button.setObjectName("new_window_button")
self.new_window_button.setGeometry(QRect(325, 90, 22, 22))
self.new_window_button.setStyleSheet(
"background-color: white; color: black; border: 0;"
)
self.new_window_button.setFont(self.text_font)
self.new_window_button.setIcon(icon)
self.new_window_button.setIconSize(QSize(22, 22))
self.new_window_button.setToolTip("Open results in a new window")
self.new_window_button.clicked.connect(self._new_window)
if os.sys.platform == "linux":
vert = 415
else:
vert = 370
self.timestamp_count_label = QLabel(main_window)
self.timestamp_count_label.setGeometry(QRect(vert, 94, 90, 22))
self.timestamp_count_label.setStyleSheet(
"background-color: white; color: black;"
)
self.timestamp_count_label.setFont(self.text_font)
self.timestamp_count_label.setAlignment(Qt.AlignmentFlag.AlignRight)
self.retranslate_ui(main_window)
QMetaObject.connectSlotsByName(main_window)
def retranslate_ui(self, main_window):
"""Retranslate the Ui"""
_translate = QCoreApplication.translate
main_window.setWindowTitle(_translate("main_window", __appname__, None))
self.date_time.setDisplayFormat(
_translate("main_window", "yyyy-MM-dd HH:mm:ss.zzz", None)
)
self.timestamp_text.setPlaceholderText(
_translate("main_window", "Timestamp", None)
)
self.guess_button.setText(_translate("main_window", "Guess", None))
self.to_all_button.setText(_translate("main_window", "To All", None))
self.encode_radio.setText(_translate("main_window", "Encode", None))
self.decode_radio.setText(_translate("main_window", "Decode", None))
self.go_button.setText(_translate("main_window", "\u2190 From", None))
self.decode_from_file_button.setText(
_translate("main_window", "From file..", None)
)
self.new_window_button.setHidden(True)
self.new_window_button.setEnabled(False)
self._menu_bar()
def set_now(self):
"""Sets the current date / time on the Calendar Widget"""
today = QDate().currentDate()
now = dt.now(timezone.utc)
self.date_time.calendarWidget().setSelectedDate(today)
self.date_time.setDateTime(now)
def update_timezones(self):
"""Updates the time_zone_offsets combo box to reflect the selected Calendar date/time"""
try:
dt_obj = dt.fromisoformat(self.date_time.text()).replace(
tzinfo=timezone.utc
)
except ValueError:
dt_obj = dt.strptime(self.date_time.text(), __fmt__).replace(
tzinfo=timezone.utc
)
ts_offsets = common_timezone_offsets(dt_obj)
self.time_zone_offsets.clear()
for k, v in enumerate(ts_offsets):
self.time_zone_offsets.addItem(f"{v[0]} {v[1]}")
self.time_zone_offsets.setItemData(k, v[1], Qt.ItemDataRole.ToolTipRole)
def _decode_select(self):
"""Sets the structure for the decode radio button"""
self.date_time.setHidden(True)
self.date_time.setEnabled(False)
self.timestamp_text.setHidden(False)
self.timestamp_text.setEnabled(True)
self.guess_button.setEnabled(True)
self.guess_button.setHidden(False)
self.to_all_button.setEnabled(False)
self.to_all_button.setHidden(True)
self.go_button.setText("\u2190 From")
self.new_window_button.setHidden(True)
self.new_window_button.setEnabled(False)
self.timestamp_count_label.setText("")
self.decode_from_file_button.setEnabled(True)
self.decode_from_file_button.setHidden(False)
self.dt_format_combo.setEnabled(True)
self.dt_format_combo.setHidden(False)
self._reset_table()
def _encode_select(self):
"""Sets the structure for the encode radio button"""
self.timestamp_text.setHidden(True)
self.timestamp_text.setEnabled(False)
self.date_time.setHidden(False)
self.date_time.setEnabled(True)
self.guess_button.setEnabled(False)
self.guess_button.setHidden(True)
self.to_all_button.setEnabled(True)
self.to_all_button.setHidden(False)
self.go_button.setText("\u2190 To")
self.new_window_button.setHidden(True)
self.new_window_button.setEnabled(False)
self.timestamp_count_label.setText("")
self.decode_from_file_button.setEnabled(False)
self.decode_from_file_button.setHidden(True)
self.dt_format_combo.setEnabled(False)
self.dt_format_combo.setHidden(True)
self._reset_table()
def _reset_table(self):
"""Resets the GUI structure"""
self.adjustSize()
self.setFixedWidth(490)
self.setFixedHeight(130)
self.output_table.setVisible(False)
self.output_table.clearContents()
self.output_table.setColumnCount(0)
self.output_table.setRowCount(0)
self.output_table.reset()
self.output_table.setStyleSheet("border: none")
def guess_decode(self):
"""Will take the provided timestamp and run it through the 'from_all' function"""
timestamp = self.timestamp_text.text()
selected_tz = self.time_zone_offsets.currentText()
tz_name = " ".join(selected_tz.split(" ")[1:])
if timestamp == "":
self._msg_box("You must enter a timestamp!", "Info")
return
if "UTC - Default" in selected_tz:
all_ts = from_all(timestamp)
else:
all_ts = from_all(timestamp, tz_name)
results = {}
for k, _ in all_ts.items():
results[k] = f"{all_ts[k][0]} {all_ts[k][2]}"
self.results = results
self.display_output(results)
def encode_toall(self):
"""Takes the date_time object, passes it to the to_timestamps function which encodes it"""
dt_val = self.date_time.text()
try:
dt_obj = dt.fromisoformat(dt_val)
except ValueError:
dt_obj = dt.strptime(dt_val, __fmt__)
if dt_obj.tzinfo is None:
dt_obj = dt_obj.replace(tzinfo=timezone.utc)
selected_tz = self.time_zone_offsets.currentText()
if "UTC - Default" not in selected_tz:
tz_name = " ".join(selected_tz.split(" ")[1:])
tz = tzone(tz_name)
dt_obj = dt_obj.replace(tzinfo=tz)
results, _ = to_timestamps(dt_obj)
self.results = results
self.display_output(results)
def display_output(self, ts_list):
"""Configures the output format for the provided values"""
self._reset_table()
tbl_fixed_width = 475
col2_width = 235
self_fixed_width = 490
if os.sys.platform == "linux":
tbl_fixed_width = 520
col2_width = 280
self_fixed_width = 535
self.output_table.setVisible(True)
self.output_table.setColumnCount(2)
self.output_table.setAlternatingRowColors(True)
self.output_table.setStyleSheet(
"""
border: none;
alternate-background-color: #EAF6FF;
background-color: white;
color: black;
selection-background-color: #1644b9;
"""
)
for ts_type, result in ts_list.items():
row = self.output_table.rowCount()
self.output_table.insertRow(row)
widget0 = QTableWidgetItem(ts_types[ts_type][0])
widget0.setFlags(widget0.flags() & ~Qt.ItemFlag.ItemIsEditable)
widget0.setToolTip(ts_types[ts_type][1])
widget1 = QTableWidgetItem(result)
widget1.setFlags(widget1.flags() & ~Qt.ItemFlag.ItemIsEditable)
self.output_table.setItem(row, 0, widget0)
self.output_table.item(row, 0).setTextAlignment(
int(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter)
)
self.output_table.setItem(row, 1, widget1)
self.output_table.item(row, 1).setTextAlignment(
int(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter)
)
if self.decode_radio.isChecked():
this_yr = int(dt.now(timezone.utc).strftime("%Y"))
try:
ts = result.split(" ")[0]
result_yr = int(dt.fromisoformat(ts).strftime("%Y"))
except ValueError:
split_ts = result.split(" ")
ts = f"{split_ts[0]} {split_ts[1]}"
result_yr = int(dt.strptime(ts, __fmt__).strftime("%Y"))
if result_yr in range(this_yr - 5, this_yr + 5):
for each_col in range(0, self.output_table.columnCount()):
this_col = self.output_table.item(row, each_col)
this_col.setBackground(QColor("lightgreen"))
this_col.setForeground(QColor("black"))
self.output_table.horizontalHeader().setFixedHeight(1)
self.output_table.verticalHeader().setFixedWidth(1)
self.output_table.setFixedWidth(tbl_fixed_width)
self.output_table.setColumnWidth(0, 220)
self.output_table.setColumnWidth(1, col2_width)
self.output_table.resizeRowsToContents()
self.output_table.setShowGrid(True)
total_row_height = sum(
self.output_table.rowHeight(row)
for row in range(self.output_table.rowCount())
)
self.output_table.setFixedHeight(400)
if total_row_height > 500:
self.setFixedHeight(540)
self.output_table.verticalScrollBar().show()
else:
self.setFixedHeight(self.height() + int(total_row_height + 12))
self.output_table.verticalScrollBar().hide()
self.setFixedWidth(self_fixed_width)
self.new_window_button.setEnabled(True)
self.new_window_button.setHidden(False)
if len(ts_list) > 1:
txt = "timestamps"
else:
txt = "timestamp"
self.timestamp_count_label.setText(f"{len(ts_list)} {txt}")
def go_function(self):
"""The To/From button: converts a date/timestamp, depending on the selected radio button"""
global __fmt__
results = {}
__fmt__ = date_formats[self.dt_format_combo.currentText()]
ts_format = self.timestamp_formats.currentText()
try:
ts_date = dt.fromisoformat(self.date_time.text()).replace(
tzinfo=timezone.utc
)
except ValueError:
ts_date = dt.strptime(self.date_time.text(), __fmt__).replace(
tzinfo=timezone.utc
)
selected_tz = self.time_zone_offsets.currentText()
if "UTC - Default" not in selected_tz:
tz_name = " ".join(selected_tz.split(" ")[1:])
tz = tzone(tz_name)
ts_date = ts_date.replace(tzinfo=tz)
in_ts_types = [k for k, v in ts_types.items() if ts_format in v]
if not in_ts_types:
self._msg_box(
f"For some reason {ts_format} is not in the list of available conversions!",
"Error",
)
return
ts_type = in_ts_types[0]
if self.encode_radio.isChecked():
is_func = False
ts_selection = f"to_{ts_type}"
for _, funcs in single_funcs.items():
this_func = funcs[1]
if inspect.isfunction(this_func):
func_name = this_func.__name__
if func_name == ts_selection:
is_func = True
if not is_func:
msg = (
f"Cannot convert to {ts_format}, information required to do this is "
"unavailable.\n\n"
"This is typically because the timestamp is only a small part of a larger "
"value, and the other 'parts' of the value are not available to combine with"
" the timestamp to provide a reasonable output."
)
self._msg_box(
msg,
"Warning",
)
return
ts_func = globals()[ts_selection]
result, _ = ts_func(ts_date)
results[ts_type] = result
self.results = results
self.display_output(results)
elif self.decode_radio.isChecked():
is_func = False
ts_text = self.timestamp_text.text()
if ts_text == "":
self._msg_box("You must enter a timestamp!", "Info")
return
ts_selection = f"from_{ts_type}"
for _, funcs in single_funcs.items():
this_func = funcs[0]
if inspect.isfunction(this_func):
func_name = this_func.__name__
if func_name == ts_selection:
is_func = True
if not is_func:
msg = (
f"Cannot convert from {ts_format}, information required to do this is "
"unavailable.\n\n"
"This is typically because the timestamp is only a small part of a larger "
"value, and the other 'parts' of are not available within your value to provide"
" a reasonable output."
)
self._msg_box(
msg,
"Warning",
)
return
ts_func = globals()[ts_selection]
result, _, _, reason, tz_out = ts_func(ts_text)
if not result:
self._msg_box(reason, "Error")
return
if "UTC - Default" not in selected_tz:
result, tz_out, _ = convert_timezone(tz_name, result)
if tz_out.startswith("+") or tz_out.startswith("-"):
results[ts_type] = f"{result}{tz_out}"
else:
results[ts_type] = f"{result} {tz_out}"
self.results = results
self.display_output(results)
def csv_decode(self):
"""GUI function to decode contents a CSV/TXT file from selected timestamp format"""
csv_file_path, _ = QFileDialog.getOpenFileName(
self, "Select a csv or txt document ...", "", "csv/txt files (*.csv *.txt)"
)
self.selected_header = None
combo_style = """
combobox-popup: 0;
background-color: white;
color: black;
selection-background-color: white;
selection-color: black;
"""
sample_rows = []
if csv_file_path:
self.csv_path = os.path.normpath(os.path.abspath(csv_file_path))
self.csv_content_window = CsvWindow(
self.timestamp_formats, self.time_zone_offsets, self.dt_format_combo
)
self.csv_content_window.setStyleSheet("background: white; color: black;")
self.csv_content_window.window_label.setFont(self.text_font)
self.csv_content_window.setWindowTitle("Choose your options for conversion")
self.csv_content_window.setMaximumWidth(330)
self.csv_go_button = QPushButton(self.csv_content_window)
self.csv_go_button.setObjectName("csv_go_button")
self.csv_go_button.setEnabled(True)
self.csv_go_button.setHidden(False)
self.csv_go_button.setFont(self.text_font)
self.csv_go_button.setText("Go")
self.csv_go_button.setGeometry(QRect(315, 230, 70, 22))
self.csv_go_button.setStyleSheet("background: white; color: black;")
self.csv_go_button.clicked.connect(
lambda: self.submit_csv_data(
csv_file_path,
self.csv_content_window.ts_formats.currentText(),
self.selected_header,
tz_name=self.csv_content_window.time_zones.currentText(),
dt_format=date_formats[
self.csv_content_window.dt_formats.currentText()
],
)
)
self.select_new_csv = QPushButton(self.csv_content_window)
self.select_new_csv.setObjectName("select_new_csv")
self.select_new_csv.setEnabled(True)
self.select_new_csv.setHidden(False)
self.select_new_csv.setFont(self.text_font)
self.select_new_csv.setText("Load new..")
self.select_new_csv.setGeometry(QRect(240, 260, 70, 22))
self.select_new_csv.clicked.connect(self.select_new_file)
self.select_new_csv.setToolTip(
"Load a new CSV/TXT file to replace the current one."
)
self.csv_content_window.ts_formats.setGeometry(QRect(10, 230, 225, 22))
self.csv_content_window.ts_formats.setStyleSheet(combo_style)
self.csv_content_window.ts_formats.view().setVerticalScrollBarPolicy(
Qt.ScrollBarPolicy.ScrollBarAsNeeded
)
self.csv_content_window.ts_formats.setFont(self.text_font)
self.csv_content_window.time_zones.setGeometry(QRect(10, 260, 225, 22))
self.csv_content_window.time_zones.setStyleSheet(combo_style)
self.csv_content_window.time_zones.view().setVerticalScrollBarPolicy(
Qt.ScrollBarPolicy.ScrollBarAsNeeded
)
self.csv_content_window.time_zones.setFont(self.text_font)
self.csv_content_window.dt_formats.setGeometry(QRect(240, 230, 70, 22))
self.csv_content_window.dt_formats.setToolTip(
"Choose your desired date/time format."
)
self.csv_content_window.dt_formats.setFont(self.text_font)
self.csv_close_button = QPushButton(self.csv_content_window)
self.csv_close_button.setObjectName("csv_close_button")
self.csv_close_button.setFont(self.text_font)
self.csv_close_button.setText("Close")
self.csv_close_button.setGeometry(QRect(315, 260, 70, 22))
self.csv_close_button.clicked.connect(self.csv_content_window.close)
try:
with open(csv_file_path, "r", newline="", encoding="utf-8") as src:
sample = src.read(1024)
try:
dialect = csv.Sniffer().sniff(sample)
except csv.Error:
dialect = csv.get_dialect("excel")
src.seek(0)
reader = csv.reader(src, dialect)
columns = len(next(reader, None))
src.seek(0)
rows = 5
for row in reader:
sample_rows.append(row)
rows -= 1
if rows == 0:
break
except (FileNotFoundError, PermissionError):
handle(sys.exc_info())
self.csv_content_window.output_table.setColumnCount(columns)
self.csv_content_window.output_table.setRowCount(len(sample_rows))
self.csv_content_window.output_table.setHorizontalHeaderLabels(
[str(i + 1) for i in range(columns)]
)
self.csv_content_window.output_table.setAlternatingRowColors(True)
self.csv_content_window.output_table.setStyleSheet(
"""
border: none;
alternate-background-color: #EAF6FF;
background-color: white;
color: black;
selection-background-color: #1644b9;
"""
)
self.csv_content_window.output_table.setFont(self.text_font)
for row_index, row in enumerate(sample_rows):
for col_index in range(columns):
cell_text = row[col_index] if col_index < len(row) else ""
item = QTableWidgetItem(cell_text)
item.setFlags(item.flags() & ~Qt.ItemFlag.ItemIsEditable)
self.csv_content_window.output_table.setItem(
row_index, col_index, item
)
self.csv_content_window.output_table.verticalHeader().setFixedWidth(1)
self.csv_content_window.output_table.horizontalHeader().setFixedHeight(1)
self.csv_content_window.output_table.resizeColumnsToContents()
self.csv_content_window.output_table.setGeometry(
QRect(
10,
50,
380,
self.csv_content_window.output_table.verticalHeader().length() + 20,
)
)
self.csv_content_window.setFixedSize(
400,
290,
)
self.csv_content_window.output_table.itemSelectionChanged.connect(
self.get_column_number
)
window_width = self.csv_content_window.width()
window_height = self.csv_content_window.height()
self.csv_content_window.window_label.setGeometry(
QRect(10, 10, window_width - 10, 30)
)
self.csv_content_window.window_label.setText(
(
"Select the column which contains your timestamps, then\n "
"choose a timestamp format and time zone, then click 'Go'."
)
)
x = (self.screen_layout.width() // 2) - (window_width // 2)
y = (self.screen_layout.height() // 2) - (window_height // 2)
self.csv_content_window.move(x, y)
self.csv_content_window.show()
def select_new_file(self):
"""Simply closes the open CSV window and reloads to select a new file"""
self.csv_content_window.close()
self.csv_decode()
def submit_csv_data(
self, csv_file, ts_format, column_num, tz_name=None, dt_format=None
):
"""Prepares data to submit for csv conversion"""
global __fmt__
if dt_format is not None and dt_format != __fmt__:
__fmt__ = dt_format
in_ts_types = [k for k, v in ts_types.items() if ts_format in v]
if not in_ts_types:
self._msg_box(
f"For some reason {ts_format} is not in the list of available conversions!",
"Error",
)
return
ts_type = in_ts_types[0]
if tz_name is not None and "UTC - Default" not in tz_name:
tz_name = " ".join(tz_name.split(" ")[1:])
status, dest, reason = generate_csv(
csv_file, ts_type, column_num, tz_name=tz_name
)
else:
status, dest, reason = generate_csv(csv_file, ts_type, column_num)
dest = os.path.normpath(dest)
if status:
self._msg_box(f"Output CSV file saved as {dest}.", "Info")
return
if reason is None:
reason = "Unknown"
self._msg_box(
f"CSV could not be processed. {dest} is incomplete.\n\nReason: {reason}",
"Error",
)
def get_column_number(self):
"""Gets the selected column number from the sample data and sets it into a variable"""
table = self.csv_content_window.output_table
selected_items = table.selectedItems()
if selected_items:
self.selected_header = selected_items[0].column() + 1
def _menu_bar(self):
"""Add a menu bar"""
self.menu_bar = self.menuBar()
self.menu_bar.setStyleSheet(self.stylesheet)
self.file_menu = self.menu_bar.addMenu("&File")
self.exit_action = QAction("&Exit", self)
self.exit_action.triggered.connect(QApplication.instance().quit)
self.exit_action.setFont(self.text_font)
self.csv_decode_action = QAction("&Decode from file ...", self)
self.csv_decode_action.triggered.connect(self.csv_decode)
self.csv_decode_action.setFont(self.text_font)
self.file_menu.addAction(self.csv_decode_action)
self.file_menu.addAction(self.exit_action)
self.menu_bar.addMenu(self.file_menu)
self.view_menu = self.menu_bar.addMenu("&View")
self.view_action = QAction("E&xamples", self)
self.view_action.triggered.connect(self._examples)
self.view_action.setFont(self.text_font)
self.view_menu.addAction(self.view_action)
self.menu_bar.addMenu(self.view_menu)
self.help_menu = self.menu_bar.addMenu("&Help")
self.about_action = QAction("&About", self)
self.about_action.triggered.connect(self._about)
self.about_action.setFont(self.text_font)
self.help_menu.addAction(self.about_action)
self.menu_bar.setFont(self.text_font)
def _msg_box(self, message, msg_type, buttons="ok"):
button_choice = None
if buttons == "ok":
button_choice = QMessageBox.StandardButton.Ok
elif buttons == "ok_cancel":
button_choice = (
QMessageBox.StandardButton.Ok | QMessageBox.StandardButton.Cancel
)
elif buttons == "yes_no_cancel":
button_choice = (
QMessageBox.StandardButton.Yes
| QMessageBox.StandardButton.No
| QMessageBox.StandardButton.Cancel
)
elif buttons == "yes_no":
button_choice = (
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
)
self.msg_box = QMessageBox()
self.msg_box.setStyleSheet("background-color: white; color: black;")
self.msg_box.setSizePolicy(
QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding
)
if msg_type == "Error":
self.msg_box.setIcon(QMessageBox.Icon.Critical)
elif msg_type == "Info":
self.msg_box.setIcon(QMessageBox.Icon.Information)
elif msg_type == "Warning":
self.msg_box.setIcon(QMessageBox.Icon.Warning)
elif msg_type == "":
self.msg_box.setIcon(QMessageBox.Icon.NoIcon)
msg_type = "Unidentified"
self.msg_box.setWindowTitle(msg_type)
self.msg_box.setFixedSize(300, 300)
self.msg_box.setText(f"{message}\t")
self.msg_box.setStandardButtons(button_choice)
x = (self.screen_layout.width() // 2) - (self.msg_box.width() // 2)
y = (self.screen_layout.height() // 2) - (self.msg_box.height() // 2)
self.msg_box.move(x, y)
self.msg_box.exec()
def _about(self):
self.about_window = AboutWindow()
self.about_window.setWindowFlags(
self.about_window.windowFlags() & ~Qt.WindowType.WindowMinMaxButtonsHint
)
github_link = f'<a href="{__source__}">View the source on GitHub</a>'
self.about_window.setWindowTitle("About")
self.about_window.about_label.setText(
f"Version: {__appname__}\nLast Updated: {__date__}\nAuthor: {__author__}"
)
self.about_window.about_label.setFont(self.text_font)
self.about_window.url_label.setOpenExternalLinks(True)
self.about_window.url_label.setText(github_link)
self.about_window.url_label.setFont(self.text_font)
self.logo = QPixmap()
self.logo.loadFromData(base64.b64decode(self.__fingerprint__))
self.about_window.logo_label.setPixmap(self.logo)
self.about_window.logo_label.resize(20, 20)
about_width = self.about_window.width()
about_height = self.about_window.height()
x = (self.screen_layout.width() // 2) - (about_width // 2)
y = (self.screen_layout.height() // 2) - (about_height // 2)
self.about_window.move(x, y)
self.about_window.show()
def _examples(self):
if self.examples_window is None:
structures = {}
for _, data_list in ts_types.items():
structures[data_list[0]] = (
data_list[1],
data_list[2],
)
structures = sorted(structures.items(), key=lambda item: item[0].casefold())
self.examples_window = NewWindow()
self.examples_window.window_label.setGeometry(QRect(0, 0, 200, 24))
self.examples_window.setWindowTitle("Timestamp Examples")
self.examples_window.setStyleSheet(
"""
border: none; alternate-background-color: #EAF6FF;
background-color: white; color: black;
"""
)
self.examples_window.output_table.setColumnCount(2)
for example in structures:
row = self.examples_window.output_table.rowCount()
self.examples_window.output_table.insertRow(row)
widget0 = QTableWidgetItem(example[1][0])
widget0.setFlags(widget0.flags() & ~Qt.ItemFlag.ItemIsEditable)
widget0.setToolTip(example[0])
widget1 = QTableWidgetItem(example[1][1])
widget1.setFlags(widget1.flags() & ~Qt.ItemFlag.ItemIsEditable)
self.examples_window.output_table.setItem(row, 0, widget0)
self.examples_window.output_table.item(row, 0).setTextAlignment(
int(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter)
)
self.examples_window.output_table.item(row, 0)
self.examples_window.output_table.setItem(row, 1, widget1)
self.examples_window.output_table.item(row, 1).setTextAlignment(
int(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter)
)
self.examples_window.output_table.horizontalHeader().setFixedHeight(1)
self.examples_window.output_table.verticalHeader().setFixedWidth(1)
self.examples_window.output_table.setGeometry(
QRect(
0,
0,
self.examples_window.output_table.horizontalHeader().length(),
self.examples_window.output_table.verticalHeader().length(),
)
)
self.examples_window.output_table.resizeColumnsToContents()
self.examples_window.output_table.resizeRowsToContents()
self.examples_window.output_table.setShowGrid(True)
self.examples_window.output_table.setAlternatingRowColors(True)
self.examples_window.setFixedSize(
self.examples_window.output_table.horizontalHeader().length() + 48,
400,
)
self.examples_window.output_table.setFont(self.text_font)
text = (
f"{self.examples_window.output_table.rowCount()} timestamp examples. "
"NOTE: Not all timestamp can be converted TO, as a timestamp may be only PART"
" of the total value."
)
self.examples_window.window_label.setText(text)
self.examples_window.window_label.setFont(self.text_font)
x = (self.screen_layout.width() // 2) - (self.examples_window.width() // 2)
y = (self.screen_layout.height() // 2) - (
self.examples_window.height() // 2
)
self.examples_window.move(x, y)
self.examples_window.show()
else:
self.examples_window.close()
self.examples_window = None
self._examples()
def _new_window(self):
table_data = self.results
selected_tz = self.time_zone_offsets.currentText()
msg = title = ""
if self.encode_radio.isChecked():
entered_value = self.date_time.text()
title = f"Encoded: {entered_value}"
if "UTC - Default" not in selected_tz:
entered_value = f"{entered_value} {selected_tz}"
msg = f"Encoded: {entered_value}"
elif self.decode_radio.isChecked():
entered_value = self.timestamp_text.text()
title = f"Decoded: {entered_value}"
if "UTC - Default" not in selected_tz:
entered_value = f"{entered_value} {selected_tz}"
msg = f"Decoded: {entered_value}"
if self.new_window is None:
self.new_window = NewWindow()
self.new_window.window_label.setGeometry(QRect(0, 0, 200, 24))
self.new_window.window_label.setText(msg)
self.new_window.window_label.setFont(self.text_font)
self.new_window.setWindowTitle(title)
self.new_window.setStyleSheet(
"""
border: none; alternate-background-color: #EAF6FF;
background-color: white; color: black;
"""
)
self.new_window.output_table.setColumnCount(2)
for ts_type, result in table_data.items():
row = self.new_window.output_table.rowCount()
self.new_window.output_table.insertRow(row)
widget0 = QTableWidgetItem(ts_types[ts_type][0])
widget0.setFlags(widget0.flags() & ~Qt.ItemFlag.ItemIsEditable)
widget0.setToolTip(ts_types[ts_type][1])
widget1 = QTableWidgetItem(result)
widget1.setFlags(widget1.flags() & ~Qt.ItemFlag.ItemIsEditable)
self.new_window.output_table.setItem(row, 0, widget0)
self.new_window.output_table.item(row, 0).setTextAlignment(
int(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter)
)
self.new_window.output_table.item(row, 0)
self.new_window.output_table.setItem(row, 1, widget1)
self.new_window.output_table.item(row, 1).setTextAlignment(
int(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter)
)
if self.decode_radio.isChecked():
ts = result.split(" ")[0]
this_yr = int(dt.now(timezone.utc).strftime("%Y"))
try:
ts = result.split(" ")[0]
result_yr = int(dt.fromisoformat(ts).strftime("%Y"))
except ValueError:
split_ts = result.split(" ")
ts = f"{split_ts[0]} {split_ts[1]}"
result_yr = int(dt.strptime(ts, __fmt__).strftime("%Y"))
if result_yr in range(this_yr - 5, this_yr + 5):
for each_col in range(
0, self.new_window.output_table.columnCount()
):
this_col = self.new_window.output_table.item(row, each_col)
this_col.setBackground(QColor("lightgreen"))
this_col.setForeground(QColor("black"))
self.new_window.output_table.horizontalHeader().setFixedHeight(1)
self.new_window.output_table.verticalHeader().setFixedWidth(1)
self.new_window.output_table.setGeometry(
QRect(
0,
0,
self.new_window.output_table.horizontalHeader().length(),
self.new_window.output_table.verticalHeader().length(),
)
)
self.new_window.output_table.resizeColumnsToContents()
for col in range(0, self.new_window.output_table.columnCount()):
col_width = self.new_window.output_table.columnWidth(col)
self.new_window.output_table.setColumnWidth(col, col_width + 10)
self.new_window.output_table.resizeRowsToContents()
row_height = self.new_window.output_table.rowHeight(row)
total_row_height = sum(
row_height for row in range(self.new_window.output_table.rowCount())
)
if total_row_height < 400:
window_height = total_row_height + (row_height * 2) + 8
else:
window_height = 400
self.new_window.output_table.setShowGrid(True)
self.new_window.output_table.setAlternatingRowColors(True)
self.new_window.setFixedSize(
self.new_window.output_table.horizontalHeader().length() + 38,
window_height,
)
self.new_window.output_table.setFont(self.text_font)
x = (self.screen_layout.width() // 2) - (self.new_window.width() // 2)
y = (self.screen_layout.height() // 2) - (self.new_window.height() // 2)
self.new_window.move(x, y)
self.new_window.show()
else:
self.new_window.close()
self.new_window = None
self._new_window()
class TimeDecodeGui(QMainWindow, UiMainWindow):
"""TimeDecode Class"""
stylesheet = """
QMainWindow {
background-color: white; color: black;
}
QLineEdit {
background-color: white; color: black;
}
QDateTimeEdit {
background-color: white; color: black;
}
QMenu {
background-color: white; color: black; border: 1px solid black; margin: 0;
}
QMenu::item {
background-color: white; color: black; margin: 0; padding: 4px 20px 4px 20px;
}
QMenu::item:selected {
background-color: #1644b9; color: white; margin: 0; padding: 4px 20px 4px 20px;
}
QMenuBar {
background-color: white; color: black;
}
QMenuBar::item {
background-color: white; color: black;
}
QMenuBar::item:selected {
background-color: #1644b9; color: white;
}
"""
__fingerprint__ = """
AAABAAIAMDAAAAEAIACoJQAAJgAAABAQAAABACAAaAQAAM4lAAAoAAAAMAAAAGAAAAABACAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAA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VKh5AAAAAAAA
AABiR9IFT0LgaURB5lVJQuNTSkLhdkxD3jFiRs8bZUfMG15F0VJYRNV5X0XPVXFQuWCEVqNWg1al
LAAAAAAAAAAAAAAAAF9E1lVXRNlqbUbKUGdGzXJbRdROckbDUmhGymFfRc9AhEmyL21GxERsRsca
h1efCgAAAAAAAAAAAAAAAAAAAAAAAAAAVkTZGFND2nZURNdgYUbPOl1F0mFbRNJhYkXMPHBGxE1u
RsV5bUbGMwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVkXVDwAAAACKSa5ofki3bXZH
vmBzR8ElAAAAAAAAAAAAAAAAAAAAAAAAAAD4f6xB4AesQeADrEHAAaxBgAGsQQABrEEAAaxBAACs
QQAArEEAgKxBgACsQYABrEGAAaxBwAOsQeAHrEH6H6xB
"""
def __init__(self):
"""Call and setup the UI"""
super().__init__()
self.setup_ui(self)
def key_press_event(self, event):
"""Create a KeyPress event for a Ctrl+C (Copy) event for selected text"""
if event.matches(QKeySequence.StandardKey.Copy):
self.context_menu.copy()
else:
super().key_press_event(event)
class TsTypes(NamedTuple):
"""Defines the structure of a Timestamp Type"""
ts_type: str
reason: str
example: str
time_zone: str
ts_types = {
"active": TsTypes(
"Active Directory/LDAP",
"Active Directory/LDAP timestamps are 18 digits",
"133908455300649390",
"UTC",
),
"apache": TsTypes(
"Apache Cookie Hex time",
"Apache Cookie hex timestamps are 13 hex characters long",
"63450e689882b",
"UTC",
),
"biome64": TsTypes(
"Apple Biome 64-bit decimal",
"Apple Biome 64-bit decimal is 19 digits in length",
"4739726202305531884",
"UTC",
),
"biomehex": TsTypes(
"Apple Biome Hex time",
"Apple Biome Hex value is 8 bytes (16 chars) long",
"41c6e3de6d084fec",
"UTC",
),
"nsdate": TsTypes(
"Apple NSDate - All",
"Apple NSDates are 9, 9.6, or 15-19 digits in length",
"704656778.285777",
"UTC",
),
"bplist": TsTypes(
"Apple NSDate - bplist / Cocoa",
"Apple NSDates (bplist) are 9 digits in length",
"768064730",
"UTC",
),
"iostime": TsTypes(
"Apple NSDate - iOS 11+",
"Apple NSDates (iOS) are 15-19 digits in length",
"768064730064939008",
"UTC",
),
"mac": TsTypes(
"Apple NSDate - Mac Absolute",
"Apple NSDates (Mac) are 9 digits '.' 6 digits",
"768064730.064939",
"UTC",
),
"bcd": TsTypes(
"Binary Coded Decimal",
"Binary Coded Decimal timestamps are 12 digits in length",
"250506232221",
"Local",
),
"bitdate": TsTypes(
"BitDate time",
"BitDate (Samsung/LG) timestamps are 8 hex characters",
"d223957e",
"Local",
),
"bitdec": TsTypes(
"Bitwise Decimal time",
"Bitwise Decimal timestamps are 10 digits",
"2123703250",
"Local",
),
"dhcp6": TsTypes(
"DHCPv6 DUID time",
"DHCPv6 DUID values are at least 14 bytes long",
"000100012faa41da000000000000",
"UTC",
),
"discord": TsTypes(
"Discord time",
"Discord timestamps are 18 digits or longer",
"1102608904745127937",
"UTC",
),
"dvr": TsTypes(
"DVR (WFS / DHFS) File System",
"DVR timestamps are 4 bytes",
"00F0063F",
"Local",
),
"exfat": TsTypes(
"exFAT time",
"exFAT 32-bit timestamps are 8 hex characters (4 bytes)",
"5aa47a59",
"Local",
),
"fat": TsTypes(
"FAT Date + Time",
"FAT (MS-DOS wFatDate wFatTime) timestamps are 8 hex characters (4 bytes)",
"a45a597a",
"Local",
),
"gbound": TsTypes(
"GMail Boundary time",
"GMail Boundary values are 28 hex chars",
"00000000000089882b063450e600",
"UTC",
),
"gmsgid": TsTypes(
"GMail Message ID time",
"GMail Message ID values are 16 hex chars or 19 digits (IMAP)",
"1969be0e7d000000",
"UTC",
),
"chrome": TsTypes(
"Google Chrome",
"Google Chrome/Webkit timestamp is 17 digits",
"13390845530064940",
"UTC",
),
"eitime": TsTypes(
"Google EI time",
"Google ei timestamps contain only URLsafe base64 characters: A-Za-z0-9=-_",
"WoUXaA",
"UTC",
),
"gclid": TsTypes(
"Google GCLID time",
"Google GCLID timestamps contain only URLsafe base64 characters: A-Za-z0-9=-_",
"CKSDxc_qhLkCFQyk4AodO24Arg",
"UTC",
),
"ved": TsTypes(
"Google VED time",
"Google VED timestamps contain only URLsafe base64 characters: A-Za-z0-9=-_",
"0ahUKEwilufv7joqNAxW3nYkEHd0vMyIQ4dUDCA8",
"UTC",
),
"gps": TsTypes("GPS time", "GPS timestamps are 10 digits", "1430407111", "UTC"),
"gsm": TsTypes(
"GSM time",
"GSM timestamps are 14 hex characters (7 bytes)",
"52504051810500",
"UTC",
),
"hfsbe": TsTypes(
"HFS / HFS+ 32-bit Hex BE",
"HFS / HFS+ Big-Endian timestamps are 8 hex characters (4 bytes)",
"e43d35da",
"Local / UTC",
),
"hfsle": TsTypes(
"HFS / HFS+ 32-bit Hex LE",
"HFS / HFS+ Little-Endian timestamps are 8 hex characters (4 bytes)",
"da353de4",
"Local / UTC",
),
"hfsdec": TsTypes(
"HFS+ Decimal Time",
"HFS+ Decimal timestamps are 10 digits",
"3829216730",
"UTC",
),
"logtime": TsTypes(
"JET LogTime",
"JET LogTime values are 8 bytes, one byte for each YY-MM-DD HH:MM:SS and 2 fillers",
"343a0d17037b0000",
"UTC",
),
"juliandec": TsTypes(
"Julian Date decimal",
"Julian Date decimal values are 7 digits, a decimal, and up to 10 digits",
"2460800.1380787035",
"UTC",
),
"julianhex": TsTypes(
"Julian Date hex",
"Julian Date hex values are 14 characters (7 bytes)",
"258c80524d235b",
"UTC",
),
"ksalnum": TsTypes(
"KSUID Alpha-numeric",
"KSUID values are 27 alpha-numeric characters",
"2PChRqPZDwT9m2gBDLd5uy7XNTr",
"UTC",
),
"ksdec": TsTypes(
"KSUID Decimal",
"KSUID decimal timestamps are 9 digits in length",
"346371930",
"UTC",
),
"leb128hex": TsTypes(
"LEB128 Hex time",
"LEB128 Hex timestamps are variable-length and even-length",
"d0cf83dfe932",
"UTC",
),
"linkedin": TsTypes(
"LinkedIn Activity time",
"LinkedIn Activity timestamps contain only digits",
"7324176984442343424",
"UTC",
),
"mastodon": TsTypes(
"Mastodon time",
"Mastodon timestamps are 18 digits or longer",
"114450230804480000",
"UTC",
),
"metasploit": TsTypes(
"Metasploit Payload UUID",
"Metasploit Payload UUID's are at least 22 chars and base64 urlsafe encoded",
"4PGoVGYmx8l6F3sVI4Rc8g",
"UTC",
),
"dotnet": TsTypes(
"Microsoft .NET DateTime Ticks",
"Microsoft .NET DateTime Ticks values are 18 digits",
"638819687300649472",
"UTC",
),
"systemtime": TsTypes(
"Microsoft 128-bit SYSTEMTIME",
"Microsoft 128-bit SYSTEMTIME timestamps are 32 hex characters (16 bytes)",
"e9070500000004000f00120032004000",
"UTC",
),
"dttm": TsTypes(
"Microsoft DTTM Date",
"Microsoft DTTM timestamps are 4 bytes",
"8768f513",
"Local",
),
"ms1904": TsTypes(
"Microsoft Excel 1904 Date",
"Microsoft Excel 1904 timestamps are 2 ints, separated by a dot",
"44319.638079455312",
"UTC",
),
"hotmail": TsTypes(
"Microsoft Hotmail time",
"Microsoft Hotmail timestamps are 2x 8 hex chars (4 bytes) colon separated",
"07bddb01:aed19dd6",
"UTC",
),
"msdos": TsTypes(
"Microsoft MS-DOS 32-bit Hex",
"Microsoft MS-DOS 32-bit timestamps are 8 hex characters (4 bytes)",
"597aa45a",
"Local",
),
"moto": TsTypes(
"Motorola time",
"Motorola 6-byte hex timestamps are 12 hex characters",
"3705040f1232",
"UTC",
),
"prtime": TsTypes(
"Mozilla PRTime",
"Mozilla PRTime timestamps are 16 digits",
"1746371930064939",
"UTC",
),
"nokia": TsTypes(
"Nokia time",
"Nokia 4-byte hex timestamps are 8 hex characters",
"d19d0f5a",
"UTC",
),
"ns40": TsTypes(
"Nokia S40 time",
"Nokia 7-byte hex timestamps are 14 hex characters",
"07e905040f1232",
"UTC",
),
"ns40le": TsTypes(
"Nokia S40 time LE",
"Nokia 7-byte hex timestamps are 14 hex characters",
"e90705040f1232",
"UTC",
),
"nokiale": TsTypes(
"Nokia time LE",
"Nokia 4-byte hex timestamps are 8 hex characters",
"5a0f9dd1",
"UTC",
),
"s32": TsTypes(
"S32 Encoded (Bluesky) time",
"S32 encoded (Bluesky) timestamps are 9 characters long",
"3muhy3twk",
"UTC",
),
"semioctet": TsTypes(
"Semi-Octet decimal",
"Semi-Octet decimal values are 12 or 14 digits long",
"525040518105",
"Local",
),
"sony": TsTypes(
"Sonyflake time",
"Sonyflake values are 15 hex characters",
"65dd4bb89000001",
"UTC",
),
"symantec": TsTypes(
"Symantec AV time",
"Symantec 6-byte hex timestamps are 12 hex characters",
"3704040f1232",
"UTC",
),
"tiktok": TsTypes(
"TikTok time",
"TikTok timestamps are 19 digits long",
"7228142017547750661",
"UTC",
),
"twitter": TsTypes(
"Twitter time",
"Twitter timestamps are 18 digits or longer",
"1189581422684274688",
"UTC",
),
"ulid": TsTypes(
"ULID time",
"ULID timestamp contains only Base32 characters",
"01JTDY1SYGCZWCBPCSEBHV1DW2",
"UTC",
),
"unixhex32be": TsTypes(
"Unix Hex 32-bit BE",
"Unix Hex 32-bit Big-Endian timestamps are 8 hex characters (4 bytes)",
"6817855a",
"UTC",
),
"unixhex32le": TsTypes(
"Unix Hex 32-bit LE",
"Unix Hex 32-bit Little-Endian timestamps are 8 hex characters (4 bytes)",
"5a851768",
"UTC",
),
"unixmilli": TsTypes(
"Unix Milliseconds",
"Unix milliseconds timestamp is 13 digits in length",
"1746371930064",
"UTC",
),
"unixmillihex": TsTypes(
"Unix Milliseconds hex",
"Unix Milliseconds hex timestamp is 12 hex characters (6 bytes)",
"01969be0e7d0",
"UTC",
),
"unixsec": TsTypes(
"Unix Seconds",
"Unix seconds timestamp is 10 digits in length",
"1746371930",
"UTC",
),
"uuid": TsTypes(
"UUID time",
"UUIDs are in the format 00000000-0000-0000-0000-000000000000",
"d93026f0-e857-11ed-a05b-0242ac120003",
"UTC",
),
"vm": TsTypes(
"VMSD time",
"VMSD values are a 6-digit value and a signed/unsigned int at least 9 digits",
"406608,-427259264",
"UTC",
),
"cookie": TsTypes(
"Windows Cookie Date",
"Windows Cookie times consist of 2 ints, entered with a comma between them",
"3600017664,31177991",
"UTC",
),
"filetimelohi": TsTypes(
"Windows FILETIME (Low|High)",
"Windows FILETIME Low|High times are 2x 8 hex chars (4 bytes) colon separated",
"d69dd1ae:01dbbd07",
"UTC",
),
"filetimebe": TsTypes(
"Windows FILETIME BE",
"Windows FILETIME Hex Big-Endian timestamp is 16 hex characters (8 bytes)",
"01dbbd07d69dd1ae",
"UTC",
),
"filetimele": TsTypes(
"Windows FILETIME LE",
"Windows FILETIME Hex Little-Endian timestamp is 16 hex characters (8 bytes)",
"aed19dd607bddb01",
"UTC",
),
"olebe": TsTypes(
"Windows OLE 64-bit hex BE",
"Windows OLE Big-Endian timestamps are 16 hex characters (8 bytes)",
"40e65ab46b259b1a",
"UTC",
),
"olele": TsTypes(
"Windows OLE 64-bit hex LE",
"Windows OLE Little-Endian timestamps are 16 hex characters (8 bytes)",
"1a9b256bb45ae640",
"UTC",
),
"oleauto": TsTypes(
"Windows OLE Automation Date",
"Windows OLE Automation timestamps are 2 ints, separated by a dot",
"45781.638079455312",
"UTC",
),
}
epochs = {
1: dt(1, 1, 1, tzinfo=timezone.utc),
1582: dt(1582, 10, 15, tzinfo=timezone.utc),
1601: dt(1601, 1, 1, tzinfo=timezone.utc),
1899: dt(1899, 12, 30, tzinfo=timezone.utc),
1904: dt(1904, 1, 1, tzinfo=timezone.utc),
1970: dt(1970, 1, 1, tzinfo=timezone.utc),
1980: dt(1980, 1, 6, tzinfo=timezone.utc),
2000: dt(2000, 1, 1, tzinfo=timezone.utc),
2001: dt(2001, 1, 1, tzinfo=timezone.utc),
2050: dt(2050, 1, 1, tzinfo=timezone.utc),
"hundreds_nano": 10000000,
"nano_2001": 1000000000,
"active": 116444736000000000,
"win_unix": 11644473600,
"hfs_dec_sub": 2082844800,
"kstime": 1400000000,
"ticks": 621355968000000000,
}
# There have been no further leapseconds since 2017,1,1 at the __date__ of this script
# which is why the leapseconds end with a dt.now object to valid/relevant timestamp output.
# See REFERENCES.md for source info.
leapseconds = {
10: [dt(1972, 1, 1, tzinfo=timezone.utc), dt(1972, 7, 1, tzinfo=timezone.utc)],
11: [dt(1972, 7, 1, tzinfo=timezone.utc), dt(1973, 1, 1, tzinfo=timezone.utc)],
12: [dt(1973, 1, 1, tzinfo=timezone.utc), dt(1974, 1, 1, tzinfo=timezone.utc)],
13: [dt(1974, 1, 1, tzinfo=timezone.utc), dt(1975, 1, 1, tzinfo=timezone.utc)],
14: [dt(1975, 1, 1, tzinfo=timezone.utc), dt(1976, 1, 1, tzinfo=timezone.utc)],
15: [dt(1976, 1, 1, tzinfo=timezone.utc), dt(1977, 1, 1, tzinfo=timezone.utc)],
16: [dt(1977, 1, 1, tzinfo=timezone.utc), dt(1978, 1, 1, tzinfo=timezone.utc)],
17: [dt(1978, 1, 1, tzinfo=timezone.utc), dt(1979, 1, 1, tzinfo=timezone.utc)],
18: [dt(1979, 1, 1, tzinfo=timezone.utc), dt(1980, 1, 1, tzinfo=timezone.utc)],
19: [dt(1980, 1, 1, tzinfo=timezone.utc), dt(1981, 7, 1, tzinfo=timezone.utc)],
20: [dt(1981, 7, 1, tzinfo=timezone.utc), dt(1982, 7, 1, tzinfo=timezone.utc)],
21: [dt(1982, 7, 1, tzinfo=timezone.utc), dt(1983, 7, 1, tzinfo=timezone.utc)],
22: [dt(1983, 7, 1, tzinfo=timezone.utc), dt(1985, 7, 1, tzinfo=timezone.utc)],
23: [dt(1985, 7, 1, tzinfo=timezone.utc), dt(1988, 1, 1, tzinfo=timezone.utc)],
24: [dt(1988, 1, 1, tzinfo=timezone.utc), dt(1990, 1, 1, tzinfo=timezone.utc)],
25: [dt(1990, 1, 1, tzinfo=timezone.utc), dt(1991, 1, 1, tzinfo=timezone.utc)],
26: [dt(1991, 1, 1, tzinfo=timezone.utc), dt(1992, 7, 1, tzinfo=timezone.utc)],
27: [dt(1992, 7, 1, tzinfo=timezone.utc), dt(1993, 7, 1, tzinfo=timezone.utc)],
28: [dt(1993, 7, 1, tzinfo=timezone.utc), dt(1994, 7, 1, tzinfo=timezone.utc)],
29: [dt(1994, 7, 1, tzinfo=timezone.utc), dt(1996, 1, 1, tzinfo=timezone.utc)],
30: [dt(1996, 1, 1, tzinfo=timezone.utc), dt(1997, 7, 1, tzinfo=timezone.utc)],
31: [dt(1997, 7, 1, tzinfo=timezone.utc), dt(1999, 1, 1, tzinfo=timezone.utc)],
32: [dt(1999, 1, 1, tzinfo=timezone.utc), dt(2006, 1, 1, tzinfo=timezone.utc)],
33: [dt(2006, 1, 1, tzinfo=timezone.utc), dt(2009, 1, 1, tzinfo=timezone.utc)],
34: [dt(2009, 1, 1, tzinfo=timezone.utc), dt(2012, 7, 1, tzinfo=timezone.utc)],
35: [dt(2012, 7, 1, tzinfo=timezone.utc), dt(2015, 7, 1, tzinfo=timezone.utc)],
36: [dt(2015, 7, 1, tzinfo=timezone.utc), dt(2017, 1, 1, tzinfo=timezone.utc)],
37: [
dt(2017, 1, 1, tzinfo=timezone.utc),
dt.now(timezone.utc) - timedelta(seconds=37),
],
}
date_formats = {
"Default": __fmt__,
"ISO 8601": "%Y-%m-%dT%H:%M:%S.%f",
"DD/MM/YY": "%d/%m/%Y %H:%M:%S.%f",
"DMY": "%d-%m-%Y %H:%M:%S.%f",
"MDY": "%m-%d-%Y %H:%M:%S.%f",
"YMD": __fmt__,
}
S32_CHARS = "234567abcdefghijklmnopqrstuvwxyz"
BASE32_CHARS = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"
URLSAFE_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890=-_"
KSALNUM_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
def from_unixsec(timestamp):
"""Convert Unix Seconds value to a date"""
ts_type, reason, _, tz_out = ts_types["unixsec"]
try:
if len(str(timestamp)) != 10 or not timestamp.isdigit():
in_unix_sec = indiv_output = combined_output = ""
else:
in_unix_sec = dt.fromtimestamp(float(timestamp), timezone.utc).strftime(
__fmt__
)
indiv_output, combined_output = format_output(ts_type, in_unix_sec, tz_out)
except Exception:
handle(sys.exc_info())
in_unix_sec = indiv_output = combined_output = ""
return in_unix_sec, indiv_output, combined_output, reason, tz_out
def to_unixsec(dt_obj):
"""Convert date to a Unix Seconds value"""
ts_type, _, _, _ = ts_types["unixsec"]
try:
out_unix_sec = str(int(dt_obj.timestamp()))
ts_output, _ = format_output(ts_type, out_unix_sec)
except Exception:
handle(sys.exc_info())
out_unix_sec = ts_output = ""
return out_unix_sec, ts_output
def from_unixmilli(timestamp):
"""Convert Unix Millisecond value to a date"""
ts_type, reason, _, tz_out = ts_types["unixmilli"]
try:
if len(str(timestamp)) != 13 or not str(timestamp).isdigit():
in_unix_milli = indiv_output = combined_output = ""
else:
in_unix_milli = dt.fromtimestamp(
float(timestamp) / 1000.0, timezone.utc
).strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_unix_milli, tz_out
)
except Exception:
handle(sys.exc_info())
in_unix_milli = indiv_output = combined_output = ""
return in_unix_milli, indiv_output, combined_output, reason, tz_out
def to_unixmilli(dt_obj):
"""Convert date to a Unix Millisecond value"""
ts_type, _, _, _ = ts_types["unixmilli"]
try:
out_unix_milli = str(int(dt_obj.timestamp() * 1000))
ts_output, _ = format_output(ts_type, out_unix_milli)
except Exception:
handle(sys.exc_info())
out_unix_milli = ts_output = ""
return out_unix_milli, ts_output
def from_unixmillihex(timestamp):
"""Convert a Unix Millisecond hex value to a date"""
ts_type, reason, _, tz_out = ts_types["unixmillihex"]
try:
if len(str(timestamp)) != 12 or not all(
char in hexdigits for char in timestamp
):
in_unix_milli_hex = indiv_output = combined_output = ""
else:
unix_mil = int(str(timestamp), 16)
in_unix_milli_hex, _, _, _, _ = from_unixmilli(unix_mil)
indiv_output, combined_output = format_output(
ts_type, in_unix_milli_hex, tz_out
)
except Exception:
handle(sys.exc_info())
in_unix_milli_hex = indiv_output = combined_output = ""
return in_unix_milli_hex, indiv_output, combined_output, reason, tz_out
def to_unixmillihex(dt_obj):
"""Convert a date to a Unix Millisecond hex value"""
ts_type, _, _, _ = ts_types["unixmillihex"]
try:
unix_mil, _ = to_unixmilli(dt_obj)
out_unix_milli_hex = f"{int(unix_mil):012x}"
ts_output, _ = format_output(ts_type, out_unix_milli_hex)
except Exception:
handle(sys.exc_info())
out_unix_milli_hex = ts_output = ""
return out_unix_milli_hex, ts_output
def from_filetimebe(timestamp):
"""Convert a Windows 64 Hex Big-Endian value to a date"""
ts_type, reason, _, tz_out = ts_types["filetimebe"]
try:
if not len(timestamp) == 16 or not all(char in hexdigits for char in timestamp):
in_filetime_be = indiv_output = combined_output = ""
else:
base10_microseconds = int(timestamp, 16) / 10
if base10_microseconds >= 1e17:
in_filetime_be = indiv_output = combined_output = ""
else:
dt_obj = epochs[1601] + timedelta(microseconds=base10_microseconds)
in_filetime_be = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_filetime_be, tz_out
)
except Exception:
handle(sys.exc_info())
in_filetime_be = indiv_output = combined_output = ""
return in_filetime_be, indiv_output, combined_output, reason, tz_out
def to_filetimebe(dt_obj):
"""Convert a date to a Windows 64 Hex Big-Endian value"""
ts_type, _, _, _ = ts_types["filetimebe"]
try:
minus_epoch = dt_obj - epochs[1601]
calc_time = (
minus_epoch.microseconds
+ (minus_epoch.seconds * 1000000)
+ (minus_epoch.days * 86400000000)
)
out_filetime_be = str(hex(int(calc_time) * 10))[2:].zfill(16)
ts_output, _ = format_output(ts_type, out_filetime_be)
except Exception:
handle(sys.exc_info())
out_filetime_be = ts_output = ""
return out_filetime_be, ts_output
def from_filetimele(timestamp):
"""Convert a Windows 64 Hex Little-Endian value to a date"""
ts_type, reason, _, tz_out = ts_types["filetimele"]
try:
if not len(timestamp) == 16 or not all(char in hexdigits for char in timestamp):
in_filetime_le = indiv_output = combined_output = ""
else:
indiv_output = combined_output = ""
endianness_change = int.from_bytes(
struct.pack("<Q", int(timestamp, 16)), "big"
)
converted_time = endianness_change / 10
if converted_time >= 1e17:
in_filetime_le = indiv_output = combined_output = ""
else:
dt_obj = epochs[1601] + timedelta(microseconds=converted_time)
in_filetime_le = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_filetime_le, tz_out
)
except Exception:
handle(sys.exc_info())
in_filetime_le = indiv_output = combined_output = ""
return in_filetime_le, indiv_output, combined_output, reason, tz_out
def to_filetimele(dt_obj):
"""Convert a date to a Windows 64 Hex Little-Endian value"""
ts_type, _, _, _ = ts_types["filetimele"]
try:
minus_epoch = dt_obj - epochs[1601]
calc_time = (
minus_epoch.microseconds
+ (minus_epoch.seconds * 1000000)
+ (minus_epoch.days * 86400000000)
)
out_filetime_le = str(struct.pack("<Q", int(calc_time * 10)).hex()).zfill(16)
ts_output, _ = format_output(ts_type, out_filetime_le)
except Exception:
handle(sys.exc_info())
out_filetime_le = ts_output = ""
return out_filetime_le, ts_output
def from_chrome(timestamp):
"""Convert a Chrome Timestamp/Webkit Value to a date"""
ts_type, reason, _, tz_out = ts_types["chrome"]
try:
if not len(timestamp) == 17 or not timestamp.isdigit():
in_chrome = indiv_output = combined_output = ""
else:
delta = timedelta(microseconds=int(timestamp))
converted_time = epochs[1601] + delta
in_chrome = converted_time.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_chrome, tz_out)
except Exception:
handle(sys.exc_info())
in_chrome = indiv_output = combined_output = ""
return in_chrome, indiv_output, combined_output, reason, tz_out
def to_chrome(dt_obj):
"""Convert a date to a Chrome Timestamp/Webkit value"""
ts_type, _, _, _ = ts_types["chrome"]
try:
chrome_time = (dt_obj - epochs[1601]).total_seconds()
out_chrome = str(int(chrome_time * 1000000))
ts_output, _ = format_output(ts_type, out_chrome)
except Exception:
handle(sys.exc_info())
out_chrome = ts_output = ""
return out_chrome, ts_output
def from_active(timestamp):
"""Convert an Active Directory/LDAP timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["active"]
try:
if not len(timestamp) == 18 or not timestamp.isdigit():
in_ad = indiv_output = combined_output = ""
else:
val_check = (
float(int(timestamp) - epochs["active"]) / epochs["hundreds_nano"]
)
if val_check < 0 or val_check >= 32536799999:
# This is the Windows maximum for parsing a unix TS
# and is 3001-01-19 02:59:59 UTC
in_ad = indiv_output = combined_output = ""
else:
dt_obj = dt.fromtimestamp(val_check, timezone.utc)
in_ad = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_ad, tz_out)
except Exception:
handle(sys.exc_info())
in_ad = indiv_output = combined_output = ""
return in_ad, indiv_output, combined_output, reason, tz_out
def to_active(dt_obj):
"""Convert a date to an Active Directory/LDAP timestamp"""
ts_type, _, _, _ = ts_types["active"]
try:
nano_convert = int(dt_obj.timestamp() * epochs["hundreds_nano"])
out_adtime = str(int(nano_convert) + int(epochs["active"]))
ts_output, _ = format_output(ts_type, out_adtime)
except Exception:
handle(sys.exc_info())
out_adtime = ts_output = ""
return out_adtime, ts_output
def from_unixhex32be(timestamp):
"""Convert a Unix Hex 32-bit Big-Endian timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["unixhex32be"]
try:
if not len(timestamp) == 8 or not all(char in hexdigits for char in timestamp):
in_unix_hex_32 = indiv_output = combined_output = ""
else:
to_dec = int(timestamp, 16)
in_unix_hex_32 = dt.fromtimestamp(float(to_dec), timezone.utc).strftime(
__fmt__
)
indiv_output, combined_output = format_output(
ts_type, in_unix_hex_32, tz_out
)
except Exception:
handle(sys.exc_info())
in_unix_hex_32 = indiv_output = combined_output = ""
return in_unix_hex_32, indiv_output, combined_output, reason, tz_out
def to_unixhex32be(dt_obj):
"""Convert a date to a Unix Hex 32-bit Big-Endian timestamp"""
ts_type, _, _, _ = ts_types["unixhex32be"]
try:
unix_time = int(dt_obj.timestamp())
out_unix_hex_32 = str(struct.pack(">L", unix_time).hex())
ts_output, _ = format_output(ts_type, out_unix_hex_32)
except Exception:
handle(sys.exc_info())
out_unix_hex_32 = ts_output = ""
return out_unix_hex_32, ts_output
def from_unixhex32le(timestamp):
"""Convert a Unix Hex 32-bit Little-Endian timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["unixhex32le"]
try:
if not len(timestamp) == 8 or not all(char in hexdigits for char in timestamp):
in_unix_hex_32le = indiv_output = combined_output = ""
else:
to_dec = int.from_bytes(struct.pack("<L", int(timestamp, 16)), "big")
in_unix_hex_32le = dt.fromtimestamp(float(to_dec), timezone.utc).strftime(
__fmt__
)
indiv_output, combined_output = format_output(
ts_type, in_unix_hex_32le, tz_out
)
except Exception:
handle(sys.exc_info())
in_unix_hex_32le = indiv_output = combined_output = ""
return in_unix_hex_32le, indiv_output, combined_output, reason, tz_out
def to_unixhex32le(dt_obj):
"""Convert a date to a Unix Hex 32-bit Little-Endian timestamp"""
ts_type, _, _, _ = ts_types["unixhex32le"]
try:
unix_time = int((dt_obj - epochs[1970]).total_seconds())
out_unix_hex_32le = str(struct.pack("<L", unix_time).hex())
ts_output, _ = format_output(ts_type, out_unix_hex_32le)
except Exception:
handle(sys.exc_info())
out_unix_hex_32le = ts_output = ""
return out_unix_hex_32le, ts_output
def from_cookie(timestamp):
"""Convert an Internet Explorer timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["cookie"]
try:
if not ("," in timestamp) or not (
timestamp.split(",")[0].isdigit() and timestamp.split(",")[1].isdigit()
):
in_cookie = indiv_output = combined_output = ""
else:
low, high = [int(h, base=10) for h in timestamp.split(",")]
calc = 10**-7 * (high * 2**32 + low) - epochs["win_unix"]
if calc >= 32536799999 or calc < 0:
in_cookie = indiv_output = combined_output = ""
else:
dt_obj = dt.fromtimestamp(calc, timezone.utc)
in_cookie = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_cookie, tz_out
)
except Exception:
handle(sys.exc_info())
in_cookie = indiv_output = combined_output = ""
return in_cookie, indiv_output, combined_output, reason, tz_out
def to_cookie(dt_obj):
"""Convert a date to Internet Explorer timestamp values"""
ts_type, _, _, _ = ts_types["cookie"]
try:
unix_time = int(dt_obj.timestamp())
high = int(((unix_time + epochs["win_unix"]) * 10**7) / 2**32)
low = (
int((unix_time + epochs["win_unix"]) * 10**7)
- (high * 2**32)
+ (dt_obj.microsecond * 10)
)
out_cookie = f"{str(low)},{str(high)}"
ts_output, _ = format_output(ts_type, out_cookie)
except Exception:
handle(sys.exc_info())
out_cookie = ts_output = ""
return out_cookie, ts_output
def from_olebe(timestamp):
"""Convert an OLE Big-Endian timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["olebe"]
try:
if not len(timestamp) == 16 or not all(char in hexdigits for char in timestamp):
in_ole_be = indiv_output = combined_output = ""
else:
delta = struct.unpack(">d", struct.pack(">Q", int(timestamp, 16)))[0]
if int(delta) < 0 or int(delta) > 2e6:
in_ole_be = indiv_output = combined_output = ""
else:
dt_obj = epochs[1899] + timedelta(days=delta)
in_ole_be = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_ole_be, tz_out
)
except Exception:
handle(sys.exc_info())
in_ole_be = indiv_output = combined_output = ""
return in_ole_be, indiv_output, combined_output, reason, tz_out
def to_olebe(dt_obj):
"""Convert a date to an OLE Big-Endian timestamp"""
ts_type, _, _, _ = ts_types["olebe"]
try:
delta = ((dt_obj - epochs[1899]).total_seconds()) / 86400
conv = struct.unpack("<Q", struct.pack("<d", delta))[0]
out_ole_be = str(struct.pack(">Q", conv).hex())
ts_output, _ = format_output(ts_type, out_ole_be)
except Exception:
handle(sys.exc_info())
out_ole_be = ts_output = ""
return out_ole_be, ts_output
def from_olele(timestamp):
"""Convert an OLE Little-Endian timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["olele"]
try:
if not len(timestamp) == 16 or not all(char in hexdigits for char in timestamp):
in_ole_le = indiv_output = combined_output = ""
else:
to_le = hex(int.from_bytes(struct.pack("<Q", int(timestamp, 16)), "big"))
delta = struct.unpack(">d", struct.pack(">Q", int(to_le[2:], 16)))[0]
if int(delta) < 0 or int(delta) > 99999:
in_ole_le = indiv_output = combined_output = ""
else:
dt_obj = epochs[1899] + timedelta(days=delta)
in_ole_le = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_ole_le, tz_out
)
except Exception:
handle(sys.exc_info())
in_ole_le = indiv_output = combined_output = ""
return in_ole_le, indiv_output, combined_output, reason, tz_out
def to_olele(dt_obj):
"""Convert a date to an OLE Little-Endian timestamp"""
ts_type, _, _, _ = ts_types["olele"]
try:
delta = ((dt_obj - epochs[1899]).total_seconds()) / 86400
conv = struct.unpack("<Q", struct.pack("<d", delta))[0]
out_ole_le = str(struct.pack("<Q", conv).hex())
ts_output, _ = format_output(ts_type, out_ole_le)
except Exception:
handle(sys.exc_info())
out_ole_le = ts_output = ""
return out_ole_le, ts_output
def from_bplist(timestamp):
"""Convert a bplist NSDate timestamp to a date value"""
_, reason, _, tz_out = ts_types["bplist"]
if len(timestamp) == 9 and timestamp.isdigit():
in_nsdate, indiv_output, combined_output, reason, tz_out = from_nsdate(
timestamp, "bplist"
)
else:
in_nsdate = indiv_output = combined_output = ""
return in_nsdate, indiv_output, combined_output, reason, tz_out
def to_bplist(dt_obj):
"""Convert a date to a Binary Plist timestamp"""
ts_type, _, _, _ = ts_types["bplist"]
try:
out_bplist = str(int((dt_obj - epochs[2001]).total_seconds()))
if int(out_bplist) < 0:
out_bplist = "[!] Timestamp Boundary Exceeded [!]"
ts_output, _ = format_output(ts_type, out_bplist)
except Exception:
handle(sys.exc_info())
out_bplist = ts_output = ""
return out_bplist, ts_output
def from_iostime(timestamp):
"""Convert an iOS NSDate timestamp to a date value"""
_, reason, _, tz_out = ts_types["iostime"]
if len(timestamp) in range(15, 19) and timestamp.isdigit():
in_nsdate, indiv_output, combined_output, reason, tz_out = from_nsdate(
timestamp, "iostime"
)
else:
in_nsdate = indiv_output = combined_output = ""
return in_nsdate, indiv_output, combined_output, reason, tz_out
def to_iostime(dt_obj):
"""Convert a date to an iOS 11 timestamp"""
ts_type, _, _, _ = ts_types["iostime"]
try:
out_iostime = str(
int(((dt_obj - epochs[2001]).total_seconds()) * epochs["nano_2001"])
)
if int(out_iostime) < 0:
out_iostime = "[!] Timestamp Boundary Exceeded [!]"
ts_output, _ = format_output(ts_type, out_iostime)
except Exception:
handle(sys.exc_info())
out_iostime = ts_output = ""
return out_iostime, ts_output
def from_mac(timestamp):
"""Convert a mac NSDate timestamp to a date value"""
_, reason, _, tz_out = ts_types["mac"]
if (
"." in timestamp
and (
(len(timestamp.split(".")[0]) == 9)
and (len(timestamp.split(".")[1]) in range(0, 7))
)
and "".join(timestamp.split(".")).isdigit()
):
in_nsdate, indiv_output, combined_output, reason, tz_out = from_nsdate(
timestamp, "mac"
)
else:
in_nsdate = indiv_output = combined_output = ""
return in_nsdate, indiv_output, combined_output, reason, tz_out
def to_mac(dt_obj):
"""Convert a date to a Mac Absolute timestamp"""
ts_type, _, _, _ = ts_types["mac"]
try:
mac_ts = (
int(((dt_obj - epochs[2001]).total_seconds()) * epochs["nano_2001"])
/ 1000000000
)
if mac_ts < 0:
out_mac = "[!] Timestamp Boundary Exceeded [!]"
else:
out_mac = str(f"{mac_ts:.6f}")
ts_output, _ = format_output(ts_type, out_mac)
except Exception:
handle(sys.exc_info())
out_mac = ts_output = ""
return out_mac, ts_output
def from_nsdate(timestamp, val_type):
"""Convert an Apple NSDate timestamp (Mac Absolute, BPlist, Cocoa, iOS) to a date"""
ts_type, reason, _, tz_out = ts_types[val_type]
in_nsdate = indiv_output = combined_output = ""
try:
if val_type in {"mac", "bplist"}:
try:
dt_obj = epochs[2001] + timedelta(seconds=float(timestamp))
except (ValueError, OverflowError):
in_nsdate = indiv_output = combined_output = ""
return in_nsdate, indiv_output, combined_output, reason, tz_out
in_nsdate = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_nsdate, tz_out)
elif val_type == "iostime":
try:
dt_obj = (int(timestamp) / int(epochs["nano_2001"])) + 978307200
except (ValueError, OverflowError):
in_nsdate = indiv_output = combined_output = ""
return in_nsdate, indiv_output, combined_output, reason, tz_out
in_nsdate = dt.fromtimestamp(dt_obj, timezone.utc).strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_nsdate, tz_out)
except Exception:
handle(sys.exc_info())
in_nsdate = indiv_output = combined_output = ""
return in_nsdate, indiv_output, combined_output, reason, tz_out
def from_hfsdec(timestamp):
"""Convert a Mac OS/HFS+ Decimal Timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["hfsdec"]
try:
if len(str(timestamp)) != 10 or not (timestamp).isdigit():
in_hfs_dec = indiv_output = combined_output = ""
else:
minus_epoch = float(int(timestamp) - epochs["hfs_dec_sub"])
if minus_epoch < 0:
in_hfs_dec = indiv_output = combined_output = ""
else:
in_hfs_dec = dt.fromtimestamp(minus_epoch, timezone.utc).strftime(
__fmt__
)
indiv_output, combined_output = format_output(
ts_type, in_hfs_dec, tz_out
)
except Exception:
in_hfs_dec = indiv_output = combined_output = ""
handle(sys.exc_info())
return in_hfs_dec, indiv_output, combined_output, reason, tz_out
def to_hfsdec(dt_obj):
"""Convert a date to a Mac OS/HFS+ Decimal Timestamp"""
ts_type, _, _, _ = ts_types["hfsdec"]
try:
out_hfs_dec = str(int((dt_obj - epochs[1904]).total_seconds()))
ts_output, _ = format_output(ts_type, out_hfs_dec)
except Exception:
handle(sys.exc_info())
out_hfs_dec = ts_output = ""
return out_hfs_dec, ts_output
def from_hfsbe(timestamp):
"""Convert an HFS / HFS+ Big-Endian timestamp to a date (HFS+ is in UTC)"""
ts_type, reason, _, tz_out = ts_types["hfsbe"]
try:
if not len(timestamp) == 8 or not all(char in hexdigits for char in timestamp):
in_hfs_be = indiv_output = combined_output = ""
else:
dt_obj = epochs[1904] + timedelta(seconds=int(timestamp, 16))
in_hfs_be = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_hfs_be, tz_out)
except Exception:
handle(sys.exc_info())
in_hfs_be = indiv_output = combined_output = ""
return in_hfs_be, indiv_output, combined_output, reason, tz_out
def to_hfsbe(dt_obj):
"""Convert a date to an HFS / HFS+ Big-Endian timestamp"""
ts_type, _, _, _ = ts_types["hfsbe"]
try:
conv = int((dt_obj - epochs[1904]).total_seconds())
if conv > 4294967295:
out_hfs_be = "[!] Timestamp Boundary Exceeded [!]"
else:
out_hfs_be = f"{conv:08x}"
ts_output, _ = format_output(ts_type, out_hfs_be)
except Exception:
handle(sys.exc_info())
out_hfs_be = ts_output = ""
return out_hfs_be, ts_output
def from_hfsle(timestamp):
"""Convert an HFS / HFS+ Little-Endian timestamp to a date (HFS+ is in UTC)"""
ts_type, reason, _, tz_out = ts_types["hfsle"]
try:
if not len(timestamp) == 8 or not all(char in hexdigits for char in timestamp):
in_hfs_le = indiv_output = combined_output = ""
else:
to_le = struct.unpack(">I", struct.pack("<I", int(timestamp, 16)))[0]
dt_obj = epochs[1904] + timedelta(seconds=to_le)
in_hfs_le = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_hfs_le, tz_out)
except Exception:
handle(sys.exc_info())
in_hfs_le = indiv_output = combined_output = ""
return in_hfs_le, indiv_output, combined_output, reason, tz_out
def to_hfsle(dt_obj):
"""Convert a date to an HFS / HFS+ Little-Endian timestamp"""
ts_type, _, _, _ = ts_types["hfsle"]
try:
conv = int((dt_obj - epochs[1904]).total_seconds())
if conv > 4294967295:
out_hfs_le = "[!] Timestamp Boundary Exceeded [!]"
else:
out_hfs_le = str(struct.pack("<I", conv).hex())
ts_output, _ = format_output(ts_type, out_hfs_le)
except Exception:
handle(sys.exc_info())
out_hfs_le = ts_output = ""
return out_hfs_le, ts_output
def from_fat(timestamp):
"""Convert an MS-DOS wFatDate wFatTime timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["fat"]
try:
if not len(timestamp) == 8 or not all(char in hexdigits for char in timestamp):
in_fat = indiv_output = combined_output = ""
else:
byte_swap = [timestamp[i : i + 2] for i in range(0, len(timestamp), 2)]
to_le = byte_swap[1] + byte_swap[0] + byte_swap[3] + byte_swap[2]
binary = f"{int(to_le, 16):032b}"
stamp = [
binary[:7],
binary[7:11],
binary[11:16],
binary[16:21],
binary[21:27],
binary[27:32],
]
for binary in stamp[:]:
dec = int(binary, 2)
stamp.remove(binary)
stamp.append(dec)
fat_year = stamp[0] + 1980
fat_month = stamp[1]
fat_day = stamp[2]
fat_hour = stamp[3]
fat_min = stamp[4]
fat_sec = stamp[5] * 2
try:
out_of_range = any(
not low <= value < high
for value, (low, high) in zip(
(fat_year, fat_month, fat_day, fat_hour, fat_min, fat_sec),
(
(1970, 2100),
(1, 13),
(1, monthrange(fat_year, fat_month)[1] + 1),
(0, 24),
(0, 60),
(0, 60),
),
)
)
if out_of_range:
in_fat = indiv_output = combined_output = ""
return in_fat, indiv_output, combined_output, reason, tz_out
except (IllegalMonthError, ValueError):
in_fat = indiv_output = combined_output = ""
return in_fat, indiv_output, combined_output, reason, tz_out
dt_obj = dt(fat_year, fat_month, fat_day, fat_hour, fat_min, fat_sec)
in_fat = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_fat, tz_out)
except Exception:
handle(sys.exc_info())
in_fat = indiv_output = combined_output = ""
return in_fat, indiv_output, combined_output, reason, tz_out
def to_fat(dt_obj):
"""Convert a date to an MS-DOS wFatDate wFatTime timestamp"""
ts_type, _, _, _ = ts_types["fat"]
try:
year = f"{(dt_obj.year - 1980):07b}"
month = f"{dt_obj.month:04b}"
day = f"{dt_obj.day:05b}"
hour = f"{dt_obj.hour:05b}"
minute = f"{dt_obj.minute:06b}"
seconds = f"{int(dt_obj.second / 2):05b}"
to_hex = str(
struct.pack(
">I", int(year + month + day + hour + minute + seconds, 2)
).hex()
)
byte_swap = "".join([to_hex[i : i + 2] for i in range(0, len(to_hex), 2)][::-1])
out_fat = "".join(
[byte_swap[i : i + 4] for i in range(0, len(byte_swap), 4)][::-1]
)
ts_output, _ = format_output(ts_type, out_fat)
except Exception:
handle(sys.exc_info())
out_fat = ts_output = ""
return out_fat, ts_output
def from_msdos(timestamp):
"""Convert an MS-DOS timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["msdos"]
try:
if not len(timestamp) == 8 or not all(char in hexdigits for char in timestamp):
in_msdos = indiv_output = combined_output = ""
else:
swap = "".join(
[timestamp[i : i + 2] for i in range(0, len(timestamp), 2)][::-1]
)
binary = f"{int(swap, 16):032b}"
stamp = [
binary[:7],
binary[7:11],
binary[11:16],
binary[16:21],
binary[21:27],
binary[27:32],
]
for val in stamp[:]:
dec = int(val, 2)
stamp.remove(val)
stamp.append(dec)
dos_year = stamp[0] + 1980
dos_month = stamp[1]
dos_day = stamp[2]
dos_hour = stamp[3]
dos_min = stamp[4]
dos_sec = stamp[5] * 2
try:
out_of_range = any(
not low <= value < high
for value, (low, high) in zip(
(dos_year, dos_month, dos_day, dos_hour, dos_min, dos_sec),
(
(1970, 2100),
(1, 13),
(1, monthrange(dos_year, dos_month)[1] + 1),
(0, 24),
(0, 60),
(0, 60),
),
)
)
if out_of_range:
in_msdos = indiv_output = combined_output = ""
return in_msdos, indiv_output, combined_output, reason, tz_out
except (IllegalMonthError, ValueError):
in_msdos = indiv_output = combined_output = ""
return in_msdos, indiv_output, combined_output, reason, tz_out
dt_obj = dt(dos_year, dos_month, dos_day, dos_hour, dos_min, dos_sec)
in_msdos = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_msdos, tz_out)
except Exception:
handle(sys.exc_info())
in_msdos = indiv_output = combined_output = ""
return in_msdos, indiv_output, combined_output, reason, tz_out
def to_msdos(dt_obj):
"""Convert a date to an MS-DOS timestamp"""
ts_type, _, _, _ = ts_types["msdos"]
try:
year = f"{(dt_obj.year - 1980):07b}"
month = f"{dt_obj.month:04b}"
day = f"{dt_obj.day:05b}"
hour = f"{dt_obj.hour:05b}"
minute = f"{dt_obj.minute:06b}"
seconds = f"{int(dt_obj.second / 2):05b}"
hexval = str(
struct.pack(
">I", int(year + month + day + hour + minute + seconds, 2)
).hex()
)
out_msdos = "".join([hexval[i : i + 2] for i in range(0, len(hexval), 2)][::-1])
ts_output, _ = format_output(ts_type, out_msdos)
except Exception:
handle(sys.exc_info())
out_msdos = ts_output = ""
return out_msdos, ts_output
def from_exfat(timestamp):
"""Convert an exFAT timestamp (LE) to a date"""
ts_type, reason, _, tz_out = ts_types["exfat"]
try:
if not len(timestamp) == 8 or not all(char in hexdigits for char in timestamp):
in_exfat = indiv_output = combined_output = ""
else:
binary = f"{int(timestamp, 16):032b}"
stamp = [
binary[:7],
binary[7:11],
binary[11:16],
binary[16:21],
binary[21:27],
binary[27:32],
]
for val in stamp[:]:
dec = int(val, 2)
stamp.remove(val)
stamp.append(dec)
exfat_year = stamp[0] + 1980
exfat_month = stamp[1]
exfat_day = stamp[2]
exfat_hour = stamp[3]
exfat_min = stamp[4]
exfat_sec = stamp[5] * 2
try:
out_of_range = any(
not low <= value < high
for value, (low, high) in zip(
(
exfat_year,
exfat_month,
exfat_day,
exfat_hour,
exfat_min,
exfat_sec,
),
(
(1970, 2100),
(1, 13),
(1, monthrange(exfat_year, exfat_month)[1] + 1),
(0, 24),
(0, 60),
(0, 60),
),
)
)
if out_of_range:
in_exfat = indiv_output = combined_output = ""
return in_exfat, indiv_output, combined_output, reason, tz_out
except (IllegalMonthError, ValueError):
in_exfat = indiv_output = combined_output = ""
return in_exfat, indiv_output, combined_output, reason, tz_out
dt_obj = dt(
exfat_year, exfat_month, exfat_day, exfat_hour, exfat_min, exfat_sec
)
in_exfat = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_exfat, tz_out)
except Exception:
handle(sys.exc_info())
in_exfat = indiv_output = combined_output = ""
return in_exfat, indiv_output, combined_output, reason, tz_out
def to_exfat(dt_obj):
"""Convert a date to an exFAT timestamp (LE)"""
ts_type, _, _, _ = ts_types["exfat"]
try:
year = f"{(dt_obj.year - 1980):07b}"
month = f"{dt_obj.month:04b}"
day = f"{dt_obj.day:05b}"
hour = f"{dt_obj.hour:05b}"
minute = f"{dt_obj.minute:06b}"
seconds = f"{int(dt_obj.second / 2):05b}"
out_exfat = str(
struct.pack(
">I", int(year + month + day + hour + minute + seconds, 2)
).hex()
)
ts_output, _ = format_output(ts_type, out_exfat)
except Exception:
handle(sys.exc_info())
out_exfat = ts_output = ""
return out_exfat, ts_output
def from_systemtime(timestamp):
"""Convert a Microsoft 128-bit SYSTEMTIME timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["systemtime"]
try:
if not len(timestamp) == 32 or not all(char in hexdigits for char in timestamp):
in_systemtime = indiv_output = combined_output = ""
else:
to_le = "".join(
[timestamp[i : i + 2] for i in range(0, len(timestamp), 2)][::-1]
)
converted = [to_le[i : i + 4] for i in range(0, len(to_le), 4)][::-1]
stamp = []
for i in converted:
dec = int(i, 16)
stamp.append(dec)
if (stamp[0] > 3000) or (stamp[1] > 12) or (stamp[2] > 31):
in_systemtime = indiv_output = combined_output = ""
else:
dt_obj = dt(
stamp[0],
stamp[1],
stamp[3],
stamp[4],
stamp[5],
stamp[6],
stamp[7] * 1000,
)
in_systemtime = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_systemtime, tz_out
)
except Exception:
handle(sys.exc_info())
in_systemtime = indiv_output = combined_output = ""
return in_systemtime, indiv_output, combined_output, reason, tz_out
def to_systemtime(dt_obj):
"""Convert a date to a Microsoft 128-bit SYSTEMTIME timestamp"""
ts_type, _, _, _ = ts_types["systemtime"]
try:
micro = int(dt_obj.microsecond / 1000)
full_date = dt_obj.strftime(f"%Y, %m, %w, %d, %H, %M, %S, {micro}")
stamp = []
for val in full_date.split(","):
to_hex = int(
hex(int.from_bytes(struct.pack("<H", int(val)), "big"))[2:], 16
)
stamp.append(f"{to_hex:04x}")
out_systemtime = "".join(stamp)
ts_output, _ = format_output(ts_type, out_systemtime)
except Exception:
handle(sys.exc_info())
out_systemtime = ts_output = ""
return out_systemtime, ts_output
def from_filetimelohi(timestamp):
"""Convert a Microsoft FILETIME timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["filetimelohi"]
try:
if not (":" in timestamp) or not (
all(char in hexdigits for char in timestamp[0:8])
and all(char in hexdigits for char in timestamp[9:])
):
in_filetime_lo_hi = indiv_output = combined_output = ""
else:
part2, part1 = [int(h, base=16) for h in timestamp.split(":")]
converted_time = struct.unpack(">Q", struct.pack(">LL", part1, part2))[0]
if converted_time >= 1e18:
in_filetime_lo_hi = indiv_output = combined_output = ""
else:
dt_obj = dt.fromtimestamp(
float(converted_time - epochs["active"]) / epochs["hundreds_nano"],
timezone.utc,
)
in_filetime_lo_hi = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_filetime_lo_hi, tz_out
)
except Exception:
handle(sys.exc_info())
in_filetime_lo_hi = indiv_output = combined_output = ""
return in_filetime_lo_hi, indiv_output, combined_output, reason, tz_out
def to_filetimelohi(dt_obj):
"""Convert a date to a Microsoft FILETIME timestamp"""
ts_type, _, _, _ = ts_types["filetimelohi"]
try:
minus_epoch = dt_obj - epochs[1601]
calc_time = (
minus_epoch.microseconds
+ (minus_epoch.seconds * 1000000)
+ (minus_epoch.days * 86400000000)
)
indiv_output = str(struct.pack(">Q", int(calc_time * 10)).hex())
out_filetime_lo_hi = f"{str(indiv_output[8:])}:{str(indiv_output[:8])}"
ts_output, _ = format_output(ts_type, out_filetime_lo_hi)
except Exception:
handle(sys.exc_info())
out_filetime_lo_hi = ts_output = ""
return out_filetime_lo_hi, ts_output
def from_hotmail(timestamp):
"""Convert a Microsoft Hotmail timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["hotmail"]
try:
if ":" not in timestamp or not (
all(char in hexdigits for char in timestamp[0:8])
and all(char in hexdigits for char in timestamp[9:])
):
in_hotmail = indiv_output = combined_output = ""
else:
hm_repl = timestamp.replace(":", "")
byte_swap = "".join(
[hm_repl[i : i + 2] for i in range(0, len(hm_repl), 2)][::-1]
)
part2 = int(byte_swap[:8], base=16)
part1 = int(byte_swap[8:], base=16)
converted_time = struct.unpack(">Q", struct.pack(">LL", part1, part2))[0]
if converted_time >= 1e18:
in_hotmail = indiv_output = combined_output = ""
else:
dt_obj = dt.fromtimestamp(
float(converted_time - epochs["active"]) / epochs["hundreds_nano"],
timezone.utc,
)
in_hotmail = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_hotmail, tz_out
)
except Exception:
handle(sys.exc_info())
in_hotmail = indiv_output = combined_output = ""
return in_hotmail, indiv_output, combined_output, reason, tz_out
def to_hotmail(dt_obj):
"""Convert a date to a Microsoft Hotmail timestamp"""
ts_type, _, _, _ = ts_types["hotmail"]
try:
minus_epoch = dt_obj - epochs[1601]
calc_time = (
minus_epoch.microseconds
+ (minus_epoch.seconds * 1000000)
+ (minus_epoch.days * 86400000000)
)
indiv_output = str(struct.pack(">Q", int(calc_time * 10)).hex())
byte_swap = "".join(
[indiv_output[i : i + 2] for i in range(0, len(indiv_output), 2)][::-1]
)
out_hotmail = f"{str(byte_swap[8:])}:{str(byte_swap[:8])}"
ts_output, _ = format_output(ts_type, out_hotmail)
except Exception:
handle(sys.exc_info())
out_hotmail = ts_output = ""
return out_hotmail, ts_output
def from_prtime(timestamp):
"""Convert a Mozilla PRTime timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["prtime"]
try:
if not len(timestamp) == 16 or not timestamp.isdigit():
in_prtime = indiv_output = combined_output = ""
else:
dt_obj = epochs[1970] + timedelta(microseconds=int(timestamp))
in_prtime = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_prtime, tz_out)
except Exception:
handle(sys.exc_info())
in_prtime = indiv_output = combined_output = ""
return in_prtime, indiv_output, combined_output, reason, tz_out
def to_prtime(dt_obj):
"""Convert a date to Mozilla's PRTime timestamp"""
ts_type, _, _, _ = ts_types["prtime"]
try:
out_prtime = str(int(((dt_obj - epochs[1970]).total_seconds()) * 1000000))
ts_output, _ = format_output(ts_type, out_prtime)
except Exception:
handle(sys.exc_info())
out_prtime = ts_output = ""
return out_prtime, ts_output
def from_oleauto(timestamp):
"""Convert an OLE Automation timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["oleauto"]
try:
if (
"." not in timestamp
or not (
(len(timestamp.split(".")[0]) == 5)
and (len(timestamp.split(".")[1]) in range(9, 13))
)
or not "".join(timestamp.split(".")).isdigit()
):
in_ole_auto = indiv_output = combined_output = ""
else:
dt_obj = epochs[1899] + timedelta(days=float(timestamp))
in_ole_auto = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_ole_auto, tz_out)
except Exception:
handle(sys.exc_info())
in_ole_auto = indiv_output = combined_output = ""
return in_ole_auto, indiv_output, combined_output, reason, tz_out
def to_oleauto(dt_obj):
"""Convert a date to an OLE Automation timestamp"""
ts_type, _, _, _ = ts_types["oleauto"]
try:
ole_ts = ((dt_obj - epochs[1899]).total_seconds()) / 86400
out_ole_auto = f"{ole_ts:.12f}"
ts_output, _ = format_output(ts_type, out_ole_auto)
except Exception:
handle(sys.exc_info())
out_ole_auto = ts_output = ""
return out_ole_auto, ts_output
def from_ms1904(timestamp):
"""Convert a Microsoft Excel 1904 timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["ms1904"]
try:
if (
"." not in timestamp
or not (
(len(timestamp.split(".")[0]) == 5)
and (len(timestamp.split(".")[1]) in range(9, 13))
)
or not "".join(timestamp.split(".")).isdigit()
):
in_ms1904 = indiv_output = combined_output = ""
else:
dt_obj = epochs[1904] + timedelta(days=float(timestamp))
in_ms1904 = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_ms1904, tz_out)
except Exception:
handle(sys.exc_info())
in_ms1904 = indiv_output = combined_output = ""
return in_ms1904, indiv_output, combined_output, reason, tz_out
def to_ms1904(dt_obj):
"""Convert a date to a Microsoft Excel 1904 timestamp"""
ts_type, _, _, _ = ts_types["ms1904"]
try:
ms1904_ts = ((dt_obj - epochs[1904]).total_seconds()) / 86400
out_ms1904 = f"{ms1904_ts:.12f}"
ts_output, _ = format_output(ts_type, out_ms1904)
except Exception:
handle(sys.exc_info())
out_ms1904 = ts_output = ""
return out_ms1904, ts_output
def from_symantec(timestamp):
"""Convert a Symantec 6-byte hex timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["symantec"]
try:
if not len(timestamp) == 12 or not all(char in hexdigits for char in timestamp):
in_symtime = indiv_output = combined_output = ""
else:
hex_to_dec = [
int(timestamp[i : i + 2], 16) for i in range(0, len(timestamp), 2)
]
hex_to_dec[0] = hex_to_dec[0] + 1970
hex_to_dec[1] = hex_to_dec[1] + 1
if hex_to_dec[1] not in range(1, 13):
in_symtime = indiv_output = combined_output = ""
else:
try:
dt_obj = dt(
hex_to_dec[0],
hex_to_dec[1],
hex_to_dec[2],
hex_to_dec[3],
hex_to_dec[4],
hex_to_dec[5],
)
except ValueError:
in_symtime = indiv_output = combined_output = ""
return in_symtime, indiv_output, combined_output, reason, tz_out
in_symtime = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_symtime, tz_out)
except Exception:
handle(sys.exc_info())
in_symtime = indiv_output = combined_output = ""
return in_symtime, indiv_output, combined_output, reason, tz_out
def to_symantec(dt_obj):
"""Convert a date to Symantec's 6-byte hex timestamp"""
ts_type, _, _, _ = ts_types["symantec"]
try:
sym_year = f"{(dt_obj.year - 1970):02x}"
sym_month = f"{(dt_obj.month - 1):02x}"
sym_day = f"{(dt_obj.day):02x}"
sym_hour = f"{(dt_obj.hour):02x}"
sym_minute = f"{(dt_obj.minute):02x}"
sym_second = f"{(dt_obj.second):02x}"
out_symtime = (
f"{sym_year}{sym_month}{sym_day}{sym_hour}{sym_minute}{sym_second}"
)
ts_output, _ = format_output(ts_type, out_symtime)
except Exception:
handle(sys.exc_info())
out_symtime = ts_output = ""
return out_symtime, ts_output
def from_gps(timestamp):
"""Convert a GPS timestamp to a date (involves leap seconds)"""
ts_type, reason, _, tz_out = ts_types["gps"]
try:
if not len(timestamp) == 10 or not timestamp.isdigit():
in_gpstime = indiv_output = combined_output = ""
else:
gps_stamp = epochs[1980] + timedelta(seconds=float(timestamp))
tai_convert = gps_stamp + timedelta(seconds=19)
epoch_convert = (tai_convert - epochs[1970]).total_seconds()
check_date = dt.fromtimestamp(epoch_convert, timezone.utc)
for entry in leapseconds:
check = date_range(
leapseconds.get(entry)[0], leapseconds.get(entry)[1], check_date
)
if check is True:
variance = entry
else:
variance = 0
gps_out = check_date - timedelta(seconds=variance)
in_gpstime = gps_out.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_gpstime, tz_out)
except Exception:
handle(sys.exc_info())
in_gpstime = indiv_output = combined_output = ""
return in_gpstime, indiv_output, combined_output, reason, tz_out
def to_gps(dt_obj):
"""Convert a date to a GPS timestamp (involves leap seconds)"""
ts_type, _, _, _ = ts_types["gps"]
try:
for entry in leapseconds:
check = date_range(
leapseconds.get(entry)[0], leapseconds.get(entry)[1], dt_obj
)
if check is True:
variance = entry
else:
variance = 0
leap_correction = dt_obj + timedelta(seconds=variance)
epoch_shift = leap_correction - epochs[1970]
gps_stamp = (
dt.fromtimestamp(epoch_shift.total_seconds(), timezone.utc) - epochs[1980]
).total_seconds() - 19
out_gpstime = str(int(gps_stamp))
ts_output, _ = format_output(ts_type, out_gpstime)
except Exception:
handle(sys.exc_info())
out_gpstime = ts_output = ""
return out_gpstime, ts_output
def from_eitime(timestamp):
"""Convert a Google ei URL timestamp"""
ts_type, reason, _, tz_out = ts_types["eitime"]
try:
if not all(char in URLSAFE_CHARS for char in timestamp):
in_eitime = indiv_output = combined_output = ""
else:
padding_check = len(timestamp) % 4
if padding_check != 0:
padding_reqd = 4 - padding_check
result_eitime = timestamp + (padding_reqd * "=")
else:
result_eitime = timestamp
try:
decoded_eitime = base64.urlsafe_b64decode(result_eitime).hex()[:8]
unix_ts = int.from_bytes(
struct.pack("<L", int(decoded_eitime, 16)), "big"
)
in_eitime = dt.fromtimestamp(unix_ts, timezone.utc).strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_eitime, tz_out
)
except base64.binascii.Error:
in_eitime = indiv_output = combined_output = ""
except Exception:
handle(sys.exc_info())
in_eitime = indiv_output = combined_output = ""
return in_eitime, indiv_output, combined_output, reason, tz_out
def to_eitime(dt_obj):
"""Try to convert a value to an ei URL timestamp"""
ts_type, _, _, _ = ts_types["eitime"]
try:
unix_time = int((dt_obj - epochs[1970]).total_seconds())
unix_hex = struct.pack("<L", unix_time)
urlsafe_encode = base64.urlsafe_b64encode(unix_hex)
out_eitime = urlsafe_encode.decode(encoding="UTF-8").strip("=")
ts_output, _ = format_output(ts_type, out_eitime)
except Exception:
handle(sys.exc_info())
out_eitime = ts_output = ""
return out_eitime, ts_output
def from_gsm(timestamp):
"""Convert a GSM timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["gsm"]
# The last byte of the GSM timestamp is a hex representation of the timezone.
# If the timezone bitwise operation on this byte results in a timezone offset
# of less than -12 or greater than 12, then the value is incorrect.
# The values in tz_in_range are hex bytes which return proper timezones.
tz_in_range = [
"00",
"01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"0a",
"0b",
"0c",
"0d",
"0e",
"0f",
"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",
"80",
"81",
"82",
"83",
"84",
"85",
"86",
"87",
"88",
"89",
"8a",
"8b",
"8c",
"8d",
"8e",
"8f",
"90",
"91",
"92",
"93",
"94",
"95",
"96",
"97",
"98",
"99",
"a0",
"a1",
"a2",
"a3",
"a4",
"a5",
"a6",
"a7",
"a8",
"a9",
"b0",
"b1",
"b2",
"b3",
"b4",
"b5",
"b6",
"b7",
"b8",
"b9",
"c0",
"c1",
"c2",
"c3",
"c4",
"c5",
"c6",
"c7",
"c8",
]
try:
tz_check = timestamp[12:14][::-1].lower()
if (
not len(timestamp) == 14
or not all(char in hexdigits for char in timestamp)
or tz_check not in tz_in_range
):
in_gsm = indiv_output = combined_output = ""
else:
utc_offset = None
swap = [timestamp[i : i + 2] for i in range(0, len(timestamp), 2)]
for value in swap[:]:
l_endian = value[::-1]
swap.remove(value)
swap.append(l_endian)
ts_tz = f"{int(swap[6], 16):08b}"
if int(ts_tz[0]) == 1:
utc_offset = (
-int(str(int(ts_tz[1:4], 2)) + str(int(ts_tz[4:8], 2))) * 0.25
)
elif int(ts_tz[0]) == 0:
utc_offset = (
int(str(int(ts_tz[0:4], 2)) + str(int(ts_tz[4:8], 2))) * 0.25
)
swap[6] = utc_offset
for string in swap[:]:
swap.remove(string)
swap.append(int(string))
dt_year, dt_month, dt_day, dt_hour, dt_min, dt_sec, dt_tz = swap
if dt_year in range(0, 50):
dt_year = dt_year + 2000
if dt_tz == 0:
tz_out = f"{tz_out}"
elif dt_tz > 0:
tz_out = f"{tz_out}+{str(dt_tz)}"
else:
tz_out = f"{tz_out}{str(dt_tz)}"
in_gsm = str(
dt(dt_year, dt_month, dt_day, dt_hour, dt_min, dt_sec).strftime(__fmt__)
)
indiv_output, combined_output = format_output(ts_type, in_gsm, tz_out)
except ValueError:
in_gsm = indiv_output = combined_output = ""
except Exception:
handle(sys.exc_info())
in_gsm = indiv_output = combined_output = ""
return in_gsm, indiv_output, combined_output, reason, tz_out
def to_gsm(dt_obj):
"""Convert a timestamp to a GSM timestamp"""
ts_type, _, _, _ = ts_types["gsm"]
try:
dt_tz = dt_obj.utcoffset().seconds
if dt_tz == 0:
hex_tz = f"{0:02d}"
elif dt_tz < 0:
dt_tz = dt_tz / 3600
conversion = str(f"{(int(abs(dt_tz)) * 4):02d}")
conv_list = list(conversion)
high_order = f"{int(conv_list[0]):04b}"
low_order = f"{int(conv_list[1]):04b}"
high_order = f"{(int(high_order, 2) + 8):04b}"
hex_tz = hex(int((high_order + low_order), 2)).lstrip("0x").upper()
else:
dt_tz = dt_tz / 3600
conversion = str(int(dt_tz) * 4).zfill(2)
conv_list = list(conversion)
high_order = f"{int(conv_list[0]):04b}"
low_order = f"{int(conv_list[1]):04b}"
hex_tz = hex(int((high_order + low_order), 2)).lstrip("0x").upper()
date_list = [
f"{(dt_obj.year - 2000):02d}",
f"{dt_obj.month:02d}",
f"{dt_obj.day:02d}",
f"{dt_obj.hour:02d}",
f"{dt_obj.minute:02d}",
f"{dt_obj.second:02d}",
hex_tz,
]
date_value_swap = []
for value in date_list[:]:
b_endian = value[::-1]
date_value_swap.append(b_endian)
out_gsm = "".join(date_value_swap)
ts_output, _ = format_output(ts_type, out_gsm)
except Exception:
handle(sys.exc_info())
out_gsm = ts_output = ""
return out_gsm, ts_output
def from_vm(timestamp):
"""Convert from a .vmsd createTimeHigh/createTimeLow timestamp"""
ts_type, reason, _, tz_out = ts_types["vm"]
try:
if "," not in timestamp:
in_vm = indiv_output = combined_output = ""
else:
create_time_high = int(timestamp.split(",")[0])
create_time_low = int(timestamp.split(",")[1])
try:
vmsd = (
float(
(create_time_high * 2**32)
+ struct.unpack("I", struct.pack("i", create_time_low))[0]
)
/ 1000000
)
except Exception:
in_vm = indiv_output = combined_output = ""
return in_vm, indiv_output, combined_output, reason, tz_out
if vmsd >= 32536799999:
in_vm = indiv_output = combined_output = ""
else:
in_vm = dt.fromtimestamp(vmsd, timezone.utc).strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_vm, tz_out)
except Exception:
handle(sys.exc_info())
in_vm = indiv_output = combined_output = ""
return in_vm, indiv_output, combined_output, reason, tz_out
def to_vm(dt_obj):
"""Convert date to a .vmsd createTime* value"""
ts_type, _, _, _ = ts_types["vm"]
try:
unix_seconds = int((dt_obj - epochs[1970]).total_seconds()) * 1000000
create_time_high = int(float(unix_seconds) / 2**32)
unpacked_int = unix_seconds - (create_time_high * 2**32)
create_time_low = struct.unpack("i", struct.pack("I", unpacked_int))[0]
out_vm = f"{str(create_time_high)},{str(create_time_low)}"
ts_output, _ = format_output(ts_type, out_vm)
except Exception:
handle(sys.exc_info())
out_vm = ts_output = ""
return out_vm, ts_output
def from_tiktok(timestamp):
"""Convert a TikTok URL value to a date/time"""
ts_type, reason, _, tz_out = ts_types["tiktok"]
try:
if len(str(timestamp)) < 19 or not timestamp.isdigit():
in_tiktok = indiv_output = combined_output = ""
else:
unix_ts = int(timestamp) >> 32
if unix_ts >= 32536799999:
in_tiktok = indiv_output = combined_output = ""
else:
in_tiktok = dt.fromtimestamp(float(unix_ts), timezone.utc).strftime(
__fmt__
)
indiv_output, combined_output = format_output(ts_type, in_tiktok, tz_out)
except Exception:
handle(sys.exc_info())
in_tiktok = indiv_output = combined_output = ""
return in_tiktok, indiv_output, combined_output, reason, tz_out
def to_tiktok(dt_obj):
"""Convert a date/time to a TikTok timestamp"""
ts_type, _, _, _ = ts_types["tiktok"]
try:
unix_ts = int(dt_obj.timestamp())
out_tiktok = str(unix_ts << 32)
ts_output, _ = format_output(ts_type, out_tiktok)
except Exception:
handle(sys.exc_info())
out_tiktok = ts_output = ""
return out_tiktok, ts_output
def from_twitter(timestamp):
"""Convert a Twitter URL value to a date/time"""
ts_type, reason, _, tz_out = ts_types["twitter"]
try:
if len(str(timestamp)) < 18 or not timestamp.isdigit():
in_twitter = indiv_output = combined_output = ""
else:
unix_ts = ((int(timestamp) >> 22) + 1288834974657) / 1000
if unix_ts >= 32536799999:
in_twitter = indiv_output = combined_output = ""
else:
in_twitter = dt.fromtimestamp(float(unix_ts), timezone.utc).strftime(
__fmt__
)
indiv_output, combined_output = format_output(ts_type, in_twitter, tz_out)
except Exception:
handle(sys.exc_info())
in_twitter = indiv_output = combined_output = ""
return in_twitter, indiv_output, combined_output, reason, tz_out
def to_twitter(dt_obj):
"""Convert a date/time value to a Twitter value"""
ts_type, _, _, _ = ts_types["twitter"]
try:
unix_ts = (dt_obj.timestamp() * 1000) - 1288834974657
out_twitter = str(int(unix_ts) << 22)
ts_output, _ = format_output(ts_type, out_twitter)
except Exception:
handle(sys.exc_info())
out_twitter = ts_output = ""
return out_twitter, ts_output
def from_discord(timestamp):
"""Convert a Discord URL value to a date/time"""
ts_type, reason, _, tz_out = ts_types["discord"]
try:
if len(str(timestamp)) < 18 or not timestamp.isdigit():
in_discord = indiv_output = combined_output = ""
else:
unix_ts = ((int(timestamp) >> 22) + 1420070400000) / 1000
if unix_ts >= 32536799999:
in_discord = indiv_output = combined_output = ""
else:
in_discord = dt.fromtimestamp(float(unix_ts), timezone.utc).strftime(
__fmt__
)
indiv_output, combined_output = format_output(ts_type, in_discord, tz_out)
except Exception:
handle(sys.exc_info())
in_discord = indiv_output = combined_output = ""
return in_discord, indiv_output, combined_output, reason, tz_out
def to_discord(dt_obj):
"""Convert a date/time to a Discord URL value"""
ts_type, _, _, _ = ts_types["discord"]
try:
timestamp = int(dt_obj.timestamp() * 1000) - 1420070400000
out_discord = str(timestamp << 22)
ts_output, _ = format_output(ts_type, out_discord)
except Exception:
handle(sys.exc_info())
out_discord = ts_output = ""
return out_discord, ts_output
def from_ksalnum(timestamp):
"""Extract a timestamp from a KSUID alpha-numeric value"""
ts_type, reason, _, tz_out = ts_types["ksalnum"]
try:
if len(str(timestamp)) != 27 or not all(
char in KSALNUM_CHARS for char in timestamp
):
in_ksalnum = indiv_output = combined_output = ""
else:
length, i, variation = len(timestamp), 0, 0
b_array = bytearray()
for val in timestamp:
variation += KSALNUM_CHARS.index(val) * (62 ** (length - (i + 1)))
i += 1
while variation > 0:
b_array.append(variation & 0xFF)
variation //= 256
b_array.reverse()
ts_bytes = bytes(b_array)[0:4]
unix_ts = int.from_bytes(ts_bytes, "big", signed=False) + epochs["kstime"]
in_ksalnum = dt.fromtimestamp(float(unix_ts), timezone.utc).strftime(
__fmt__
)
indiv_output, combined_output = format_output(ts_type, in_ksalnum, tz_out)
except Exception:
handle(sys.exc_info())
in_ksalnum = indiv_output = combined_output = ""
return in_ksalnum, indiv_output, combined_output, reason, tz_out
def to_ksalnum(dt_obj):
"""Convert a date/time to a KSUID alpha-numeric value"""
ts_type, _, _, _ = ts_types["ksalnum"]
try:
out_ksalnum = ""
unix_ts = int(dt_obj.timestamp())
ts_bytes = (unix_ts - epochs["kstime"]).to_bytes(4, "big")
filler = os.urandom(16)
all_bytes = ts_bytes + filler
big_int = int.from_bytes(all_bytes, "big")
while big_int > 0:
big_int, rem = divmod(big_int, 62)
out_ksalnum = KSALNUM_CHARS[rem] + out_ksalnum
out_ksalnum = out_ksalnum.rjust(27, "0")
ts_output, _ = format_output(ts_type, out_ksalnum)
except Exception:
handle(sys.exc_info())
out_ksalnum = ts_output = ""
return out_ksalnum, ts_output
def from_mastodon(timestamp):
"""Convert a Mastodon value to a date/time"""
ts_type, reason, _, tz_out = ts_types["mastodon"]
try:
if len(str(timestamp)) < 18 or not timestamp.isdigit():
in_mastodon = indiv_output = combined_output = ""
else:
ts_conversion = int(timestamp) >> 16
unix_ts = float(ts_conversion) / 1000.0
if int(unix_ts) >= 32536799999:
in_mastodon = indiv_output = combined_output = ""
else:
in_mastodon = dt.fromtimestamp(unix_ts, timezone.utc).strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_mastodon, tz_out
)
except Exception:
handle(sys.exc_info())
in_mastodon = indiv_output = combined_output = ""
return in_mastodon, indiv_output, combined_output, reason, tz_out
def to_mastodon(dt_obj):
"""Convert a date/time to a Mastodon value"""
ts_type, _, _, _ = ts_types["mastodon"]
try:
unix_seconds = int((dt_obj - epochs[1970]).total_seconds()) * 1000
bit_shift = unix_seconds << 16
out_mastodon = f"{str(bit_shift)}"
ts_output, _ = format_output(ts_type, out_mastodon)
except Exception:
handle(sys.exc_info())
out_mastodon = ts_output = ""
return out_mastodon, ts_output
def from_metasploit(timestamp):
"""Convert a Metasploit Payload UUID value to a date/time"""
ts_type, reason, _, tz_out = ts_types["metasploit"]
meta_format = "8sBBBBBBBB"
try:
if len(str(timestamp)) < 22 or not all(
char in URLSAFE_CHARS for char in timestamp
):
in_metasploit = indiv_output = combined_output = ""
else:
b64decoded = base64.urlsafe_b64decode(timestamp[0:22] + "==")
if len(b64decoded) < struct.calcsize(meta_format):
in_metasploit = indiv_output = combined_output = ""
return in_metasploit, indiv_output, combined_output, reason, tz_out
(
_,
xor1,
xor2,
_,
_,
ts1_xored,
ts2_xored,
ts3_xored,
ts4_xored,
) = struct.unpack(meta_format, b64decoded)
unix_ts = struct.unpack(
">I",
bytes(
[
ts1_xored ^ xor1,
ts2_xored ^ xor2,
ts3_xored ^ xor1,
ts4_xored ^ xor2,
]
),
)[0]
in_metasploit = dt.fromtimestamp(float(unix_ts), timezone.utc).strftime(
__fmt__
)
indiv_output, combined_output = format_output(
ts_type, in_metasploit, tz_out
)
except Exception:
handle(sys.exc_info())
in_metasploit = indiv_output = combined_output = ""
return in_metasploit, indiv_output, combined_output, reason, tz_out
def from_sony(timestamp):
"""Convert a Sonyflake value to a date/time"""
ts_type, reason, _, tz_out = ts_types["sony"]
try:
if len(str(timestamp)) != 15 or not all(
char in hexdigits for char in timestamp
):
in_sony = indiv_output = combined_output = ""
else:
dec_value = int(timestamp, 16)
ts_value = dec_value >> 24
unix_ts = (ts_value + 140952960000) * 10
in_sony = dt.fromtimestamp(float(unix_ts) / 1000.0, timezone.utc).strftime(
__fmt__
)
indiv_output, combined_output = format_output(ts_type, in_sony, tz_out)
except Exception:
handle(sys.exc_info())
in_sony = indiv_output = combined_output = ""
return in_sony, indiv_output, combined_output, reason, tz_out
def to_sony(dt_obj):
"""Convert a date/time to a Sonyflake value"""
ts_type, _, _, _ = ts_types["sony"]
try:
dec_value = int((dt_obj.timestamp() * 100) - 140952960000)
out_sony = f"{(dec_value << 24):0x}"
ts_output, _ = format_output(ts_type, out_sony)
except Exception:
handle(sys.exc_info())
out_sony = ts_output = ""
return out_sony, ts_output
def from_uuid(timestamp):
"""Convert a UUID value to date/time"""
ts_type, reason, _, tz_out = ts_types["uuid"]
try:
uuid_lower = timestamp.lower()
uuid_regex = re.compile(
"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
)
if not bool(uuid_regex.match(uuid_lower)):
in_uuid = indiv_output = combined_output = ""
else:
u_data = uuid.UUID(uuid_lower)
if u_data.version == 1:
unix_ts = int((u_data.time / 10000) - 12219292800000)
in_uuid = dt.fromtimestamp(
float(unix_ts) / 1000.0, timezone.utc
).strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_uuid, tz_out)
else:
in_uuid = indiv_output = combined_output = ""
except Exception:
handle(sys.exc_info())
in_uuid = indiv_output = combined_output = ""
return in_uuid, indiv_output, combined_output, reason, tz_out
def to_uuid(dt_obj):
"""Convert a date/time value to a UUID"""
ts_type, _, _, _ = ts_types["uuid"]
try:
timestamp = int((dt_obj - epochs[1582]).total_seconds() * 1e7)
time_lo = timestamp & 0xFFFFFFFF
time_mid = (timestamp >> 32) & 0xFFFF
time_hi = (timestamp >> 48) & 0x0FFF
time_hi_ver_1 = time_hi | (1 << 12)
clock_seq = uuid.getnode() & 0x3FFF
clock_seq_hi_variant = (clock_seq >> 8) | 0x80
clock_seq_low = clock_seq & 0xFF
node = uuid.getnode()
out_uuid = str(
uuid.UUID(
fields=(
time_lo,
time_mid,
time_hi_ver_1,
clock_seq_hi_variant,
clock_seq_low,
node,
)
)
)
ts_output, _ = format_output(ts_type, out_uuid)
except Exception:
handle(sys.exc_info())
out_uuid = ts_output = ""
return out_uuid, ts_output
def from_dhcp6(timestamp):
"""Convert a DHCPv6 DUID value to date/time"""
ts_type, reason, _, tz_out = ts_types["dhcp6"]
try:
if len(str(timestamp)) < 28 or not all(char in hexdigits for char in timestamp):
in_dhcp6 = indiv_output = combined_output = ""
else:
dhcp6_bytes = timestamp[8:16]
dhcp6_dec = int(dhcp6_bytes, 16)
dhcp6_ts = epochs[2000] + timedelta(seconds=int(dhcp6_dec))
in_dhcp6 = dhcp6_ts.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_dhcp6, tz_out)
except Exception:
handle(sys.exc_info())
in_dhcp6 = indiv_output = combined_output = ""
return in_dhcp6, indiv_output, combined_output, reason, tz_out
def to_dhcp6(dt_obj):
"""Convert a timestamp to a DHCP DUID value"""
ts_type, _, _, _ = ts_types["dhcp6"]
try:
unix_time = int((dt_obj - epochs[2000]).total_seconds())
if int(unix_time) < 0:
out_dhcp6 = "[!] Timestamp Boundary Exceeded [!]"
else:
dhcp6_ts = str(struct.pack(">L", unix_time).hex())
out_dhcp6 = f"00010001{dhcp6_ts}000000000000"
ts_output, _ = format_output(ts_type, out_dhcp6)
except Exception:
handle(sys.exc_info())
out_dhcp6 = ts_output = ""
return out_dhcp6, ts_output
def from_dotnet(timestamp):
"""Convert a .NET DateTime Ticks value to date/time"""
ts_type, reason, _, tz_out = ts_types["dotnet"]
try:
if len(str(timestamp)) != 18 or not (timestamp).isdigit():
in_dotnet = indiv_output = combined_output = ""
else:
dotnet_to_umil = (int(timestamp) - epochs["ticks"]) / epochs[
"hundreds_nano"
]
if dotnet_to_umil < 0:
in_dotnet = indiv_output = combined_output = ""
else:
in_dotnet = dt.fromtimestamp(dotnet_to_umil, timezone.utc).strftime(
__fmt__
)
indiv_output, combined_output = format_output(ts_type, in_dotnet, tz_out)
except Exception:
handle(sys.exc_info())
in_dotnet = indiv_output = combined_output = ""
return in_dotnet, indiv_output, combined_output, reason, tz_out
def to_dotnet(dt_obj):
"""Convert date to a .NET DateTime Ticks value"""
ts_type, _, _, _ = ts_types["dotnet"]
try:
ts = dt_obj.timestamp() * epochs["hundreds_nano"]
out_dotnet = str(int(ts + epochs["ticks"]))
ts_output, _ = format_output(ts_type, out_dotnet)
except Exception:
handle(sys.exc_info())
out_dotnet = ts_output = ""
return out_dotnet, ts_output
def from_gbound(timestamp):
"""Convert a GMail Boundary value to date/time"""
ts_type, reason, _, tz_out = ts_types["gbound"]
try:
if len(str(timestamp)) != 28 or not all(
char in hexdigits for char in timestamp
):
in_gbound = indiv_output = combined_output = ""
else:
working_value = timestamp[12:26]
end = working_value[:6]
begin = working_value[6:14]
full_dec = int("".join(begin + end), 16)
in_gbound = dt.fromtimestamp(full_dec / 1000000, timezone.utc).strftime(
__fmt__
)
indiv_output, combined_output = format_output(ts_type, in_gbound, tz_out)
except Exception:
handle(sys.exc_info())
in_gbound = indiv_output = combined_output = ""
return in_gbound, indiv_output, combined_output, reason, tz_out
def to_gbound(dt_obj):
"""Convert date to a GMail Boundary value"""
ts_type, _, _, _ = ts_types["gbound"]
try:
to_int = int(((dt_obj - epochs[1970]).total_seconds()) * 1000000)
if len(f"{to_int:x}") < 14:
to_int = f"0{to_int:x}"
begin = to_int[8:]
end = to_int[:8]
out_gbound = f"000000000000{begin}{end}00"
ts_output, _ = format_output(ts_type, out_gbound)
except Exception:
handle(sys.exc_info())
out_gbound = ts_output = ""
return out_gbound, ts_output
def from_gmsgid(timestamp):
"""Convert a GMail Message ID to a date/time value"""
ts_type, reason, _, tz_out = ts_types["gmsgid"]
try:
gmsgid = timestamp
if str(gmsgid).isdigit() and len(str(gmsgid)) == 19:
gmsgid = str(f"{int(gmsgid):x}")
if len(str(gmsgid)) != 16 or not all(char in hexdigits for char in gmsgid):
in_gmsgid = indiv_output = combined_output = ""
else:
working_value = gmsgid[:11]
to_int = int(working_value, 16)
in_gmsgid = dt.fromtimestamp(to_int / 1000, timezone.utc).strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_gmsgid, tz_out)
except Exception:
handle(sys.exc_info())
in_gmsgid = indiv_output = combined_output = ""
return in_gmsgid, indiv_output, combined_output, reason, tz_out
def to_gmsgid(dt_obj):
"""Convert date to a GMail Message ID value"""
ts_type, _, _, _ = ts_types["gmsgid"]
try:
to_int = int(((dt_obj - epochs[1970]).total_seconds()) * 1000)
ts_hex = f"{to_int:x}"
out_gmsgid = f"{ts_hex}00000"
ts_output, _ = format_output(ts_type, out_gmsgid)
except Exception:
handle(sys.exc_info())
out_gmsgid = ts_output = ""
return out_gmsgid, ts_output
def from_moto(timestamp):
"""Convert a Motorola 6-byte hex timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["moto"]
try:
if len(str(timestamp)) != 12 or not all(
char in hexdigits for char in timestamp
):
in_moto = indiv_output = combined_output = ""
else:
hex_to_dec = [
int(timestamp[i : i + 2], 16) for i in range(0, len(timestamp), 2)
]
hex_to_dec[0] = hex_to_dec[0] + 1970
if hex_to_dec[1] not in range(1, 13):
in_moto = indiv_output = combined_output = ""
else:
try:
dt_obj = dt(
hex_to_dec[0],
hex_to_dec[1],
hex_to_dec[2],
hex_to_dec[3],
hex_to_dec[4],
hex_to_dec[5],
)
except ValueError:
in_moto = indiv_output = combined_output = ""
return in_moto, indiv_output, combined_output, reason, tz_out
in_moto = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_moto, tz_out)
except Exception:
handle(sys.exc_info())
in_moto = indiv_output = combined_output = ""
return in_moto, indiv_output, combined_output, reason, tz_out
def to_moto(dt_obj):
"""Convert a date to Motorola's 6-byte hex timestamp"""
ts_type, _, _, _ = ts_types["moto"]
try:
moto_year = f"{(dt_obj.year - 1970):02x}"
moto_month = f"{(dt_obj.month):02x}"
moto_day = f"{(dt_obj.day):02x}"
moto_hour = f"{(dt_obj.hour):02x}"
moto_minute = f"{(dt_obj.minute):02x}"
moto_second = f"{(dt_obj.second):02x}"
out_moto = str(
f"{moto_year}{moto_month}{moto_day}"
f"{moto_hour}{moto_minute}{moto_second}"
)
ts_output, _ = format_output(ts_type, out_moto)
except Exception:
handle(sys.exc_info())
out_moto = ts_output = ""
return out_moto, ts_output
def from_nokia(timestamp):
"""Convert a Nokia 4-byte value to date/time"""
ts_type, reason, _, tz_out = ts_types["nokia"]
try:
if not len(timestamp) == 8 or not all(char in hexdigits for char in timestamp):
in_nokia = indiv_output = combined_output = ""
else:
to_int = int(timestamp, 16)
int_diff = to_int ^ 4294967295
int_diff = ~int_diff + 1
unix_ts = int_diff + (epochs[2050] - epochs[1970]).total_seconds()
if unix_ts < 0:
in_nokia = indiv_output = combined_output = ""
else:
in_nokia = dt.fromtimestamp(unix_ts, timezone.utc).strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_nokia, tz_out)
except Exception:
handle(sys.exc_info())
in_nokia = indiv_output = combined_output = ""
return in_nokia, indiv_output, combined_output, reason, tz_out
def to_nokia(dt_obj):
"""Convert a date/time value to a Nokia 4-byte timestamp"""
ts_type, _, _, _ = ts_types["nokia"]
try:
unix_ts = (dt_obj - epochs[1970]).total_seconds()
int_diff = int(unix_ts - (epochs[2050] - epochs[1970]).total_seconds())
int_diff = int_diff - 1
dec_value = ~int_diff ^ 4294967295
out_nokia = f"{dec_value:x}"
ts_output, _ = format_output(ts_type, out_nokia)
except Exception:
handle(sys.exc_info())
out_nokia = ts_output = ""
return out_nokia, ts_output
def from_nokiale(timestamp):
"""Convert a little-endian Nokia 4-byte value to date/time"""
ts_type, reason, _, tz_out = ts_types["nokiale"]
try:
if not len(timestamp) == 8 or not all(char in hexdigits for char in timestamp):
in_nokiale = indiv_output = combined_output = ""
else:
to_be = "".join(
[timestamp[i : i + 2] for i in range(0, len(timestamp), 2)][::-1]
)
to_int = int(to_be, 16)
int_diff = to_int ^ 4294967295
int_diff = ~int_diff + 1
unix_ts = int_diff + (epochs[2050] - epochs[1970]).total_seconds()
if unix_ts < 0:
in_nokiale = indiv_output = combined_output = ""
else:
in_nokiale = dt.fromtimestamp(unix_ts, timezone.utc).strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_nokiale, tz_out
)
except Exception:
handle(sys.exc_info())
in_nokiale = indiv_output = combined_output = ""
return in_nokiale, indiv_output, combined_output, reason, tz_out
def to_nokiale(dt_obj):
"""Convert a date/time value to a little-endian Nokia 4-byte timestamp"""
ts_type, _, _, _ = ts_types["nokiale"]
try:
unix_ts = (dt_obj - epochs[1970]).total_seconds()
int_diff = int(unix_ts - (epochs[2050] - epochs[1970]).total_seconds())
int_diff = int_diff - 1
dec_val = ~int_diff ^ 4294967295
hex_val = f"{dec_val:x}"
out_nokiale = "".join(
[hex_val[i : i + 2] for i in range(0, len(hex_val), 2)][::-1]
)
ts_output, _ = format_output(ts_type, out_nokiale)
except Exception:
handle(sys.exc_info())
out_nokiale = ts_output = ""
return out_nokiale, ts_output
def from_ns40(timestamp):
"""Convert a Nokia S40 7-byte value to a time/time"""
ts_type, reason, _, tz_out = ts_types["ns40"]
try:
if not len(timestamp) == 14 or not all(char in hexdigits for char in timestamp):
in_ns40 = indiv_output = combined_output = ""
else:
ns40 = timestamp
ns40_val = {
"yr": ns40[:4],
"mon": ns40[4:6],
"day": ns40[6:8],
"hr": ns40[8:10],
"min": ns40[10:12],
"sec": ns40[12:],
}
for each_key, _ in ns40_val.items():
ns40_val[str(each_key)] = int(ns40_val[str(each_key)], 16)
if ns40_val["yr"] > 9999:
in_ns40 = indiv_output = combined_output = ""
elif (int(ns40_val["mon"]) > 12) or (int(ns40_val["mon"] < 1)):
in_ns40 = indiv_output = combined_output = ""
else:
in_ns40 = dt(
ns40_val["yr"],
ns40_val["mon"],
ns40_val["day"],
ns40_val["hr"],
ns40_val["min"],
ns40_val["sec"],
).strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_ns40, tz_out)
except Exception:
handle(sys.exc_info())
in_ns40 = indiv_output = combined_output = ""
return in_ns40, indiv_output, combined_output, reason, tz_out
def to_ns40(dt_obj):
"""Convert a date/time value to a Nokia S40 7-byte timestamp"""
ts_type, _, _, _ = ts_types["ns40"]
try:
hex_vals = []
hex_vals.append(f"{dt_obj.year:x}".zfill(4))
hex_vals.append(f"{dt_obj.month:x}".zfill(2))
hex_vals.append(f"{dt_obj.day:x}".zfill(2))
hex_vals.append(f"{dt_obj.hour:x}".zfill(2))
hex_vals.append(f"{dt_obj.minute:x}".zfill(2))
hex_vals.append(f"{dt_obj.second:x}".zfill(2))
out_ns40 = "".join(hex_vals)
ts_output, _ = format_output(ts_type, out_ns40)
except Exception:
handle(sys.exc_info())
out_ns40 = ts_output = ""
return out_ns40, ts_output
def from_ns40le(timestamp):
"""Convert a little-endian Nokia S40 7-byte value to a date/time"""
ts_type, reason, _, tz_out = ts_types["ns40le"]
try:
if len(str(timestamp)) != 14 or not all(
char in hexdigits for char in timestamp
):
in_ns40le = indiv_output = combined_output = ""
else:
ns40le = timestamp
ns40_val = {
"yr": "".join(
[ns40le[i : i + 2] for i in range(0, len(ns40le[:4]), 2)][::-1]
),
"mon": ns40le[4:6],
"day": ns40le[6:8],
"hr": ns40le[8:10],
"min": ns40le[10:12],
"sec": ns40le[12:],
}
for each_key, _ in ns40_val.items():
ns40_val[str(each_key)] = int(ns40_val[str(each_key)], 16)
if ns40_val["yr"] > 9999:
in_ns40le = indiv_output = combined_output = ""
elif (int(ns40_val["mon"]) > 12) or (int(ns40_val["mon"] < 1)):
in_ns40le = indiv_output = combined_output = ""
else:
in_ns40le = dt(
ns40_val["yr"],
ns40_val["mon"],
ns40_val["day"],
ns40_val["hr"],
ns40_val["min"],
ns40_val["sec"],
).strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_ns40le, tz_out)
except Exception:
handle(sys.exc_info())
in_ns40le = indiv_output = combined_output = ""
return in_ns40le, indiv_output, combined_output, reason, tz_out
def to_ns40le(dt_obj):
"""Convert a date/time value to a little-endian Nokia S40 7-byte timestamp"""
ts_type, _, _, _ = ts_types["ns40le"]
try:
hex_vals = []
year_le = f"{dt_obj.year:x}".zfill(4)
year_le = "".join(
[year_le[i : i + 2] for i in range(0, len(year_le[:4]), 2)][::-1]
)
hex_vals.append(f"{year_le}".zfill(4))
hex_vals.append(f"{dt_obj.month:x}".zfill(2))
hex_vals.append(f"{dt_obj.day:x}".zfill(2))
hex_vals.append(f"{dt_obj.hour:x}".zfill(2))
hex_vals.append(f"{dt_obj.minute:x}".zfill(2))
hex_vals.append(f"{dt_obj.second:x}".zfill(2))
out_ns40le = "".join(hex_vals)
ts_output, _ = format_output(ts_type, out_ns40le)
except Exception:
handle(sys.exc_info())
out_ns40le = ts_output = ""
return out_ns40le, ts_output
def from_bitdec(timestamp):
"""Convert a 10-digit Bitwise Decimal value to a date/time"""
ts_type, reason, _, tz_out = ts_types["bitdec"]
try:
if len(str(timestamp)) != 10 or not (timestamp).isdigit():
in_bitdec = indiv_output = combined_output = ""
else:
full_ts = int(timestamp)
bd_yr = full_ts >> 20
bd_mon = (full_ts >> 16) & 15
bd_day = (full_ts >> 11) & 31
bd_hr = (full_ts >> 6) & 31
bd_min = full_ts & 63
try:
in_bitdec = dt(bd_yr, bd_mon, bd_day, bd_hr, bd_min).strftime(__fmt__)
except ValueError:
in_bitdec = indiv_output = combined_output = ""
return in_bitdec, indiv_output, combined_output, reason, tz_out
indiv_output, combined_output = format_output(ts_type, in_bitdec, tz_out)
except Exception:
handle(sys.exc_info())
in_bitdec = indiv_output = combined_output = ""
return in_bitdec, indiv_output, combined_output, reason, tz_out
def to_bitdec(dt_obj):
"""Convert a date/time value to a Bitwise Decimal timestamp"""
ts_type, _, _, _ = ts_types["bitdec"]
try:
out_bitdec = str(
(dt_obj.year << 20)
+ (dt_obj.month << 16)
+ (dt_obj.day << 11)
+ (dt_obj.hour << 6)
+ (dt_obj.minute)
)
ts_output, _ = format_output(ts_type, out_bitdec)
except Exception:
handle(sys.exc_info())
out_bitdec = ts_output = ""
return out_bitdec, ts_output
def from_bitdate(timestamp):
"""Convert a Samsung/LG 4-byte hex timestamp to a date/time"""
ts_type, reason, _, tz_out = ts_types["bitdate"]
try:
if len(str(timestamp)) != 8 or not all(char in hexdigits for char in timestamp):
in_bitdate = indiv_output = combined_output = ""
else:
to_le = "".join(
[timestamp[i : i + 2] for i in range(0, len(str(timestamp)), 2)][::-1]
)
to_binary = f"{int(to_le, 16):032b}"
bitdate_yr = int(to_binary[:12], 2)
bitdate_mon = int(to_binary[12:16], 2)
bitdate_day = int(to_binary[16:21], 2)
bitdate_hr = int(to_binary[21:26], 2)
bitdate_min = int(to_binary[26:32], 2)
if bitdate_yr not in range(1900, 2500):
in_bitdate = indiv_output = combined_output = ""
return in_bitdate, indiv_output, combined_output, reason, tz_out
try:
in_bitdate = dt(
bitdate_yr, bitdate_mon, bitdate_day, bitdate_hr, bitdate_min
).strftime(__fmt__)
except ValueError:
in_bitdate = indiv_output = combined_output = ""
return in_bitdate, indiv_output, combined_output, reason, tz_out
indiv_output, combined_output = format_output(ts_type, in_bitdate, tz_out)
except Exception:
handle(sys.exc_info())
in_bitdate = indiv_output = combined_output = ""
return in_bitdate, indiv_output, combined_output, reason, tz_out
def to_bitdate(dt_obj):
"""Convert a date/time value to a Samsung/LG timestamp"""
ts_type, _, _, _ = ts_types["bitdate"]
try:
bitdate_yr = f"{dt_obj.year:012b}"
bitdate_mon = f"{dt_obj.month:04b}"
bitdate_day = f"{dt_obj.day:05b}"
bitdate_hr = f"{dt_obj.hour:05b}"
bitdate_min = f"{dt_obj.minute:06b}"
to_hex = str(
struct.pack(
">I",
int(
bitdate_yr + bitdate_mon + bitdate_day + bitdate_hr + bitdate_min, 2
),
).hex()
)
out_bitdate = "".join(
[to_hex[i : i + 2] for i in range(0, len(to_hex), 2)][::-1]
)
ts_output, _ = format_output(ts_type, out_bitdate)
except Exception:
handle(sys.exc_info())
out_bitdate = ts_output = ""
return out_bitdate, ts_output
def from_ksdec(timestamp):
"""Convert a KSUID decimal value to a date"""
ts_type, reason, _, tz_out = ts_types["ksdec"]
try:
if len(timestamp) != 9 or not timestamp.isdigit():
in_ksdec = indiv_output = combined_output = ""
else:
ts_val = int(timestamp) + int(epochs["kstime"])
in_ksdec = dt.fromtimestamp(float(ts_val), timezone.utc).strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_ksdec, tz_out)
except Exception:
handle(sys.exc_info())
in_ksdec = indiv_output = combined_output = ""
return in_ksdec, indiv_output, combined_output, reason, tz_out
def to_ksdec(dt_obj):
"""Convert date to a KSUID decimal value"""
ts_type, _, _, _ = ts_types["ksdec"]
try:
unix_ts = str(int((dt_obj - epochs[1970]).total_seconds()))
out_ksdec = str(int(unix_ts) - int(epochs["kstime"]))
if int(out_ksdec) < 0:
out_ksdec = "[!] Timestamp Boundary Exceeded [!]"
ts_output, _ = format_output(ts_type, out_ksdec)
except Exception:
handle(sys.exc_info())
out_ksdec = ts_output = ""
return out_ksdec, ts_output
def from_biomehex(timestamp):
"""Convert an Apple Biome Hex value to a date - from Little Endian"""
ts_type, reason, _, tz_out = ts_types["biomehex"]
try:
biomehex = str(timestamp)
if len(biomehex) != 16 or not all(char in hexdigits for char in biomehex):
in_biomehex = indiv_output = combined_output = ""
else:
if biomehex[:2] == "41":
biomehex = "".join(
[biomehex[i : i + 2] for i in range(0, len(biomehex), 2)][::-1]
)
byte_val = bytes.fromhex(str(biomehex))
nsdate_val = struct.unpack("<d", byte_val)[0]
if nsdate_val >= 1e17:
in_biomehex = indiv_output = combined_output = ""
else:
dt_obj = epochs[2001] + timedelta(seconds=float(nsdate_val))
in_biomehex = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_biomehex, tz_out
)
except Exception:
handle(sys.exc_info())
in_biomehex = indiv_output = combined_output = ""
return in_biomehex, indiv_output, combined_output, reason, tz_out
def to_biomehex(dt_obj):
"""Convert a date/time to an Apple Biome Hex value"""
ts_type, _, _, _ = ts_types["biomehex"]
try:
bplist_stamp = str(float((dt_obj - epochs[2001]).total_seconds()))
byte_biome = struct.pack(">d", float(bplist_stamp))
out_biomehex = bytes.hex(byte_biome)
ts_output, _ = format_output(ts_type, out_biomehex)
except Exception:
handle(sys.exc_info())
out_biomehex = ts_output = ""
return out_biomehex, ts_output
def from_biome64(timestamp):
"""Convert a 64-bit decimal value to a date/time value"""
ts_type, reason, _, tz_out = ts_types["biome64"]
try:
if len(timestamp) != 19 or not timestamp.isdigit():
in_biome64 = indiv_output = combined_output = ""
else:
nsdate_unpacked = int(
struct.unpack("<d", int(timestamp).to_bytes(8, "little"))[0]
)
if nsdate_unpacked >= 1e17:
in_biome64 = indiv_output = combined_output = ""
else:
dt_obj = epochs[2001] + timedelta(seconds=float(nsdate_unpacked))
in_biome64 = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_biome64, tz_out
)
except Exception:
handle(sys.exc_info())
in_biome64 = indiv_output = combined_output = ""
return in_biome64, indiv_output, combined_output, reason, tz_out
def to_biome64(dt_obj):
"""Convert a date/time value to a"""
ts_type, _, _, _ = ts_types["biome64"]
try:
nsdate_stamp = float((dt_obj - epochs[2001]).total_seconds())
out_biome64 = str(int.from_bytes(struct.pack(">d", nsdate_stamp), "big"))
ts_output, _ = format_output(ts_type, out_biome64)
except Exception:
handle(sys.exc_info())
out_biome64 = ts_output = ""
return out_biome64, ts_output
def from_s32(timestamp):
"""
Convert an S32 timestamp to a date/time value
"""
ts_type, reason, _, tz_out = ts_types["s32"]
try:
result = 0
timestamp = str(timestamp)
if len(timestamp) != 9 or not all(char in S32_CHARS for char in timestamp):
in_s32 = indiv_output = combined_output = ""
else:
for char in timestamp:
result = result * 32 + S32_CHARS.index(char)
dt_obj = dt.fromtimestamp(result / 1000.0, timezone.utc)
in_s32 = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_s32, tz_out)
except Exception:
handle(sys.exc_info())
in_s32 = indiv_output = combined_output = ""
return in_s32, indiv_output, combined_output, reason, tz_out
def to_s32(dt_obj):
"""Convert a date/time to an S32-encoded timestamp"""
ts_type, _, _, _ = ts_types["s32"]
try:
result = ""
index = 0
unix_mil = int(((dt_obj - epochs[1970]).total_seconds())) * 1000
while unix_mil:
index = unix_mil % 32
unix_mil = math.floor(unix_mil / 32)
result = S32_CHARS[index] + result
out_s32 = result
ts_output, _ = format_output(ts_type, out_s32)
except Exception:
handle(sys.exc_info())
out_s32 = ts_output = ""
return out_s32, ts_output
def from_apache(timestamp):
"""
Convert an Apache hex timestamp to a date/time value
This value has 13 hex characters, and does not fit a byte boundary
"""
ts_type, reason, _, tz_out = ts_types["apache"]
try:
timestamp = str(timestamp)
if len(timestamp) != 13 or not all(char in hexdigits for char in timestamp):
in_apache = indiv_output = combined_output = ""
else:
dec_val = int(timestamp, 16)
dt_obj = epochs[1970] + timedelta(microseconds=dec_val)
in_apache = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_apache, tz_out)
except Exception:
handle(sys.exc_info())
in_apache = indiv_output = combined_output = ""
return in_apache, indiv_output, combined_output, reason, tz_out
def to_apache(dt_obj):
"""Convert a date/time to an Apache cookie value"""
ts_type, _, _, _ = ts_types["apache"]
try:
apache_int = int(((dt_obj - epochs[1970]).total_seconds()) * 1000000)
out_apache = f"{apache_int:x}"
ts_output, _ = format_output(ts_type, out_apache)
except Exception:
handle(sys.exc_info())
out_apache = ts_output = ""
return out_apache, ts_output
def from_leb128hex(timestamp):
"""Convert a LEB 128 hex value to a date"""
ts_type, reason, _, tz_out = ts_types["leb128hex"]
try:
if not len(timestamp) % 2 == 0 or not all(
char in hexdigits for char in timestamp
):
in_leb128_hex = indiv_output = combined_output = ""
else:
ts_hex_list = [(timestamp[i : i + 2]) for i in range(0, len(timestamp), 2)]
unix_milli = 0
shift = 0
for hex_val in ts_hex_list:
byte_val = int(hex_val, 16)
unix_milli |= (byte_val & 0x7F) << shift
if (byte_val & 0x80) == 0:
break
shift += 7
in_leb128_hex, _, _, _, _ = from_unixmilli(str(unix_milli))
indiv_output, combined_output = format_output(
ts_type, in_leb128_hex, tz_out
)
except Exception:
handle(sys.exc_info())
in_leb128_hex = indiv_output = combined_output = ""
return in_leb128_hex, indiv_output, combined_output, reason, tz_out
def to_leb128hex(dt_obj):
"""Convert a date to a LEB128 hex value."""
ts_type, _, _, _ = ts_types["leb128hex"]
try:
unix_milli, _ = to_unixmilli(dt_obj)
unix_milli = int(unix_milli)
byte_list = []
while True:
byte_val = unix_milli & 0x7F
unix_milli >>= 7
if unix_milli != 0:
byte_val |= 0x80
byte_list.append(byte_val)
if unix_milli == 0:
break
out_leb128_hex = "".join([f"{byte_val:02x}" for byte_val in byte_list])
ts_output, _ = format_output(ts_type, out_leb128_hex)
except Exception:
handle(sys.exc_info())
out_leb128_hex = ts_output = ""
return out_leb128_hex, ts_output
def from_juliandec(timestamp):
"""Convert Julian Date decimal value to a date"""
ts_type, reason, _, tz_out = ts_types["juliandec"]
try:
if (
"." not in timestamp
or not (
(len(timestamp.split(".")[0]) == 7)
and (len(timestamp.split(".")[1]) in range(0, 11))
)
or not "".join(timestamp.split(".")).isdigit()
):
in_julian_dec = indiv_output = combined_output = ""
else:
try:
timestamp = float(timestamp)
except Exception:
timestamp = int(timestamp)
yr, mon, day, hr, mins, sec, mil = jd.to_gregorian(timestamp)
dt_vals = [yr, mon, day, hr, mins, sec, mil]
if any(val < 0 for val in dt_vals):
in_julian_dec = indiv_output = combined_output = ""
else:
in_julian_dec = (dt(yr, mon, day, hr, mins, sec, mil)).strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_julian_dec, tz_out
)
except Exception:
handle(sys.exc_info())
in_julian_dec = indiv_output = combined_output = ""
return in_julian_dec, indiv_output, combined_output, reason, tz_out
def to_juliandec(dt_obj):
"""Convert a date to a Julian Date"""
ts_type, _, _, _ = ts_types["juliandec"]
try:
out_julian_dec = str(
jd.from_gregorian(
dt_obj.year,
dt_obj.month,
dt_obj.day,
dt_obj.hour,
dt_obj.minute,
dt_obj.second,
)
)
ts_output, _ = format_output(ts_type, out_julian_dec)
except Exception:
handle(sys.exc_info())
out_julian_dec = ts_output = ""
return out_julian_dec, ts_output
def from_julianhex(timestamp):
"""Convert Julian Date hex value to a date"""
ts_type, reason, _, tz_out = ts_types["julianhex"]
try:
if not len(timestamp) // 2 == 7 or not all(
char in hexdigits for char in timestamp
):
in_julian_hex = indiv_output = combined_output = ""
else:
julianday = int(timestamp[:6], 16)
julianmil = int(timestamp[6:], 16)
julianmil = julianmil / 10 ** int((len(str(julianmil))))
julian_date = int(julianday) + int(julianmil)
yr, mon, day, hr, mins, sec, mil = jd.to_gregorian(julian_date)
dt_vals = [yr, mon, day, hr, mins, sec, mil]
if yr > 3000 or any(val < 0 for val in dt_vals):
in_julian_hex = indiv_output = combined_output = ""
else:
dt_obj = dt(yr, mon, day, hr, mins, sec, mil)
in_julian_hex = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_julian_hex, tz_out
)
except Exception:
handle(sys.exc_info())
in_julian_hex = indiv_output = combined_output = ""
return in_julian_hex, indiv_output, combined_output, reason, tz_out
def to_julianhex(dt_obj):
"""Convert a date to a Julian Hex Date"""
ts_type, _, _, _ = ts_types["julianhex"]
try:
jul_dec = jd.from_gregorian(
dt_obj.year,
dt_obj.month,
dt_obj.day,
dt_obj.hour,
dt_obj.minute,
dt_obj.second,
)
if isinstance(jul_dec, float):
left_val, right_val = str(jul_dec).split(".")
left_val = f"{int(left_val):06x}"
right_val = f"{int(right_val):08x}"
elif isinstance(jul_dec, int):
left_val = f"{jul_dec:06x}"
right_val = f"{0:08x}"
out_julian_hex = f"{str(left_val)}{str(right_val)}"
ts_output, _ = format_output(ts_type, out_julian_hex)
except Exception:
handle(sys.exc_info())
out_julian_hex = ts_output = ""
return out_julian_hex, ts_output
def from_semioctet(timestamp):
"""Convert from a Semi-Octet decimal value to a date"""
ts_type, reason, _, tz_out = ts_types["semioctet"]
try:
yr = mon = day = hr = mins = sec = None
if (
len(str(timestamp)) != 12
or len(str(timestamp)) != 14
and not str(timestamp).isdigit()
):
in_semi_octet = indiv_output = combined_output = ""
else:
if len(str(timestamp)) == 12:
yr, mon, day, hr, mins, sec = [
(a + b)[::-1] for a, b in zip(timestamp[::2], timestamp[1::2])
]
elif len(str(timestamp)) == 14:
yr, mon, day, hr, mins, sec, _ = [
(a + b)[::-1] for a, b in zip(timestamp[::2], timestamp[1::2])
]
try:
dt_obj = dt(
int(yr) + 2000, int(mon), int(day), int(hr), int(mins), int(sec)
)
except ValueError:
in_semi_octet = indiv_output = combined_output = ""
return in_semi_octet, indiv_output, combined_output, reason, tz_out
in_semi_octet = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(
ts_type, in_semi_octet, tz_out
)
except Exception:
handle(sys.exc_info())
in_semi_octet = indiv_output = combined_output = ""
return in_semi_octet, indiv_output, combined_output, reason, tz_out
def to_semioctet(dt_obj):
"""Convert a date to a Semi-Octet decimal value"""
ts_type, _, _, _ = ts_types["semioctet"]
try:
swap_list = []
ts_vals = [
str(f"{(dt_obj.year - 2000):02d}"),
str(f"{dt_obj.month:02d}"),
str(f"{dt_obj.day:02d}"),
str(f"{dt_obj.hour:02d}"),
str(f"{dt_obj.minute:02d}"),
str(f"{dt_obj.second:02d}"),
]
for each in ts_vals:
swap_list.append(each[::-1])
out_semi_octet = "".join(swap_list)
ts_output, _ = format_output(ts_type, out_semi_octet)
except Exception:
handle(sys.exc_info())
out_semi_octet = ts_output = ""
return out_semi_octet, ts_output
def from_ved(timestamp):
"""Convert from a VED urlsafe base64 encoded protobuf"""
ts_type, reason, _, tz_out = ts_types["ved"]
try:
if not all(char in URLSAFE_CHARS for char in timestamp):
in_ved = indiv_output = combined_output = ""
else:
decoded_ved = None
if timestamp[0].isdigit() and int(timestamp[0]) in range(0, 3):
timestamp = timestamp[1:]
padding_check = len(timestamp) % 4
if padding_check != 0:
padding_reqd = 4 - padding_check
result_ved = timestamp + (padding_reqd * "=")
else:
result_ved = timestamp
try:
decoded_ved = base64.urlsafe_b64decode(result_ved)
except base64.binascii.Error:
in_ved = indiv_output = combined_output = ""
try:
buff_content, _ = blackboxprotobuf.decode_message(decoded_ved)
except (DecoderException, TypeError):
in_ved = indiv_output = combined_output = ""
return in_ved, indiv_output, combined_output, reason, tz_out
if "13" in buff_content:
ved_ts = buff_content["13"]["1"]["1"]
in_ved = dt.fromtimestamp(ved_ts / 1000000, timezone.utc).strftime(
__fmt__
)
indiv_output, combined_output = format_output(ts_type, in_ved, tz_out)
else:
in_ved = indiv_output = combined_output = ""
except Exception:
handle(sys.exc_info())
in_ved = indiv_output = combined_output = ""
return in_ved, indiv_output, combined_output, reason, tz_out
def from_gclid(timestamp):
"""Convert from a gclid urlsafe base64 encoded protobuf"""
ts_type, reason, _, tz_out = ts_types["gclid"]
try:
if not all(char in URLSAFE_CHARS for char in timestamp):
in_gclid = indiv_output = combined_output = ""
else:
decoded_gclid = None
if timestamp[0].isdigit() and int(timestamp[0]) in range(0, 3):
timestamp = timestamp[1:]
padding_check = len(timestamp) % 4
if padding_check != 0:
padding_reqd = 4 - padding_check
result_gclid = timestamp + (padding_reqd * "=")
else:
result_gclid = timestamp
try:
decoded_gclid = base64.urlsafe_b64decode(result_gclid)
except base64.binascii.Error:
in_gclid = indiv_output = combined_output = ""
try:
buff_content, _ = blackboxprotobuf.decode_message(decoded_gclid)
except (DecoderException, TypeError):
in_gclid = indiv_output = combined_output = ""
return in_gclid, indiv_output, combined_output, reason, tz_out
if (
"1" in buff_content
and isinstance(buff_content["1"], int)
and len(str(buff_content["1"])) == 16
):
gclid_ts = buff_content["1"]
in_gclid = dt.fromtimestamp(gclid_ts / 1000000, timezone.utc).strftime(
__fmt__
)
indiv_output, combined_output = format_output(ts_type, in_gclid, tz_out)
else:
in_gclid = indiv_output = combined_output = ""
except Exception:
handle(sys.exc_info())
in_gclid = indiv_output = combined_output = ""
return in_gclid, indiv_output, combined_output, reason, tz_out
def from_linkedin(timestamp):
"""Convert from a LinkedIn Post Activity ID"""
ts_type, reason, _, tz_out = ts_types["linkedin"]
try:
if not str(timestamp).isdigit():
in_linkedin = indiv_output = combined_output = ""
else:
bin_convert = bin(int(timestamp))[2:43]
li_ts = int(bin_convert, 2) / 1000
in_linkedin = dt.fromtimestamp(li_ts, timezone.utc).strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_linkedin, tz_out)
except Exception:
handle(sys.exc_info())
in_linkedin = indiv_output = combined_output = ""
return in_linkedin, indiv_output, combined_output, reason, tz_out
def to_linkedin(dt_obj):
"""Convert a date/time to a LinkedIn Post Activity ID"""
ts_type, _, _, _ = ts_types["linkedin"]
padding = "1011100101100100110110"
try:
unix_ts = dt_obj.timestamp() * 1000
to_bin = bin(int(unix_ts))[2:43]
out_linkedin = str(int(to_bin + padding, 2))
ts_output, _ = format_output(ts_type, out_linkedin)
except Exception:
handle(sys.exc_info())
out_linkedin = ts_output = ""
return out_linkedin, ts_output
def from_ulid(timestamp):
"""Convert from a ULID value"""
ts_type, reason, _, tz_out = ts_types["ulid"]
try:
if (
not all(char in BASE32_CHARS for char in timestamp)
or len(str(timestamp)) != 26
):
in_ulid = indiv_output = combined_output = ""
else:
ulid_dt = ULID.parse(timestamp).datetime
in_ulid = ulid_dt.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_ulid, tz_out)
except Exception:
handle(sys.exc_info())
in_ulid = indiv_output = combined_output = ""
return in_ulid, indiv_output, combined_output, reason, tz_out
def to_ulid(dt_obj):
"""Convert a date to a ULID value"""
ts_type, _, _, _ = ts_types["ulid"]
try:
out_ulid = str(ULID.from_datetime(dt_obj))
ts_output, _ = format_output(ts_type, out_ulid)
except Exception:
handle(sys.exc_info())
out_ulid = ts_output = ""
return out_ulid, ts_output
def from_dttm(timestamp):
"""Convert a Microsoft DTTM timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["dttm"]
try:
if not len(timestamp) == 8 or not all(char in hexdigits for char in timestamp):
in_dttm = indiv_output = combined_output = ""
else:
int_ts = int(timestamp, 16)
binary = f"{int_ts:032b}"
stamp = [
binary[:3],
binary[3:12],
binary[12:16],
binary[16:21],
binary[21:26],
binary[26:32],
]
for binary in stamp[:]:
dec = int(binary, 2)
stamp.remove(binary)
stamp.append(dec)
dttm_dow = stamp[0]
dttm_year = stamp[1] + 1900
dttm_month = stamp[2]
dttm_dom = stamp[3]
dttm_hour = stamp[4]
dttm_min = stamp[5]
try:
out_of_range = any(
not low <= value < high
for value, (low, high) in zip(
(
dttm_dow,
dttm_year,
dttm_month,
dttm_dom,
dttm_hour,
dttm_min,
),
(
(0, 6),
(1900, 2050),
(1, 13),
(0, monthrange(dttm_year, dttm_month)[1] + 1),
(0, 24),
(0, 60),
),
)
)
if out_of_range:
in_dttm = indiv_output = combined_output = ""
return in_dttm, indiv_output, combined_output, reason, tz_out
except (IllegalMonthError, ValueError):
in_dttm = indiv_output = combined_output = ""
return in_dttm, indiv_output, combined_output, reason, tz_out
dt_obj = dt(dttm_year, dttm_month, dttm_dom, dttm_hour, dttm_min, 0)
in_dttm = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_dttm, tz_out)
except Exception:
handle(sys.exc_info())
in_dttm = indiv_output = combined_output = ""
return in_dttm, indiv_output, combined_output, reason, tz_out
def to_dttm(dt_obj):
"""Convert a date to a Microsoft DTTM timestamp"""
ts_type, _, _, _ = ts_types["dttm"]
try:
year = f"{(dt_obj.year - 1900):09b}"
month = f"{dt_obj.month:04b}"
day = f"{dt_obj.day:05b}"
hour = f"{dt_obj.hour:05b}"
minute = f"{dt_obj.minute:06b}"
dow = f"{dt_obj.isoweekday():03b}"
out_dttm = str(
struct.pack(">I", int(dow + year + month + day + hour + minute, 2)).hex()
)
ts_output, _ = format_output(ts_type, out_dttm)
except Exception:
handle(sys.exc_info())
out_dttm = ts_output = ""
return out_dttm, ts_output
def from_bcd(timestamp):
"""Convert a Binary Coded Decimal timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["bcd"]
try:
if len(timestamp) != 12 and not timestamp.isdigit():
in_bcd = indiv_output = combined_output = ""
else:
yr, mon, day, hr, mins, sec = [
timestamp[i : i + 2] for i in range(0, len(timestamp), 2)
]
yr, mon, day, hr, mins, sec = (
int(yr) + 2000,
int(mon),
int(day),
int(hr),
int(mins),
int(sec),
)
in_bcd = dt(yr, mon, day, hr, mins, sec, tzinfo=timezone.utc).strftime(
__fmt__
)
indiv_output, combined_output = format_output(ts_type, in_bcd, tz_out)
except ValueError:
in_bcd = indiv_output = combined_output = ""
except Exception:
handle(sys.exc_info())
in_bcd = indiv_output = combined_output = ""
return in_bcd, indiv_output, combined_output, reason, tz_out
def to_bcd(dt_obj):
"""Convert a date/time to a Binary Coded Decimal"""
ts_type, _, _, _ = ts_types["bcd"]
try:
yr, mon, day, hr, mins, sec = dt_obj.strftime("%Y-%m-%d-%H-%M-%S").split("-")
yr = str(int(yr) - 2000)
out_bcd = f"{yr}{mon}{day}{hr}{mins}{sec}"
ts_output, _ = format_output(ts_type, out_bcd)
except Exception:
handle(sys.exc_info())
out_bcd = ts_output = ""
return out_bcd, ts_output
def from_dvr(timestamp):
"""Convert a DVR (WFS / DHFS) file system timestamp to a date"""
ts_type, reason, _, tz_out = ts_types["dvr"]
try:
if not len(timestamp) == 8 or not all(char in hexdigits for char in timestamp):
in_dvr = indiv_output = combined_output = ""
else:
int_ts = int(timestamp, 16)
binary = f"{int_ts:032b}"
stamp = [
binary[:6],
binary[6:10],
binary[10:15],
binary[15:20],
binary[20:26],
binary[26:32],
]
for binary in stamp[:]:
dec = int(binary, 2)
stamp.remove(binary)
stamp.append(dec)
dvr_yr = stamp[0] + 2000
dvr_mon = stamp[1]
dvr_day = stamp[2]
dvr_hr = stamp[3]
dvr_min = stamp[4]
dvr_sec = stamp[5]
try:
out_of_range = any(
not low <= value < high
for value, (low, high) in zip(
(
dvr_yr,
dvr_mon,
dvr_day,
dvr_hr,
dvr_min,
dvr_sec,
),
(
(2000, 3000),
(1, 13),
(0, monthrange(dvr_yr, dvr_mon)[1] + 1),
(0, 24),
(0, 60),
(0, 60),
),
)
)
if out_of_range:
in_dvr = indiv_output = combined_output = ""
return in_dvr, indiv_output, combined_output, reason, tz_out
except (IllegalMonthError, ValueError):
in_dvr = indiv_output = combined_output = ""
return in_dvr, indiv_output, combined_output, reason, tz_out
dt_obj = dt(dvr_yr, dvr_mon, dvr_day, dvr_hr, dvr_min, dvr_sec)
in_dvr = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_dvr, tz_out)
except Exception:
handle(sys.exc_info())
in_dvr = indiv_output = combined_output = ""
return in_dvr, indiv_output, combined_output, reason, tz_out
def to_dvr(dt_obj):
"""Convert a date to a DVR (WFS / DHFS) file system timestamp"""
ts_type, _, _, _ = ts_types["dvr"]
try:
year = f"{(dt_obj.year - 2000):06b}"
month = f"{dt_obj.month:04b}"
day = f"{dt_obj.day:05b}"
hour = f"{dt_obj.hour:05b}"
minute = f"{dt_obj.minute:06b}"
sec = f"{dt_obj.second:06b}"
out_dvr = str(
struct.pack(">I", int(year + month + day + hour + minute + sec, 2)).hex()
)
ts_output, _ = format_output(ts_type, out_dvr)
except Exception:
handle(sys.exc_info())
out_dvr = ts_output = ""
return out_dvr, ts_output
def from_logtime(timestamp):
ts_type, reason, _, tz_out = ts_types["logtime"]
try:
if len(str(timestamp)) != 16 and not all(
char in hexdigits for char in timestamp
):
in_logtime = indiv_output = combined_output = ""
else:
vals = [int(timestamp[i:i+2], 16) for i in range(0, len(timestamp), 2)]
if len(vals) < 6:
in_logtime = indiv_output = combined_output = ""
return in_logtime, indiv_output, combined_output, reason, tz_out
dt_obj = dt(vals[5] + 1900, vals[4], vals[3], vals[2], vals[1], vals[0])
in_logtime = dt_obj.strftime(__fmt__)
indiv_output, combined_output = format_output(ts_type, in_logtime, tz_out)
except Exception:
handle(sys.exc_info())
in_logtime = indiv_output = combined_output = ""
return in_logtime, indiv_output, combined_output, reason, tz_out
def to_logtime(dt_obj):
ts_type, _, _, _ = ts_types["logtime"]
try:
vals = [dt_obj.second, dt_obj.minute, dt_obj.hour, dt_obj.day, dt_obj.month, dt_obj.year - 1900]
out_logtime = ''.join(f'{i:02X}' for i in vals) + '0000'
ts_output, _ = format_output(ts_type, out_logtime)
except Exception:
handle(sys.exc_info())
out_logtime = ts_output = ""
return out_logtime, ts_output
def date_range(start, end, check_date):
"""Check if date is in range of start and end, return True if it is"""
if start <= end:
return start <= check_date <= end
return start <= check_date or check_date <= end
def from_all(timestamps, tz_name=None):
"""Output all processed timestamp values and find date from provided timestamp"""
this_yr = int(dt.now(timezone.utc).strftime("%Y"))
full_list = {}
for _, funcs in single_funcs.items():
func = funcs[0]
func_name = func.__name__.replace("from_", "")
(result, _, combined_output, _, tz_out) = func(timestamps)
if result and combined_output:
if isinstance(result, str):
if tz_name is not None:
new_ts, new_tz, _ = convert_timezone(tz_name, result)
combined_output = combined_output.replace(result, new_ts)
combined_output = combined_output.replace(tz_out, new_tz)
tz_out = new_tz
result = new_ts
try:
ts = result.split(" ")[0]
result_yr = int(dt.fromisoformat(ts).strftime("%Y"))
except ValueError:
split_ts = result.split(" ")
ts = f"{split_ts[0]} {split_ts[1]}"
result_yr = int(dt.strptime(ts, __fmt__).strftime("%Y"))
if result_yr not in range(this_yr - 5, this_yr + 5):
combined_output = combined_output.strip(__red__).strip(__clr__)
full_list[func_name] = [result, combined_output, tz_out]
return full_list
def to_timestamps(dt_obj, tz_name=None):
"""Convert provided date to all timestamps"""
results = {}
ts_outputs = []
if isinstance(dt_obj, str):
try:
dt_obj = dt.fromisoformat(dt_obj)
except ValueError:
dt_obj = dt.strptime(dt_obj, __fmt__)
except Exception as exc:
print(
f"[!] Check that your input timestamp follows the format: 'YYYY-MM-DD HH:MM:SS'\n"
f"[!] with '.ffffff' for milliseconds and '+/-HH:MM' for timezones\n"
f"[!] or use --date-formats to pick a format and use the --date-format NAME:\n{exc}"
)
sys.exit(1)
if dt_obj.tzinfo is None and tz_name is None:
dt_obj = dt_obj.replace(tzinfo=timezone.utc)
elif tz_name is not None:
tz = tzone(tz_name)
dt_obj = dt_obj.replace(tzinfo=tz)
for _, funcs in single_funcs.items():
func = funcs[1]
if not func:
continue
result, ts_output = func(dt_obj)
func_name = (func.__name__).replace("to_", "")
if result and isinstance(result, str):
results[func_name] = result
ts_outputs.append(ts_output)
return results, ts_outputs
def gui():
"""Execute the application"""
try:
from ctypes import windll
app_id = f"digitalsleuth.time-decode.gui.v{__version__.replace('.','-')}"
windll.shell32.SetCurrentProcessExplicitAppUserModelID(app_id)
except ImportError:
pass
td_app = QApplication([__appname__, "windows:darkmode=2"])
td_app.setApplicationDisplayName(__appname__)
td_app.setApplicationName(__appname__)
icon = QPixmap()
icon.loadFromData(base64.b64decode(TimeDecodeGui.__fingerprint__))
td_app.setWindowIcon(QIcon(icon))
td_app.setStyle("Fusion")
td_form = TimeDecodeGui()
td_form.show()
td_app.exec()
def handle(error):
"""Error handling output and formatting to include function causing error"""
exc_type, exc_obj, _ = error
error_tb = traceback.extract_stack()[:-3] + traceback.extract_tb(
exc_obj.__traceback__
)
_, line_no, function_name, _ = error_tb[-1]
print(f"{str(exc_type.__name__)}: {str(exc_obj)} - {function_name} line {line_no}")
def formats(display="ALL"):
"""Displays a PrettyTable output of examples of all timestamps and their formats"""
structures = {}
for arg, data_list in ts_types.items():
structures[data_list[0]] = (data_list[1], data_list[2], arg)
structures = sorted(structures.items(), key=lambda item: item[0].casefold())
table = PrettyTable()
table.set_style(TableStyle.SINGLE_BORDER)
table.align = "l"
table.field_names = ["Type", "Format", "Example", "Argument"]
for structure in structures:
ts_type, details = structure
argument = f"--{details[2]}"
if display == "ALL":
table.add_row([ts_type, details[0], details[1], argument])
elif details[2] == display:
table.add_row([ts_type, details[0], details[1], argument])
print(table)
print("* BE = Big-Endian / LE = Little-Endian")
def format_output(ts_type, ts, tz=None):
"""Format the output of the timestamp functions"""
tabs = ""
if len(ts_type) < 15:
tabs = "\t\t\t"
elif len(ts_type) in range(15, 23):
tabs = "\t\t"
elif len(ts_type) in range(23, 32):
tabs = "\t"
if tz:
indiv_output = f"{ts_type}: {ts} {tz}"
combined_output = f"{__red__}{ts_type}:{tabs}{ts} {tz}{__clr__}"
else:
indiv_output = f"{ts_type}:{tabs}{ts}"
combined_output = None
return indiv_output, combined_output
def tzdata_timezones():
"""Return available system timezones for the dropdown"""
return sorted(
tz for tz in available_timezones()
if not tz.startswith(("posix", "right"))
)
def common_timezone_offsets(dt_obj):
"""Generates a list of all tzdata timezones for conversion, sorted by UTC offset"""
timezone_offsets = [("UTC - Default", "")]
duplicates = [
"Factory",
"Zulu",
"Etc\\Zulu",
"Etc\\UTC",
"GMT-0",
"GMT+0",
"Etc\\Universal",
"GMT0",
"UCT",
"Etc\\Greenwich",
"Etc\\GMT",
"Etc\\GMT+0",
"Etc\\GMT-0",
"Etc\\GMT0",
"Etc\\UCT",
"Universal",
]
for tz_name in tzdata_timezones():
if tz_name in duplicates:
continue
try:
set_timezone = tzone(tz_name)
dt_val = dt_obj.astimezone(set_timezone)
offset_tz = dt_val.utcoffset()
if offset_tz is None:
continue
offset_seconds = offset_tz.total_seconds()
hours, remainder = divmod(abs(offset_seconds), 3600)
minutes = remainder // 60
sign = "+" if offset_seconds >= 0 else "-"
int_offset = f"{sign}{int(hours):02}:{int(minutes):02}"
formatted_offset = f"UTC{int_offset}"
timezone_offsets.append((formatted_offset, tz_name))
except Exception:
continue
timezone_offsets.sort(key=lambda x: x[0])
return timezone_offsets
def generate_csv(src_file, ts_choice, column_num=None, tz_name=None):
"""Loads a CSV file, reads a column and decodes the timestamps from the selected format"""
ts_func = single_funcs[ts_choice][0]
src_file = os.path.normpath(os.path.abspath(src_file))
dst_file = f"{os.path.splitext(src_file)[0]}_out.csv"
status = False
reason = None
csv_output = []
if isinstance(column_num, str) and not column_num.isdigit():
if len(column_num) == 1:
column_num = int(ascii_lowercase.index(column_num.lower()))
else:
return status, dst_file, reason
elif isinstance(column_num, str) and column_num.isdigit():
column_num = int(column_num)
if column_num > 0:
column_num -= 1
elif column_num < 0:
column_num = 0
elif isinstance(column_num, int):
if column_num > 0:
column_num -= 1
elif column_num < 0:
column_num = 0
elif column_num is None:
column_num = 0
try:
with open(src_file, "r", newline="", encoding="utf-8") as src, open(
dst_file, "w", newline="", encoding="utf-8"
) as dst:
sample = src.read(2048)
try:
dialect = csv.Sniffer().sniff(sample)
except csv.Error:
dialect = csv.get_dialect("excel")
try:
has_header = csv.Sniffer().has_header(sample)
except csv.Error:
has_header = False
header_check = sample.count(",")
content = sample.split("\n")
if header_check == 0:
line_one = content[0]
line_two = content[1]
if len(line_one) != len(line_two):
has_header = True
elif len(content[0].split(",")[0]) != len(content[1].split(",")[1]):
has_header = True
src.seek(0)
reader = csv.reader(src, dialect)
columns = len(next(reader, None))
src.seek(0)
if has_header:
header = next(reader)
if column_num > columns:
reason = "The selected column number is higher than the amount of actual columns."
return status, dst_file, reason
for row in reader:
ts = row[column_num]
results = ts_func(ts)
result = results[0]
reason = results[3]
if result == "":
return status, dst_file, reason
if tz_name is not None:
new_result, new_tz, _ = convert_timezone(tz_name, result)
if new_tz.startswith("+") or new_tz.startswith("-"):
result = f"{new_result}{new_tz}"
else:
result = f"{new_result} {new_tz}"
row.append(result)
csv_output.append(row)
writer = csv.writer(dst, quotechar='"', quoting=csv.QUOTE_MINIMAL)
if has_header:
header.append(f"{ts_choice}_ts")
writer.writerow(header)
for row in csv_output:
writer.writerow(row)
status = True
except (FileNotFoundError, PermissionError):
handle(sys.exc_info())
status = False
return status, dst_file, reason
def convert_timezone(tz_name, dt_val):
"""Separate function to take a string date/time and convert it to the identified time zone"""
tz = tzone(tz_name)
try:
dt_obj = dt.fromisoformat(dt_val).replace(tzinfo=timezone.utc)
except ValueError:
dt_obj = dt.strptime(dt_val, __fmt__).replace(tzinfo=timezone.utc)
tz_change = dt_obj.astimezone(tz)
tz_offset = tz_change.strftime("%z")
tz_offset = f"{tz_offset[:3]}:{tz_offset[3:]}"
tz_selected = tz_change.strftime(__fmt__)
if check_daylight(dt_obj, tz):
tz_out = f"{tz_offset} DST"
else:
tz_out = tz_offset
return tz_selected, tz_out, tz_change
def check_daylight(dtval, tz):
"""Checks to see if the provided timestamp, in the provided timezone, is observing DST"""
if dtval.tzinfo is None:
dtval = dtval.replace(tzinfo=tz)
else:
dtval = dtval.astimezone(tz)
return dtval.dst() != timedelta(0, 0)
def list_timezones():
"""Displays all available time zone conversion options in a PrettyTable"""
tzs = common_timezone_offsets(dt.now(timezone.utc))
tzs = tzs[1:]
tzs.sort(key=lambda x: x[1])
table = PrettyTable()
table.set_style(TableStyle.SINGLE_BORDER)
table.align = "l"
table.field_names = ["Time Zone Name", "Current Offset"]
for tz in tzs:
table.add_row([tz[1], tz[0]])
print(table)
print(f"* Based on the current date/time of {dt.now(timezone.utc)}")
def list_date_formats():
"""Displays available date/time format strings"""
table = PrettyTable()
table.set_style(TableStyle.SINGLE_BORDER)
table.align = "l"
table.field_names = ["Name", "Format"]
for k, v in date_formats.items():
table.add_row([k, v.replace("%", "")])
print(table)
single_funcs = {
"active": [from_active, to_active],
"apache": [from_apache, to_apache],
"biome64": [from_biome64, to_biome64],
"biomehex": [from_biomehex, to_biomehex],
"bplist": [from_bplist, to_bplist],
"iostime": [from_iostime, to_iostime],
"mac": [from_mac, to_mac],
"bcd": [from_bcd, to_bcd],
"bitdate": [from_bitdate, to_bitdate],
"bitdec": [from_bitdec, to_bitdec],
"dhcp6": [from_dhcp6, to_dhcp6],
"discord": [from_discord, to_discord],
"dvr": [from_dvr, to_dvr],
"exfat": [from_exfat, to_exfat],
"fat": [from_fat, to_fat],
"gbound": [from_gbound, to_gbound],
"gmsgid": [from_gmsgid, to_gmsgid],
"chrome": [from_chrome, to_chrome],
"eitime": [from_eitime, to_eitime],
"gclid": [from_gclid, None],
"ved": [from_ved, None],
"gps": [from_gps, to_gps],
"gsm": [from_gsm, to_gsm],
"hfsbe": [from_hfsbe, to_hfsbe],
"hfsle": [from_hfsle, to_hfsle],
"hfsdec": [from_hfsdec, to_hfsdec],
"logtime": [from_logtime, to_logtime],
"juliandec": [from_juliandec, to_juliandec],
"julianhex": [from_julianhex, to_julianhex],
"ksalnum": [from_ksalnum, to_ksalnum],
"ksdec": [from_ksdec, to_ksdec],
"leb128hex": [from_leb128hex, to_leb128hex],
"linkedin": [from_linkedin, to_linkedin],
"mastodon": [from_mastodon, to_mastodon],
"metasploit": [from_metasploit, None],
"dotnet": [from_dotnet, to_dotnet],
"systemtime": [from_systemtime, to_systemtime],
"dttm": [from_dttm, to_dttm],
"ms1904": [from_ms1904, to_ms1904],
"hotmail": [from_hotmail, to_hotmail],
"msdos": [from_msdos, to_msdos],
"moto": [from_moto, to_moto],
"prtime": [from_prtime, to_prtime],
"ns40": [from_ns40, to_ns40],
"ns40le": [from_ns40le, to_ns40le],
"nokia": [from_nokia, to_nokia],
"nokiale": [from_nokiale, to_nokiale],
"s32": [from_s32, to_s32],
"semioctet": [from_semioctet, to_semioctet],
"sony": [from_sony, to_sony],
"symantec": [from_symantec, to_symantec],
"tiktok": [from_tiktok, to_tiktok],
"twitter": [from_twitter, to_twitter],
"ulid": [from_ulid, to_ulid],
"unixhex32be": [from_unixhex32be, to_unixhex32be],
"unixhex32le": [from_unixhex32le, to_unixhex32le],
"unixmilli": [from_unixmilli, to_unixmilli],
"unixmillihex": [from_unixmillihex, to_unixmillihex],
"unixsec": [from_unixsec, to_unixsec],
"uuid": [from_uuid, to_uuid],
"vm": [from_vm, to_vm],
"cookie": [from_cookie, to_cookie],
"filetimelohi": [from_filetimelohi, to_filetimelohi],
"filetimebe": [from_filetimebe, to_filetimebe],
"filetimele": [from_filetimele, to_filetimele],
"olebe": [from_olebe, to_olebe],
"olele": [from_olele, to_olele],
"oleauto": [from_oleauto, to_oleauto],
}
__types__ = len(single_funcs)
def main():
"""Parse all passed arguments"""
global __fmt__
now = dt.now(timezone.utc).strftime(__fmt__)
arg_parse = argparse.ArgumentParser(
description=f"Time Decoder and Converter v"
f"{str(__version__)} - supporting "
f"{str(__types__)} timestamps!\n\n"
f"Some timestamps are only part of the entire value, and as such, full\n"
f"timestamps may not be generated based on only the date/time portion.",
formatter_class=argparse.RawTextHelpFormatter,
usage=argparse.SUPPRESS,
)
arg_parse.add_argument(
"--csv",
metavar="SRC_FILE TS_FORMAT <column-number>",
help=(
"Process a csv/txt file with timestamps and convert them to the selected timestamp\n"
"Requires a timestamp format be provided without --. ie. 'unixsec' vice '--unixsec'.\n"
"You can also provide a column number if your input file contains multiple columns."
),
nargs="*",
)
arg_parse.add_argument(
"--date-format",
metavar="FORMAT_NAME",
help=(
"Changes the output format of a date/time value.\n"
"Use the NAME for the format provided.\n"
"Use --date-formats to see all available options."
),
type=str,
default="Default",
)
arg_parse.add_argument(
"--date-formats",
action="store_true",
help="Displays available date formats for the output of a date/time value",
)
arg_parse.add_argument(
"--formats",
metavar="ARGUMENT",
help=(
"Display timestamp format and example by providing an available argument (without --)."
"\nIf no argument is selected, all will be displayed."
),
nargs="?",
const="ALL",
)
arg_parse.add_argument(
"--guess",
metavar="TIMESTAMP",
help="Guess the timestamp format and output possibilities",
)
arg_parse.add_argument(
"--gui",
"-g",
action="store_true",
help="Launch the gui",
)
arg_parse.add_argument(
"--minimal",
"-m",
action="store_true",
help="Output only the timestamp, not the description",
)
arg_parse.add_argument(
"--to",
action="store_true",
help="Convert a date/time to a selected timestamp format",
)
arg_parse.add_argument(
"--timestamp",
metavar="DATE",
help=(
"Convert date to every timestamp\n"
'Enter date as "YYYY-MM-DD HH:MM:SS.f" in 24h fmt\n'
"Without a provided DATE, it will convert the current UTC date/time\n"
),
nargs="?",
const=now,
)
arg_parse.add_argument(
"--timezones",
help="Prints a list of timezones to use for conversion",
action="store_true",
)
arg_parse.add_argument(
"--tz",
metavar="TIMEZONE_NAME",
help=(
"Provide the name of a timezone for conversion within quotes.\n"
"Use --timezones to see a list."
),
type=str,
default=None,
)
for argument, data in ts_types.items():
arg_parse.add_argument(f"--{argument}", metavar="", help=f"{data.ts_type}")
arg_parse.add_argument(
"--version", "-v", action="version", version=arg_parse.description
)
if len(sys.argv[1:]) == 0:
arg_parse.print_help()
arg_parse.exit()
if len(sys.argv[1:]) > 0 and ("--timezones" in sys.argv):
list_timezones()
sys.exit(0)
args = arg_parse.parse_args()
if args.date_format in date_formats:
__fmt__ = date_formats[args.date_format]
else:
arg_parse.error(
(
f"[!] The format {args.date_format} is not one of the available options.\n"
"Please use the --date-formats argument to find a valid NAME."
)
)
all_args = vars(args)
if args.formats:
formats(args.formats)
sys.exit(0)
if args.date_formats:
list_date_formats()
sys.exit(0)
if args.guess:
full_list = from_all(args.guess, args.tz)
if len(full_list) == 0:
print("[!] No valid dates found. Check your input and try again")
else:
print(
f"[+] Guessing timestamp format for {args.guess}\n"
f"[+] Outputs which do NOT result in a date/time value are NOT displayed\r"
)
if len(full_list) == 1:
dt_text = "date"
else:
dt_text = "dates"
print(
f"[+] Displaying {len(full_list)} potential {dt_text}\n"
f"{__red__}[+] Most likely results (+/- 5 years) are highlighted\n{__clr__}"
)
for _, output in enumerate(full_list):
print(f"{full_list[output][1]}")
print("\r")
return
if args.timestamp:
_, ts_outputs = to_timestamps(args.timestamp, args.tz)
print(f"\n[+] Converting {args.timestamp} to {len(ts_outputs)} timestamps:\n")
for ts_val in ts_outputs:
print(ts_val)
print("\r")
return
if args.gui:
gui()
return
if args.csv:
if len(args.csv) == 2:
src_file = os.path.normpath(os.path.abspath(args.csv[0]))
ts_type = args.csv[1]
src_exists = os.path.exists(src_file) and os.path.isfile(src_file)
if ts_type in single_funcs and src_exists:
result, dst, reason = generate_csv(src_file, ts_type, tz_name=args.tz)
dst = os.path.normpath(dst)
if result:
print(f"[+] CSV file was saved as {dst}.")
else:
print(f"[!] Unable to complete CSV export to {dst} - {reason}.")
else:
arg_parse.error(
"[!] Provided argument is not in the list of conversion options"
)
elif len(args.csv) == 3:
src_file = os.path.normpath(os.path.abspath(args.csv[0]))
ts_type = args.csv[1]
column = args.csv[2]
src_exists = os.path.exists(src_file) and os.path.isfile(src_file)
if ts_type in single_funcs and src_exists:
result, dst, reason = generate_csv(
src_file, ts_type, column, tz_name=args.tz
)
dst = os.path.normpath(dst)
if result:
print(f"[+] CSV file was saved as {dst}.")
else:
print(f"[!] Unable to complete CSV export to {dst} - {reason}.")
else:
arg_parse.error(
"[!] Provided argument is not in the list of conversion options"
)
else:
arg_parse.error(
(
"[!] --csv requires the file name to process "
f"and the timestamp type without the '--' {args.csv}"
)
)
return
for arg_passed, funcs in single_funcs.items():
requested = all_args[arg_passed]
if requested and not args.to:
date_time, indiv_output, _, reason, _ = funcs[0](requested)
if indiv_output is False:
print(f"[!] {reason}")
else:
if args.minimal:
print(date_time)
else:
print(indiv_output)
elif requested and args.to:
try:
dt_obj = dt.fromisoformat(requested)
except ValueError:
dt_obj = dt.strptime(requested, __fmt__)
except Exception:
arg_parse.error(
"[!] Format should be 'YYYY-MM-DD HH:MM:SS.fff' in 24h fmt."
"Milliseconds (.fff) are optional.\n"
"[!] Otherwise, use --date-formats to find an accepted format and use:\n"
"[!] --date-format NAME where NAME is the format NAME, not the format STRING."
)
return
if not dt_obj.tzinfo:
if not args.tz:
dt_obj = dt_obj.replace(tzinfo=timezone.utc)
else:
tz = tzone(args.tz)
dt_obj = dt_obj.replace(tzinfo=tz)
out_func = funcs[1]
timestamp = ""
formatted_output = ""
if out_func is not None:
timestamp, formatted_output = out_func(dt_obj)
else:
arg_parse.error(f"[!] {arg_passed} does not support a 'to' conversion.")
if timestamp == "":
print(f"[!] Unable to convert {requested} to {arg_passed}.")
else:
if args.minimal:
print(timestamp)
else:
print(formatted_output)
if __name__ == "__main__":
main()
|