} // 'SZDD' public override ImageMetaData ReadMetaData(IBinaryStream file) { file.Position = 0xE; using (var lz = OpenCrzStream(file)) { int max_header_length = KnownKeys.Keys.Max(x => x.Length); var header = new byte[max_header_length + 0x35]; lz.Read(header, 0, header.Length); var id = Binary.GetCString(header, 0, max_header_length); byte[] key; if (!KnownKeys.TryGetValue(id, out key)) { return(null); } int seed_pos = id.Length + 1; int header_pos = seed_pos + 0x10; for (int i = 0; i < 0x24; ++i) { header[header_pos + i] ^= (byte)(key[i] ^ header[seed_pos + (i & 0xF)]); } return(new CrzMetaData { Width = header.ToUInt32(header_pos + 4), Height = header.ToUInt32(header_pos + 0x10), BPP = 16, HeaderSize = header.ToInt32(header_pos + 0x18) + 0x34 + seed_pos }); } }
public object Build(KeyedDescription description) { if (!ShouldBuildDescription(description)) { return(null); } var key = string.IsNullOrEmpty(description.Key) ? DefaultKey : description.Key; Type type; if (!KnownKeys.TryGetValue(key, out type)) { throw new KeyNotFoundException("Could not find class for " + description.Key); } var constructor = type.GetConstructors() .FirstOrDefault(c => c.GetParameters().All(p => p.IsOptional)); if (constructor == null) { throw new ArgumentException("No parameterless Constructor found for " + key); } // due to Mono and WP implementation issues, we don't use Type.Missing //var parameters = constructor.GetParameters().Select(p => (object)Type.Missing).ToArray(); var parameters = constructor.GetParameters().Select(p => p.DefaultValue).ToArray(); var instance = constructor.Invoke(null, parameters); return(instance); }
static byte[] GetKeyData(string scheme) { byte[] key; if (KnownKeys.TryGetValue(scheme, out key)) { return(key); } return(null); }
public static byte[] GetKey(string title) { byte[] key; if (string.IsNullOrEmpty(title) || !KnownKeys.TryGetValue(title, out key)) { return(null); } return(key); }
byte[] GetKeyForTitle(string title) { byte[] key = null; if (!string.IsNullOrEmpty(title)) { KnownKeys.TryGetValue(title, out key); } return(key); }
uint GetAsbKey(string scheme) { uint key; if (KnownKeys.TryGetValue(scheme, out key)) { return(key); } return(0); }
byte[] ReadIndex(string bmi_name) { var index = File.ReadAllBytes(bmi_name); uint signature = index.ToUInt32(0); string passkey; if (!KnownKeys.TryGetValue(signature, out passkey)) { var root = Path.GetPathRoot(bmi_name); if (string.IsNullOrEmpty(root)) { return(null); } uint serial; if (!GetVolumeInformation(root, IntPtr.Zero, 0, out serial, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, 0)) { return(null); } passkey = string.Format("{0:x4}{1}", serial, (int)serial); } uint seed = GetSeedFromString(passkey); var twister = new MersenneTwister(seed); unsafe { fixed(byte *idx8 = index) { uint *dst = (uint *)idx8; for (int n = index.Length / 4; n > 0; --n) { *dst++ ^= twister.Rand(); } } } return(index); }
byte[] GetKey(string title) { byte[] key; KnownKeys.TryGetValue(title, out key); return(key); }