Example #1
0
    def redraw_table(self, length=None):
        with DisableUpdates(self.datatable):
            oldsig = self.datatable.blockSignals(True)
            self.row_size = length or self.row_size
            self.datatable.setColumnCount(self.row_size + 1)
            self.datatable.setRowCount(0)
            self.str_col = self.row_size

            self.datatable.horizontalHeader().hide()
            self.datatable.verticalHeader().hide()

            rows = int(len(self.data) / self.row_size)
            if len(self.data) % self.row_size > 0:
                rows += 1
            self.datatable.setRowCount(rows)

            for i in range(rows * self.row_size):
                row = i / self.row_size
                col = i % self.row_size
                if i < len(self.data):
                    dataval = "%02x" % self.data[i]
                    item = QTableWidgetItem(dataval)
                    if self.read_only:
                        item.setFlags(item.flags() ^ Qt.ItemIsEditable)
                else:
                    item = QTableWidgetItem("")
                    item.setFlags(item.flags() ^ Qt.ItemIsEditable)
                self.datatable.setItem(row, col, item)

            for row in range(rows):
                self._redraw_strcol(row)
            self.datatable.blockSignals(oldsig)
            self.datatable.resizeColumnsToContents()
            self.datatable.resizeRowsToContents()
Example #2
0
 def update_request(self, req):
     with DisableUpdates(self.tableView):
         self.tableModel.update_request(req)
         if req.db_id != "":
             if req.unmangled and req.unmangled.db_id != "":
                 self.tableModel.delete_request(
                     reqid=self.client.get_reqid(req.unmangled))
Example #3
0
 def fill_json(self):
     from .decoder import pp_json
     with DisableUpdates(self.json_widg):
         self.json_widg.setPlainText("")
         if not self.data:
             return
         try:
             j = pp_json(self.data.decode())
         except Exception:
             return
         highlighted = textedit_highlight(j, JsonLexer())
         self.json_widg.setHtml(highlighted)
Example #4
0
 def add_request(self, req):
     with DisableUpdates(self.tableView):
         if req.db_id != "":
             reqid = self.client.get_reqid(req)
             if self.client.check_request(self.query, reqid=reqid):
                 self.tableModel.add_request_head(req)
             if req.unmangled and req.unmangled.db_id != "" and self.tableModel.has_request(
                     req.unmangled):
                 self.tableModel.delete_request(req.unmangled)
         else:
             if self.client.check_request(self.query, req=req):
                 self.tableModel.add_request_head(req)
Example #5
0
 def set_bytes_highlighted(self, bs, lexer=None):
     if not self.enable_pretty:
         self.set_bytes(bs)
         return
     with DisableUpdates(self.textedit):
         self.pretty_mode = True
         self.clear()
         self.data = bs
         if lexer:
             self.lexer = lexer
         printable = printable_data(bs)
         highlighted = textedit_highlight(printable, self.lexer)
         self.textedit.setHtml(highlighted)
     self.repaint()  # needed to fix issue with py2app
Example #6
0
 def fill_highlighted(self):
     with DisableUpdates(self.htmlxml_widg):
         self.highlighted_widg.setPlainText("")
         if not self.data:
             return
         ct = self.headers.get('Content-Type').lower()
         if ";" in ct:
             ct = ct.split(";")[0]
         try:
             lexer = get_lexer_for_mimetype(ct)
             highlighted = textedit_highlight(self.data, lexer)
         except:
             highlighted = printable_data(self.data)
         self.highlighted_widg.setHtml(highlighted)
Example #7
0
    def fill_htmlxml(self):
        from lxml import etree, html

        with DisableUpdates(self.htmlxml_widg):
            self.htmlxml_widg.setPlainText("")
            if not self.data:
                return
            try:
                fragments = html.fragments_fromstring(self.data.decode())
                parsed_frags = []
                for f in fragments:
                    parsed_frags.append(etree.tostring(f, pretty_print=True))
                pretty = b''.join(parsed_frags)
            except Exception:
                return
            highlighted = textedit_highlight(pretty, HtmlLexer())
            self.htmlxml_widg.setHtml(highlighted)
Example #8
0
 def set_requests(self, reqs, check_filter=False):
     to_add = []
     if not check_filter:
         to_add = reqs
     else:
         for req in reqs:
             if req.db_id != "":
                 reqid = self.client.get_reqid(req)
                 if self.client.check_request(self.query, reqid=reqid):
                     to_add.append(req)
             else:
                 if self.client.check_request(self.query, req=req):
                     to_add.append(req)
     with DisableUpdates(self.tableView):
         self.clear()
         self.tableModel.disable_sort()
         self.tableModel.add_requests(to_add)
         self.tableModel.enable_sort()
         self.set_is_not_loading()
Example #9
0
    def set_request(self, req):
        with DisableUpdates(self.urltable, self.posttable, self.cookietable):
            self.clear_tables()
            if req is None:
                return
            post_params = req.parameters()
            url_params = req.url.parameters()
            cookies = [(k, v) for k, v in req.cookie_iter()]

            if url_params:
                for k, vv in url_params.items():
                    for v in vv:
                        self._add_info(self.urltable, k, v)
            if post_params:
                for k, vv in post_params.items():
                    for v in vv:
                        self._add_info(self.posttable, k, v)
            if cookies:
                for k, v in cookies:
                    self._add_info(self.cookietable, k, v)
Example #10
0
 def set_bytes(self, bs):
     with DisableUpdates(self.textedit):
         self.pretty_mode = False
         self.data = bs
         chunks = HextEditor._split_by_printables(bs)
         self.clear()
         cursor = QTextCursor(self.textedit.document())
         cursor.beginEditBlock()
         try:
             cursor.select(QTextCursor.Document)
             cursor.setCharFormat(QTextCharFormat())
             cursor.clearSelection()
             for chunk in chunks:
                 if chr(chunk[0]) in qtprintable:
                     cursor.insertText(chunk.decode())
                 else:
                     for b in chunk:
                         self._insert_byte(cursor, b)
         finally:
             cursor.endEditBlock()
     self.repaint()  # needed to fix issue with py2app
Example #11
0
    def set_request(self, req):
        with DisableUpdates(self.infotable):
            self.request = req
            self.infotable.setRowCount(0)
            if self.request is None:
                return
            reqlen = len(self.request.body)
            reqlen = '%d bytes' % reqlen
            rsplen = 'No response'

            mangle_str = 'Nothing mangled'
            if self.request.unmangled:
                mangle_str = 'Request'

            if self.request.response:
                response_code = str(self.request.response.status_code) + \
                    ' ' + self.request.response.reason
                rsplen = self.request.response.content_length
                rsplen = '%d bytes' % rsplen

                if self.request.response.unmangled:
                    if mangle_str == 'Nothing mangled':
                        mangle_str = 'Response'
                    else:
                        mangle_str += ' and Response'
            else:
                response_code = ''

            time_str = '--'
            if self.request.time_end is not None and self.request.time_start is not None:
                time_delt = self.request.time_end - self.request.time_start
                time_str = "%.2f sec" % time_delt.total_seconds()

            if self.request.use_tls:
                is_ssl = 'YES'
            else:
                is_ssl = 'NO'

            if self.request.time_start:
                time_made_str = datetime_string(self.request.time_start)
            else:
                time_made_str = '--'

            verb = self.request.method
            host = self.request.dest_host

            self._add_info('Made on', time_made_str)
            self._add_info('URL', get_full_url(self.request))
            self._add_info('Host', host)
            self._add_info('Path', self.request.url.path)
            self._add_info('Verb', verb)
            self._add_info('Status Code', response_code)
            self._add_info('Request Length', reqlen)
            self._add_info('Response Length', rsplen)
            if self.request.response and self.request.response.unmangled:
                self._add_info('Unmangled Response Length', self.request.response.unmangled.content_length)
            self._add_info('Time', time_str)
            self._add_info('Port', str(self.request.dest_port))
            self._add_info('SSL', is_ssl)
            self._add_info('Mangled', mangle_str)
            self._add_info('Tags', ', '.join(self.request.tags))
Example #12
0
 def delete_request(self, reqid):
     with DisableUpdates(self.tableView):
         self.tableModel.delete_request(reqid=reqid)
Example #13
0
 def delete_selected(self):
     with DisableUpdates(self.tableView):
         for req in self.selected_reqs:
             self.tableModel.delete_request(req=req)
Example #14
0
 def set_loading(self, is_loading):
     with DisableUpdates(self.tableView):
         if is_loading:
             self.layout().setCurrentIndex(1)
         else:
             self.layout().setCurrentIndex(0)