public AmiiboFileMessage(string AmiiboFileFullName) { Decrypted = new byte[NtagHelpers.NFC3D_AMIIBO_SIZE]; this.FullName = AmiiboFileFullName; FileInfo fi = new FileInfo(this.FullName); this.Name = fi.Name; this.DirectoryName = fi.DirectoryName; this.Length = fi.Length; AmiiKeys = AmiiboKeys.LoadKeys(key_retail); this.AmiiboData = GetFileData(this.FullName); UnPack(); myMessage = this.GetMessage(); }
public AmiiboFileMessage(string AmiiboFileFullName) //2018-03-27 { Decrypted = new byte[NtagHelpers.NFC3D_AMIIBO_SIZE]; this.FullName = AmiiboFileFullName; FileInfo fi = new FileInfo(this.FullName); this.Name = fi.Name; this.DirectoryName = fi.DirectoryName; this.Length = fi.Length; this.AmiiboData = GetFileData(this.FullName); FileToCRC32 crc32 = new FileToCRC32(); this.CRC32 = crc32.ComputeCRC32(this.AmiiboData, 0, (int)this.Length); if (this.Length >= 532) { AmiiKeys = AmiiboKeys.LoadKeys(key_retail); UnPack(); myMessage = this.GetMessage(); } }
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); }