Esempio n. 1
0
        public static byte[] Patch(byte[] Data, string UID)
        {
            // ToDo: Fix UID Cast

            byte[] Decrypted_Amiibo;
            if (IsEncrypted(Data))
            {
                Decrypted_Amiibo = Amiibo_Class.Decrypt(Data, Main_Form.AmiiKeys);
            }
            else
            {
                Decrypted_Amiibo = Data;
            }

            byte[] Password_Amiibo = Amiibo_Class.Generate_Password(UID);
            byte[] UID_Long        = NtagHelpers.StringToByteArrayFastest(UID);

            Array.Copy(UID_Long, 0x008, Decrypted_Amiibo, 0x000, 0x001);                        //Put LastChar of Long UID
            Array.Copy(new byte[] { 0x00, 0x00 }, 0x000, Decrypted_Amiibo, 0x002, 0x002);       //Reset Static Lock Bytes
            Array.Copy(UID_Long, 0x000, Decrypted_Amiibo, 0x1D4, 0x008);                        //Modify UID
            Array.Copy(new byte[] { 0x00, 0x00, 0x00 }, 0x000, Decrypted_Amiibo, 0x208, 0x003); //Reset Dynamic Lock Bytes
            Array.Copy(Password_Amiibo, 0x000, Decrypted_Amiibo, 0x214, 0x004);                 //Modify Password
            Array.Copy(new byte[] { 0x80, 0x80 }, 0x000, Decrypted_Amiibo, 0x218, 0x002);       //Reset PACK0 & PACK1

            return(Amiibo_Class.Encrypt(Decrypted_Amiibo, Main_Form.AmiiKeys));
        }
Esempio n. 2
0
        public void Pack(byte[] plain, byte[] tag)
        {
            byte[] cipher = new byte[NtagHelpers.NFC3D_AMIIBO_SIZE];

            // Generate keys
            var tagKeys  = GenerateKey(this.tag, plain);
            var dataKeys = GenerateKey(this.data, plain);

            // Init OpenSSL HMAC context
            HMac hmacCtx = new HMac(new Sha256Digest());

            // Generate tag HMAC
            hmacCtx.Init(new KeyParameter(tagKeys.hmacKey));
            hmacCtx.BlockUpdate(plain, 0x1D4, 0x34);
            hmacCtx.DoFinal(cipher, HMAC_POS_TAG);

            // Generate data HMAC
            hmacCtx.Init(new KeyParameter(dataKeys.hmacKey));
            hmacCtx.BlockUpdate(plain, 0x029, 0x18B);           // Data
            hmacCtx.BlockUpdate(cipher, HMAC_POS_TAG, 0x20);    // Tag HMAC
            hmacCtx.BlockUpdate(plain, 0x1D4, 0x34);            // Tag
            hmacCtx.DoFinal(cipher, HMAC_POS_DATA);

            // Encrypt
            dataKeys.Cipher(plain, cipher, true);

            // Convert back to hardware
            NtagHelpers.InternalToTag(cipher, tag);

            Array.Copy(plain, 0x208, tag, 0x208, 0x014);
        }
Esempio n. 3
0
        public bool Unpack(byte[] tag, byte[] plain)
        {
            byte[] internalBytes = NtagHelpers.GetInternalTag(tag);

            // Generate keys
            KeygenDerivedkeys dataKeys = GenerateKey(this.data, internalBytes);
            KeygenDerivedkeys tagKeys  = GenerateKey(this.tag, internalBytes);

            // Decrypt
            dataKeys.Cipher(internalBytes, plain, false);

            // Init OpenSSL HMAC context
            HMac hmacCtx = new HMac(new Sha256Digest());

            // Regenerate tag HMAC. Note: order matters, data HMAC depends on tag HMAC!
            hmacCtx.Init(new KeyParameter(tagKeys.hmacKey));
            hmacCtx.BlockUpdate(plain, 0x1D4, 0x34);
            hmacCtx.DoFinal(plain, HMAC_POS_TAG);

            // Regenerate data HMAC
            hmacCtx.Init(new KeyParameter(dataKeys.hmacKey));
            hmacCtx.BlockUpdate(plain, 0x029, 0x1DF);
            hmacCtx.DoFinal(plain, HMAC_POS_DATA);

            Array.Copy(tag, 0x208, plain, 0x208, 0x014);

            return
                (NativeHelpers.MemCmp(plain, internalBytes, HMAC_POS_DATA, 32) &&
                 NativeHelpers.MemCmp(plain, internalBytes, HMAC_POS_TAG, 32));
        }
Esempio n. 4
0
        public static string Get_Amiibo_LastModifiedDate(byte[] internalTag)
        {
            var Amiibo_Date_Buffer = new byte[0x02];

            Array.Copy(internalTag, 0x02C + 0x006, Amiibo_Date_Buffer, 0x000, Amiibo_Date_Buffer.Length);
            Array.Reverse(Amiibo_Date_Buffer);

            return(NtagHelpers.DateTimeFromTag((BitConverter.ToUInt16(Amiibo_Date_Buffer, 0))).ToShortDateString());
        }