├── .gitignore ├── BUILD.md ├── LICENSE ├── NuGet.config ├── README.md ├── TypeRefHasher.sln ├── artifacts └── artifacts.txt ├── azure-pipelines.yml ├── manifests └── g │ └── GDATA │ └── TypeRefHasher │ ├── 1.0.0 │ └── GDATA.TypeRefHasher.yaml │ └── 1.0.3 │ ├── GDATA.TypeRefHasher.installer.yaml │ ├── GDATA.TypeRefHasher.locale.en-US.yaml │ └── GDATA.TypeRefHasher.yaml ├── sha_imdetection_typerefhash_filtered.json ├── src ├── Installer │ ├── Installer.wixproj │ ├── Product.wxs │ └── build-msi.ps1 └── TRH │ ├── Program.cs │ ├── TRH.csproj │ └── rd.xml └── test └── TRH.Test ├── Binaries ├── NetCoreConsole.dll ├── firefox_x86.exe └── notPeFile.txt ├── CLI_Test.cs └── TRH.Test.csproj /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | launchSettings.json 13 | 14 | # User-specific files (MonoDevelop/Xamarin Studio) 15 | *.userprefs 16 | 17 | # Mono auto generated files 18 | mono_crash.* 19 | 20 | # Build results 21 | [Dd]ebug/ 22 | [Dd]ebugPublic/ 23 | [Rr]elease/ 24 | [Rr]eleases/ 25 | x64/ 26 | x86/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # StyleCop 66 | StyleCopReport.xml 67 | 68 | # Files built by Visual Studio 69 | *_i.c 70 | *_p.c 71 | *_h.h 72 | *.ilk 73 | *.meta 74 | *.obj 75 | *.iobj 76 | *.pch 77 | *.pdb 78 | *.ipdb 79 | *.pgc 80 | *.pgd 81 | *.rsp 82 | *.sbr 83 | *.tlb 84 | *.tli 85 | *.tlh 86 | *.tmp 87 | *.tmp_proj 88 | *_wpftmp.csproj 89 | *.log 90 | *.vspscc 91 | *.vssscc 92 | .builds 93 | *.pidb 94 | *.svclog 95 | *.scc 96 | 97 | # Chutzpah Test files 98 | _Chutzpah* 99 | 100 | # Visual C++ cache files 101 | ipch/ 102 | *.aps 103 | *.ncb 104 | *.opendb 105 | *.opensdf 106 | *.sdf 107 | *.cachefile 108 | *.VC.db 109 | *.VC.VC.opendb 110 | 111 | # Visual Studio profiler 112 | *.psess 113 | *.vsp 114 | *.vspx 115 | *.sap 116 | 117 | # Visual Studio Trace Files 118 | *.e2e 119 | 120 | # TFS 2012 Local Workspace 121 | $tf/ 122 | 123 | # Guidance Automation Toolkit 124 | *.gpState 125 | 126 | # ReSharper is a .NET coding add-in 127 | _ReSharper*/ 128 | *.[Rr]e[Ss]harper 129 | *.DotSettings.user 130 | 131 | # TeamCity is a build add-in 132 | _TeamCity* 133 | 134 | # DotCover is a Code Coverage Tool 135 | *.dotCover 136 | 137 | # AxoCover is a Code Coverage Tool 138 | .axoCover/* 139 | !.axoCover/settings.json 140 | 141 | # Visual Studio code coverage results 142 | *.coverage 143 | *.coveragexml 144 | 145 | # NCrunch 146 | _NCrunch_* 147 | .*crunch*.local.xml 148 | nCrunchTemp_* 149 | 150 | # MightyMoose 151 | *.mm.* 152 | AutoTest.Net/ 153 | 154 | # Web workbench (sass) 155 | .sass-cache/ 156 | 157 | # Installshield output folder 158 | [Ee]xpress/ 159 | 160 | # DocProject is a documentation generator add-in 161 | DocProject/buildhelp/ 162 | DocProject/Help/*.HxT 163 | DocProject/Help/*.HxC 164 | DocProject/Help/*.hhc 165 | DocProject/Help/*.hhk 166 | DocProject/Help/*.hhp 167 | DocProject/Help/Html2 168 | DocProject/Help/html 169 | 170 | # Click-Once directory 171 | publish/ 172 | 173 | # Publish Web Output 174 | *.[Pp]ublish.xml 175 | *.azurePubxml 176 | # Note: Comment the next line if you want to checkin your web deploy settings, 177 | # but database connection strings (with potential passwords) will be unencrypted 178 | *.pubxml 179 | *.publishproj 180 | 181 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 182 | # checkin your Azure Web App publish settings, but sensitive information contained 183 | # in these scripts will be unencrypted 184 | PublishScripts/ 185 | 186 | # NuGet Packages 187 | *.nupkg 188 | # NuGet Symbol Packages 189 | *.snupkg 190 | # The packages folder can be ignored because of Package Restore 191 | **/[Pp]ackages/* 192 | # except build/, which is used as an MSBuild target. 193 | !**/[Pp]ackages/build/ 194 | # Uncomment if necessary however generally it will be regenerated when needed 195 | #!**/[Pp]ackages/repositories.config 196 | # NuGet v3's project.json files produces more ignorable files 197 | *.nuget.props 198 | *.nuget.targets 199 | 200 | # Microsoft Azure Build Output 201 | csx/ 202 | *.build.csdef 203 | 204 | # Microsoft Azure Emulator 205 | ecf/ 206 | rcf/ 207 | 208 | # Windows Store app package directories and files 209 | AppPackages/ 210 | BundleArtifacts/ 211 | Package.StoreAssociation.xml 212 | _pkginfo.txt 213 | *.appx 214 | *.appxbundle 215 | *.appxupload 216 | 217 | # Visual Studio cache files 218 | # files ending in .cache can be ignored 219 | *.[Cc]ache 220 | # but keep track of directories ending in .cache 221 | !?*.[Cc]ache/ 222 | 223 | # Others 224 | ClientBin/ 225 | ~$* 226 | *~ 227 | *.dbmdl 228 | *.dbproj.schemaview 229 | *.jfm 230 | *.pfx 231 | *.publishsettings 232 | orleans.codegen.cs 233 | 234 | # Including strong name files can present a security risk 235 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 236 | #*.snk 237 | 238 | # Since there are multiple workflows, uncomment next line to ignore bower_components 239 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 240 | #bower_components/ 241 | 242 | # RIA/Silverlight projects 243 | Generated_Code/ 244 | 245 | # Backup & report files from converting an old project file 246 | # to a newer Visual Studio version. Backup files are not needed, 247 | # because we have git ;-) 248 | _UpgradeReport_Files/ 249 | Backup*/ 250 | UpgradeLog*.XML 251 | UpgradeLog*.htm 252 | ServiceFabricBackup/ 253 | *.rptproj.bak 254 | 255 | # SQL Server files 256 | *.mdf 257 | *.ldf 258 | *.ndf 259 | 260 | # Business Intelligence projects 261 | *.rdl.data 262 | *.bim.layout 263 | *.bim_*.settings 264 | *.rptproj.rsuser 265 | *- [Bb]ackup.rdl 266 | *- [Bb]ackup ([0-9]).rdl 267 | *- [Bb]ackup ([0-9][0-9]).rdl 268 | 269 | # Microsoft Fakes 270 | FakesAssemblies/ 271 | 272 | # GhostDoc plugin setting file 273 | *.GhostDoc.xml 274 | 275 | # Node.js Tools for Visual Studio 276 | .ntvs_analysis.dat 277 | node_modules/ 278 | 279 | # Visual Studio 6 build log 280 | *.plg 281 | 282 | # Visual Studio 6 workspace options file 283 | *.opt 284 | 285 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 286 | *.vbw 287 | 288 | # Visual Studio LightSwitch build output 289 | **/*.HTMLClient/GeneratedArtifacts 290 | **/*.DesktopClient/GeneratedArtifacts 291 | **/*.DesktopClient/ModelManifest.xml 292 | **/*.Server/GeneratedArtifacts 293 | **/*.Server/ModelManifest.xml 294 | _Pvt_Extensions 295 | 296 | # Paket dependency manager 297 | .paket/paket.exe 298 | paket-files/ 299 | 300 | # FAKE - F# Make 301 | .fake/ 302 | 303 | # CodeRush personal settings 304 | .cr/personal 305 | 306 | # Python Tools for Visual Studio (PTVS) 307 | __pycache__/ 308 | *.pyc 309 | 310 | # Cake - Uncomment if you are using it 311 | # tools/** 312 | # !tools/packages.config 313 | 314 | # Tabs Studio 315 | *.tss 316 | 317 | # Telerik's JustMock configuration file 318 | *.jmconfig 319 | 320 | # BizTalk build output 321 | *.btp.cs 322 | *.btm.cs 323 | *.odx.cs 324 | *.xsd.cs 325 | 326 | # OpenCover UI analysis results 327 | OpenCover/ 328 | 329 | # Azure Stream Analytics local run output 330 | ASALocalRun/ 331 | 332 | # MSBuild Binary and Structured Log 333 | *.binlog 334 | 335 | # NVidia Nsight GPU debugger configuration file 336 | *.nvuser 337 | 338 | # MFractors (Xamarin productivity tool) working folder 339 | .mfractor/ 340 | 341 | # Local History for Visual Studio 342 | .localhistory/ 343 | 344 | # BeatPulse healthcheck temp database 345 | healthchecksdb 346 | 347 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 348 | MigrationBackup/ 349 | 350 | # Ionide (cross platform F# VS Code tools) working folder 351 | .ionide/ 352 | -------------------------------------------------------------------------------- /BUILD.md: -------------------------------------------------------------------------------- 1 | # How to build and publish TypeRefHasher 2 | 3 | Most of the work is done by the *Azure Pipeline*, except for the publish to *winget*. 4 | 5 | ## Release a new version to GitHub 6 | 7 | To release a new version to *Github*, you need to push a tagged commit. Replace the version with the one you want to release. The *Azure Pipeline* does the rest. 8 | 9 | ```powershell 10 | git tag -a v1.0.0 -m "Release version 1.0.0" 11 | git push origin v1.0.0 12 | ``` 13 | 14 | ## Release to winget 15 | 16 | To release to *winget-pkgs* you need to release to *Github* first. If you have already done that and a new `trh.msi` is available on the [Github Release](https://github.com/GDATASoftwareAG/TypeRefHasher/releases) page, you need to create a PR to *winget*. 17 | 18 | 1. Clone the [G DATA fork](https://github.com/GDATASoftwareAG/winget-pkgs) of the *winget* repo. 19 | 2. Add a new `manifests\g\GDATA\TypeRefHasher\VERSION\GDATA.TypeRefHasher.yaml` file for the new version you want to release. Just copy an older version for that. You can find an example [here](manifests\g\GDATA\TypeRefHasher\1.0.3\GDATA.TypeRefHasher.yaml). 20 | 1. Update the `PackageVersion` tag to the new version. 21 | 2. Update the `InstallerUrl` tag to point to the new `trh.msi` on [Github Release](https://github.com/GDATASoftwareAG/TypeRefHasher/releases). 22 | 3. Update the `InstallerSha256` of the `trh.msi`. 23 | 1. Bash: `curl -O -L https://github.com/GDATASoftwareAG/TypeRefHasher/releases/download/VERSION/trh.msi` 24 | 2. Bash: `sha256sum trh.msi | tr '[:lower:]' '[:upper:]'` 25 | 26 | If you want to verify your changes you can test the manifest with the following commands: 27 | 28 | ```powershell 29 | # Check the schema of the manifest 30 | winget validate 31 | 32 | # Install the package locally. 33 | winget install -m 34 | ``` 35 | 36 | If you are sure that your manifest works, create a PR to the official [winget-pkgs repository](https://github.com/microsoft/winget-pkgs). -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /NuGet.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TypeRef Hasher 2 | 3 | [![license](https://img.shields.io/github/license/GDATASoftwareAG/TypeRefHasher.svg)](https://raw.githubusercontent.com/GDATASoftwareAG/TypeRefHasher/master/LICENSE) 4 | [![Build](https://img.shields.io/azure-devops/build/gdatasoftware/TypeRefHasher/6.svg)](https://dev.azure.com/gdatasoftware/TypeRefHasher/_build?definitionId=6) 5 | [![Test](https://img.shields.io/azure-devops/tests/gdatasoftware/TypeRefHasher/6.svg)](https://dev.azure.com/gdatasoftware/TypeRefHasher/_build?definitionId=6) 6 | 7 | CLI tool to compute the [TypeRefHash (TRH)](https://www.gdatasoftware.com/blog/2020/06/36164-introducing-the-typerefhash-trh) for .NET binaries. 8 | 9 | ## Installation 10 | 11 | There are multiple options to obtain the *TypeRefHasher*. 12 | 13 | ### Windows 14 | 15 | Install the tool with [winget](https://github.com/microsoft/winget-cli). The tool gets added to your `PATH` environment variable. 16 | 17 | ```powershell 18 | winget install GDATA.TypeRefHasher 19 | ``` 20 | 21 | Another option is to just download the binary or installer from the [GitHub Releases](https://github.com/GDATASoftwareAG/TypeRefHasher/releases) tab 22 | 23 | 1. `trh.msi` -> Windows x64 Installer (Allows uninstall and adds the tool to your `PATH`) 24 | 2. `trh.exe` -> Windows x64 (Standalone binary) 25 | 26 | ### Linux 27 | 28 | Download the binary or installer from the [GitHub Releases](https://github.com/GDATASoftwareAG/TypeRefHasher/releases) tab. 29 | 30 | 1. `trh` -> Linux x64 (Standalone binary) 31 | 32 | ## Usage 33 | 34 | The usage is as straight forward as possible. 35 | 36 | Windows: 37 | 38 | ```powershell 39 | > trh.exe file 40 | ``` 41 | 42 | Linux: 43 | 44 | ```bash 45 | > trh file 46 | ``` 47 | 48 | In both cases the output is the TRH (example: 1defec485ab3060a9201f35d69cfcdec4b70b84a2b71c83b53795ca30d1ae8be) for the given file or an error message with a description why the hash could not be computed. 49 | 50 | ## Build & Deploy 51 | 52 | Find more information [here](BUILD.md) -------------------------------------------------------------------------------- /TypeRefHasher.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30128.36 5 | MinimumVisualStudioVersion = 15.0.26124.0 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{88766F58-287E-4BFA-A053-6336BA1244F2}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TRH", "src\TRH\TRH.csproj", "{16565A4A-FDE7-4A26-AD8D-356915EF3D1D}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{927B09CD-2903-4AEF-BB7A-997DCF60D767}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TRH.Test", "test\TRH.Test\TRH.Test.csproj", "{7C3D1BD9-2115-4909-ACA2-1B90E8254872}" 13 | EndProject 14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1E48FD0D-6DF8-4897-AD5D-B34F9D15BA2C}" 15 | ProjectSection(SolutionItems) = preProject 16 | .gitignore = .gitignore 17 | azure-pipelines.yml = azure-pipelines.yml 18 | LICENSE = LICENSE 19 | NuGet.config = NuGet.config 20 | README.md = README.md 21 | EndProjectSection 22 | EndProject 23 | Global 24 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 25 | Debug|Any CPU = Debug|Any CPU 26 | Debug|x64 = Debug|x64 27 | Debug|x86 = Debug|x86 28 | Release|Any CPU = Release|Any CPU 29 | Release|x64 = Release|x64 30 | Release|x86 = Release|x86 31 | EndGlobalSection 32 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 33 | {16565A4A-FDE7-4A26-AD8D-356915EF3D1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 34 | {16565A4A-FDE7-4A26-AD8D-356915EF3D1D}.Debug|Any CPU.Build.0 = Debug|Any CPU 35 | {16565A4A-FDE7-4A26-AD8D-356915EF3D1D}.Debug|x64.ActiveCfg = Debug|Any CPU 36 | {16565A4A-FDE7-4A26-AD8D-356915EF3D1D}.Debug|x64.Build.0 = Debug|Any CPU 37 | {16565A4A-FDE7-4A26-AD8D-356915EF3D1D}.Debug|x86.ActiveCfg = Debug|Any CPU 38 | {16565A4A-FDE7-4A26-AD8D-356915EF3D1D}.Debug|x86.Build.0 = Debug|Any CPU 39 | {16565A4A-FDE7-4A26-AD8D-356915EF3D1D}.Release|Any CPU.ActiveCfg = Release|Any CPU 40 | {16565A4A-FDE7-4A26-AD8D-356915EF3D1D}.Release|Any CPU.Build.0 = Release|Any CPU 41 | {16565A4A-FDE7-4A26-AD8D-356915EF3D1D}.Release|x64.ActiveCfg = Release|Any CPU 42 | {16565A4A-FDE7-4A26-AD8D-356915EF3D1D}.Release|x64.Build.0 = Release|Any CPU 43 | {16565A4A-FDE7-4A26-AD8D-356915EF3D1D}.Release|x86.ActiveCfg = Release|Any CPU 44 | {16565A4A-FDE7-4A26-AD8D-356915EF3D1D}.Release|x86.Build.0 = Release|Any CPU 45 | {7C3D1BD9-2115-4909-ACA2-1B90E8254872}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 46 | {7C3D1BD9-2115-4909-ACA2-1B90E8254872}.Debug|Any CPU.Build.0 = Debug|Any CPU 47 | {7C3D1BD9-2115-4909-ACA2-1B90E8254872}.Debug|x64.ActiveCfg = Debug|Any CPU 48 | {7C3D1BD9-2115-4909-ACA2-1B90E8254872}.Debug|x64.Build.0 = Debug|Any CPU 49 | {7C3D1BD9-2115-4909-ACA2-1B90E8254872}.Debug|x86.ActiveCfg = Debug|Any CPU 50 | {7C3D1BD9-2115-4909-ACA2-1B90E8254872}.Debug|x86.Build.0 = Debug|Any CPU 51 | {7C3D1BD9-2115-4909-ACA2-1B90E8254872}.Release|Any CPU.ActiveCfg = Release|Any CPU 52 | {7C3D1BD9-2115-4909-ACA2-1B90E8254872}.Release|Any CPU.Build.0 = Release|Any CPU 53 | {7C3D1BD9-2115-4909-ACA2-1B90E8254872}.Release|x64.ActiveCfg = Release|Any CPU 54 | {7C3D1BD9-2115-4909-ACA2-1B90E8254872}.Release|x64.Build.0 = Release|Any CPU 55 | {7C3D1BD9-2115-4909-ACA2-1B90E8254872}.Release|x86.ActiveCfg = Release|Any CPU 56 | {7C3D1BD9-2115-4909-ACA2-1B90E8254872}.Release|x86.Build.0 = Release|Any CPU 57 | EndGlobalSection 58 | GlobalSection(SolutionProperties) = preSolution 59 | HideSolutionNode = FALSE 60 | EndGlobalSection 61 | GlobalSection(NestedProjects) = preSolution 62 | {16565A4A-FDE7-4A26-AD8D-356915EF3D1D} = {88766F58-287E-4BFA-A053-6336BA1244F2} 63 | {7C3D1BD9-2115-4909-ACA2-1B90E8254872} = {927B09CD-2903-4AEF-BB7A-997DCF60D767} 64 | EndGlobalSection 65 | GlobalSection(ExtensibilityGlobals) = postSolution 66 | SolutionGuid = {E99B7C7C-FF53-433C-9F7A-1BBF877834A9} 67 | EndGlobalSection 68 | EndGlobal 69 | -------------------------------------------------------------------------------- /artifacts/artifacts.txt: -------------------------------------------------------------------------------- 1 | This folder holds all build artifacts -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | branches: 3 | include: 4 | - '*' 5 | tags: 6 | include: 7 | - '*' 8 | 9 | jobs: 10 | - job: Linux 11 | displayName: Build & Test Linux 12 | pool: 13 | vmImage: 'ubuntu-latest' 14 | variables: 15 | buildConfiguration: 'Release' 16 | artifactsFolder: '$(Build.SourcesDirectory)/artifacts/' 17 | 18 | steps: 19 | - script: sudo apt-get install clang zlib1g-dev libkrb5-dev libtinfo5 -y 20 | displayName: Install requirements 21 | 22 | - task: UseDotNet@2 23 | displayName: 'Use .NET 6.x' 24 | inputs: 25 | version: '6.x' 26 | packageType: sdk 27 | 28 | - powershell: dotnet publish ./src/TRH/TRH.csproj -c $(buildConfiguration) -r linux-x64 -o $(artifactsFolder) --self-contained 29 | displayName: 'Build' 30 | 31 | - powershell: mv TRH trh 32 | displayName: Rename artifact 33 | workingDirectory: '$(artifactsFolder)' 34 | 35 | - powershell: strip trh 36 | displayName: Strip artifact 37 | workingDirectory: '$(artifactsFolder)' 38 | 39 | - task: DotNetCoreCLI@2 40 | displayName: Test 41 | inputs: 42 | command: test 43 | projects: '**/*Test/*.csproj' 44 | arguments: '--configuration $(buildConfiguration) --collect "Code coverage"' 45 | 46 | - powershell: mv $(artifactsFolder)/trh $(Build.ArtifactStagingDirectory) 47 | displayName: Copy artifacts 48 | 49 | - task: PublishBuildArtifacts@1 50 | displayName: Publish 51 | inputs: 52 | pathtoPublish: '$(Build.ArtifactStagingDirectory)' 53 | artifactName: trhLin 54 | 55 | - job: Windows 56 | displayName: Build & Test Windows 57 | pool: 58 | vmImage: 'windows-latest' 59 | variables: 60 | buildConfiguration: 'Release' 61 | artifactsFolder: '$(Build.SourcesDirectory)/artifacts/' 62 | 63 | steps: 64 | - task: UseDotNet@2 65 | displayName: 'Use .NET 6.x' 66 | inputs: 67 | version: '6.x' 68 | packageType: sdk 69 | 70 | - powershell: $version = '0.0.0'; echo "##vso[task.setvariable variable=version]$version" 71 | displayName: Set default version 72 | 73 | - powershell: $version = ($env:Build_SourceBranch -replace 'refs/tags/v',''); echo $version; echo "##vso[task.setvariable variable=version]$version" 74 | displayName: Get version from tag 75 | condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/')) 76 | 77 | - powershell: dotnet publish ./src/TRH/TRH.csproj -c $(buildConfiguration) -r win-x64 -o $(artifactsFolder) --self-contained 78 | displayName: 'Build' 79 | 80 | - powershell: mv TRH.exe trh.exe 81 | displayName: Rename artifact 82 | workingDirectory: '$(artifactsFolder)' 83 | 84 | - task: DotNetCoreCLI@2 85 | displayName: Test 86 | inputs: 87 | command: test 88 | projects: '**/*Test/*.csproj' 89 | arguments: '--configuration $(buildConfiguration) --collect "Code coverage"' 90 | 91 | - task: PowerShell@2 92 | displayName: 'Build MSI setup' 93 | inputs: 94 | targetPath: 'filePath' 95 | filePath: '$(Build.SourcesDirectory)/src/Installer/build-msi.ps1' 96 | arguments: "-version $env:version" 97 | workingDirectory: '$(Build.SourcesDirectory)/src/Installer' 98 | 99 | - powershell: mv $(artifactsFolder)/trh.exe $(Build.ArtifactStagingDirectory); mv $(artifactsFolder)/trh.msi $(Build.ArtifactStagingDirectory) 100 | displayName: Copy artifacts 101 | 102 | - task: PublishBuildArtifacts@1 103 | displayName: Publish 104 | inputs: 105 | pathtoPublish: '$(Build.ArtifactStagingDirectory)' 106 | artifactName: trhWin 107 | 108 | 109 | - job: Release 110 | dependsOn: 111 | - Linux 112 | - Windows 113 | 114 | pool: 115 | vmImage: 'windows-latest' 116 | 117 | steps: 118 | - task: DownloadBuildArtifacts@0 119 | displayName: Download Linux executable 120 | inputs: 121 | buildType: 'current' 122 | downloadType: 'single' 123 | artifactName: 'trhLin' 124 | downloadPath: '$(System.ArtifactsDirectory)' 125 | 126 | - task: DownloadBuildArtifacts@0 127 | displayName: Download Windows executable 128 | inputs: 129 | buildType: 'current' 130 | downloadType: 'single' 131 | artifactName: 'trhWin' 132 | downloadPath: '$(System.ArtifactsDirectory)' 133 | 134 | - powershell: $version = ($env:Build_SourceBranch -replace 'refs/tags/v',''); echo $version; echo "##vso[task.setvariable variable=version]$version" 135 | displayName: Get version from tag 136 | condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/')) 137 | 138 | - task: GitHubRelease@0 139 | displayName: GitHub Release 140 | condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/')) 141 | inputs: 142 | gitHubConnection: 'GitHubTRH' 143 | repositoryName: 'GDATASoftwareAG/TypeRefHasher' 144 | title: 'TypeRefHasher $(version)' 145 | addChangeLog: false 146 | assets: | 147 | $(System.ArtifactsDirectory)\trhLin\* 148 | $(System.ArtifactsDirectory)\trhWin\*.exe 149 | $(System.ArtifactsDirectory)\trhWin\*.msi -------------------------------------------------------------------------------- /manifests/g/GDATA/TypeRefHasher/1.0.0/GDATA.TypeRefHasher.yaml: -------------------------------------------------------------------------------- 1 | 2 | PackageIdentifier: GDATA.TypeRefHasher 3 | PackageVersion: 1.0.0 4 | PackageName: TypeRefHasher 5 | Publisher: G DATA CyberDefense AG 6 | License: Apache 2 7 | LicenseUrl: https://raw.githubusercontent.com/GDATASoftwareAG/TypeRefHasher/master/LICENSE 8 | Moniker: trh 9 | Tags: 10 | - .net 11 | - typerefhash 12 | - trh 13 | - imphash 14 | ShortDescription: CLI tool to compute the TypeRefHash for .NET binaries. 15 | PackageUrl: https://github.com/GDATASoftwareAG/TypeRefHasher 16 | Commands: 17 | - trh 18 | Installers: 19 | - Architecture: x64 20 | InstallerUrl: https://github.com/GDATASoftwareAG/TypeRefHasher/releases/download/v1.0.0/trh.msi 21 | InstallerSha256: E308F5199F4F4972252784DD6B8A39CB542A566B1B75E040F130388E177F5E0B 22 | InstallerType: msi 23 | PackageLocale: en-US 24 | ManifestType: singleton 25 | ManifestVersion: 1.0.0 -------------------------------------------------------------------------------- /manifests/g/GDATA/TypeRefHasher/1.0.3/GDATA.TypeRefHasher.installer.yaml: -------------------------------------------------------------------------------- 1 | # Created using wingetcreate 0.4.2.1 2 | # yaml-language-server: $schema=https://aka.ms/winget-manifest.installer.1.0.0.schema.json 3 | 4 | PackageIdentifier: GDATA.TypeRefHasher 5 | PackageVersion: 1.0.3 6 | InstallerLocale: en-US 7 | MinimumOSVersion: 10.0.0.0 8 | InstallerType: msi 9 | UpgradeBehavior: install 10 | Commands: 11 | - trh 12 | Installers: 13 | - Architecture: x64 14 | InstallerUrl: https://github.com/GDATASoftwareAG/TypeRefHasher/releases/download/v1.0.3/trh.msi 15 | InstallerSha256: 1CF20CA66DCDFDA4007D5B27CEABC81BA8866926E91BB943F6DCC0240810571D 16 | ManifestType: installer 17 | ManifestVersion: 1.0.0 18 | 19 | -------------------------------------------------------------------------------- /manifests/g/GDATA/TypeRefHasher/1.0.3/GDATA.TypeRefHasher.locale.en-US.yaml: -------------------------------------------------------------------------------- 1 | # Created using wingetcreate 0.4.2.1 2 | # yaml-language-server: $schema=https://aka.ms/winget-manifest.defaultLocale.1.0.0.schema.json 3 | 4 | PackageIdentifier: GDATA.TypeRefHasher 5 | PackageVersion: 1.0.3 6 | PackageLocale: en-US 7 | Publisher: G DATA CyberDefense AG 8 | PublisherUrl: https://github.com/GDATASoftwareAG 9 | PublisherSupportUrl: https://github.com/GDATASoftwareAG/TypeRefHasher/issues 10 | PackageName: TypeRefHasher 11 | PackageUrl: https://github.com/GDATASoftwareAG/TypeRefHasher/ 12 | License: Apache 2 13 | LicenseUrl: https://raw.githubusercontent.com/GDATASoftwareAG/TypeRefHasher/master/LICENSE 14 | ShortDescription: CLI tool to compute the TypeRefHash for .NET binaries. 15 | Moniker: trh 16 | Tags: 17 | - .net 18 | - typerefhash 19 | - trh 20 | - imphash 21 | ManifestType: defaultLocale 22 | ManifestVersion: 1.0.0 23 | 24 | -------------------------------------------------------------------------------- /manifests/g/GDATA/TypeRefHasher/1.0.3/GDATA.TypeRefHasher.yaml: -------------------------------------------------------------------------------- 1 | # Created using wingetcreate 0.4.2.1 2 | # yaml-language-server: $schema=https://aka.ms/winget-manifest.version.1.0.0.schema.json 3 | 4 | PackageIdentifier: GDATA.TypeRefHasher 5 | PackageVersion: 1.0.3 6 | DefaultLocale: en-US 7 | ManifestType: version 8 | ManifestVersion: 1.0.0 9 | 10 | -------------------------------------------------------------------------------- /src/Installer/Installer.wixproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | x86 6 | 3.10 7 | d265bb58-6895-4672-89fc-a859f5db514a 8 | 2.0 9 | trh 10 | Package 11 | 12 | 13 | bin\$(Configuration)\ 14 | obj\$(Configuration)\ 15 | Debug 16 | -arch x64 17 | 18 | 19 | bin\$(Configuration)\ 20 | obj\$(Configuration)\ 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/Installer/Product.wxs: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /src/Installer/build-msi.ps1: -------------------------------------------------------------------------------- 1 | Param( 2 | [Parameter(Mandatory=$true)] 3 | [string]$version 4 | ) 5 | 6 | Write-Host "-- Build MSI installer --" 7 | 8 | # Download and install Wix tools 9 | $wixToolsZipUrl = "https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip" 10 | $wixZip = "wix.zip" 11 | $wixPath = "C:\Temp\wix" 12 | 13 | Write-Host "Download Wix Tools" 14 | $ProgressPreference = 'SilentlyContinue' 15 | Invoke-WebRequest -Uri $wixToolsZipUrl -out $wixZip 16 | 17 | Write-Host "Install Wix Toolset" 18 | Expand-Archive $wixZip -DestinationPath $wixPath 19 | $env:PATH += ";$wixPath" 20 | Remove-Item $wixZip 21 | 22 | # Build the MSI package 23 | Write-Host "Build the MSI package" 24 | ((Get-Content -path .\Product.wxs -Raw) -replace '0.0.0',$version) | Set-Content -Path .\Product.wxs 25 | candle -arch x64 -v .\Product.wxs 26 | light -out trh.msi .\Product.wixobj 27 | Copy-Item trh.msi ..\..\artifacts\trh.msi 28 | 29 | -------------------------------------------------------------------------------- /src/TRH/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using PeNet; 3 | using File = System.IO.File; 4 | 5 | namespace TRH 6 | { 7 | class Program 8 | { 9 | private const int Error = 1; 10 | private const int Success = 0; 11 | 12 | public static int Main(string[] args) 13 | { 14 | if (args.Length != 1) 15 | { 16 | Console.Error.WriteLine("Usage: trh pathtofile"); 17 | return Error; 18 | } 19 | 20 | var file = args[0]; 21 | if (!File.Exists(file)) 22 | { 23 | Console.Error.WriteLine("File not found."); 24 | return Error; 25 | } 26 | 27 | if (!PeFile.TryParse(file, out var peFile)) 28 | { 29 | Console.Error.WriteLine("Not a valid PE file."); 30 | return Error; 31 | } 32 | 33 | if (!peFile!.IsDotNet) 34 | { 35 | Console.Error.WriteLine("Not a valid .NET binary."); 36 | return Error; 37 | } 38 | 39 | try 40 | { 41 | Console.WriteLine(peFile.TypeRefHash); 42 | } 43 | catch (Exception) 44 | { 45 | Console.Error.WriteLine("Cannot compute TypeRefHash."); 46 | return Error; 47 | } 48 | 49 | return Success; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/TRH/TRH.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | false 19 | false 20 | false 21 | Size 22 | true 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/TRH/rd.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /test/TRH.Test/Binaries/NetCoreConsole.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDATASoftwareAG/TypeRefHasher/a4b0903c1a2c95e2a50c3e585c0058d482a76c4f/test/TRH.Test/Binaries/NetCoreConsole.dll -------------------------------------------------------------------------------- /test/TRH.Test/Binaries/firefox_x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDATASoftwareAG/TypeRefHasher/a4b0903c1a2c95e2a50c3e585c0058d482a76c4f/test/TRH.Test/Binaries/firefox_x86.exe -------------------------------------------------------------------------------- /test/TRH.Test/Binaries/notPeFile.txt: -------------------------------------------------------------------------------- 1 | This is not a pe file -------------------------------------------------------------------------------- /test/TRH.Test/CLI_Test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using Xunit; 5 | 6 | namespace TRH.Test 7 | { 8 | public class CliTest 9 | { 10 | [Fact] 11 | public void Cli_GivenWrongNumParams_ReturnsError() 12 | { 13 | var cli = GetCliTool(); 14 | 15 | var (exitCode, msg) = RunCli(cli, null); 16 | 17 | Assert.Equal(1, exitCode); 18 | Assert.Equal("Usage: trh pathtofile", msg); 19 | } 20 | 21 | [Fact] 22 | public void Cli_GivenWrongPath_ReturnsError() 23 | { 24 | var cli = GetCliTool(); 25 | var file = "Binaries/doesNotExist.exe"; 26 | 27 | var (exitCode, msg) = RunCli(cli, file); 28 | 29 | Assert.Equal(1, exitCode); 30 | Assert.Equal("File not found.", msg); 31 | } 32 | 33 | [Fact] 34 | public void Cli_GivenNoPeFile_ReturnsError() 35 | { 36 | var cli = GetCliTool(); 37 | var file = "Binaries/notPeFile.txt"; 38 | 39 | var (exitCode, msg) = RunCli(cli, file); 40 | 41 | Assert.Equal(1, exitCode); 42 | Assert.Equal("Not a valid PE file.", msg); 43 | } 44 | 45 | [Fact] 46 | public void Cli_GivenAPeFile_ReturnsError() 47 | { 48 | var cli = GetCliTool(); 49 | var file = "Binaries/firefox_x86.exe"; 50 | 51 | var (exitCode, msg) = RunCli(cli, file); 52 | 53 | Assert.Equal(1, exitCode); 54 | Assert.Equal("Not a valid .NET binary.", msg); 55 | } 56 | 57 | [Fact] 58 | public void Cli_GivenADotNetFile_ReturnsTrh() 59 | { 60 | var cli = GetCliTool(); 61 | var file = "Binaries/NetCoreConsole.dll"; 62 | 63 | var (exitCode, msg) = RunCli(cli, file); 64 | 65 | Assert.Equal(0, exitCode); 66 | Assert.Equal("9b435fef12d55da7073890330a9a4d7f6e02194aa63e6093429db574407458ba", msg); 67 | } 68 | 69 | static (int, string) RunCli(string cli, string param) 70 | { 71 | var process = new Process 72 | { 73 | StartInfo = 74 | { 75 | FileName = cli, 76 | Arguments = param, 77 | UseShellExecute = false, 78 | RedirectStandardOutput = true, 79 | RedirectStandardError = true 80 | } 81 | }; 82 | process.Start(); 83 | var output = process.StandardOutput.ReadToEnd(); 84 | var err = process.StandardError.ReadToEnd(); 85 | process.WaitForExit(); 86 | 87 | return (process.ExitCode, (err + output).Trim()); 88 | } 89 | 90 | private static string GetCliTool() 91 | => Environment.OSVersion.Platform == PlatformID.Unix 92 | ? Path.GetFullPath("../../../../../artifacts/trh") 93 | : Path.GetFullPath("../../../../../artifacts/trh.exe"); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /test/TRH.Test/TRH.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net6.0 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | PreserveNewest 27 | 28 | 29 | PreserveNewest 30 | 31 | 32 | PreserveNewest 33 | 34 | 35 | 36 | 37 | --------------------------------------------------------------------------------