Beispiel #1
0
        public ASMDecoderResult DecodeASM(string hex, uint pc, string spacePadding, bool littleEndian, bool includeAddress, bool useRegAliases, bool clearErrorText)
        {
            if (clearErrorText)
            {
                ClearErrorText();
            }

            //string[] lines = hex.Split('\n');
            //lines = ASMStringHelper.RemoveFromLines(lines, "\r");

            string[]      lines = ASMValueHelper.GetHexLines(hex);
            StringBuilder sb    = new StringBuilder();

            foreach (string line in lines)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                string strAddress = "[0x" + ASMValueHelper.UnsignedToHex_WithLength(pc, 8) + "] ";
                string strPrefix  = (includeAddress ? strAddress : "") + spacePadding;
                string modLine    = line.Replace(" ", "").Replace("\t", "");

                try
                {
                    uint uLine = Convert.ToUInt32(modLine, 16);
                    if (littleEndian)
                    {
                        uLine = ASMValueHelper.ReverseBytes(uLine);
                    }

                    string decodedLine = TryDecodeSingle(uLine, pc, useRegAliases);
                    sb.Append(strPrefix);
                    sb.Append(decodedLine);
                    sb.Append("\r\n");
                    pc += 4;
                }
                catch (Exception ex)
                {
                    _errorTextBuilder.AppendLine("FAILED TO DECODE LINE: " + line + " (" + ex.Message + ")");
                }
            }

            return(new ASMDecoderResult(sb.ToString(), _errorTextBuilder.ToString()));
        }