Beispiel #1
0
        public override Program Load(Address addrLoad)
        {
            var cfgSvc = Services.RequireService <IConfigurationService>();
            var rdr    = new Core.Memory.BeImageReader(RawImage);
            var hdr    = rdr.ReadStruct <Header>();
            var things = new Entry[hdr.cEntries];

            for (int i = 0; i < things.Length; ++i)
            {
                things[i] = rdr.ReadStruct <Entry>();
                Debug.Print("Type: {0,-16} Offset: {1:X8} Length: {2:X8}", things[i].type, things[i].offset, things[i].length);
            }

            var resourceEntry = things.FirstOrDefault(t => t.type == EntryType.ResourceFork);

            if (resourceEntry.type == EntryType.ResourceFork)
            {
                var bytes = new byte[resourceEntry.length];
                Array.Copy(RawImage, resourceEntry.offset, bytes, 0, bytes.Length);
                var arch     = cfgSvc.GetArchitecture("m68k");
                var platform = (MacOSClassic)cfgSvc.GetEnvironment("macOs").Load(Services, arch);
                this.rsrcFork   = new ResourceFork(platform, bytes);
                this.mem        = new ByteMemoryArea(addrLoad, bytes);
                this.segmentMap = new SegmentMap(addrLoad);
                return(new Program(this.segmentMap, arch, platform));
            }
            else
            {
                throw new BadImageFormatException("Unable to find a resource fork.");
            }
        }
Beispiel #2
0
 public AppleDoubleLoader(IServiceProvider services, string filename, byte[] rawImage)
     : base(services, filename, rawImage)
 {
     rsrcFork   = null !;
     mem        = null !;
     segmentMap = null !;
 }
Beispiel #3
0
 public AppleDoubleLoader(IServiceProvider services, ImageLocation imageUri, byte[] rawImage)
     : base(services, imageUri, rawImage)
 {
     rsrcFork   = null !;
     mem        = null !;
     segmentMap = null !;
 }
Beispiel #4
0
        public void Relocate()
        {
            var  memA5          = (ByteMemoryArea)platform.A5World.MemoryArea;
            var  a5belowWriter  = new BeImageWriter(memA5, 0);
            var  a5belowReader  = new BeImageReader(memA5, 0);
            uint a5globalOffset = platform.A5Offset - a5dbelow;

            var a5WorldAddress = (UInt32)((platform.A5World.Address.Offset + platform.A5Offset) & 0xFFFFFFFF);

            // set Repeat count = 1, reset after each completed copy cycle
            // byte token lower 4 bits number of words to copy from compressed data
            // byte token upper 4 bits number of words to skip in global application data space
            // if either value is 0 then get run length value which is in bytes.
            // if the new run length value for copy is 0 then it's the end of compression data.

            for (;;)
            {
                int a5repeat = 1;
                // Skip is number of 16-bit words to skip
                uint a5globalSkip = a5dr.ReadByte();
                if (a5globalSkip == 0)
                {
                    a5globalSkip = a5dr.ReadByte();
                    if (a5globalSkip == 0)
                    {
                        break;
                    }
                    if (a5globalSkip > 0x7F)
                    {
                        a5globalSkip = ((a5globalSkip & 0x7F) << 8) + a5dr.ReadByte();
                        a5globalSkip = (a5globalSkip << 16) + a5dr.ReadBeUInt16();
                    }
                    else
                    {
                        a5repeat = ResourceFork.GetRunLengthValue(a5dr, ref a5repeat);
                        //$BUG: a5repeat could return the value 0. The do-while below will
                        // decrement a5repeat before testing. This will lead to an effective
                        // repeat count of 2^32; likely not wanted.
                    }
                }
                else
                {
                    if ((a5globalSkip & 0x80) == 0x80)
                    {
                        a5globalSkip = ((a5globalSkip & 0x7F) << 8) + a5dr.ReadByte();
                    }
                }
                a5globalSkip = a5globalSkip * 2;
                do
                {
                    a5globalOffset += a5globalSkip;
                    a5belowReader.Seek(a5globalOffset, SeekOrigin.Begin);
                    uint a5ptrOffset = a5belowReader.ReadBeUInt32();
                    a5belowWriter.Position = (int)a5globalOffset;

                    // write relocated A5World pointers to absolute address in A5World segment
                    // Possible register/mark as Global pointer references to strings

                    a5belowWriter.WriteBeUInt32((a5WorldAddress + a5ptrOffset) & 0xFFFFFFFF);
                    --a5repeat;
                } while (a5repeat > 0);
            }
        }