├── SteamAPIValidator ├── App.config ├── NativeMethods.cs ├── Properties │ └── AssemblyInfo.cs ├── Program.cs ├── SteamAPIValidator.csproj └── SteamApiValidator.cs ├── README.MD ├── SteamAPIValidator.sln └── .gitignore /SteamAPIValidator/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /SteamAPIValidator/NativeMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SteamAPIValidator 9 | { 10 | internal static class NativeMethods 11 | { 12 | [DllImport("kernel32.dll")] 13 | public static extern IntPtr LoadLibrary(string dllToLoad); 14 | 15 | [DllImport("kernel32.dll")] 16 | public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); 17 | 18 | [DllImport("kernel32.dll")] 19 | public static extern bool FreeLibrary(IntPtr hModule); 20 | 21 | [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] 22 | [return: MarshalAs(UnmanagedType.Bool)] 23 | public static extern bool SetDllDirectory(string lpPathName); 24 | 25 | [DllImport("UnityPlayer")] 26 | public static extern int UnityMain(IntPtr hInstance, IntPtr hPrevInstance, 27 | [MarshalAs(UnmanagedType.LPWStr)]ref string lpCmdline, int nShowCmd); 28 | } 29 | } -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | Every single game on Steam is cracked by just having a steam_api emulator that takes all the calls and gives the application the illusion they're connected and own the product. This launcher verifies the validity of signature on the steam_api DLL to ensure it's the official Valve one. 2 | 3 | This is simple to bypass and should be obfuscated but the interesting part is this all runs as a replacement launcher for Unity so you can do your own cool looking thing referencing this code. Maybe just take the interop method for launching the unity game. 4 | 5 | You should reference the Program.cs as it also performs a validation of the game assembly for mods and if so, disables achievements. Essentially, you want to clone this and take what you need. 6 | 7 | 8 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 9 | Version 2, December 2004 10 | 11 | Copyright (C) 2004 Sam Hocevar 12 | 13 | Everyone is permitted to copy and distribute verbatim or modified 14 | copies of this license document, and changing it is allowed as long 15 | as the name is changed. 16 | 17 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 18 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 19 | 20 | 0. You just DO WHAT THE FUCK YOU WANT TO. 21 | 22 | 23 | (if you use it give me a holler, i've got plenty of small things sitting here to mess with steam piracy) 24 | -------------------------------------------------------------------------------- /SteamAPIValidator/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SteamAPIValidator.cs")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SteamAPIValidator.cs")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("23ff8003-cc1e-41ce-a4ef-825474c34ce2")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /SteamAPIValidator.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28803.156 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SteamAPIValidator", "SteamAPIValidator\SteamAPIValidator.csproj", "{23FF8003-CC1E-41CE-A4EF-825474C34CE2}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|x64 = Debug|x64 12 | Release|Any CPU = Release|Any CPU 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {23FF8003-CC1E-41CE-A4EF-825474C34CE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {23FF8003-CC1E-41CE-A4EF-825474C34CE2}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {23FF8003-CC1E-41CE-A4EF-825474C34CE2}.Debug|x64.ActiveCfg = Debug|x64 19 | {23FF8003-CC1E-41CE-A4EF-825474C34CE2}.Debug|x64.Build.0 = Debug|x64 20 | {23FF8003-CC1E-41CE-A4EF-825474C34CE2}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {23FF8003-CC1E-41CE-A4EF-825474C34CE2}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {23FF8003-CC1E-41CE-A4EF-825474C34CE2}.Release|x64.ActiveCfg = Release|x64 23 | {23FF8003-CC1E-41CE-A4EF-825474C34CE2}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {02538CF1-4D5C-4446-A34C-9FD5441E70E1} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /SteamAPIValidator/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | using System.Security.Cryptography; 9 | using System.Security.Cryptography.X509Certificates; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | 13 | namespace SteamAPIValidator 14 | { 15 | internal class Program 16 | { 17 | public const string ASSEMBLY_SHA = "729A5065775444990384357A30D7D5A8D5B7EE767206272982E2397366D65C56"; 18 | 19 | private static string GetChecksum(string file) 20 | { 21 | using (FileStream stream = File.OpenRead(file)) 22 | { 23 | SHA256Managed sha = new SHA256Managed(); 24 | byte[] checksum = sha.ComputeHash(stream); 25 | return BitConverter.ToString(checksum).Replace("-", String.Empty); 26 | } 27 | } 28 | 29 | public static void Main() 30 | { 31 | bool basicCheck = SteamApiValidator.IsValidSteamApiDll(); 32 | bool? advancedCheck = null; 33 | if (SteamApiValidator.IsSteamClientUsed()) 34 | { 35 | advancedCheck = SteamApiValidator.IsValidSteamClientDll(); 36 | } 37 | 38 | var dirInfo = new DirectoryInfo(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath); 39 | string gameName = dirInfo.Name; 40 | 41 | dirInfo = dirInfo.Root; 42 | 43 | if (basicCheck && advancedCheck == true || advancedCheck == null) 44 | { 45 | Console.WriteLine("No SteamClient DLL bundled! Great!"); 46 | Console.WriteLine($"Steam API/Client has passed first phase. Running {gameName}."); 47 | } 48 | else 49 | { 50 | if (!basicCheck) 51 | { 52 | Console.WriteLine("Steam API DLL has been tampered and missing the certificate."); 53 | } 54 | 55 | if (!advancedCheck == false) 56 | { 57 | Console.WriteLine("Steam client DLL has been tampered."); 58 | } 59 | 60 | Console.WriteLine("Due to Steam DRM tampering, game will not begin."); 61 | Console.WriteLine("Press enter to quit."); 62 | Console.ReadLine(); 63 | Environment.Exit(1); 64 | } 65 | 66 | Console.WriteLine($"Thank you for support {gameName}! Loading..."); 67 | 68 | string assemblyDataPath = Path.Combine(dirInfo.FullName, gameName + "_Data", "Managed", "Assembly-CSharp.dll"); 69 | Directory.SetCurrentDirectory(dirInfo.FullName); 70 | IntPtr hPrevInstance = IntPtr.Zero; 71 | NativeMethods.SetDllDirectory(dirInfo.FullName); 72 | string niceArgs = string.Join(" ", new[] { Assembly.GetExecutingAssembly().CodeBase }.Concat(Environment.GetCommandLineArgs())); 73 | 74 | if (GetChecksum(assemblyDataPath) == ASSEMBLY_SHA) 75 | { 76 | niceArgs += " --disable-achievements"; 77 | } 78 | 79 | var dllModule = NativeMethods.LoadLibrary(Path.Combine(dirInfo.FullName + "UnityPlayer.dll")); 80 | 81 | // TODO: Hop in appdomain and be cautious. 82 | 83 | NativeMethods.UnityMain(Process.GetCurrentProcess().Handle, IntPtr.Zero, ref niceArgs, 1); 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /SteamAPIValidator/SteamAPIValidator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {23FF8003-CC1E-41CE-A4EF-825474C34CE2} 8 | Exe 9 | UnityLauncher 10 | UnityLauncher 11 | v4.6.1 12 | 512 13 | true 14 | 15 | 16 | 17 | 18 | AnyCPU 19 | true 20 | full 21 | false 22 | D:\SteamLibrary\steamapps\common\Risk of Rain 2\ 23 | DEBUG;TRACE 24 | prompt 25 | 0 26 | false 27 | 28 | 29 | AnyCPU 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | true 39 | bin\x64\Debug\ 40 | DEBUG;TRACE 41 | full 42 | x64 43 | prompt 44 | MinimumRecommendedRules.ruleset 45 | true 46 | 47 | 48 | bin\x64\Release\ 49 | TRACE 50 | true 51 | pdbonly 52 | x64 53 | prompt 54 | MinimumRecommendedRules.ruleset 55 | true 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | PreserveNewest 80 | 81 | 82 | 83 | 84 | 5.4.0.201 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /.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 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /SteamAPIValidator/SteamApiValidator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Darvell Long 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | * 22 | */ 23 | 24 | using System; 25 | using System.Collections.Generic; 26 | using System.ComponentModel; 27 | using System.Diagnostics; 28 | using System.IO; 29 | using System.Linq; 30 | using System.Reflection; 31 | using System.Runtime.InteropServices; 32 | using System.Runtime.Remoting.Messaging; 33 | using System.Security.Cryptography.Pkcs; 34 | using System.Security.Cryptography.X509Certificates; 35 | using System.Text; 36 | 37 | namespace SteamAPIValidator 38 | { 39 | #region WinCrypt 40 | 41 | internal static class WinCrypt 42 | { 43 | [StructLayout(LayoutKind.Sequential)] 44 | public struct BLOB 45 | { 46 | public int cbData; 47 | public IntPtr pbData; 48 | } 49 | 50 | [StructLayout(LayoutKind.Sequential)] 51 | public struct CRYPT_ALGORITHM_IDENTIFIER 52 | { 53 | public String pszObjId; 54 | private BLOB Parameters; 55 | } 56 | 57 | [StructLayout(LayoutKind.Sequential)] 58 | public struct CERT_ID 59 | { 60 | public int dwIdChoice; 61 | public BLOB IssuerSerialNumberOrKeyIdOrHashId; 62 | } 63 | 64 | [StructLayoutAttribute(LayoutKind.Sequential)] 65 | public struct SIGNER_SUBJECT_INFO 66 | { 67 | /// DWORD->unsigned int 68 | public uint cbSize; 69 | 70 | /// DWORD* 71 | public System.IntPtr pdwIndex; 72 | 73 | /// DWORD->unsigned int 74 | public uint dwSubjectChoice; 75 | 76 | /// SubjectChoiceUnion 77 | public SubjectChoiceUnion Union1; 78 | } 79 | 80 | [StructLayoutAttribute(LayoutKind.Explicit)] 81 | public struct SubjectChoiceUnion 82 | { 83 | /// SIGNER_FILE_INFO* 84 | [FieldOffsetAttribute(0)] 85 | public System.IntPtr pSignerFileInfo; 86 | 87 | /// SIGNER_BLOB_INFO* 88 | [FieldOffsetAttribute(0)] 89 | public System.IntPtr pSignerBlobInfo; 90 | } 91 | 92 | [StructLayout(LayoutKind.Sequential)] 93 | public struct CERT_NAME_BLOB 94 | { 95 | public uint cbData; 96 | 97 | [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] 98 | public byte[] pbData; 99 | } 100 | 101 | [StructLayout(LayoutKind.Sequential)] 102 | public struct CRYPT_INTEGER_BLOB 103 | { 104 | public UInt32 cbData; 105 | public IntPtr pbData; 106 | } 107 | 108 | [StructLayout(LayoutKind.Sequential)] 109 | public struct CRYPT_ATTR_BLOB 110 | { 111 | public uint cbData; 112 | 113 | [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] 114 | public byte[] pbData; 115 | } 116 | 117 | [StructLayout(LayoutKind.Sequential)] 118 | public struct CRYPT_ATTRIBUTE 119 | { 120 | [MarshalAs(UnmanagedType.LPStr)] 121 | public string pszObjId; 122 | 123 | public uint cValue; 124 | 125 | [MarshalAs(UnmanagedType.LPStruct)] 126 | public CRYPT_ATTR_BLOB rgValue; 127 | } 128 | 129 | [StructLayout(LayoutKind.Sequential)] 130 | public struct CMSG_SIGNER_INFO 131 | { 132 | public int dwVersion; 133 | private CERT_NAME_BLOB Issuer; 134 | private CRYPT_INTEGER_BLOB SerialNumber; 135 | private CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm; 136 | private CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm; 137 | private BLOB EncryptedHash; 138 | private CRYPT_ATTRIBUTE[] AuthAttrs; 139 | private CRYPT_ATTRIBUTE[] UnauthAttrs; 140 | } 141 | 142 | [DllImport("crypt32.dll", CharSet = CharSet.Auto, SetLastError = true)] 143 | public static extern Boolean CryptQueryObject( 144 | int dwObjectType, 145 | IntPtr pvObject, 146 | int dwExpectedContentTypeFlags, 147 | int dwExpectedFormatTypeFlags, 148 | int dwFlags, 149 | out int pdwMsgAndCertEncodingType, 150 | out int pdwContentType, 151 | out int pdwFormatType, 152 | ref IntPtr phCertStore, 153 | ref IntPtr phMsg, 154 | ref IntPtr ppvContext); 155 | 156 | [DllImport("crypt32.dll", CharSet = CharSet.Auto, SetLastError = true)] 157 | public static extern Boolean CryptMsgGetParam( 158 | IntPtr hCryptMsg, 159 | int dwParamType, 160 | int dwIndex, 161 | IntPtr pvData, 162 | ref int pcbData 163 | ); 164 | 165 | [DllImport("crypt32.dll", CharSet = CharSet.Auto, SetLastError = true)] 166 | public static extern Boolean CryptMsgGetParam( 167 | IntPtr hCryptMsg, 168 | int dwParamType, 169 | int dwIndex, 170 | [In, Out] byte[] vData, 171 | ref int pcbData 172 | ); 173 | 174 | [DllImport("crypt32.dll", CharSet = CharSet.Auto, SetLastError = true)] 175 | [return: MarshalAs(UnmanagedType.Bool)] 176 | public static extern bool CryptDecodeObject( 177 | uint CertEncodingType, 178 | UIntPtr lpszStructType, 179 | byte[] pbEncoded, 180 | uint cbEncoded, 181 | uint flags, 182 | [In, Out] byte[] pvStructInfo, 183 | ref uint cbStructInfo); 184 | 185 | public const int CRYPT_ASN_ENCODING = 0x00000001; 186 | public const int CRYPT_NDR_ENCODING = 0x00000002; 187 | public const int X509_ASN_ENCODING = 0x00000001; 188 | public const int X509_NDR_ENCODING = 0x00000002; 189 | public const int PKCS_7_ASN_ENCODING = 0x00010000; 190 | public const int PKCS_7_NDR_ENCODING = 0x00020000; 191 | 192 | public static UIntPtr PKCS7_SIGNER_INFO = new UIntPtr(500); 193 | public static UIntPtr CMS_SIGNER_INFO = new UIntPtr(501); 194 | 195 | public static string szOID_RSA_signingTime = "1.2.840.113549.1.9.5"; 196 | public static string szOID_RSA_counterSign = "1.2.840.113549.1.9.6"; 197 | 198 | //+------------------------------------------------------------------------- 199 | // Get parameter types and their corresponding data structure definitions. 200 | //-------------------------------------------------------------------------- 201 | public const int CMSG_TYPE_PARAM = 1; 202 | 203 | public const int CMSG_CONTENT_PARAM = 2; 204 | public const int CMSG_BARE_CONTENT_PARAM = 3; 205 | public const int CMSG_INNER_CONTENT_TYPE_PARAM = 4; 206 | public const int CMSG_SIGNER_COUNT_PARAM = 5; 207 | public const int CMSG_SIGNER_INFO_PARAM = 6; 208 | public const int CMSG_SIGNER_CERT_INFO_PARAM = 7; 209 | public const int CMSG_SIGNER_HASH_ALGORITHM_PARAM = 8; 210 | public const int CMSG_SIGNER_AUTH_ATTR_PARAM = 9; 211 | public const int CMSG_SIGNER_UNAUTH_ATTR_PARAM = 10; 212 | public const int CMSG_CERT_COUNT_PARAM = 11; 213 | public const int CMSG_CERT_PARAM = 12; 214 | public const int CMSG_CRL_COUNT_PARAM = 13; 215 | public const int CMSG_CRL_PARAM = 14; 216 | public const int CMSG_ENVELOPE_ALGORITHM_PARAM = 15; 217 | public const int CMSG_RECIPIENT_COUNT_PARAM = 17; 218 | public const int CMSG_RECIPIENT_INDEX_PARAM = 18; 219 | public const int CMSG_RECIPIENT_INFO_PARAM = 19; 220 | public const int CMSG_HASH_ALGORITHM_PARAM = 20; 221 | public const int CMSG_HASH_DATA_PARAM = 21; 222 | public const int CMSG_COMPUTED_HASH_PARAM = 22; 223 | public const int CMSG_ENCRYPT_PARAM = 26; 224 | public const int CMSG_ENCRYPTED_DIGEST = 27; 225 | public const int CMSG_ENCODED_SIGNER = 28; 226 | public const int CMSG_ENCODED_MESSAGE = 29; 227 | public const int CMSG_VERSION_PARAM = 30; 228 | public const int CMSG_ATTR_CERT_COUNT_PARAM = 31; 229 | public const int CMSG_ATTR_CERT_PARAM = 32; 230 | public const int CMSG_CMS_RECIPIENT_COUNT_PARAM = 33; 231 | public const int CMSG_CMS_RECIPIENT_INDEX_PARAM = 34; 232 | public const int CMSG_CMS_RECIPIENT_ENCRYPTED_KEY_INDEX_PARAM = 35; 233 | public const int CMSG_CMS_RECIPIENT_INFO_PARAM = 36; 234 | public const int CMSG_UNPROTECTED_ATTR_PARAM = 37; 235 | public const int CMSG_SIGNER_CERT_ID_PARAM = 38; 236 | public const int CMSG_CMS_SIGNER_INFO_PARAM = 39; 237 | 238 | //------------------------------------------------------------------------- 239 | //dwObjectType for CryptQueryObject 240 | //------------------------------------------------------------------------- 241 | public const int CERT_QUERY_OBJECT_FILE = 0x00000001; 242 | 243 | public const int CERT_QUERY_OBJECT_BLOB = 0x00000002; 244 | 245 | //------------------------------------------------------------------------- 246 | //dwContentType for CryptQueryObject 247 | //------------------------------------------------------------------------- 248 | //encoded single certificate 249 | public const int CERT_QUERY_CONTENT_CERT = 1; 250 | 251 | //encoded single CTL 252 | public const int CERT_QUERY_CONTENT_CTL = 2; 253 | 254 | //encoded single CRL 255 | public const int CERT_QUERY_CONTENT_CRL = 3; 256 | 257 | //serialized store 258 | public const int CERT_QUERY_CONTENT_SERIALIZED_STORE = 4; 259 | 260 | //serialized single certificate 261 | public const int CERT_QUERY_CONTENT_SERIALIZED_CERT = 5; 262 | 263 | //serialized single CTL 264 | public const int CERT_QUERY_CONTENT_SERIALIZED_CTL = 6; 265 | 266 | //serialized single CRL 267 | public const int CERT_QUERY_CONTENT_SERIALIZED_CRL = 7; 268 | 269 | //a PKCS#7 signed message 270 | public const int CERT_QUERY_CONTENT_PKCS7_SIGNED = 8; 271 | 272 | //a PKCS#7 message, such as enveloped message. But it is not a signed message, 273 | public const int CERT_QUERY_CONTENT_PKCS7_UNSIGNED = 9; 274 | 275 | //a PKCS7 signed message embedded in a file 276 | public const int CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED = 10; 277 | 278 | //an encoded PKCS#10 279 | public const int CERT_QUERY_CONTENT_PKCS10 = 11; 280 | 281 | //an encoded PKX BLOB 282 | public const int CERT_QUERY_CONTENT_PFX = 12; 283 | 284 | //an encoded CertificatePair (contains forward and/or reverse cross certs) 285 | public const int CERT_QUERY_CONTENT_CERT_PAIR = 13; 286 | 287 | //------------------------------------------------------------------------- 288 | //dwExpectedConentTypeFlags for CryptQueryObject 289 | //------------------------------------------------------------------------- 290 | //encoded single certificate 291 | public const int CERT_QUERY_CONTENT_FLAG_CERT = (1 << CERT_QUERY_CONTENT_CERT); 292 | 293 | //encoded single CTL 294 | public const int CERT_QUERY_CONTENT_FLAG_CTL = (1 << CERT_QUERY_CONTENT_CTL); 295 | 296 | //encoded single CRL 297 | public const int CERT_QUERY_CONTENT_FLAG_CRL = (1 << CERT_QUERY_CONTENT_CRL); 298 | 299 | //serialized store 300 | public const int CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE = (1 << CERT_QUERY_CONTENT_SERIALIZED_STORE); 301 | 302 | //serialized single certificate 303 | public const int CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT = (1 << CERT_QUERY_CONTENT_SERIALIZED_CERT); 304 | 305 | //serialized single CTL 306 | public const int CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL = (1 << CERT_QUERY_CONTENT_SERIALIZED_CTL); 307 | 308 | //serialized single CRL 309 | public const int CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL = (1 << CERT_QUERY_CONTENT_SERIALIZED_CRL); 310 | 311 | //an encoded PKCS#7 signed message 312 | public const int CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED = (1 << CERT_QUERY_CONTENT_PKCS7_SIGNED); 313 | 314 | //an encoded PKCS#7 message. But it is not a signed message 315 | public const int CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED = (1 << CERT_QUERY_CONTENT_PKCS7_UNSIGNED); 316 | 317 | //the content includes an embedded PKCS7 signed message 318 | public const int CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED = (1 << CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED); 319 | 320 | //an encoded PKCS#10 321 | public const int CERT_QUERY_CONTENT_FLAG_PKCS10 = (1 << CERT_QUERY_CONTENT_PKCS10); 322 | 323 | //an encoded PFX BLOB 324 | public const int CERT_QUERY_CONTENT_FLAG_PFX = (1 << CERT_QUERY_CONTENT_PFX); 325 | 326 | //an encoded CertificatePair (contains forward and/or reverse cross certs) 327 | public const int CERT_QUERY_CONTENT_FLAG_CERT_PAIR = (1 << CERT_QUERY_CONTENT_CERT_PAIR); 328 | 329 | //content can be any type 330 | public const int CERT_QUERY_CONTENT_FLAG_ALL = 331 | CERT_QUERY_CONTENT_FLAG_CERT | 332 | CERT_QUERY_CONTENT_FLAG_CTL | 333 | CERT_QUERY_CONTENT_FLAG_CRL | 334 | CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE | 335 | CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT | 336 | CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL | 337 | CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL | 338 | CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED | 339 | CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED | 340 | CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED | 341 | CERT_QUERY_CONTENT_FLAG_PKCS10 | 342 | CERT_QUERY_CONTENT_FLAG_PFX | 343 | CERT_QUERY_CONTENT_FLAG_CERT_PAIR; 344 | 345 | //------------------------------------------------------------------------- 346 | //dwFormatType for CryptQueryObject 347 | //------------------------------------------------------------------------- 348 | //the content is in binary format 349 | public const int CERT_QUERY_FORMAT_BINARY = 1; 350 | 351 | //the content is base64 encoded 352 | public const int CERT_QUERY_FORMAT_BASE64_ENCODED = 2; 353 | 354 | //the content is ascii hex encoded with "{ASN}" prefix 355 | public const int CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED = 3; 356 | 357 | //------------------------------------------------------------------------- 358 | //dwExpectedFormatTypeFlags for CryptQueryObject 359 | //------------------------------------------------------------------------- 360 | //the content is in binary format 361 | public const int CERT_QUERY_FORMAT_FLAG_BINARY = (1 << CERT_QUERY_FORMAT_BINARY); 362 | 363 | //the content is base64 encoded 364 | public const int CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED = (1 << CERT_QUERY_FORMAT_BASE64_ENCODED); 365 | 366 | //the content is ascii hex encoded with "{ASN}" prefix 367 | public const int CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED = (1 << CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED); 368 | 369 | //the content can be of any format 370 | public const int CERT_QUERY_FORMAT_FLAG_ALL = 371 | CERT_QUERY_FORMAT_FLAG_BINARY | 372 | CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED | 373 | CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED; 374 | } 375 | 376 | #endregion WinCrypt 377 | 378 | public static class SteamApiValidator 379 | { 380 | #region P/Invoke Methods 381 | 382 | [DllImport("kernel32.dll")] 383 | private static extern IntPtr LoadLibrary(string dllToLoad); 384 | 385 | [DllImport("kernel32.dll", CharSet = CharSet.Auto)] 386 | private static extern IntPtr GetModuleHandle(string lpModuleName); 387 | 388 | [DllImport("kernel32.dll", SetLastError = true)] 389 | [PreserveSig] 390 | private static extern uint GetModuleFileName 391 | ( 392 | [In] IntPtr hModule, 393 | [Out] StringBuilder lpFilename, 394 | [In][MarshalAs(UnmanagedType.U4)] int nSize 395 | ); 396 | 397 | #endregion P/Invoke Methods 398 | 399 | private const int MAX_PATH_SIZE = 32767; // Windows <10 are 256, GPO's now allow max paths of 32767 400 | 401 | /// 402 | /// Determines whether a valid steam API DLL has been loaded and is codesigned by Valve. 403 | /// 404 | /// true if steam API DLL has a valid Valve signature otherwise, false. 405 | public static bool IsValidSteamApiDll() 406 | { 407 | foreach (string steamDllName in new[] { "steam_api64.dll", "steam_api.dll" }) 408 | { 409 | IntPtr steamApiPtr = GetModuleHandle(steamDllName); 410 | 411 | if (steamApiPtr == IntPtr.Zero) 412 | { 413 | Debug.WriteLine("Steam API has not loaded. Forcing an emergency load, this won't cause issues."); 414 | steamApiPtr = LoadLibrary(steamDllName); 415 | } 416 | if (steamApiPtr == IntPtr.Zero) 417 | { 418 | Debug.WriteLine("Steam API not found."); 419 | return false; 420 | } 421 | 422 | if (steamApiPtr != IntPtr.Zero) 423 | { 424 | StringBuilder fileBuilder = new StringBuilder(MAX_PATH_SIZE); 425 | if (GetModuleFileName(steamApiPtr, fileBuilder, MAX_PATH_SIZE) > 0) // 0 means you screwed up. 426 | { 427 | return CheckIfValveSigned(fileBuilder.ToString()); 428 | } 429 | } 430 | } 431 | 432 | return false; 433 | } 434 | 435 | public static bool IsSteamClientUsed() 436 | { 437 | return Directory.GetFileSystemEntries(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), 438 | "steamclien*.dll", SearchOption.AllDirectories).Length > 0; 439 | } 440 | 441 | /// 442 | /// Determines whether the loaded Steam client library is codesigned by Valve. Not all games use this. 443 | /// 444 | /// true if steamclient is codesigned; otherwise, false. 445 | public static bool IsValidSteamClientDll() 446 | { 447 | string steamClientDllName = Environment.Is64BitProcess ? "steamclient64.dll" : "steamclient.dll"; 448 | IntPtr steamClientPtr = GetModuleHandle(steamClientDllName); 449 | 450 | if (steamClientPtr == IntPtr.Zero) 451 | { 452 | bool deepCheck = false; 453 | bool anySteamClient = false; 454 | foreach (var steamDlls in Directory.GetFileSystemEntries(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), 455 | "steamclien*.dll", SearchOption.AllDirectories)) 456 | { 457 | anySteamClient = true; 458 | if (!CheckIfValveSigned(steamDlls)) 459 | { 460 | try 461 | { 462 | Console.WriteLine($"Invalid DLL found. {steamDlls}"); 463 | new FileInfo(steamDlls).MoveTo("PEOPLE_WORKED_HARD.CMON"); 464 | } 465 | catch 466 | { 467 | Console.WriteLine("Couldn't remove offending Steam DLL."); 468 | } 469 | } 470 | else 471 | { 472 | deepCheck = true; 473 | } 474 | } 475 | 476 | return deepCheck; 477 | } 478 | 479 | if (steamClientPtr != IntPtr.Zero) 480 | { 481 | StringBuilder fileBuilder = new StringBuilder(MAX_PATH_SIZE); 482 | if (GetModuleFileName(steamClientPtr, fileBuilder, MAX_PATH_SIZE) > 0) // 0 means you screwed up. 483 | { 484 | return CheckIfValveSigned(fileBuilder.ToString()); 485 | } 486 | } 487 | 488 | return false; 489 | } 490 | 491 | private static X509Certificate2 GetDigitalCertificate(string filePath) 492 | { 493 | X509Certificate2 cert = null; 494 | 495 | int encodingType; 496 | int contentType; 497 | int formatType; 498 | IntPtr certStore = IntPtr.Zero; 499 | IntPtr cryptMsg = IntPtr.Zero; 500 | IntPtr context = IntPtr.Zero; 501 | 502 | if (!WinCrypt.CryptQueryObject( 503 | WinCrypt.CERT_QUERY_OBJECT_FILE, 504 | Marshal.StringToHGlobalUni(filePath), 505 | (WinCrypt.CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED 506 | | WinCrypt.CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED 507 | | WinCrypt.CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED), 508 | WinCrypt.CERT_QUERY_FORMAT_FLAG_ALL, 509 | 0, 510 | out encodingType, 511 | out contentType, 512 | out formatType, 513 | ref certStore, 514 | ref cryptMsg, 515 | ref context)) 516 | { 517 | Console.WriteLine("Can't read cert at all."); 518 | throw new InvalidOperationException($"{Marshal.GetLastWin32Error()} - Sigs ain't working."); 519 | } 520 | 521 | // Get size of the encoded message. 522 | int cbData = 0; 523 | if (!WinCrypt.CryptMsgGetParam( 524 | cryptMsg, 525 | WinCrypt.CMSG_ENCODED_MESSAGE, 526 | 0, 527 | IntPtr.Zero, 528 | ref cbData)) 529 | { 530 | throw new Win32Exception(Marshal.GetLastWin32Error()); 531 | } 532 | 533 | var vData = new byte[cbData]; 534 | 535 | // Get the encoded message. 536 | if (!WinCrypt.CryptMsgGetParam( 537 | cryptMsg, 538 | WinCrypt.CMSG_ENCODED_MESSAGE, 539 | 0, 540 | vData, 541 | ref cbData)) 542 | { 543 | throw new Win32Exception(Marshal.GetLastWin32Error()); 544 | } 545 | 546 | var signedCms = new SignedCms(); 547 | signedCms.Decode(vData); 548 | 549 | if (signedCms.SignerInfos.Count > 0) 550 | { 551 | var signerInfo = signedCms.SignerInfos[0]; 552 | 553 | if (signerInfo.Certificate != null) 554 | { 555 | cert = signerInfo.Certificate; 556 | } 557 | } 558 | 559 | return cert; 560 | } 561 | 562 | /// 563 | /// Checks if DLL or EXE is signed by Valve. 564 | /// 565 | /// The file path. 566 | /// System.Boolean. 567 | private static int signCount = 0; 568 | 569 | private static bool CheckIfValveSigned(string filePath) 570 | { 571 | try 572 | { 573 | if (signCount == 0) 574 | { 575 | Console.WriteLine($"Looking at that cert in {filePath}"); 576 | } 577 | else if (signCount == 5) 578 | { 579 | Console.WriteLine($"Unable to {filePath} after 5 times. Assuming CN emulator."); 580 | return false; 581 | } 582 | 583 | using (var cert = GetDigitalCertificate(filePath)) 584 | { 585 | if (cert.Subject == "CN=Valve, O=Valve, L=Bellevue, S=WA, C=US") 586 | { 587 | Console.WriteLine($"{filePath} is signed."); 588 | try 589 | { 590 | // It's super true but the name info is hard to get. 591 | if (cert.GetNameInfo(X509NameType.SimpleName, true) == "Valve") 592 | { 593 | Console.WriteLine($"{filePath} is super legit."); 594 | return true; 595 | } 596 | } 597 | catch 598 | { 599 | // Ignore. 600 | } 601 | 602 | return true; 603 | } 604 | } 605 | } 606 | catch 607 | { 608 | // Try again. Keep a temporary counter. 609 | signCount += 1; 610 | CheckIfValveSigned(filePath); 611 | // Ignore. 612 | } 613 | 614 | return false; 615 | } 616 | 617 | /// 618 | /// Helps iterate through subdirectories to find naughty DLL's. 619 | /// 620 | /// 621 | /// 622 | /// 623 | private static List GetAllFilesFromFolder(string root, bool searchSubfolders) 624 | { 625 | Queue folders = new Queue(); 626 | List files = new List(); 627 | folders.Enqueue(root); 628 | while (folders.Count != 0) 629 | { 630 | string currentFolder = folders.Dequeue(); 631 | try 632 | { 633 | string[] filesInCurrent = System.IO.Directory.GetFiles(currentFolder, "*.*", System.IO.SearchOption.TopDirectoryOnly); 634 | files.AddRange(filesInCurrent); 635 | } 636 | catch 637 | { 638 | // Do Nothing 639 | } 640 | try 641 | { 642 | if (searchSubfolders) 643 | { 644 | string[] foldersInCurrent = System.IO.Directory.GetDirectories(currentFolder, "*.*", System.IO.SearchOption.TopDirectoryOnly); 645 | foreach (string _current in foldersInCurrent) 646 | { 647 | folders.Enqueue(_current); 648 | } 649 | } 650 | } 651 | catch 652 | { 653 | // Do Nothing 654 | } 655 | } 656 | return files; 657 | } 658 | 659 | public static void Rename(this FileInfo fileInfo, string newName) 660 | { 661 | fileInfo.MoveTo(fileInfo.Directory.FullName + "\\" + newName); 662 | try 663 | { 664 | File.Delete(fileInfo.FullName); 665 | } 666 | catch 667 | { 668 | } 669 | } 670 | } 671 | } --------------------------------------------------------------------------------