Пример #1
0
        public static List <HackSignature <PatchFootprint> > GeneratePatchHistory(string originalEXE, string modifiedEXE, int maxGapSize = 16)
        {
            var p = new HackSignature <PatchFootprint>(new HackSettings(Path.GetFileName(modifiedEXE), "Generated Patch History"));

            using var oribr = new BinaryReader(new FileStream(originalEXE, FileMode.Open, FileAccess.Read));
            using var modbr = new BinaryReader(new FileStream(modifiedEXE, FileMode.Open, FileAccess.Read));
            while (oribr.BaseStream.Position != oribr.BaseStream.Length)
            {
                //scan for a change
                while (oribr.BaseStream.Position < oribr.BaseStream.Length && oribr.ReadByte() == modbr.ReadByte())
                {
                    ;
                }
                //stop if reaches the end of stream
                if (oribr.BaseStream.Position == oribr.BaseStream.Length)
                {
                    break;
                }
                ulong address = (ulong)(oribr.BaseStream.Position - 1);
                //store the length
                ulong length    = 1;
                int   gapBuffer = maxGapSize;
                bool  wasDifference;
                while (oribr.BaseStream.Position < oribr.BaseStream.Length && ((wasDifference = oribr.ReadByte() != modbr.ReadByte()) || gapBuffer > 0))
                {
                    length++;
                    gapBuffer = (wasDifference) ? maxGapSize : gapBuffer - 1;
                }
                length -= (ulong)(maxGapSize - gapBuffer);
                //add the patch
                p.Patches.Add(new PatchFootprint(address, length));
            }
            return(new List <HackSignature <PatchFootprint> >()
            {
                p
            });
        }
Пример #2
0
 public static HackFootprint Create <T>(HackSignature <T> missingHack) where T : IPatchFootprint
 {
     IPatchFootprint[] p = new IPatchFootprint[missingHack.Patches.Count];
     missingHack.Patches.ToArray().CopyTo(p, 0);
     return(new HackFootprint(missingHack.Settings, p));
 }