public void SlibCodeRead()
        {
            var src = @"<?xml version=""1.0"" encoding=""utf-16""?>
<project xmlns=""http://schemata.jklnet.org/Reko/v5"">
  <input>
    <user>
      <global>
        <Address>00100000</Address>
        <arr length=""10"">
          <ptr size=""4"">
            <code />
          </ptr>
        </arr>
        <Name>foo</Name>
      </global>
      <extractResources>false</extractResources>
    </user>
  </input>
</project>";

            var ser  = SerializedLibrary.CreateSerializer_v5(typeof(Project_v5));
            var sr   = new StringReader(src);
            var rdr  = new XmlTextReader(sr);
            var proj = (Project_v5)ser.Deserialize(rdr);

            Assert.AreEqual(1, proj.InputFiles.Count);
            var input = (DecompilerInput_v5)proj.InputFiles[0];

            Assert.AreEqual(1, input.User.GlobalData.Count);
            Assert.AreEqual("arr(ptr(code),10)", input.User.GlobalData[0].DataType.ToString());
        }
        public void SlibCodeWrite()
        {
            var proj = new Project_v5
            {
                InputFiles =
                {
                    new DecompilerInput_v5 {
                        User = new UserData_v4
                        {
                            GlobalData =
                            {
                                new GlobalDataItem_v2
                                {
                                    Address  = "00100000",
                                    Name     = "foo",
                                    DataType = new ArrayType_v1{
                                        ElementType = new PointerType_v1{
                                            PointerSize = 4,
                                            DataType    = new CodeType_v1()
                                        },
                                        Length = 10,
                                    }
                                }
                            }
                        }
                    }
                }
            };
            var ser    = SerializedLibrary.CreateSerializer_v5(typeof(Project_v5));
            var sw     = new StringWriter();
            var writer = new FilteringXmlWriter(sw);

            writer.Formatting = Formatting.Indented;
            ser.Serialize(writer, proj);

            Debug.Print(sw.ToString());
            var sExp = @"<?xml version=""1.0"" encoding=""utf-16""?>
<project xmlns=""http://schemata.jklnet.org/Reko/v5"">
  <input>
    <user>
      <global>
        <Address>00100000</Address>
        <arr length=""10"">
          <ptr size=""4"">
            <code />
          </ptr>
        </arr>
        <Name>foo</Name>
      </global>
      <extractResources>false</extractResources>
    </user>
  </input>
</project>";

            Assert.AreEqual(sExp, sw.ToString());
        }
 private void Verify(SerializedSignature ssig, string outputFilename)
 {
     using (FileUnitTester fut = new FileUnitTester(outputFilename))
     {
         XmlTextWriter x = new FilteringXmlWriter(fut.TextWriter);
         x.Formatting = Formatting.Indented;
         XmlSerializer ser = SerializedLibrary.CreateSerializer_v5(ssig.GetType());
         ser.Serialize(x, ssig);
         fut.AssertFilesEqual();
     }
 }
 private void When_SaveToTextWriter(Program program, TextWriter sw)
 {
     var saver = new ProjectSaver(sc);
     var sProj = new Project_v5
     {
         Inputs = { saver.VisitProgram("foo.exe", program) }
     };
     var writer = new FilteringXmlWriter(sw);
     writer.Formatting = System.Xml.Formatting.Indented;
     XmlSerializer ser = SerializedLibrary.CreateSerializer_v5(typeof(Project_v5));
     ser.Serialize(writer, sProj);
 }
Beispiel #5
0
        public void SudSaveScripts()
        {
            var project = new Project
            {
                ScriptFiles =
                {
                    new Mock <ScriptFile>(
                        null, "/var/foo/script.fake", new byte[100]).Object
                },
            };
            var sw     = new StringWriter();
            var writer = new FilteringXmlWriter(sw)
            {
                Formatting = System.Xml.Formatting.Indented
            };
            var ser = SerializedLibrary.CreateSerializer_v5(
                typeof(Project_v5));

            var saver    = new ProjectSaver(sc);
            var sProject = saver.Serialize("/var/foo/foo.proj", project);

            ser.Serialize(writer, sProject);

            var expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<project xmlns=""http://schemata.jklnet.org/Reko/v5"">
  <script>
    <filename>script.fake</filename>
  </script>
</project>";

            if (sw.ToString() != expected)
            {
                Console.WriteLine("{0}", sw.ToString());
            }
            Assert.AreEqual(expected, sw.ToString());
        }
Beispiel #6
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.Object,
                        Platform             = platform.Object,
                        SegmentMap           = new SegmentMap(Address.SegPtr(0x1000, 0)), //, new byte[100]),
                        DisassemblyDirectory = "",
                        User = new UserData
                        {
                            Loader           = "CustomLoader",
                            ExtractResources = true,
                            Procedures       =
                            {
                                {
                                    Address.SegPtr(0x1000, 0x10),
                                    new UserProcedure(Address.SegPtr(0x1000, 0x10), "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 UserGlobal(Address.SegPtr(0x2000, 0), "g_20000", 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(eax, Constant.Word32(0x01231)),
                                        new UserRegisterValue(ecx, 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 }
                            },
                            OutputFilePolicy = Program.SegmentFilePolicy,
                        }
                    }
                }
            };

            using (FileUnitTester fut = new FileUnitTester("Core/SudSaveProject.txt"))
            {
                FilteringXmlWriter writer = new FilteringXmlWriter(fut.TextWriter);
                writer.Formatting = System.Xml.Formatting.Indented;
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v5(typeof(Project_v5));
                Project_v5    ud  = new ProjectSaver(sc).Serialize("/var/foo/foo.proj", project);
                ser.Serialize(writer, ud);
                fut.AssertFilesEqual();
            }
        }
Beispiel #7
0
        public void SudWrite()
        {
            Project_v5 ud = new Project_v5
            {
                InputFiles =
                {
                    new DecompilerInput_v5
                    {
                        DisassemblyDirectory = "",
                        User = new UserData_v4      {
                            ExtractResources = true,
                            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   = "1000:0000",
                            IndirectJumps =
                            {
                                new IndirectJump_v4 {
                                    InstructionAddress = "1000:0220",
                                    TableAddress       = "1000:0228"
                                },
                            },
                            JumpTables =
                            {
                                new JumpTable_v4
                                {
                                    TableAddress = "1000:0228",
                                    Destinations = new string[]
                                    {
                                        "1000:0230",
                                        "1000:0244",
                                        "1000:033F",
                                    }
                                }
                            }
                        }
                    }
                }
            };

            using (FileUnitTester fut = new FileUnitTester("Core/SudWrite.txt"))
            {
                var writer = new FilteringXmlWriter(fut.TextWriter);
                writer.Formatting = System.Xml.Formatting.Indented;
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v5(typeof(Project_v5));
                ser.Serialize(writer, ud);
                fut.AssertFilesEqual();
            }
        }