public void MakeFreeAreaList(byte[] data, uint RebuildAddress, Dictionary <uint, uint> useMap)
        {
            List <Address> knownList = U.MakeAllStructPointersList(false);
            List <DisassemblerTrumb.LDRPointer> ldrmap = DisassemblerTrumb.MakeLDRMap(Program.ROM.Data, 0x100);

            U.AppendAllASMStructPointersList(knownList
                                             , ldrmap
                                             , isPatchInstallOnly: true
                                             , isPatchPointerOnly: false
                                             , isPatchStructOnly: false
                                             , isUseOtherGraphics: true
                                             , isUseOAMSP: true
                                             );
            MoveToFreeSapceForm.AppendSkillSystemsSanctuary(knownList);

            Dictionary <uint, bool> knownDic = MakeKnownListToDic(knownList);

            MakeFreeDataList(RecycleFreeAreaList, knownDic, FREEAREA_BLOCK_SIZE + 16 + 16, data, RebuildAddress, useMap);

            for (int i = 0; i < this.RecycleFreeAreaList.Count;)
            {
                Address p = this.RecycleFreeAreaList[i];

                //頭としっぽはくれてやれ
                if (p.Length < 64)
                {
                    this.RecycleFreeAreaList.RemoveAt(i);
                    continue;
                }
                p.ResizeAddress(p.Addr + 16, p.Length - 16 - 16);
                i++;
            }
        }
Esempio n. 2
0
 public List <DisassemblerTrumb.LDRPointer> GetLDRMapCache()
 {
     if (this.LDRMapCache.Count <= 0)
     {//まだデータがないらしいので仕方ない更新する.
         List <DisassemblerTrumb.LDRPointer> ldrmap;
         ldrmap           = DisassemblerTrumb.MakeLDRMap(Program.ROM.Data, 0x100);
         this.LDRMapCache = ldrmap;
         return(ldrmap);
     }
     return(this.LDRMapCache);
 }
        void CheckLDRCache()
        {
            if (LDRCache != null)
            {
                return;
            }
            uint limit = Program.ROM.RomInfo.compress_image_borderline_address();

            if (this.WriteOffset < limit)
            {
                limit = this.WriteOffset;
            }
            this.LDRCache = DisassemblerTrumb.MakeLDRMap(this.WriteROMData32MB, 0x100, limit, true);
        }
Esempio n. 4
0
        public List <DisassemblerTrumb.LDRPointer> GetLDRMapCache()
        {
            if (this.LDRMapCache.Count <= 0)
            {//まだデータがないらしいので仕方ない更新する.
                List <DisassemblerTrumb.LDRPointer> ldrmap;
                ldrmap           = DisassemblerTrumb.MakeLDRMap(Program.ROM.Data, 0x100);
                this.LDRMapCache = ldrmap;
                return(ldrmap);
            }
#if DEBUG
            //一応、キャッシュと同じかどうかのテストをしておく.
            List <DisassemblerTrumb.LDRPointer> ldrmaplow = DisassemblerTrumb.MakeLDRMap(Program.ROM.Data, 0x100);
            Debug.Assert(this.LDRMapCache.Count == ldrmaplow.Count);
#endif
            return(this.LDRMapCache);
        }
Esempio n. 5
0
        void LoadTargetROM(string filename)
        {
            ROM    OtherROM = new ROM();
            string version;

            if (OtherROM.Load(filename, out version))
            {
                this.OtherROMASMMap = new AsmMapFile(OtherROM);
            }

            this.OtherROMFilename = filename;
            this.OtherROMData     = File.ReadAllBytes(filename);

            this.OtherLoadName.Text = R._("別ゲームROM:{0}", Path.GetFileNameWithoutExtension(this.OtherROMFilename));
            //自分のLDRMAPをここで作る. 相手のROMに探索に利用する
            this.LDRMAPs = Program.AsmMapFileAsmCache.GetLDRMapCache();
            //相手のROMのLDRMAPを作る.
            this.OtherLDRMAPs = DisassemblerTrumb.MakeLDRMap(this.OtherROMData, 0x100, 0);
        }
Esempio n. 6
0
        List <Address> SearchAllLZ77Data(InputFormRef.AutoPleaseWait wait)
        {
            //念のためパッチのCheckIFをスキャンをやり直す.
            PatchForm.ClearCheckIF();

            wait.DoEvents("GrepAllStructPointers");
            List <DisassemblerTrumb.LDRPointer> ldrmap = DisassemblerTrumb.MakeLDRMap(Program.ROM.Data, 0x100, Program.ROM.RomInfo.compress_image_borderline_address, true);
            List <Address> structList = U.MakeAllStructPointersList(false);

            U.AppendAllASMStructPointersList(structList
                                             , ldrmap
                                             , isPatchInstallOnly: true
                                             , isPatchPointerOnly: false
                                             , isPatchStructOnly: false
                                             , isUseOtherGraphics: false
                                             , isUseOAMSP: false
                                             );
            AsmMapFile.InvalidateUNUNSED(structList);

            Dictionary <uint, bool> dupCheck = new Dictionary <uint, bool>();

            List <Address> ret = new List <Address>();

            foreach (Address a in structList)
            {
                if (!Address.IsLZ77(a.DataType))
                {
                    continue;
                }
                if (dupCheck.ContainsKey(a.Addr))
                {
                    continue;
                }
                ret.Add(a);
                dupCheck[a.Addr] = true;
            }
            ret.Sort((aa, bb) => { return((int)(aa.Addr - bb.Addr)); });

            return(ret);
        }
Esempio n. 7
0
        AsmMapFile MakeFullLow()
        {
            AsmMapFile map = new AsmMapFile(this.BaseSymbol);

            if (IsStopFlag)
            {
                return(map);
            }

            //LDRマップのクリア
            this.LDRMapCache = new List <DisassemblerTrumb.LDRPointer>(0x1000);
            this.FELintCache = new Dictionary <uint, List <FELint.ErrorSt> >();

            List <DisassemblerTrumb.LDRPointer> ldrmap;

            try
            {
                ldrmap           = DisassemblerTrumb.MakeLDRMap(Program.ROM.Data, 0x100);
                this.LDRMapCache = ldrmap;
                if (IsStopFlag)
                {
                    return(map);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                Debug.Assert(false);
                return(map);
            }

            try
            {
                MakeHardCodeWarning(); //ハードコーディングされているデータの警告
                if (IsStopFlag)
                {
                    return(map);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                Debug.Assert(false);
            }

            try
            {
                ScanFELintByThread(ldrmap);
                if (IsStopFlag)
                {
                    return(map);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                Debug.Assert(false);
                return(map);
            }

            Dictionary <uint, bool> knownDic = new Dictionary <uint, bool>();
            List <Address>          structlist;

            try
            {
                structlist = U.MakeAllStructPointersList(false); //既存の構造体
                if (IsStopFlag)
                {
                    return(map);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                Debug.Assert(false);
                return(map);
            }

            try
            {
                PatchForm.MakePatchStructDataList(structlist, true, true, false); //パッチが知っている領域.
                if (IsStopFlag)
                {
                    return(map);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                Debug.Assert(false);
            }

            try
            {
                //参照の逆追跡
                this.VarsIDArray = U.MakeVarsIDArray(map);
                if (IsStopFlag)
                {
                    return(map);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                Debug.Assert(false);
            }

            try
            {
                GraphicsToolForm.MakeLZ77DataList(structlist); //lz77で圧縮されたもの(主に画像)
                if (IsStopFlag)
                {
                    return(map);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                Debug.Assert(false);
            }

            try
            {
                ProcsScriptForm.MakeAllDataLength(structlist, ldrmap);
                if (IsStopFlag)
                {
                    return(map);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                Debug.Assert(false);
            }

            try
            {
                OAMSPForm.MakeAllDataLength(structlist, structlist, ldrmap);
                if (IsStopFlag)
                {
                    return(map);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                Debug.Assert(false);
            }

            try
            {
                knownDic = AsmMapFile.MakeKnownListToDic(structlist);
                AsmMapFile.MakeFreeDataList(structlist, knownDic, 0x100, 0x00, 16); //フリー領域
                if (IsStopFlag)
                {
                    return(map);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                Debug.Assert(false);
            }

            try
            {
                AsmMapFile.MakeFreeDataList(structlist, knownDic, 0x100, 0xFF, 16); //フリー領域
                if (IsStopFlag)
                {
                    return(map);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                Debug.Assert(false);
            }

            try
            {
                map.AppendMAP(structlist);
                if (IsStopFlag)
                {
                    return(map);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                Debug.Assert(false);
            }

            Dictionary <uint, uint> ldrtable = new Dictionary <uint, uint>();  //LDR参照データがある位置を記録します. コードの末尾などにあります. 数が多くなるのでマップする.

            try
            {
                AsmMapFile.MakeSwitchDataList(ldrtable, 0x100, 0);
                if (IsStopFlag)
                {
                    return(map);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                Debug.Assert(false);
            }

            try
            {
                map.AppendMAP(ldrtable);
                if (IsStopFlag)
                {
                    return(map);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                Debug.Assert(false);
            }

            //近場リスト生成.
            map.MakeNearSearchSortedList();

            return(map);
        }
Esempio n. 8
0
        AsmMapFile MakeFullLow()
        {
            AsmMapFile map = MakeInstant();

            if (IsStopFlag)
            {
                return(map);
            }

            //LDRマップのクリア
            this.LDRMapCache = new List <DisassemblerTrumb.LDRPointer>();
            this.FELintCache = new Dictionary <uint, List <FELint.ErrorSt> >();

            List <DisassemblerTrumb.LDRPointer> ldrmap;

#if !DEBUG
            try
            {
#endif
            ldrmap           = DisassemblerTrumb.MakeLDRMap(Program.ROM.Data, 0x100);
            this.LDRMapCache = ldrmap;
            if (IsStopFlag)
            {
                return(map);
            }
#if !DEBUG
        }

        catch (Exception e)
        {
            Log.Error(e.ToString());
            return(map);
        }
#endif
#if !DEBUG
            try
            {
#endif
            MakeHardCodeWarning(); //ハードコーディングされているデータの警告
            if (IsStopFlag)
            {
                return(map);
            }
#if !DEBUG
        }
        catch (Exception e)
        {
            Log.Error(e.ToString());
        }
#endif
#if !DEBUG
            try
            {
#endif
            ScanFELintByThread(ldrmap);
            if (IsStopFlag)
            {
                return(map);
            }
#if !DEBUG
        }
        catch (Exception e)
        {
            Log.Error(e.ToString());
            return(map);
        }
#endif
            List <Address> structlist;
#if !DEBUG
            try
            {
#endif
            structlist = U.MakeAllStructPointersList(false); //既存の構造体
            if (IsStopFlag)
            {
                return(map);
            }
#if !DEBUG
        }
        catch (Exception e)
        {
            Log.Error(e.ToString());
            return(map);
        }
#endif

#if !DEBUG
            try
            {
#endif
            PatchForm.MakePatchStructDataList(structlist, true, true, false); //パッチが知っている領域.
            if (IsStopFlag)
            {
                return(map);
            }
#if !DEBUG
        }
        catch (Exception e)
        {
            Log.Error(e.ToString());
        }
#endif
#if !DEBUG
            try
            {
#endif
            map.MakeTextIDArray(); //全テキストIDの検出
            if (IsStopFlag)
            {
                return(map);
            }
#if !DEBUG
        }
        catch (Exception e)
        {
            Log.Error(e.ToString());
        }
#endif
#if !DEBUG
            try
            {
#endif
            GraphicsToolForm.MakeLZ77DataList(structlist); //lz77で圧縮されたもの(主に画像)
            if (IsStopFlag)
            {
                return(map);
            }
#if !DEBUG
        }
        catch (Exception e)
        {
            Log.Error(e.ToString());
        }
#endif
#if !DEBUG
            try
            {
#endif
            ProcsScriptForm.MakeAllDataLength(structlist, ldrmap);
            if (IsStopFlag)
            {
                return(map);
            }
#if !DEBUG
        }
        catch (Exception e)
        {
            Log.Error(e.ToString());
        }
#endif


#if !DEBUG
            try
            {
#endif
            OAMSPForm.MakeAllDataLength(structlist, structlist, ldrmap);
            if (IsStopFlag)
            {
                return(map);
            }
#if !DEBUG
        }
        catch (Exception e)
        {
            Log.Error(e.ToString());
        }
#endif
#if !DEBUG
            try
            {
#endif
            AsmMapFile.MakeFreeDataList(structlist, 0x100, 0x00, 16); //フリー領域
            if (IsStopFlag)
            {
                return(map);
            }
#if !DEBUG
        }
        catch (Exception e)
        {
            Log.Error(e.ToString());
        }
#endif
#if !DEBUG
            try
            {
#endif
            AsmMapFile.MakeFreeDataList(structlist, 0x100, 0xFF, 16); //フリー領域
            if (IsStopFlag)
            {
                return(map);
            }
#if !DEBUG
        }
        catch (Exception e)
        {
            Log.Error(e.ToString());
        }
#endif
#if !DEBUG
            try
            {
#endif
            map.AppendMAP(structlist);
            if (IsStopFlag)
            {
                return(map);
            }
#if !DEBUG
        }
        catch (Exception e)
        {
            Log.Error(e.ToString());
        }
#endif
            Dictionary <uint, uint> ldrtable = new Dictionary <uint, uint>();  //LDR参照データがある位置を記録します. コードの末尾などにあります. 数が多くなるのでマップする.
#if !DEBUG
            try
            {
#endif

            AsmMapFile.MakeSwitchDataList(ldrtable, 0x100, 0);
            if (IsStopFlag)
            {
                return(map);
            }
#if !DEBUG
        }
        catch (Exception e)
        {
            Log.Error(e.ToString());
        }
#endif
#if !DEBUG
            try
            {
#endif

            map.AppendMAP(ldrtable);
            if (IsStopFlag)
            {
                return(map);
            }
#if !DEBUG
        }
        catch (Exception e)
        {
            Log.Error(e.ToString());
        }
#endif

            //近場リスト生成.
            map.MakeNearSearchSortedList();

            return(map);
        }
Esempio n. 9
0
        public static void AllMakeNoDollSymFile(Form self, string symfilename, InputFormRef.AutoPleaseWait wait)
        {
            Encoding encoding = U.GetSystemDefault();

            using (StreamWriter writer = new StreamWriter(symfilename, false, encoding))
            {
                wait.DoEvents("GrepAllStructPointers");
                AsmMapFile asmMapFile = new AsmMapFile();

                DisassemblerTrumb Disassembler = new DisassemblerTrumb(asmMapFile);


                List <DisassemblerTrumb.LDRPointer> ldrmap = DisassemblerTrumb.MakeLDRMap(Program.ROM.Data, 0x100);

                List <Address> structlist = new List <Address>();
                //no$gbaは32546lines以上の symを読みこむと落ちるので手加減する.
                //                List<Address> structlist = U.MakeAllStructPointersList(); //既存の構造体
                U.AppendAllASMStructPointersList(structlist
                                                 , ldrmap
                                                 , isPatchInstallOnly: true
                                                 , isPatchPointerOnly: false
                                                 , isPatchStructOnly: false
                                                 , isUseOtherGraphics: false
                                                 , isUseOAMSP: false
                                                 );
                asmMapFile.AppendMAP(structlist);

                //コメントデータ
                Program.CommentCache.MakeAddressList(structlist);
                asmMapFile.AppendMAP(structlist);

                uint   lastNumber = 0;
                string line;
                Dictionary <uint, AsmMapFile.AsmMapSt> asmmap = asmMapFile.GetAsmMap();
                foreach (var pair in asmmap)
                {
                    if (pair.Key == 0x0 || pair.Key == U.NOT_FOUND)
                    {
                        continue;
                    }
                    if (pair.Key >= 0x08000000 && pair.Key <= 0x08000200)
                    {
                        continue;
                    }

                    if (pair.Value.IsPointer)
                    {//ポインタデータは不要
                        continue;
                    }

                    //長いと不便なので、名前以外不要.
                    string name = pair.Value.Name;
                    name = U.term(name, "\t");
                    name = name.Replace(" ", "_"); //スペースがあるとダメらしい.

                    if (name.IndexOf("6CStructHeader") >= 0)
                    {//6Cは全部表示する
                    }
                    else
                    {
                        uint arrayNumner = ParseArrayIndex(name);
                        if (arrayNumner >= 10)
                        {//容量削減のため2桁の配列は1つのみ
                            if (lastNumber == arrayNumner)
                            {
                                continue;
                            }
                            lastNumber = arrayNumner;
                        }
                    }

                    line = string.Format("{0} {1}", U.ToHexString(pair.Key), name);

                    writer.WriteLine(line);
                }
            }
        }
Esempio n. 10
0
        public static void RunAllMakeMAPFileButton(Form self)
        {
            if (InputFormRef.IsPleaseWaitDialog(self))
            {//2重割り込み禁止
                return;
            }

            string title  = R._("保存するファイル名を選択してください");
            string filter = R._("MAP|*.map|TEXT|*.txt|All files|*");

            SaveFileDialog save = new SaveFileDialog();

            save.Title  = title;
            save.Filter = filter;
            save.ShowDialog();
            if (save.FileNames.Length <= 0 || !U.CanWriteFileRetry(save.FileNames[0]))
            {
                return;
            }

            using (InputFormRef.AutoPleaseWait wait = new InputFormRef.AutoPleaseWait(self))
                using (StreamWriter writer = new StreamWriter(save.FileNames[0]))
                {
                    writer.WriteLine(" Start         Length     Name                   Class");

                    wait.DoEvents("GrepAllStructPointers");
                    AsmMapFile asmMapFile = new AsmMapFile();

                    DisassemblerTrumb Disassembler = new DisassemblerTrumb(asmMapFile);



                    List <DisassemblerTrumb.LDRPointer> ldrmap = DisassemblerTrumb.MakeLDRMap(Program.ROM.Data, 0x100);

                    List <Address> structlist = U.MakeAllStructPointersList(false); //既存の構造体
                    U.AppendAllASMStructPointersList(structlist
                                                     , ldrmap
                                                     , isPatchInstallOnly: false
                                                     , isPatchPointerOnly: false
                                                     , isPatchStructOnly: false
                                                     , isUseOtherGraphics: true
                                                     , isUseOAMSP: true
                                                     );
                    AsmMapFile.MakeFreeDataList(structlist, 0x100, 0x00, 16); //フリー領域
                    AsmMapFile.MakeFreeDataList(structlist, 0x100, 0xFF, 16); //フリー領域
                    asmMapFile.AppendMAP(structlist);

                    //コメントデータ
                    Program.CommentCache.MakeAddressList(structlist);
                    asmMapFile.AppendMAP(structlist);


                    string line;
                    Dictionary <uint, AsmMapFile.AsmMapSt> asmmap = asmMapFile.GetAsmMap();
                    foreach (var pair in asmmap)
                    {
                        if (pair.Key == 0x0 || pair.Key == U.NOT_FOUND)
                        {
                            continue;
                        }
                        if (pair.Key >= 0x08000000 && pair.Key <= 0x08000200)
                        {
                            continue;
                        }
                        //長いと不便なので、名前以外不要.
                        string name = pair.Value.Name;
                        name = U.term(name, "\t");

                        if (pair.Value.Length > 0)
                        {
                            line = string.Format(" 0000:{0} 0{1}H {2}  DATA", U.ToHexString(pair.Key), pair.Value.Length.ToString("X08"), name);
                        }
                        else
                        {
                            line = string.Format(" 0000:{0}       {1}", U.ToHexString(pair.Key), name);
                        }

                        writer.WriteLine(line);
                    }
                }

            //エクスプローラで選択しよう
            U.SelectFileByExplorer(save.FileNames[0]);
        }
Esempio n. 11
0
        public static void RunAllDisASMButton(Form self)
        {
            if (InputFormRef.IsPleaseWaitDialog(self))
            {//2重割り込み禁止
                return;
            }

            string title  = R._("保存するファイル名を選択してください");
            string filter = R._("TEXT|*.txt|All files|*");

            SaveFileDialog save = new SaveFileDialog();

            save.Title  = title;
            save.Filter = filter;
            save.ShowDialog();
            if (save.FileNames.Length <= 0 || !U.CanWriteFileRetry(save.FileNames[0]))
            {
                return;
            }

            uint addr = 0x100;


            using (InputFormRef.AutoPleaseWait wait = new InputFormRef.AutoPleaseWait(self))
                using (StreamWriter writer = new StreamWriter(save.FileNames[0]))
                {
                    writer.WriteLine("//FEBuilderGBA " + R._("逆アセンブラ"));

                    wait.DoEvents("GrepAllStructPointers");

                    AsmMapFile asmMapFile = new AsmMapFile();

                    DisassemblerTrumb Disassembler = new DisassemblerTrumb(asmMapFile);

                    List <DisassemblerTrumb.LDRPointer> ldrmap = DisassemblerTrumb.MakeLDRMap(Program.ROM.Data, 0x100);

                    List <Address> structlist = U.MakeAllStructPointersList(false); //既存の構造体
                    U.AppendAllASMStructPointersList(structlist
                                                     , ldrmap
                                                     , isPatchInstallOnly: false
                                                     , isPatchPointerOnly: false
                                                     , isPatchStructOnly: false
                                                     , isUseOtherGraphics: true
                                                     , isUseOAMSP: true
                                                     );
                    UnpackBINByCode(structlist);

                    AsmMapFile.MakeFreeDataList(structlist, 0x100, 0x00, 16); //フリー領域
                    AsmMapFile.MakeFreeDataList(structlist, 0x100, 0xFF, 16); //フリー領域
                    asmMapFile.AppendMAP(structlist);

                    //コメントデータ
                    Program.CommentCache.MakeAddressList(structlist);
                    asmMapFile.AppendMAP(structlist);


                    {//設計をミスった。 綺麗なリストを作りたいので、もう一回読みこみなおそう...
                        AsmMapFile asmMapFile2 = new AsmMapFile();
                        asmMapFile2.MakeAllDataLength(structlist);
                    }

                    uint limit = (uint)Program.ROM.Data.Length;

                    int                     jisage          = 0;                             //字下げする数
                    string                  jisageSpaceData = "";                            //字下げに利用するマージンデータ
                    List <uint>             jmplabel        = new List <uint>();             //ジャンプラベル 字下げに使う
                    Dictionary <uint, uint> ldrtable        = new Dictionary <uint, uint>(); //LDR参照データがある位置を記録します. コードの末尾などにあります. 数が多くなるのでマップする.
                    AsmMapFile.MakeSwitchDataList(ldrtable, 0x100, 0);

                    wait.DoEvents(R._("データを準備中..."));
                    //探索を早くするために、データをアドレスへマッピングする. メモリを大量に使うが早い.
                    Dictionary <uint, Address> lookupStructMap = MakeAllStructMapping(structlist);
                    structlist = null;

                    uint    nextDoEvents = 0;
                    bool    prevPointer  = false; //ひとつ前がポインタだった
                    Address matchAddress;
                    DisassemblerTrumb.VM vm = new DisassemblerTrumb.VM();
                    while (addr < limit)
                    {
                        if (addr > nextDoEvents)
                        {//毎回更新するのは無駄なのである程度の間隔で更新して以降
                            wait.DoEvents(String.Format("{0}/{1}", addr, limit));
                            nextDoEvents = addr + 0xfff;
                        }


                        if (lookupStructMap.TryGetValue(addr, out matchAddress))
                        {
                            if (matchAddress.Pointer <= addr && addr < matchAddress.Pointer + 4)
                            {//ポインタ?
                                writer.WriteLine(U.toPointer(addr).ToString("X08") + " " + U.MakeOPData(addr, 4) + "   //POINTER " + matchAddress.Info);
                                addr += 4;
                            }
                            else
                            {//データ
                                uint newaddr = U.Padding2(matchAddress.Addr + matchAddress.Length);
                                uint length  = (newaddr - addr);
                                Debug.Assert(length < 10000000);
                                writer.WriteLine("{0} - {1} //{2} ({3}bytes)", U.toPointer(addr).ToString("X08"), U.toPointer(newaddr).ToString("X08"), matchAddress.Info, length);
                                addr = U.Padding4(newaddr);
                            }
                            prevPointer = true;
                            continue;
                        }

                        //LDR参照とスイッチ参照
                        if (ldrtable.ContainsKey(addr))
                        {//LDR参照のポインタデータが入っている
                            uint ldr = ldrtable[addr];
                            if (ldr == U.NOT_FOUND)
                            {//switch case
                                writer.WriteLine(U.toPointer(addr).ToString("X08") + " " + U.MakeOPData(addr, 4) + "   //SWITCH CASE");
                            }
                            else
                            {
                                writer.WriteLine(U.toPointer(addr).ToString("X08") + " " + U.MakeOPData(addr, 4) + "   //LDRDATA");
                            }
                            addr       += 4;
                            prevPointer = true;
                            continue;
                        }

                        if (prevPointer)
                        {//ひとつ前がポインタの場合、野生のポインタをチェック
                            uint data = Program.ROM.u32(addr);
                            if (U.isPointer(data))
                            {
                                if (lookupStructMap.TryGetValue(U.toOffset(data), out matchAddress))
                                {
                                    writer.WriteLine(U.toPointer(addr).ToString("X08") + " " + U.MakeOPData(addr, 4) + "   //Wild POINTER " + U.ToHexString8(data) + " " + matchAddress.Info);
                                    addr += 4;
                                    continue;
                                }
                            }
                        }

                        //ひとつ前はポインタではない.
                        prevPointer = false;

                        //Disassembler
                        DisassemblerTrumb.Code code =
                            Disassembler.Disassembler(Program.ROM.Data, addr, limit, vm);
                        if (code.Type == DisassemblerTrumb.CodeType.BXJMP)
                        {//関数の出口なので字下げをすべて取り消す.
                            jisage = 0;
                            jmplabel.Clear();
                            jisageSpaceData = "";
                        }
                        else
                        {
                            for (int i = 0; i < jmplabel.Count;)
                            {
                                if (addr >= jmplabel[i])
                                {
                                    jmplabel.RemoveAt(i);
                                    jisage--;
                                    jisageSpaceData = U.MakeJisageSpace(jisage);
                                    i = 0;
                                    continue;
                                }
                                i++;
                            }
                        }

                        writer.WriteLine(jisageSpaceData + U.toPointer(addr).ToString("X08") + " " + U.MakeOPData(addr, code.GetLength()) + "   " + code.ASM.ToLower() + code.Comment);

                        if (code.Type == DisassemblerTrumb.CodeType.CONDJMP //条件式なので字下げ開始
                            )
                        {
                            uint jumplabel = U.toOffset(code.Data);
                            if (addr < jumplabel)
                            {//とび先が自分より後ろであること. 前方はすでに過ぎてしまったので字下げできない.
                                jisage++;
                                jmplabel.Add(jumplabel);
                                jisageSpaceData = U.MakeJisageSpace(jisage);
                            }
                        }
                        else if (code.Type == DisassemblerTrumb.CodeType.BXJMP)
                        {//関数の終わりなので空行を入れる.
                            writer.WriteLine("");
                        }

                        if (code.Type == DisassemblerTrumb.CodeType.LDR)
                        {//LDR参照位置を記録していく.
                            ldrtable[code.Data2] = addr;
                        }

                        addr += code.GetLength();
                    }
                }

            //エクスプローラで選択しよう
            U.SelectFileByExplorer(save.FileNames[0]);
        }
Esempio n. 12
0
        static List <U.AddrResult> ScanWithoutUI(InputFormRef.AutoPleaseWait pleaseWait, bool useIgnoreData)
        {
            List <U.AddrResult> errorMapUI = new List <U.AddrResult>();
            List <U.AddrResult> maps       = MapSettingForm.MakeMapIDList();

            List <DisassemblerTrumb.LDRPointer> ldrmap;

            ldrmap = DisassemblerTrumb.MakeLDRMap(Program.ROM.Data, 0x100);

            //システム全体の問題
            {
                if (pleaseWait != null)
                {
                    pleaseWait.DoEvents(R._("システムチェック中"));
                }

                List <FELint.ErrorSt> errorList = FELint.ScanMAP(FELint.SYSTEM_MAP_ID, ldrmap);
                if (!useIgnoreData)
                {
                    errorList = FELint.HiddenErrorFilter(errorList);
                }

                if (errorList.Count > 0)
                {//エラーがある
                    U.AddrResult ar = new U.AddrResult();
                    ar.addr = FELint.SYSTEM_MAP_ID;
                    ar.name = R._("システム");
                    ar.tag  = (uint)errorList.Count;

                    errorMapUI.Add(ar);
                }
            }

            for (int i = 0; i < maps.Count; i++)
            {
                if (pleaseWait != null)
                {
                    pleaseWait.DoEvents(R._("調査中 {0}/{1}", i, maps.Count));
                }

                uint         mapid = (uint)i;
                U.AddrResult ar    = new U.AddrResult();

                //このマップのエラースキャン
                List <FELint.ErrorSt> errorList = FELint.ScanMAP(mapid, ldrmap);
                if (!useIgnoreData)
                {
                    errorList = FELint.HiddenErrorFilter(errorList);
                }
                if (errorList.Count <= 0)
                {//エラーがない
                    continue;
                }

                ar.addr = mapid;
                ar.name = maps[i].name;
                ar.tag  = (uint)errorList.Count;

                errorMapUI.Add(ar);
            }


            return(errorMapUI);
        }