Esempio n. 1
0
        static void DisassembleRom(RomVersion ver, string path)
        {
            Rom rom;

            Console.Write("Initializing task list:  ");
            if (ver.Game == Game.OcarinaOfTime)
            {
                rom = new ORom(path, ver);
            }
            else
            {
                rom = new MRom(path, ver);
            }

            List <DisassemblyTask> taskList = DisassemblyTask.CreateTaskList(rom);

            taskList = taskList.Where(x => x.VRom.End > 0).ToList();
            Console.WriteLine("DONE!");
            Console.Write($"Building symbol table: ");
            Stream getFile(FileAddress x) => rom.Files.GetFile(x);

            LoadFunctionDatabase(ver);
            GetSymbols(taskList, rom.Version, getFile);

            Console.WriteLine("DONE!");
            Console.WriteLine("Disassembling files: ");

            DisassembleTasks(rom.Version, taskList, getFile);
            DumpFoundFunctions(rom.Version, Disassemble.GetFunctions());
        }
Esempio n. 2
0
        static void DisassembleRom(RomVersion version, string path, Func <DisassemblyTask, bool> filter)
        {
            Console.WriteLine($"{version} {path}");
            Console.Write("Initializing task list:  ");
            Rom rom = Rom.New(path, version);
            List <DisassemblyTask> taskList = DisassemblyTask.CreateTaskList(rom);

            taskList = taskList.Where(filter).Where(x => x.VRom.End > 0).ToList();

            if (taskList.Count == 0)
            {
                Console.WriteLine("Error: No tasks to process!");
                return;
            }

            Console.WriteLine("DONE!");
            Console.Write($"Loading symbol table from file: ");
            LoadFunctionDatabase(version);

            Console.WriteLine("DONE!");
            Console.WriteLine("Disassembling files: ");

            Stream getFile(FileAddress x) => rom.Files.GetFile(x);

            DisassembleTasks(rom.Version, taskList, getFile);
            DumpFoundFunctions(rom.Version, Disassemble.GetFunctions());
        }
Esempio n. 3
0
        static void OverlayTest(RomVersion ver, string testOvl)
        {
            PathUtil.TryGetRomLocation(ver, out string path);
            Rom rom   = Rom.New(path, ver);
            var tasks = DisassemblyTask.CreateTaskList(rom);

            Disassemble.PrintRelocations = true;
            Disassemble.GccOutput        = true;

            var task = tasks.SingleOrDefault(x => x.Name == testOvl || x.Name == $"ovl_{testOvl}");

            if (task == null)
            {
                Console.WriteLine("Cannot find overlay");
                return;
            }
            //var taskbss = tasks.Where(x => x.Sections["bss"]?.Size > 0).ToList();

            var reader = new BinaryReader(rom.Files.GetFile(task.VRom));

            //using (StreamWriter sw = new StreamWriter("__test.txt"))
            //{
            //    foreach (var rel in task.Map.Relocations.Where(x => x.SectionId == Overlay.RelocationWord.Section.text))
            //    {
            //        reader.BaseStream.Position = rel.Offset;
            //        sw.WriteLine($"{rel.Offset:X6}: {rel.RelocType}  {GetOP(reader.ReadBigInt32())}");
            //    }
            //}

            using (StreamWriter sw = new StreamWriter($"__{testOvl}.txt"))
            {
                BinaryReader br = new BinaryReader(rom.Files.GetFile(task.VRom));
                Disassemble.FirstParse(br, task);
                if (Disassemble.GccOutput)
                {
                    sw.WriteLine("#include <mips.h>");
                    sw.WriteLine(".set noreorder");
                    sw.WriteLine(".set noat");
                    sw.WriteLine();
                }
                Disassemble.Task(sw, br, task);
            }

            using (StreamWriter sw = new StreamWriter($"__{testOvl}_f.txt"))
            {
                foreach (var item in Disassemble.Symbols.OrderBy(x => x.Key))
                {
                    sw.WriteLine($"{item.Value.ToString()} = 0x{item.Key}");
                }
            }
        }