AsmMapFile MakeBaseSymbol() { AsmMapFile map = new AsmMapFile(Program.ROM); if (Program.ROM.RomInfo.version == 0) { return(map); } { List <Address> list = new List <Address>(50000); uint maxcount = MapSettingForm.GetDataCount(); for (uint mapid = 0; mapid < maxcount; mapid++) { //イベント命令 一覧の取得(開始イベントと終了イベントのみ) List <U.AddrResult> eventlist = EventCondForm.MakeEventScriptPointerStartAndEndEventOnly(mapid); for (int i = 0; i < eventlist.Count; i++) { if (!U.isSafetyOffset(eventlist[i].addr)) { continue; } Address.AddAddress(list , eventlist[i].addr , 4 , U.NOT_FOUND , eventlist[i].name , Address.DataTypeEnum.EVENTSCRIPT); } } map.AppendMAP(list, "EVENT"); } //イベント命令にあるASM命令 { List <Address> list = new List <Address>(0x40); EventScript.MakeEventASMMAPList(list, false, "", true); map.AppendMAP(list); } //イベント命令にあるEVENT命令 { List <Address> list = new List <Address>(0x40); EventScript.MakeEventASMMAPList(list, true, "", true); map.AppendMAP(list, "EVENT"); } map.MakeNearSearchSortedList(); return(map); }
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(Program.ROM); DisassemblerTrumb Disassembler = new DisassemblerTrumb(asmMapFile); List <DisassemblerTrumb.LDRPointer> ldrmap = Program.AsmMapFileAsmCache.GetLDRMapCache(); List <Address> structlist = U.MakeAllStructPointersList(false); //既存の構造体 U.AppendAllASMStructPointersList(structlist , ldrmap , isPatchInstallOnly: false , isPatchPointerOnly: false , isPatchStructOnly: false , isUseOtherGraphics: true , isUseOAMSP: true ); AsmMapFile.InvalidateUNUNSED(structlist); MakeFreeData(structlist); 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]); }
public static void MakeAllDisASMButton(Form self, string store_filename, bool notifyUpdateMessage) { uint addr = 0x100; using (InputFormRef.AutoPleaseWait wait = new InputFormRef.AutoPleaseWait(self)) using (StreamWriter writer = new StreamWriter(store_filename)) { writer.WriteLine("//FEBuilderGBA " + R._("逆アセンブラ")); if (notifyUpdateMessage) { writer.WriteLine("//" + DateTime.Now.ToString("yyyyMMdd") + " " + R._("ソースコードを更新する場合は、このファイル消すか、0バイトの空ファイルにしてください。")); } wait.DoEvents("GrepAllStructPointers"); AsmMapFile asmMapFile = new AsmMapFile(Program.ROM); DisassemblerTrumb Disassembler = new DisassemblerTrumb(asmMapFile); List <DisassemblerTrumb.LDRPointer> ldrmap = Program.AsmMapFileAsmCache.GetLDRMapCache(); List <Address> structlist = U.MakeAllStructPointersList(false); //既存の構造体 U.AppendAllASMStructPointersList(structlist , ldrmap , isPatchInstallOnly: false , isPatchPointerOnly: false , isPatchStructOnly: false , isUseOtherGraphics: true , isUseOAMSP: true ); AsmMapFile.InvalidateUNUNSED(structlist); UnpackBINByCode(structlist); MakeFreeData(structlist); asmMapFile.AppendMAP(structlist); //コメントデータ Program.CommentCache.MakeAddressList(structlist); asmMapFile.AppendMAP(structlist); {//設計をミスった。 綺麗なリストを作りたいので、もう一回読みこみなおそう... AsmMapFile asmMapFile2 = new AsmMapFile(Program.ROM); asmMapFile2.MakeAllDataLength(structlist); AsmMapFile.InvalidateUNUNSED(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(); } } if (self != null) { //エクスプローラで選択しよう U.SelectFileByExplorer(store_filename); } }
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(Program.ROM); DisassemblerTrumb Disassembler = new DisassemblerTrumb(asmMapFile); List <DisassemblerTrumb.LDRPointer> ldrmap = Program.AsmMapFileAsmCache.GetLDRMapCache(); List <Address> structlist = new List <Address>(50000); //昔のno$gbaは32546lines以上の symを読みこむと落ちるので手加減する. U.AppendAllASMStructPointersList(structlist , ldrmap , isPatchInstallOnly: true , isPatchPointerOnly: false , isPatchStructOnly: false , isUseOtherGraphics: false , isUseOAMSP: false ); AsmMapFile.InvalidateUNUNSED(structlist); asmMapFile.AppendMAP(structlist); //コメントデータ Program.CommentCache.MakeAddressList(structlist); asmMapFile.AppendMAP(structlist); 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 = ConvertNoDollGBASymName(name); if (name == "") {//名前が空 continue; } if (pair.Value.TypeName == "ARM") { string line = string.Format("{0} .arm", U.ToHexString(pair.Key), ".arm"); writer.WriteLine(line); } else if (pair.Value.TypeName == "ASM" || U.toOffset(pair.Key) < Program.ROM.RomInfo.compress_image_borderline_address) { string line = string.Format("{0} .thumb", U.ToHexString(pair.Key)); writer.WriteLine(line); } { string line = string.Format("{0} {1}", U.ToHexString(pair.Key), name); writer.WriteLine(line); } } } }
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); }
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); }
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); } } }