/// <summary> /// Loads a chunk of data, applies any extra settings, calls UpdateOutput /// </summary> /// <param name="Entry"></param> public async Task LoadChunk(IChunkInfo Entry) { if (Entry == null) { return; } this.CurrentChunk = this.Image.GetChunk(Entry); this.strip_txtStart.Text = this.CurrentChunk.Info.Addr.StartOffset.ToString("X"); if (this.UseLength) { this.strip_txtEnd.Text = this.CurrentChunk.Info.Addr.Length.ToString("X"); } else { this.strip_txtEnd.Text = this.CurrentChunk.Info.Addr.EndOffset.ToString("X"); } if (Entry is TextChunkInfo) { this.OutMode = DumpTypes.Text; } else if (Entry is GfxChunkInfo) { this.OutMode = DumpTypes.Gfx; } //else this.OutMode = DumpTypes.Raw; await this.UpdateOutput(); }
public static void RegisterType(IChunkInfo ChunkInfo) { if (ChunkInfo == null) { throw new ArgumentNullException(); } ImageMap.chunktypes.Add(ChunkInfo.ID, typeof(ChunkInfo)); }
/// <summary> /// Adds a ChunkEntry object to the image map /// </summary> /// <param name="NewEntry"></param> public void Add(IChunkInfo NewEntry) { if (NewEntry == null) { throw new ArgumentNullException(); } this.Entries.Add(NewEntry); }
/// <summary> /// Constructs a data chunk /// </summary> /// <param name="Info">Information describing the data chunk, including the address range</param> /// <param name="Image">The source media image</param> public DataChunk(IChunkInfo Info, MediaImage Image) { if (Info == null || Image == null) { throw new ArgumentNullException(); } this.info = Info; this.data = Image.GetBytes(Info.Addr); }
public DataChunk(byte[] Data, IChunkInfo Info = null) { if (Data == null) { throw new ArgumentNullException("Data cannot be null"); } this.Data = Data; this.Info = Info; }
public async Task<IChunk> DownloadChunk(IChunkInfo chunkInfo) { if(string.IsNullOrEmpty(Url)) { throw new NullReferenceException("Url is null."); } using (var message = new HttpRequestMessage( HttpMethod.Get, Url)) { message.Headers.Range = new RangeHeaderValue( chunkInfo.Start, chunkInfo.Start + (chunkInfo.Length - 1) ); using (var wc = new HttpClient()) using (var response = await wc.SendAsync(message)) { switch (response.StatusCode) { case System.Net.HttpStatusCode.PartialContent: { var content = await response.Content.ReadAsByteArrayAsync(); int start = chunkInfo.Start; int length = content.Length; var chunk = new Chunk(start, content); return chunk; } case System.Net.HttpStatusCode.RequestedRangeNotSatisfiable: return null; default: throw new Exception("Unknown response"); } } } }
public DataChunk(byte[] Data, IChunkInfo Info = null) { if (Data == null) throw new ArgumentNullException("Data cannot be null"); this.Data = Data; this.Info = Info; }
/// <summary> /// Loads a chunk of data, applies any extra settings, calls UpdateOutput /// </summary> /// <param name="Entry"></param> public async Task LoadChunk(IChunkInfo Entry) { if (Entry == null) return; this.CurrentChunk = this.Image.GetChunk(Entry); this.strip_txtStart.Text = this.CurrentChunk.Info.Addr.StartOffset.ToString("X"); if (this.UseLength) this.strip_txtEnd.Text = this.CurrentChunk.Info.Addr.Length.ToString("X"); else this.strip_txtEnd.Text = this.CurrentChunk.Info.Addr.EndOffset.ToString("X"); if (Entry is TextChunkInfo) this.OutMode = DumpTypes.Text; else if (Entry is GfxChunkInfo) this.OutMode = DumpTypes.Gfx; //else this.OutMode = DumpTypes.Raw; await this.UpdateOutput(); }
/// <summary> /// Returns a DataChunk containing the data from the specified address range, as the specified chunk type /// </summary> /// <param name="ChunkInfo"></param> /// <returns></returns> public DataChunk GetChunk(IChunkInfo ChunkInfo) { return(new DataChunk(this.GetBytes(ChunkInfo.Addr), ChunkInfo)); }
/// <summary> /// Constructs a data chunk /// </summary> /// <param name="Info">Information describing the data chunk, including the address range</param> /// <param name="Image">The source media image</param> public DataChunk(IChunkInfo Info, MediaImage Image) { if (Info == null || Image == null) throw new ArgumentNullException(); this.info = Info; this.data = Image.GetBytes(Info.Addr); }
/// <summary> /// Returns a DataChunk containing the data from the specified address range, as the specified chunk type /// </summary> /// <param name="ChunkInfo"></param> /// <returns></returns> public DataChunk GetChunk(IChunkInfo ChunkInfo) { return new DataChunk(this.GetBytes(ChunkInfo.Addr), ChunkInfo); }
private Layout.IChunkInfo ParseLine(string text) { // returns a ChunkEntry object from a line in the imp file // May 2014 - oh boy more uncommented code. At least this is relatively simple // time to rewrite and comment! // do some simple checks to make sure the line is valid if (!text.Contains("[") || !text.Contains("]") || !(text.Contains("-") || text.Contains("+")) || text.Length < 6) { throw new FormatException("Entry not properly formatted"); } //get the text between the [] brackets, which should be the address and any arguments string offsets = dumplib.Text.Table.GetLabel(text); string[] args = null; // a comma delimits the address and all args, so if there's a comma in the text between []... if (offsets.Contains(",")) { //... then split by args, set the first result to offsets and the rest to the args array string[] temp = offsets.Split(','); args = new string[temp.Length - 1]; offsets = temp[0]; //Buffer.BlockCopy(temp, 1, args, 0, args.Length); Array.Copy(temp, 1, args, 0, args.Length); } // the offset string can have a - or + to delimit between the two numbers long first; int second; if (offsets.IndexOf('-') > 0) { string[] offsetsplit = offsets.Split('-'); first = long.Parse(offsetsplit[0], System.Globalization.NumberStyles.HexNumber); second = int.Parse(offsetsplit[1], System.Globalization.NumberStyles.HexNumber); if (second < first) { throw new ArgumentOutOfRangeException("Ending offset cannot be less than start offset"); } second = (second - (int)first) + 1; } else if (offsets.IndexOf('+') > 0) { string[] offsetsplit = offsets.Split('+'); first = long.Parse(offsetsplit[0], System.Globalization.NumberStyles.HexNumber); second = int.Parse(offsetsplit[1], System.Globalization.NumberStyles.HexNumber); if (second < 1) { throw new ArgumentOutOfRangeException("Length cannot be less than 1"); } } else { throw new FormatException("Offsets incorrectly formatted"); } string desc = text.Substring(text.IndexOf(']') + 1); //if (!ChunkTypes.ContainsKey(text.Substring(0, 1).ToUpper())) throw new ArgumentException("Specified chunk type not found"); object[] thisinfo = new object[2]; thisinfo[0] = new Range(first, second); thisinfo[1] = desc; IChunkInfo _out = Activator.CreateInstance(chunktypes[text.Substring(0, 1).ToUpper()], thisinfo) as IChunkInfo; if (args != null && args.Length > 0) { _out.ParseArgs(args); } return(_out); }
/// <summary> /// Adds a ChunkEntry object to the image map /// </summary> /// <param name="NewEntry"></param> public void Add(IChunkInfo NewEntry) { if (NewEntry == null) throw new ArgumentNullException(); this.Entries.Add(NewEntry); }
public static void RegisterType(IChunkInfo ChunkInfo) { if (ChunkInfo == null) throw new ArgumentNullException(); ImageMap.chunktypes.Add(ChunkInfo.ID, typeof(ChunkInfo)); }