T8SuitePro.Disassembler.DisassembleFunction C# (CSharp) Method

DisassembleFunction() private method

private DisassembleFunction ( long addr, CommonSuite.SymbolCollection symbols, FileStream fs, BinaryReader br, long offset ) : void
addr long
symbols CommonSuite.SymbolCollection
fs System.IO.FileStream
br System.IO.BinaryReader
offset long
return void
        private void DisassembleFunction(long addr, SymbolCollection symbols, FileStream fs, BinaryReader br, long offset)
        {
            CastProgressEvent("Disassembling function: " + addr.ToString("X8"), func_count++, ProgressType.DisassemblingFunctions);
            //logger.Debug("DisassembleFunction: " + addr.ToString("X8"));
            MNemonicCollection functionList = new MNemonicCollection();

            MNemonicHelper label = new MNemonicHelper();
            //long realAddr = fs.Position + offset;
            //label.Mnemonic = "Function_" + realAddr.ToString("X8") + ":";
            label.Mnemonic = "Function_" + addr.ToString("X8") +":";
            label.Address = addr;
            if (AddressInMnemonicList(addr))
            {
                //logger.Debug("Already disassembled: " + addr.ToString("X8"));
                return ;
            }
            labels.Add(label);
            functionList.Add(label);
            long offaddr = 0;
            if (addr == 0) return ;
            if (addr > offset)
            {
                fs.Position = addr - offset;
            }
            else
            {
                fs.Position = addr;
            }

            bool endsub = false;
            bool issub = false;
            bool isjump = false;
            string str;
            while (!endsub)
            {
                byte ch1 = br.ReadByte();
                byte ch2 = br.ReadByte();
                uint i = (uint)((ch1 << 8) + ch2);
                uint seg = (uint)(((addr + offaddr) & 0xffff0000) >> 16);
                uint adr = (uint)(((addr + offaddr) & 0xffff));
                /*if (ch1 == 0x58 && ch2 == 0x8F)
                {
                    logger.Debug("break!");
                }*/
                uint t = disasm(out str, addr, ch1, ch2, offaddr, br, out endsub, out issub, out isjump);
                //logger.Debug(str);
                if (str != "")
                {
                    MNemonicHelper mnhelper = new MNemonicHelper();
                    mnhelper.Mnemonic = str;
                    mnhelper.Address = addr;
                    //realAddr = fs.Position + offset;
                    //mnhelper.Address = realAddr;
                    if (!AddressInMnemonicList(addr))
                    {
                        if (isjump)
                        {
                            TranslateLabels(mnhelper);
                        }
                        mnemonics.Add(mnhelper);
                    }
                    functionList.Add(mnhelper);
                }
                if (t > 5) t = 5;
                //addr += t;
                switch (t)
                {
                    case 0:
                    case 1:
                        addr += 2L;
                        break;
                    case 2:
                        addr += 4L;
                        break;
                    case 3:
                        addr += 6L;
                        break;
                    case 4:
                        addr += 8L;
                        break;
                    case 5:
                        addr += 10L;
                        break;
                }
                if (issub)
                {
                    /*if (trgdata == 0)
                    {
                        logger.Debug("break!");
                    }*/

                    // alleen als die nog niet geweest is
                    if (trgdata != 0)
                    {
                        if (!AddressInMnemonicList(trgdata))
                        {
                            if (trgdata < 0x00100000) // 0x00F00000 == T7
                            {
                                long position = fs.Position;
                                //logger.Debug("recursive: " + trgdata.ToString("X8") + " curr address: " + addr.ToString("X8"));
                                DisassembleFunction(trgdata, symbols, fs, br, offset);
                                //logger.Debug("After recursion: " + addr.ToString("X8"));
                                fs.Position = position; // reset to previous position
                            }
                        }
                    }
                }
                if (endsub)
                {
                }
            }

            //logger.Debug("Done with function: " + mnemonics.Count.ToString());
        }