public static void ReportState(SpiderResult result) { using (var factory = new ChannelFactory <ISpiderClientToManageClient>(new NetNamedPipeBinding() { MaxReceivedMessageSize = int.MaxValue }, new EndpointAddress("net.pipe://127.0.0.1/Server"))) { ISpiderClientToManageClient manageClientToManageSpiderClientChannel = factory.CreateChannel(); try { manageClientToManageSpiderClientChannel.TransferData(result); } catch (TimeoutException) { (manageClientToManageSpiderClientChannel as ICommunicationObject).Abort(); throw; } catch (CommunicationException) { (manageClientToManageSpiderClientChannel as ICommunicationObject).Abort(); throw; } finally { CloseChannel((ICommunicationObject)manageClientToManageSpiderClientChannel); } } }
public void TransferData(SpiderResult result) { //MessageBox.Show(result.Url); if (currentTaskCount == 0) { totalTask = result.TaskCount; } totalTime += result.Elapse; currentTaskCount++; toolStripStatusLabel.Text = result.Url; //this.Text = result.Url; if (this.toolStripProgressBar.Maximum != result.TaskCount) { this.toolStripProgressBar.Maximum = result.TaskCount; //this.toolStripProgressBar.Step = result.TaskCount; this.toolStripProgressBar.Minimum = 0; this.toolStripProgressBar.Width = 200; } if (currentTaskCount % result.TaskCount == 0) { totalTask += result.TaskCount; } this.Text = result.Title; this.toolStripProgressBar.Text = result.Current + "/" + result.TaskCount + "/" + this.totalTask + "/平均:" + totalTime / currentTaskCount + "/当前" + result.Elapse + ""; this.toolStripProgressBar.Value = result.Current; SpiderManager.SpiderProductDetail(new SpiderProductInfo() { ECPlatformId = 1, HtmlSource = result.HtmlSource }); //File.WriteAllText("z:\\" + result.Title + ".html", result.HtmlSource, Encoding.GetEncoding(result.Charset)); }
private static void AddResult(int level, SpiderResult parentResult, ConcurrentBag <SpiderResult> results, string match, int offset, long addressFoundAt) { if (match != null) { var newResult = new SpiderResult(parentResult); newResult.Level = level; newResult.SetOffset(level, offset, addressFoundAt); newResult.Value = match; results.Add(newResult); } }
private void CheckNextLevel(int level, long startAddress, SpiderResult parentResult, SpiderSearch search, ConcurrentBag <SpiderResult> results, Memory memory) { var allData = memory.ReadBytes(startAddress, search.Length + search.ExtraRead); for (int index = 0; index < search.EndIncrement; index++) { var offset = index * search.Alignment; var addressToCheck = startAddress + offset; var match = CheckForMatchValue(allData, offset, search); if (match != null) { AddResult(level, parentResult, results, match, offset, addressToCheck); } if (!(level >= search.Levels)) { var nextResult = new SpiderResult(parentResult); nextResult.SetOffset(level, index * search.Alignment, addressToCheck); var nextLevel = level + 1; if (search.Is64Bit) { var pointer = BitConverter.ToInt64(allData, offset); if (pointer > 50000) { CheckNextLevel(nextLevel, pointer, nextResult, search, results, memory); } } else { var pointer = BitConverter.ToInt32(allData, offset); if (pointer > 50000) { CheckNextLevel(nextLevel, pointer, nextResult, search, results, memory); } } } } }
public void TransferData(SpiderResult result) { this.Invoker.Invoke(proxy => proxy.TransferData(result)); }
public void Button_Seach_Click(object sender, RoutedEventArgs e) { var processes = Process.GetProcessesByName(_mainWindow.SelectedProcessName); if (!processes.Any()) { MessageBox.Show("Select a process"); return; } var process = processes.First(); var memory = new Memory(process.Id); try { if (SpiderSearch.Levels > 10) { MessageBox.Show(_mainWindow, "Only 10 levels deep supported."); return; } switch (SpiderSearch.DataType) { case DataType.UTF16: if (SpiderSearch.StringLength <= 0) { SpiderSearch.StringLength = SpiderSearch.StringValue.Length * 2; } break; case DataType.Float: float floatValue; if (!float.TryParse(TextBox_Value.Text, out floatValue)) { MessageBox.Show(_mainWindow, "Can't parse value as float."); return; } SpiderSearch.FloatValue = floatValue; break; default: long longValue; if (!long.TryParse(TextBox_Value.Text, out longValue)) { MessageBox.Show(_mainWindow, "Can't parse value as non float."); return; } SpiderSearch.LongValue = longValue; break; } if (SpiderSearch.StringLength > 8) { SpiderSearch.ExtraRead = SpiderSearch.StringLength; } else { SpiderSearch.ExtraRead = 8; } SpiderSearch.EndIncrement = SpiderSearch.Length / SpiderSearch.Alignment; var allData = memory.ReadBytes(SpiderSearch.Address, SpiderSearch.Length + SpiderSearch.ExtraRead); var results = new ConcurrentBag <SpiderResult>(); Parallel.For(0, SpiderSearch.EndIncrement, index => { var offset = index * SpiderSearch.Alignment; var addressToCheck = SpiderSearch.Address + offset; int currentLevel = 0; var currentResult = new SpiderResult() { Level = currentLevel }; currentResult.Offset0 = offset; //currentResult.Address0 = addressToCheck; var match = CheckForMatchValue(allData, offset, SpiderSearch); if (match != null) { AddResult(currentLevel, currentResult, results, match, offset, addressToCheck); } if (!(currentLevel >= SpiderSearch.Levels)) { var nextLevel = currentLevel + 1; if (SpiderSearch.Is64Bit) { var pointer = BitConverter.ToInt64(allData, offset); if (pointer > 50000) { CheckNextLevel(nextLevel, pointer, currentResult, SpiderSearch, results, memory); } } else { var pointer = BitConverter.ToInt32(allData, offset); if (pointer > 50000) { CheckNextLevel(nextLevel, pointer, currentResult, SpiderSearch, results, memory); } } } }); SpiderSearch.Results.Clear(); foreach (var spiderResult in results) { SpiderSearch.Results.Add(spiderResult); } VisibleResults = SpiderSearch.Results.Take(200).ToList(); } finally { memory.Close(); } }