Skip to content

Instantly share code, notes, and snippets.

@stevefan1999-personal
Created June 24, 2018 07:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevefan1999-personal/31623529fd5a1941ff1fd310e5c84a64 to your computer and use it in GitHub Desktop.
Save stevefan1999-personal/31623529fd5a1941ff1fd310e5c84a64 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.Principal;
using System.Threading.Tasks;
public class SigScanSharp
{
public byte[] Target { get; set; }
private bool PatternCheck(int nOffset, byte[] arrPattern)
{
for (int i = 0; i < arrPattern.Length; i++) {
if (arrPattern[i] == 0x0)
continue;
if (arrPattern[i] != this.Target[nOffset + i])
return false;
}
return true;
}
public ulong FindPattern(string szPattern, out long lTime)
{
Stopwatch stopwatch = Stopwatch.StartNew();
byte[] arrPattern = ParsePatternString(szPattern);
for (int nModuleIndex = 0; nModuleIndex < Target.Length; nModuleIndex++) {
if (this.Target[nModuleIndex] != arrPattern[0])
continue;
if (PatternCheck(nModuleIndex, arrPattern)) {
lTime = stopwatch.ElapsedMilliseconds;
return (ulong)nModuleIndex;
}
}
lTime = stopwatch.ElapsedMilliseconds;
return 0;
}
private byte[] ParsePatternString(string szPattern)
{
List<byte> patternbytes = new List<byte>();
foreach (var szByte in szPattern.Split(' '))
patternbytes.Add(szByte == "?" ? (byte)0x0 : Convert.ToByte(szByte, 16));
return patternbytes.ToArray();
}
}
class Program {
static bool IsElevated => WindowsIdentity.GetCurrent().Owner.IsWellKnown(WellKnownSidType.BuiltinAdministratorsSid);
static void Main(string[] args) {
if (!IsElevated) {
Console.WriteLine("Error: this program requires administrator permission");
goto exit;
}
var streamServer = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
"NVIDIA Corporation",
"NvStreamSrv"
);
var streamBackup = Path.Combine(streamServer, "nvstreamer.bak.exe");
if (File.Exists(streamBackup)) {
Console.WriteLine("Error: nvstreamer is already patched");
goto exit;
}
var streamer = Path.Combine(streamServer, "nvstreamer.exe");
Console.WriteLine("Backing up nvstreamer.exe to nvstreamer.bak.exe");
try {
File.Copy(streamer, streamBackup);
Console.WriteLine("Backing up nvstreamer.exe success");
} catch {
Console.WriteLine("Unable to back up nvstreamer.exe");
goto exit;
}
Console.WriteLine("Patching nvstreamer.exe");
try {
Console.WriteLine("Loading nvstreamer.exe");
var streamerBytes = File.ReadAllBytes(streamer);
Console.WriteLine($"File size: {streamerBytes.Length}");
var scanner = new SigScanSharp() {
Target = streamerBytes
};
var pat = scanner.FindPattern("FF 15 ? ? ? ? EB 22 4C 8B 45 F0", out var time);
if (pat != 0) {
Console.WriteLine($"ScreenMonitor::Impl::IsFrameSkipped->ClipCursor found at {pat:X}, time taken {time} ms");
Console.WriteLine("Writing nops");
Parallel.For(0, 6, i => streamerBytes[pat + (uint)i] = 0x90);
var check = streamerBytes.Skip((int)pat).Take(10).ToArray();
Console.WriteLine($"Final bytes: {BitConverter.ToString(check).Replace("-", " ")}");
Console.WriteLine("Writing back to file");
try {
File.WriteAllBytes(streamer, streamerBytes);
Console.WriteLine("Success!");
} catch {
Console.WriteLine("File failed to write");
}
} else {
Console.WriteLine("ScreenMonitor::Impl::IsFrameSkipped->ClipCursor not found");
}
} catch {
Console.WriteLine("Unable to load nvstreamer.exe");
goto exit;
}
exit:
Console.WriteLine("Press enter to exit...");
Console.ReadLine();
}
}
@stevefan1999-personal
Copy link
Author

I have confirmed the clipping is unbounded after my patch by using moonlight to drag the touch control outside my main monitor and so it goes to the second

@RL-shuyi
Copy link

I have confirmed the clipping is unbounded after my patch by using moonlight to drag the touch control outside my main monitor and so it goes to the second
特別感謝您的辛勤付出,我受困于這個問題很長時間了,直到發現您的帖子,很難描述我的激動心情!請原諒我的無知,對於程序代碼一竅不通,斗膽請求您給與我一個能夠運行的程序,再次表達對您的敬意!!郵箱:liuxiaoke10@icloud.com 再次表達歉意,給您添麻煩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment