示例#1
0
        public byte[] RePack(string getUID, string getID)
        {
            byte[] tempDecrypted = Decrypted;
            byte[] Encrypted     = new byte[NtagHelpers.NFC3D_AMIIBO_SIZE];

            //UID
            if (getUID.Length == 14)
            {
                tempDecrypted[0x1d4] = (byte)Convert.ToInt32(getUID.Substring(0, 2), 16);
                tempDecrypted[0x1d5] = (byte)Convert.ToInt32(getUID.Substring(2, 2), 16);
                tempDecrypted[0x1d6] = (byte)Convert.ToInt32(getUID.Substring(4, 2), 16);
                tempDecrypted[0x1d7] = (byte)(0x88 ^ tempDecrypted[0x1d4] ^ tempDecrypted[0x1d5] ^ tempDecrypted[0x1d6]);
                tempDecrypted[0x1d8] = (byte)Convert.ToInt32(getUID.Substring(6, 2), 16);
                tempDecrypted[0x1d9] = (byte)Convert.ToInt32(getUID.Substring(8, 2), 16);
                tempDecrypted[0x1da] = (byte)Convert.ToInt32(getUID.Substring(10, 2), 16);
                tempDecrypted[0x1db] = (byte)Convert.ToInt32(getUID.Substring(12, 2), 16);
                tempDecrypted[0x000] = (byte)(tempDecrypted[0x1d8] ^ tempDecrypted[0x1d9] ^ tempDecrypted[0x1da] ^ tempDecrypted[0x1db]);
            }

            //ID
            if (getID.Length == 16)
            {
                tempDecrypted[0x1dc] = (byte)Convert.ToInt32(getID.Substring(0, 2), 16);
                tempDecrypted[0x1dd] = (byte)Convert.ToInt32(getID.Substring(2, 2), 16);
                tempDecrypted[0x1de] = (byte)Convert.ToInt32(getID.Substring(4, 2), 16);
                tempDecrypted[0x1df] = (byte)Convert.ToInt32(getID.Substring(6, 2), 16);
                tempDecrypted[0x1e0] = (byte)Convert.ToInt32(getID.Substring(8, 2), 16);
                tempDecrypted[0x1e1] = (byte)Convert.ToInt32(getID.Substring(10, 2), 16);
                tempDecrypted[0x1e2] = (byte)Convert.ToInt32(getID.Substring(12, 2), 16);
                tempDecrypted[0x1e3] = (byte)Convert.ToInt32(getID.Substring(14, 2), 16);
            }

            AmiiKeys.Pack(tempDecrypted, Encrypted);
            return(Encrypted);
        }
示例#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);
        }