Beispiel #1
0
        public void CanDisassemble()
        {
            var testData = new object[, ]
            {
                { new byte[] { 0xCC }, "INT3" },
                { new byte[] { 0x8B, 0xEC }, "MOV EBP,ESP" },
                { new byte[] { 0x83, 0xC4, 0x04 }, "ADD ESP,4" },
                { new byte[] { 0x90 }, "NOP" }
            };

            for (int i = 0; i < testData.GetLength(0); i++)
            {
                var shellCode   = (byte[])testData[i, 0];
                var instruction = (string)testData[i, 1];
                var actual      = DisasmWrapper.Disasm(shellCode);
                Assert.Equal(instruction, actual.Instruction);
                Assert.Equal(shellCode.Length, actual.Bytes.Length);
                for (int y = 0; y < shellCode.Length; y++)
                {
                    Assert.Equal(shellCode[y], actual.Bytes[y]);
                }
            }

            try
            {
                DisasmWrapper.Disasm(new byte[] { 0xF1, 0x00, 0x00 });
                Assert.True(false, "Should have thrown invalid x86 instruction");
            }
            catch (AssemblerException)
            {
            }
        }
Beispiel #2
0
        public static void CanAssemble()
        {
            var testData = new object[, ]
            {
                { new byte[] { 0xCC }, "INT3", false },
                { new byte[] { 0x8B, 0xEC }, "MOV EBP,ESP", true },
                { new byte[] { 0x83, 0xC4, 0x04 }, "ADD ESP,4", true },
                { new byte[] { 0x90 }, "NOP", false }
            };

            for (int i = 0; i < testData.GetLength(0); i++)
            {
                var shellCode           = (byte[])testData[i, 0];
                var instruction         = (string)testData[i, 1];
                var hasMultipleEncoding = (bool)testData[i, 2];
                var actual = DisasmWrapper.Assemble(instruction);
                Assert.Equal(instruction, actual.Instruction);


                //Some command have multiple encoding (http://www.ollydbg.de/srcdescr.htm#_Toc531975951)
                if (!hasMultipleEncoding)
                {
                    Assert.Equal(shellCode.Length, actual.Bytes.Length);
                    for (int y = 0; y < shellCode.Length; y++)
                    {
                        Assert.Equal(shellCode[y], actual.Bytes[y]);
                    }
                }
            }

            try
            {
                DisasmWrapper.Assemble("Hello");
                Assert.False(true, "Should have thrown on bad instruction");
            }
            catch (AssemblerException)
            {
            }
        }