Exemplo n.º 1
0
        public void ParseFile_bin(string filename)
        {
            List <string> Lines     = FrameworkCodes.ToList( );
            List <string> OrigLines = new List <string>( );

            CurrentFile = filename;

            try {
                Byte[] bytes = File.ReadAllBytes(filename);

                for (int i = 0; i + 3 < bytes.Length; i++)
                {
                    string bincode = "";
                    for (int j = 0; j < 4; j++)
                    {
                        bincode += Convert.ToString(bytes[i + j], 2).PadLeft(8, '0');
                    }
                    OrigLines.Add(bincode);

                    Lines.Add(Decompiler.Decode(bincode));
                }


                Lines.AddRange(Lines);

                _updateEditorDocument(OrigLines);

                _updateTextOutput(Lines);

                _updateDataOutput( );
            }
            catch (Exception except) {
                System.Windows.MessageBox.Show("Parse File Failed :\n" + except.Message);
                return;
            }
        }
Exemplo n.º 2
0
        public void ParseFile_coe(string filename)
        {
            List <string> Lines     = FrameworkCodes.ToList( );
            List <string> OrigLines = File.ReadAllLines(filename).ToList();

            CurrentFile = filename;

            int datawidth = 0, radix = 0;

            try {
                for (int i = 0; i < OrigLines.Count; i++)
                {
                    var tmpline = OrigLines[i].Split(';')[0].ToLower( );;
                    if (tmpline.Length == 0)
                    {
                        continue;
                    }
                    if (tmpline.StartsWith("memory_initialization_radix"))
                    {
                        switch (Convert.ToInt32(tmpline.Split(new char[] { ' ', '=' }, StringSplitOptions.RemoveEmptyEntries)[1]))
                        {
                        case 2:
                            datawidth = 32;
                            radix     = 2;
                            break;

                        //case 8:
                        //	datawidth = 2;
                        // radix = 8;
                        // break;
                        case 16:
                            datawidth = 8;
                            radix     = 16;
                            break;
                        }
                    }
                    if (tmpline.StartsWith("memory_initialization_vector"))
                    {
                        var tmplst = tmpline.Split(new char[] { ' ', '=' }, StringSplitOptions.RemoveEmptyEntries);
                        if (tmplst.Length > 1)
                        {
                            tmpline = tmplst[1];
                        }
                        else
                        {
                            tmpline = string.Empty;
                        }
                        while (!tmpline.Contains(';'))
                        {
                            tmpline += OrigLines[++i].Replace(",", "").Replace(" ", "");
                        }
                        tmpline = tmpline.Replace(";", "");
                        for (int j = 0; j + datawidth < tmpline.Length; j += datawidth)
                        {
                            var tmpstr = Convert.ToString(Convert.ToUInt32(tmpline.Substring(j, datawidth), radix), 2).PadLeft(32, '0');
                            Lines.Add(Decompiler.Decode(tmpstr));
                        }
                    }
                }

                _updateEditorDocument(OrigLines);

                _updateTextOutput(Lines);

                _updateDataOutput( );
            }
            catch (Exception except) {
                System.Windows.MessageBox.Show("Parse File Failed :\n" + except.Message);
                return;
            }
        }