Esempio n. 1
0
 public MemoryCardMifareClassicSectorControl(MemoryCardMifareClassic Card, MemoryCardMifareClassic.Sector Sector)
 {
     InitializeComponent();
     this.Card   = Card;
     this.Sector = Sector;
     PrintData();
 }
Esempio n. 2
0
 public MemoryCardMifareClassicSectorControl(MemoryCardMifareClassic Card, int sectorCounter)
 {
     SectorNumber = sectorCounter;
     InitializeComponent();
     this.Card     = Card;
     this.Sector   = null;
     lbSector.Text = sectorCounter.ToString();
     PrintData();
 }
        public MemoryCardMifareClassicControl(MemoryCardMifareClassic card)
        {
            InitializeComponent();
            MemoryCardMifareClassicSectorControl sector_control;

            foreach (KeyValuePair <int, MemoryCardMifareClassic.Sector> pair in card.Sectors)
            {
                Logger.Trace("Display sector " + pair.Key);
                if (pair.Value == null)
                {
                    sector_control = new MemoryCardMifareClassicSectorControl(card, pair.Key);
                }
                else
                {
                    sector_control = new MemoryCardMifareClassicSectorControl(card, pair.Value);
                }
                sector_control.Dock = DockStyle.Top;
                this.Controls.Add(sector_control);
                sector_control.BringToFront();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Write changes to card
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void BtWriteToCardClick(object sender, EventArgs e)
        {
            // @TODO: Interdire la modification du block 0
            byte[] b = getDataFromHexbox();
            if (b == null)
            {
                return;
            }

            MemoryCardMifareClassic.Sector newSector = new MemoryCardMifareClassic.Sector(Sector.Number);

            /* Fill the sector data */
            int firstBlockAddress = MemoryCardMifareClassic.SectorFirstBlockAddress(Sector.Number);
            int lastBlockAddress  = MemoryCardMifareClassic.SectorTrailerAddress(Sector.Number) - 1;            // Excluded trailer def.
            int startingAddress   = 0;

            for (int address = 0; address < 3; address++)
            {
                byte[] data = new byte[16];
                Array.Copy(b, startingAddress, data, 0, 16);
                startingAddress += 16;
                Logger.Trace("Content " + BinConvert.ToHex(data));
                newSector.SetBlock(address, data);
            }

            bool success = false;

            /* Write data */
            if (Card.WriteSector(newSector))
            {
                success = true;
            }
            else
            {
                // Can't write, we are going to try with a key
                string  message = String.Format("Please enter the key to write sector {0}:", SectorNumber);
                KeyForm keyForm = new KeyForm(message, KeyForm.KeyType.writing);

                if (keyForm.ShowDialog() != DialogResult.Cancel)
                {
                    if (newSector.setWritingKeyFromString(keyForm.getUserKey()))
                    {
                        if (Card.WriteSector(newSector))
                        {
                            success = true;
                        }
                        else
                        {
                            MessageBox.Show(this.Parent,
                                            "There has been an error while writing the sector.",
                                            "Writing failed",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show(this.Parent,
                                        "The application is unable to use the specified key.",
                                        "Internal error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                }
            }

            if (success)
            {
                MessageBox.Show(this.Parent,
                                "The sectors's content has been successfully updated !",
                                "Writing succeeded",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }

            btWriteToCard.Enabled = false;
        }