Ejemplo n.º 1
0
        public void TickleTickle()
        {
            STDFU.DFU_Status dfuStatus = new STDFU.DFU_Status();
            UInt32           Result    = STDFU.STDFU_SelectCurrentConfiguration(ref hDevice, 0, 0, 0);

            Console.WriteLine("SelectConfig Res: " + Result);
            STDFU.STDFU_GetStatus(ref hDevice, ref dfuStatus);
            STDFU.STDFU_ClrStatus(ref hDevice);
            // Console.WriteLine("DFU iString: " + dfuStatus.iString);
            // Console.WriteLine("DFU State: " + dfuStatus.bState);
            // Console.WriteLine("DFU STATUS: " + dfuStatus.bStatus);
            IntPtr strinng = Marshal.AllocHGlobal(256);

            Result = STDFU.STDFU_GetStringDescriptor(ref hDevice, 1, strinng, 256);
            // Console.WriteLine("StringDesc Res: " + Result);

            STDFU.STDFU_GetStatus(ref hDevice, ref dfuStatus);
            STDFU.STDFU_ClrStatus(ref hDevice);
            // Console.WriteLine("DFU iString: " + dfuStatus.iString);
            //Console.WriteLine("DFU State: " + dfuStatus.bState);
            //Console.WriteLine("DFU STATUS: " + dfuStatus.bStatus);
            byte[] bytes = new byte[256];
            Marshal.Copy(strinng, bytes, 0, 256);
            Marshal.FreeHGlobal(strinng);
            Console.WriteLine(Encoding.ASCII.GetString(bytes));
        }
Ejemplo n.º 2
0
        public string getDeviceDescriptor(uint index = 1)
        {
            STDFU.DFU_Status dfuStatus = new STDFU.DFU_Status();
            UInt32           Result    = STDFU.STDFU_SelectCurrentConfiguration(ref hDevice, 0, 0, 0);

            STDFU.STDFU_GetStatus(ref hDevice, ref dfuStatus);
            STDFU.STDFU_ClrStatus(ref hDevice);

            IntPtr strinng = Marshal.AllocHGlobal(256);

            STDFU.STDFU_GetStringDescriptor(ref hDevice, index, strinng, 256);

            STDFU.STDFU_GetStatus(ref hDevice, ref dfuStatus);
            STDFU.STDFU_ClrStatus(ref hDevice);

            byte[] bytes = new byte[256];
            Marshal.Copy(strinng, bytes, 0, 256);
            Marshal.FreeHGlobal(strinng);
            return(Encoding.ASCII.GetString(bytes));
        }
Ejemplo n.º 3
0
        public void WriteFirmware(byte[] data)
        {
            IntPtr strinng = Marshal.AllocHGlobal(255);

            STDFU.STDFU_GetStringDescriptor(ref hDevice, 1, strinng, 255);

            byte[] bytes = new byte[255];
            Marshal.Copy(strinng, bytes, 0, 255);


            String device = Encoding.ASCII.GetString(bytes).Trim();

            Console.WriteLine("Device: " + device);

            if (device.Equals("AnyRoad Technology"))
            {
                Console.WriteLine("Radio not in DFU Mode!");
                return;
            }

            byte[] tmp = new byte[14];
            Array.Copy(data, 0, tmp, 0, 14);
            if (Encoding.GetEncoding("ASCII").GetString(tmp) == "OutSecurityBin")
            {
                byte[] newdata = new byte[data.Length - 0x100];
                Array.Copy(data, 0x100, newdata, 0, newdata.Length);
                data = newdata;
            }

            uint[] addresses =
            {
                0x0800c000,
                0x08010000,
                0x08020000,
                0x08040000,
                0x08060000,
                0x08080000,
                0x080a0000,
                0x080c0000,
                0x080e0000
            };

            uint[] sizes =
            {
                0x4000,    // 0c
                0x10000,   // 1
                0x20000,   // 2
                0x20000,   // 4
                0x20000,   // 6
                0x20000,   // 8
                0x20000,   // a
                0x20000,   // c
                0x20000    // e
            };

            uint[] block_ends = { 0x11, 0x41, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81 };

            WaitUntilIdle();

            CustomCommand(0x91, 0x01);
            CustomCommand(0x91, 0x31);

            int jj = 0;

            foreach (uint addr in addresses)
            {
                progress = (int)((float)jj++ / (addresses.Length + 1) * 50.0) + 1;
                EraseSector(addr);
            }

            uint block_size  = 1024;
            uint block_start = 2;
            uint address_idx = 0;
            uint datawritten = 0;

            for (uint i = 0; i < addresses.Length && datawritten < data.Length; i++)
            {
                Console.WriteLine("\r" + (address_idx * 100 / addresses.Length) + "% complete");
                SetAddressPointer(addresses[i]);


                uint   block_number = block_start;
                byte[] buffa        = new byte[block_size];

                uint blk_data_len = 0;

                while (blk_data_len < sizes[i] && datawritten < data.Length)
                {
                    if (block_number > block_ends[address_idx])
                    {
                        // Console.WriteLine("Something bad happenin!");
                        return;
                    }

                    for (int b = 0; b < buffa.Length; b++)
                    {
                        buffa[b] = 0xFF;
                    }

                    uint dat_siz = (uint)data.Length - datawritten;
                    Array.Copy(data, datawritten, buffa, 0, (dat_siz < block_size ? dat_siz : block_size));
                    datawritten  += (dat_siz < block_size ? dat_siz : block_size);
                    blk_data_len += (dat_siz < block_size ? dat_siz : block_size);

                    WriteBlock(buffa, block_number);
                    WaitUntilIdle();

                    block_number++;
                    int stuff = (int)((float)datawritten / (float)(data.Length) * 50.0) + 50;
                    progress = (stuff == 0 ? 1 : stuff);
                }
                address_idx += 1;
            }
        }
Ejemplo n.º 4
0
        public void WriteFirmware_2017(byte[] data)
        {
            IntPtr strinng = Marshal.AllocHGlobal(255);

            STDFU.STDFU_GetStringDescriptor(ref hDevice, 1, strinng, 255);

            byte[] bytes = new byte[255];
            Marshal.Copy(strinng, bytes, 0, 255);


            String device = Encoding.ASCII.GetString(bytes).Trim();

            Console.WriteLine("Device: " + device);

            if (device.Equals("AnyRoad Technology"))
            {
                Console.WriteLine("Radio not in DFU Mode!");
                return;
            }

            byte[] tmp = new byte[14];
            Array.Copy(data, 0, tmp, 0, 14);
            if (Encoding.GetEncoding("ASCII").GetString(tmp) == "OutSecurityBin")
            {
                byte[] newdata = new byte[data.Length - 0x100];
                Array.Copy(data, 0x100, newdata, 0, newdata.Length);
                data = newdata;
            }

            //byte[] unkData = File.ReadAllBytes("C:\\TYT\\FW_2017_f.bin");

            uint[] addresses1 =
            {
                0x00060000,
                0x00070000,
                0x00080000,
                0x00090000,
                0x000a0000,
                0x000b0000,
                0x000c0000,
                0x000d0000,
                0x000e0000,
                0x000f0000,

                0x0800c000,
                0x08010000,
                0x08020000,
                0x08040000,
                0x08060000,
                0x08080000,
                0x080a0000,
                0x080c0000,
                0x080e0000
            };

            uint[] block_ends = { 0x11, 0x41, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81 };

            WaitUntilIdle();

            CustomCommand(0x91, 0x01);
            CustomCommand(0x91, 0x31);

            //CustomCommand(0xA2, 0x01);
            //CustomCommand(0xA2, 0x31);
            //CustomCommand(0xA2, 0x02);
            //CustomCommand(0xA2, 0x03);
            //CustomCommand(0xA2, 0x04);
            //CustomCommand(0xA2, 0x07);
            //CustomCommand(0x91, 0x31);



            int jj = 0;

            foreach (uint addr in addresses1)
            {
                progress = (int)((float)jj++ / (float)0.0) + 1;
                EraseSector(addr);
            }

            SetAddressPointer(0);

            uint block_size  = 1024;
            uint block_start = 2;
            uint address_idx = 0;
            uint datawritten = 0;

            for (; datawritten < data.Length;)
            {
                Console.WriteLine("\r" + "% complete");
                SetAddressPointer(addresses1[i]);


                uint   block_number = block_start;
                byte[] buffa        = new byte[block_size];

                uint blk_data_len = 0;

                if (block_number == 0x42)
                {
                }
                else
                {
                    for (int b = 0; b < buffa.Length; b++)
                    {
                        buffa[b] = 0xFF;
                    }

                    uint dat_siz = (uint)data.Length - datawritten;
                    Array.Copy(data, datawritten, buffa, 0, (dat_siz < block_size ? dat_siz : block_size));
                    datawritten  += (dat_siz < block_size ? dat_siz : block_size);
                    blk_data_len += (dat_siz < block_size ? dat_siz : block_size);

                    WriteBlock(buffa, block_number);
                    WaitUntilIdle();

                    block_number++;
                    int stuff = (int)((float)datawritten / (float)(data.Length) * 50.0) + 50;
                    progress = (stuff == 0 ? 1 : stuff);
                }
                address_idx += 1;
            }
        }