Пример #1
0
    private List <LinhaBios> LerBios()
    {
        List <LinhaBios> list = new List <LinhaBios>();

        int num = CE027.E000(arquivoEmBytes, PE0000, 0, false, new byte?());

        if (num > -1)
        {
            RomHeader obj;
            do
            {
                obj = new RomHeader(arquivoEmBytes, num);
                if (obj.E00B.PE000)
                {
                    list.Add(new LinhaBios(arquivoEmBytes, num));
                    num += obj.E00B.PE004;
                }
                else
                {
                    break;
                }
            }while (!obj.E00B.PE005);
        }
        return(list);
    }
Пример #2
0
        public void ShouldGenerateAbsoluteInstructionsWithLabel()
        {
            string input = @"procedure Test
{
    php

mainLoop:
    jmp mainLoop
}
";

            ZealCpuDriver driver = new ZealCpuDriver(input.ToMemoryStream());

            driver.Parse();

            RomHeader fakeHeader = new RomHeader();

            fakeHeader.MapMode  = MapMode.LoROM;
            fakeHeader.RomSpeed = RomSpeed.SlowROM;

            MemoryStream     memoryStream = new MemoryStream(32);
            CpuCodeGenerator generator    = new CpuCodeGenerator(memoryStream);

            generator.Instructions = driver.GlobalScope.Children[0].Statements.Where(x => x is CpuInstructionStatement).Select(x => x as CpuInstructionStatement).ToList();
            generator.Scope        = driver.GlobalScope.Children[0];
            generator.Header       = fakeHeader;
            generator.Generate();

            Assert.Equal(0x01, memoryStream.GetBuffer()[2]);
            Assert.Equal(0x80, memoryStream.GetBuffer()[3]);
        }
        /// <summary>
        /// Quickly replace a certain file in rom
        /// Does some hacks, leaves old file contents, so it should not be used repeatedly
        /// </summary>
        public static void ReplaceFile(string inromPath, Stream outrom, Stream injfile, string targetName)
        {
            using var inrom       = File.OpenRead(inromPath);
            using var readableRom = new FileReadableGameArchive(inromPath);

            var header = new RomHeader();

            inrom.Read(SpanUtil.AsBytes(ref header));

            outrom.Seek(0, SeekOrigin.Begin);
            inrom.Seek(0, SeekOrigin.Begin);
            inrom.CopyTo(outrom);

            var fileEntry         = readableRom.FindFile(targetName);
            var rawEntry          = new RomEntry();
            var rawEntryOffset    = Marshal.SizeOf <RomHeader>() + fileEntry.SourceOffset;
            var rawEntryBytesSpan = SpanUtil.AsBytes(ref rawEntry);

            outrom.Seek(rawEntryOffset, SeekOrigin.Begin);
            outrom.Read(rawEntryBytesSpan);
            outrom.Seek(rawEntryOffset, SeekOrigin.Begin);

            var newDataOffset = outrom.Length;

            while (newDataOffset % header.offsetMultiplier != 0)
            {
                newDataOffset++;
            }

            rawEntry.RawDataOffset = newDataOffset / header.offsetMultiplier;
            rawEntry.DataSize      = (int)injfile.Length;

            outrom.Write(rawEntryBytesSpan);

            outrom.Seek(newDataOffset, SeekOrigin.Begin);

            injfile.CopyTo(outrom);
        }
Пример #4
0
            static async ValueTask <EInputBlockResult> ConvertAsync(IRomData data, ERomFormat format)
            {
                FileInfo output;

                EraseLine();
                if (data.Header.Format == format)
                {
                    Console.WriteLine();
                    Console.WriteLine("The ROM data is already in the correct format.");
                    if (data is not RomFile)
                    {
                        output = new FileInfo(data.GetFilename());
                        await data.SaveAsync(output);

                        Console.WriteLine($"File saved to {output.FullName}");
                    }

                    // If it is a RomFile, the file already exists. Do nothing.
                    return(EInputBlockResult.Success);
                }

                output = data is RomFile rf
                    ? rf.File.WithExtension(RomHeader.GetFormatExtension(format))
                    : new FileInfo(data.GetFilename());

                var converted = await data.ConvertToAsync(format);

                if (await PromptOverwriteIfExistsAsync(output) != EInputBlockResult.Success)
                {
                    return(EInputBlockResult.Failed);
                }

                await converted.SaveAsync(output);

                Console.WriteLine($"File saved to {output.FullName}");
                return(EInputBlockResult.Success);
Пример #5
0
 public Mbc5Rom(byte[] bytes)
 {
     Header = new RomHeader(in bytes);
     bytes.CopyTo(data, 0);
     //todo: load ram if present
 }
Пример #6
0
 public BasicRom(byte[] bytes)
 {
     Header = new RomHeader(in bytes);
     bytes.CopyTo(data, 0);
 }
Пример #7
0
        public NDS(byte[] data)
        {
            EndianBinaryReader er = new EndianBinaryReader(new MemoryStream(data), Endianness.LittleEndian);

            Header = new RomHeader(er);

            er.BaseStream.Position = Header.MainRomOffset;
            MainRom = er.ReadBytes((int)Header.MainSize);
            if (er.ReadUInt32() == 0xDEC00621)            //Nitro Footer!
            {
                er.BaseStream.Position -= 4;
                StaticFooter            = new NitroFooter(er);
            }

            er.BaseStream.Position = Header.SubRomOffset;
            SubRom = er.ReadBytes((int)Header.SubSize);

            er.BaseStream.Position = Header.FntOffset;
            Fnt = new RomFNT(er);

            er.BaseStream.Position = Header.MainOvtOffset;
            MainOvt = new RomOVT[Header.MainOvtSize / 32];
            for (int i = 0; i < Header.MainOvtSize / 32; i++)
            {
                MainOvt[i] = new RomOVT(er);
            }

            er.BaseStream.Position = Header.SubOvtOffset;
            SubOvt = new RomOVT[Header.SubOvtSize / 32];
            for (int i = 0; i < Header.SubOvtSize / 32; i++)
            {
                SubOvt[i] = new RomOVT(er);
            }

            er.BaseStream.Position = Header.FatOffset;
            Fat = new FileAllocationEntry[Header.FatSize / 8];
            for (int i = 0; i < Header.FatSize / 8; i++)
            {
                Fat[i] = new FileAllocationEntry(er);
            }

            if (Header.BannerOffset != 0)
            {
                er.BaseStream.Position = Header.BannerOffset;
                Banner = new RomBanner(er);
            }

            FileData = new byte[Header.FatSize / 8][];
            for (int i = 0; i < Header.FatSize / 8; i++)
            {
                er.BaseStream.Position = Fat[i].fileTop;
                FileData[i]            = er.ReadBytes((int)Fat[i].fileSize);
            }
            //RSA Signature
            if (Header.RomSize + 0x88 <= er.BaseStream.Length)
            {
                er.BaseStream.Position = Header.RomSize;
                byte[] RSASig = er.ReadBytes(0x88);
                for (int i = 0; i < RSASig.Length; i++)
                {
                    //It could be padding, so check if there is something other than 0xFF or 0x00
                    if (RSASig[i] != 0xFF || RSASig[i] != 0x00)
                    {
                        RSASignature = RSASig;
                        break;
                    }
                }
            }
            er.Close();
        }
Пример #8
0
    public LinhaBios(byte[] param0, int param1) : base(param0, param1)
    {
        this.RomHeader = new RomHeader(param0, param1);
        int num = CE027.E000(param0, this.PE002, param1, false, new byte?(0));

        if (this.E003(num))
        {
            this.FE001 = new CE001(param0, num, param1);
        }

        if (this.FE001 == null || !this.FE001.PE004 || !this.PE000(this.RomHeader.E00B.PE002))
        {
            return;
        }

        if (this.E003(this.FE001.FE004.PE001))
        {
            this.PerfTable = new PerfTable(param0, this.FE001.FE004.PE001);
        }

        if (this.E003(this.FE001.FE004.PE005))
        {
            this.PowerTable = new PowerTable(param0, this.FE001.FE004.PE005);
        }

        if (this.E003(this.FE001.FE004.PE004))
        {
            this.VoltageTable = new VoltageTable(param0, this.FE001.FE004.PE004);
        }

        if (this.E003(this.FE001.FE004.PE006))
        {
            this.BoostProfile = new BoostProfile(param0, this.FE001.FE004.PE006);
        }

        if (this.E003(this.FE001.FE004.PE007))
        {
            this.BoostTable = new BoostTable(param0, this.FE001.FE004.PE007);
        }

        if (this.E003(this.FE001.FE004.PE008))
        {
            this.FE006 = new CE01F(param0, this.FE001.FE004.PE008);
        }

        if (this.E003(this.FE001.FE004.PE002))
        {
            this.FanSettings = new FanSettings(param0, this.FE001.FE004.PE002);
        }

        if (this.E003(this.FE001.FE004.PE003))
        {
            this.FanSettings2 = new FanSettings2(param0, this.FE001.FE004.PE003);
        }

        if (!this.E003(this.FE001.FE004.PE009))
        {
            return;
        }

        this.TempTargets = new TempTargets(param0, this.FE001.FE004.PE009);
    }
Пример #9
0
 /// <summary>
 /// Returns a new <see cref="RomHeader"/> instance with the header entry address adjusted
 /// based on the CIC.
 /// </summary>
 /// <remarks>
 /// This method may return the original <see cref="RomHeader"/>.
 /// </remarks>
 /// <param name="header">The old header data.</param>
 /// <param name="data">The ROM data.</param>
 public static RomHeader WithCalculatedEntryOffset(this RomHeader header, in ReadOnlySpan <byte> data)