OleViewDotNet.psm1
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 |
# This file is part of OleViewDotNet. # Copyright (C) James Forshaw 2018 # # OleViewDotNet is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # OleViewDotNet is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with OleViewDotNet. If not, see <http://www.gnu.org/licenses/>. Set-StrictMode -Version Latest $Script:GlobalDbgHelpPath = [OleViewDotNet.COMUtilities]::GetDefaultDbgHelp() $Script:GlobalSymbolPath = "srv*https://msdl.microsoft.com/download/symbols" $Script:CurrentComDatabase = $null [OleViewDotNet.COMUtilities]::SetupCachedSymbols() function New-CallbackProgress { Param( [parameter(Mandatory)] [string]$Activity, [switch]$NoProgress ) if ($NoProgress) { $callback = {} } else { $callback = { Write-Progress -Activity $args[0] -Status "Processing $($args[1])" -PercentComplete $args[2] } } [OleViewDotNet.PowerShell.CallbackProgress]::new($Activity, [Action[string, string, int]]$callback) } function Resolve-LocalPath { [CmdletBinding()] Param( [Parameter(Mandatory, Position = 0)] [string]$Path ) $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) } function Wrap-ComObject { [CmdletBinding(DefaultParameterSetName = "FromType")] Param( [Parameter(Mandatory, Position = 0)] [object]$Object, [Parameter(Mandatory, Position = 1, ParameterSetName = "FromIid")] [Guid]$Iid, [Parameter(ParameterSetName = "FromIid")] [switch]$LoadType, [Parameter(Mandatory, Position = 1, ParameterSetName = "FromType")] [Type]$Type, [Parameter(Mandatory, Position = 1, ParameterSetName = "FromInterface")] [OleViewDotNet.Database.COMInterfaceEntry]$Interface, [Parameter(Mandatory, Position = 1, ParameterSetName = "FromInterfaceInstance")] [OleViewDotNet.Database.COMInterfaceInstance]$InterfaceInstance, [Parameter(Mandatory, Position = 1, ParameterSetName = "FromIpid")] [OleViewDotNet.COMIPIDEntry]$Ipid, [switch]$NoWrapper, [OleViewDotNet.Database.COMRegistry]$Database ) if ($NoWrapper) { return $Object } $db = $null if ($LoadType) { $db = Get-CurrentComDatabase $Database if ($null -eq $db) { Write-Error "No database specified and current database isn't set" return } } switch($PSCmdlet.ParameterSetName) { "FromIid" { [OleViewDotNet.Wrappers.COMWrapperFactory]::Wrap($Object, $Iid, $db) } "FromType" { [OleViewDotNet.Wrappers.COMWrapperFactory]::Wrap($Object, $Type) } "FromInterface" { [OleViewDotNet.Wrappers.COMWrapperFactory]::Wrap($Object, $Interface) } "FromInterfaceInstance" { [OleViewDotNet.Wrappers.COMWrapperFactory]::Wrap($Object, $InterfaceInstance) } "FromIpid" { [OleViewDotNet.Wrappers.COMWrapperFactory]::Wrap($Object, $Ipid) } } } function Unwrap-ComObject { [CmdletBinding(DefaultParameterSetName = "FromType")] Param( [Parameter(Mandatory, Position = 0)] [object]$Object ) [OleViewDotNet.Wrappers.COMWrapperFactory]::Unwrap($Object) } <# .SYNOPSIS Wrap a COM object inside a callable wrapper. .DESCRIPTION This cmdlet generates a callable wrapper for a COM interface and wraps the object. .PARAMETER Object The object to wrap. .PARAMETER Iid The interface ID to base the wrapper on. .PARAMETER LoadType Specify to load interface type from proxy/typelib if available and not already loaded. .PARAMETER Database Specify with LoadType to indicate the database to get interface information from. .PARAMETER Type The existing interface type to wrap with. .PARAMETER Interface A COM interface from a database. If no existing interface exists for this class it'll try and build one from its proxy. #> function Get-ComObjectInterface { [CmdletBinding(DefaultParameterSetName = "FromType")] Param( [Parameter(Mandatory, Position = 0, ValueFromPipeline)] [object[]]$Object, [Parameter(Mandatory, Position = 1, ParameterSetName = "FromIid")] [Guid]$Iid, [Parameter(ParameterSetName = "FromIid")] [switch]$LoadType, [Parameter(ParameterSetName = "FromIid")] [OleViewDotNet.Database.COMRegistry]$Database, [Parameter(Mandatory, Position = 1, ParameterSetName = "FromType")] [Type]$Type, [Parameter(Mandatory, Position = 1, ParameterSetName = "FromInterface")] [OleViewDotNet.Database.COMInterfaceEntry]$Interface, [Parameter(Mandatory, Position = 1, ParameterSetName = "FromInterfaceInstance")] [OleViewDotNet.Database.COMInterfaceInstance]$InterfaceInstance ) PROCESS { foreach($o in $Object) { $o = Unwrap-ComObject $o switch($PSCmdlet.ParameterSetName) { "FromIid" { Wrap-ComObject -Object $o -Iid $Iid -LoadType:$LoadType | Write-Output } "FromType" { Wrap-ComObject -Object $o -Type $Type | Write-Output } "FromInterface" { Wrap-ComObject -Object $o -Interface $Interface | Write-Output } "FromInterfaceInstance" { Wrap-ComObject -Object $o -InterfaceInstance $InterfaceInstance | Write-Output } } } } } function Get-ComSymbolResolver { Param ( [parameter( Position=0)] [string]$DbgHelpPath = "", [parameter(Position=1)] [string]$SymbolPath = "srv*https://msdl.microsoft.com/download/symbols" ) if ($DbgHelpPath -eq "") { $DbgHelpPath = $Script:GlobalDbgHelpPath } if ($SymbolPath -eq "") { $SymbolPath = $env:_NT_SYMBOL_PATH if ($SymbolPath -eq "") { $SymbolPath = $Script:GlobalSymbolPath } } @{DbgHelpPath=$DbgHelpPath; SymbolPath=$SymbolPath} } <# .SYNOPSIS Gets the current COM database. .DESCRIPTION This cmdlet gets the current COM database. .PARAMETER Database A database parameter to test. This function returns $Database if it's not $null, otherwise returns the current database. #> function Get-CurrentComDatabase { Param( [parameter(Position=0)] [OleViewDotNet.Database.COMRegistry]$Database ) if ($null -ne $Database) { $Database } else { if ($null -eq $Script:CurrentComDatabase) { $result = $Host.UI.PromptForChoice("Load COM Database?", ` "No database specified, do you want to load the default?", @("&Yes", "&No"), 0) if ($result -eq 0) { Get-ComDatabase } } $Script:CurrentComDatabase } } <# .SYNOPSIS Sets the current COM database. .DESCRIPTION This cmdlet sets the current COM database. It allows you to load a COM database and not need to pass it as a parameter. .PARAMETER Database The database to set as the current database. You can specify $null to remove the current. #> function Set-CurrentComDatabase { Param( [parameter(Mandatory, Position=0)] [AllowNull()] [OleViewDotNet.Database.COMRegistry]$Database ) $Script:CurrentComDatabase = $Database } <# .SYNOPSIS Get a COM database from the registry or a file. .DESCRIPTION This cmdlet loads a COM registration information database from the current registry or a file and returns an object which can be inspected or passed to other methods. The database will be set as the current global data unless -PassThru is specified. .PARAMETER LoadMode Specify what to load from the registry. .PARAMETER User Specify a user to load when loading user-specific COM registration information. .PARAMETER Path Specify a path to load a saved COM database. .PARAMETER NoProgress Don't show progress for load. .PARAMETER SetCurrent No longer used. .PARAMETER PassThru Specify to return the loaded database. .PARAMETER .INPUTS None .OUTPUTS OleViewDotNet.COMRegistry .EXAMPLE Get-ComDatabase Load a default, merged COM database. .EXAMPLE Get-ComDatabase -LoadMode UserOnly Load a user-only database for the current user. .EXAMPLE Get-ComDatabase -User S-1-5-X-Y-Z Load a merged COM database including user-only information from the user SID. .EXAMPLE $db = Get-ComDatabase -PassThru Load a default, merged COM database and return it as an object. #> function Get-ComDatabase { [CmdletBinding(DefaultParameterSetName = "FromRegistry")] Param( [Parameter(ParameterSetName = "FromRegistry")] [OleViewDotNet.Database.COMRegistryMode]$LoadMode = "Merged", [Parameter(ParameterSetName = "FromRegistry")] [NtApiDotNet.Sid]$User, [Parameter(Mandatory, ParameterSetName = "FromFile", Position = 0)] [string]$Path, [switch]$NoProgress, [switch]$SetCurrent, [switch]$PassThru ) $callback = New-CallbackProgress -Activity "Loading COM Registry" -NoProgress:$NoProgress $comdb = switch($PSCmdlet.ParameterSetName) { "FromRegistry" { [OleViewDotNet.Database.COMRegistry]::Load($LoadMode, $User, $callback) } "FromFile" { $Path = Resolve-Path $Path [OleViewDotNet.Database.COMRegistry]::Load($Path, $callback) } } if ($SetCurrent) { Write-Warning "SetCurrent is now the default. Use PassThru to return a database object." } if ($PassThru) { Write-Output $comdb } else { Set-CurrentComDatabase $comdb } } <# .SYNOPSIS Save a COM database to a file. .DESCRIPTION This cmdlet saves a COM registration database to a file. .PARAMETER Path The path to save the database to. .PARAMETER Database The database to save. .PARAMETER NoProgress Don't show progress for save. .INPUTS None .OUTPUTS None .EXAMPLE Set-ComDatabase -Path output.db Save the current database to the file output.db .EXAMPLE Set-ComDatabase -Path output.db -Database $comdb Save a specific database to the file output.db #> function Set-ComDatabase { [CmdletBinding()] Param( [Parameter(Mandatory,Position=0)] [string]$Path, [OleViewDotNet.Database.COMRegistry]$Database, [switch]$NoProgress ) $Database = Get-CurrentComDatabase $Database if ($null -eq $Database) { Write-Error "No database specified and current database isn't set" return } $callback = New-CallbackProgress -Activity "Saving COM Registry" -NoProgress:$NoProgress $Path = Resolve-LocalPath $Path $Database.Save($Path, $callback) } <# .SYNOPSIS Compares two COM databases and returns the difference. .DESCRIPTION The cmdlet compares two COM database, generates the difference and returns a new database with only the differences. .PARAMETER Left The database to the left of the comparison. .PARAMETER Right The database to the right of the comparison. .PARAMETER DiffMode Specify which database information to preserve in the diff, choice between left (default) or right. .PARAMETER NoProgress Don't show progress for compare. .INPUTS None .OUTPUTS OleViewDotNet.COMRegistry .EXAMPLE Compare-ComRegistry -Left $comdb1 -Right $comdb2 Compare two databases, returning the differences in the left database. .EXAMPLE Compare-ComRegistry -Left $comdb1 -Right $comdb2 -DiffMode RightOnly Compare two databases, returning the differences in the right database. #> function Compare-ComDatabase { [CmdletBinding()] Param( [Parameter(Mandatory, Position = 0)] [OleViewDotNet.Database.COMRegistry]$Left, [Parameter(Mandatory, Position = 1)] [OleViewDotNet.Database.COMRegistry]$Right, [OleViewDotNet.Database.COMRegistryDiffMode]$DiffMode = "LeftOnly", [switch]$NoProgresss ) $callback = New-CallbackProgress -Activity "Comparing COM Registries" -NoProgress:$NoProgress [OleViewDotNet.Database.COMRegistry]::Diff($Left, $Right, $DiffMode, $callback) } function Where-HasComServer { [CmdletBinding()] Param( [Parameter(Mandatory, ValueFromPipeline)] [OleViewDotNet.Database.COMCLSIDEntry]$ClassEntry, [string]$ServerName, [OleViewDotNet.Database.COMServerType]$ServerType ) PROCESS { $write_to_output = $false if ($ServerType -eq "UnknownServer") { foreach($server in $ClassEntry.Servers.Values) { if ($server.Server -match $ServerName) { $write_to_output = $true break } } } else { $write_to_output = $ClassEntry.Servers.ContainsKey($ServerType) -and $ClassEntry.Servers[$ServerType].Server -match $ServerName } if ($write_to_output) { Write-Output $ClassEntry } } } <# .SYNOPSIS Get COM classes from a database. .DESCRIPTION This cmdlet gets COM classes from the database based on a set of criteria. The default is to return all registered classes. .PARAMETER Database The database to use. .PARAMETER Clsid Specify a CLSID to lookup. .PARAMETER AllowNoReg Allows the class entry to be returned even if not registered. .PARAMETER Name Specify a name which equals the class name. .PARAMETER ServerName Specify a server name to match against. .PARAMETER ServerType Specify a type of server to match against. If specified as UnknownServer will search all servers. .PARAMETER InteractiveUser Specify that the COM classes should be configured to run as the Interactive User. .PARAMETER ProgId Specify looking up the COM class from a ProgID. .PARAMETER Iid Specify looking up a COM class based on it's proxy IID. .PARAMETER Object Specify looking up the COM class based on an object instance. Needs to support an IPersist inteface to extract the CLSID. .PARAMETER CatId Specify looking up the COM classes based on a category ID. .PARAMETER CatName Specify looking up the COM classes based on a category name. .PARAMETER Source Specify looking up the COM classes based on a source type. .INPUTS None .OUTPUTS OleViewDotNet.COMCLSIDEntry .EXAMPLE Get-ComClass Get all COM classes from the current databae. .EXAMPLE Get-ComClass -Database $comdb Get all COM classes from a database. .EXAMPLE Get-ComClass -Clsid "ffe1df5f-9f06-46d3-af27-f1fc10d63892" Get a COM class with a specified CLSID. .EXAMPLE Get-ComClass -PartialClsid "ffe1df5f" Get COM classes with a partial CLSID. .EXAMPLE Get-ComClass -Name "TestClass" Get COM classes which where the name is TestClass. .EXAMPLE Get-ComClass -ServerName "obj.ocx" Get COM classes which are implemented in a server containing the string "obj.ocx" .EXAMPLE Get-ComClass -ServerType InProcServer32 Get COM classes which are registered with an in-process server. .EXAMPLE Get-ComClass -Iid "00000001-0000-0000-C000-000000000046" Get COM class registered as an interface proxy for a specific IID. .EXAMPLE Get-ComClass -ProgId htafile Get COM class from a Prog ID. .EXAMPLE Get-ComClass -InteractiveUser Get COM classes registered to run as the interactive user. .EXAMPLE Get-ComClass -Service Get COM classes registered to run inside a service. .EXAMPLE Get-ComClass -ServiceName "ExampleService" Get COM classes registered to run inside a service with a specific name. .EXAMPLE Get-ComClass -Object $obj Get COM class based on an object instance. .EXAMPLE Get-ComClass -CatId "62c8fe65-4ebb-45e7-b440-6e39b2cdbf29" Get COM classes in a category with ID 62c8fe65-4ebb-45e7-b440-6e39b2cdbf29. .EXAMPLE Get-ComClass -CatName ".NET Category" Get COM classes in the .NET category. .EXAMPLE Get-ComClass -Source Packaged Get COM classes which came from packaged COM source. #> function Get-ComClass { [CmdletBinding(DefaultParameterSetName = "All")] Param( [OleViewDotNet.Database.COMRegistry]$Database, [Parameter(Position = 0, Mandatory, ParameterSetName = "FromClsid")] [Guid]$Clsid, [Parameter(Mandatory, ParameterSetName = "FromPartialClsid")] [string]$PartialClsid, [Parameter(ParameterSetName = "FromClsid")] [switch]$AllowNoReg, [Parameter(Mandatory, ParameterSetName = "FromName")] [string]$Name, [Parameter(ParameterSetName = "FromServer")] [string]$ServerName = "", [Parameter(ParameterSetName = "FromServer")] [OleViewDotNet.Database.COMServerType]$ServerType = "UnknownServer", [Parameter(Mandatory, ParameterSetName = "FromIid")] [Guid]$Iid, [Parameter(Mandatory, ParameterSetName = "FromProgId")] [string]$ProgId, [Parameter(Mandatory, ParameterSetName = "FromIU")] [switch]$InteractiveUser, [Parameter(Mandatory, ParameterSetName = "FromService")] [switch]$Service, [Parameter(Mandatory, ParameterSetName = "FromServiceName")] [string]$ServiceName, [Parameter(Mandatory, ParameterSetName = "FromObject")] [object]$Object, [Parameter(Mandatory, ParameterSetName = "FromCatId")] [Guid]$CatId, [Parameter(Mandatory, ParameterSetName = "FromCatName")] [string]$CatName, [Parameter(Mandatory, ParameterSetName = "FromSource")] [OleViewDotNet.Database.COMRegistryEntrySource]$Source, [Parameter(Mandatory, ParameterSetName = "FromTrustedMarshaller")] [switch]$TrustedMarshaller ) $Database = Get-CurrentComDatabase $Database if ($null -eq $Database) { Write-Error "No database specified and current database isn't set." return } switch($PSCmdlet.ParameterSetName) { "All" { Write-Output $Database.Clsids.Values } "FromClsid" { if ($AllowNoReg) { $Database.MapClsidToEntry($Clsid) | Write-Output } else { Write-Output $Database.Clsids[$Clsid] } } "FromPartialClsid" { Get-ComClass -Database $Database | Where-Object Clsid -Match $PartialClsid | Write-Output } "FromName" { Get-ComClass -Database $Database | Where-Object Name -eq $Name | Write-Output } "FromServer" { Get-ComClass -Database $Database | Where-HasComServer -ServerName $ServerName -ServerType $ServerType | Write-Output } "FromIid" { Write-Output $Database.MapIidToInterface($Iid).ProxyClassEntry } "FromProgId" { Write-Output $Database.MapProgIdToClsid($ProgId) } "FromIU" { Get-ComClass -Database $Database | Where-Object { $_.HasAppID -and $_.AppIDEntry.RunAs -eq "Interactive User" } | Write-Output } "FromService" { Get-ComClass -Database $Database | Where-Object { $_.HasAppID -and $_.AppIDEntry.IsService } | Write-Output } "FromServiceName" { Get-ComClass -Database $Database -Service | Where-Object { $_.AppIDEntry.ServiceName -eq $ServiceName } | Write-Output } "FromObject" { $Object = Unwrap-ComObject $Object $Clsid = [OleViewDotNet.COMUtilities]::GetObjectClass($Object) if ($Clsid -ne [Guid]::Empty) { Get-ComClass -Database $Database -Clsid $Clsid | Write-Output } } "FromCatId" { Get-ComCategory -CatId $CatId | Select-Object -ExpandProperty ClassEntries | Write-Output } "FromCatName" { Get-ComCategory -Name $CatName | Select-Object -ExpandProperty ClassEntries | Write-Output } "FromSource" { Get-ComClass -Database $Database | Where-Object Source -eq $Source | Write-Output } "FromTrustedMarshaller" { Get-ComClass -Database $Database | Where-Object TrustedMarshaller } } } <# .SYNOPSIS Get COM process information. .DESCRIPTION This cmdlet opens a specified set of processes and extracts the COM information from them. For this to work you need symbol support. .PARAMETER Database The database to use to lookup information. .PARAMETER Process Specify a list of process objects to parse. You can get these from Get-Process cmdlet. .PARAMETER DbgHelpPath Specify location of DBGHELP.DLL file. For remote symbol support use one from Debugging Tools for Windows. .PARAMETER SymbolPath Specify the location of symbols for the resolver. .PARAMETER ParseStubMethods Specify to parse the method parameter information on a process stub. .PARAMETER ResolveMethodNames Specify to try and resolve method names for interfaces. .PARAMETER ParseRegisteredClasses Specify to parse classes registered by the process. .PARAMETER ParseClients Specify to parse client proxy information from the process. .PARAMETER ParseActivationContext Specify to parse process activation context. .PARAMETER NoProgress Don't show progress for process parsing. .PARAMETER ServiceName Specify names of services to parse. .INPUTS None .OUTPUTS OleViewDotNet.COMProcessEntry .EXAMPLE Get-ComProcess Get all COM processes using the current database. .EXAMPLE Get-ComProcess -Database $comdb Get all COM processes. .EXAMPLE Get-Process notepad | Get-ComProcess Get COM process from a list of processes. #> function Get-ComProcess { [CmdletBinding(DefaultParameterSetName = "All")] Param( [OleViewDotNet.Database.COMRegistry]$Database, [alias("dbghelp")] [string]$DbgHelpPath = "", [string]$SymbolPath = "", [switch]$ParseStubMethods, [switch]$ResolveMethodNames, [switch]$ParseRegisteredClasses, [switch]$ParseClients, [switch]$ParseActivationContext, [parameter(Mandatory, ValueFromPipeline, ParameterSetName = "FromProcessId")] [alias("pid")] [int[]]$ProcessId, [parameter(Mandatory, ValueFromPipeline, ParameterSetName = "FromProcess")] [System.Diagnostics.Process[]]$Process, [parameter(Mandatory, ValueFromPipeline, ParameterSetName = "FromObjRef")] [OleViewDotNet.COMObjRef[]]$ObjRef, [parameter(Mandatory, ParameterSetName = "FromName")] [string]$Name, [parameter(Mandatory, ParameterSetName = "FromServiceName")] [string[]]$ServiceName, [switch]$NoProgress ) BEGIN { $resolver = Get-ComSymbolResolver $DbgHelpPath $SymbolPath $procs = @() $objrefs = @() } PROCESS { switch($PSCmdlet.ParameterSetName) { "All" { $procs = Get-Process } "FromProcessId" { $procs = Get-Process -Id $ProcessId } "FromProcess" { $procs += $Process } "FromObjRef" { $objrefs += $ObjRef } "FromName" { $procs = Get-Process -Name $Name } } } END { $Database = Get-CurrentComDatabase $Database if ($null -eq $Database) { Write-Error "No database specified and current database isn't set" return } $callback = New-CallbackProgress -Activity "Parsing COM Processes" -NoProgress:$NoProgress $config = [OleViewDotNet.COMProcessParserConfig]::new($resolver.DbgHelpPath, $resolver.SymbolPath, ` $ParseStubMethods, $ResolveMethodNames, $ParseRegisteredClasses, $ParseClients, $ParseActivationContext) switch($PSCmdlet.ParameterSetName) { "FromObjRef" { [OleViewDotNet.COMProcessParser]::GetProcesses([OleViewDotNet.COMObjRef[]]$objrefs, $config, $callback, $Database) | Write-Output } "FromServiceName" { [OleViewDotNet.COMProcessParser]::GetProcesses($ServiceName, $config, $callback, $Database) | Write-Output } default { [OleViewDotNet.COMProcessParser]::GetProcesses([System.Diagnostics.Process[]]$procs, $config, $callback, $Database) | Write-Output } } } } <# .SYNOPSIS Start a log of COM activations in the current process. .DESCRIPTION This cmdlet starts a COM activation log for the current process. It will write out all COM classes created until Stop-ComActivationLog is called. .PARAMETER Database Optional database to lookup names for activated objects. .PARAMETER Path Specify a path for the log file. .PARAMETER Append If specified then new entries will be appended to the log rather than replacing the log file. .INPUTS None .OUTPUTS None .EXAMPLE Start-ComActivationLog activations.log Start COM activation log to activations.log. .EXAMPLE Start-ComActivationLog activations.log -Database $comdb Start COM activation log to activations.log with a database for name lookup. .EXAMPLE Start-ComActivationLog activations.log -Append Start COM activation log to activations.log appending new entries to the end of the file. #> function Start-ComActivationLog { [CmdletBinding()] Param( [Parameter(Mandatory, Position = 0)] [string]$Path, [switch]$Append, [OleViewDotNet.Database.COMRegistry]$Database ) $Database = Get-CurrentComDatabase $Database $Path = Resolve-LocalPath $Path [OleViewDotNet.PowerShell.LoggingActivationFilter]::Instance.Start($Path, $Append, $Database) } <# .SYNOPSIS Stop the log of COM activations in the current process. .DESCRIPTION This cmdlet stops a COM activation log for the current process. .INPUTS None .OUTPUTS None .EXAMPLE Stop-ComActivationLog Stop COM activation log. #> function Stop-ComActivationLog { [OleViewDotNet.PowerShell.LoggingActivationFilter]::Instance.Stop() } <# .SYNOPSIS Get COM AppIDs from a database. .DESCRIPTION This cmdlet gets COM AppIDs from the database based on a set of criteria. The default is to return all registered AppIds. .PARAMETER Database The database to use. .PARAMETER AppId Specify a AppID to lookup. .PARAMETER Name Specify a name to match against the AppId name. .PARAMETER ServiceName Specify a service name to match against. .PARAMETER IsService Specify a returns AppIDs implemented by services. .PARAMETER Source Specify looking up the COM AppIDs based on a source type. .INPUTS None .OUTPUTS OleViewDotNet.COMAppIDEntry .EXAMPLE Get-ComAppId -Database $comdb Get all COM AppIDs from a database. #> function Get-ComAppId { [CmdletBinding(DefaultParameterSetName = "All")] Param( [OleViewDotNet.Database.COMRegistry]$Database, [Parameter(Position = 0, Mandatory, ParameterSetName = "FromAppId")] [Guid]$AppId, [Parameter(Mandatory, ParameterSetName = "FromPartialAppId")] [string]$PartialAppId, [Parameter(Mandatory, ParameterSetName = "FromName")] [string]$Name, [Parameter(ParameterSetName = "FromServiceName")] [string]$ServiceName = "", [Parameter(ParameterSetName = "FromIsService")] [switch]$IsService, [Parameter(Mandatory, ParameterSetName = "FromSource")] [OleViewDotNet.Database.COMRegistryEntrySource]$Source ) $Database = Get-CurrentComDatabase $Database if ($null -eq $Database) { Write-Error "No database specified and current database isn't set" return } switch($PSCmdlet.ParameterSetName) { "All" { Write-Output $Database.AppIDs.Values } "FromAppId" { Write-Output $Database.AppIDs[$AppId] } "FromPartialAppId" { Get-ComAppId -Database $Database | Where-Object AppId -Match $PartialAppId | Write-Output } "FromName" { Get-ComAppId -Database $Database | Where-Object Name -eq $Name | Write-Output } "FromServiceName" { Get-ComAppId -Database $Database | Where-Object ServiceName -eq $ServiceName | Write-Output } "FromIsService" { Get-ComAppId -Database $Database | Where-Object IsService | Write-Output } "FromSource" { Get-ComAppId -Database $Database | Where-Object Source -eq $Source | Write-Output } } } <# .SYNOPSIS Show a COM database in the main viewer. .DESCRIPTION This cmdlet starts the main viewer application and loads a specified database file. .PARAMETER Database The database to view. .PARAMETER Path The path to the database to view. .INPUTS None .OUTPUTS None .EXAMPLE Show-ComDatabase Show the current COM database in the viewer. .EXAMPLE Show-ComDatabase -Database $comdb Show a COM database in the viewer. .EXAMPLE Show-ComDatabase -Path com.db Show a COM database in the viewer from a file. #> function Show-ComDatabase { [CmdletBinding(DefaultParameterSetName="FromDb")] Param( [Parameter(Position = 0, ParameterSetName = "FromDb")] [OleViewDotNet.Database.COMRegistry]$Database, [Parameter(Mandatory, Position = 0, ParameterSetName = "FromFile")] [string]$Path ) $DeleteFile = $false switch($PSCmdlet.ParameterSetName) { "FromDb" { $Database = Get-CurrentComDatabase $Database if ($null -eq $Database) { Write-Error "No database specified and current database isn't set" return } $Path = (New-TemporaryFile).FullName Set-ComDatabase $Path -NoProgress -Database $Database $DeleteFile = $true } "FromFile" { # Do nothing. } } $exe = [OleViewDotNet.COMUtilities]::GetExePathForCurrentBitness() $args = @("`"-i=$Path`"") if ($DeleteFile) { $args += @("-d") } Start-Process $exe $args } <# .SYNOPSIS Get a COM class or Runtime class instance interfaces. .DESCRIPTION This cmdlet enumerates the supported interfaces for a COM class or Runtime class and returns them. .PARAMETER ClassEntry The COM or Runtime classes to enumerate. .PARAMETER Refresh Specify to force the interfaces to be refreshed. .PARAMETER Factory Specify to return the implemented factory interfaces. .PARAMETER NoQuery Specify to not query for the interfaces at all and only return what's already available. .PARAMETER NoProgress Don't show progress for query. .PARAMETER Token The token to use when querying for the interfaces. .INPUTS None .OUTPUTS OleViewDotNet.COMInterfaceInstance[] .EXAMPLE Get-ComClassInterface -ClassEntry $cls Get instance interfaces for a COM class. .EXAMPLE Get-ComClassInterface -ClassEntry $cls -Factory Get factory interfaces for a COM class. .EXAMPLE Get-ComClassInterface -ClassEntry $cls -Refresh Get instance interfaces for a COM class forcing them to be refreshed if necessary. #> function Get-ComClassInterface { [CmdletBinding()] Param( [Parameter(Mandatory, Position = 0, ValueFromPipeline)] [OleViewDotNet.Database.ICOMClassEntry[]]$ClassEntry, [switch]$Refresh, [switch]$Factory, [switch]$NoQuery, [switch]$NoProgress, [NtApiDotNet.NtToken]$Token ) PROCESS { $i = 0 foreach($class in $ClassEntry) { if (!$NoQuery) { if (!$NoProgress) { if ($PSCmdlet.MyInvocation.ExpectingInput) { Write-Progress "Querying for Class Interfaces" -Status $class.Name } else { Write-Progress "Querying for Class Interfaces" -Status $class.Name -PercentComplete (($i / $ClassEntry.Count) * 100) $i++ } } $class.LoadSupportedInterfaces($Refresh, $Token) | Out-Null } if ($Factory) { $class.FactoryInterfaces | Write-Output } else { $class.Interfaces | Write-Output } } } } <# .SYNOPSIS Get COM Runtime classes from a database. .DESCRIPTION This cmdlet gets COM Runtime classes from the database based on a set of criteria. The default is to return all registered runtime classes. .PARAMETER Database The database to use. .PARAMETER Name Specify a name to equal the class name. .PARAMETER DllPath Specify the DLL path to match against. .PARAMETER ActivationType Specify a type of activation to match against. .INPUTS None .OUTPUTS OleViewDotNet.COMRuntimeClassEntry .EXAMPLE Get-ComRuntimeClass $comdb Get all COM Runtime classes from the current database. .EXAMPLE Get-ComRuntimeClass -Name "Windows.ABC.XYZ" Get COM Runtime classes with the name Windows.ABC.XYZ. .EXAMPLE Get-ComRuntimeClass -DllPath "c:\path\to\runtime.dll" Get COM Runtime classes which are implemented in a DLL with the path "c:\path\to\runtime.dll" .EXAMPLE Get-ComRuntimeClass -ActivationType OutOfProcess Get COM Runtime classes which are implemented out-of-process. #> function Get-ComRuntimeClass { [CmdletBinding(DefaultParameterSetName = "All")] Param( [OleViewDotNet.Database.COMRegistry]$Database, [Parameter(Position = 0, Mandatory, ParameterSetName = "FromName")] [string]$Name, [Parameter(Mandatory, ParameterSetName = "FromDllPath")] [string]$DllPath, [Parameter(Mandatory, ParameterSetName = "FromActivationType")] [OleViewDotNet.Database.ActivationType]$ActivationType, [Parameter(Mandatory, ParameterSetName = "FromTrustLevel")] [OleViewDotNet.Database.TrustLevel]$TrustLevel ) $Database = Get-CurrentComDatabase $Database if ($null -eq $Database) { Write-Error "No database specified and current database isn't set" return } switch($PSCmdlet.ParameterSetName) { "All" { Write-Output $Database.RuntimeClasses.Values } "FromName" { $Database.RuntimeClasses[$Name] | Write-Output } "FromDllPath" { Get-ComRuntimeClass -Database $Database | Where-Object DllPath -eq $DllPath | Write-Output } "FromActivationType" { Get-ComRuntimeClass -Database $Database | Where-Object ActivationType -eq $ActivationType | Write-Output } "FromTrustLevel" { Get-ComRuntimeClass -Database $Database | Where-Object TrustLevel -eq $TrustLevel | Write-Output } } } <# .SYNOPSIS Get COM Runtime servers from a database. .DESCRIPTION This cmdlet gets COM Runtime server from the database based on a set of criteria. The default is to return all registered runtime servers. .PARAMETER Database The database to use. Optional if the current database has been set. .PARAMETER Name Specify a name to equal the server name. .PARAMETER ExePath Specify the executable path to match against. .PARAMETER ServerType Specify a type of server to match against. .PARAMETER IdentityType Specify the identity type of the server to match against. .INPUTS None .OUTPUTS OleViewDotNet.COMRuntimeClassEntry .EXAMPLE Get-ComRuntimeServer Get all COM Runtime classes from the current data database. .EXAMPLE Get-ComRuntimeServer -Name "ABC" Get COM Runtime server with the name ABC. #> function Get-ComRuntimeServer { [CmdletBinding(DefaultParameterSetName = "All")] Param( [OleViewDotNet.Database.COMRegistry]$Database, [Parameter(Position = 0, Mandatory, ParameterSetName = "FromName")] [string]$Name, [Parameter(Mandatory, ParameterSetName = "FromExePath")] [string]$ExePath, [Parameter(Mandatory, ParameterSetName = "FromServerType")] [OleViewDotNet.Database.ServerType]$ServerType, [Parameter(Mandatory, ParameterSetName = "FromIdentityType")] [OleViewDotNet.Database.IdentityType]$IdentityType ) $Database = Get-CurrentComDatabase $Database if ($null -eq $Database) { Write-Error "No database specified and current database isn't set" return } switch($PSCmdlet.ParameterSetName) { "All" { Write-Output $Database.RuntimeServers.Values } "FromName" { $Database.RuntimeServers[$Name] | Write-Output } "FromExePath" { Get-ComRuntimeServer -Database $Database | Where-Object ExePath -eq $ExePath | Write-Output } "FromServerType" { Get-ComRuntimeServer -Database $Database | Where-Object ServerType -eq $ServerType | Write-Output } "FromIdentityType" { Get-ComRuntimeServer -Database $Database | Where-Object IdentityType -eq $IdentityType | Write-Output } } } <# .SYNOPSIS Get COM interfaces from a database. .DESCRIPTION This cmdlet gets COM interfaces from the database based on a set of criteria. The default is to return all registered interfaces. .PARAMETER Database The database to use. If not specified then the current database is used. .PARAMETER Iid Specify a IID to lookup. .PARAMETER AllowNoReg Creates an interface entry even if not registered. .PARAMETER Name Specify a name to match against the interface name. .PARAMETER Object A running COM object to query for interfaces (can take a long time/hang). .PARAMETER Proxy Return interfaces which have a registered proxy class. .PARAMETER TypeLib Return interfaces which have a registered type library. .PARAMETER Source Return interfaces which came from a specific source. .INPUTS None .OUTPUTS OleViewDotNet.COMInterfaceEntry .EXAMPLE Get-ComInterface Get all COM interfaces from the current database. .EXAMPLE Get-ComInterface -Database $comdb Get all COM interfaces from a specific database. .EXAMPLE Get-ComInterface -Iid "00000001-0000-0000-C000-000000000046" Get COM interface from an IID from a database. .EXAMPLE Get-ComInterface -Name "IBlah" Get COM interface which is called IBlah. .EXAMPLE Get-ComInterface -Object $obj Get COM interfaces supported by an object. #> function Get-ComInterface { [CmdletBinding(DefaultParameterSetName = "All")] Param( [Parameter(Position = 0, Mandatory, ParameterSetName = "FromIid", ValueFromPipelineByPropertyName)] [Guid]$Iid, [Parameter(ParameterSetName = "FromIid")] [switch]$AllowNoReg, [Parameter(Mandatory, ParameterSetName = "FromPartialIid")] [string]$PartialIid, [Parameter(Mandatory, ParameterSetName = "FromName")] [string]$Name, [Parameter(Mandatory, ParameterSetName = "FromObject")] [object]$Object, [Parameter(Mandatory, ParameterSetName = "FromProxy")] [switch]$Proxy, [Parameter(Mandatory, ParameterSetName = "FromTypeLib")] [switch]$TypeLib, [Parameter(Mandatory, ParameterSetName = "FromSource")] [OleViewDotNet.Database.COMRegistryEntrySource]$Source, [OleViewDotNet.Database.COMRegistry]$Database ) $Database = Get-CurrentComDatabase $Database if ($null -eq $Database) { Write-Error "No database specified and current database isn't set" return } switch($PSCmdlet.ParameterSetName) { "All" { Write-Output $Database.Interfaces.Values } "FromName" { Get-ComInterface -Database $Database | Where-Object Name -eq $Name | Write-Output } "FromPartialIid" { Get-ComInterface -Database $Database | Where-Object Iid -Match $PartialIid | Write-Output } "FromIid" { if ($AllowNoReg) { $Database.MapIidToInterface($Iid) | Write-Output } else { $Database.Interfaces[$Iid] | Write-Output } } "FromObject" { $Database.GetInterfacesForObject($Object) | Write-Output } "FromProxy" { Get-ComInterface -Database $Database | Where-Object ProxyClassEntry -ne $null | Write-Output } "FromTypeLib" { Get-ComInterface -Database $Database | Where-Object TypeLibEntry -ne $null | Write-Output } "FromSource" { Get-ComInterface -Database $Database | Where-Object Source -eq $Source | Write-Output } } } <# .SYNOPSIS Filter launch accessible COM database information. .DESCRIPTION This cmdlet filters various types of COM database information such as Classes, AppIDs and processes to only those launchable accessible by certain processes or tokens. .PARAMETER InputObject The COM object entry to select on. .PARAMETER Token An access token to perform the access check on. .PARAMETER Process A process to get the access token from for the access check. .PARAMETER ProcessId A process ID to get the access token from for the access check. .PARAMETER Access The access mask to check, for access permissions. Defaults to local execute. .PARAMETER Access The access mask to check, for launch permissions. Defaults to local execute and activation. .PARAMETER Principal The principal for the access check, defaults to the current user. .PARAMETER NotAccessible Filter out accessible objects. .PARAMETER IgnoreDefault If the object doesn't have a specific set of launch permissions uses the system default. If this flag is specified objects without a specific launch permission are ignored. .INPUTS OleViewDotNet.ICOMAccessSecurity .OUTPUTS OleViewDotNet.ICOMAccessSecurity .EXAMPLE Get-ComClass | Select-ComAccess Get all COM classes which are accessible by the current process. .EXAMPLE Get-ComClass | Select-ComAccess -IgnoreDefault Get all COM classes which are accessible by the current process ignoring default security permissions. .EXAMPLE Get-ComClass | Select-ComAccess -Token $token Get all COM classes which are accessible by a specified token. .EXAMPLE Get-ComClass | Select-ComAccess -Process $process Get all COM classes which are accessible by a specified process. .EXAMPLE Get-ComClass | Select-ComAccess -ProcessId 1234 Get all COM classes which are accessible by a specified process from its ID. .EXAMPLE Get-ComClass | Select-ComAccess -Access 0 Only check for launch permissions and ignore access permissions. .EXAMPLE Get-ComClass | Select-ComAccess -LaunchAccess 0 Only check for access permissions and ignore launch permissions. #> function Select-ComAccess { [CmdletBinding(DefaultParameterSetName = "FromProcessId")] Param( [Parameter(Mandatory, Position = 0, ValueFromPipeline)] [OleViewDotNet.ICOMAccessSecurity]$InputObject, [OleViewDotNet.COMAccessRights]$Access = "ExecuteLocal", [OleViewDotNet.COMAccessRights]$LaunchAccess = "ActivateLocal, ExecuteLocal", [Parameter(Mandatory, ParameterSetName = "FromToken")] [NtApiDotNet.NtToken]$Token, [Parameter(Mandatory, ParameterSetName = "FromProcess")] [NtApiDotNet.NtProcess]$Process, [Parameter(ParameterSetName = "FromProcessId")] [alias("pid")] [int]$ProcessId = $pid, [NtApiDotNet.Sid]$Principal = [NtApiDotNet.NtProcess]::Current.User, [switch]$NotAccessible, [switch]$IgnoreDefault ) BEGIN { switch($PSCmdlet.ParameterSetName) { "FromProcessId" { $access_check = [OleViewDotNet.PowerShell.PowerShellUtils]::GetAccessCheck($ProcessId, ` $Principal, $Access, $LaunchAccess, $IgnoreDefault) } "FromProcess" { $access_check = [OleViewDotNet.PowerShell.PowerShellUtils]::GetAccessCheck($Process, ` $Principal, $Access, $LaunchAccess, $IgnoreDefault) } "FromToken" { $access_check = [OleViewDotNet.PowerShell.PowerShellUtils]::GetAccessCheck($Token, ` $Principal, $Access, $LaunchAccess, $IgnoreDefault) } } } PROCESS { $result = $access_check.AccessCheck($InputObject) if ($NotAccessible) { $result = !$result } if ($result) { Write-Output $InputObject } } END { if ($null -ne $access_check) { $access_check.Dispose() } } } Enum ComObjRefOutput { Object Bytes Moniker } function Out-ObjRef { [CmdletBinding()] Param( [parameter(Mandatory, Position = 0, ValueFromPipeline)] [OleViewDotNet.ComObjRef]$ObjRef, [ComObjRefOutput]$Output = "Object" ) switch($Output) { "Bytes" { Write-Output $objref.ToArray() } "Moniker" { $moniker = $objref.ToMoniker() Write-Output $moniker } "Object" { Write-Output $objref } } } <# .SYNOPSIS Get an OBJREF for a COM object. .DESCRIPTION This cmdlet marshals a COM object to an OBJREF, returning a byte array, a COMObjRef object or a moniker. .PARAMETER Object The object to marshal. .PARAMETER Path Specify a path for the output OBJREF. .PARAMETER Output Specify the output mode for the OBJREF. .PARAMETER IID Specify the IID to marshal. .PARAMETER MarshalContext Specify the context to marshal for. .PARAMETER MarshalFlags Specify flags for the marshal operation. .INPUTS None .OUTPUTS OleViewDotNet.COMObjRef or string. .EXAMPLE Get-ComObjRef $obj Marshal an object to the file marshal.bin as a COMObjRef object. .EXAMPLE Get-ComObjRef $obj -Output Bytes | Set-Content objref.bin -Encoding Bytes Marshal an object to a byte array and write to a file. .EXAMPLE Get-ComObjRef $obj -Output Moniker Marshal an object to a moniker. .EXAMPLE Get-ComObjRef objref.bin Gets an OBJREF from a file. #> function Get-ComObjRef { [CmdletBinding(DefaultParameterSetName = "FromPath")] Param( [Parameter(Mandatory, Position = 0, ParameterSetName = "FromObject")] [object]$Object, [Parameter(Mandatory, Position = 0, ParameterSetName = "FromPath")] [string]$Path, [Parameter(Mandatory, Position = 0, ParameterSetName = "FromBytes")] [byte[]]$Bytes, [ComObjRefOutput]$Output = "Object", [Parameter(ParameterSetName = "FromObject", ValueFromPipelineByPropertyName)] [Guid]$Iid = "00000000-0000-0000-C000-000000000046", [Parameter(ParameterSetName = "FromObject")] [OleViewDotNet.MSHCTX]$MarshalContext = "DIFFERENTMACHINE", [Parameter(ParameterSetName = "FromObject")] [OleViewdotNet.MSHLFLAGS]$MarshalFlags = "NORMAL" ) BEGIN { switch($PSCmdlet.ParameterSetName) { "FromObject" { $Object = Unwrap-ComObject $Object } } } PROCESS { switch($PSCmdlet.ParameterSetName) { "FromObject" { [OleViewDotNet.COMUtilities]::MarshalObjectToObjRef($Object, ` $Iid, $MarshalContext, $MarshalFlags) | Out-ObjRef -Output $Output } "FromPath" { $ba = Get-Content -Path $Path -Encoding Byte [OleViewDotNet.COMObjRef]::FromArray($ba) | Out-ObjRef -Output $Output } "FromBytes" { [OleViewDotNet.COMObjRef]::FromArray($Bytes) | Out-ObjRef -Output $Output } } } } <# .SYNOPSIS Views a COM security descriptor. .DESCRIPTION This cmdlet opens a viewer for a COM security descriptor. .PARAMETER SecurityDescriptor The security descriptor to view in SDDL format. .PARAMETER ShowAccess Show access rights rather than launch rights. .PARAMETER InputObject Shows the security descriptor for a database object. .PARAMETER Default Shows the default security descriptor for the specified database. .PARAMETER RuntimeDefault Shows the default security descriptor for the Windows Runtime Broker. .PARAMETER Restriction Shows the security descriptor restriction for the specified database. .PARAMETER Database Specify the database for showing the default or restriction security descriptors. .INPUTS None .OUTPUTS None .EXAMPLE Show-ComSecurityDescriptor $obj Shows a launch security descriptor from an object. .EXAMPLE Show-ComSecurityDescriptor $obj -ShowAccess Shows an access security descriptor from an object. .EXAMPLE Show-ComSecurityDescriptor "D:(A;;GA;;;WD)" Shows a SDDL launch security descriptor. .EXAMPLE Show-ComSecurityDescriptor "D:(A;;GA;;;WD)" -ShowAccess Shows a SDDL access security descriptor. .EXAMPLE Show-ComSecurityDescriptor -Default Show the default launch security descriptor for the current database. .EXAMPLE Show-ComSecurityDescriptor -Default -ShowAccess Show the default access security descriptor for the current database. .EXAMPLE Show-ComSecurityDescriptor -Restriction Show the launch security descriptor restriction for the current database. .EXAMPLE Show-ComSecurityDescriptor -Restriction -ShowAccess Show the access security descriptor restriction for the current database. #> function Show-ComSecurityDescriptor { [CmdletBinding(DefaultParameterSetName="FromObject")] Param( [Parameter(Mandatory, ParameterSetName = "FromSddl")] [string]$SecurityDescriptor, [Parameter(Mandatory, Position = 0, ValueFromPipeline, ParameterSetName = "FromObject")] [OleViewDotNet.ICOMAccessSecurity]$InputObject, [Parameter(Mandatory, ParameterSetName = "FromRestriction")] [switch]$Restriction, [Parameter(Mandatory, ParameterSetName = "FromDefault")] [switch]$Default, [Parameter(Mandatory, ParameterSetName = "FromRuntimeDefault")] [switch]$RuntimeDefault, [Parameter(ParameterSetName = "FromRestriction")] [Parameter(ParameterSetName = "FromDefault")] [OleViewDotNet.Database.COMRegistry]$Database, [switch]$ShowAccess ) PROCESS { if ($PSCmdlet.ParameterSetName -eq "FromRestriction" -or $PSCmdlet.ParameterSetName -eq "FromDefault") { $Database = Get-CurrentComDatabase $Database if ($null -eq $Database) { Write-Error "No database specified and current database isn't set" return } } $name = "" switch($PSCmdlet.ParameterSetName) { "FromSddl" { # Do nothing. } "FromObject" { if ($ShowAccess) { $SecurityDescriptor = [OleViewDotNet.COMAccessCheck]::GetAccessPermission($InputObject) } else { $SecurityDescriptor = [OleViewDotNet.COMAccessCheck]::GetLaunchPermission($InputObject) } $name = $InputObject.Name.Replace("`"", " ") } "FromDefault" { if ($ShowAccess) { $SecurityDescriptor = $Database.DefaultAccessPermission } else { $SecurityDescriptor = $Database.DefaultLaunchPermission } $name = "Default" } "FromRestriction" { if ($ShowAccess) { $SecurityDescriptor = $Database.DefaultAccessRestriction } else { $SecurityDescriptor = $Database.DefaultLaunchRestriction } $name = "Restriction" } "FromRuntimeDefault" { $SecurityDescriptor = [OleViewDotNet.Database.COMRuntimeClassEntry]::DefaultActivationPermission } } if ("" -ne $SecurityDescriptor) { $exe = [OleViewDotNet.COMUtilities]::GetExePathForCurrentBitness() if ($ShowAccess) { $cmd = "-v" } else { $cmd = "-l" } $args = @("`"$cmd=$SecurityDescriptor`"") if ("" -ne $name) { $args += @("`"-n=$name`"") } Start-Process $exe $args } } } <# .SYNOPSIS Creates a new COM object instance. .DESCRIPTION This cmdlet creates a new COM object instance from a class or factory. .PARAMETER Class Specify the class to use for the new COM object. .PARAMETER Factory Specify an existing class factory for the new COM object. .PARAMETER Clsid Specify a CLSID to use for the new COM object. .PARAMETER ClassContext Specify the context the new object will be created from. .PARAMETER RemoteServer Specify the remote server the COM object will be created on. .PARAMETER SessionId Specify the console session to create the object in. .PARAMETER NoWrapper Don't wrap object in a callable wrapper. .PARAMETER Iid Specify the interface to query for initially. .PARAMETER LoadType Specify to load interface type from proxy/typelib if available and not already loaded. .PARAMETER Database Specify with LoadType to indicate the database to get interface information from. .PARAMETER Ipid Create the object from an existing IPID. #> function New-ComObject { [CmdletBinding(DefaultParameterSetName="FromClass")] Param( [Parameter(Mandatory, Position = 0, ParameterSetName = "FromClass", ValueFromPipeline)] [Parameter(Mandatory, Position = 0, ParameterSetName = "FromSessionIdClass")] [OleViewDotNet.Database.ICOMClassEntry]$Class, [Parameter(Mandatory, Position = 0, ParameterSetName = "FromFactory", ValueFromPipeline)] [OleViewDotNet.Wrappers.IClassFactoryWrapper]$Factory, [Parameter(Mandatory, Position = 0, ParameterSetName = "FromActivationFactory")] [OleViewDotNet.Wrappers.IActivationFactoryWrapper]$ActivationFactory, [Parameter(Mandatory, ParameterSetName = "FromClsid")] [Parameter(Mandatory, ParameterSetName = "FromSessionIdClsid")] [Guid]$Clsid, [Parameter(ParameterSetName = "FromClsid")] [Parameter(ParameterSetName = "FromClass")] [OleViewDotNet.CLSCTX]$ClassContext = "ALL", [Parameter(ParameterSetName = "FromClsid")] [Parameter(ParameterSetName = "FromClass")] [string]$RemoteServer, [Parameter(ParameterSetName = "FromObjRef")] [OleViewDotNet.COMObjRef]$ObjRef, [Parameter(ParameterSetName = "FromIpid")] [OleViewDotNet.COMIPIDEntry]$Ipid, [Parameter(Mandatory, ParameterSetName = "FromSessionIdClass")] [Parameter(Mandatory, ParameterSetName = "FromSessionIdClsid")] [int]$SessionId, [switch]$NoWrapper, [Guid]$Iid = [guid]::Empty, [switch]$LoadType, [OleViewDotNet.Database.COMRegistry]$Database ) PROCESS { $obj = $null $iid_set = $true if ($Iid -eq [guid]::Empty) { $Iid = "00000000-0000-0000-C000-000000000046" $iid_set = $false } switch($PSCmdlet.ParameterSetName) { "FromClass" { $obj = $Class.CreateInstanceAsObject($ClassContext, $RemoteServer) } "FromClsid" { $obj = [OleViewDotNet.COMUtilities]::CreateInstanceAsObject($Clsid, ` $Iid, $ClassContext, $RemoteServer) } "FromFactory" { $obj = [OleViewDotNet.COMUtilities]::CreateInstanceFromFactory($Factory, $Iid) } "FromActivationFactory" { $obj = $ActivationFactory.ActivateInstance() } "FromObjRef" { $obj = [OleViewDotNet.COMUtilities]::UnmarshalObject($ObjRef) } "FromIpid" { $obj = [OleViewDotNet.COMUtilities]::UnmarshalObject($Ipid.ToObjRef()) } "FromSessionIdClass" { $obj = Get-ComMoniker "session:$SessionId!new:$($Class.Clsid)" -Bind -NoWrapper } "FromSessionIdClsid" { $obj = Get-ComMoniker "session:$SessionId!new:$Clsid" -Bind -NoWrapper } } if ($null -ne $obj) { if ($null -ne $Ipid -and !$iid_set) { Wrap-ComObject $obj -Ipid $Ipid -NoWrapper:$NoWrapper | Write-Output } else { Wrap-ComObject $obj -Iid $Iid -NoWrapper:$NoWrapper -LoadType:$LoadType -DataBase $DataBase | Write-Output } } } } <# .SYNOPSIS Creates a new COM object factory. .DESCRIPTION This cmdlet creates a new COM object factory from a class. .PARAMETER Class Specify the class to use for the new COM object factory. .PARAMETER Clsid Specify a CLSID to use for the new COM object factory. .PARAMETER ClassContext Specify the context the new factory will be created from. .PARAMETER RemoteServer Specify the remote server the COM object factory will be created on. .PARAMETER SessionId Specify the console session to create the factory in. .PARAMETER NoWrapper Don't wrap factory object in a callable wrapper. #> function New-ComObjectFactory { [CmdletBinding(DefaultParameterSetName="FromClass")] Param( [Parameter(Mandatory, Position = 0, ParameterSetName = "FromClass", ValueFromPipeline)] [Parameter(Mandatory, Position = 0, ParameterSetName = "FromSessionIdClass")] [OleViewDotNet.Database.ICOMClassEntry]$Class, [Parameter(Mandatory, Position = 0, ParameterSetName = "FromClsid")] [Parameter(Mandatory, Position = 0, ParameterSetName = "FromSessionIdClsid")] [Guid]$Clsid, [Parameter(ParameterSetName = "FromClsid")] [Parameter(ParameterSetName = "FromClass")] [OleViewDotNet.CLSCTX]$ClassContext = "ALL", [Parameter(ParameterSetName = "FromClsid")] [Parameter(ParameterSetName = "FromClass")] [string]$RemoteServer, [Parameter(Mandatory, ParameterSetName = "FromSessionIdClass")] [Parameter(Mandatory, ParameterSetName = "FromSessionIdClsid")] [int]$SessionId, [switch]$NoWrapper ) PROCESS { $obj = $null switch($PSCmdlet.ParameterSetName) { "FromClass" { $obj = $Class.CreateClassFactory($ClassContext, $RemoteServer) } "FromClsid" { $obj = [OleViewDotNet.COMUtilities]::CreateClassFactory($Clsid, ` "00000000-0000-0000-C000-000000000046", $ClassContext, $RemoteServer) } "FromSessionIdClass" { $obj = Get-ComMoniker "session:$SessionId!clsid:$($Class.Clsid)" -Bind -NoWrapper } "FromSessionIdClsid" { $obj = Get-ComMoniker "session:$SessionId!clsid:$Clsid" -Bind -NoWrapper } } if ($null -ne $obj) { $type = [OleViewDotNet.PowerShell.PowerShellUtils]::GetFactoryType($Class) Wrap-ComObject $obj $type -NoWrapper:$NoWrapper | Write-Output } } } <# .SYNOPSIS Creates a new COM moniker instance and optionally binds to it. .DESCRIPTION This cmdlet creates a new COM moniker instance and optionally binds to the object. .PARAMETER NoWrapper Don't wrap object in a callable wrapper. .PARAMETER Moniker Specify a moniker to parse. .PARAMETER Bind Bind to parsed moniker. .PARAMETER Composite Parse the moniker as a composite, each component separated by a '!' #> function Get-ComMoniker { Param( [Parameter(Mandatory, Position = 0)] [string]$Moniker, [switch]$Bind, [switch]$Composite, [switch]$NoWrapper ) $obj = $null if ($Bind) { $type = [OleViewDotNet.IUnknown] $obj = [OleViewDotNet.COMUtilities]::ParseAndBindMoniker($Moniker, $Composite) } else { $type = [System.Runtime.InteropServices.ComTypes.IMoniker] $obj = [OleViewDotNet.COMUtilities]::ParseMoniker($Moniker, $Composite) } if ($null -ne $obj) { Wrap-ComObject $obj $type -NoWrapper:$NoWrapper | Write-Output } } <# .SYNOPSIS Gets the display name from a COM moniker. .DESCRIPTION This cmdlet gets the display name from a COM moniker .PARAMETER Moniker Specify a moniker to get the display name from. #> function Get-ComMonikerDisplayName { Param( [Parameter(Mandatory, Position = 0)] [System.Runtime.InteropServices.ComTypes.IMoniker]$Moniker ) [OleViewDotNet.COMUtilities]::GetMonikerDisplayName($Moniker) | Write-Output } <# .SYNOPSIS Parses COM proxy information for an interface or a proxy class. .DESCRIPTION This cmdlet parses the COM proxy information for an interface or specified COM proxy class. If a class is specified all interfaces from that class are returned. .PARAMETER Class A COM proxy class. .PARAMETER Interface A COM interface with a registered proxy. .PARAMETER InterfaceInstance A COM interface instance. .PARAMETER Iid A COM IID which is being proxied. .PARAMETER AsText Return the results as text rather than objects. .OUTPUTS The parsed proxy information and complex types. .EXAMPLE Get-ComProxy $intf Parse the proxy information for an interface. .EXAMPLE Get-ComProxy $class Parse the proxy information for a class. .EXAMPLE Get-ComProxy "00000001-0000-0000-C000-000000000046" Parse the proxy based on a IID. #> function Get-ComProxy { [CmdletBinding(DefaultParameterSetName = "FromIid")] Param( [parameter(Mandatory, Position=0, ParameterSetName = "FromInterface", ValueFromPipeline)] [OleViewDotNet.Database.COMInterfaceEntry]$Interface, [parameter(Mandatory, Position=0, ParameterSetName = "FromInterfaceInstance", ValueFromPipeline)] [OleViewDotNet.Database.COMInterfaceInstance]$InterfaceInstance, [parameter(Mandatory, Position=0, ParameterSetName = "FromClass")] [OleViewDotNet.Database.COMClsidEntry]$Class, [parameter(Mandatory, ParameterSetName = "FromClsid")] [Guid]$Clsid, [parameter(Mandatory, Position=0, ParameterSetName = "FromIid")] [Guid]$Iid, [parameter(ParameterSetName = "FromIid")] [parameter(ParameterSetName = "FromClsid")] [OleViewDotNet.Database.COMRegistry]$Database, [switch]$AsText ) PROCESS { $proxy = switch($PSCmdlet.ParameterSetName) { "FromClass" { [OleViewDotNet.COMProxyInstance]::GetFromCLSID($Class, $null) } "FromInterface" { [OleViewDotNet.COMProxyInterfaceInstance]::GetFromIID($Interface, $null) } "FromInterfaceInstance" { [OleViewDotNet.COMProxyInterfaceInstance]::GetFromIID($InterfaceInstance, $null) } "FromIid" { $intf = Get-ComInterface -Database $Database -Iid $Iid if ($null -ne $intf) { [OleViewDotNet.COMProxyInterfaceInstance]::GetFromIID($intf, $null) } } "FromClsid" { $class = Get-ComClass -Database $Database -Clsid $Clsid if ($null -ne $class) { [OleViewDotNet.COMProxyInstance]::GetFromCLSID($class, $null) } } } if ($null -ne $proxy) { if ($AsText) { Write-Output $proxy.FormatText() } else { Write-Output $proxy } } } } <# .SYNOPSIS Sets the COM symbol resolver paths. .DESCRIPTION This cmdlet sets the COM symbol resolver paths. This allows you to specify symbol resolver paths for cmdlets which support it. .PARAMETER DbgHelpPath Specify path to a dbghelp DLL to use for symbol resolving. This should be ideally the dbghelp from debugging tool for Windows which will allow symbol servers however you can use the system version if you just want to pull symbols locally. .PARAMETER SymbolPath Specify path for the symbols. .INPUTS None .OUTPUTS None .EXAMPLE Set-ComSymbolResolver -DbgHelpPath c:\windbg\x64\dbghelp.dll Specify the global dbghelp path. .EXAMPLE Set-ComSymbolResolver -DbgHelpPath dbghelp.dll -SymbolPath "c:\symbols" Specify the global dbghelp path using c:\symbols to source the symbol files. #> function Set-ComSymbolResolver { Param( [alias("dbghelp")] [parameter(Mandatory, Position=0)] [string]$DbgHelpPath, [parameter(Position=1)] [string]$SymbolPath ) $Script:GlobalDbgHelpPath = $DbgHelpPath if ("" -ne $SymbolPath) { $Script:GlobalSymbolPath = $SymbolPath } } <# .SYNOPSIS Gets IPID entries for a COM object. .DESCRIPTION This cmdlet gets the IPID entries for a COM object. It queries for all known remote interfaces on the object, marshal the interfaces then parse the containing process. If the containing process cannot be opend then this will fail. .PARAMETER Database The COM database to extract information from. .PARAMETER object The object to query. .PARAMETER DbgHelpPath Specify path to a dbghelp DLL to use for symbol resolving. This should be ideally the dbghelp from debugging tool for Windows which will allow symbol servers however you can use the system version if you just want to pull symbols locally. .PARAMETER SymbolPath Specify path for the symbols. .PARAMETER ResolveMethodNames Specify to try and resolve method names for interfaces. .INPUTS None .OUTPUTS OleViewDotNet.COMIPIDEntry[] .EXAMPLE Get-ComObjectIpid $comdb $obj Get all .EXAMPLE Set-ComSymbolResolver -DbgHelpPath dbghelp.dll -SymbolPath "c:\symbols" Specify the global dbghelp path using c:\symbols to source the symbol files. #> function Get-ComObjectIpid { [CmdletBinding()] Param( [parameter(Mandatory, Position=0)] [object]$Object, [OleViewDotNet.Database.COMRegistry]$Database, [alias("dbghelp")] [string]$DbgHelpPath = "", [string]$SymbolPath = "", [switch]$ResolveMethodNames ) $Database = Get-CurrentComDatabase $Database if ($null -eq $Database) { Write-Error "No database specified and current database isn't set" return } $resolver = Get-ComSymbolResolver $DbgHelpPath $SymbolPath $ps = Get-ComInterface -Database $Database -Object $Object | Get-ComObjRef $Object | Get-ComProcess -Database $Database ` -DbgHelpPath $resolver.DbgHelpPath -ParseStubMethods -SymbolPath $resolver.SymbolPath -ResolveMethodNames:$ResolveMethodNames $ps.Ipids | Write-Output } <# .SYNOPSIS Get registered class information from COM processes. .DESCRIPTION This cmdlet parses all accessible processes for registered COM clsses. .PARAMETER Database The database to use to lookup information. .PARAMETER DbgHelpPath Specify location of DBGHELP.DLL file. For remote symbol support use one from Debugging Tools for Windows. .PARAMETER SymbolPath Specify the location of symbols for the resolver. .PARAMETER NoProgress Don't show progress for process parsing. .INPUTS None .OUTPUTS OleViewDotNet.COMProcessClassRegistration .EXAMPLE Get-ComRegisteredClass Get all COM registered classes accessible. #> function Get-ComRegisteredClass { [CmdletBinding()] Param( [OleViewDotNet.Database.COMRegistry]$Database, [alias("dbghelp")] [string]$DbgHelpPath = "", [string]$SymbolPath = "", [switch]$NoProgress ) $Database = Get-CurrentComDatabase $Database if ($null -eq $Database) { Write-Error "No database specified and current database isn't set" return } Get-ComProcess -DbgHelpPath $DbgHelpPath -SymbolPath $SymbolPath -Database $Database -ParseRegisteredClasses -NoProgress:$NoProgress ` | select -ExpandProperty Classes | Where-Object {$_.Context -eq 0 -or $_.Context -match "LOCAL_SERVER"} | Write-Output } <# .SYNOPSIS Formats a COM proxy or IPID as text. .DESCRIPTION This cmdlet formats a COM proxy object or IPID entry as text. .PARAMETER Proxy The proxy or IPID entry to format. .PARAMETER Flags Specify flags for the formatter. .PARAMETER Process Format the IPIDs of a COM process. .INPUTS OleViewDotNet.IProxyFormatter .OUTPUTS string .EXAMPLE Format-ComProxy $proxy Format a COM proxy as text. .EXAMPLE Format-ComProxy $proxy -Flags RemoveComments Format a COM proxy as text removing comments. .EXAMPLE Format-ComProxy $proxy -Flags RemoveComplexTypes Format a COM proxy as text removing complex types. .EXAMPLE $ipids | Format-ComProxy Format a list of IPIDs as text. #> function Format-ComProxy { [CmdletBinding(DefaultParameterSetName="FromProxy")] Param( [parameter(Mandatory, Position=0, ValueFromPipeline, ParameterSetName="FromProxy")] [OleViewDotNet.IProxyFormatter]$Proxy, [parameter(Mandatory, Position=0, ValueFromPipeline, ParameterSetName="FromProcess")] [OleViewDotNet.COMProcessEntry]$Process, [parameter(Mandatory, Position=0, ValueFromPipeline, ParameterSetName="FromInterface")] [OleViewDotNet.Database.COMInterfaceEntry]$Interface, [parameter(Mandatory, Position=0, ValueFromPipeline, ParameterSetName = "FromInterfaceInstance")] [OleViewDotNet.Database.COMInterfaceInstance]$InterfaceInstance, [OleViewDotNet.ProxyFormatterFlags]$Flags = 0 ) PROCESS { switch($PSCmdlet.ParameterSetName) { "FromProxy" { $Proxy.FormatText($Flags) | Write-Output } "FromProcess" { $Process.Ipids | Format-ComProxy -Flags $Flags } "FromInterface" { $Interface | Get-ComProxy | Format-ComProxy -Flags $Flags } "FromInterfaceInstance" { $InterfaceInstance | Get-ComProxy | Format-ComProxy -Flags $Flags } } } } <# .SYNOPSIS Gets registered COM type libraries. .DESCRIPTION This cmdlet gets all COM type libraries from a database.` .PARAMETER Database The database to use to lookup information. .PARAMETER Iid Get type library from an IID if that interface has a type library. .PARAMETER Source Specify a source where the typelib came from. .INPUTS None .OUTPUTS OleViewDotNet.COMTypeLibVersionEntry[] .EXAMPLE Get-ComTypeLib Get all COM registered type libraries. #> function Get-ComTypeLib { [CmdletBinding(DefaultParameterSetName = "All")] Param( [parameter(Mandatory, ParameterSetName = "FromIid", Position=0)] [Guid]$Iid, [parameter(Mandatory, ParameterSetName = "FromInterface")] [OleViewDotNet.Database.COMInterfaceEntry]$Interface, [parameter(Mandatory, ParameterSetName = "FromInterfaceInstance")] [OleViewDotNet.Database.COMInterfaceInstance]$InterfaceInstance, [Parameter(Mandatory, ParameterSetName = "FromSource")] [OleViewDotNet.Database.COMRegistryEntrySource]$Source, [OleViewDotNet.Database.COMRegistry]$Database ) $Database = Get-CurrentComDatabase $Database if ($null -eq $Database) { Write-Error "No database specified and current database isn't set" return } switch($PSCmdlet.ParameterSetName) { "All" { $Database.Typelibs.Values.Versions | Write-Output } "FromIid" { $intf = Get-ComInterface -Database $Database -Iid $Iid if ($null -ne $intf) { $intf.TypeLibVersionEntry | Write-Output } } "FromInterface" { Get-ComTypeLib $Interface.Iid -Database $Database | Write-Output } "FromInterfaceInstance" { Get-ComTypeLib $InterfaceInstance.Iid -Database $Database | Write-Output } "FromSource" { Get-ComTypeLib -Database $Database | Where-Object Source -eq $Source | Write-Output } } } <# .SYNOPSIS Gets a .NET assembly which represents the type library. .DESCRIPTION This cmdlet converts a type library to a .NET assembly. This process can take a while depending on the size of the library. .PARAMETER TypeLib The type library version entry to convert. .PARAMETER Path The path to a type library to convert. .PARAMETER NoProgress Don't show progress during conversion. .INPUTS OleViewDotNet.COMTypeLibVersionEntry or string. .OUTPUTS System.Reflection.Assembly .EXAMPLE Get-ComTypeLibAssembly $typelib Get a .NET assembly from a type library entry. #> function Get-ComTypeLibAssembly { [CmdletBinding()] Param( [parameter(Mandatory, ValueFromPipeline, ParameterSetName = "FromTypeLib", Position=0)] [OleViewDotNet.Database.COMTypeLibVersionEntry]$TypeLib, [parameter(Mandatory, ParameterSetName = "FromPath")] [string]$Path, [switch]$NoProgress ) PROCESS { $callback = New-CallbackProgress -Activity "Converting TypeLib" -NoProgress:$NoProgress if ($PSCmdlet.ParameterSetName -eq "FromTypeLib") { $Path = "" if ([Environment]::Is64BitProcess) { $Path = $TypeLib.Win64Path } if ($Path -eq "") { $Path = $TypeLib.Win32Path } } if ($Path -ne "") { [OleViewDotNet.COMUtilities]::LoadTypeLib($Path, $callback) | Write-Output } } } <# .SYNOPSIS Formats a .NET assembly or Type which represents COM type. .DESCRIPTION This cmdlet formats a .NET assembly or a .NET type which represents a COM type. .PARAMETER Assembly Specify a converted COM type library assembly. .PARAMETER InterfacesOnly Only convert interfaces to text. .PARAMETER Type Specify COM type object. .PARAMETER TypeLib Specify a registered COM typelib entry to format. .PARAMETER NoProgress Don't show progress for conversion. .PARAMETER Path The path to a type library to format. .INPUTS System.Reflection.Assembly .OUTPUTS string .EXAMPLE Format-ComTypeLib $typelib Format a .NET assembly. .EXAMPLE Format-ComTypeLib $type Format a .NET assembly. #> function Format-ComTypeLib { [CmdletBinding()] Param( [parameter(Mandatory, ValueFromPipeline, Position=0, ParameterSetName = "FromAssembly")] [System.Reflection.Assembly]$Assembly, [parameter(Mandatory, ValueFromPipeline, Position=0, ParameterSetName = "FromType")] [System.Type]$Type, [parameter(Mandatory, ValueFromPipeline, Position=0, ParameterSetName = "FromTypeLib")] [OleViewDotNet.Database.COMTypeLibVersionEntry]$TypeLib, [parameter(Mandatory, ParameterSetName = "FromPath")] [string]$Path, [parameter(ParameterSetName = "FromAssembly")] [parameter(ParameterSetName = "FromTypeLib")] [parameter(ParameterSetName = "FromPath")] [switch]$InterfacesOnly, [parameter(ParameterSetName = "FromTypeLib")] [parameter(ParameterSetName = "FromPath")] [switch]$NoProgress ) PROCESS { switch($PSCmdlet.ParameterSetName) { "FromAssembly" { [OleViewDotNet.COMUtilities]::FormatComAssembly($Assembly, $InterfacesOnly) | Write-Output } "FromType" { [OleViewDotNet.COMUtilities]::FormatComType($Type) | Write-Output } "FromTypeLib" { Get-ComTypeLibAssembly -TypeLib $TypeLib -NoProgress:$NoProgress | Format-ComTypeLib -InterfacesOnly:$InterfacesOnly } "FromPath" { Get-ComTypeLibAssembly -Path $Path -NoProgress:$NoProgress | Format-ComTypeLib -InterfacesOnly:$InterfacesOnly } } } } <# .SYNOPSIS Formats a GUID in various formats. .DESCRIPTION This cmdlet formats a GUID in various formats. .INPUTS System.Guid .OUTPUTS string .EXAMPLE Format-ComGuid $Guid Format a GUID to a string. .EXAMPLE Format-ComGuid $Guid Object Format a GUID to a HTML object. #> function Format-ComGuid { [CmdletBinding()] Param( [parameter(Mandatory, ValueFromPipeline, Position=0)] [Guid]$Guid, [OleViewDotNet.GuidFormat]$Format = "String" ) PROCESS { [OleViewDotNet.COMUtilities]::GuidToString($Guid, $Format) } } <# .SYNOPSIS Generate a symbol cache file for the current base DLL. .DESCRIPTION This cmdlet generates a symbol cache file in a specified directory. This should be copied to cached_symbols directory in the installation to allow you to parse processes without symbols. You need to do this in both a 32 and 64 bit process to get support for both symbols. .PARAMETER Path The directory where the cached symbol file will be created. .PARAMETER DbgHelpPath Specify location of DBGHELP.DLL file. For remote symbol support use one from Debugging Tools for Windows. .PARAMETER SymbolPath Specify the location of symbols for the resolver. .INPUTS None .OUTPUTS None .EXAMPLE Set-ComSymbolCache .\symbol_cache Generates a symbol cache in the "symbol_cache" directory. #> function Set-ComSymbolCache { [CmdletBinding()] Param( [parameter(Mandatory, Position = 0)] [string]$Path, [alias("dbghelp")] [string]$DbgHelpPath = "", [string]$SymbolPath = "" ) $resolver = Get-ComSymbolResolver $DbgHelpPath $SymbolPath $Path = Resolve-Path $Path if ($null -ne $Path) { [OleViewDotNet.COMUtilities]::ClearCachedSymbols() [OleViewDotNet.COMUtilities]::GenerateSymbolFile($Path, $resolver.DbgHelpPath, $resolver.SymbolPath) [OleViewDotNet.COMUtilities]::SetupCachedSymbols() } } <# .SYNOPSIS Creates a new OLE storage object. .DESCRIPTION This cmdlet creates a new OLE storage object based on a file. .PARAMETER Path The path to the storage object to create. .PARAMETER Mode The mode to use when creating the storage object. .PARAMETER Format The format of the storage object to create. .INPUTS None .OUTPUTS OleViewDotNet.StorageWrapper .EXAMPLE New-ComStorageObject storage.stg Creates a new storage object. #> function New-ComStorageObject { [CmdletBinding()] Param( [parameter(Mandatory, Position = 0)] [string]$Path, [OleViewDotNet.STGM]$Mode = "SHARE_EXCLUSIVE, READWRITE", [OleViewDotNet.STGFMT]$Format = "Storage" ) $type = [OleViewDotNet.IStorage] $iid = $type.GUID $Path = Resolve-LocalPath $Path [OleViewDotNet.COMUtilities]::CreateStorage($Path, $Mode, $Format) } <# .SYNOPSIS Opens an existing OLE storage object. .DESCRIPTION This cmdlet opens a existing OLE storage object based on a file. .PARAMETER Path The path to the storage object to open. .PARAMETER Mode The mode to use when opening the storage object. .PARAMETER Format The format of the storage object to open. .PARAMETER ReadOnly Opens storage read only. Overrides $Mode parameter. .INPUTS None .OUTPUTS OleViewDotNet.StorageWrapper .EXAMPLE Get-ComStorageObject storage.stg Creates a new storage object. #> function Get-ComStorageObject { [CmdletBinding()] Param( [parameter(Mandatory, Position = 0)] [string]$Path, [switch]$ReadOnly, [OleViewDotNet.STGM]$Mode = "SHARE_EXCLUSIVE, READWRITE", [OleViewDotNet.STGFMT]$Format = "Storage" ) $type = [OleViewDotNet.IStorage] $iid = $type.GUID $Path = Resolve-LocalPath $Path if ($ReadOnly) { $Mode = "SHARE_EXCLUSIVE, READ" } [OleViewDotNet.COMUtilities]::OpenStorage($Path, $Mode, $Format) } <# .SYNOPSIS Get COM runtime interfaces from local metadata. .DESCRIPTION This cmdlet gets types representing COM runtime interfaces based on a set of criteria. The default is to return all interfaces. .PARAMETER Iid Specify a IID to lookup. .PARAMETER Name Specify a name to match against the interface name. .PARAMETER FullName Specify a full name to match against the interface name. .INPUTS None .OUTPUTS System.Type .EXAMPLE Get-ComRuntimeInterface Get all COM runtime interfaces. .EXAMPLE Get-ComRuntimeInterface -Iid "00000001-0000-0000-C000-000000000046" Get COM runtime interface from an IID. .EXAMPLE Get-ComRuntimeInterface -Name "IBlah" Get COM runtime interface called IBlah. .EXAMPLE Get-ComRuntimeInterface -FullName "App.ABC.IBlah" Get COM runtime interface whose full name is App.ABC.IBlah. #> function Get-ComRuntimeInterface { [CmdletBinding(DefaultParameterSetName = "All")] Param( [Parameter(Mandatory, ParameterSetName = "FromIid", ValueFromPipelineByPropertyName)] [Guid]$Iid, [Parameter(Mandatory, ParameterSetName = "FromName")] [string]$Name, [Parameter(Mandatory, ParameterSetName = "FromFullName")] [string]$FullName ) PROCESS { switch($PSCmdlet.ParameterSetName) { "All" { [OleViewDotNet.COMUtilities]::RuntimeInterfaceMetadata.Values | Write-Output } "FromName" { Get-ComRuntimeInterface | Where-Object Name -eq $Name | Write-Output } "FromFullName" { Get-ComRuntimeInterface | Where-Object FullName -eq $FullName | Write-Output } "FromIid" { [OleViewDotNet.COMUtilities]::RuntimeInterfaceMetadata[$Iid] | Write-Output } } } } <# .SYNOPSIS Format COM clients as a DOT graph. .DESCRIPTION This cmdlet converts a set of processes with parsed clients into a DOT graph format. .PARAMETER Process One or more processes to format. .PARAMETER RemoveUnknownProcess Remove unknown processes from the graph. .PARAMETER IncludePid Include one or more PIDs as roots of the graph. .PARAMETER IncludeName Include one or more process names as roots of the graph. .PARAMETER Path Output the graph to a path. .INPUTS None .OUTPUTS string .EXAMPLE Format-ComProcessClient $ps Format a list of processes. .EXAMPLE Get-ComProcess -ParseClients | Format-ComProcessClient Format a list of processes. #> function Format-ComProcessClient { [CmdletBinding(DefaultParameterSetName = "All")] Param( [Parameter(Mandatory, Position = 0, ValueFromPipeline)] [OleViewDotNet.COMProcessEntry[]]$Process, [int[]]$IncludePid, [string[]]$IncludeName, [switch]$RemoveUnknownProcess, [string]$Path ) BEGIN { $builder = [OleViewDotNet.PowerShell.ComClientGraphBuilder]::new($IncludePid, $IncludeName, $RemoveUnknownProcess) } PROCESS { $builder.AddRange($Process) } END { if ("" -ne $Path) { $builder.ToString() | Set-Content -Path $Path } else { $builder.ToString() | Write-Output } } } <# .SYNOPSIS Get COM categories from a database. .DESCRIPTION This cmdlet gets the COM categories from a database. .PARAMETER CatId Specify a CATID to lookup. .PARAMETER Name Specify a name to match against the category name. .PARAMETER Database The COM database to use. .INPUTS None .OUTPUTS OleViewDotNet.COMCategory .EXAMPLE Get-ComCategory Get all COM categories. .EXAMPLE Get-ComCategory -CatId "00000001-0000-0000-C000-000000000046" Get COM category from a CATID. .EXAMPLE Get-ComCategory -Name "Blah" Get the COM category with the name blah. #> function Get-ComCategory { [CmdletBinding(DefaultParameterSetName = "All")] Param( [Parameter(Mandatory, ParameterSetName = "FromCatId")] [Guid]$CatId, [Parameter(Mandatory, ParameterSetName = "FromName")] [string]$Name, [OleViewDotNet.Database.COMRegistry]$Database ) $Database = Get-CurrentComDatabase $Database if ($null -eq $Database) { Write-Error "No database specified and current database isn't set" return } switch($PSCmdlet.ParameterSetName) { "All" { $Database.ImplementedCategories.Values | Write-Output } "FromName" { Get-ComCategory | Where-Object Name -eq $Name | Write-Output } "FromCatId" { $Database.ImplementedCategories[$CatId] | Write-Output } } } <# .SYNOPSIS Filter COM classes based on whether they support one or more interfaces. .DESCRIPTION This cmdlet filters COM classes for one or more supported interfaces. This can take a very long time if the interface list needs to be queried first. .PARAMETER InputObject The COM class entry to filter on. .PARAMETER Iid Filter on an IID or list of IIDs. .PARAMETER Name Filter on a name or list of names. .PARAMETER NameMatch Filter on a partial matching name. .PARAMETER Factory Filter based on the factory interfaces rather than the main class interfaces. .PARAMETER Refresh Specify to force the interfaces to be refreshed. .PARAMETER NoQuery Specify to not query for the interfaces at all and only return what's already available. .PARAMETER Exclude Specify to return classes which do not implement one of the interfaces. .PARAMETER NoProgress Don't show progress for query. .INPUTS OleViewDotNet.ICOMClassEntry .OUTPUTS OleViewDotNet.ICOMClassEntry .EXAMPLE Get-ComClass | Select-ComClassInterface -Name "IDispatch" Get all COM classes which implement IDispatch. .EXAMPLE Get-ComClass | Select-ComClassInterface -NameMatch "Blah" Get all COM classes which implement an interface containing the name Blah. .EXAMPLE Get-ComClass | Select-ComClassInterface -Iid "00020400-0000-0000-c000-000000000046" Get all COM classes which implement an interface with a specific IID. .EXAMPLE Get-ComClass | Select-ComClassInterface -Factory -Iid "00000001-0000-0000-C000-000000000046" Get all COM classes which implement a factory interface with a specific IID. #> function Select-ComClassInterface { [CmdletBinding(DefaultParameterSetName = "FromName")] Param( [Parameter(Mandatory, Position = 0, ValueFromPipeline)] [OleViewDotNet.Database.ICOMClassEntry]$InputObject, [Parameter(Mandatory, ParameterSetName = "FromIid")] [Guid[]]$Iid, [Parameter(Mandatory, ParameterSetName = "FromName")] [string[]]$Name, [Parameter(Mandatory, ParameterSetName = "FromNameMatch")] [string]$NameMatch, [switch]$Factory, [switch]$Refresh, [switch]$NoQuery, [switch]$Exclude, [switch]$NoProgress ) PROCESS { $result = $false $intfs = Get-ComClassInterface $InputObject -Factory:$Factory -Refresh:$Refresh -NoQuery:$NoQuery -NoProgress:$NoProgress $result = $false foreach($intf in $intfs) { switch($PSCmdlet.ParameterSetName) { "FromIid" { $result = $intf.Iid -in $Iid } "FromName" { $result = $intf.Name -in $Name } "FromNameMatch" { $result = $intf.Name -match $NameMatch } } if ($result) { break } } if ($Exclude) { $result = !$result } if ($result) { Write-Output $InputObject } } } <# .SYNOPSIS Get Windows Runtime extensions. .DESCRIPTION This cmdlet gets the Windows Runtime extensions from a database. .PARAMETER ContractId Specify a contract ID to lookup. .PARAMETER Launch Only show Windows.Launch extensions. .PARAMETER Protocol Only show Windows.Protocol extensions. Select out the Protocol property to see the name. .PARAMETER BackgroundTasks Only show Windows.BackgroundTasks extensions. .PARAMETER Database The COM database to use. .INPUTS None .OUTPUTS OleViewDotNet.COMRuntimeExtensionEntry .EXAMPLE Get-ComRuntimeExtension Get all Windows Runtime extensions. .EXAMPLE Get-ComRuntimeExtension -ContractId "Windows.Protocol" Get Windows Runtime extensions with contract ID of Windows.Protocol. .EXAMPLE Get-ComRuntimeExtension -Launch Get Windows Runtime extensions with contract ID of Windows.Launch. .EXAMPLE Get-ComRuntimeExtension -Protocol Get Windows Runtime extensions with contract ID of Windows.Protocol. .EXAMPLE Get-ComRuntimeExtension -BackgroundTasks Get Windows Runtime extensions with contract ID of Windows.BackgroundTasks. #> function Get-ComRuntimeExtension { [CmdletBinding(DefaultParameterSetName = "All")] Param( [Parameter(Mandatory, ParameterSetName = "FromCategoryId")] [string]$ContractId, [Parameter(Mandatory, ParameterSetName = "FromLaunch")] [switch]$Launch, [Parameter(Mandatory, ParameterSetName = "FromProtocol")] [switch]$Protocol, [Parameter(Mandatory, ParameterSetName = "FromBackgroundTasks")] [switch]$BackgroundTasks, [OleViewDotNet.Database.COMRegistry]$Database ) $Database = Get-CurrentComDatabase $Database if ($null -eq $Database) { Write-Error "No database specified and current database isn't set" return } switch($PSCmdlet.ParameterSetName) { "All" { $Database.RuntimeExtensions | Write-Output } "FromCategoryId" { $Database.RuntimeExtensionsByContractId[$ContractId] | Write-Output } "FromLaunch" { $Database.RuntimeExtensionsByContractId["Windows.Launch"] | Write-Output } "FromProtocol" { $Database.RuntimeExtensionsByContractId["Windows.Protocol"] | Write-Output } "FromBackgroundTasks" { $Database.RuntimeExtensionsByContractId["Windows.BackgroundTasks"] | Write-Output } } } <# .SYNOPSIS Start a Windows Runtime extension. .DESCRIPTION This cmdlet starts a Windows Runtime extension and returns a reference to the COM interface. .PARAMETER ContractId Specify a contract ID to start. .PARAMETER PackageId Specify a package ID to start. .PARAMETER AppId Specify an AppId to start. .PARAMETER Extension Specify an extension to start. .PARAMETER UseExistingHostId Use an existing host ID for the activation. A hosted application in the same package must be running. .PARAMETER HostId Specify the host ID to use for the activation. .PARAMETER NoWrapper Don't wrap object in a callable wrapper. .INPUTS OleViewDotNet.COMRuntimeExtensionEntry .OUTPUTS COM object instance. .EXAMPLE Start-ComRuntimeExtension $Extension Start a runtime extension from an extension object. .EXAMPLE Get-ComRuntimeExtension -ContractId "Windows.Protocol" -PackageId "Pkg_1.0.0.0_xxxx" -AppId App Start a runtime extension from parts. .EXAMPLE Start-ComRuntimeExtension $Extension -UseExistingHostId Start a runtime extension from an extension object using an existing host ID. .EXAMPLE Start-ComRuntimeExtension $Extension -HostId 1234 Start a runtime extension from an extension object using an specific host ID. #> function Start-ComRuntimeExtension { [CmdletBinding()] Param( [parameter(Mandatory, Position = 0, ParameterSetName = "FromParts")] [string]$ContractId, [parameter(Mandatory, Position = 1, ParameterSetName = "FromParts")] [string]$PackageId, [parameter(Mandatory, Position = 2, ParameterSetName = "FromParts")] [string]$AppId, [parameter(Mandatory, Position = 0, ParameterSetName = "FromExtension", ValueFromPipeline)] [OleViewDotNet.Database.COMRuntimeExtensionEntry]$Extension, [switch]$UseExistingHostId, [int64]$HostId, [switch]$NoWrapper ) PROCESS { try { switch($PSCmdlet.ParameterSetName) { "FromParts" { $act = [OleViewDotNet.RuntimeExtensionActivator]::new($ContractId, $PackageId, $AppId) } "FromExtension" { $act = [OleViewDotNet.RuntimeExtensionActivator]::new($Extension) } } if ($UseExistingHostId) { $act.UseExistingHostId() } else { $act.HostId = $HostId } $obj = $act.Activate() if ($null -ne $obj) { $type = [OleViewDotNet.IUnknown] Wrap-ComObject $obj -Type $type -NoWrapper:$NoWrapper | Write-Output } } catch { Write-Error $_ } } } <# .SYNOPSIS Get COM MIME types. .DESCRIPTION This cmdlet gets the COM mime types from a database. .PARAMETER MimeType Specify the name of a MIME type to lookup. .PARAMETER Extension Specify the file extension of a MIME type to lookup, can have a period or not. .PARAMETER Database The COM database to use. .INPUTS None .OUTPUTS OleViewDotNet.COMMimeType .EXAMPLE Get-ComMimeType Get all COM MIME types from the current database. .EXAMPLE Get-ComMimeType -MimeType "application/xml" Get the COM MIME type with the name application/xml. .EXAMPLE Get-ComMimeType -Extension xml Get the COM MIME type with the extension xml. #> function Get-ComMimeType { [CmdletBinding(DefaultParameterSetName = "All")] Param( [Parameter(Mandatory, ParameterSetName = "FromMimeType")] [string]$MimeType, [Parameter(Mandatory, ParameterSetName = "FromExtension")] [string]$Extension, [OleViewDotNet.Database.COMRegistry]$Database ) $Database = Get-CurrentComDatabase $Database if ($null -eq $Database) { Write-Error "No database specified and current database isn't set" return } switch($PSCmdlet.ParameterSetName) { "All" { $Database.MimeTypes | Write-Output } "FromMimeType" { $Database.MimeTypes | Where-Object MimeType -eq $MimeType | Write-Output } "FromExtension" { if (!$Extension.StartsWith(".")) { $Extension = "." + $Extension } $Database.MimeTypes | Where-Object Extension -eq $Extension | Write-Output } } } <# .SYNOPSIS Get COM ProgIDs from a database. .DESCRIPTION This cmdlet gets COM ProgIDs from the database based on a set of criteria. The default is to return all registered ProgIds. .PARAMETER Database The database to use. .PARAMETER ProgId Specify a ProgID to lookup. .PARAMETER Name Specify a name to match against the ProgId name. .PARAMETER Source Specify a source where the ProgID came from. .INPUTS None .OUTPUTS OleViewDotNet.COMProgIDEntry .EXAMPLE Get-ComProgId Get all COM ProgIds from the current database. #> function Get-ComProgId { [CmdletBinding(DefaultParameterSetName = "All")] Param( [OleViewDotNet.Database.COMRegistry]$Database, [Parameter(Position = 0, Mandatory, ParameterSetName = "FromProgId")] [string]$ProgId, [Parameter(Mandatory, ParameterSetName = "FromName")] [string]$Name, [Parameter(Mandatory, ParameterSetName = "FromSource")] [OleViewDotNet.Database.COMRegistryEntrySource]$Source ) $Database = Get-CurrentComDatabase $Database if ($null -eq $Database) { Write-Error "No database specified and current database isn't set" return } switch($PSCmdlet.ParameterSetName) { "All" { Write-Output $Database.Progids.Values } "FromProgId" { Write-Output $Database.Progids[$ProgId] } "FromName" { Get-ComProgId -Database $Database | Where-Object Name -Match $Name | Write-Output } "FromSource" { Get-ComProgId -Database $Database | Where-Object Source -eq $Source | Write-Output } } } <# .SYNOPSIS Converts a type library or proxy instance to a .NET assembly. .DESCRIPTION This cmdlet converts a type library or proxy instance object to a .NET assembly. This assembly can then be used to access COM interfaces. The assembly will be automatically registered with the applications so that you can use it with Get-ComObjectInterface. .PARAMETER TypeLib The type library version entry to convert. .PARAMETER Path The path to a type library to convert. .PARAMETER NoProgress Don't show progress during conversion. .PARAMETER Proxy The proxy instance to convert. .PARAMETER Ipid The IPID entry to convert. Must have been created with ParseStubMethods parameter. .INPUTS None .OUTPUTS System.Reflection.Assembly #> function ConvertTo-ComAssembly { [CmdletBinding(DefaultParameterSetName="FromTypeLib")] Param( [parameter(Mandatory, ParameterSetName = "FromTypeLib", Position = 0)] [OleViewDotNet.Database.COMTypeLibVersionEntry]$TypeLib, [parameter(Mandatory, ParameterSetName = "FromPath", Position = 0)] [string]$Path, [parameter(Mandatory, ParameterSetName = "FromProxy", Position = 0)] [OleViewDotNet.COMProxyInstance]$Proxy, [parameter(Mandatory, ParameterSetName = "FromProxyInterface", Position = 0)] [OleViewDotNet.COMProxyInterfaceInstance]$ProxyInterface, [parameter(Mandatory, ParameterSetName = "FromIpid", Position = 0)] [OleViewDotNet.COMIPIDEntry]$Ipid, [switch]$NoProgress ) PROCESS { $callback = New-CallbackProgress -Activity "Converting to Assembly" -NoProgress:$NoProgress switch($PSCmdlet.ParameterSetName) { "FromTypeLib" { Get-ComTypeLibAssembly -TypeLib $TypeLib -NoProgress:$NoProgress | Write-Output } "FromPath" { Get-ComTypeLibAssembly -Path $TypeLib -NoProgress:$NoProgress | Write-Output } "FromProxy" { [OleViewDotNet.COMUtilities]::ConvertProxyToAssembly($Proxy, $callback) | Write-Output } "FromProxyInterface" { [OleViewDotNet.COMUtilities]::ConvertProxyToAssembly($ProxyInterface, $callback) | Write-Output } "FromIpid" { [OleViewDotNet.COMUtilities]::ConvertProxyToAssembly($Ipid, $callback) | Write-Output } } } } <# .SYNOPSIS Converts various input formats into a GUID. .DESCRIPTION This cmdlet converts various input formats into a GUID structure. .PARAMETER ComGuid Get GUIDs from database objects. .PARAMETER Bytes Convert from a 16 byte array. .PARAMETER Ints Convert from a 4 integer array. .INPUTS None .OUTPUTS System.Guid #> function Get-ComGuid { [CmdletBinding(DefaultParameterSetName="FromComGuid")] Param( [parameter(Mandatory, ParameterSetName = "FromComGuid", Position = 0, ValueFromPipeline)] [OleViewDotNet.IComGuid[]]$ComGuid, [parameter(Mandatory, ParameterSetName = "FromBytes")] [byte[]]$Bytes, [parameter(Mandatory, ParameterSetName = "FromInts")] [int[]]$Ints ) PROCESS { switch($PSCmdlet.ParameterSetName) { "FromBytes" { [guid]::new($Bytes) | Write-Output } "FromInts" { [OleViewDotNet.PowerShell.PowerShellUtils]::GuidFromInts($Ints) | Write-Output } "FromComGuid" { foreach($obj in $Object) { $Object.ComGuid | Write-Output } } } } } <# .SYNOPSIS Tests if an object supports an interface. .DESCRIPTION This cmdlet queries a COM object for a specified interface. .PARAMETER Iid The IID of the interface. .PARAMETER Interface A COM interface entry. .PARAMETER Object The object to query. .INPUTS None .OUTPUTS Boolean #> function Test-ComInterface { [CmdletBinding(DefaultParameterSetName="FromIid")] Param( [parameter(Mandatory, ParameterSetName = "FromIid", Position = 0)] [Guid]$Iid, [parameter(Mandatory, Position=1)] [object]$Object, [parameter(Mandatory, ParameterSetName = "FromIntf", Position = 0)] [OleViewDotNet.Database.COMInterfaceEntry]$Interface ) if($PSCmdlet.ParameterSetName -eq "FromIid") { $Interface = Get-ComInterface -Iid $Iid -AllowNoReg } $Object = Unwrap-ComObject -Object $Object return $Interface.TestInterface($Object) } |