Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- namespace Patch_libnp
- {
- internal class Program
- {
- private static void Main()
- {
- if (!File.Exists("libnp.dll"))
- {
- Console.WriteLine("libnp.dll not found, exiting...");
- return;
- }
- Console.WriteLine("Loading libnp.dll....");
- _file = File.ReadAllBytes("libnp.dll");
- Console.WriteLine("Finding patch point...");
- var index =
- FindPattern(
- new byte[]
- {
- 0x55, 0x8b, 0xec, 0x83, 0xec, 0x00, 0x53, 0x56, 0x57, 0x8b, 0x45, 0x00, 0xa3, 0x00, 0x00,
- 0x00, 0x00, 0x6a, 0x00, 0xff, 0x15, 0x00, 0x00, 0x00, 0x00, 0x83, 0xc4, 0x00, 0x5f, 0x5e,
- 0x5b, 0x8b, 0xe5
- },
- "xxxxx?xxxxx?x????x?xx????xx?xxxxx");
- if (index == -1)
- {
- Console.WriteLine("Patch point not found! Exiting...");
- return;
- }
- _file[index] = 0xc3;
- Console.WriteLine("Backing up libnp.dll as libnp.dll.bak");
- File.Move("libnp.dll", "libnp.dll.bak");
- Console.WriteLine("Writing patches...");
- File.WriteAllBytes("libnp.dll", _file);
- Console.WriteLine("File written.");
- Console.Read();
- }
- /// <summary>
- /// Byte array to be used by FindPattern
- /// </summary>
- private static byte[] _file;
- /// <summary>
- /// Finds a specific pattern in a byte array
- /// Example:
- /// FindPattern(
- /// new byte[]
- /// {
- /// 0x55, 0x8b, 0xec, 0x83, 0xec, 0x00, 0x53, 0x56, 0x57, 0x8b, 0x45, 0x00, 0xa3, 0x00, 0x00,
- /// 0x00, 0x00, 0x6a, 0x00, 0xff, 0x15, 0x00, 0x00, 0x00, 0x00, 0x83, 0xc4, 0x00, 0x5f, 0x5e,
- /// 0x5b, 0x8b, 0xe5
- /// },
- /// "xxxxx?xxxxx?x????x?xx????xx?xxxxx");
- /// </summary>
- /// <param name="btPattern">Byte array containing pattern to search</param>
- /// <param name="strMask">x for exact match, ? for wildcard</param>
- /// <returns>Position of pattern in _file, -1 if pattern not found</returns>
- private static int FindPattern(byte[] btPattern, string strMask)
- {
- try
- {
- if (strMask.Length != btPattern.Length)
- return -1;
- for (int x = 0; x < _file.Length; x++)
- {
- if (MaskCheck(x, btPattern, strMask))
- {
- return x;
- }
- }
- return -1;
- }
- catch (Exception ex)
- {
- return -1;
- }
- }
- private static bool MaskCheck(int nOffset, byte[] btPattern, string strMask)
- {
- return !btPattern.Where((t, x) => strMask[x] != '?' && ((strMask[x] == 'x') && (t != _file[nOffset + x]))).Any();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment