├── .gitignore ├── LICENSE ├── README.md ├── Translator ├── DissectorPowershell.cs ├── Manifest.cs ├── Properties │ └── AssemblyInfo.cs ├── Translator.cs ├── Translator.csproj ├── Translator.csproj.user ├── app.config └── packages.config ├── assets ├── example1.png ├── example2.png ├── example3.png ├── example4.png └── example5.png ├── ntTraceControl.sln ├── ntTraceControl ├── Cmdlet │ ├── ByteSerialization.cs │ ├── ConnectEventCmdlet.cs │ ├── DisconnectEventCmdlet.cs │ ├── VirtualMemoryManager.cs │ ├── WriteEventCmdlet.cs │ └── WriteSecurityCmdlet.cs ├── Properties │ └── AssemblyInfo.cs ├── WriteEtw.ps1 ├── WriteEventLogRecord.ps1 ├── WritePowershell.ps1 ├── WriteRdpCoreTS.ps1 ├── WriteRemoteConnectionManager.ps1 ├── WriteSecurity.ps1 ├── WriteSysmon.ps1 ├── WriteWMIActivity.ps1 ├── ntTraceControl.csproj ├── ntTraceControl.psd1 ├── ntTraceControl.psm1 └── packages.config └── ntTraceControlInstall ├── Product.wxs └── ntTraceControlInstall.wixproj /.gitignore: -------------------------------------------------------------------------------- 1 | ntTraceControl/packages/ 2 | ntTraceControl/obj/ 3 | ntTraceControl/bin/ 4 | ntTraceControl/.vs/ 5 | 6 | Translator/packages/ 7 | Translator/obj/ 8 | Translator/bin/ 9 | Translator/.vs/ 10 | 11 | *.dll 12 | *.pdb 13 | *.xml 14 | *.user 15 | 16 | ntTraceControlInstall/bin/ 17 | ntTraceControlInstall/obj/ 18 | 19 | .vs/ 20 | packages/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ntTraceControl -- Powershell Event Tracing Toolbox 2 | 3 | ntTraceControl is a set of Powershell commands to forge/generate Windows logs. Simply put, ntTraceControl supports Detection teams by simplifying the testing of detection use cases and alerts without using complex infrastructure, tools, or the testing of vulnerabilities. 4 | 5 | # Use Cases 6 | 7 | ## Generate command line : Write Sysmon Create Process Event 8 | 9 | Many detection teams rely upon Sysmon to create advanced detection rules. ntTraceControl includes dedicated cmdlets for Sysmon through Write-SysmonEventId*: 10 | 11 | ``` 12 | Import-Module ntTraceControl 13 | 14 | Write-SysmonEventId1 -Image mimikatz.exe -CommandLine "c:\Users\Admin\personal\mimikatz.exe" -ParentCommandLine "Get-Password.ps1" 15 | ``` 16 | 17 | Therefore, you can easily generate a `fake` command line to test your use cases and alerts. 18 | 19 | ![Sysmon Process Create Example](assets/example1.png) 20 | 21 | 22 | ## Generate `fake` authentification: Write Security Logon 23 | 24 | Microsoft-Windows-Audit-Security is the provider used to log messages like 4624 used to inform of a login session. All security logs are available through the Write-SecurityEventId* cmdlets: 25 | 26 | ``` 27 | Import-Module ntTraceControl 28 | 29 | Write-SecurityEventId4624 -SubjectUserName "Welcome ntTraceControl" -SubjectDomainName "Airbus CERT" 30 | ``` 31 | 32 | ![Security Login Example](assets/example2.png) 33 | 34 | ## Write an EventLogRecord (EVTX file) 35 | 36 | Modern Powershell includes cmdlet to parse windows logs files (.evtx) and produce EventLogRecord objects. ntTraceControl includes a dedicated cmdlet to write EventLogRecord objects. As the EVTX file can include logs from different providers, we recommend using a SYSTEM-privileged Powershell command. 37 | 38 | For our example, we used the wonderful [EVTX-ATTACK-SAMPLES](https://github.com/sbousseaden/EVTX-ATTACK-SAMPLES) repository from [@sbousseaden](https://github.com/sbousseaden) ! 39 | 40 | ``` 41 | Import-Module ntTraceControl 42 | 43 | Invoke-WebRequest -Uri https://github.com/sbousseaden/EVTX-ATTACK-SAMPLES/raw/master/Credential%20Access/CA_teamviewer-dumper_sysmon_10.evtx -OutFile C:\Users\sylvain.COSMOS\Desktop\CA_teamviewer-dumper_sysmon_10.evtx 44 | 45 | Get-WinEvent -Path C:\Users\sylvain.COSMOS\Desktop\CA_teamviewer-dumper_sysmon_10.evtx | ForEach-Object {$_ | Write-EventLogRecord -Channel 10} 46 | ``` 47 | 48 | ![From an evtx file example 1](assets/example3.png) 49 | 50 | ``` 51 | Import-Module ntTraceControl 52 | 53 | Invoke-WebRequest -Uri https://github.com/sbousseaden/EVTX-ATTACK-SAMPLES/raw/master/Credential%20Access/CA_DCSync_4662.evtx -OutFile C:\Users\sylvain.COSMOS\Desktop\CA_DCSync_4662.evtx 54 | 55 | Get-WinEvent -Path C:\Users\sylvain.COSMOS\Desktop\CA_DCSync_4662.evtx | ForEach-Object {$_ | Write-EventLogRecord -Channel 0} 56 | ``` 57 | 58 | ![From an evtx file example 2](assets/example4.png) 59 | 60 | # Write-Etw 61 | 62 | All cmdlets are based on a more generic one named Write-Etw. This cmdlet has no context from the provider and can be used to emit logs that are not yet supported by a dedicated function. 63 | 64 | Here is an example to emit an event ID 4, "Sysmon service changed", from the Sysmon provider: 65 | 66 | ``` 67 | Import-Module ntTraceControl 68 | 69 | Write-Etw -ProviderGuid ([System.Guid]::Parse("5770385f-c22a-43e0-bf4c-06f5698ffbd9")) -Id 4 -Version 3 -Channel 16 -Level 0 -Opcode 0 -Task 4 -Keyword ([Int64]"0x8000000000000000") -Parameters @(“monday”,”running”,”8.0”,”11.0”) 70 | ``` 71 | 72 | ![Write-Etw cmdlet example](assets/example5.png) 73 | 74 | # How to install 75 | 76 | An installer is provided at the [Release](https://github.com/airbus-cert/ntTraceControl/releases/) page ! It will install Powershell module for every users. 77 | 78 | # How it works 79 | 80 | We rely on NtTraceControl and NtTraceEvent syscall, to emit any kind of ETW. 81 | To write an ETW, we need to first register the associated provider GUID, with the Connect-Event cmdlet, then write a message using the Write-Event cmdlet, then disconnect the provider using Disconnect-Event. 82 | 83 | In most cases, administrator rights are needed to produce a log. 84 | 85 | For security reasons, the Microsoft-Windows-Audit-Security provider is not managed using the straight API. Only the lsass process can emit Security logs. To simulate security logs, ntTraceControl will inject a payload into the lsass.exe process to call the proper API. So to achieve injection you must have system privileges. 86 | 87 | Next, the Translator project is used to create Powershell functions, with strong type enforcement deduced from the ETW provider manifest. Sometimes we have to customize a little bit what is automatically extracted from the manifest, this is why we versioned the output files. 88 | 89 | For example the following command will Generate WriteSysmon.ps1 : 90 | 91 | ``` 92 | Translator.exe -p Microsoft-Windows-Sysmon -c 17 -s Sysmon -o .\WriteSysmon.ps1 -k 0x8000000000000000 93 | ``` 94 | 95 | We generated functions for the following providers: 96 | 97 | |Name|GUID|CmdLet Pattern| 98 | |----|----|--------------| 99 | |Microsoft-Windows-PowerShell|a0c1853b-5c40-4b15-8766-3cf1c58f985a|Write-PowershellEventId*| 100 | |Microsoft-Windows-RemoteDesktopServices-RdpCoreTS|1139c61b-b549-4251-8ed3-27250a1edec8|Write-RdpCoreTSEventId*| 101 | |Microsoft-Windows-TerminalServices-RemoteConnectionManager|c76baa63-ae81-421c-b425-340b4b24157f|Write-RdpCoreTSEventId*| 102 | |Microsoft-Windows-Security-Auditing|54849625-5478-4994-a5ba-3e3b0328c30d|Write-SecurityEventId*| 103 | |Microsoft-Windows-Sysmon|5770385f-c22a-43e0-bf4c-06f5698ffbd9|Write-SysmonEventId*| 104 | |Microsoft-Windows-WMI-Activity|1418ef04-b0b4-4623-bf7e-d74ab47bbdaa|Write-WMIActivityEventId*| 105 | 106 | 107 | As generating new ones is only a call to the Translator project, it will be easy to add more if needed. 108 | 109 | -------------------------------------------------------------------------------- /Translator/DissectorPowershell.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | 6 | namespace Translator 7 | { 8 | static class DissectorPowershellTemplate 9 | { 10 | public const string PROVIDER = @" 11 | # This module was generated automaticaly using Translator.exe 12 | # Some customs could be made afterwards to take into account some specificity of the provider (like Task or keywords arguments) 13 | # This is the module that handle the following provider 14 | # Name : {0} 15 | # GUID : {1} 16 | "; 17 | 18 | public const string EVENT_TEMPLATE = @" 19 | Function Write-{0}EventId{1} 20 | {{ 21 | <# 22 | .SYNOPSIS 23 | This function was generated using Translator.exe 24 | If you modify it afterwards please add a comment 25 | 26 | Version 1.0 Translator.exe 27 | 28 | Symbol : {2} 29 | #> 30 | Param( 31 | {3} 32 | ) 33 | {4} 34 | Write-Etw -ProviderGuid ([System.Guid]::Parse(""{5}"")) -Id {6} -Version {7} -Channel {8} -Level {9} -Opcode {10} -Task {11} -Keyword ([Int64]""{12}"") -Parameters @({13}) 35 | }};"; 36 | 37 | public const string EVENT_FIELD = @" 38 | [Parameter(Position = {0}, Mandatory = $false)] 39 | [{2}] 40 | ${1} = {3}"; 41 | 42 | public static readonly Dictionary> EVENT_DATA_TYPE_CONVERT = new Dictionary>() 43 | { 44 | { Data.InType.Int8, new Tuple("Byte", "0")}, 45 | { Data.InType.Int16, new Tuple("Int16", "0")}, 46 | { Data.InType.Int32, new Tuple("Int32", "0")}, 47 | { Data.InType.Int64, new Tuple("Int64", "0")}, 48 | { Data.InType.UInt16, new Tuple("UInt16", "0")}, 49 | { Data.InType.UInt32, new Tuple("UInt32", "0")}, 50 | { Data.InType.UInt64, new Tuple("UInt64", "0")}, 51 | { Data.InType.UInt8, new Tuple("Byte", "0")}, 52 | { Data.InType.GUID, new Tuple("System.Guid", "[System.Guid]::NewGuid()")}, 53 | { Data.InType.UnicodeString, new Tuple("String", "\"\"")}, 54 | { Data.InType.Boolean, new Tuple("UInt32", "0")}, 55 | { Data.InType.HexInt32, new Tuple("UInt32", "0")}, 56 | { Data.InType.HexInt64, new Tuple("UInt64", "0")}, 57 | { Data.InType.FILETIME, new Tuple("DateTime", "[System.DateTime]::Now")}, 58 | { Data.InType.Pointer, new Tuple("UInt64", "0")}, 59 | { Data.InType.AnsiString, new Tuple("String", "\"\"")}, 60 | { Data.InType.SYSTEMTIME, new Tuple("DateTime", "[System.DateTime]::Now")}, 61 | { Data.InType.SID, new Tuple("System.Security.Principal.SecurityIdentifier", "[System.Security.Principal.SecurityIdentifier]::new(\"S-1-5-18\")")} 62 | }; 63 | 64 | } 65 | 66 | 67 | class DissectorPowershell 68 | { 69 | 70 | public Manifest Manifest { get; private set; } 71 | 72 | public string Channel { get; private set; } 73 | 74 | public string ShortName { get; private set; } 75 | 76 | public string Keywords { get; private set; } 77 | 78 | private static void GenerateProvider(Provider Current, StreamWriter Writer) 79 | { 80 | Writer.WriteLine(string.Format(DissectorPowershellTemplate.PROVIDER, Current.name, Current.guid)); 81 | } 82 | 83 | private void GenerateEvent(Event EtwEvent, Provider Provider, StreamWriter Writer) 84 | { 85 | var template = Provider.templates.Where(x => x.tid == EtwEvent.template).Single(); 86 | var fields_declaration = new List(); 87 | var fields_convertion = new List(); 88 | 89 | int index = 0; 90 | foreach (var data in template.datas) 91 | { 92 | var MatchingValues = DissectorPowershellTemplate.EVENT_DATA_TYPE_CONVERT[data.inType]; 93 | fields_declaration.Add(string.Format(DissectorPowershellTemplate.EVENT_FIELD, index++, data.name, MatchingValues.Item1, MatchingValues.Item2)); 94 | if (data.inType == Data.InType.AnsiString) 95 | { 96 | // Fields conversion for AnsiString handles 97 | fields_convertion.Add(string.Format("[Byte[]]${0} = [System.Text.Encoding]::ASCII.GetBytes(${0}) + [Byte]0", data.name)); 98 | } 99 | } 100 | 101 | var Task = Provider.tasks.Find(x => x.name == EtwEvent.task); 102 | 103 | Writer.WriteLine( 104 | string.Format( 105 | DissectorPowershellTemplate.EVENT_TEMPLATE, 106 | this.ShortName, 107 | EtwEvent.value, 108 | EtwEvent.symbol, 109 | string.Join(",\n", fields_declaration), 110 | string.Join(",\n", fields_convertion), 111 | Provider.guid.ToString(), 112 | EtwEvent.value, 113 | EtwEvent.version, 114 | this.Channel, 115 | (byte)EtwEvent.level, 116 | "0", 117 | Task == null ? "0" : Task.value, 118 | this.Keywords, 119 | string.Join(",", template.datas.Select(x => "$" + x.name)) 120 | ) 121 | ); 122 | } 123 | 124 | public DissectorPowershell(Manifest Source, string Channel, string ShortName, string Keywords) 125 | { 126 | this.Manifest = Source; 127 | this.Channel = Channel; 128 | this.ShortName = ShortName; 129 | this.Keywords = Keywords; 130 | } 131 | 132 | public void create(Stream Output) 133 | { 134 | using (var s = new StreamWriter(Output)) 135 | { 136 | GenerateProvider(this.Manifest.instrumentation.events.provider, s); 137 | 138 | // delete all event with same value and version (exist in scheme) 139 | var EventSet = new HashSet(this.Manifest.instrumentation.events.provider.events, new EventComparer()); 140 | 141 | foreach (var EtwEvent in EventSet) 142 | { 143 | if (EtwEvent.template == null) 144 | { 145 | continue; 146 | } 147 | GenerateEvent(EtwEvent, this.Manifest.instrumentation.events.provider, s); 148 | } 149 | } 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /Translator/Manifest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Xml; 3 | using System.Xml.Serialization; 4 | using System.IO; 5 | using System.Collections.Generic; 6 | 7 | namespace Translator 8 | { 9 | [XmlType("map")] 10 | public class Map 11 | { 12 | [XmlAttribute] 13 | public string message; 14 | 15 | [XmlAttribute] 16 | public string value; 17 | } 18 | 19 | [XmlType("valueMap")] 20 | public class ValueMap 21 | { 22 | [XmlAttribute] 23 | public string name; 24 | 25 | [XmlElement("map")] 26 | public List maps; 27 | } 28 | 29 | public class Maps 30 | { 31 | [XmlElement("valueMap")] 32 | public List valueMaps; 33 | } 34 | 35 | [XmlType("opcode")] 36 | public class Opcode 37 | { 38 | [XmlAttribute] 39 | public string name; 40 | 41 | [XmlAttribute] 42 | public string message; 43 | 44 | [XmlAttribute] 45 | public string value; 46 | } 47 | 48 | [XmlType("task")] 49 | public class Task 50 | { 51 | [XmlAttribute] 52 | public string name; 53 | 54 | [XmlAttribute] 55 | public string message; 56 | 57 | [XmlAttribute] 58 | public string value; 59 | 60 | public List opcodes; 61 | } 62 | 63 | [XmlType("event")] 64 | public class Event 65 | { 66 | public enum Level 67 | { 68 | [XmlEnum(Name = "win:Always")] 69 | Always, 70 | [XmlEnum(Name = "win:Critical")] 71 | Critical, 72 | [XmlEnum(Name = "win:Error")] 73 | Error, 74 | [XmlEnum(Name = "win:Warning")] 75 | Warning, 76 | [XmlEnum(Name = "win:Informational")] 77 | Informational, 78 | [XmlEnum(Name = "win:Verbose")] 79 | Verbose 80 | } 81 | 82 | [XmlAttribute] 83 | public string value; 84 | 85 | [XmlAttribute] 86 | public string symbol; 87 | 88 | [XmlAttribute] 89 | public int version; 90 | 91 | [XmlAttribute] 92 | public string task; 93 | 94 | [XmlAttribute] 95 | public Level level; 96 | 97 | [XmlAttribute] 98 | public string template; 99 | 100 | [XmlAttribute] 101 | public string keywords; 102 | 103 | [XmlAttribute] 104 | public string opcode; 105 | } 106 | 107 | public class EventComparer : IEqualityComparer 108 | { 109 | public bool Equals(Event x, Event y) 110 | { 111 | return x.value == y.value && x.version == y.version; 112 | } 113 | 114 | public int GetHashCode(Event obj) 115 | { 116 | return obj.value.GetHashCode() ^ obj.version.GetHashCode(); 117 | } 118 | } 119 | 120 | 121 | [XmlType("data")] 122 | public class Data 123 | { 124 | [XmlAttribute] 125 | public string name; 126 | 127 | public enum InType 128 | { 129 | [XmlEnum(Name = "win:UnicodeString")] 130 | UnicodeString, 131 | [XmlEnum(Name = "win:AnsiString")] 132 | AnsiString, 133 | [XmlEnum(Name = "win:GUID")] 134 | GUID, 135 | [XmlEnum(Name = "win:UInt32")] 136 | UInt32, 137 | [XmlEnum(Name = "win:HexInt32")] 138 | HexInt32, 139 | [XmlEnum(Name = "win:HexInt64")] 140 | HexInt64, 141 | [XmlEnum(Name = "win:Boolean")] 142 | Boolean, 143 | [XmlEnum(Name = "win:UInt16")] 144 | UInt16, 145 | [XmlEnum(Name = "win:Binary")] 146 | Binary, 147 | [XmlEnum(Name = "win:UInt64")] 148 | UInt64, 149 | [XmlEnum(Name = "win:Double")] 150 | Double, 151 | [XmlEnum(Name = "win:UInt8")] 152 | UInt8, 153 | [XmlEnum(Name = "win:Int8")] 154 | Int8, 155 | [XmlEnum(Name = "win:Int16")] 156 | Int16, 157 | [XmlEnum(Name = "win:Int32")] 158 | Int32, 159 | [XmlEnum(Name = "win:Int64")] 160 | Int64, 161 | [XmlEnum(Name = "win:FILETIME")] 162 | FILETIME, 163 | [XmlEnum(Name = "win:Pointer")] 164 | Pointer, 165 | [XmlEnum(Name = "win:SYSTEMTIME")] 166 | SYSTEMTIME, 167 | [XmlEnum(Name = "win:SID")] 168 | SID, 169 | [XmlEnum(Name = "win:Float")] 170 | Float 171 | } 172 | 173 | [XmlAttribute] 174 | public InType inType; 175 | 176 | [XmlAttribute] 177 | public string length; 178 | 179 | [XmlAttribute] 180 | public string count; 181 | 182 | [XmlAttribute] 183 | public string map; 184 | } 185 | 186 | [XmlType("template")] 187 | public class Template 188 | { 189 | [XmlAttribute] 190 | public string tid; 191 | 192 | [XmlElement("data")] 193 | public List datas; 194 | } 195 | 196 | [XmlType("keyword")] 197 | public class Keyword 198 | { 199 | [XmlAttribute] 200 | public string name; 201 | 202 | [XmlAttribute] 203 | public string message; 204 | 205 | [XmlAttribute] 206 | public string mask; 207 | } 208 | 209 | public class Provider 210 | { 211 | [XmlAttribute] 212 | public string name; 213 | 214 | [XmlAttribute] 215 | public Guid guid; 216 | 217 | [XmlAttribute] 218 | public string resourceFileName; 219 | 220 | [XmlAttribute] 221 | public string messageFileName; 222 | 223 | [XmlAttribute] 224 | public string symbol; 225 | 226 | [XmlAttribute] 227 | public string source; 228 | 229 | public List keywords; 230 | 231 | public List tasks; 232 | 233 | public List events; 234 | 235 | public List