Last active
July 4, 2018 11:10
-
-
Save IS4Code/56aa0ba9b8f4c4808882 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The MIT License (MIT) | |
Copyright (c) 2015-2018 IllidanS4 | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. | |
*/ | |
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.IO; | |
using System.Linq; | |
using System.Reflection; | |
using System.Runtime.InteropServices; | |
namespace mbw_novac | |
{ | |
class Program | |
{ | |
[DllImport("kernel32.dll")] | |
static extern IntPtr OpenProcess(ProcessAccessFlags dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, int dwProcessId); | |
[DllImport("kernel32.dll", SetLastError = true)] | |
static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out IntPtr lpNumberOfBytesWritten); | |
[DllImport("kernel32.dll", SetLastError = true)] | |
static extern bool ReadProcessMemory( | |
IntPtr hProcess, | |
IntPtr lpBaseAddress, | |
[Out] byte[] lpBuffer, | |
int dwSize, | |
out IntPtr lpNumberOfBytesRead | |
); | |
[DllImport("kernel32.dll")] | |
static extern Int32 CloseHandle(IntPtr hProcess); | |
static readonly Dictionary<long, IntPtr> addrMap = new Dictionary<long, IntPtr>{ | |
{5361664, (IntPtr)0x0087C30C}, | |
{5359616, (IntPtr)0x0087B30C}, | |
}; | |
public static void Main(string[] args) | |
{ | |
var ass = Assembly.GetExecutingAssembly().GetName(); | |
Console.WriteLine("M&B: Warband VAC Disable v"+ass.Version.ToString(2)+" by IllidanS4 ([email protected])"); | |
var proc = Process.GetProcessesByName("mb_warband").FirstOrDefault(); | |
if(proc == null) | |
{ | |
Console.WriteLine("mb_warband.exe is not running."); | |
}else{ | |
var file = new FileInfo(proc.MainModule.FileName); | |
IntPtr ptr; | |
if(!addrMap.TryGetValue(file.Length, out ptr)) | |
{ | |
Console.WriteLine("Unrecognized mb_warband.exe size, do you want to continue? (Y/N)"); | |
char ch = Char.ToUpper(Console.ReadKey(true).KeyChar); | |
if(!(ch == 'Y' || ch == 'Z')) | |
{ | |
Console.WriteLine("Quitting..."); | |
return; | |
} | |
} | |
var hProc = OpenProcess(ProcessAccessFlags.All, false, (int)proc.Id); | |
try{ | |
IntPtr tmp; | |
byte[] buffer = new byte[1]; | |
ReadProcessMemory(hProc, ptr, buffer, 1, out tmp); | |
if(buffer[0] != 1) | |
{ | |
Console.Write("Unrecognized version"); | |
if(buffer[0] == 0) | |
{ | |
Console.WriteLine(" / VAC is already turned off."); | |
}else{ | |
Console.WriteLine("."); | |
} | |
}else{ | |
buffer[0] = 0; | |
WriteProcessMemory(hProc, ptr, buffer, 1, out tmp); | |
Console.WriteLine("VAC disabled."); | |
} | |
}finally{ | |
CloseHandle(hProc); | |
} | |
} | |
Console.ReadKey(true); | |
} | |
[Flags] | |
enum ProcessAccessFlags : uint | |
{ | |
All = 0x001F0FFF, | |
Terminate = 0x00000001, | |
CreateThread = 0x00000002, | |
VMOperation = 0x00000008, | |
VMRead = 0x00000010, | |
VMWrite = 0x00000020, | |
DupHandle = 0x00000040, | |
SetInformation = 0x00000200, | |
QueryInformation = 0x00000400, | |
Synchronize = 0x00100000 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment