private void UpdateRecPacket(httpsession osession) { if (rid > 40) { dataGridView1.VirtualMode = true; dataGridView1.RowCount = dic_ack_httpsession.Count; } else { dataGridView1.VirtualMode = false; // log(method + "\t" + url); ; //debugmsg(string.Format("[{0}] 创建 {1}", seq, url)); dataGridView1.Rows.Add(osession.id, osession.ack, osession.method, osession.url, Encoding.ASCII.GetString(osession.sendraw.ToArray()), osession.statucode); } }
private void dataGridView1_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e) { //if ((!dic_rid_ack.ContainsKey(e.RowIndex)) || (!dic_ack_httpsession.ContainsKey(dic_rid_ack[e.RowIndex]))) // return; if (list_ack.Count <= e.RowIndex || !dic_ack_httpsession.ContainsKey(list_ack[e.RowIndex])) { return; } // vrow vr= _dic_rid_virow[e.RowIndex]; httpsession osession = dic_ack_httpsession[list_ack[e.RowIndex]]; switch (e.ColumnIndex) { case 0: e.Value = osession.id; break; case 1: e.Value = osession.ack; break; case 2: e.Value = osession.method; break; case 3: e.Value = osession.url; break; case 4: e.Value = System.Text.Encoding.ASCII.GetString(osession.sendraw.ToArray()); break; case 5: e.Value = osession.statucode; break; case 6: e.Value = (int)((osession.responoversetime - osession.senddtime).TotalMilliseconds); break; } }
private void dataGridView1_SelectionChanged(object sender, EventArgs e) { int tt = 0; try { if (dataGridView1.SelectedRows.Count > 0) { if (dataGridView1.SelectedRows.Count > 0) { resetui(); string seq = dataGridView1.SelectedRows[0].Cells["seq"].Value.ToString(); if (dic_ack_httpsession.ContainsKey(seq)) { httpsession osession = dic_ack_httpsession[seq]; var requestBody = dataGridView1.SelectedRows[0].Cells["RAW"].Value.ToString(); this.textview_requst.SetText(requestBody); if (!string.IsNullOrWhiteSpace(requestBody)) { try { jsonViewerRequest.Json = requestBody; } catch { } } if (osession.responseraw == null) { debugmsg("没有数据"); return; } byte[] dataall = osession.responseraw.ToArray(); this.hexview_responce.body = dataall; this.hexview_request.body = osession.sendraw.ToArray(); int tag = 0; for (int i = 0; i < dataall.Length - 3; i++) { if (dataall[i] == 0x0D && dataall[i + 1] == 0x0A && dataall[i + 2] == 0x0D && dataall[i + 3] == 0x0A) { tag = i; break; } } byte[] headbyte = new byte[tag + 4]; Array.Copy(dataall, 0, headbyte, 0, tag + 4); byte[] recbyte = new byte[dataall.Length - headbyte.Length]; Array.Copy(dataall, tag + 4, recbyte, 0, recbyte.Length); string headstring = Encoding.ASCII.GetString(headbyte).Trim(new char[] { '\0' }); if (headstring.IndexOf("chunk") >= 0) { recbyte = Chunk.doUnchunk(recbyte); } // this.hexview_responce.body = headbyte; System.IO.Stream responseStream = new System.IO.MemoryStream(recbyte); string compress = getencompress(headstring); if (compress == "gzip") { responseStream = new GZipStream(responseStream, CompressionMode.Decompress); } else if (compress == "deflate")// if (headstring.ToLower().Contains("deflate")) { responseStream = new DeflateStream(responseStream, CompressionMode.Decompress); } if (isimage(headstring)) //图形 { this.imgview.body = recbyte; } else { string encstring = getencfromhead(headstring); if (encstring == "") { string prs = System.Text.Encoding.ASCII.GetString(recbyte); encstring = getencfromhead(prs); } if (encstring == "") { encstring = "utf-8"; } Encoding enc = Encoding.GetEncoding(encstring); #region // HttpWatch.Control.ByteCollection bytecollection = new HttpWatch.Control.ByteCollection(); // while (true) // { // byte[] buf = new byte[1024]; // int l = responseStream.Read(buf, 0, buf.Length); // if (l <= 0) break; // if (l < buf.Length) // { // byte[] n = new byte[l]; // Array.Copy(buf, 0, n, 0, n.Length); // bytecollection.AddRange(n); // } // else // { // bytecollection.AddRange(buf); // } // } // //textview_responce.m_headers = new Fiddler.HTTPResponseHeaders(enc); //// textview_responce.. // //textview_responce.m_headers.Add("Content-Type", "text/xml; charset=" + encstring); // textview_responce.body = bytecollection.GetBytes(); #endregion System.IO.StreamReader sr = new System.IO.StreamReader(responseStream, enc); string html = sr.ReadToEnd(); //string body = html.Substring(html.IndexOf(headstring)); if (!string.IsNullOrWhiteSpace(html)) { try { if (headstring.ToLower().Contains("application/json")) { jsonViewResponse.Json = html; } } catch { } } textview_responce.SetText(headstring + html); this.webBrowser1.DocumentText = html; } } // } } } } catch (Exception ex) { MessageBox.Show(string.Format("[异常] {0}", ex.ToString())); debugmsg(string.Format("[异常] {0}", ex.ToString())); } //this.dataGridView1.Enabled = true; }
/// <summary> /// 组包 /// </summary> /// <param name="isout"></param> /// <param name="ack"></param> /// <param name="seq"></param> /// <param name="PacketData"></param> /// <param name="start"></param> /// <param name="reclen"></param> /// private void BuildPacket(bool isout, string ack, string seq, byte[] PacketData, int start, int reclen) { try { if (reclen <= start) { return; } byte[] dataArray = new byte[reclen - start]; Array.Copy(PacketData, start, dataArray, 0, dataArray.Length); if (isout)//如果是请求包 { httpsession osesion = new httpsession(); osesion.id = rid; osesion.senddtime = DateTime.Now; osesion.ack = ack; log(ack); if (dic_senddata.ContainsKey(ack)) { log("包含:" + ack); osesion.sendraw = dic_senddata[ack]; } else { osesion.sendraw = new List <byte>(); } osesion.sendraw.AddRange(dataArray); string http_str = System.Text.Encoding.ASCII.GetString(osesion.sendraw.ToArray()); log(http_str); string host = Gethost(http_str); if (filtedomain == "" || host.IndexOf(filtedomain) >= 0) { //// this.dataGridView1.Rows.Add(vr.rid, vr.seq, vr.method, vr.url,http_str); //else int fltag = http_str.IndexOf("\r\n"); if (fltag > 0) { string fline = http_str.Substring(0, fltag); int fblacktag = fline.IndexOf(" "); if (fblacktag > 0) { osesion.method = fline.Substring(0, fline.IndexOf(" ")); int urllen = fline.LastIndexOf(" ") - fblacktag - 1; if (urllen > 0) { osesion.url = String.Format("http://{0}{1}", host, fline.Substring(fblacktag + 1, urllen)); } } } if (!this.dic_ack_httpsession.ContainsKey(osesion.ack)) { this.dic_ack_httpsession.Add(osesion.ack, osesion); this.list_ack.Add(ack); } rid++; this.dataGridView1.BeginInvoke(Myrecvie, new object[] { osesion }); debugmsg(string.Format("[{0}] 创建 {1}", seq, osesion.url)); } } else//如果是返回数据包 { if (dic_ack_httpsession.ContainsKey(seq))//如果第一次匹配 { // log(ack + ":" + seq + " 第一次返回匹配,添加映射"); debugmsg(string.Format("[{0}] 开始接受 {1}:{2}", seq, ack, seq)); httpsession osession = dic_ack_httpsession[seq]; if (osession.responseraw == null) { osession.responseraw = new List <byte>(); } osession.responseraw.AddRange(dataArray); osession.responoversetime = DateTime.Now; string headb = System.Text.Encoding.ASCII.GetString(dataArray); int flinetag = headb.IndexOf("\r\n"); if (flinetag > 0) { headb = headb.Substring(0, flinetag); string[] p3 = headb.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (p3.Length >= 2) { osession.statucode = int.Parse(p3[1]); this.dataGridView1.BeginInvoke(myupdatestatehandle, new object[] { osession.id, osession.statucode, (osession.responoversetime - osession.senddtime).TotalMilliseconds }); log(osession.method + "\t" + osession.url + "\t" + osession.statucode);; } } dic_ack_httpsession[seq] = osession; if (!dic_ack_seq.ContainsKey(ack)) { dic_ack_seq.Add(ack, seq); } // if (osession.id<=40) }//后面的数据包 else { if (dic_ack_seq.ContainsKey(ack)) { httpsession osession = dic_ack_httpsession[dic_ack_seq[ack]]; osession.responseraw.AddRange(dataArray); dic_ack_httpsession[dic_ack_seq[ack]] = osession; debugmsg(string.Format("[{0}] 继续接受 {1}:{2} 总长度 {3} ", dic_ack_seq[ack], ack, seq, osession.responseraw.Count)); } else { debugmsg(string.Format("[未识别] 接受 {1}:{2}", 0, ack, seq)); } } } } catch (Exception ex) { debugmsg(string.Format("[异常] {0}", ex.ToString())); log(ex.ToString()); } }