Skip to content

Instantly share code, notes, and snippets.

@icls1337
Forked from exdownloader/gfe.cs
Created December 8, 2022 17:08
Show Gist options
  • Select an option

  • Save icls1337/e37a1cba8d8fa639989f341c1fc8e2e0 to your computer and use it in GitHub Desktop.

Select an option

Save icls1337/e37a1cba8d8fa639989f341c1fc8e2e0 to your computer and use it in GitHub Desktop.
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
//Based on documentation provided at: https://github.com/Moyster/BaiGfe
//You use this at your own risk, or lack thereof. Works on my machine :^)
public class Scratchpad
{
public static void Main(string[] args)
{
string Prompt(string p) {
Console.Write(p);
return Console.ReadLine();
}
Console.WriteLine("Attempting to modify GFE App.js");
if (!ModifyGFE())
Console.WriteLine("Failed to modify app.js, potentially already modified or patterns have changed. No further changes have been made.");
var fullBlock = string.Empty;
var allowedResponses = new[] { "full", "lite" };
while(!allowedResponses.Contains(fullBlock))
{
fullBlock = Prompt("Full block or lite block? [full/lite]: ");
}
Console.WriteLine("Attempting to modify hosts file");
if (!AddEntriesToHostsFile(fullBlock == "full"))
Console.WriteLine("Failed to modify hosts file, no changes have been made.");
Prompt("Press any key to quit.");
}
static bool ModifyGFE()
{
Console.WriteLine("Locating GFE");
var regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\NVIDIA Corporation\Global\GFExperience");
if (regKey == null) return false;
Console.WriteLine("Locating regkey");
var fullPath = regKey.GetValue("FullPath") as string;
if (fullPath == null) return false;
Console.WriteLine($"Found reg value: {fullPath}");
Console.WriteLine("Locating exe");
var fi = new FileInfo(fullPath);
if (!fi.Exists) return false;
Console.WriteLine("Found exe");
Console.WriteLine("Locating app.js");
var appJs = Path.Combine(fi.Directory.FullName, @"www\app.js");
if(!File.Exists(appJs)) return false;
Console.WriteLine("Found app.js");
Console.WriteLine("Modifying app.js");
var js = File.ReadAllText(appJs);
var findObjectLetter = Regex.Match(js, @"([a-z])\.isLeftPaneVisible=function\(\)", RegexOptions.IgnoreCase);
if (!findObjectLetter.Success) return false;
var objectLetter = findObjectLetter.Groups[1].Value;
var didWork = false;
//TODO: inefficient
if(js.IndexOf("if(e.domains.list.indexOf(n)>-1)return!0") != -1)
{
js = js.Replace("if(e.domains.list.indexOf(n)>-1)return!0", $"if(e.domains.list.indexOf(n)>-1)return {objectLetter}.handleLoggedIn(e), !0");
Console.WriteLine("Added call to login handler");
didWork = true;
}
var patternForIsLeftPaneVisible = Regex.Match(js, "\"choose\"===b\\.nvActiveAuthView\\)\\}\\}", RegexOptions.IgnoreCase);
if (patternForIsLeftPaneVisible.Success)
{
var locationToInsertLoginHandler = patternForIsLeftPaneVisible.Index + patternForIsLeftPaneVisible.Length - 1; //before last curly brace
js = js.Insert(locationToInsertLoginHandler, $",{objectLetter}.handleLoggedIn({{sessionToken:\"dummySessionToken\",userToken:\"dummyUserToken\",user:{{core:{{displayName:\"Anonymous\",primaryEmailVerified:true}}}}}});");
Console.WriteLine("Added login handler");
didWork = true;
}
var patternForShadowplayAndShare = Regex.Match(js, @"[a-z]\.isShareSupported=!1,[a-z]\.isShareButtonClicked=!1", RegexOptions.IgnoreCase);
if (patternForShadowplayAndShare.Success)
{
js = js.Replace(patternForShadowplayAndShare.Value, patternForShadowplayAndShare.Value.Replace("!1", "!0"));
Console.WriteLine("Patched shadowplay and share buttons");
didWork = true;
}
var patternForPreviousLogin = Regex.Match(js, $"EMAIL_NOT_VERIFIED\"\\),{objectLetter}\\.showEmailVerification\\(e\\)", RegexOptions.IgnoreCase);
if (patternForPreviousLogin.Success)
{
js = js.Replace(patternForPreviousLogin.Value, "EMAIL_NOT_VERIFIED\")");
Console.WriteLine("Patched email verification");
didWork = true;
}
if (didWork)
{
var bakPath = appJs + $".{DateTime.Now.Ticks}.bak";
Console.WriteLine($"Backing up app.js to: {bakPath}");
File.Copy(appJs, appJs + $".{DateTime.Now.Ticks}.bak", true);
File.WriteAllText(appJs, js);
Console.WriteLine("Successfully modifed app.js");
}
return didWork;
}
static bool AddEntriesToHostsFile(bool fullBlock)
{
var blockLinesLite = new[]
{
"0.0.0.0 ls.dtrace.nvidia.com",
"0.0.0.0 telemetry.gfe.nvidia.com",
"0.0.0.0 accounts.nvgs.nvidia.com",
"0.0.0.0 accounts.nvgs.nvidia.cn",
"0.0.0.0 nvidia.tt.omtrdc.net",
"0.0.0.0 api.commune.ly",
"0.0.0.0 login.nvgs.nvidia.com",
"0.0.0.0 login.nvgs.nvidia.cn"
};
var blockLinesFull = new[]
{
"0.0.0.0 telemetry.gfe.nvidia.com",
"0.0.0.0 gfe.nvidia.com",
"0.0.0.0 gfwsl.geforce.com",
"0.0.0.0 services.gfe.nvidia.com",
"0.0.0.0 accounts.nvgs.nvidia.com",
"0.0.0.0 accounts.nvgs.nvidia.cn",
"0.0.0.0 events.gfe.nvidia.com",
"0.0.0.0 img.nvidiagrid.net",
"0.0.0.0 images.nvidiagrid.net",
"0.0.0.0 images.nvidia.com",
"0.0.0.0 ls.dtrace.nvidia.com",
"0.0.0.0 ota.nvidia.com",
"0.0.0.0 ota-downloads.nvidia.com",
"0.0.0.0 rds-assets.nvidia.com",
"0.0.0.0 assets.nvidiagrid.net",
"0.0.0.0 nvidia.tt.omtrdc.net",
"0.0.0.0 api.commune.ly",
"0.0.0.0 login.nvgs.nvidia.com",
"0.0.0.0 login.nvgs.nvidia.cn"
};
const string START = "#NVIDIA BLOCKLIST START";
const string END = "#NVIDIA BLOCKLIST END";
var hostsFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"drivers\etc\hosts");
if (!File.Exists(hostsFilePath)) return false;
var linesToRemove = blockLinesLite.Concat(blockLinesFull).Concat(new[] { START, END }).Distinct();
var linesToAdd = new List<string>();
linesToAdd.Add(START);
linesToAdd.AddRange(fullBlock ? blockLinesFull : blockLinesLite);
linesToAdd.Add(END);
var lines = File.ReadAllLines(hostsFilePath)
.Except(linesToRemove)
.Concat(linesToAdd);
File.WriteAllLines(hostsFilePath, lines);
Console.WriteLine("Successfully modified hosts file");
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment