def generateSimilarSymbolsTableHTML(self): table_html = "" index = 0 for symbol_pair in self.binary_pair.similar_symbols: index = index + 1 old_symbol = symbol_pair[0] new_symbol = symbol_pair[1] old_symbol_name_html = html.escapeString(old_symbol.name) new_symbol_name_html = html.escapeString(new_symbol.name) table_html += "<tr><td>%s</td><td><p>%s</p><p>%s</p></td><td><p>%s</p><p>%s</p></td><td><p>%s</p><p>%s</p></td><td>%s</td></tr>\n" % ( \ html.generateSimilarSymbolTableEntry(str(index)), \ html.generateSymbolTableEntryLight(old_symbol_name_html), \ html.generateSymbolTableEntryLight(new_symbol_name_html), \ old_symbol.type, \ new_symbol.type, \ html.formatNumber(old_symbol.size), \ html.formatNumber(new_symbol.size), \ html.formatNumberDelta(old_symbol.size, new_symbol.size)) if len(self.binary_pair.similar_symbols) == 0: table_visible = "invisible" else: table_visible = True return [ table_html, table_visible, len(self.binary_pair.similar_symbols) ]
def generateResourceConsumptionTableHTML(self): table_lines_html = [] for binary_pair in self.binary_pairs: table_lines_html.append("<tr><td>{short_name}</td><td>{code_size_old_overall}</td><td>{code_size_new_overall}</td><td>{code_size_delta_overall}</td><td>{static_ram_old_overall}</td><td>{static_ram_new_overall}</td><td>{static_ram_change_overall}</td></tr>\n".format( \ short_name = binary_pair.short_name, \ code_size_old_overall = binary_pair.old_binary.progmem_size, \ code_size_new_overall = binary_pair.new_binary.progmem_size, \ code_size_delta_overall = html.formatNumberDelta(binary_pair.old_binary.progmem_size, \ binary_pair.new_binary.progmem_size), \ static_ram_old_overall = binary_pair.old_binary.static_ram_size, \ static_ram_new_overall = binary_pair.new_binary.static_ram_size, \ static_ram_change_overall = html.formatNumberDelta(binary_pair.old_binary.static_ram_size, \ binary_pair.new_binary.static_ram_size) \ )) return "\n".join(table_lines_html)
def generatePersistingSymbolsTableHTML(self): old_binary = self.binary_pair.old_binary new_binary = self.binary_pair.new_binary table_html = "" import operator diff_by_symbol = {} for symbol_name in self.binary_pair.persisting_symbol_names: old_symbol = old_binary.symbols[symbol_name] new_symbol = new_binary.symbols[symbol_name] difference = new_symbol.size - old_symbol.size diff_by_symbol[symbol_name] = difference sorted_by_diff = sorted(diff_by_symbol.items(), key=operator.itemgetter(1), reverse=True) size_delta = 0 changed_symbols = [] for symbol_tuple in sorted_by_diff: symbol_name = symbol_tuple[0] old_symbol = old_binary.symbols[symbol_name] new_symbol = new_binary.symbols[symbol_name] if new_symbol.livesInProgramMemory(): size_delta += new_symbol.size - old_symbol.size if old_symbol.size != new_symbol.size: symbol_name_html = html.escapeString(symbol_name) changed_symbols.append(symbol_name) table_html += "<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n" % ( \ html.generateSymbolTableEntry(symbol_name_html), \ new_symbol.type, \ html.formatNumber(old_symbol.size), \ html.formatNumber(new_symbol.size), \ html.formatNumberDelta(old_symbol.size, new_symbol.size)) if size_delta == 0: table_visible = False else: table_visible = True return [ table_html, table_visible, html.highlightNumber(size_delta), changed_symbols ]
def configureJinjaKeywords(self, skip_details): import datetime old_binary = self.binary_pair.old_binary new_binary = self.binary_pair.new_binary # If we generate a pdf files, we skip the details # if skip_details: details_visibility = False persisting_symbol_details_html = "" disappeared_symbol_details_html = "" new_symbol_details_html = "" similar_symbol_details_html = "" else: details_visibility = True persisting_symbol_details_html = self.generatePersistentSymbolDetailsHTML( ) disappeared_symbol_details_html = self.generateDisappearedSymbolDetailsHTML( ) new_symbol_details_html = self.generateNewSymbolDetailsHTML() similar_symbol_details_html = self.generateSimilarSymbolDetailsHTML( ) if self.settings.project_title: doc_title = html.escapeString(self.settings.project_title) else: doc_title = "ELF Binary Comparison" [ persisting_symbols_table, persisting_symbols_table_visible, persisting_symbols_delta, symbols_changed ] = self.generatePersistingSymbolsTableHTML() [ disappeared_symbols_table, disappeared_symbols_table_visible, disappeared_symbols_size ] = self.generateDisappearedSymbolsTableHTML() [new_symbols_table, new_symbols_table_visible, new_symbols_size] = self.generateNewSymbolsTableHTML() [ similar_symbols_table, similar_symbols_table_visible, num_similar_symbols ] = self.generateSimilarSymbolsTableHTML() if self.settings.build_info == "": build_info_visible = False else: build_info_visible = True binary_details_visible = False if self.settings.old_binary_info == "": old_binary_info_visible = False else: old_binary_info_visible = True binary_details_visible = True if self.settings.new_binary_info == "": new_binary_info_visible = False else: new_binary_info_visible = True binary_details_visible = True return { "page_title": u"ELF Binary Comparison - (c) 2019 by noseglasses", "doc_title": doc_title, "elf_diff_repo_base": self.settings.repo_path, "old_binary_file": html.escapeString(self.settings.old_alias), "new_binary_file": html.escapeString(self.settings.new_alias), "code_size_old_overall": str(old_binary.progmem_size), "code_size_new_overall": str(new_binary.progmem_size), "code_size_change_overall": html.formatNumberDelta(old_binary.progmem_size, new_binary.progmem_size), "static_ram_old_overall": str(old_binary.static_ram_size), "static_ram_new_overall": str(new_binary.static_ram_size), "static_ram_change_overall": html.formatNumberDelta(old_binary.static_ram_size, new_binary.static_ram_size), "text_size_old_overall": str(old_binary.text_size), "text_size_new_overall": str(new_binary.text_size), "text_size_change_overall": html.formatNumberDelta(old_binary.text_size, new_binary.text_size), "data_size_old_overall": str(old_binary.data_size), "data_size_new_overall": str(new_binary.data_size), "data_size_change_overall": html.formatNumberDelta(old_binary.data_size, new_binary.data_size), "bss_size_old_overall": str(old_binary.bss_size), "bss_size_new_overall": str(new_binary.bss_size), "bss_size_change_overall": html.formatNumberDelta(old_binary.bss_size, new_binary.bss_size), "total_symbols_old": str(len(old_binary.symbols.keys())), "total_symbols_new": str(len(new_binary.symbols.keys())), "num_persisting_symbols": str(len(self.binary_pair.persisting_symbol_names)), "num_disappeared_symbols": str(self.binary_pair.num_symbols_disappeared), "num_new_symbols": str(self.binary_pair.num_symbols_new), "num_similar_symbols": str(num_similar_symbols), "persisting_symbols_table_visible": persisting_symbols_table_visible, "disappeared_symbols_table_visible": disappeared_symbols_table_visible, "new_symbols_table_visible": new_symbols_table_visible, "similar_symbols_table_visible": similar_symbols_table_visible, "persisting_symbols_table": persisting_symbols_table, "disappeared_symbols_table": disappeared_symbols_table, "new_symbols_table": new_symbols_table, "similar_symbols_table": similar_symbols_table, "persisting_symbols_delta": persisting_symbols_delta, "disappeared_symbols_size": disappeared_symbols_size, "new_symbols_size": new_symbols_size, "details_visibility": details_visibility, "persisting_symbol_details_html": persisting_symbol_details_html, "disappeared_symbol_details_html": disappeared_symbol_details_html, "new_symbol_details_html": new_symbol_details_html, "similar_symbol_details_html": similar_symbol_details_html, "binary_details_visible": binary_details_visible, "old_binary_info_visible": old_binary_info_visible, "new_binary_info_visible": new_binary_info_visible, "old_binary_info": html.escapeString(self.settings.old_binary_info), "new_binary_info": html.escapeString(self.settings.new_binary_info), "build_info_visible": build_info_visible, "build_info": html.escapeString(self.settings.build_info), "date": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "symbols_changed": symbols_changed # not escaped, do not print in the HTML }