Beispiel #1
0
        private void ReadAddressLookupTableFromFile(int startofsymboltable, int numberofsymbols,  AddressLookupCollection curAddressLookupCollection, string filename)
        {
            // find the address lookuptable
            // this table starts with 48 79 00 04
            int readstate = 0;
            int readaddress = 0;
            int lookuptablestartaddress = 0x00;

            // test
            readstate = -30;
            // test

            FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
            using (BinaryReader br = new BinaryReader(fs))
            {
                byte[] filebytes = br.ReadBytes((int)fs.Length);
                for (int t = 0; t < filebytes.Length; t++)
                {
                    byte b = filebytes[t];
                /*for (int t = 0; t < fs.Length; t++)
                {
                    byte b = br.ReadByte();*/
                    //4E 75 48 E7 01 30 26 6F 00 16 3E 2F 00 14 24 6F 00 10 60 00 00 0A
                    switch (readstate)
                    {
                        case -30:
                            if (b == 0x4E)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -29:
                            if (b == 0x75)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -28:
                            if (b == 0x48)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -27:
                            if (b == 0xE7)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -26:
                            if (b == 0x01)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -25:
                            if (b == 0x30)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -24:
                            if (b == 0x26)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -23:
                            if (b == 0x6F)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -22:
                            if (b == 0x00)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -21:
                            if (b == 0x16)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -20:
                            if (b == 0x3E)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -19:
                            if (b == 0x2F)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -18:
                            if (b == 0x00)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -17:
                            if (b == 0x14)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -16:
                            if (b == 0x24)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -15:
                            if (b == 0x6F)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -14:
                            if (b == 0x00)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -13:
                            if (b == 0x10)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -12:
                            if (b == 0x60)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -11:
                            if (b == 0x00)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -10:
                            if (b == 0x00)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;
                        case -9:
                            if (b == 0x0A)
                            {
                                readstate = 0;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = -30;
                            }
                            break;

                        case 0:
                            // waiting for first recognition char 48
                            if (b == 0x48)
                            {
                                lookuptablestartaddress = t;
                                readstate++;
                            }
                            break;
                        case 1:
                            // waiting for second char 79
                            if (b == 0x79)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = 0;
                            }
                            break;
                        case 2:
                            // waiting for third char 00
                            if (b == 0x00)
                            {
                                readstate++;
                            }
                            else
                            {
                                lookuptablestartaddress = 0x00;
                                readstate = 0;
                            }
                            break;
                        case 3:
                            // waiting for last char 04
                            if (fs.Length == 0x20000)
                            {
                                if (b == 0x06)
                                {
                                    readstate++;
                                }
                                else
                                {
                                    lookuptablestartaddress = 0x00;
                                    readstate = 0;
                                }
                            }
                            else
                            {
                                if (b == 0x04)
                                {
                                    readstate++;
                                }
                                else
                                {
                                    lookuptablestartaddress = 0x00;
                                    readstate = 0;
                                }
                            }
                            break;
                        default:
                            break;

                    }
                }
            }
            //fs.Flush();
            fs.Close();
            fs.Dispose();

            FileStream fs2 = new FileStream(filename, FileMode.Open, FileAccess.Read);
            fs2.Seek(lookuptablestartaddress + 2, SeekOrigin.Begin);
            readaddress = lookuptablestartaddress + 2;
            using (BinaryReader br = new BinaryReader(fs2))
            {
                for (int sc = 0; sc < numberofsymbols; sc++)
                {
                    if (readaddress >= startofsymboltable) break;
                    int sramaddress = 0;
                    int flashaddress = 0;
                    byte b = br.ReadByte();
                    flashaddress = b * 256 * 256 * 256;
                    b = br.ReadByte();
                    flashaddress += (b * 256 * 256);
                    b = br.ReadByte();
                    flashaddress += (b * 256);
                    b = br.ReadByte();
                    flashaddress += (b);
                    // 8 x dummy
                    b = br.ReadByte();
                    b = br.ReadByte();
                    b = br.ReadByte();
                    b = br.ReadByte();
                    b = br.ReadByte();
                    b = br.ReadByte();
                    b = br.ReadByte();
                    b = br.ReadByte();
                    // lees sram adres
                    b = br.ReadByte();
                    sramaddress = (b * 256);
                    b = br.ReadByte();
                    sramaddress += (b);
                    AddressLookupHelper alh = new AddressLookupHelper();
                    alh.Flash_address = flashaddress;
                    alh.Sram_adddress = sramaddress;
                    curAddressLookupCollection.Add(alh);
                    /*using (StreamWriter sw = new StreamWriter("lookupcollection.txt", true))
                    {
                        sw.WriteLine("Lookup entry: " + alh.Sram_adddress.ToString("X4") + " : " + alh.Flash_address.ToString("X6"));
                    }*/

                    // lees naar volgende 48 79
                    int tel = 0;
                    bool found = false;
                    int tstate = 0;
                    while (tel++ < 16 && !found)
                    {
                        byte tb = br.ReadByte();
                        switch (tstate)
                        {
                            case 0:
                                if (tb == 0x048) tstate++;
                                break;
                            case 1:
                                if (tb == 0x79) found = true;
                                else tstate = 0;
                                break;
                        }
                    }
                    // als niet gevonden.. ?
                    if (!found)
                    {
                        break;
                    }

                }
                //lees 4 bytes address
                /*
                for (int fa = 0; fa < 4; fa++)
                {

                }*/

            }
            //fs2.Flush();
            fs2.Close();
            fs2.Dispose();
            /*using (StreamWriter sw = new StreamWriter("lookupdump.txt", false))
            {
                foreach (AddressLookupHelper ah in m_addresslookup)
                {
                    sw.WriteLine("Helper: " + ah.Sram_adddress.ToString("X4") + " " + ah.Flash_address.ToString("X8"));
                }
            }*/
        }
 public bool Contains(AddressLookupHelper value)
 {
     // If value is not of type Int16, this will return false.
     return (List.Contains(value));
 }
 public int Add(AddressLookupHelper value)
 {
     return (List.Add(value));
 }
 public void Remove(AddressLookupHelper value)
 {
     List.Remove(value);
 }
 public void Insert(int index, AddressLookupHelper value)
 {
     List.Insert(index, value);
 }
 public int IndexOf(AddressLookupHelper value)
 {
     return (List.IndexOf(value));
 }