예제 #1
0
        uint get_total_devices()
        {
            DevStruct devstruct;
            uint      dll_version = 0;
            uint      num_mfcs    = 0;
            uint      num_devices = 0;

            GetDllInfo(ref dll_version, ref num_mfcs);
            //Iterate over the entire manufacturers
            for (uint i = 0; i < num_mfcs; i++)
            {
                MfcStruct mfcstruct = new MfcStruct();
                GetMfcStru(i, ref mfcstruct);
                //Iterate over the entire devices in the curent manufacturer
                for (uint k = 0; k < mfcstruct.num_devs; k++)
                {
                    //Get the device struct
                    devstruct = (DevStruct)Marshal.PtrToStructure(new IntPtr(mfcstruct.devs.ToInt32() + k * Marshal.SizeOf(new DevStruct())), typeof(DevStruct));

                    //Skip devices marked as not ready yet
                    if ((devstruct.opts8 & 0x10000000) == 0)
                    {
                        num_devices++;
                    }
                }
            }
            return(num_devices);
        }
예제 #2
0
        //Populate the manufacturers list
        private void populate_mfc_list()
        {
            try
            {
                uint[]    manufacturers = new uint[4096];
                MfcStruct b             = new MfcStruct();
                MfcList.Items.Clear();
                DeviceList.Items.Clear();
                uint num_mfcs = GetIcMFC(SearchBox.Text.ToUpper(), manufacturers, GetIcType(), 0x20000000);
                for (int i = 0; i < num_mfcs; i++)
                {
                    GetMfcStru(manufacturers[i], ref b);
                    MfcList.Items.Add(b.manufacturer_name);
                }
                MfcList.Tag = manufacturers;
                if (MfcList.Items.Count > 0)
                {
                    MfcList.SelectedIndex = 0;
                }

                label_total.Text = "Total Devices:" + get_total_devices().ToString();
            }
            catch
            {
                foreach (Control control in this.Controls)
                {
                    control.Enabled = false;
                }
            }
        }
예제 #3
0
        //manufacturers list selection was changed
        private void MfcList_SelectedIndexChanged(System.Object sender, System.EventArgs e)
        {
            MfcStruct mfcstruct = new MfcStruct();

            uint[] tag = (uint[])MfcList.Tag;
            GetMfcStru(tag[MfcList.SelectedIndex], ref mfcstruct);
            LogoImage.Image = GetBitmapFromResources(mfcstruct.logo);
            Label1.Text     = mfcstruct.manufacturer_description;
            uint[]    devices   = new uint[4096];
            DevStruct devstruct = new DevStruct();

            DeviceList.Items.Clear();
            for (int i = 0; i < GetIcList(SearchBox.Text.ToUpper(), devices, (uint)tag[MfcList.SelectedIndex], GetIcType()); i++)
            {
                //Skip devices marked as not ready yet
                GetIcStru((uint)tag[MfcList.SelectedIndex], devices[i], ref devstruct);
                if ((devstruct.opts8 & 0x10000000) != 0)
                {
                    continue;
                }
                DeviceList.Items.Add(devstruct.name);
            }
            DeviceList.Tag = devices;
            if (DeviceList.Items.Count > 0)
            {
                DeviceList.SelectedIndex = 0;
            }
            label_mfc.Text = "Manufacturers:" + MfcList.Items.Count.ToString();
        }
예제 #4
0
        //Perform the infoic.dll dump
        private void dump_database()
        {
            DevStruct        devstruct;
            List <DevStruct> devices_list         = new List <DevStruct>();
            List <string>    duplicates           = new List <string>();
            List <string>    device_list_ini      = new List <string>();
            List <string>    device_list_c        = new List <string>();
            SortedDictionary <uint, string> total = new SortedDictionary <uint, string>();

            uint dll_version = 0;
            uint num_mfcs    = 0;

            GetDllInfo(ref dll_version, ref num_mfcs);
            //Iterate over the entire manufacturers
            for (uint i = 0; i < num_mfcs; i++)
            {
                MfcStruct mfcstruct = new MfcStruct();
                GetMfcStru(i, ref mfcstruct);
                //Iterate over the entire devices in the curent manufacturer
                for (uint k = 0; k < mfcstruct.num_devs; k++)
                {
                    //Get the device struct
                    devstruct = (DevStruct)Marshal.PtrToStructure(new IntPtr(mfcstruct.devs.ToInt32() + k * Marshal.SizeOf(new DevStruct())), typeof(DevStruct));

                    //Skip devices marked as not ready yet
                    if ((devstruct.opts8 & 0x10000000) != 0)
                    {
                        continue;
                    }

                    //Remove spaces
                    devstruct.type   &= 0xff;
                    devstruct.name    = devstruct.name.Replace(" ", "");
                    devstruct.chip_id = change_endianess(devstruct.chip_id, devstruct.chip_id_bytes_count);

                    //Add device to list
                    devstruct.category |= (i << 8);
                    devices_list.Add(devstruct);
                    //Log the device
                    if (total.ContainsKey(devstruct.protocol_id))
                    {
                        total[devstruct.protocol_id] += devstruct.name + Environment.NewLine;
                    }
                    else
                    {
                        total.Add(devstruct.protocol_id, devstruct.name + Environment.NewLine);
                    }
                }
            }


            List <DevStruct> tmp_list   = new List <DevStruct>();
            List <DevStruct> clean_list = new List <DevStruct>();

            progressBar.Maximum = devices_list.Count;

            if (checkBox5.Checked)
            {
                int j = 0;
                while (j < devices_list.Count)
                {
                    if (!clean_list.Contains(devices_list[j]))
                    {
                        clean_list.Add(devices_list[j]);
                    }
                    else
                    {
                        duplicates.Add(devices_list[j].name);
                    }
                    j++;
                    progressBar.Value = j;
                    Application.DoEvents();
                }
                progressBar.Value = progressBar.Maximum;
            }
            else
            {
                clean_list = devices_list;
            }


            foreach (DevStruct d in clean_list)
            {
                devstruct = d;
                //Patch Microchip and Atmel controllers
                if ((devstruct.category & 0xff) == 2)
                {
                    string key = devstruct.name.Split('@')[0];
                    key = key.Split('(')[0];
                    if (microchip_csv_list.ContainsKey(key))
                    {
                        devstruct.chip_id = microchip_csv_list[key].DeviceID;
                    }
                    else if (atmel_csv_list.ContainsKey(key))
                    {
                        devstruct.chip_id = atmel_csv_list[key].DeviceID;
                    }
                }
                devstruct.name = devstruct.name.Replace("1.8v", "(1.8v)");
                devstruct.name = devstruct.name.Replace("((1.8v))", "(1.8v)");
                devstruct.name = devstruct.name.Replace("1.8V", "(1.8V)");
                devstruct.name = devstruct.name.Replace("((1.8V))", "(1.8V)");
                devstruct.name = devstruct.name.Replace("ISP", "ICSP");

                //Pass the device structure pointer to an external "C" patcher
                //The external patcher is implemented in plain C code
                Patch_Device(ref devstruct);

                tmp_list.Add(devstruct);
            }
            devices_list = tmp_list;
            tmp_list     = new List <DevStruct>();



            //Sort the list by category
            if (checkBox6.Checked == true)
            {
                for (uint i = 1; i < 7; i++)
                {
                    foreach (DevStruct d in devices_list)
                    {
                        if ((d.category & 0xff) == i)
                        {
                            tmp_list.Add(d);
                        }
                    }
                }
                devices_list = tmp_list;
            }

            //Convert
            foreach (DevStruct d in devices_list)
            {
                //Get the element in ini format
                if (checkBox2.Checked)
                {
                    device_list_ini.Add(get_ic_string_ini(d) + Environment.NewLine);
                }

                //Get the element in C header format
                if (checkBox1.Checked)
                {
                    device_list_c.Add(get_ic_string_c(d));
                }
            }
            try
            {
                //Write the devices.h file
                if (checkBox1.Checked)
                {
                    using (StreamWriter stream_writer = new StreamWriter("devices.h"))
                    {
                        foreach (string elem in device_list_c)
                        {
                            stream_writer.WriteLine(elem);
                        }
                    }
                }

                //write the devices.ini file
                if (checkBox2.Checked)
                {
                    using (StreamWriter stream_writer = new StreamWriter("devices.ini"))
                    {
                        foreach (string elem in device_list_ini)
                        {
                            stream_writer.WriteLine(elem);
                        }
                    }
                }

                //write the devices.xml file
                if (checkBox3.Checked)
                {
                    SortedDictionary <uint, XElement> cat = new SortedDictionary <uint, XElement>();
                    XElement   db    = new XElement("database");
                    XAttribute rattr = new XAttribute("device", "TL866II");
                    db.Add(rattr);
                    XElement devices;
                    foreach (DevStruct dev in devices_list)
                    {
                        XElement ic = new XElement("ic");
                        ic.Add(get_ic_xml(dev));
                        if (cat.ContainsKey((dev.category >> 8)))
                        {
                            cat[dev.category >> 8].Add(ic);
                        }
                        else
                        {
                            MfcStruct mfcstruct = new MfcStruct();
                            GetMfcStru(dev.category >> 8, ref mfcstruct);
                            devices = new XElement("manufacturer");
                            XAttribute manuf = new XAttribute("name", mfcstruct.manufacturer_name);
                            devices.Add(manuf);
                            devices.Add(ic);
                            cat.Add((dev.category >> 8), devices);
                        }
                    }

                    foreach (XElement dev in cat.Values)
                    {
                        db.Add(dev);
                    }
                    XElement root = new XElement("infoic");
                    root.Add(db);
                    XmlWriterSettings xws = new XmlWriterSettings();
                    xws.Indent = true;
                    xws.Indent = true;
                    XmlWriter xml_writer = XmlWriter.Create("Devices.xml", xws);
                    root.WriteTo(xml_writer);
                    xml_writer.Close();
                }

                //write the log.txt file
                if (checkBox4.Checked)
                {
                    using (StreamWriter stream_writer = new StreamWriter("log.txt"))
                    {
                        foreach (KeyValuePair <uint, string> key in total)
                        {
                            stream_writer.WriteLine("Protocol:0x" + key.Key.ToString("X2") + Environment.NewLine + key.Value);
                        }
                        stream_writer.Write(Environment.NewLine +
                                            devices_list.Count.ToString() + " devices in " +
                                            total.Count.ToString() + " protocols.");
                    }

                    using (StreamWriter stream_writer = new StreamWriter("duplicates.txt"))
                    {
                        foreach (string d in duplicates)
                        {
                            stream_writer.WriteLine(d);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Save error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                progressBar.Value = 0;
                return;
            }
            MessageBox.Show(this, "Dump was saved in " + Application.StartupPath, "InfoIc", MessageBoxButtons.OK, MessageBoxIcon.Information);
            progressBar.Value = 0;
        }
예제 #5
0
 private static extern void GetMfcStru(uint Manuf, ref MfcStruct mfstr);