Ejemplo n.º 1
0
    private static readonly int MAX_FW_SIZE = 0x60000;             //Max is 384KB (128KB are reserved for Bootloader)

    static int Main(string[] args)
    {
        // Test if input arguments were supplied:
        if (args.Length != 2)
        {
            System.Console.WriteLine("FWextractor v0.1");
            System.Console.WriteLine("Please enter binary FW package and output file name.");
            System.Console.WriteLine("Usage: FWextractor <input FW binary> <output decoded FW binary>");
            return(1);
        }

        // Decode the FW.
        byte[]      FWdata    = new byte[MAX_FW_SIZE];
        Codec.CoDec extractor = new Codec.CoDec();
        int         result    = extractor.GetFW(args[0], FWdata);

        if (result > 0)
        {
            StreamWriter streamWriter;
            try
            {
                streamWriter = new StreamWriter(args[1]);
            }
            catch (Exception)
            {
                System.Console.WriteLine("Unable to generate output file:" + args[1]);
                return(-1);
            }
            streamWriter.BaseStream.Write(FWdata, 0, result * 2048);
            streamWriter.Close();
            System.Console.WriteLine("FW extracted ({0} blocks)", result);
            return(0);
        }
        else
        {
            System.Console.WriteLine("FW extraction failed!");
            return(1);
        }
    }
Ejemplo n.º 2
0
        private void Button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                InitialDirectory = AppDomain.CurrentDomain.BaseDirectory,
                Filter           = "FW files (*.lcd;*.twp)|*.lcd;*.twp|All files (*.*)|*.*",
                FilterIndex      = 1,
                RestoreDirectory = true
            };

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //Get the path of specified file
                filePath = openFileDialog.FileName;
                //Get the specified file extension
                fileExtension = Path.GetExtension(filePath);
                //If file extension is TWP update file magic
                if (string.Compare(fileExtension, 0, ".twp", 0, 4, true) == 0)
                {
                    fileMagic = TWP_FileMagic;
                }
                else
                {
                    fileMagic = LCD_FileMagic;
                }

                //Decode input file
                usedBlocks = FWCodec.GetFW(filePath, FWdata, fileMagic);
                if (usedBlocks > 0)
                {
                    //Read current colors
                    if (ReadColors() == 0)
                    {
                        //Update GUI
                        textBox1.Text = Brand + " " + Version;
                        UpdateGUIcolors();

                        //Enable save
                        button2.Enabled = true;
                        //Enable save theme
                        button13.Enabled = true;
                    }
                    else
                    {
                        textBox1.Text = "Unsupported";

                        //Disable save
                        button2.Enabled = false;
                    }
                }
                else
                {
                    if (usedBlocks == -4)
                    {
                        MessageBox.Show("Unable to open specified file", "FW file error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    if (usedBlocks == -3)
                    {
                        MessageBox.Show("Corrupted FW file", "FW file error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    if (usedBlocks == -2)
                    {
                        MessageBox.Show("Invalid FW file size", "FW file error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    if (usedBlocks == -1)
                    {
                        MessageBox.Show("Not a CBD FW file!", "FW file error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    button2.Enabled  = false;
                    button3.Enabled  = false;
                    button4.Enabled  = false;
                    button5.Enabled  = false;
                    button6.Enabled  = false;
                    button7.Enabled  = false;
                    button8.Enabled  = false;
                    button9.Enabled  = false;
                    button10.Enabled = false;
                }
            }
        }