Пример #1
0
        bool PerformRelocations(MemoryArea mem, ImageReader rdr)
        {
            if (!rdr.TryReadBeUInt32(out uint fixup))
            {
                return(false);
            }
            if (fixup == 0)
            {
                return(true);    // no relocations to do.
            }
            uint offset = fixup;

            for (;;)
            {
                var dst = mem.BaseAddress + offset;
                if (!mem.TryReadBeUInt32(offset, out uint l))
                {
                    return(false);
                }
                l += mem.BaseAddress.ToUInt32();
                mem.WriteBeUInt32(offset, l);
                mem.Relocations.AddPointerReference(mem.BaseAddress.ToLinear() + offset, l);

                for (;;)
                {
                    if (!rdr.TryReadByte(out byte b))
                    {
                        return(false);
                    }
                    if (b == 0)
                    {
                        return(true);
                    }
                    else if (b == 1)
                    {
                        offset += 254;
                    }
                    else
                    {
                        offset += b;
                        break;
                    }
                }
            }
        }
Пример #2
0
        public Parser CreateParser()
        {
            if (!MemoryArea.TryReadBeUInt32(RawImage, 0, out uint magic))
            {
                throw new BadImageFormatException("Invalid Mach-O header.");
            }
            switch (magic)
            {
            case MH_MAGIC: return(new Loader32(this, new BeImageReader(RawImage, 0)));

            case MH_MAGIC_64: return(new Loader64(this, new BeImageReader(RawImage, 0)));

            case MH_MAGIC_32_LE: return(new Loader32(this, new LeImageReader(RawImage, 0)));

            case MH_MAGIC_64_LE: return(new Loader64(this, new LeImageReader(RawImage, 0)));
            }
            throw new BadImageFormatException("Invalid Mach-O header.");
        }