public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
            {
                if (destType == typeof(string) && value is MNemonicHelper)
                {
                    // Cast the value to an Employee type
                    MNemonicHelper pp = (MNemonicHelper)value;

                    return(pp.Mnemonic + ", " + pp.Address.ToString("X8"));
                }
                return(base.ConvertTo(context, culture, value, destType));
            }
Exemplo n.º 2
0
 private void AddLabel(long trgaddr)
 {
     if (trgaddr < 0xF00000)
     {
         MNemonicHelper label = new MNemonicHelper();
         label.Address = trgaddr;
         label.Mnemonic = "LBL_" + trgaddr.ToString("X8") + ":";
         if (!_passOne)
         {
             if (!LabelPresent(trgaddr))
             {
                 labels.Add(label);
             }
         }
         else
         {
             if (!AddressInLabelList(trgaddr))
             {
                 _labels.Add(label);
             }
         }
     }
 }
Exemplo n.º 3
0
 private void TranslateLabels(MNemonicHelper mnemonic)
 {
     if (AddressInLabelList(mnemonic.Mnemonic))
     {
         foreach (MNemonicHelper label in _labels)
         {
             if (mnemonic.Mnemonic.Contains("JSR") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
             {
                 mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                 break;
             }
             else if (mnemonic.Mnemonic.Contains("BEQ") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
             {
                 mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                 break;
             }
             else if (mnemonic.Mnemonic.Contains("BRA") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
             {
                 mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                 break;
             }
             else if (mnemonic.Mnemonic.Contains("BLS") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
             {
                 mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                 break;
             }
             else if (mnemonic.Mnemonic.Contains("BNE") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
             {
                 mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                 break;
             }
             else if (mnemonic.Mnemonic.Contains("BHI") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
             {
                 mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                 break;
             }
             else if (mnemonic.Mnemonic.Contains("BCS") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
             {
                 mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                 break;
             }
             else if (mnemonic.Mnemonic.Contains("BCC") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
             {
                 mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                 break;
             }
             else if (mnemonic.Mnemonic.Contains("BGE") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
             {
                 mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                 break;
             }
             else if (mnemonic.Mnemonic.Contains("BLT") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
             {
                 mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                 break;
             }
             else if (mnemonic.Mnemonic.Contains("BGT") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
             {
                 mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                 break;
             }
             else if (mnemonic.Mnemonic.Contains("BLE") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
             {
                 mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                 break;
             }
         }
     }
 }
Exemplo n.º 4
0
        private void LoadLabels(long addr, FileStream fs, BinaryReader br, long offset)
        {
            //logger.Debug("Load labels from addr: " + addr.ToString("X8"));
            MNemonicHelper label = new MNemonicHelper();
            MNemonicCollection functionList = new MNemonicCollection();
            label.Mnemonic = "Function_" + addr.ToString("X8") + ":";
            label.Address = addr;

            if (AddressInLabelList(addr))
            {
                return;
            }
            _labels.Add(label);
            //logger.Debug("Added label: " + label.Mnemonic + " " + label.Address.ToString("X8"));

            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));
                uint t = disasm(out str, addr, ch1, ch2, offaddr, br, out endsub, out issub, out isjump);
                if (str != "")
                {
                    MNemonicHelper mnhelper = new MNemonicHelper();
                    mnhelper.Mnemonic = str;
                    mnhelper.Address = addr;
                    //realAddr = fs.Position + offset;
                    //mnhelper.Address = realAddr;
                    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)
                    {
                        if (!AddressInLabelList(trgdata))
                        {
                            if (trgdata < 0x00F00000)
                            {
                                long position = fs.Position;
                                LoadLabels(trgdata,  fs, br, offset);
                                fs.Position = position; // reset to previous position
                            }
                        }
                    }
                }
                if (endsub)
                {
                }
            }
        }
Exemplo n.º 5
0
        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 < 0x00F00000)
                            {
                                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());
        }
Exemplo n.º 6
0
 public bool Contains(MNemonicHelper value)
 {
     // If value is not of type Int16, this will return false.
     return (List.Contains(value));
 }
Exemplo n.º 7
0
 public int Add(MNemonicHelper value)
 {
     return (List.Add(value));
 }
Exemplo n.º 8
0
 public void Remove(MNemonicHelper value)
 {
     List.Remove(value);
 }
Exemplo n.º 9
0
 public void Insert(int index, MNemonicHelper value)
 {
     List.Insert(index, value);
 }
Exemplo n.º 10
0
 public int IndexOf(MNemonicHelper value)
 {
     return (List.IndexOf(value));
 }
 public bool Contains(MNemonicHelper value)
 {
     // If value is not of type Int16, this will return false.
     return(List.Contains(value));
 }
 public void Remove(MNemonicHelper value)
 {
     List.Remove(value);
 }
 public void Insert(int index, MNemonicHelper value)
 {
     List.Insert(index, value);
 }
 public int IndexOf(MNemonicHelper value)
 {
     return(List.IndexOf(value));
 }
 public int Add(MNemonicHelper value)
 {
     return(List.Add(value));
 }