/// <summary> /// Loads a file and displays the hex in the text editor /// </summary> /// <param name="pathToFile">The full path to the file to load</param> private async Task LoadFileAndDisplayHex(string pathToFile) { HexViewer.Clear(); byte[] fileBytes = await new FileLoader().LoadFile(pathToFile); HexViewer.AppendText(new HexBuilder().BuildHex(fileBytes)); }
public void AddRanges(HexViewer control, byte[] buffer) { control.Clear(); if (buffer.Length > 8) { int[] pointer; short width; short height; width = WordHelpers.GetInt16Le(buffer, 0); height = WordHelpers.GetInt16Le(buffer, 2); // do some basic sanity checking if (width > 0 && width <= 320 && height > 0 && height <= 200) { control.AddRange(0, 2, Color.MediumSeaGreen, Color.White, "Width"); // width control.AddRange(2, 2, Color.SeaGreen, Color.White, "Height"); // height control.AddRange(4, 2, Color.DeepPink, Color.White, "X-Offset"); // x offset control.AddRange(6, 2, Color.HotPink, Color.White, "Y-Offset"); // y offset pointer = new int[width]; for (int i = 0; i < width; i++) { int index; index = 8 + (i * 4); pointer[i] = WordHelpers.GetInt32Le(buffer, index); control.AddRange(new HexViewer.ByteGroup { Start = index, Length = 4, ForeColor = Color.White, BackColor = Color.Orange, Pointer = pointer[i], Type = "Pointer #" + i.ToString() }); // column pointer } for (int i = 0; i < width; i++) { int index; byte length; int sourceIndex; index = pointer[i]; length = buffer[index + 1]; sourceIndex = 8 + (i * 4); // post if (_showPrimaryPosts) { this.AddPost(control, index, length, sourceIndex, true); } if (length != 255) { index = this.IncrementColumn(buffer, index + 3, length); //index += length + 4; // row, length, 2xunused, pixel data if (buffer[index] == 255) { this.AddColumnEndMarker(control, index, pointer[i]); } else { while (true) { length = buffer[index + 1]; if (length == 255 || index + length + 4 > buffer.Length) { break; } else if (_showSecondaryPosts) { this.AddPost(control, index, length, sourceIndex, false); } index = this.IncrementColumn(buffer, index + 3, length); // index += length + 4; if (buffer[index] == 255) { this.AddColumnEndMarker(control, index, pointer[i]); break; } } } } } } } control.Invalidate(); }