예제 #1
0
        public void ApplyRelocation(uint baseOfImage, uint page, ImageReader rdr, RelocationDictionary relocations)
        {
            ushort fixup = rdr.ReadLeUInt16();

            switch (fixup >> 12)
            {
            case RelocationAbsolute:
                // Used for padding to 4-byte boundary, ignore.
                break;

            case RelocationHighLow:
            {
                uint offset = page + (fixup & 0x0FFFu);
                uint n      = (uint)(imgLoaded.ReadLeUInt32(offset) + (baseOfImage - preferredBaseOfImage.ToLinear()));
                imgLoaded.WriteLeUInt32(offset, n);
                relocations.AddPointerReference(offset, n);
                break;
            }

            case 0xA:
                break;

            default:
                throw new NotImplementedException(string.Format("Fixup type: {0:X}", fixup >> 12));
            }
        }
예제 #2
0
        private TWord Read(MachineOperand op)
        {
            var r = op as RegisterOperand;

            if (r != null)
            {
                return(ReadRegister(r.Register));
            }
            var i = op as ImmediateOperand;

            if (i != null)
            {
                return(i.Value.ToUInt32());
            }
            var a = op as AddressOperand;

            if (a != null)
            {
                return(a.Address.ToUInt32());
            }
            var m = op as MemoryOperand;

            if (m != null)
            {
                TWord ea = GetEffectiveAddress(m);
                byte  b;
                switch (op.Width.Size)
                {
                case 1: if (!img.TryReadByte(Address.Ptr32(ea), out b))
                    {
                        throw new IndexOutOfRangeException();
                    }
                    else
                    {
                        return(b);
                    }

                case 4: return(img.ReadLeUInt32(Address.Ptr32(ea)));
                }
                throw new NotImplementedException();
            }
            throw new NotImplementedException();
        }
예제 #3
0
        public void X86Emu_Write_Byte()
        {
            Given_Code(m =>
            {
                m.Label("datablob");
                m.Dd(0x12345678);
                m.Mov(m.MemB(0x00100000), m.ah);
            });
            Given_RegValue(Registers.eax, 0x40302010);
            emu.InstructionPointer += 4;
            emu.Start();

            Assert.AreEqual(0x12345620u, image.ReadLeUInt32(0));
        }
예제 #4
0
		public void ApplyRelocation(uint baseOfImage, uint page, ImageReader rdr, RelocationDictionary relocations)
		{
			ushort fixup = rdr.ReadLeUInt16();
			uint offset = page + (fixup & 0x0FFFu);
			switch (fixup >> 12)
			{
			case RelocationAbsolute:
				// Used for padding to 4-byte boundary, ignore.
				break;
			case RelocationHighLow:
			{
				uint n = (uint) (imgLoaded.ReadLeUInt32(offset) + (baseOfImage - preferredBaseOfImage.ToLinear()));
				imgLoaded.WriteLeUInt32(offset, n);
				relocations.AddPointerReference(offset, n);
				break;
			}
            case 0xA:
            break;
			default:
                var dcSvc = Services.RequireService<DecompilerEventListener>();
                dcSvc.Warn(
                    dcSvc.CreateAddressNavigator(program, Address.Ptr32(offset)),
                    string.Format(
                        "Unsupported PE fixup type: {0:X}",
                        fixup >> 12));
                break;
			}

#if I386
            //
// I386 relocation types.
//
const static final ushort IMAGE_REL_I386_ABSOLUTE        = 0x0000;  // Reference is absolute, no relocation is necessary
const static final ushort IMAGE_REL_I386_DIR16           = 0x0001;  // Direct 16-bit reference to the symbols virtual address
const static final ushort IMAGE_REL_I386_REL16           = 0x0002;  // PC-relative 16-bit reference to the symbols virtual address
const static final ushort IMAGE_REL_I386_DIR32           = 0x0006;  // Direct 32-bit reference to the symbols virtual address
const static final ushort IMAGE_REL_I386_DIR32NB         = 0x0007;  // Direct 32-bit reference to the symbols virtual address, base not included
const static final ushort IMAGE_REL_I386_SEG12           = 0x0009;  // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
const static final ushort IMAGE_REL_I386_SECTION         = 0x000A;
const static final ushort IMAGE_REL_I386_SECREL          = 0x000B;
const static final ushort IMAGE_REL_I386_TOKEN           = 0x000C;  // clr token
const static final ushort IMAGE_REL_I386_SECREL7         = 0x000D;  // 7 bit offset from base of section containing target
const static final ushort IMAGE_REL_I386_REL32           = 0x0014;  // PC-relative 32-bit reference to the symbols virtual address