示例#1
0
        public SymbolicMemoryOperand(MemoryOperand opr, SymbolicTarget target)
        {
            base.Base         = opr.Base;
            base.Displacement = opr.Displacement;
            base.Index        = opr.Index;
            base.Scaling      = opr.Scaling;
            base.Segment      = opr.Segment;
            base.Size         = opr.Size;

            this.Target = target;
        }
        protected override Address ResolveFlowInstructionTarget(PointerOperand operand)
        {
            SymbolicTarget symbolicTarget = operand.Tag as SymbolicTarget;

            if (symbolicTarget != null)
            {
                Address symbolicAddress = ResolveSymbolicTarget(symbolicTarget);
                return(symbolicAddress);
            }
            return(base.ResolveFlowInstructionTarget(operand));
        }
        private Address ResolveSymbolicTarget(SymbolicTarget symbolicTarget)
        {
            Address referentAddress = symbolicTarget.Referent.Resolve();

            if (referentAddress == Address.Invalid)
            {
                //AddError(start, ErrorCode.UnresolvedTarget,
                //    "Cannot resolve target: {0}.", symbolicTarget);
                return(Address.Invalid);
            }
            Address symbolicAddress = referentAddress + (int)symbolicTarget.Displacement;

            return(symbolicAddress);
        }
        protected override Address ResolveFlowInstructionTarget(RelativeOperand operand)
        {
            SymbolicTarget symbolicTarget = operand.Tag as SymbolicTarget;

            if (symbolicTarget != null)
            {
                Address symbolicAddress = ResolveSymbolicTarget(symbolicTarget);
                if (symbolicAddress != Address.Invalid)
                {
                    Address target = symbolicAddress + operand.Offset.Value;
                    return(new Address(target.Segment, (UInt16)target.Offset));
                }
                return(Address.Invalid);
            }
            return(base.ResolveFlowInstructionTarget(operand));
        }
示例#5
0
 public SymbolicPointerOperand(SymbolicTarget target)
 {
     this.Target = target;
 }
示例#6
0
 public SymbolicImmediateOperand(ImmediateOperand opr, SymbolicTarget target)
     : base(opr.Immediate, opr.Size)
 {
     this.Target = target;
 }
示例#7
0
 public SymbolicRelativeOperand(SymbolicTarget target)
 {
     this.Target = target;
 }
示例#8
0
        public SymbolicMemoryOperand(MemoryOperand opr, SymbolicTarget target)
        {
            base.Base = opr.Base;
            base.Displacement = opr.Displacement;
            base.Index = opr.Index;
            base.Scaling = opr.Scaling;
            base.Segment = opr.Segment;
            base.Size = opr.Size;

            this.Target = target;
        }
        private void UpdateImage(ObjectModule module)
        {
            #if false
            // For each segment, construct a list of LEDATA/LIDATA records.
            // These records fill data into the segment.
            // It is required that the data do not overlap, and do not
            // exceed segment boundary (here we only support 16-bit segments,
            // whose maximum size is 64KB).

            // Find the first CODE segment.
            LogicalSegment codeSegment = null;
            foreach (var seg in module.Segments)
            {
                if (seg.Class == "CODE")
                {
                    codeSegment = seg;
                    break;
                }
            }
            if (codeSegment == null)
                return;

            // Create a BinaryImage with the code.
            BinaryImage image = new BinaryImage(codeSegment.Image.Data, new Pointer(0, 0));

            // Disassemble the instructions literally. Note that this should
            // be improved, but we don't do that yet.
            var addr = image.BaseAddress;
            for (var i = image.StartAddress; i < image.EndAddress; )
            {
                var instruction = image.DecodeInstruction(addr);

                // An operand may have zero or one component that may be
                // fixed up. Check this.
            #if false
                for (int k = 0; k < instruction.Operands.Length; k++)
                {
                    var operand = instruction.Operands[k];
                    if (operand is RelativeOperand)
                    {
                        var opr = (RelativeOperand)operand;
                        var loc = opr.Offset.Location;
                        int j = i - image.StartAddress + loc.StartOffset;
                        int fixupIndex = codeSegment.DataFixups[j];
                        if (fixupIndex != 0)
                        {
                            FixupDefinition fixup = codeSegment.Fixups[fixupIndex - 1];
                            if (fixup.DataOffset != j)
                                continue;

                            var target = new SymbolicTarget(fixup, module);
                            instruction.Operands[k] = new SymbolicRelativeOperand(target);
                            System.Diagnostics.Debug.WriteLine(instruction.ToString());
                        }
                    }
                }
            #endif

                image.CreatePiece(addr, addr + instruction.EncodedLength, ByteType.Code);
                image[addr].Instruction = instruction;
                addr = addr.Increment(instruction.EncodedLength);

                // TODO: we need to check more accurately.

            #if false
                // Check if any bytes covered by this instruction has a fixup
                // record associated with it. Note that an instruction might
                // have multiple fixup records associated with it, such as
                // in a far call.
                for (int j = 0; j < instruction.EncodedLength; j++)
                {
                    int fixupIndex = codeSegment.DataFixups[i - image.StartAddress + j];
                    if (fixupIndex != 0)
                    {
                        FixupDefinition fixup = codeSegment.Fixups[fixupIndex - 1];
                        if (fixup.DataOffset != i - image.StartAddress + j)
                            continue;

                        if (fixup.Target.Method == FixupTargetSpecFormat.ExternalPlusDisplacement ||
                            fixup.Target.Method == FixupTargetSpecFormat.ExternalWithoutDisplacement)
                        {
                            var extIndex = fixup.Target.IndexOrFrame;
                            var extName = module.ExternalNames[extIndex - 1];
                            var disp = fixup.Target.Displacement;

                            System.Diagnostics.Debug.WriteLine(string.Format(
                                "{0} refers to {1}+{2} : {3}",
                                instruction, extName, disp, fixup.Location));
                        }
                    }
                }
            #endif

                i += instruction.EncodedLength;
            }
            // ...

            // Display the code in our disassmbly window.
            if (this.ListingWindow != null)
            {
                Document doc = new Document();
                doc.Image = image;
                this.ListingWindow.Document = doc;
            }
            #endif
        }
 private Address ResolveSymbolicTarget(SymbolicTarget symbolicTarget)
 {
     Address referentAddress = symbolicTarget.Referent.Resolve();
     if (referentAddress == Address.Invalid)
     {
         //AddError(start, ErrorCode.UnresolvedTarget,
         //    "Cannot resolve target: {0}.", symbolicTarget);
         return Address.Invalid;
     }
     Address symbolicAddress = referentAddress + (int)symbolicTarget.Displacement;
     return symbolicAddress;
 }
示例#11
0
 public SymbolicPointerOperand(SymbolicTarget target)
 {
     this.Target = target;
 }
示例#12
0
 public SymbolicImmediateOperand(ImmediateOperand opr, SymbolicTarget target)
     : base(opr.Immediate, opr.Size)
 {
     this.Target = target;
 }
示例#13
0
        public SymbolicRelativeOperand(SymbolicTarget target)

        {
            this.Target = target;
        }