コード例 #1
0
        //internal static void InjectAsm(uint parPtr, string[] parInstructions, string parPatchName = "")
        //{
        //    if (Asm == null) Asm = new FasmNet();

        //    Asm.Clear();
        //    IntPtr start = new IntPtr(parPtr);
        //    Asm.AddLine("use32");
        //    foreach (string x in parInstructions)
        //    {
        //        Asm.AddLine(x);
        //    }

        //    byte[] byteCode = new byte[0];
        //    try
        //    {
        //        byteCode = Asm.Assemble(start);
        //    }
        //    catch (FasmAssemblerException ex)
        //    {
        //        MessageBox.Show(String.Format("Error definition: {0}; Error code: {1}; Error line: {2}; Error offset: {3}; Mnemonics: {4}",
        //            ex.ErrorCode, (int)ex.ErrorCode, ex.ErrorLine, ex.ErrorOffset, ex.Mnemonics));
        //    }
        //    byte[] originalBytes = Memory.Reader.ReadBytes((IntPtr)start, byteCode.Length);
        //    Memory.Reader.WriteBytes(start, byteCode);

        //    if (parPatchName != "")
        //    {
        //        Hack parHack = new Hack(start,
        //            byteCode,
        //            originalBytes, parPatchName);
        //        HookWardenMemScan.AddHack(parHack);
        //    }
        //}

        //[Obfuscation(Feature = "virtualization", Exclude = false)]
        internal static IntPtr InjectAsm(string[] parInstructions, string parPatchName)
        {
            if (Asm == null)
            {
                Asm = new FasmNet();
            }

            Asm.Clear();
            Asm.AddLine("use32");
            foreach (var x in parInstructions)
            {
                Asm.AddLine(x);
            }

            var byteCode = new byte[0];

            try
            {
                byteCode = Asm.Assemble();
            }
            catch (FasmAssemblerException ex)
            {
                MessageBox.Show(
                    $"Error definition: {ex.ErrorCode}; Error code: {(int)ex.ErrorCode}; Error line: {ex.ErrorLine}; Error offset: {ex.ErrorOffset}; Mnemonics: {ex.Mnemonics}");
            }

            var start = Reader.Alloc(byteCode.Length);

            Asm.Clear();
            Asm.AddLine("use32");
            foreach (var x in parInstructions)
            {
                Asm.AddLine(x);
            }
            byteCode = Asm.Assemble(start);

            HookWardenMemScan.RemoveHack(start);
            HookWardenMemScan.RemoveHack(parPatchName);
            var originalBytes = Reader.ReadBytes(start, byteCode.Length);

            if (parPatchName != "")
            {
                var parHack = new Hack(start,
                                       byteCode,
                                       originalBytes, parPatchName);
                HookWardenMemScan.AddHack(parHack);
                Console.WriteLine($"Protecting {parHack.Name} from Warden at {parHack.Address.ToString("X")}");
                parHack.Apply();
            }
            else
            {
                Reader.WriteBytes(start, byteCode);
            }
            return(start);
        }
コード例 #2
0
ファイル: Fasm.NET.cs プロジェクト: JamesMenetrey/Sandbox
        public void ObjectClear()
        {
            // Arrange
            var fasm = new FasmNet();

            // Act
            fasm.AddLine("retn");
            fasm.Clear();
            fasm.AddLine("push eax");
            fasm.AddLine("pop {0}", "eax");
            fasm.InsertLine(0, "use32");
            var asm = fasm.Assemble();

            // Assert
            CollectionAssert.AreEqual(new byte[] { 0x50, 0x58 }, asm);
        }
コード例 #3
0
ファイル: Fasm.NET.cs プロジェクト: aash/Fasm.NET
        public void ObjectClear()
        {
            // Arrange
            var fasm = new FasmNet();

            // Act
            fasm.AddLine("retn");
            fasm.Clear();
            fasm.AddLine("push eax");
            fasm.AddLine("pop {0}", "eax");
            fasm.InsertLine(0, "use32");
            var asm = fasm.Assemble();

            // Assert
            CollectionAssert.AreEqual(new byte[] { 0x50, 0x58 }, asm);
        }