You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
4.2 KiB

  1. using System;
  2. using System.IO;
  3. using System.Runtime.InteropServices;
  4. using System.Security.Principal;
  5. using IPA.Utilities;
  6. #if NET3
  7. using Net3_Proxy;
  8. using Path = Net3_Proxy.Path;
  9. using File = Net3_Proxy.File;
  10. using Directory = Net3_Proxy.Directory;
  11. #endif
  12. namespace IPA.Injector
  13. {
  14. internal class AntiPiracy
  15. {
  16. public static bool IsInvalid(string path)
  17. {
  18. var dataPlugins = Path.Combine(GameVersionEarly.ResolveDataPath(path), "Plugins");
  19. try
  20. {
  21. var userDir = GetPath(new Guid("374DE290-123F-4565-9164-39C4925E467B"),
  22. KnownFolderFlags.AliasOnly | KnownFolderFlags.DontVerify);
  23. var userDir2 = GetPath(new Guid("7d83ee9b-2244-4e70-b1f5-5393042af1e4"),
  24. KnownFolderFlags.AliasOnly | KnownFolderFlags.DontVerify);
  25. var curdir = Environment.CurrentDirectory;
  26. if (curdir.IsSubPathOf(userDir) ||
  27. curdir.IsSubPathOf(userDir2)) return false;
  28. }
  29. catch { }
  30. // To the guys that maintain a fork that removes this code: I would greatly appreciate if we could talk
  31. // about this for a little bit. Please message me on Discord at DaNike#6223
  32. return
  33. File.Exists(Path.Combine(path, "IGG-GAMES.COM.url")) ||
  34. File.Exists(Path.Combine(path, "SmartSteamEmu.ini")) ||
  35. File.Exists(Path.Combine(path, "GAMESTORRENT.CO.url")) ||
  36. File.Exists(Path.Combine(dataPlugins, "BSteam crack.dll")) ||
  37. File.Exists(Path.Combine(dataPlugins, "HUHUVR_steam_api64.dll")) ||
  38. Directory.GetFiles(dataPlugins, "*.ini", SearchOption.TopDirectoryOnly).Length > 0;
  39. }
  40. private static string GetPath(Guid guid, KnownFolderFlags flags)
  41. {
  42. int result = SHGetKnownFolderPath(guid, (uint)flags, WindowsIdentity.GetCurrent().Token, out IntPtr outPath);
  43. if (result >= 0)
  44. {
  45. string path = Marshal.PtrToStringUni(outPath);
  46. Marshal.FreeCoTaskMem(outPath);
  47. return path;
  48. }
  49. return "";
  50. }
  51. /// <summary>
  52. /// Retrieves the full path of a known folder identified by the folder's known folder ID.
  53. /// </summary>
  54. /// <param name="rfid">A known folder ID that identifies the folder.</param>
  55. /// <param name="dwFlags">Flags that specify special retrieval options. This value can be 0; otherwise, one or
  56. /// more of the <see cref="KnownFolderFlags"/> values.</param>
  57. /// <param name="hToken">An access token that represents a particular user. If this parameter is NULL, which is
  58. /// the most common usage, the function requests the known folder for the current user. Assigning a value of -1
  59. /// indicates the Default User. The default user profile is duplicated when any new user account is created.
  60. /// Note that access to the Default User folders requires administrator privileges.</param>
  61. /// <param name="ppszPath">When this method returns, contains the address of a string that specifies the path of
  62. /// the known folder. The returned path does not include a trailing backslash.</param>
  63. /// <returns>Returns S_OK if successful, or an error value otherwise.</returns>
  64. /// <msdn-id>bb762188</msdn-id>
  65. [DllImport("Shell32.dll")]
  66. private static extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)]Guid rfid, uint dwFlags,
  67. IntPtr hToken, out IntPtr ppszPath);
  68. /// <summary>
  69. /// Represents the retrieval options for known folders.
  70. /// </summary>
  71. /// <msdn-id>dd378447</msdn-id>
  72. [Flags]
  73. private enum KnownFolderFlags : uint
  74. {
  75. None = 0x00000000,
  76. SimpleIDList = 0x00000100,
  77. NotParentRelative = 0x00000200,
  78. DefaultPath = 0x00000400,
  79. Init = 0x00000800,
  80. NoAlias = 0x00001000,
  81. DontUnexpand = 0x00002000,
  82. DontVerify = 0x00004000,
  83. Create = 0x00008000,
  84. NoAppcontainerRedirection = 0x00010000,
  85. AliasOnly = 0x80000000
  86. }
  87. }
  88. }