private void UnPack()           //2018-03-27
        {
            //解密
            if (AmiiboData.Length < NtagHelpers.NFC3D_AMIIBO_SIZE)
            {
                byte[] AmiiboDataTemp = this.AmiiboData;
                Array.Resize(ref AmiiboDataTemp, NtagHelpers.NFC3D_AMIIBO_SIZE);
                this.AmiiboData = AmiiboDataTemp;
            }

            try
            {
                //AmiiKeys = AmiiboKeys.LoadKeys("KeyTemp.bin");
                //AmiiKeys = AmiiboKeys.LoadKeys(key_retail);
                AmiiKeys.Unpack(this.AmiiboData, Decrypted);
                this.AmiiboDataDecrypted = Decrypted;
                this.msgNFC = new Message_NFC(AmiiboDataDecrypted);

                msgTP  = new Message_TP(AmiiboDataDecrypted, msgNFC);
                msgSSB = new Message_SSB(AmiiboDataDecrypted, msgNFC);
            }
            catch
            {
            }
            this.NTAG_ID = GetFileString(0x00, 3) + GetFileString(0x04, 4);
            this.SerA    = GetFileString(0x54, 4);
            this.SerB    = GetFileString(0x58, 4);

            this.isBegin04 = (GetFileString(0x00, 1) == "04") ? true : false;
            IdMessage      = new AmiiboMessage(this.SerA + this.SerB);       //2018-01-25

            FileToCRC32 crc32 = new FileToCRC32();

            this.CRC32_Decrypted = crc32.ComputeCRC32(this.AmiiboDataDecrypted, 0x28, 0x18c);   //2018-01-27 0x28~0x1B3 396
            this.CRC32_block36   = crc32.ComputeCRC32(this.AmiiboDataDecrypted, 0x1e4, 0x24);   //2018-01-30 0x1E4~0x207 36

            getMcasName myMcasName = new getMcasName(this.CRC32);

            this.mcasName = myMcasName.Mcas_Name;

            this.NewName  = this.isBegin04 ? "" : "[E]";
            this.NewName += "[" + this.IdMessage.GameShortName + "]";
            this.NewName += " " + this.IdMessage.Number + "-" + this.IdMessage.AmiiboName + " ";
            this.NewName += "[" + this.CRC32_Decrypted + "-" + this.CRC32_block36 + "-" + this.NTAG_ID + "-" + this.Length.ToString("000") + "]";
            if (msgSSB.canEdit)
            {
                this.NewName += "(" + this.msgSSB.LEVEL + ")";
            }
            this.NewName += ".bin";

            this.NetPath     = "http://amiibo.life/nfc/" + this.SerA + "-" + this.SerB;
            this.PicturePath = "https://raw.githubusercontent.com/N3evin/AmiiboAPI/master/images/icon_" + this.SerA.ToLower() + "-" + this.SerB.ToLower() + ".png";
            //"image": "https://raw.githubusercontent.com/N3evin/AmiiboAPI/master/images/icon_00000000-00340102.png",
        }
Beispiel #2
0
        static int Main(string[] args)
        {
            try
            {
                p.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("amiitool: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `amiitool --help' for more information.");
                return(1);
            }

            if (showHelp || !(doEncrypt ^ doDecrypt) || keyFile == null)
            {
                ShowHelp();
                return(1);
            }

            AmiiboKeys amiiboKeys = AmiiboKeys.LoadKeys(keyFile);

            if (amiiboKeys == null)
            {
                Console.Error.WriteLine("Could not load keys from \"{0}\"", keyFile);
                return(5);
            }

            byte[] original = new byte[NTAG215_SIZE];
            byte[] modified = new byte[NtagHelpers.NFC3D_AMIIBO_SIZE];

            Stream file;

            try
            {
                file = File.OpenRead(inputFile);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Could not open input file: {0}", ex.Message);
                return(3);
            }

            int readBytes = 0;

            try
            {
                using (var reader = new BinaryReader(file))
                {
                    readBytes = reader.Read(original, 0, original.Length);
                    if (readBytes < NtagHelpers.NFC3D_AMIIBO_SIZE)
                    {
                        throw new Exception("Wrong length");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Could not read from input: {0}", ex.Message);
                return(3);
            }

            if (doEncrypt)
            {
                amiiboKeys.Pack(original, modified);
            }
            else
            {
                if (!amiiboKeys.Unpack(original, modified))
                {
                    Console.Error.WriteLine("!!! WARNING !!!: Tag signature was NOT valid");
                    if (!deactivateSignatureCheck)
                    {
                        return(6);
                    }
                }

                var amiiboTag1 = AmiiboTag.FromInternalTag(modified);
                var amiiboTag2 = AmiiboTag.FromInternalTag(NtagHelpers.GetInternalTag(original));
            }

            file = Console.OpenStandardOutput();
            if (outputFile != null)
            {
                try
                {
                    file = File.OpenWrite(outputFile);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("Could not open output file: {0}", ex.Message);
                    return(4);
                }
            }

            try
            {
                using (var writer = new BinaryWriter(file))
                {
                    writer.Write(modified, 0, modified.Length);
                    if (readBytes > modified.Length)
                    {
                        writer.Write(original, modified.Length, readBytes - modified.Length);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("CouldCould not write to output: {0}", ex.Message);
                return(3);
            }

            return(0);
        }