Exemplo n.º 1
0
        public void relocate32(int hunk_no, byte[] data, uint offset, uint hunk_addr)
        {
            var delta = MemoryArea.ReadBeUInt32(data, offset);
            var addr  = hunk_addr + delta;

            MemoryArea.WriteBeUInt32(data, offset, addr);
            Debug.WriteIf(Trace.TraceVerbose, string.Format("#{0,2} + {1:X8}: {2:X6} (delta) + {3:X6} (hunk_addr) -> {4:X6}", hunk_no, offset, delta, hunk_addr, addr));
        }
Exemplo n.º 2
0
        public ResourceFork(byte[] bytes, IProcessorArchitecture arch)
        {
            this.image = bytes;
            this.arch  = arch;

            rsrcDataOff = MemoryArea.ReadBeUInt32(bytes, 0);
            rsrcMapOff  = MemoryArea.ReadBeUInt32(bytes, 4);
            dataSize    = MemoryArea.ReadBeUInt32(bytes, 8);
            mapSize     = MemoryArea.ReadBeUInt32(bytes, 0x0C);

            rsrcTypes = new ResourceTypeCollection(image, rsrcMapOff, mapSize);
        }
Exemplo n.º 3
0
        public override RelocationResults Relocate(Program program, Address addrLoad)
        {
            // Get the Reset address from offset $0004 of the interrupt vector.
            var addrReset = Address.Ptr32(MemoryArea.ReadBeUInt32(RawImage, 4));
            var eps       = new List <EntryPoint>();

            if (program.ImageMap.IsValidAddress(addrReset))
            {
                eps.Add(new EntryPoint(addrReset, "Reset", program.Architecture.CreateProcessorState()));
            }
            return(new RelocationResults(eps, new List <Address>()));
        }
Exemplo n.º 4
0
        public ResourceFork(MacOSClassic platform, byte[] bytes)
        {
            this.image    = bytes;
            this.platform = platform;
            this.arch     = platform.Architecture;

            rsrcDataOff = MemoryArea.ReadBeUInt32(bytes, 0);
            rsrcMapOff  = MemoryArea.ReadBeUInt32(bytes, 4);
            dataSize    = MemoryArea.ReadBeUInt32(bytes, 8);
            mapSize     = MemoryArea.ReadBeUInt32(bytes, 0x0C);

            rsrcTypes = new ResourceTypeCollection(image, rsrcMapOff, mapSize);
        }
Exemplo n.º 5
0
        public virtual void ParseOverlay(Action <Hunk> h)
        {
            OverlayHunk hunk = new OverlayHunk();

            h(hunk);
            // read size of overlay hunk
            var ov_size = this.read_long();

            if (ov_size < 0)
            {
                throw new BadImageFormatException(string.Format("{0} has invalid size.", hunk.HunkType));
            }

            // read data of overlay
            var byte_size = (ov_size + 1) * 4;
            var ov_data   = f.ReadBytes(byte_size);

            hunk.ov_data = ov_data;
            // check: first get header hunk
            var hdr_hunk = this.hunks[0];

            if (hdr_hunk.HunkType != HunkType.HUNK_HEADER)
            {
                throw new BadImageFormatException(string.Format("{0} has no header hunk.", hunk.HunkType));
            }

            // first find the code segment of the overlay manager
            var overlayManagerHunk = this.FindFirstCodeHunk();

            if (overlayManagerHunk == null)
            {
                throw new BadImageFormatException(string.Format("{0} has no overlay manager hunk.", hunk.HunkType));
            }

            // check overlay manager
            var  overlay_mgr_data = overlayManagerHunk.Data;
            uint magic            = MemoryArea.ReadBeUInt32(overlay_mgr_data, 4);

            if (magic != 0xABCD)
            {
                throw new BadImageFormatException("No valid overlay manager found.");
            }

            // check for standard overlay manager
            var magic2      = MemoryArea.ReadBeUInt32(overlay_mgr_data, 24);
            var magic3      = MemoryArea.ReadBeUInt32(overlay_mgr_data, 20);
            var magic4      = MemoryArea.ReadBeUInt32(overlay_mgr_data, 32);
            var std_overlay = magic2 == 23456 && magic3 == 122648165 && magic4 == 1919705465;

            hunk.ov_std = std_overlay;
        }
Exemplo n.º 6
0
            public IEnumerator <ResourceReference> GetEnumerator()
            {
                var offset = this.offset;

                for (int i = 0; i < count; ++i)
                {
                    ushort rsrcID  = MemoryArea.ReadBeUInt16(bytes, offset);
                    string name    = ReadName(MemoryArea.ReadBeUInt16(bytes, offset + 2));
                    uint   dataOff = MemoryArea.ReadBeUInt32(bytes, offset + 4) & 0x00FFFFFFU;
                    yield return(new ResourceReference(rsrcID, name, dataOff));

                    offset += 0x0C;
                }
            }
Exemplo n.º 7
0
        public override RelocationResults Relocate(Program program, Address addrLoad)
        {
            // Get the Reset address from offset $0004 of the interrupt vector.
            var addrReset = Address.Ptr32(MemoryArea.ReadBeUInt32(RawImage, 4));
            var syms      = new SortedList <Address, ImageSymbol>();
            var eps       = new List <ImageSymbol>();

            if (program.SegmentMap.IsValidAddress(addrReset))
            {
                var sym = ImageSymbol.Procedure(program.Architecture, addrReset, "Reset", state: program.Architecture.CreateProcessorState());
                syms.Add(sym.Address, sym);
                eps.Add(sym);
            }
            return(new RelocationResults(eps, syms));
        }
Exemplo n.º 8
0
        bool PerformRelocations(MemoryArea mem, ImageReader rdr)
        {
            uint fixup;

            if (!rdr.TryReadBeUInt32(out fixup))
            {
                return(false);
            }
            if (fixup == 0)
            {
                return(true);    // no relocations to do.
            }
            uint offset = fixup;

            for (;;)
            {
                var  dst = mem.BaseAddress + offset;
                uint l   = mem.ReadBeUInt32(offset);
                l += mem.BaseAddress.ToUInt32();
                mem.WriteBeUInt32(offset, l);
                mem.Relocations.AddPointerReference(mem.BaseAddress.ToLinear() + offset, l);

                byte b;
                for (;;)
                {
                    if (!rdr.TryReadByte(out b))
                    {
                        return(false);
                    }
                    if (b == 0)
                    {
                        return(true);
                    }
                    else if (b == 1)
                    {
                        offset += 254;
                    }
                    else
                    {
                        offset += b;
                        break;
                    }
                }
            }
        }