Exemple #1
0
        static void Main(string[] args)
        {
            var keyManager = new KeyManager();

            keyManager.LoadKeys("keys/");

            if (!keyManager.HasFixedKey())
            {
                throw new Exception("Fixed key is not initialized properly.");
            }
            if (!keyManager.HasUnFixedKey())
            {
                throw new Exception("UnFixed key is not initialized properly.");
            }

            var tagData = TagUtil.ReadTag("amiibos/amiibo.bin");

            MifareUltralight mifare = MifareUltralight.GetTagInfo();

            if (mifare == null)
            {
                throw new Exception("Error getting tag data. Possibly not a NTAG215");
            }

            Console.WriteLineFormatted("Creating an amiibo NTAG is {0}, press a key to continue.", Color.Red, Color.White, "not reversable");
            Console.ReadLine();

            TagWriter.WriteToTagAuto(mifare, tagData, keyManager);

            mifare.Close();
        }
Exemple #2
0
        public static void ValidateTag(byte[] data)
        {
            byte[][] pages = TagUtil.SplitPages(data);

            if (pages[0][0] != (byte)0x04)
            {
                throw new Exception("Invalid tag file. Tag must start with a 0x04.");
            }

            if (pages[2][2] != (byte)0x0F || pages[2][3] != (byte)0xE0)
            {
                throw new Exception("Invalid tag file. lock signature mismatch.");
            }

            if (pages[3][0] != (byte)0xF1 || pages[3][1] != (byte)0x10 || pages[3][2] != (byte)0xFF || pages[3][3] != (byte)0xEE)
            {
                throw new Exception("Invalid tag file. CC signature mismatch.");
            }

            if (pages[0x82][0] != (byte)0x01 || pages[0x82][1] != (byte)0x0 || pages[0x82][2] != (byte)0x0F)
            {
                throw new Exception("Invalid tag file. dynamic lock signature mismatch.");
            }

            if (pages[0x83][0] != (byte)0x0 || pages[0x83][1] != (byte)0x0 || pages[0x83][2] != (byte)0x0 || pages[0x83][3] != (byte)0x04)
            {
                throw new Exception("Invalid tag file. CFG0 signature mismatch.");
            }

            if (pages[0x84][0] != (byte)0x5F || pages[0x84][1] != (byte)0x0 || pages[0x84][2] != (byte)0x0 || pages[0x84][3] != (byte)0x00)
            {
                throw new Exception("Invalid tag file. CFG1 signature mismatch.");
            }
        }
Exemple #3
0
        static byte[] AdjustTag(KeyManager keyManager, byte[] tagData, MifareUltralight mifare)
        {
            byte[] pages = mifare.ReadPages(0);
            if (pages == null || pages.Length != TagUtil.PAGE_SIZE * 4)
            {
                throw new Exception("Read failed! Unexpected read size.");
            }

            return(TagUtil.PatchUid(pages, tagData, keyManager, true));
        }
Exemple #4
0
        static void WritePassword(MifareUltralight tag)
        {
            byte[] pages0_1 = tag.ReadPages(0);

            if (pages0_1 == null || pages0_1.Length != TagUtil.PAGE_SIZE * 4)
            {
                throw new Exception("Read failed");
            }

            byte[] uid      = TagUtil.UidFromPages(pages0_1);
            byte[] password = TagUtil.Keygen(uid);

            tag.WritePage(0x86, new byte[] { (byte)0x80, (byte)0x80, (byte)0, (byte)0 });

            tag.WritePage(0x85, password);
        }
Exemple #5
0
        public static bool WriteToTagAuto(MifareUltralight mifare, byte[] tagData, KeyManager keyManager)
        {
            tagData = AdjustTag(keyManager, tagData, mifare);

            if (!Validate(mifare, tagData) || !ValidateBlankTag(mifare))
            {
                return(false);
            }

            try
            {
                byte[][] pages = TagUtil.SplitPages(tagData);
                WritePages(mifare, 3, 129, pages);
                Console.WriteLine("Wrote main data", Color.Green);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error while writing main data (stage 1)", Color.Red);
                return(false);
            }

            try
            {
                WritePassword(mifare);
                Console.WriteLine("Wrote password", Color.Green);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error while setting password (stage 2)", Color.Red);
                return(false);
            }

            try
            {
                WriteLockInfo(mifare);
                Console.WriteLine("Wrote lock info", Color.Green);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error while setting lock info (stage 3)", Color.Red);
                return(false);
            }

            return(true);
        }