public void ParseAndFormat([ValueSource(nameof(Samples))] string name) { var source = Load(name); var match = Splitter.Match(source); Assert.That(match.Success, Is.True); var group = match.Groups["splitter"]; var blob = BinaryProcessor.Parse(source.AsSpan(0, group.Index)); MethodData data; if (name.StartsWith("Body.", StringComparison.InvariantCulture)) { data = MethodParser.ParseBody(blob); } else if (name.StartsWith("IL.", StringComparison.InvariantCulture)) { data = MethodParser.ParseIL(blob); } else { throw new ArgumentException(); } var actual = MethodFormatter.Format(data); var expected = source.Substring(group.Index + group.Length); Assert.That(actual, Is.EqualTo(expected)); }
/// <summary> /// Constructor. /// </summary> /// <param name="cfg">Configuration.</param> /// <param name="name">Grid name.</param> /// <param name="proc">Interop processor.</param> /// <param name="marsh">Marshaller.</param> /// <param name="lifecycleHandlers">Lifecycle beans.</param> /// <param name="cbs">Callbacks.</param> public Ignite(IgniteConfiguration cfg, string name, IPlatformTargetInternal proc, Marshaller marsh, IList <LifecycleHandlerHolder> lifecycleHandlers, UnmanagedCallbacks cbs) : base(proc) { Debug.Assert(cfg != null); Debug.Assert(proc != null); Debug.Assert(marsh != null); Debug.Assert(lifecycleHandlers != null); Debug.Assert(cbs != null); _cfg = cfg; _name = name; _proc = proc; _marsh = marsh; _lifecycleHandlers = lifecycleHandlers; _cbs = cbs; marsh.Ignite = this; _prj = new ClusterGroupImpl(Target.OutObjectInternal((int)Op.GetClusterGroup), null); _binary = new Binary.Binary(marsh); _binaryProc = new BinaryProcessor(DoOutOpObject((int)Op.GetBinaryProcessor)); cbs.Initialize(this); // Set reconnected task to completed state for convenience. _clientReconnectTaskCompletionSource.SetResult(false); SetCompactFooter(); _pluginProcessor = new PluginProcessor(this); }
private void PostConvertion(string input) { BinaryNibbles.Text = BinaryProcessor.ConvertToNibbles(BinaryTextBox.Text); ErrorMessage.Text = string.Empty; HistoryList.ItemsSource = HistoryProcessor.SaveInput(input); }
private void LoadSniff(object sender, EventArgs e) { var fileDialog = new OpenFileDialog { Filter = @"PKT files|*.pkt" }; if (fileDialog.ShowDialog() != DialogResult.OK) { return; } Processor = new BinaryProcessor(); Processor.OnPacketParsed += PacketStore.Insert; Task.Factory.StartNew(() => { var stopwatch = new Stopwatch(); stopwatch.Start(); Processor.Process(fileDialog.FileName); stopwatch.Stop(); Invoke((MethodInvoker)(() => { _filterTextBox.AutoCompleteCustomSource.Clear(); _filterTextBox.AutoCompleteCustomSource.AddRange(Enum.GetNames(typeof(Opcodes))); _opcodeListView.Enabled = true; _opcodeListView.Objects = PacketStore.GetAvailablePackets(); _filterTextBox.Enabled = true; _sniffLoadProgressBar.Visible = false; toolStripStatusLabel1.Text = $"{Processor.Count} packets parsed in {stopwatch.Elapsed}"; })); }); }
public Bitmap Process(Bitmap input, ProgressBar progressBar) { var w = new BinaryProcessor(input); var structure = new StructuringElement(StructuringElementShape.Rectangle, 3); w.Erode(structure); return(w.GetBitmap()); }
public MainWindow() { InitializeComponent(); HexProcessor = new HexProcessor(); BinaryProcessor = new BinaryProcessor(); IntegerProcessor = new IntegerProcessor(); HistoryProcessor = new HistoryProcessor(); ReadFromClipboard(); }
public void TestFile() { using (var fs = File.OpenRead(@"C:\Users\verto\Desktop\Reversing\Sniffs\22996_2016-11-30_09-40-46.pkt")) { var sw = new Stopwatch(); sw.Start(); BinaryProcessor.Process(fs); sw.Stop(); Console.WriteLine("Parsed in {0}.", sw.Elapsed); } }
public Bitmap Process(Bitmap input, ProgressBar progressBar) { var w = new BinaryProcessor(input); var structure = new StructuringElement(StructuringElementShape.Rectangle, 3); var x = (BinaryProcessor)w.Clone(); var y = (BinaryProcessor)w.Clone(); x.Dilate(structure); y.Erode(structure); y.Complement(); x.And(y); return(x.GetBitmap()); }
private Point findFirstPoint(BinaryProcessor p) { for (int y = 0; y < p.Width; y++) { for (int x = 0; x < p.Height; x++) { if (p.Image[x, y] > 0) { return(new Point(x, y)); } } } return(new Point(-1, -1)); }
public void Format() { const string Expected = @"00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20"; ReadOnlySpan <byte> blob = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, }; Assert.That(BinaryProcessor.Format(blob), Is.EqualTo(Expected)); }
public Bitmap Process(Bitmap input, ProgressBar progressBar) { var p = new BinaryProcessor(input); //var p2 = (BinaryProcessor)p.Clone(); //p2.Erode(_se); //p2.Complement(); //p.And(p2); var points = MooreTracing(p); var res = "Boundary Pixels \n"; foreach (var po in points) { res += $"\nX: {po.X}, Y: {po.Y}"; } System.Diagnostics.Trace.WriteLine(res); return(PointsToBitmap(points, p.Width, p.Height)); }
private List <Point> MooreTracing(BinaryProcessor p) { List <Point> boundary = new List <Point>(); var dirs = new Point[] { new Point(0, -1), // north new Point(1, -1), // north east new Point(1, 0), // east new Point(1, 1), // south east new Point(0, 1), // south new Point(-1, 1), // south west new Point(-1, 0), // west new Point(-1, -1) // north west }; var sPoint = findFirstPoint(p); boundary.Add(sPoint); // initialize boundary trace var cDir = 7; // north west var onPoint = sPoint; var cPoint = addPoints(onPoint, dirs[cDir]); while (cPoint != sPoint) { if (inBounds(cPoint, p) && p.Image[cPoint.X, cPoint.Y] == 255) { boundary.Add(cPoint); onPoint = cPoint; //backtrack cDir = (cDir + 6) % 8; cDir -= cDir % 2; cPoint = addPoints(onPoint, dirs[cDir]); } else { cDir = ++cDir % 8; cPoint = addPoints(onPoint, dirs[cDir]); } } return(boundary); }
private void ReadFromClipboard() { if (Clipboard.ContainsText(TextDataFormat.Text)) { string copiedText = Clipboard.GetText(TextDataFormat.Text).Trim(); if (BinaryProcessor.IsBinaryNumber(copiedText)) { BinaryTextBox.Text = copiedText; } else if (HexProcessor.IsHexNumber(copiedText)) { HexTextBox.Text = copiedText; } else if (IntegerProcessor.IsInteger(copiedText, out int intNumber)) { IntegerTextBox.Text = copiedText; } } }
/// <summary> /// Constructor. /// </summary> /// <param name="cfg">Configuration.</param> /// <param name="name">Grid name.</param> /// <param name="proc">Interop processor.</param> /// <param name="marsh">Marshaller.</param> /// <param name="lifecycleBeans">Lifecycle beans.</param> /// <param name="cbs">Callbacks.</param> public Ignite(IgniteConfiguration cfg, string name, IUnmanagedTarget proc, Marshaller marsh, IList <LifecycleBeanHolder> lifecycleBeans, UnmanagedCallbacks cbs) { Debug.Assert(cfg != null); Debug.Assert(proc != null); Debug.Assert(marsh != null); Debug.Assert(lifecycleBeans != null); Debug.Assert(cbs != null); _cfg = cfg; _name = name; _proc = proc; _marsh = marsh; _lifecycleBeans = lifecycleBeans; _cbs = cbs; marsh.Ignite = this; _prj = new ClusterGroupImpl(proc, UU.ProcessorProjection(proc), marsh, this, null); _binary = new Binary.Binary(marsh); _binaryProc = new BinaryProcessor(UU.ProcessorBinaryProcessor(proc), marsh); _proxy = new IgniteProxy(this); cbs.Initialize(this); // Grid is not completely started here, can't initialize interop transactions right away. _transactions = new Lazy <TransactionsImpl>( () => new TransactionsImpl(UU.ProcessorTransactions(proc), marsh, GetLocalNode().Id)); // Set reconnected task to completed state for convenience. _clientReconnectTaskCompletionSource.SetResult(false); SetCompactFooter(); _pluginProcessor = new PluginProcessor(this); }
public Bitmap Process(Bitmap input, ProgressBar progressBar) { var p = new ImageProcessor(input); var s1 = new StructuringElement(StructuringElementShape.Rectangle, 5); var s2 = new StructuringElement(StructuringElementShape.Rectangle, 9); var mask = new BinaryProcessor(_filter.Process(input, progressBar)); mask.Close(s1); mask.Open(s1); p.Mask(mask); mask.Dilate(s2); var bt = new BoundaryTrace(s1); var bmp = bt.Process(mask.GetBitmap(), progressBar); var p2 = new BinaryProcessor(bmp); //p.Layer(p2); return(p.GetBitmap()); }
private void BinaryTextBox_TextChanged(object sender, TextChangedEventArgs e) { var input = BinaryTextBox.Text.Trim(); if (!string.IsNullOrEmpty(input)) { if (BinaryProcessor.IsBinaryNumber(input)) { var binaryValue = BinaryProcessor.ConvertToBinary(input); IntegerTextBox.Text = binaryValue.ToString(); HexTextBox.Text = binaryValue.ToHexString(); PostConvertion(input); } else { ErrorMessage.Text = ERROR_MESSAGE; } } else { RefreshExecute(null, null); } }
public void TestMethod1() { using (var ms = new MemoryStream()) using (var writer = new BinaryWriter(ms)) { #region PKT bullshit writer.Write(new byte[3 + 2 + 1]); writer.Write(20772); // Build writer.Write(System.Text.Encoding.UTF8.GetBytes("enUS")); // Locale writer.Write(new byte[40 + 4 + 4 + 4]); // Write a single dummy opcode writer.Write(0x47534D43u); // CMSG writer.Write(0); // Connection ID writer.Write(1489646141); // Timestamp writer.Write(0); // Opt. Data Length var sizeOffset = ms.Position; writer.Write(0); // placeholder writer.Write((int)OpcodeClient.CMSG_AUTH_SESSION); var ofsStart = ms.Position; #endregion writer.Write(1000ul); // DosResponse writer.Write((ushort)15595); // Build writer.Write((byte)1); // BuildType writer.Write((uint)2); // RegionID writer.Write((uint)3); // BattlegroundID writer.Write((uint)4); // RealmID // LocalChallenge foreach (var i in Enumerable.Range(0, 16)) { writer.Write((byte)i); // 0, 1, ..., 15 } // Digest foreach (var i in Enumerable.Range(100, 24)) { writer.Write((byte)i); // 100, 101, ..., 123 } // UsesIPv6 writer.Write((byte)0xFF); // all bits set, cheap, but just to make it work // RealmJoinTicket const string realmJoinTicket = "!Warpten:[email protected]"; writer.Write(realmJoinTicket.Length); writer.Write(System.Text.Encoding.UTF8.GetBytes(realmJoinTicket)); #region PKT stuff // Get actual data size, skip back to position, write size ofsStart = ms.Position - ofsStart; ms.Position = sizeOffset; writer.Write((int)ofsStart + 4); // Aaaand back to the start we go ms.Position = 0; #endregion BinaryProcessor.Process(ms); // Console.WriteLine("{0}", PacketStore.Count); } }
public void FormatEmpty() { Assert.That(BinaryProcessor.Format(Array.Empty <byte>()), Is.EqualTo(string.Empty)); }
public void ParseComments() { var blob = BinaryProcessor.Parse("42 51 0A // 05\r\n\r\n54".AsSpan()); Assert.That(blob, Is.EqualTo(new byte[] { 0x42, 0x51, 0x0A, 0x54 })); }
public void ParseHalfByte() { var blob = BinaryProcessor.Parse("4".AsSpan()); Assert.That(blob, Is.EqualTo(new byte[] { 0x40 })); }
public void ParseEmpty() { var blob = BinaryProcessor.Parse(string.Empty.AsSpan()); Assert.That(blob, Is.Empty); }