Exemple #1
0
        private void Verify(Argument_v1 sarg, string outputFilename)
        {
            using (FileUnitTester fut = new FileUnitTester(outputFilename))
            {
                XmlTextWriter x = new FilteringXmlWriter(fut.TextWriter);
                x.Formatting = Formatting.Indented;
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(sarg.GetType());
                ser.Serialize(x, sarg);

                fut.AssertFilesEqual();
            }
        }
        private void Verify(SerializedLibrary slib, string outputFile)
        {
            using (FileUnitTester fut = new FileUnitTester(outputFile))
            {
                XmlTextWriter writer = new FilteringXmlWriter(fut.TextWriter);
                writer.Formatting = Formatting.Indented;
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(slib.GetType());
                ser.Serialize(writer, slib);

                fut.AssertFilesEqual();
            }
        }
        public void SserSerialize()
        {
            StringWriter  sw  = new StringWriter();
            XmlTextWriter xml = new XmlTextWriter(sw);
            XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(svc.GetType());

            ser.Serialize(xml, svc);
            string s = sw.ToString();
            int    i = s.IndexOf("<syscallin");

            s = s.Substring(i, s.IndexOf("</syscalli") - i);
            Assert.AreEqual("<syscallinfo><vector>21</vector><regvalue reg=\"ah\">44</regvalue><regvalue reg=\"al\">00</regvalue>", s);
        }
Exemple #4
0
        public void StWritePrimitive()
        {
            SerializedType st     = new PointerType_v1(new PrimitiveType_v1(Domain.SignedInt, 4));
            StringWriter   writer = new StringWriter();
            XmlSerializer  ser    = SerializedLibrary.CreateSerializer_v1(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));
        }
        public void SsigReadAxBxCl()
        {
            SerializedSignature ssig;

            using (FileStream stm = new FileStream(FileUnitTester.MapTestPath("Core/AxBxCl.xml"), FileMode.Open))
            {
                XmlTextReader rdr = new XmlTextReader(stm);
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(typeof(SerializedSignature));
                ssig = (SerializedSignature)ser.Deserialize(rdr);
            }
            Given_X86ProcedureSerializer();
            Assert.AreEqual("Register word16 AxBxCl(Register word16 bx, Register byte cl)", sser.Deserialize(ssig, arch.CreateFrame()).ToString("AxBxCl"));
        }
Exemple #6
0
        //$REVIEW: consider removing this unit test. It sole function is counting the
        // number of reconstituted function. This changes each time msvcrt.xml is modified,
        // and provides no value.
        public void SlibReadMsvcrtXml()
        {
            XmlSerializer     ser = SerializedLibrary.CreateSerializer_v1(typeof(SerializedLibrary));
            SerializedLibrary lib;

            using (Stream stm = fsSvc.CreateFileStream(
                       FileUnitTester.MapTestPath("../Environments/Windows/msvcrt.xml"),
                       FileMode.Open,
                       FileAccess.Read))
            {
                lib = (SerializedLibrary)ser.Deserialize(stm);
            }
            Assert.AreEqual(68, lib.Procedures.Count);
        }
Exemple #7
0
        public void SudRead_v1()
        {
            Project_v1 proj = null;

            using (FileStream stm = new FileStream(FileUnitTester.MapTestPath("Core/SudRead.xml"), FileMode.Open))
            {
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(typeof(Project_v1));
                proj = (Project_v1)ser.Deserialize(stm);
            }
            Assert.AreEqual("10003330", proj.Input.Address);
            Assert.AreEqual(2, proj.UserProcedures.Count);
            Procedure_v1 proc = (Procedure_v1)proj.UserProcedures[0];

            Assert.IsNull(proc.Signature.ReturnValue);
        }
Exemple #8
0
        public void SlibReadOneProcedure()
        {
            XmlSerializer     ser = SerializedLibrary.CreateSerializer_v1(typeof(SerializedLibrary));
            SerializedLibrary lib;

            using (Stream stm = fsSvc.CreateFileStream(FileUnitTester.MapTestPath("Core/SlibOneProcedure.xml"), FileMode.Open))
            {
                lib = (SerializedLibrary)ser.Deserialize(stm);
            }
            Assert.AreEqual(1, lib.Procedures.Count);
            Procedure_v1 proc = (Procedure_v1)lib.Procedures[0];

            Assert.AreEqual("malloc", proc.Name);
            Assert.AreEqual(1, proc.Signature.Arguments.Length);
            Assert.AreEqual("int", proc.Signature.Arguments[0].Type.ToString());
        }
Exemple #9
0
        public void ProcChar_DeserializeArraySize()
        {
            string x = "<?xml version=\"1.0\" encoding=\"utf-16\"?>" +
                       "<ProcedureCharacteristics>" +
                       "  <array-size argument=\"0\">" +
                       "    <factor argument=\"1\"/>" +
                       "    <factor constant=\"30\"/>" +
                       "  </array-size>" +
                       "</ProcedureCharacteristics>";
            XmlSerializer            ser  = SerializedLibrary.CreateSerializer_v1(typeof(ProcedureCharacteristics));
            ProcedureCharacteristics pc   = (ProcedureCharacteristics)ser.Deserialize(new StringReader(x));
            ArraySizeCharacteristic  arrs = pc.ArraySize;

            Assert.IsNotNull(arrs, "Should have deserialized an array size.");
            Assert.IsNotNull(arrs.Argument, "Array size is useless without an argument to refer to.");
            Assert.AreEqual(2, arrs.Factors.Length);
            Assert.AreEqual("1", arrs.Factors[0].Argument);
            Assert.AreEqual("30", arrs.Factors[1].Constant);
        }
Exemple #10
0
        public void SudWrite()
        {
            Project_v1 ud = new Project_v1();

            ud.Input.Address = "0x1000:0x0";
            ud.Output.DisassemblyFilename  = "foo.asm";
            ud.Output.IntermediateFilename = "foo.cod";
            Procedure_v1 proc = new Procedure_v1();

            proc.Name      = "foo";
            proc.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)
                    }
                }
            };
            ud.UserProcedures.Add(proc);

            using (FileUnitTester fut = new FileUnitTester("Core/SudWrite.txt"))
            {
                var writer = new FilteringXmlWriter(fut.TextWriter);
                writer.Formatting = System.Xml.Formatting.Indented;
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(typeof(Project_v1));
                ser.Serialize(writer, ud);
                fut.AssertFilesEqual();
            }
        }
        public void SseqCreate()
        {
            Identifier         head = new Identifier(Registers.dx.Name, Registers.dx.DataType, Registers.dx);
            Identifier         tail = new Identifier(Registers.ax.Name, Registers.ax.DataType, Registers.ax);
            Identifier         seq  = new Identifier("dx_ax", PrimitiveType.Word32, new SequenceStorage(head.Storage, tail.Storage, PrimitiveType.Word32));
            SerializedSequence sq   = new SerializedSequence((SequenceStorage)seq.Storage);

            Assert.AreEqual("dx", sq.Registers[0].Name);
            Assert.AreEqual("ax", sq.Registers[1].Name);

            XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(sq.GetType());
            StringWriter  sw  = new StringWriter();
            XmlTextWriter xml = new XmlTextWriter(sw);

            xml.Formatting = Formatting.None;
            ser.Serialize(xml, sq);
            string s = sw.ToString();
            int    i = s.IndexOf("<reg");

            Assert.AreEqual("<reg>dx</reg><reg>ax</reg>", s.Substring(i, s.IndexOf("</Se") - i));
        }
Exemple #12
0
        public void SlibReadRealModeIntServices_v1()
        {
            var ser = SerializedLibrary.CreateSerializer_v1(typeof(SerializedLibrary));
            SerializedLibrary lib;
            var contents =
                @"<?xml version=""1.0"" encoding=""utf-16"" ?>
<library xmlns=""http://schemata.jklnet.org/Decompiler"">
  <service name=""msdos_rename_file"">
    <syscallinfo>
      <vector>21</vector>
      <regvalue reg=""ah"">56</regvalue>
    </syscallinfo>
    <signature>
      <return>
        <flag>C</flag>
      </return>
      <arg name=""oldName""><seq><reg>ds</reg><reg>dx</reg></seq></arg>
      <arg name=""newName""><seq><reg>es</reg><reg>di</reg></seq></arg>
      <arg name=""errorCode"" out=""true""><reg>ax</reg></arg>
    </signature>
  </service>
</library>
";

            lib = (SerializedLibrary)ser.Deserialize(new StringReader(contents));
            Assert.AreEqual(1, lib.Procedures.Count);
            var svc = (SerializedService)lib.Procedures[0];

            Assert.AreEqual("msdos_rename_file", svc.Name);
            Assert.AreEqual("21", svc.SyscallInfo.Vector);
            Assert.AreEqual("ah", svc.SyscallInfo.RegisterValues[0].Register);
            Assert.AreEqual("56", svc.SyscallInfo.RegisterValues[0].Value);
            Assert.AreEqual("arg()", svc.Signature.ReturnValue.ToString());
            Assert.AreEqual(3, svc.Signature.Arguments.Length);
            Assert.AreEqual("arg(oldName,)", svc.Signature.Arguments[0].ToString());
            Assert.AreEqual("arg(newName,)", svc.Signature.Arguments[1].ToString());
            Assert.AreEqual("arg(errorCode,)", svc.Signature.Arguments[2].ToString());
        }