Ejemplo n.º 1
0
        public override RelocationResults Relocate(Program program, Address addrLoad)
		{
			ImageMap imageMap = imgLoadedMap;
			ImageReader rdr = new LeImageReader(exe.RawImage, (uint) exe.e_lfaRelocations);
            var relocations = new RelocationDictionary();
			int i = exe.e_cRelocations;
			while (i != 0)
			{
				uint offset = rdr.ReadLeUInt16();
				ushort segOffset = rdr.ReadLeUInt16();
				offset += segOffset * 0x0010u;

				ushort seg = (ushort) (imgLoaded.ReadLeUInt16(offset) + addrLoad.Selector.Value);
				imgLoaded.WriteLeUInt16(offset, seg);
				relocations.AddSegmentReference(offset, seg);

				imageMap.AddSegment(Address.SegPtr(seg, 0), seg.ToString("X4"), AccessMode.ReadWriteExecute, 0);
				--i;
			}
		
			// Found the start address.

			Address addrStart = Address.SegPtr((ushort)(exe.e_cs + addrLoad.Selector.Value), exe.e_ip);
			imageMap.AddSegment(
                Address.SegPtr(addrStart.Selector.Value, 0),
                addrStart.Selector.Value.ToString("X4"),
                AccessMode.ReadWriteExecute, 0);
            return new RelocationResults(
                new List<EntryPoint> { new EntryPoint(addrStart, arch.CreateProcessorState()) },
                relocations,
                new List<Address>());
		}
Ejemplo n.º 2
0
 public void AddSegmentRelocation()
 {
     RelocationDictionary rd = new RelocationDictionary();
     rd.AddSegmentReference(0xD234, 0x0C00);
     Assert.AreEqual(1, rd.Count);
     Constant c = rd[0xD234];
     Assert.AreEqual("selector", c.DataType.ToString());
 }
Ejemplo n.º 3
0
        public override RelocationResults Relocate(Program program, Address addrLoad)
		{
            var relocations = new RelocationDictionary();
			ushort segCode = (ushort) (addrLoad.Selector.Value + (PspSize >> 4));
			for (;;)
			{
				int relocs = (ushort) bitStm.GetByte();
				if (relocs == 0)
					break;

				uint relocBase = PspSize + bitStm.GetWord() * 0x10u;
				do
				{
					ushort relocOff = bitStm.GetWord();
					ushort seg = imgU.ReadLeUInt16(relocBase + relocOff);
					seg = (ushort) (seg + segCode);

					imgU.WriteLeUInt16(relocBase + relocOff, seg);
					relocations.AddSegmentReference(relocBase + relocOff, seg);
					imageMap.AddSegment(Address.SegPtr(seg, 0), seg.ToString("X4"), AccessMode.ReadWriteExecute,0);
				} while (--relocs != 0);
			}

			ushort pklSs = (ushort) (bitStm.GetWord() + segCode);
			ushort pklSp = (ushort) bitStm.GetWord();
			pklCs = (ushort) (bitStm.GetWord() + segCode);
			pklIp = bitStm.GetWord();

			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(pklCs));
			state.SetRegister(Registers.ax, Constant.Word16(0));
			state.SetRegister(Registers.bx, Constant.Word16(0));
			state.SetRegister(Registers.cx, Constant.Word16(0));
			state.SetRegister(Registers.dx, Constant.Word16(0));
			state.SetRegister(Registers.bp, Constant.Word16(0));
			state.SetRegister(Registers.sp, Constant.Word16(pklSp));
			state.SetRegister(Registers.si, Constant.Word16(0));
			state.SetRegister(Registers.di, Constant.Word16(0));

            return new RelocationResults(
                new List<EntryPoint> {new EntryPoint(Address.SegPtr(pklCs, pklIp), state) },
                relocations,
                new List<Address>());
		}
Ejemplo n.º 4
0
        // Unpacks the relocation entries in a LzExe 0.91 binary
        private ImageMap Relocate91(byte [] abUncompressed, ushort segReloc, LoadedImage pgmImgNew, RelocationDictionary relocations)
        {
            const int CompressedRelocationTableAddress = 0x0158;
            int ifile = lzHdrOffset + CompressedRelocationTableAddress;

            int rel_off=0;
            for (;;)
            {
                ushort span = abUncompressed[ifile++];
                if (span == 0)
                {
                    span = abUncompressed[ifile++];
                    span |= (ushort) (abUncompressed[ifile++] << 8);
                    if (span == 0)
                    {
                        rel_off += 0x0FFF0;
                        continue;
                    }
                    else if (span == 1)
                    {
                        break;
                    }
                }

                rel_off += span;
                ushort seg = (ushort) (pgmImgNew.ReadLeUInt16((uint)rel_off) + segReloc);
                pgmImgNew.WriteLeUInt16((uint)rel_off, seg);
                relocations.AddSegmentReference((uint)rel_off, seg);
                imageMap.AddSegment(Address.SegPtr(seg, 0), seg.ToString("X4"), AccessMode.ReadWriteExecute, 0);
            }
            return imageMap;
        }