示例#1
0
        public void SudWrite()
        {
            Project_v4 ud = new Project_v4
            {
                Inputs =
                {
                    new DecompilerInput_v4
                    {
                        DisassemblyFilename  = "foo.asm",
                        IntermediateFilename = "foo.cod",
                        User = new UserData_v4{
                            Procedures =
                            {
                                new Procedure_v1
                                {
                                    Name      = "foo",
                                    Signature = new SerializedSignature
                                    {
                                        ReturnValue = new Argument_v1
                                        {
                                            Kind = new Register_v1("eax")
                                        },
                                        Arguments = new Argument_v1[]
                                        {
                                            new Argument_v1
                                            {
                                                Kind = new StackVariable_v1(),
                                                Type = new PrimitiveType_v1(Domain.SignedInt, 4)
                                            },
                                            new Argument_v1
                                            {
                                                Kind = new StackVariable_v1(),
                                                Type = new PrimitiveType_v1(Domain.SignedInt, 4)
                                            }
                                        }
                                    }
                                }
                            },
                            LoadAddress = "0x1000:0x0",
                        }
                    }
                }
            };

            using (FileUnitTester fut = new FileUnitTester("Core/SudWrite.txt"))
            {
                var writer = new FilteringXmlWriter(fut.TextWriter);
                writer.Formatting = System.Xml.Formatting.Indented;
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v4(typeof(Project_v4));
                ser.Serialize(writer, ud);
                fut.AssertFilesEqual();
            }
        }
示例#2
0
        public void StWritePrimitive()
        {
            SerializedType st     = new PointerType_v1(new PrimitiveType_v1(Domain.SignedInt, 4));
            StringWriter   writer = new StringWriter();
            XmlSerializer  ser    = SerializedLibrary.CreateSerializer_v4(st.GetType());

            ser.Serialize(writer, st);
            string s = writer.ToString();
            int    b = s.IndexOf("<prim");
            int    e = s.IndexOf("/>");

            Assert.AreEqual("<prim domain=\"SignedInt\" size=\"4\" xmlns=\"http://schemata.jklnet.org/Decompiler\" ", s.Substring(b, e - b));
        }
示例#3
0
        private void When_SaveToTextWriter(Program program, TextWriter sw)
        {
            var saver = new ProjectSaver(sc);
            var sProj = new Project_v4
            {
                Inputs = { saver.VisitProgram("foo.exe", program) }
            };
            var writer = new FilteringXmlWriter(sw);

            writer.Formatting = System.Xml.Formatting.Indented;
            XmlSerializer ser = SerializedLibrary.CreateSerializer_v4(typeof(Project_v4));

            ser.Serialize(writer, sProj);
        }
示例#4
0
        public void SudSaveProject()
        {
            Given_Architecture();
            Given_TestOS_Platform();
            var eax       = new RegisterStorage("eax", 0, 0, PrimitiveType.Word32);
            var ecx       = new RegisterStorage("ecx", 1, 0, PrimitiveType.Word32);
            var jumpTable = new ImageMapVectorTable(
                Address.SegPtr(0x1000, 0x400),
                new Address[] {
                Address.SegPtr(0x1000, 0x500),
                Address.SegPtr(0x1000, 0x513),
                Address.SegPtr(0x1000, 0x5BA),
            }, 0);

            Project project = new Project
            {
                Programs =
                {
                    new Program
                    {
                        Architecture         = arch,
                        Platform             = platform,
                        SegmentMap           = new SegmentMap(Address.SegPtr(0x1000, 0)), //, new byte[100]),
                        DisassemblyFilename  = "foo.asm",
                        IntermediateFilename = "foo.cod",
                        User = new UserData
                        {
                            Loader     = "CustomLoader",
                            Procedures =
                            {
                                {
                                    Address.SegPtr(0x1000, 0x10),
                                    new Procedure_v1
                                    {
                                        Name      = "foo",
                                        Signature = new SerializedSignature
                                        {
                                            ReturnValue = new Argument_v1{
                                                Kind = new Register_v1("eax")
                                            },
                                            Arguments = new Argument_v1[]
                                            {
                                                new Argument_v1
                                                {
                                                    Kind = new StackVariable_v1(),
                                                    Type = new PrimitiveType_v1(Domain.SignedInt, 4)
                                                },
                                                new Argument_v1
                                                {
                                                    Kind = new StackVariable_v1(),
                                                    Type = new PrimitiveType_v1(Domain.SignedInt, 4)
                                                }
                                            }
                                        }
                                    }
                                }
                            },
                            Globals =
                            {
                                {
                                    Address.SegPtr(0x2000, 0),
                                    new GlobalDataItem_v2     {
                                        Address  = Address.SegPtr(0x2000, 0).ToString(),
                                        DataType = new StringType_v2{
                                            Termination = StringType_v2.ZeroTermination,
                                            CharType    = new PrimitiveType_v1 {
                                                Domain = Domain.Character, ByteSize = 1
                                            }
                                        }
                                    }
                                }
                            },
                            Calls =
                            {
                                {
                                    Address.SegPtr(0x1000, 0x0320),
                                    new UserCallData
                                    {
                                        Address  = Address.SegPtr(0x1000, 0x0320),
                                        NoReturn = true,
                                    }
                                }
                            },
                            RegisterValues =
                            {
                                {
                                    Address.Ptr32(0x012310),
                                    new List <UserRegisterValue>
                                    {
                                        new UserRegisterValue {
                                            Register = eax, Value = Constant.Word32(0x01231)
                                        },
                                        new UserRegisterValue {
                                            Register = ecx, Value = Constant.Word32(0x42424711)
                                        },
                                    }
                                }
                            },
                            IndirectJumps =
                            {
                                {
                                    Address.SegPtr(0x1000, 0x380),
                                    new UserIndirectJump      {
                                        Address       = jumpTable.Address,
                                        Table         = jumpTable,
                                        IndexRegister = new RegisterStorage("R1", 1, 0, PrimitiveType.Word32)
                                    }
                                }
                            },
                            JumpTables =
                            {
                                { jumpTable.Address, jumpTable }
                            }
                        }
                    }
                }
            };

            mr.ReplayAll();

            using (FileUnitTester fut = new FileUnitTester("Core/SudSaveProject.txt"))
            {
                FilteringXmlWriter writer = new FilteringXmlWriter(fut.TextWriter);
                writer.Formatting = System.Xml.Formatting.Indented;
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v4(typeof(Project_v4));
                Project_v4    ud  = new ProjectSaver(sc).Serialize("/var/foo/foo.proj", project);
                ser.Serialize(writer, ud);
                fut.AssertFilesEqual();
            }
        }
示例#5
0
        public void SudSaveProject()
        {
            Given_Architecture();
            Given_TestOS_Platform();
            Project project = new Project
            {
                Programs =
                {
                    new Program
                    {
                        Architecture         = arch,
                        Platform             = platform,
                        ImageMap             = new ImageMap(Address.SegPtr(0x1000, 0)), //, new byte[100]),
                        DisassemblyFilename  = "foo.asm",
                        IntermediateFilename = "foo.cod",
                        User = new UserData
                        {
                            Procedures =
                            {
                                {
                                    Address.SegPtr(0x1000, 0x10),
                                    new Procedure_v1
                                    {
                                        Name      = "foo",
                                        Signature = new SerializedSignature
                                        {
                                            ReturnValue = new Argument_v1{
                                                Kind = new Register_v1("eax")
                                            },
                                            Arguments = new Argument_v1[]
                                            {
                                                new Argument_v1
                                                {
                                                    Kind = new StackVariable_v1(),
                                                    Type = new PrimitiveType_v1(Domain.SignedInt, 4)
                                                },
                                                new Argument_v1
                                                {
                                                    Kind = new StackVariable_v1(),
                                                    Type = new PrimitiveType_v1(Domain.SignedInt, 4)
                                                }
                                            }
                                        }
                                    }
                                }
                            },
                            Globals =
                            {
                                {
                                    Address.SegPtr(0x2000, 0),
                                    new GlobalDataItem_v2 {
                                        Address  = Address.SegPtr(0x2000, 0).ToString(),
                                        DataType = new StringType_v2{
                                            Termination = StringType_v2.ZeroTermination,
                                            CharType    = new PrimitiveType_v1 {
                                                Domain = Domain.Character, ByteSize = 1
                                            }
                                        }
                                    }
                                }
                            },
                            Calls =
                            {
                                {
                                    Address.SegPtr(0x1000, 0x0320),
                                    new UserCallData
                                    {
                                        Address  = Address.SegPtr(0x1000, 0x0320),
                                        NoReturn = true,
                                    }
                                }
                            }
                        }
                    }
                }
            };

            mr.ReplayAll();

            using (FileUnitTester fut = new FileUnitTester("Core/SudSaveProject.txt"))
            {
                FilteringXmlWriter writer = new FilteringXmlWriter(fut.TextWriter);
                writer.Formatting = System.Xml.Formatting.Indented;
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v4(typeof(Project_v4));
                Project_v4    ud  = new ProjectSaver(sc).Save("/var/foo/foo.proj", project);
                ser.Serialize(writer, ud);
                fut.AssertFilesEqual();
            }
        }