/// <summary> /// Read a single string from the metadata blob. /// </summary> /// <remarks> /// Consider returning false, printing error message. But, need to /// be certain to abort the whole process at that point... /// </remarks> public bool TryReadDefData(Blob metadata, out string metaString, out uint metaOffset, ref int offset) { metaString = null; metaOffset = 0; UInt32 cookie = 0; List <byte> tempbytelist = new List <byte>(); metadata.TryGetUInt32(ref metaOffset, ref offset); while ((metadata.Content.Count > offset + 8) && metadata.TryGetUInt32(ref cookie, ref offset)) { if ((cookie < 0x43210010 && cookie > 0x43210000) || cookie == 0x00090009) { if (cookie != 0x00090009) { offset -= 4; } char[] splitter = { '\0' }; string tempstring = System.Text.Encoding.ASCII.GetString(tempbytelist.ToArray()); metaString = tempstring.Split(splitter)[0]; return(true); } byte tempbyte = new byte(); offset -= 4; for (int i = 0; i < 4; i++) { if (!metadata.TryGetByte(ref tempbyte, ref offset)) { return(false); } tempbytelist.Add(tempbyte); } } tempbytelist.ToString(); return(false); }
/// <summary> /// Read a single string from the metadata blob. /// </summary> /// <remarks> /// Consider returning false, printing error message. But, need to /// be certain to abort the whole process at that point... /// </remarks> public bool TryReadDefString(Blob metadata, out string metaString, ref int offset) { metaString = null; UInt32 cookie = 0; List<byte> tempbytelist = new List<byte>(); while ((metadata.Content.Count > offset + 8) && metadata.TryGetUInt32(ref cookie, ref offset)) { if ((cookie < cookieMax && cookie > cookieMin) || cookie == cookieEnd) { if (cookie != cookieEnd) { offset -= 4; } char[] splitter = { '\0' }; string tempstring = System.Text.Encoding.ASCII.GetString(tempbytelist.ToArray()); metaString = tempstring.Split(splitter)[0]; return true; } byte tempbyte = new byte(); offset -= 4; for (int i = 0; i < 4; i++) { if (!metadata.TryGetByte(ref tempbyte, ref offset)) { return false; } tempbytelist.Add(tempbyte); } } tempbytelist.ToString(); return false; }
/// <summary> /// Read a single string from the metadata blob. /// </summary> /// <remarks> /// Consider returning false, printing error message. But, need to /// be certain to abort the whole process at that point... /// </remarks> public bool TryReadMetaString(Blob metadata, out string metaString, ref int offset) { metaString = null; UInt32 cookie = 0; List<byte> tempbytelist = new List<byte>(); while ((metadata.Content.Count > offset + 4) && metadata.TryGetUInt32(ref cookie, ref offset)) { if ((cookie < 0x12340010 && cookie > 0x12340000) || cookie == 0x00090009) { offset -= 4; char[] splitter = { '\0' }; //TODO FIX THIS string tempstring = System.Text.Encoding.ASCII.GetString(tempbytelist.ToArray()); metaString = tempstring.Split(splitter)[0]; return true; } byte tempbyte = new byte(); offset -= 4; for (int i = 0; i < 4; i++) { if (!metadata.TryGetByte(ref tempbyte,ref offset)) { return false; } tempbytelist.Add(tempbyte); } } tempbytelist.ToString(); return false; }
/// <summary> /// Try to read the calibration ID from the patch metadata. /// </summary> private bool TryReadCalibrationId(Blob blob, ref int offset, out string calibrationId) { calibrationId = string.Empty; List<byte> calibrationIdBytes = new List<byte>(); byte tempByte = 0; for (int index = 0; index < 16; index++) { if (!blob.TryGetByte(ref tempByte, ref offset)) { Trace.WriteLine("This patch file's metadata ran out before the complete calibration ID could be found."); return false; } if (calibrationId == string.Empty) { if (tempByte != 0) { calibrationIdBytes.Add(tempByte); } else { calibrationId = System.Text.Encoding.ASCII.GetString(calibrationIdBytes.ToArray()); } } else { if (tempByte != 0) { Trace.WriteLine("This patch file's metadata contains garbage after the calibration ID."); return false; } } } return true; }