public void UShortFixup() { var bytes = new byte[] { 0x01, 0x02, 0x03 }; var img = new LoadedImage(Address.SegPtr(0x0C00, 0), bytes); ushort newSeg = img.FixupLeUInt16(1, 0x4444); Assert.AreEqual(0x4746, newSeg); }
public override RelocationResults Relocate(Program program, Address addrLoad) { ImageReader 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); imageMap.AddSegment(Address.SegPtr(seg, 0), seg.ToString("X4"), AccessMode.ReadWriteExecute, 0); } while (--cx != 0); } if (dx == 0xF000) { break; } dx += (ushort)0x1000U; } this.cs += segCode; imageMap.AddSegment(Address.SegPtr(cs, 0), cs.ToString("X4"), AccessMode.ReadWriteExecute, 0); 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 entryPoints = new List <EntryPoint> { new EntryPoint(Address.SegPtr(cs, ip), state) }; return(new RelocationResults(entryPoints, new RelocationDictionary(), new List <Address>())); }