예제 #1
0
        private void EmitUnitTest()
        {
            if (seen.Contains(dasm.Current.Opcode))
            {
                return;
            }
            seen.Add(dasm.Current.Opcode);

            var r2 = rdr.Clone();

            r2.Offset -= dasm.Current.Length;
            var bytes = r2.ReadBytes(dasm.Current.Length);

            Debug.WriteLine("        [Test]");
            Debug.WriteLine("        public void VaxRw_" + dasm.Current.Opcode + "()");
            Debug.WriteLine("        {");
            Debug.Write("            BuildTest(");
            Debug.Write(string.Join(
                            ", ",
                            bytes.Select(b => string.Format("0x{0:X2}", (int)b))));
            Debug.WriteLine(");\t// " + dasm.Current.ToString());
            Debug.WriteLine("            AssertCode(");
            Debug.WriteLine("                \"0|L--|00100000(2): 1 instructions\",");
            Debug.WriteLine("                \"1|L--|@@@\");");
            Debug.WriteLine("        }");
            Debug.WriteLine("");
        }
예제 #2
0
        public CodeFormatter VisitArray(ArrayType at)
        {
            Debug.Assert(at.Length != 0, "Expected sizes of arrays to have been determined by now");
            var fmt = codeFormatter.InnerFormatter;

            fmt.Terminate();
            fmt.Indent();
            fmt.Write("{");
            fmt.Terminate();
            fmt.Indentation += fmt.TabSize;

            for (int i = 0; i < at.Length; ++i)
            {
                var r = rdr.Clone();
                fmt.Indent();
                at.ElementType.Accept(this);
                fmt.Terminate(",");
                r.Offset += (uint)at.ElementType.Size;
                rdr       = r;
            }

            fmt.Indentation -= fmt.TabSize;
            fmt.Indent();
            fmt.Write("}");
            return(codeFormatter);
        }
예제 #3
0
        string ReadByteLengthString(ImageReader rdr, int offset)
        {
            var clone = rdr.Clone();

            clone.Offset = (ulong)((long)clone.Offset + offset);
            var len   = clone.ReadByte();
            var abStr = clone.ReadBytes(len);

            return(Encoding.ASCII.GetString(abStr));
        }
예제 #4
0
파일: MachOLoader.cs 프로젝트: xor2003/reko
            public SegmentMap ParseLoadCommands(uint ncmds, Address addrLoad)
            {
                var imageMap = new SegmentMap(addrLoad);

                Debug.Print("Parsing load commands, {0} of them.", ncmds);

                var lookup = GetType()
                             .GetFields(
                    BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
                             .Where(fi => fi.IsLiteral && !fi.IsInitOnly && fi.Name.StartsWith("LC_"))
                             .ToDictionary(fi => (uint)fi.GetValue(null), fi => fi.Name);

                for (uint i = 0; i < ncmds; ++i)
                {
                    var  pos = rdr.Offset;
                    uint cmd;
                    uint cmdsize;
                    if (!rdr.TryReadUInt32(out cmd) ||
                        !rdr.TryReadUInt32(out cmdsize))
                    {
                        throw new BadImageFormatException(string.Format(
                                                              "Unable to read Mach-O command ({0:X}).",
                                                              rdr.Offset));
                    }
                    Debug.Print("{0,3}: Read load command 0x{1:X} {2} of size {3}.", i, cmd, lookup.ContainsKey(cmd) ? lookup[cmd] : "", cmdsize);

                    switch (cmd & ~LC_REQ_DYLD)
                    {
                    //case LC_SEGMENT:
                    //    parseSegmentCommand<segment_command, section>();
                    //    break;
                    case LC_SEGMENT_64:
                        parseSegmentCommand64(imageMap);
                        break;

                    //case LC_SYMTAB:
                    //    parseSymtabCommand<Mach>();
                    //    break;
                    case LC_FUNCTION_STARTS:
                        parseFunctionStarts(rdr.Clone());
                        break;
                    }
                    rdr.Offset = pos + cmdsize;
                }
                return(imageMap);
            }
예제 #5
0
 public override IEnumerable <RtlInstructionCluster> CreateRewriter(ImageReader rdr, ProcessorState state, Frame frame, IRewriterHost host)
 {
     return(new Rewriter(this, rdr.Clone(), state, frame, host));
 }
예제 #6
0
 public override IEnumerable <MachineInstruction> CreateDisassembler(ImageReader imageReader)
 {
     return(new Disassembler(imageReader.Clone()));
 }