コード例 #1
0
        public void UShortFixup()
        {
            var    bytes  = new byte[] { 0x01, 0x02, 0x03 };
            var    img    = new MemoryArea(Address.SegPtr(0x0C00, 0), bytes);
            ushort newSeg = img.FixupLeUInt16(1, 0x4444);

            Assert.AreEqual(0x4746, newSeg);
        }
コード例 #2
0
ファイル: ExePackLoader.cs プロジェクト: smx-smx/reko
        public override RelocationResults Relocate(Program program, Address addrLoad)
        {
            EndianImageReader rdr     = new LeImageReader(RawImage, hdrOffset + relocationsOffset);
            ushort            segCode = (ushort)(addrLoad.Selector.Value + (ExeImageLoader.CbPsp >> 4));
            ushort            dx      = 0;

            for (; ;)
            {
                int cx = rdr.ReadLeUInt16();
                if (cx != 0)
                {
                    uint relocBase = ExeImageLoader.CbPsp + dx * 0x10u;
                    do
                    {
                        ushort relocOff = rdr.ReadLeUInt16();
                        ushort seg      = imgU.FixupLeUInt16(relocBase + relocOff, segCode);
                        var    segment  = segmentMap.AddSegment(new ImageSegment(
                                                                    seg.ToString("X4"),
                                                                    Address.SegPtr(seg, 0),
                                                                    imgU,
                                                                    AccessMode.ReadWriteExecute));
                    } while (--cx != 0);
                }
                if (dx == 0xF000)
                {
                    break;
                }
                dx += (ushort)0x1000U;
            }

            this.cs += segCode;
            segmentMap.AddOverlappingSegment(cs.ToString("X4"), imgU, Address.SegPtr(cs, 0), AccessMode.ReadWriteExecute);
            this.ss += segCode;
            var state = arch.CreateProcessorState();

            state.SetRegister(Registers.ds, Constant.Word16(addrLoad.Selector.Value));
            state.SetRegister(Registers.es, Constant.Word16(addrLoad.Selector.Value));
            state.SetRegister(Registers.cs, Constant.Word16(cs));
            state.SetRegister(Registers.ss, Constant.Word16(ss));
            state.SetRegister(Registers.bx, Constant.Word16(0));
            var ep = new ImageSymbol(Address.SegPtr(cs, ip))
            {
                ProcessorState = state
            };
            var entryPoints = new List <ImageSymbol> {
                ep
            };
            var imageSymbols = entryPoints.ToSortedList(e => e.Address, e => e);

            return(new RelocationResults(entryPoints, imageSymbols));
        }