{ // 获取包含Hugging Face文本的span元素 const spans = link.querySelectorAll('span.whitespace-nowrap, span.hidden.whitespace-nowrap'); spans.forEach(span => { if (span.textContent && span.textContent.trim().match(/Hugging\s*Face/i)) { span.textContent = 'AI快站'; } }); }); // 替换logo图片的alt属性 document.querySelectorAll('img[alt*="Hugging"], img[alt*="Face"]').forEach(img => { if (img.alt.match(/Hugging\s*Face/i)) { img.alt = 'AI快站 logo'; } }); } // 替换导航栏中的链接 function replaceNavigationLinks() { // 已替换标记,防止重复运行 if (window._navLinksReplaced) { return; } // 已经替换过的链接集合,防止重复替换 const replacedLinks = new Set(); // 只在导航栏区域查找和替换链接 const headerArea = document.querySelector('header') || document.querySelector('nav'); if (!headerArea) { return; } // 在导航区域内查找链接 const navLinks = headerArea.querySelectorAll('a'); navLinks.forEach(link => { // 如果已经替换过,跳过 if (replacedLinks.has(link)) return; const linkText = link.textContent.trim(); const linkHref = link.getAttribute('href') || ''; // 替换Spaces链接 - 仅替换一次 if ( (linkHref.includes('/spaces') || linkHref === '/spaces' || linkText === 'Spaces' || linkText.match(/^s*Spacess*$/i)) && linkText !== '免费Z-image图片生成' && linkText !== '免费Z-image图片生成' ) { link.textContent = '免费Z-image图片生成'; link.href = 'https://zimage.run'; link.setAttribute('target', '_blank'); link.setAttribute('rel', 'noopener noreferrer'); replacedLinks.add(link); } // 删除Posts链接 else if ( (linkHref.includes('/posts') || linkHref === '/posts' || linkText === 'Posts' || linkText.match(/^s*Postss*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } // 替换Docs链接 - 仅替换一次 else if ( (linkHref.includes('/docs') || linkHref === '/docs' || linkText === 'Docs' || linkText.match(/^s*Docss*$/i)) && linkText !== 'Vibevoice' ) { link.textContent = 'Vibevoice'; link.href = 'https://vibevoice.info/'; replacedLinks.add(link); } // 替换Pricing链接 - 仅替换一次 else if ( (linkHref.includes('/pricing') || linkHref === '/pricing' || linkText === 'Pricing' || linkText.match(/^s*Pricings*$/i)) && linkText !== '免费去水印' ) { link.textContent = '免费去水印'; link.href = 'https://sora2watermarkremover.net/'; replacedLinks.add(link); } // 替换Enterprise链接 else if ( (linkHref.includes('/enterprise') || linkHref === '/enterprise' || linkText === 'Enterprise' || linkText.match(/^s*Enterprises*$/i)) && linkText !== 'LTX-2' ) { link.textContent = 'LTX-2'; link.href = 'https://ltx-2.run/'; replacedLinks.add(link); } }); // 查找可能嵌套的Spaces和Posts文本 const textNodes = []; function findTextNodes(element) { if (element.nodeType === Node.TEXT_NODE) { const text = element.textContent.trim(); if (text === 'Spaces' || text === 'Posts' || text === 'Enterprise') { textNodes.push(element); } } else { for (const child of element.childNodes) { findTextNodes(child); } } } // 只在导航区域内查找文本节点 findTextNodes(headerArea); // 替换找到的文本节点 textNodes.forEach(node => { const text = node.textContent.trim(); if (text === 'Spaces') { node.textContent = node.textContent.replace(/Spaces/g, '免费Z-image图片生成'); } else if (text === 'Posts') { // 删除Posts文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } else if (text === 'Enterprise') { // 删除Enterprise文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } }); // 标记已替换完成 window._navLinksReplaced = true; } // 替换代码区域中的域名 function replaceCodeDomains() { // 特别处理span.hljs-string和span.njs-string元素 document.querySelectorAll('span.hljs-string, span.njs-string, span[class*="hljs-string"], span[class*="njs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换hljs-string类的span中的域名(移除多余的转义符号) document.querySelectorAll('span.hljs-string, span[class*="hljs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换pre和code标签中包含git clone命令的域名 document.querySelectorAll('pre, code').forEach(element => { if (element.textContent && element.textContent.includes('git clone')) { const text = element.innerHTML; if (text.includes('huggingface.co')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 处理特定的命令行示例 document.querySelectorAll('pre, code').forEach(element => { const text = element.innerHTML; if (text.includes('huggingface.co')) { // 针对git clone命令的专门处理 if (text.includes('git clone') || text.includes('GIT_LFS_SKIP_SMUDGE=1')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 特别处理模型下载页面上的代码片段 document.querySelectorAll('.flex.border-t, .svelte_hydrator, .inline-block').forEach(container => { const content = container.innerHTML; if (content && content.includes('huggingface.co')) { container.innerHTML = content.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 特别处理模型仓库克隆对话框中的代码片段 try { // 查找包含"Clone this model repository"标题的对话框 const cloneDialog = document.querySelector('.svelte_hydration_boundary, [data-target="MainHeader"]'); if (cloneDialog) { // 查找对话框中所有的代码片段和命令示例 const codeElements = cloneDialog.querySelectorAll('pre, code, span'); codeElements.forEach(element => { if (element.textContent && element.textContent.includes('huggingface.co')) { if (element.innerHTML.includes('huggingface.co')) { element.innerHTML = element.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { element.textContent = element.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); } // 更精确地定位克隆命令中的域名 document.querySelectorAll('[data-target]').forEach(container => { const codeBlocks = container.querySelectorAll('pre, code, span.hljs-string'); codeBlocks.forEach(block => { if (block.textContent && block.textContent.includes('huggingface.co')) { if (block.innerHTML.includes('huggingface.co')) { block.innerHTML = block.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { block.textContent = block.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); }); } catch (e) { // 错误处理但不打印日志 } } // 当DOM加载完成后执行替换 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); }); } else { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); } // 增加一个MutationObserver来处理可能的动态元素加载 const observer = new MutationObserver(mutations => { // 检查是否导航区域有变化 const hasNavChanges = mutations.some(mutation => { // 检查是否存在header或nav元素变化 return Array.from(mutation.addedNodes).some(node => { if (node.nodeType === Node.ELEMENT_NODE) { // 检查是否是导航元素或其子元素 if (node.tagName === 'HEADER' || node.tagName === 'NAV' || node.querySelector('header, nav')) { return true; } // 检查是否在导航元素内部 let parent = node.parentElement; while (parent) { if (parent.tagName === 'HEADER' || parent.tagName === 'NAV') { return true; } parent = parent.parentElement; } } return false; }); }); // 只在导航区域有变化时执行替换 if (hasNavChanges) { // 重置替换状态,允许再次替换 window._navLinksReplaced = false; replaceHeaderBranding(); replaceNavigationLinks(); } }); // 开始观察document.body的变化,包括子节点 if (document.body) { observer.observe(document.body, { childList: true, subtree: true }); } else { document.addEventListener('DOMContentLoaded', () => { observer.observe(document.body, { childList: true, subtree: true }); }); } })(); \"\n\n # Beautify and write HTML\n soup = bs(complete_html_string, 'lxml')\n pretty_html = soup.prettify()\n with open(filename, \"w+\") as cf:\n cf.write(pretty_html)\n\n def create_str_node_ctx_idx(self, cov_ct_idx):\n prefixed_zeros = \"0\" * (len(\"00000\") - len(cov_ct_idx))\n return f\"{prefixed_zeros}{cov_ct_idx}\"\n\n def get_fuzz_blockers(\n self,\n profile: fuzz_data_loader."},"intellij_completions_filtered":{"kind":"list like","value":["FuzzerProfile","MergedProjectProfile","List","None","logger","add_func_to_reached_and_clone","FunctionProfile","load_all_profiles","read_fuzzer_data_file_to_profile","Any","Dict","Optional","Set","Tuple"],"string":"[\n \"FuzzerProfile\",\n \"MergedProjectProfile\",\n \"List\",\n \"None\",\n \"logger\",\n \"add_func_to_reached_and_clone\",\n \"FunctionProfile\",\n \"load_all_profiles\",\n \"read_fuzzer_data_file_to_profile\",\n \"Any\",\n \"Dict\",\n \"Optional\",\n \"Set\",\n \"Tuple\"\n]"},"prefix_truncated":{"kind":"string","value":"ospector: { profile.get_key() }\"\n )\n html_header += '
'\n complete_html_string += html_header\n\n # Display fuzz blocker at top of page\n fuzz_blockers = self.get_fuzz_blockers(\n profile,\n max_blockers_to_extract=12\n )\n\n fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], \"\", fuzz_blockers)\n if fuzz_blocker_table is not None:\n complete_html_string += \"
\"\n complete_html_string += \"

Fuzz blockers

\"\n complete_html_string += fuzz_blocker_table\n complete_html_string += \"
\"\n\n # Display calltree\n complete_html_string += calltree_html_string\n complete_html_string += \"
\"\n\n # HTML end\n html_end = ''\n blocker_idxs = []\n for node in fuzz_blockers:\n blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx)))\n\n if len(blocker_idxs) > 0:\n html_end = \"\"\n\n html_end += \"\"\n html_end += \"\"\n html_end += \"\"\n complete_html_string += html_end\n\n complete_html_string += \"\"\n\n # Beautify and write HTML\n soup = bs(complete_html_string, 'lxml')\n pretty_html = soup.prettify()\n with open(filename, \"w+\") as cf:\n cf.write(pretty_html)\n\n def create_str_node_ctx_idx(self, cov_ct_idx):\n prefixed_zeros = \"0\" * (len(\"00000\") - len(cov_ct_idx))\n return f\"{prefixed_zeros}{cov_ct_idx}\"\n\n def get_fuzz_blockers(\n self,\n profile: fuzz_data_loader."},"__index_level_0__":{"kind":"number","value":25,"string":"25"}}},{"rowIdx":14,"cells":{"idx":{"kind":"number","value":36,"string":"36"},"idx_lca":{"kind":"number","value":0,"string":"0"},"offset":{"kind":"number","value":7895,"string":"7,895"},"repo":{"kind":"string","value":"ossf__fuzz-introspector"},"commit_hash":{"kind":"string","value":"4867924b714a7789f94fbcde53713a29ceab7272"},"target_file":{"kind":"string","value":"post-processing/analyses/fuzz_calltree_analysis.py"},"line_type_lca":{"kind":"string","value":"inproject"},"ground_truth":{"kind":"string","value":"CalltreeCallsite"},"in_completions":{"kind":"bool","value":true,"string":"true"},"completion_type":{"kind":"string","value":"class"},"non_dunder_count_intellij":{"kind":"number","value":9,"string":"9"},"non_dunder_count_jedi":{"kind":"number","value":9,"string":"9"},"start_with_":{"kind":"bool","value":false,"string":"false"},"first_occurrence":{"kind":"bool","value":true,"string":"true"},"intellij_completions":{"kind":"list like","value":["extract_all_callsites","List","None","logger","Optional","CalltreeCallsite","data_file_read_calltree","extract_all_callsites_recursive","print_ctcs_tree"],"string":"[\n \"extract_all_callsites\",\n \"List\",\n \"None\",\n \"logger\",\n \"Optional\",\n \"CalltreeCallsite\",\n \"data_file_read_calltree\",\n \"extract_all_callsites_recursive\",\n \"print_ctcs_tree\"\n]"},"jedi_completions":{"kind":"list like","value":[{"name":"CalltreeCallsite","type":"class"},{"name":"data_file_read_calltree","type":"function"},{"name":"extract_all_callsites","type":"function"},{"name":"extract_all_callsites_recursive","type":"function"},{"name":"List","type":"class"},{"name":"logger","type":"statement"},{"name":"logging","type":"module"},{"name":"Optional","type":"class"},{"name":"print_ctcs_tree","type":"function"},{"name":"__doc__","type":"instance"},{"name":"__file__","type":"instance"},{"name":"__name__","type":"instance"},{"name":"__package__","type":"instance"}],"string":"[\n {\n \"name\": \"CalltreeCallsite\",\n \"type\": \"class\"\n },\n {\n \"name\": \"data_file_read_calltree\",\n \"type\": \"function\"\n },\n {\n \"name\": \"extract_all_callsites\",\n \"type\": \"function\"\n },\n {\n \"name\": \"extract_all_callsites_recursive\",\n \"type\": \"function\"\n },\n {\n \"name\": \"List\",\n \"type\": \"class\"\n },\n {\n \"name\": \"logger\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"logging\",\n \"type\": \"module\"\n },\n {\n \"name\": \"Optional\",\n \"type\": \"class\"\n },\n {\n \"name\": \"print_ctcs_tree\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__doc__\",\n \"type\": \"instance\"\n },\n {\n \"name\": \"__file__\",\n \"type\": \"instance\"\n },\n {\n \"name\": \"__name__\",\n \"type\": \"instance\"\n },\n {\n \"name\": \"__package__\",\n \"type\": \"instance\"\n }\n]"},"prefix":{"kind":"string","value":"# Copyright 2022 Fuzz Introspector Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Logic related to calltree analysis\"\"\"\n\nimport os\nimport logging\nimport json\n\nfrom typing import (\n List,\n Tuple,\n Optional,\n Set,\n)\n\nimport fuzz_analysis\nimport fuzz_data_loader\nimport fuzz_utils\nimport fuzz_cfg_load\nimport fuzz_html_helpers\n\n# For pretty printing the html code:\nfrom bs4 import BeautifulSoup as bs\n\nlogger = logging.getLogger(name=__name__)\n\n\nclass FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface):\n def __init__(self):\n self.name = \"FuzzCalltreeAnalysis\"\n logger.info(\"Creating FuzzCalltreeAnalysis\")\n\n def analysis_func(self,\n toc_list: List[Tuple[str, str, int]],\n tables: List[str],\n project_profile: fuzz_data_loader.MergedProjectProfile,\n profiles: List[fuzz_data_loader.FuzzerProfile],\n basefolder: str,\n coverage_url: str,\n conclusions) -> str:\n \"\"\"\n Creates the HTML of the calltree. Returns the HTML as a string.\n \"\"\"\n logger.info(\"Not implemented\")\n return \"\"\n\n def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str:\n logger.info(\"In calltree\")\n # Generate HTML for the calltree\n calltree_html_string = \"
\"\n calltree_html_string += \"

Fuzzer calltree

\"\n nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths)\n for i in range(len(nodes)):\n node = nodes[i]\n\n demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name)\n # We may not want to show certain functions at times, e.g. libc functions\n # in case it bloats the calltree\n # libc_funcs = { \"free\" }\n libc_funcs: Set[str] = set()\n avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0\n if avoid:\n continue\n\n # Prepare strings needed in the HTML\n color_to_be = node.cov_color\n callsite_link = node.cov_callsite_link\n link = node.cov_link\n ct_idx_str = self.create_str_node_ctx_idx(str(node.cov_ct_idx))\n\n # Only display [function] link if we have, otherwhise show no [function] text.\n if node.dst_function_source_file.replace(\" \", \"\") != \"/\":\n func_href = f\"\"\"[function]\"\"\"\n else:\n func_href = \"\"\n\n if i > 0:\n previous_node = nodes[i - 1]\n if previous_node.depth == node.depth:\n calltree_html_string += \"
\"\n depth_diff = previous_node.depth - node.depth\n if depth_diff >= 1:\n closing_divs = \"\" # To close \"calltree-line-wrapper\"\n closing_divs = \"\" * (int(depth_diff) + 1)\n calltree_html_string += closing_divs\n\n calltree_html_string += f\"\"\"\n
\n \n {node.depth}\n \n {demangled_name}\n \n \n {func_href}\n \n [call site2]\n \n [calltree idx: {ct_idx_str}]\n \n \n \"\"\"\n if i != len(nodes) - 1:\n next_node = nodes[i + 1]\n if next_node.depth > node.depth:\n calltree_html_string += f\"\"\"\"\"\"\n elif next_node.depth < node.depth:\n depth_diff = int(node.depth - next_node.depth)\n calltree_html_string += \"
\" * depth_diff\n\n calltree_html_string += \"\"\n logger.info(\"Calltree created\")\n\n # Write the HTML to a file called calltree_view_XX.html where XX is a counter.\n calltree_file_idx = 0\n calltree_html_file = f\"calltree_view_{calltree_file_idx}.html\"\n while os.path.isfile(calltree_html_file):\n calltree_file_idx += 1\n calltree_html_file = f\"calltree_view_{calltree_file_idx}.html\"\n\n self.html_create_dedicated_calltree_file(\n calltree_html_string,\n calltree_html_file,\n profile,\n )\n return calltree_html_file\n\n def html_create_dedicated_calltree_file(\n self,\n calltree_html_string,\n filename,\n profile: fuzz_data_loader.FuzzerProfile):\n \"\"\"\n Write a wrapped HTML file with the tags needed from fuzz-introspector\n We use this only for wrapping calltrees at the moment, however, down\n the line it makes sense to have an easy wrapper for other HTML pages too.\n \"\"\"\n complete_html_string = \"\"\n\n # HTML start\n html_header = fuzz_html_helpers.html_get_header(\n calltree=True,\n title=f\"Fuzz introspector: { profile.get_key() }\"\n )\n html_header += '
'\n complete_html_string += html_header\n\n # Display fuzz blocker at top of page\n fuzz_blockers = self.get_fuzz_blockers(\n profile,\n max_blockers_to_extract=12\n )\n\n fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], \"\", fuzz_blockers)\n if fuzz_blocker_table is not None:\n complete_html_string += \"
\"\n complete_html_string += \"

Fuzz blockers

\"\n complete_html_string += fuzz_blocker_table\n complete_html_string += \"
\"\n\n # Display calltree\n complete_html_string += calltree_html_string\n complete_html_string += \"
\"\n\n # HTML end\n html_end = ''\n blocker_idxs = []\n for node in fuzz_blockers:\n blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx)))\n\n if len(blocker_idxs) > 0:\n html_end = \"\"\n\n html_end += \"\"\n html_end += \"\"\n html_end += \"\"\n complete_html_string += html_end\n\n complete_html_string += \"\"\n\n # Beautify and write HTML\n soup = bs(complete_html_string, 'lxml')\n pretty_html = soup.prettify()\n with open(filename, \"w+\") as cf:\n cf.write(pretty_html)\n\n def create_str_node_ctx_idx(self, cov_ct_idx):\n prefixed_zeros = \"0\" * (len(\"00000\") - len(cov_ct_idx))\n return f\"{prefixed_zeros}{cov_ct_idx}\"\n\n def get_fuzz_blockers(\n self,\n profile: fuzz_data_loader.FuzzerProfile,\n max_blockers_to_extract=999):\n \"\"\"Gets a list of fuzz blockers\"\"\"\n blocker_list: List[fuzz_cfg_load."},"intellij_completions_filtered":{"kind":"list like","value":["extract_all_callsites","List","None","logger","Optional","CalltreeCallsite","data_file_read_calltree","extract_all_callsites_recursive","print_ctcs_tree"],"string":"[\n \"extract_all_callsites\",\n \"List\",\n \"None\",\n \"logger\",\n \"Optional\",\n \"CalltreeCallsite\",\n \"data_file_read_calltree\",\n \"extract_all_callsites_recursive\",\n \"print_ctcs_tree\"\n]"},"prefix_truncated":{"kind":"string","value":"tml_string += html_header\n\n # Display fuzz blocker at top of page\n fuzz_blockers = self.get_fuzz_blockers(\n profile,\n max_blockers_to_extract=12\n )\n\n fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], \"\", fuzz_blockers)\n if fuzz_blocker_table is not None:\n complete_html_string += \"
\"\n complete_html_string += \"

Fuzz blockers

\"\n complete_html_string += fuzz_blocker_table\n complete_html_string += \"
\"\n\n # Display calltree\n complete_html_string += calltree_html_string\n complete_html_string += \"\"\n\n # HTML end\n html_end = ''\n blocker_idxs = []\n for node in fuzz_blockers:\n blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx)))\n\n if len(blocker_idxs) > 0:\n html_end = \"\"\n\n html_end += \"\"\n html_end += \"\"\n html_end += \"\"\n complete_html_string += html_end\n\n complete_html_string += \"\"\n\n # Beautify and write HTML\n soup = bs(complete_html_string, 'lxml')\n pretty_html = soup.prettify()\n with open(filename, \"w+\") as cf:\n cf.write(pretty_html)\n\n def create_str_node_ctx_idx(self, cov_ct_idx):\n prefixed_zeros = \"0\" * (len(\"00000\") - len(cov_ct_idx))\n return f\"{prefixed_zeros}{cov_ct_idx}\"\n\n def get_fuzz_blockers(\n self,\n profile: fuzz_data_loader.FuzzerProfile,\n max_blockers_to_extract=999):\n \"\"\"Gets a list of fuzz blockers\"\"\"\n blocker_list: List[fuzz_cfg_load."},"__index_level_0__":{"kind":"number","value":26,"string":"26"}}},{"rowIdx":15,"cells":{"idx":{"kind":"number","value":37,"string":"37"},"idx_lca":{"kind":"number","value":0,"string":"0"},"offset":{"kind":"number","value":8028,"string":"8,028"},"repo":{"kind":"string","value":"ossf__fuzz-introspector"},"commit_hash":{"kind":"string","value":"4867924b714a7789f94fbcde53713a29ceab7272"},"target_file":{"kind":"string","value":"post-processing/analyses/fuzz_calltree_analysis.py"},"line_type_lca":{"kind":"string","value":"inproject"},"ground_truth":{"kind":"string","value":"extract_all_callsites"},"in_completions":{"kind":"bool","value":true,"string":"true"},"completion_type":{"kind":"string","value":"function"},"non_dunder_count_intellij":{"kind":"number","value":8,"string":"8"},"non_dunder_count_jedi":{"kind":"number","value":9,"string":"9"},"start_with_":{"kind":"bool","value":false,"string":"false"},"first_occurrence":{"kind":"bool","value":false,"string":"false"},"intellij_completions":{"kind":"list like","value":["extract_all_callsites","CalltreeCallsite","List","logger","extract_all_callsites_recursive","data_file_read_calltree","print_ctcs_tree","Optional"],"string":"[\n \"extract_all_callsites\",\n \"CalltreeCallsite\",\n \"List\",\n \"logger\",\n \"extract_all_callsites_recursive\",\n \"data_file_read_calltree\",\n \"print_ctcs_tree\",\n \"Optional\"\n]"},"jedi_completions":{"kind":"list like","value":[{"name":"CalltreeCallsite","type":"class"},{"name":"data_file_read_calltree","type":"function"},{"name":"extract_all_callsites","type":"function"},{"name":"extract_all_callsites_recursive","type":"function"},{"name":"List","type":"class"},{"name":"logger","type":"statement"},{"name":"logging","type":"module"},{"name":"Optional","type":"class"},{"name":"print_ctcs_tree","type":"function"},{"name":"__doc__","type":"instance"},{"name":"__file__","type":"instance"},{"name":"__name__","type":"instance"},{"name":"__package__","type":"instance"}],"string":"[\n {\n \"name\": \"CalltreeCallsite\",\n \"type\": \"class\"\n },\n {\n \"name\": \"data_file_read_calltree\",\n \"type\": \"function\"\n },\n {\n \"name\": \"extract_all_callsites\",\n \"type\": \"function\"\n },\n {\n \"name\": \"extract_all_callsites_recursive\",\n \"type\": \"function\"\n },\n {\n \"name\": \"List\",\n \"type\": \"class\"\n },\n {\n \"name\": \"logger\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"logging\",\n \"type\": \"module\"\n },\n {\n \"name\": \"Optional\",\n \"type\": \"class\"\n },\n {\n \"name\": \"print_ctcs_tree\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__doc__\",\n \"type\": \"instance\"\n },\n {\n \"name\": \"__file__\",\n \"type\": \"instance\"\n },\n {\n \"name\": \"__name__\",\n \"type\": \"instance\"\n },\n {\n \"name\": \"__package__\",\n \"type\": \"instance\"\n }\n]"},"prefix":{"kind":"string","value":"# Copyright 2022 Fuzz Introspector Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Logic related to calltree analysis\"\"\"\n\nimport os\nimport logging\nimport json\n\nfrom typing import (\n List,\n Tuple,\n Optional,\n Set,\n)\n\nimport fuzz_analysis\nimport fuzz_data_loader\nimport fuzz_utils\nimport fuzz_cfg_load\nimport fuzz_html_helpers\n\n# For pretty printing the html code:\nfrom bs4 import BeautifulSoup as bs\n\nlogger = logging.getLogger(name=__name__)\n\n\nclass FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface):\n def __init__(self):\n self.name = \"FuzzCalltreeAnalysis\"\n logger.info(\"Creating FuzzCalltreeAnalysis\")\n\n def analysis_func(self,\n toc_list: List[Tuple[str, str, int]],\n tables: List[str],\n project_profile: fuzz_data_loader.MergedProjectProfile,\n profiles: List[fuzz_data_loader.FuzzerProfile],\n basefolder: str,\n coverage_url: str,\n conclusions) -> str:\n \"\"\"\n Creates the HTML of the calltree. Returns the HTML as a string.\n \"\"\"\n logger.info(\"Not implemented\")\n return \"\"\n\n def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str:\n logger.info(\"In calltree\")\n # Generate HTML for the calltree\n calltree_html_string = \"
\"\n calltree_html_string += \"

Fuzzer calltree

\"\n nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths)\n for i in range(len(nodes)):\n node = nodes[i]\n\n demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name)\n # We may not want to show certain functions at times, e.g. libc functions\n # in case it bloats the calltree\n # libc_funcs = { \"free\" }\n libc_funcs: Set[str] = set()\n avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0\n if avoid:\n continue\n\n # Prepare strings needed in the HTML\n color_to_be = node.cov_color\n callsite_link = node.cov_callsite_link\n link = node.cov_link\n ct_idx_str = self.create_str_node_ctx_idx(str(node.cov_ct_idx))\n\n # Only display [function] link if we have, otherwhise show no [function] text.\n if node.dst_function_source_file.replace(\" \", \"\") != \"/\":\n func_href = f\"\"\"[function]\"\"\"\n else:\n func_href = \"\"\n\n if i > 0:\n previous_node = nodes[i - 1]\n if previous_node.depth == node.depth:\n calltree_html_string += \"
\"\n depth_diff = previous_node.depth - node.depth\n if depth_diff >= 1:\n closing_divs = \"\" # To close \"calltree-line-wrapper\"\n closing_divs = \"\" * (int(depth_diff) + 1)\n calltree_html_string += closing_divs\n\n calltree_html_string += f\"\"\"\n
\n \n {node.depth}\n \n {demangled_name}\n \n \n {func_href}\n \n [call site2]\n \n [calltree idx: {ct_idx_str}]\n \n \n \"\"\"\n if i != len(nodes) - 1:\n next_node = nodes[i + 1]\n if next_node.depth > node.depth:\n calltree_html_string += f\"\"\"\"\"\"\n elif next_node.depth < node.depth:\n depth_diff = int(node.depth - next_node.depth)\n calltree_html_string += \"
\" * depth_diff\n\n calltree_html_string += \"\"\n logger.info(\"Calltree created\")\n\n # Write the HTML to a file called calltree_view_XX.html where XX is a counter.\n calltree_file_idx = 0\n calltree_html_file = f\"calltree_view_{calltree_file_idx}.html\"\n while os.path.isfile(calltree_html_file):\n calltree_file_idx += 1\n calltree_html_file = f\"calltree_view_{calltree_file_idx}.html\"\n\n self.html_create_dedicated_calltree_file(\n calltree_html_string,\n calltree_html_file,\n profile,\n )\n return calltree_html_file\n\n def html_create_dedicated_calltree_file(\n self,\n calltree_html_string,\n filename,\n profile: fuzz_data_loader.FuzzerProfile):\n \"\"\"\n Write a wrapped HTML file with the tags needed from fuzz-introspector\n We use this only for wrapping calltrees at the moment, however, down\n the line it makes sense to have an easy wrapper for other HTML pages too.\n \"\"\"\n complete_html_string = \"\"\n\n # HTML start\n html_header = fuzz_html_helpers.html_get_header(\n calltree=True,\n title=f\"Fuzz introspector: { profile.get_key() }\"\n )\n html_header += '
'\n complete_html_string += html_header\n\n # Display fuzz blocker at top of page\n fuzz_blockers = self.get_fuzz_blockers(\n profile,\n max_blockers_to_extract=12\n )\n\n fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], \"\", fuzz_blockers)\n if fuzz_blocker_table is not None:\n complete_html_string += \"
\"\n complete_html_string += \"

Fuzz blockers

\"\n complete_html_string += fuzz_blocker_table\n complete_html_string += \"
\"\n\n # Display calltree\n complete_html_string += calltree_html_string\n complete_html_string += \"
\"\n\n # HTML end\n html_end = ''\n blocker_idxs = []\n for node in fuzz_blockers:\n blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx)))\n\n if len(blocker_idxs) > 0:\n html_end = \"\"\n\n html_end += \"\"\n html_end += \"\"\n html_end += \"\"\n complete_html_string += html_end\n\n complete_html_string += \"\"\n\n # Beautify and write HTML\n soup = bs(complete_html_string, 'lxml')\n pretty_html = soup.prettify()\n with open(filename, \"w+\") as cf:\n cf.write(pretty_html)\n\n def create_str_node_ctx_idx(self, cov_ct_idx):\n prefixed_zeros = \"0\" * (len(\"00000\") - len(cov_ct_idx))\n return f\"{prefixed_zeros}{cov_ct_idx}\"\n\n def get_fuzz_blockers(\n self,\n profile: fuzz_data_loader.FuzzerProfile,\n max_blockers_to_extract=999):\n \"\"\"Gets a list of fuzz blockers\"\"\"\n blocker_list: List[fuzz_cfg_load.CalltreeCallsite] = list()\n\n # Extract all callsites in calltree and exit early if none\n all_callsites = fuzz_cfg_load."},"intellij_completions_filtered":{"kind":"list like","value":["extract_all_callsites","CalltreeCallsite","List","logger","extract_all_callsites_recursive","data_file_read_calltree","print_ctcs_tree","Optional"],"string":"[\n \"extract_all_callsites\",\n \"CalltreeCallsite\",\n \"List\",\n \"logger\",\n \"extract_all_callsites_recursive\",\n \"data_file_read_calltree\",\n \"print_ctcs_tree\",\n \"Optional\"\n]"},"prefix_truncated":{"kind":"string","value":"profile,\n max_blockers_to_extract=12\n )\n\n fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], \"\", fuzz_blockers)\n if fuzz_blocker_table is not None:\n complete_html_string += \"
\"\n complete_html_string += \"

Fuzz blockers

\"\n complete_html_string += fuzz_blocker_table\n complete_html_string += \"
\"\n\n # Display calltree\n complete_html_string += calltree_html_string\n complete_html_string += \"\"\n\n # HTML end\n html_end = ''\n blocker_idxs = []\n for node in fuzz_blockers:\n blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx)))\n\n if len(blocker_idxs) > 0:\n html_end = \"\"\n\n html_end += \"\"\n html_end += \"\"\n html_end += \"\"\n complete_html_string += html_end\n\n complete_html_string += \"\"\n\n # Beautify and write HTML\n soup = bs(complete_html_string, 'lxml')\n pretty_html = soup.prettify()\n with open(filename, \"w+\") as cf:\n cf.write(pretty_html)\n\n def create_str_node_ctx_idx(self, cov_ct_idx):\n prefixed_zeros = \"0\" * (len(\"00000\") - len(cov_ct_idx))\n return f\"{prefixed_zeros}{cov_ct_idx}\"\n\n def get_fuzz_blockers(\n self,\n profile: fuzz_data_loader.FuzzerProfile,\n max_blockers_to_extract=999):\n \"\"\"Gets a list of fuzz blockers\"\"\"\n blocker_list: List[fuzz_cfg_load.CalltreeCallsite] = list()\n\n # Extract all callsites in calltree and exit early if none\n all_callsites = fuzz_cfg_load."},"__index_level_0__":{"kind":"number","value":27,"string":"27"}}},{"rowIdx":16,"cells":{"idx":{"kind":"number","value":41,"string":"41"},"idx_lca":{"kind":"number","value":0,"string":"0"},"offset":{"kind":"number","value":9121,"string":"9,121"},"repo":{"kind":"string","value":"ossf__fuzz-introspector"},"commit_hash":{"kind":"string","value":"4867924b714a7789f94fbcde53713a29ceab7272"},"target_file":{"kind":"string","value":"post-processing/analyses/fuzz_calltree_analysis.py"},"line_type_lca":{"kind":"string","value":"infile"},"ground_truth":{"kind":"string","value":"get_fuzz_blockers"},"in_completions":{"kind":"bool","value":true,"string":"true"},"completion_type":{"kind":"string","value":"function"},"non_dunder_count_intellij":{"kind":"number","value":7,"string":"7"},"non_dunder_count_jedi":{"kind":"number","value":7,"string":"7"},"start_with_":{"kind":"bool","value":false,"string":"false"},"first_occurrence":{"kind":"bool","value":false,"string":"false"},"intellij_completions":{"kind":"list like","value":["get_fuzz_blockers","create_fuzz_blocker_table","name","create_str_node_ctx_idx","html_create_dedicated_calltree_file","__init__","analysis_func","create_calltree","__annotations__","__class__","__delattr__","__dict__","__dir__","__eq__","__format__","__getattribute__","__hash__","__init_subclass__","__ne__","__new__","__reduce__","__reduce_ex__","__repr__","__setattr__","__sizeof__","__slots__","__str__","__subclasshook__","__doc__","__module__"],"string":"[\n \"get_fuzz_blockers\",\n \"create_fuzz_blocker_table\",\n \"name\",\n \"create_str_node_ctx_idx\",\n \"html_create_dedicated_calltree_file\",\n \"__init__\",\n \"analysis_func\",\n \"create_calltree\",\n \"__annotations__\",\n \"__class__\",\n \"__delattr__\",\n \"__dict__\",\n \"__dir__\",\n \"__eq__\",\n \"__format__\",\n \"__getattribute__\",\n \"__hash__\",\n \"__init_subclass__\",\n \"__ne__\",\n \"__new__\",\n \"__reduce__\",\n \"__reduce_ex__\",\n \"__repr__\",\n \"__setattr__\",\n \"__sizeof__\",\n \"__slots__\",\n \"__str__\",\n \"__subclasshook__\",\n \"__doc__\",\n \"__module__\"\n]"},"jedi_completions":{"kind":"list like","value":[{"name":"analysis_func","type":"function"},{"name":"create_calltree","type":"function"},{"name":"create_fuzz_blocker_table","type":"function"},{"name":"create_str_node_ctx_idx","type":"function"},{"name":"get_fuzz_blockers","type":"function"},{"name":"html_create_dedicated_calltree_file","type":"function"},{"name":"name","type":"statement"},{"name":"__annotations__","type":"statement"},{"name":"__class__","type":"property"},{"name":"__delattr__","type":"function"},{"name":"__dict__","type":"statement"},{"name":"__dir__","type":"function"},{"name":"__doc__","type":"statement"},{"name":"__eq__","type":"function"},{"name":"__format__","type":"function"},{"name":"__getattribute__","type":"function"},{"name":"__hash__","type":"function"},{"name":"__init__","type":"function"},{"name":"__init_subclass__","type":"function"},{"name":"__module__","type":"statement"},{"name":"__ne__","type":"function"},{"name":"__new__","type":"function"},{"name":"__reduce__","type":"function"},{"name":"__reduce_ex__","type":"function"},{"name":"__repr__","type":"function"},{"name":"__setattr__","type":"function"},{"name":"__sizeof__","type":"function"},{"name":"__slots__","type":"statement"},{"name":"__str__","type":"function"}],"string":"[\n {\n \"name\": \"analysis_func\",\n \"type\": \"function\"\n },\n {\n \"name\": \"create_calltree\",\n \"type\": \"function\"\n },\n {\n \"name\": \"create_fuzz_blocker_table\",\n \"type\": \"function\"\n },\n {\n \"name\": \"create_str_node_ctx_idx\",\n \"type\": \"function\"\n },\n {\n \"name\": \"get_fuzz_blockers\",\n \"type\": \"function\"\n },\n {\n \"name\": \"html_create_dedicated_calltree_file\",\n \"type\": \"function\"\n },\n {\n \"name\": \"name\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"__annotations__\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"__class__\",\n \"type\": \"property\"\n },\n {\n \"name\": \"__delattr__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__dict__\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"__dir__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__doc__\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"__eq__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__format__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__getattribute__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__hash__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__init__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__init_subclass__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__module__\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"__ne__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__new__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__reduce__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__reduce_ex__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__repr__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__setattr__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__sizeof__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__slots__\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"__str__\",\n \"type\": \"function\"\n }\n]"},"prefix":{"kind":"string","value":"# Copyright 2022 Fuzz Introspector Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Logic related to calltree analysis\"\"\"\n\nimport os\nimport logging\nimport json\n\nfrom typing import (\n List,\n Tuple,\n Optional,\n Set,\n)\n\nimport fuzz_analysis\nimport fuzz_data_loader\nimport fuzz_utils\nimport fuzz_cfg_load\nimport fuzz_html_helpers\n\n# For pretty printing the html code:\nfrom bs4 import BeautifulSoup as bs\n\nlogger = logging.getLogger(name=__name__)\n\n\nclass FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface):\n def __init__(self):\n self.name = \"FuzzCalltreeAnalysis\"\n logger.info(\"Creating FuzzCalltreeAnalysis\")\n\n def analysis_func(self,\n toc_list: List[Tuple[str, str, int]],\n tables: List[str],\n project_profile: fuzz_data_loader.MergedProjectProfile,\n profiles: List[fuzz_data_loader.FuzzerProfile],\n basefolder: str,\n coverage_url: str,\n conclusions) -> str:\n \"\"\"\n Creates the HTML of the calltree. Returns the HTML as a string.\n \"\"\"\n logger.info(\"Not implemented\")\n return \"\"\n\n def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str:\n logger.info(\"In calltree\")\n # Generate HTML for the calltree\n calltree_html_string = \"
\"\n calltree_html_string += \"

Fuzzer calltree

\"\n nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths)\n for i in range(len(nodes)):\n node = nodes[i]\n\n demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name)\n # We may not want to show certain functions at times, e.g. libc functions\n # in case it bloats the calltree\n # libc_funcs = { \"free\" }\n libc_funcs: Set[str] = set()\n avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0\n if avoid:\n continue\n\n # Prepare strings needed in the HTML\n color_to_be = node.cov_color\n callsite_link = node.cov_callsite_link\n link = node.cov_link\n ct_idx_str = self.create_str_node_ctx_idx(str(node.cov_ct_idx))\n\n # Only display [function] link if we have, otherwhise show no [function] text.\n if node.dst_function_source_file.replace(\" \", \"\") != \"/\":\n func_href = f\"\"\"[function]\"\"\"\n else:\n func_href = \"\"\n\n if i > 0:\n previous_node = nodes[i - 1]\n if previous_node.depth == node.depth:\n calltree_html_string += \"
\"\n depth_diff = previous_node.depth - node.depth\n if depth_diff >= 1:\n closing_divs = \"\" # To close \"calltree-line-wrapper\"\n closing_divs = \"\" * (int(depth_diff) + 1)\n calltree_html_string += closing_divs\n\n calltree_html_string += f\"\"\"\n
\n \n {node.depth}\n \n {demangled_name}\n \n \n {func_href}\n \n [call site2]\n \n [calltree idx: {ct_idx_str}]\n \n \n \"\"\"\n if i != len(nodes) - 1:\n next_node = nodes[i + 1]\n if next_node.depth > node.depth:\n calltree_html_string += f\"\"\"\"\"\"\n elif next_node.depth < node.depth:\n depth_diff = int(node.depth - next_node.depth)\n calltree_html_string += \"
\" * depth_diff\n\n calltree_html_string += \"\"\n logger.info(\"Calltree created\")\n\n # Write the HTML to a file called calltree_view_XX.html where XX is a counter.\n calltree_file_idx = 0\n calltree_html_file = f\"calltree_view_{calltree_file_idx}.html\"\n while os.path.isfile(calltree_html_file):\n calltree_file_idx += 1\n calltree_html_file = f\"calltree_view_{calltree_file_idx}.html\"\n\n self.html_create_dedicated_calltree_file(\n calltree_html_string,\n calltree_html_file,\n profile,\n )\n return calltree_html_file\n\n def html_create_dedicated_calltree_file(\n self,\n calltree_html_string,\n filename,\n profile: fuzz_data_loader.FuzzerProfile):\n \"\"\"\n Write a wrapped HTML file with the tags needed from fuzz-introspector\n We use this only for wrapping calltrees at the moment, however, down\n the line it makes sense to have an easy wrapper for other HTML pages too.\n \"\"\"\n complete_html_string = \"\"\n\n # HTML start\n html_header = fuzz_html_helpers.html_get_header(\n calltree=True,\n title=f\"Fuzz introspector: { profile.get_key() }\"\n )\n html_header += '
'\n complete_html_string += html_header\n\n # Display fuzz blocker at top of page\n fuzz_blockers = self.get_fuzz_blockers(\n profile,\n max_blockers_to_extract=12\n )\n\n fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], \"\", fuzz_blockers)\n if fuzz_blocker_table is not None:\n complete_html_string += \"
\"\n complete_html_string += \"

Fuzz blockers

\"\n complete_html_string += fuzz_blocker_table\n complete_html_string += \"
\"\n\n # Display calltree\n complete_html_string += calltree_html_string\n complete_html_string += \"
\"\n\n # HTML end\n html_end = ''\n blocker_idxs = []\n for node in fuzz_blockers:\n blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx)))\n\n if len(blocker_idxs) > 0:\n html_end = \"\"\n\n html_end += \"\"\n html_end += \"\"\n html_end += \"\"\n complete_html_string += html_end\n\n complete_html_string += \"\"\n\n # Beautify and write HTML\n soup = bs(complete_html_string, 'lxml')\n pretty_html = soup.prettify()\n with open(filename, \"w+\") as cf:\n cf.write(pretty_html)\n\n def create_str_node_ctx_idx(self, cov_ct_idx):\n prefixed_zeros = \"0\" * (len(\"00000\") - len(cov_ct_idx))\n return f\"{prefixed_zeros}{cov_ct_idx}\"\n\n def get_fuzz_blockers(\n self,\n profile: fuzz_data_loader.FuzzerProfile,\n max_blockers_to_extract=999):\n \"\"\"Gets a list of fuzz blockers\"\"\"\n blocker_list: List[fuzz_cfg_load.CalltreeCallsite] = list()\n\n # Extract all callsites in calltree and exit early if none\n all_callsites = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths)\n if len(all_callsites) == 0:\n return blocker_list\n\n # Filter nodes that has forward reds. Extract maximum max_blockers_to_extract nodes.\n nodes_sorted_by_red_ahead = sorted(all_callsites,\n key=lambda x: x.cov_forward_reds,\n reverse=True)\n for node in nodes_sorted_by_red_ahead:\n if node.cov_forward_reds == 0 or len(blocker_list) >= max_blockers_to_extract:\n break\n blocker_list.append(node)\n return blocker_list\n\n def create_fuzz_blocker_table(\n self,\n profile: fuzz_data_loader.FuzzerProfile,\n tables: List[str],\n calltree_file_name: str,\n fuzz_blockers=None) -> Optional[str]:\n \"\"\"\n Creates HTML string for table showing fuzz blockers.\n \"\"\"\n logger.info(\"Creating fuzz blocker table\")\n\n # Get the fuzz blockers\n if fuzz_blockers is None:\n fuzz_blockers = self."},"intellij_completions_filtered":{"kind":"list like","value":["get_fuzz_blockers","create_fuzz_blocker_table","name","create_str_node_ctx_idx","html_create_dedicated_calltree_file","analysis_func","create_calltree"],"string":"[\n \"get_fuzz_blockers\",\n \"create_fuzz_blocker_table\",\n \"name\",\n \"create_str_node_ctx_idx\",\n \"html_create_dedicated_calltree_file\",\n \"analysis_func\",\n \"create_calltree\"\n]"},"prefix_truncated":{"kind":"string","value":"ee.js\\\">\"\n complete_html_string += html_end\n\n complete_html_string += \"\"\n\n # Beautify and write HTML\n soup = bs(complete_html_string, 'lxml')\n pretty_html = soup.prettify()\n with open(filename, \"w+\") as cf:\n cf.write(pretty_html)\n\n def create_str_node_ctx_idx(self, cov_ct_idx):\n prefixed_zeros = \"0\" * (len(\"00000\") - len(cov_ct_idx))\n return f\"{prefixed_zeros}{cov_ct_idx}\"\n\n def get_fuzz_blockers(\n self,\n profile: fuzz_data_loader.FuzzerProfile,\n max_blockers_to_extract=999):\n \"\"\"Gets a list of fuzz blockers\"\"\"\n blocker_list: List[fuzz_cfg_load.CalltreeCallsite] = list()\n\n # Extract all callsites in calltree and exit early if none\n all_callsites = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths)\n if len(all_callsites) == 0:\n return blocker_list\n\n # Filter nodes that has forward reds. Extract maximum max_blockers_to_extract nodes.\n nodes_sorted_by_red_ahead = sorted(all_callsites,\n key=lambda x: x.cov_forward_reds,\n reverse=True)\n for node in nodes_sorted_by_red_ahead:\n if node.cov_forward_reds == 0 or len(blocker_list) >= max_blockers_to_extract:\n break\n blocker_list.append(node)\n return blocker_list\n\n def create_fuzz_blocker_table(\n self,\n profile: fuzz_data_loader.FuzzerProfile,\n tables: List[str],\n calltree_file_name: str,\n fuzz_blockers=None) -> Optional[str]:\n \"\"\"\n Creates HTML string for table showing fuzz blockers.\n \"\"\"\n logger.info(\"Creating fuzz blocker table\")\n\n # Get the fuzz blockers\n if fuzz_blockers is None:\n fuzz_blockers = self."},"__index_level_0__":{"kind":"number","value":30,"string":"30"}}},{"rowIdx":17,"cells":{"idx":{"kind":"number","value":42,"string":"42"},"idx_lca":{"kind":"number","value":0,"string":"0"},"offset":{"kind":"number","value":9537,"string":"9,537"},"repo":{"kind":"string","value":"ossf__fuzz-introspector"},"commit_hash":{"kind":"string","value":"4867924b714a7789f94fbcde53713a29ceab7272"},"target_file":{"kind":"string","value":"post-processing/analyses/fuzz_calltree_analysis.py"},"line_type_lca":{"kind":"string","value":"inproject"},"ground_truth":{"kind":"string","value":"html_create_table_head"},"in_completions":{"kind":"bool","value":true,"string":"true"},"completion_type":{"kind":"string","value":"function"},"non_dunder_count_intellij":{"kind":"number","value":9,"string":"9"},"non_dunder_count_jedi":{"kind":"number","value":9,"string":"9"},"start_with_":{"kind":"bool","value":false,"string":"false"},"first_occurrence":{"kind":"bool","value":true,"string":"true"},"intellij_completions":{"kind":"list like","value":["html_table_add_row","html_get_header","html_create_table_head","html_get_table_of_contents","html_get_navbar","html_add_header_with_link","Any","List","Tuple"],"string":"[\n \"html_table_add_row\",\n \"html_get_header\",\n \"html_create_table_head\",\n \"html_get_table_of_contents\",\n \"html_get_navbar\",\n \"html_add_header_with_link\",\n \"Any\",\n \"List\",\n \"Tuple\"\n]"},"jedi_completions":{"kind":"list like","value":[{"name":"Any","type":"class"},{"name":"html_add_header_with_link","type":"function"},{"name":"html_create_table_head","type":"function"},{"name":"html_get_header","type":"function"},{"name":"html_get_navbar","type":"function"},{"name":"html_get_table_of_contents","type":"function"},{"name":"html_table_add_row","type":"function"},{"name":"List","type":"class"},{"name":"Tuple","type":"class"},{"name":"__doc__","type":"instance"},{"name":"__file__","type":"instance"},{"name":"__name__","type":"instance"},{"name":"__package__","type":"instance"}],"string":"[\n {\n \"name\": \"Any\",\n \"type\": \"class\"\n },\n {\n \"name\": \"html_add_header_with_link\",\n \"type\": \"function\"\n },\n {\n \"name\": \"html_create_table_head\",\n \"type\": \"function\"\n },\n {\n \"name\": \"html_get_header\",\n \"type\": \"function\"\n },\n {\n \"name\": \"html_get_navbar\",\n \"type\": \"function\"\n },\n {\n \"name\": \"html_get_table_of_contents\",\n \"type\": \"function\"\n },\n {\n \"name\": \"html_table_add_row\",\n \"type\": \"function\"\n },\n {\n \"name\": \"List\",\n \"type\": \"class\"\n },\n {\n \"name\": \"Tuple\",\n \"type\": \"class\"\n },\n {\n \"name\": \"__doc__\",\n \"type\": \"instance\"\n },\n {\n \"name\": \"__file__\",\n \"type\": \"instance\"\n },\n {\n \"name\": \"__name__\",\n \"type\": \"instance\"\n },\n {\n \"name\": \"__package__\",\n \"type\": \"instance\"\n }\n]"},"prefix":{"kind":"string","value":"# Copyright 2022 Fuzz Introspector Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Logic related to calltree analysis\"\"\"\n\nimport os\nimport logging\nimport json\n\nfrom typing import (\n List,\n Tuple,\n Optional,\n Set,\n)\n\nimport fuzz_analysis\nimport fuzz_data_loader\nimport fuzz_utils\nimport fuzz_cfg_load\nimport fuzz_html_helpers\n\n# For pretty printing the html code:\nfrom bs4 import BeautifulSoup as bs\n\nlogger = logging.getLogger(name=__name__)\n\n\nclass FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface):\n def __init__(self):\n self.name = \"FuzzCalltreeAnalysis\"\n logger.info(\"Creating FuzzCalltreeAnalysis\")\n\n def analysis_func(self,\n toc_list: List[Tuple[str, str, int]],\n tables: List[str],\n project_profile: fuzz_data_loader.MergedProjectProfile,\n profiles: List[fuzz_data_loader.FuzzerProfile],\n basefolder: str,\n coverage_url: str,\n conclusions) -> str:\n \"\"\"\n Creates the HTML of the calltree. Returns the HTML as a string.\n \"\"\"\n logger.info(\"Not implemented\")\n return \"\"\n\n def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str:\n logger.info(\"In calltree\")\n # Generate HTML for the calltree\n calltree_html_string = \"
\"\n calltree_html_string += \"

Fuzzer calltree

\"\n nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths)\n for i in range(len(nodes)):\n node = nodes[i]\n\n demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name)\n # We may not want to show certain functions at times, e.g. libc functions\n # in case it bloats the calltree\n # libc_funcs = { \"free\" }\n libc_funcs: Set[str] = set()\n avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0\n if avoid:\n continue\n\n # Prepare strings needed in the HTML\n color_to_be = node.cov_color\n callsite_link = node.cov_callsite_link\n link = node.cov_link\n ct_idx_str = self.create_str_node_ctx_idx(str(node.cov_ct_idx))\n\n # Only display [function] link if we have, otherwhise show no [function] text.\n if node.dst_function_source_file.replace(\" \", \"\") != \"/\":\n func_href = f\"\"\"[function]\"\"\"\n else:\n func_href = \"\"\n\n if i > 0:\n previous_node = nodes[i - 1]\n if previous_node.depth == node.depth:\n calltree_html_string += \"
\"\n depth_diff = previous_node.depth - node.depth\n if depth_diff >= 1:\n closing_divs = \"\" # To close \"calltree-line-wrapper\"\n closing_divs = \"\" * (int(depth_diff) + 1)\n calltree_html_string += closing_divs\n\n calltree_html_string += f\"\"\"\n
\n \n {node.depth}\n \n {demangled_name}\n \n \n {func_href}\n \n [call site2]\n \n [calltree idx: {ct_idx_str}]\n \n \n \"\"\"\n if i != len(nodes) - 1:\n next_node = nodes[i + 1]\n if next_node.depth > node.depth:\n calltree_html_string += f\"\"\"\"\"\"\n elif next_node.depth < node.depth:\n depth_diff = int(node.depth - next_node.depth)\n calltree_html_string += \"
\" * depth_diff\n\n calltree_html_string += \"\"\n logger.info(\"Calltree created\")\n\n # Write the HTML to a file called calltree_view_XX.html where XX is a counter.\n calltree_file_idx = 0\n calltree_html_file = f\"calltree_view_{calltree_file_idx}.html\"\n while os.path.isfile(calltree_html_file):\n calltree_file_idx += 1\n calltree_html_file = f\"calltree_view_{calltree_file_idx}.html\"\n\n self.html_create_dedicated_calltree_file(\n calltree_html_string,\n calltree_html_file,\n profile,\n )\n return calltree_html_file\n\n def html_create_dedicated_calltree_file(\n self,\n calltree_html_string,\n filename,\n profile: fuzz_data_loader.FuzzerProfile):\n \"\"\"\n Write a wrapped HTML file with the tags needed from fuzz-introspector\n We use this only for wrapping calltrees at the moment, however, down\n the line it makes sense to have an easy wrapper for other HTML pages too.\n \"\"\"\n complete_html_string = \"\"\n\n # HTML start\n html_header = fuzz_html_helpers.html_get_header(\n calltree=True,\n title=f\"Fuzz introspector: { profile.get_key() }\"\n )\n html_header += '
'\n complete_html_string += html_header\n\n # Display fuzz blocker at top of page\n fuzz_blockers = self.get_fuzz_blockers(\n profile,\n max_blockers_to_extract=12\n )\n\n fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], \"\", fuzz_blockers)\n if fuzz_blocker_table is not None:\n complete_html_string += \"
\"\n complete_html_string += \"

Fuzz blockers

\"\n complete_html_string += fuzz_blocker_table\n complete_html_string += \"
\"\n\n # Display calltree\n complete_html_string += calltree_html_string\n complete_html_string += \"
\"\n\n # HTML end\n html_end = ''\n blocker_idxs = []\n for node in fuzz_blockers:\n blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx)))\n\n if len(blocker_idxs) > 0:\n html_end = \"\"\n\n html_end += \"\"\n html_end += \"\"\n html_end += \"\"\n complete_html_string += html_end\n\n complete_html_string += \"\"\n\n # Beautify and write HTML\n soup = bs(complete_html_string, 'lxml')\n pretty_html = soup.prettify()\n with open(filename, \"w+\") as cf:\n cf.write(pretty_html)\n\n def create_str_node_ctx_idx(self, cov_ct_idx):\n prefixed_zeros = \"0\" * (len(\"00000\") - len(cov_ct_idx))\n return f\"{prefixed_zeros}{cov_ct_idx}\"\n\n def get_fuzz_blockers(\n self,\n profile: fuzz_data_loader.FuzzerProfile,\n max_blockers_to_extract=999):\n \"\"\"Gets a list of fuzz blockers\"\"\"\n blocker_list: List[fuzz_cfg_load.CalltreeCallsite] = list()\n\n # Extract all callsites in calltree and exit early if none\n all_callsites = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths)\n if len(all_callsites) == 0:\n return blocker_list\n\n # Filter nodes that has forward reds. Extract maximum max_blockers_to_extract nodes.\n nodes_sorted_by_red_ahead = sorted(all_callsites,\n key=lambda x: x.cov_forward_reds,\n reverse=True)\n for node in nodes_sorted_by_red_ahead:\n if node.cov_forward_reds == 0 or len(blocker_list) >= max_blockers_to_extract:\n break\n blocker_list.append(node)\n return blocker_list\n\n def create_fuzz_blocker_table(\n self,\n profile: fuzz_data_loader.FuzzerProfile,\n tables: List[str],\n calltree_file_name: str,\n fuzz_blockers=None) -> Optional[str]:\n \"\"\"\n Creates HTML string for table showing fuzz blockers.\n \"\"\"\n logger.info(\"Creating fuzz blocker table\")\n\n # Get the fuzz blockers\n if fuzz_blockers is None:\n fuzz_blockers = self.get_fuzz_blockers(\n profile,\n max_blockers_to_extract=12\n )\n if len(fuzz_blockers) == 0:\n return None\n\n html_table_string = \"

The followings nodes \" \\\n \"represent call sites where fuzz blockers occur

\"\n tables.append(f\"myTable{len(tables)}\")\n html_table_string += fuzz_html_helpers."},"intellij_completions_filtered":{"kind":"list like","value":["html_table_add_row","html_get_header","html_create_table_head","html_get_table_of_contents","html_get_navbar","html_add_header_with_link","Any","List","Tuple"],"string":"[\n \"html_table_add_row\",\n \"html_get_header\",\n \"html_create_table_head\",\n \"html_get_table_of_contents\",\n \"html_get_navbar\",\n \"html_add_header_with_link\",\n \"Any\",\n \"List\",\n \"Tuple\"\n]"},"prefix_truncated":{"kind":"string","value":"idx))\n return f\"{prefixed_zeros}{cov_ct_idx}\"\n\n def get_fuzz_blockers(\n self,\n profile: fuzz_data_loader.FuzzerProfile,\n max_blockers_to_extract=999):\n \"\"\"Gets a list of fuzz blockers\"\"\"\n blocker_list: List[fuzz_cfg_load.CalltreeCallsite] = list()\n\n # Extract all callsites in calltree and exit early if none\n all_callsites = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths)\n if len(all_callsites) == 0:\n return blocker_list\n\n # Filter nodes that has forward reds. Extract maximum max_blockers_to_extract nodes.\n nodes_sorted_by_red_ahead = sorted(all_callsites,\n key=lambda x: x.cov_forward_reds,\n reverse=True)\n for node in nodes_sorted_by_red_ahead:\n if node.cov_forward_reds == 0 or len(blocker_list) >= max_blockers_to_extract:\n break\n blocker_list.append(node)\n return blocker_list\n\n def create_fuzz_blocker_table(\n self,\n profile: fuzz_data_loader.FuzzerProfile,\n tables: List[str],\n calltree_file_name: str,\n fuzz_blockers=None) -> Optional[str]:\n \"\"\"\n Creates HTML string for table showing fuzz blockers.\n \"\"\"\n logger.info(\"Creating fuzz blocker table\")\n\n # Get the fuzz blockers\n if fuzz_blockers is None:\n fuzz_blockers = self.get_fuzz_blockers(\n profile,\n max_blockers_to_extract=12\n )\n if len(fuzz_blockers) == 0:\n return None\n\n html_table_string = \"

The followings nodes \" \\\n \"represent call sites where fuzz blockers occur

\"\n tables.append(f\"myTable{len(tables)}\")\n html_table_string += fuzz_html_helpers."},"__index_level_0__":{"kind":"number","value":31,"string":"31"}}},{"rowIdx":18,"cells":{"idx":{"kind":"number","value":45,"string":"45"},"idx_lca":{"kind":"number","value":0,"string":"0"},"offset":{"kind":"number","value":10653,"string":"10,653"},"repo":{"kind":"string","value":"ossf__fuzz-introspector"},"commit_hash":{"kind":"string","value":"4867924b714a7789f94fbcde53713a29ceab7272"},"target_file":{"kind":"string","value":"post-processing/analyses/fuzz_calltree_analysis.py"},"line_type_lca":{"kind":"string","value":"inproject"},"ground_truth":{"kind":"string","value":"html_table_add_row"},"in_completions":{"kind":"bool","value":true,"string":"true"},"completion_type":{"kind":"string","value":"function"},"non_dunder_count_intellij":{"kind":"number","value":9,"string":"9"},"non_dunder_count_jedi":{"kind":"number","value":9,"string":"9"},"start_with_":{"kind":"bool","value":false,"string":"false"},"first_occurrence":{"kind":"bool","value":true,"string":"true"},"intellij_completions":{"kind":"list like","value":["html_create_table_head","html_get_header","List","html_get_table_of_contents","html_table_add_row","html_add_header_with_link","html_get_navbar","Any","Tuple"],"string":"[\n \"html_create_table_head\",\n \"html_get_header\",\n \"List\",\n \"html_get_table_of_contents\",\n \"html_table_add_row\",\n \"html_add_header_with_link\",\n \"html_get_navbar\",\n \"Any\",\n \"Tuple\"\n]"},"jedi_completions":{"kind":"list like","value":[{"name":"Any","type":"class"},{"name":"html_add_header_with_link","type":"function"},{"name":"html_create_table_head","type":"function"},{"name":"html_get_header","type":"function"},{"name":"html_get_navbar","type":"function"},{"name":"html_get_table_of_contents","type":"function"},{"name":"html_table_add_row","type":"function"},{"name":"List","type":"class"},{"name":"Tuple","type":"class"},{"name":"__doc__","type":"instance"},{"name":"__file__","type":"instance"},{"name":"__name__","type":"instance"},{"name":"__package__","type":"instance"}],"string":"[\n {\n \"name\": \"Any\",\n \"type\": \"class\"\n },\n {\n \"name\": \"html_add_header_with_link\",\n \"type\": \"function\"\n },\n {\n \"name\": \"html_create_table_head\",\n \"type\": \"function\"\n },\n {\n \"name\": \"html_get_header\",\n \"type\": \"function\"\n },\n {\n \"name\": \"html_get_navbar\",\n \"type\": \"function\"\n },\n {\n \"name\": \"html_get_table_of_contents\",\n \"type\": \"function\"\n },\n {\n \"name\": \"html_table_add_row\",\n \"type\": \"function\"\n },\n {\n \"name\": \"List\",\n \"type\": \"class\"\n },\n {\n \"name\": \"Tuple\",\n \"type\": \"class\"\n },\n {\n \"name\": \"__doc__\",\n \"type\": \"instance\"\n },\n {\n \"name\": \"__file__\",\n \"type\": \"instance\"\n },\n {\n \"name\": \"__name__\",\n \"type\": \"instance\"\n },\n {\n \"name\": \"__package__\",\n \"type\": \"instance\"\n }\n]"},"prefix":{"kind":"string","value":"# Copyright 2022 Fuzz Introspector Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Logic related to calltree analysis\"\"\"\n\nimport os\nimport logging\nimport json\n\nfrom typing import (\n List,\n Tuple,\n Optional,\n Set,\n)\n\nimport fuzz_analysis\nimport fuzz_data_loader\nimport fuzz_utils\nimport fuzz_cfg_load\nimport fuzz_html_helpers\n\n# For pretty printing the html code:\nfrom bs4 import BeautifulSoup as bs\n\nlogger = logging.getLogger(name=__name__)\n\n\nclass FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface):\n def __init__(self):\n self.name = \"FuzzCalltreeAnalysis\"\n logger.info(\"Creating FuzzCalltreeAnalysis\")\n\n def analysis_func(self,\n toc_list: List[Tuple[str, str, int]],\n tables: List[str],\n project_profile: fuzz_data_loader.MergedProjectProfile,\n profiles: List[fuzz_data_loader.FuzzerProfile],\n basefolder: str,\n coverage_url: str,\n conclusions) -> str:\n \"\"\"\n Creates the HTML of the calltree. Returns the HTML as a string.\n \"\"\"\n logger.info(\"Not implemented\")\n return \"\"\n\n def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str:\n logger.info(\"In calltree\")\n # Generate HTML for the calltree\n calltree_html_string = \"
\"\n calltree_html_string += \"

Fuzzer calltree

\"\n nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths)\n for i in range(len(nodes)):\n node = nodes[i]\n\n demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name)\n # We may not want to show certain functions at times, e.g. libc functions\n # in case it bloats the calltree\n # libc_funcs = { \"free\" }\n libc_funcs: Set[str] = set()\n avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0\n if avoid:\n continue\n\n # Prepare strings needed in the HTML\n color_to_be = node.cov_color\n callsite_link = node.cov_callsite_link\n link = node.cov_link\n ct_idx_str = self.create_str_node_ctx_idx(str(node.cov_ct_idx))\n\n # Only display [function] link if we have, otherwhise show no [function] text.\n if node.dst_function_source_file.replace(\" \", \"\") != \"/\":\n func_href = f\"\"\"[function]\"\"\"\n else:\n func_href = \"\"\n\n if i > 0:\n previous_node = nodes[i - 1]\n if previous_node.depth == node.depth:\n calltree_html_string += \"
\"\n depth_diff = previous_node.depth - node.depth\n if depth_diff >= 1:\n closing_divs = \"\" # To close \"calltree-line-wrapper\"\n closing_divs = \"\" * (int(depth_diff) + 1)\n calltree_html_string += closing_divs\n\n calltree_html_string += f\"\"\"\n
\n \n {node.depth}\n \n {demangled_name}\n \n \n {func_href}\n \n [call site2]\n \n [calltree idx: {ct_idx_str}]\n \n \n \"\"\"\n if i != len(nodes) - 1:\n next_node = nodes[i + 1]\n if next_node.depth > node.depth:\n calltree_html_string += f\"\"\"\"\"\"\n elif next_node.depth < node.depth:\n depth_diff = int(node.depth - next_node.depth)\n calltree_html_string += \"
\" * depth_diff\n\n calltree_html_string += \"\"\n logger.info(\"Calltree created\")\n\n # Write the HTML to a file called calltree_view_XX.html where XX is a counter.\n calltree_file_idx = 0\n calltree_html_file = f\"calltree_view_{calltree_file_idx}.html\"\n while os.path.isfile(calltree_html_file):\n calltree_file_idx += 1\n calltree_html_file = f\"calltree_view_{calltree_file_idx}.html\"\n\n self.html_create_dedicated_calltree_file(\n calltree_html_string,\n calltree_html_file,\n profile,\n )\n return calltree_html_file\n\n def html_create_dedicated_calltree_file(\n self,\n calltree_html_string,\n filename,\n profile: fuzz_data_loader.FuzzerProfile):\n \"\"\"\n Write a wrapped HTML file with the tags needed from fuzz-introspector\n We use this only for wrapping calltrees at the moment, however, down\n the line it makes sense to have an easy wrapper for other HTML pages too.\n \"\"\"\n complete_html_string = \"\"\n\n # HTML start\n html_header = fuzz_html_helpers.html_get_header(\n calltree=True,\n title=f\"Fuzz introspector: { profile.get_key() }\"\n )\n html_header += '
'\n complete_html_string += html_header\n\n # Display fuzz blocker at top of page\n fuzz_blockers = self.get_fuzz_blockers(\n profile,\n max_blockers_to_extract=12\n )\n\n fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], \"\", fuzz_blockers)\n if fuzz_blocker_table is not None:\n complete_html_string += \"
\"\n complete_html_string += \"

Fuzz blockers

\"\n complete_html_string += fuzz_blocker_table\n complete_html_string += \"
\"\n\n # Display calltree\n complete_html_string += calltree_html_string\n complete_html_string += \"
\"\n\n # HTML end\n html_end = ''\n blocker_idxs = []\n for node in fuzz_blockers:\n blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx)))\n\n if len(blocker_idxs) > 0:\n html_end = \"\"\n\n html_end += \"\"\n html_end += \"\"\n html_end += \"\"\n complete_html_string += html_end\n\n complete_html_string += \"\"\n\n # Beautify and write HTML\n soup = bs(complete_html_string, 'lxml')\n pretty_html = soup.prettify()\n with open(filename, \"w+\") as cf:\n cf.write(pretty_html)\n\n def create_str_node_ctx_idx(self, cov_ct_idx):\n prefixed_zeros = \"0\" * (len(\"00000\") - len(cov_ct_idx))\n return f\"{prefixed_zeros}{cov_ct_idx}\"\n\n def get_fuzz_blockers(\n self,\n profile: fuzz_data_loader.FuzzerProfile,\n max_blockers_to_extract=999):\n \"\"\"Gets a list of fuzz blockers\"\"\"\n blocker_list: List[fuzz_cfg_load.CalltreeCallsite] = list()\n\n # Extract all callsites in calltree and exit early if none\n all_callsites = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths)\n if len(all_callsites) == 0:\n return blocker_list\n\n # Filter nodes that has forward reds. Extract maximum max_blockers_to_extract nodes.\n nodes_sorted_by_red_ahead = sorted(all_callsites,\n key=lambda x: x.cov_forward_reds,\n reverse=True)\n for node in nodes_sorted_by_red_ahead:\n if node.cov_forward_reds == 0 or len(blocker_list) >= max_blockers_to_extract:\n break\n blocker_list.append(node)\n return blocker_list\n\n def create_fuzz_blocker_table(\n self,\n profile: fuzz_data_loader.FuzzerProfile,\n tables: List[str],\n calltree_file_name: str,\n fuzz_blockers=None) -> Optional[str]:\n \"\"\"\n Creates HTML string for table showing fuzz blockers.\n \"\"\"\n logger.info(\"Creating fuzz blocker table\")\n\n # Get the fuzz blockers\n if fuzz_blockers is None:\n fuzz_blockers = self.get_fuzz_blockers(\n profile,\n max_blockers_to_extract=12\n )\n if len(fuzz_blockers) == 0:\n return None\n\n html_table_string = \"

The followings nodes \" \\\n \"represent call sites where fuzz blockers occur

\"\n tables.append(f\"myTable{len(tables)}\")\n html_table_string += fuzz_html_helpers.html_create_table_head(\n tables[-1],\n [\n (\"Amount of callsites blocked\",\n \"Total amount of callsites blocked\"),\n (\"Calltree index\",\n \"Index in call tree where the fuzz blocker is.\"),\n (\"Parent function\",\n \"Function in which the call site that blocks resides.\"),\n (\"Callsite\",\n \"\"),\n (\"Largest blocked function\",\n \"This is the function with highest cyclomatiic complexity amongst\"\n \"all of the functions that are blocked. As such, it's a way of \"\n \"highlighting a potentially important function being blocked\")\n ],\n sort_by_column=0,\n sort_order=\"desc\"\n )\n for node in fuzz_blockers:\n link_prefix = \"0\" * (5 - len(str(node.cov_ct_idx)))\n node_link = \"%s?scrollToNode=%s%s\" % (\n calltree_file_name,\n link_prefix,\n node.cov_ct_idx\n )\n html_table_string += fuzz_html_helpers."},"intellij_completions_filtered":{"kind":"list like","value":["html_create_table_head","html_get_header","List","html_get_table_of_contents","html_table_add_row","html_add_header_with_link","html_get_navbar","Any","Tuple"],"string":"[\n \"html_create_table_head\",\n \"html_get_header\",\n \"List\",\n \"html_get_table_of_contents\",\n \"html_table_add_row\",\n \"html_add_header_with_link\",\n \"html_get_navbar\",\n \"Any\",\n \"Tuple\"\n]"},"prefix_truncated":{"kind":"string","value":": fuzz_data_loader.FuzzerProfile,\n tables: List[str],\n calltree_file_name: str,\n fuzz_blockers=None) -> Optional[str]:\n \"\"\"\n Creates HTML string for table showing fuzz blockers.\n \"\"\"\n logger.info(\"Creating fuzz blocker table\")\n\n # Get the fuzz blockers\n if fuzz_blockers is None:\n fuzz_blockers = self.get_fuzz_blockers(\n profile,\n max_blockers_to_extract=12\n )\n if len(fuzz_blockers) == 0:\n return None\n\n html_table_string = \"

The followings nodes \" \\\n \"represent call sites where fuzz blockers occur

\"\n tables.append(f\"myTable{len(tables)}\")\n html_table_string += fuzz_html_helpers.html_create_table_head(\n tables[-1],\n [\n (\"Amount of callsites blocked\",\n \"Total amount of callsites blocked\"),\n (\"Calltree index\",\n \"Index in call tree where the fuzz blocker is.\"),\n (\"Parent function\",\n \"Function in which the call site that blocks resides.\"),\n (\"Callsite\",\n \"\"),\n (\"Largest blocked function\",\n \"This is the function with highest cyclomatiic complexity amongst\"\n \"all of the functions that are blocked. As such, it's a way of \"\n \"highlighting a potentially important function being blocked\")\n ],\n sort_by_column=0,\n sort_order=\"desc\"\n )\n for node in fuzz_blockers:\n link_prefix = \"0\" * (5 - len(str(node.cov_ct_idx)))\n node_link = \"%s?scrollToNode=%s%s\" % (\n calltree_file_name,\n link_prefix,\n node.cov_ct_idx\n )\n html_table_string += fuzz_html_helpers."},"__index_level_0__":{"kind":"number","value":34,"string":"34"}}},{"rowIdx":19,"cells":{"idx":{"kind":"number","value":64,"string":"64"},"idx_lca":{"kind":"number","value":1,"string":"1"},"offset":{"kind":"number","value":4330,"string":"4,330"},"repo":{"kind":"string","value":"vanheeringen-lab__seq2science"},"commit_hash":{"kind":"string","value":"d5ff9782c8f6c4cd989f74684154c508b7c65127"},"target_file":{"kind":"string","value":"docs/scripts/clean_dags.py"},"line_type_lca":{"kind":"string","value":"infile"},"ground_truth":{"kind":"string","value":"type"},"in_completions":{"kind":"bool","value":true,"string":"true"},"completion_type":{"kind":"string","value":"statement"},"non_dunder_count_intellij":{"kind":"number","value":17,"string":"17"},"non_dunder_count_jedi":{"kind":"number","value":16,"string":"16"},"start_with_":{"kind":"bool","value":false,"string":"false"},"first_occurrence":{"kind":"bool","value":true,"string":"true"},"intellij_completions":{"kind":"list like","value":["edges","nodes","label2id","name","type","__init__","_get_node_id","_order_edges","color_node","edge_style","graph_style","hide_node","node_style","remove_edge","remove_node","transitive_reduction","write","for","__annotations__","__class__","__delattr__","__dict__","__dir__","__eq__","__format__","__getattribute__","__hash__","__init_subclass__","__ne__","__new__","__reduce__","__reduce_ex__","__repr__","__setattr__","__sizeof__","__str__","__subclasshook__","__doc__","__module__"],"string":"[\n \"edges\",\n \"nodes\",\n \"label2id\",\n \"name\",\n \"type\",\n \"__init__\",\n \"_get_node_id\",\n \"_order_edges\",\n \"color_node\",\n \"edge_style\",\n \"graph_style\",\n \"hide_node\",\n \"node_style\",\n \"remove_edge\",\n \"remove_node\",\n \"transitive_reduction\",\n \"write\",\n \"for\",\n \"__annotations__\",\n \"__class__\",\n \"__delattr__\",\n \"__dict__\",\n \"__dir__\",\n \"__eq__\",\n \"__format__\",\n \"__getattribute__\",\n \"__hash__\",\n \"__init_subclass__\",\n \"__ne__\",\n \"__new__\",\n \"__reduce__\",\n \"__reduce_ex__\",\n \"__repr__\",\n \"__setattr__\",\n \"__sizeof__\",\n \"__str__\",\n \"__subclasshook__\",\n \"__doc__\",\n \"__module__\"\n]"},"jedi_completions":{"kind":"list like","value":[{"name":"color_node","type":"function"},{"name":"edge_style","type":"statement"},{"name":"edges","type":"statement"},{"name":"graph_style","type":"statement"},{"name":"hide_node","type":"function"},{"name":"label2id","type":"statement"},{"name":"name","type":"statement"},{"name":"node_style","type":"statement"},{"name":"nodes","type":"statement"},{"name":"remove_edge","type":"function"},{"name":"remove_node","type":"function"},{"name":"transitive_reduction","type":"function"},{"name":"type","type":"statement"},{"name":"write","type":"function"},{"name":"_get_node_id","type":"function"},{"name":"_order_edges","type":"function"},{"name":"__annotations__","type":"statement"},{"name":"__class__","type":"property"},{"name":"__delattr__","type":"function"},{"name":"__dict__","type":"statement"},{"name":"__dir__","type":"function"},{"name":"__doc__","type":"statement"},{"name":"__eq__","type":"function"},{"name":"__format__","type":"function"},{"name":"__getattribute__","type":"function"},{"name":"__hash__","type":"function"},{"name":"__init__","type":"function"},{"name":"__init_subclass__","type":"function"},{"name":"__module__","type":"statement"},{"name":"__ne__","type":"function"},{"name":"__new__","type":"function"},{"name":"__reduce__","type":"function"},{"name":"__reduce_ex__","type":"function"},{"name":"__repr__","type":"function"},{"name":"__setattr__","type":"function"},{"name":"__sizeof__","type":"function"},{"name":"__slots__","type":"statement"},{"name":"__str__","type":"function"}],"string":"[\n {\n \"name\": \"color_node\",\n \"type\": \"function\"\n },\n {\n \"name\": \"edge_style\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"edges\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"graph_style\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"hide_node\",\n \"type\": \"function\"\n },\n {\n \"name\": \"label2id\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"name\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"node_style\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"nodes\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"remove_edge\",\n \"type\": \"function\"\n },\n {\n \"name\": \"remove_node\",\n \"type\": \"function\"\n },\n {\n \"name\": \"transitive_reduction\",\n \"type\": \"function\"\n },\n {\n \"name\": \"type\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"write\",\n \"type\": \"function\"\n },\n {\n \"name\": \"_get_node_id\",\n \"type\": \"function\"\n },\n {\n \"name\": \"_order_edges\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__annotations__\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"__class__\",\n \"type\": \"property\"\n },\n {\n \"name\": \"__delattr__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__dict__\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"__dir__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__doc__\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"__eq__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__format__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__getattribute__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__hash__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__init__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__init_subclass__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__module__\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"__ne__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__new__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__reduce__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__reduce_ex__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__repr__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__setattr__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__sizeof__\",\n \"type\": \"function\"\n },\n {\n \"name\": \"__slots__\",\n \"type\": \"statement\"\n },\n {\n \"name\": \"__str__\",\n \"type\": \"function\"\n }\n]"},"prefix":{"kind":"string","value":"import re\nimport networkx as nx\n\nrules_to_keep = {\n # \"0.13 0.6 0.85\", # yellow\n # \"0.09 0.6 0.85\", # brown\n # \"0.28 0.6 0.85\", # green\n # \"0.04 0.6 0.85\", # red\n # \"0.00 0.6 0.85\", # cherry\n # \"0.63 0.6 0.85\", # purple\n # \"0.59 0.6 0.85\", # dark blue\n # \"0.58 0.6 0.85\", # blue\n # \"0.49 0.6 0.85\", # teal\n # input\n \"get_genome\": \"0.49 0.6 0.85\", # teal\n \"ena2fastq_SE\": \"0.49 0.6 0.85\", # teal\n \"ena2fastq_PE\": \"0.49 0.6 0.85\", # teal\n \"sra2fastq_SE\": \"0.49 0.6 0.85\", # teal\n \"sra2fastq_PE\": \"0.49 0.6 0.85\", # teal\n # fastq\n \"fastp_SE\": \"0.13 0.6 0.85\", # yellow\n \"fastp_PE\": \"0.13 0.6 0.85\", # yellow\n \"trimgalore_SE\": \"0.13 0.6 0.85\", # yellow\n \"trimgalore_PE\": \"0.13 0.6 0.85\", # yellow\n \"merge_replicates\": \"0.13 0.6 0.85\", # yellow\n # align\n \"bowtie2_align\": \"0.13 0.6 0.85\", # yellow\n \"bwa_mem\": \"0.13 0.6 0.85\", # yellow\n \"bwa_mem2\": \"0.13 0.6 0.85\", # yellow\n \"hisat2_align\": \"0.13 0.6 0.85\", # yellow\n \"minimap2_align\": \"0.13 0.6 0.85\", # yellow\n \"star_align\": \"0.13 0.6 0.85\", # yellow\n \"mark_duplicates\": \"0.13 0.6 0.85\", # yellow\n \"sieve_bam\": \"0.13 0.6 0.85\", # yellow\n # peak counting\n \"macs2_callpeak\": \"0.13 0.6 0.85\", # yellow\n \"call_peak_genrich\": \"0.13 0.6 0.85\", # yellow\n \"hmmratac\": \"0.13 0.6 0.85\", # yellow\n \"create_SNAP_object\": \"0.13 0.6 0.85\", # yellow\n # gene counting/quantification\n \"htseq_count\": \"0.13 0.6 0.85\", # yellow\n \"featurecounts\": \"0.13 0.6 0.85\", # yellow\n \"salmon_quant\": \"0.13 0.6 0.85\", # yellow\n # trackhub\n \"bam_bigwig\": \"0.00 0.6 0.85\", # cherry\n \"peak_bigpeak\": \"0.00 0.6 0.85\", # cherry\n \"bedgraph_bigwig\": \"0.00 0.6 0.85\", # cherry\n \"trackhub\": \"0.00 0.6 0.85\", # cherry\n # multiqc\n \"multiqc\": \"0.63 0.6 0.85\", # purple\n # peak files\n \"coverage_table\": \"0.28 0.6 0.85\", # green\n \"onehot_peaks\": \"0.28 0.6 0.85\", # green\n \"create_bins_SNAP_object\": \"0.28 0.6 0.85\", # green\n # gene files\n \"gene_id2name\": \"0.28 0.6 0.85\", # green\n \"tpm_matrix\": \"0.28 0.6 0.85\", # green\n \"count_matrix\": \"0.28 0.6 0.85\", # green\n \"txi_count_matrix\": \"0.28 0.6 0.85\", # green\n \"pytxi_count_matrix\": \"0.28 0.6 0.85\", # green\n \"citeseqcount\": \"0.28 0.6 0.85\", # green\n \"kallistobus_count\": \"0.28 0.6 0.85\", # green\n # other\n \"gimme_maelstrom\": \"0.28 0.6 0.85\", # green\n \"deseq2\": \"0.28 0.6 0.85\", # green\n \"dexseq_count_matrix\": \"0.28 0.6 0.85\", # green\n}\n\n\nclass Digraph:\n def __init__(self, infile):\n with open(infile) as f:\n lines = f.readlines()\n self.type, self.name = lines[0].split()[0:2]\n self.graph_style = lines[1]\n self.node_style = lines[2]\n self.edge_style = lines[3]\n\n self.nodes = dict()\n self.edges = set()\n self.label2id = dict()\n l = re.compile(r'label = \"(.*?)\"')\n c = re.compile(r'color = \"(.*?)\"')\n s = re.compile(r'style=\"(.*?)\"')\n for line in lines[4:]:\n line = line.strip()\n\n # read edges\n edge = tuple(line.split(\" -> \"))\n if len(edge) == 2:\n self.edges.add(edge)\n\n # read nodes\n elif \"[\" in line[:5]:\n node_id = line.split(\"[\")[0]\n label = l.search(line).groups()[0]\n color = c.search(line).groups()[0]\n style = s.search(line).groups()[0]\n self.nodes[node_id] = {\n \"label\": label,\n \"color\": color,\n \"style\": style,\n }\n self.label2id[label] = node_id\n\n def _order_edges(self):\n \"\"\"\n edges are sorted by\n 1) ascending target nodes and\n 2) descending source nodes\n \"\"\"\n ordered = []\n sources = sorted(set(int(e[0]) for e in list(self.edges)), reverse=True)\n targets = sorted(set(int(e[1]) for e in list(self.edges)))\n for target in targets:\n for source in sources:\n edge = (str(source), str(target))\n if edge in self.edges:\n ordered.append(edge)\n return ordered\n\n def write(self, fname):\n with open(fname, \"w\") as f:\n f.write(\" \".join([self."},"intellij_completions_filtered":{"kind":"list like","value":["edges","nodes","label2id","name","type","color_node","edge_style","graph_style","hide_node","node_style","remove_edge","remove_node","transitive_reduction","write","for"],"string":"[\n \"edges\",\n \"nodes\",\n \"label2id\",\n \"name\",\n \"type\",\n \"color_node\",\n \"edge_style\",\n \"graph_style\",\n \"hide_node\",\n \"node_style\",\n \"remove_edge\",\n \"remove_node\",\n \"transitive_reduction\",\n \"write\",\n \"for\"\n]"},"prefix_truncated":{"kind":"string","value":"8 0.6 0.85\", # green\n \"deseq2\": \"0.28 0.6 0.85\", # green\n \"dexseq_count_matrix\": \"0.28 0.6 0.85\", # green\n}\n\n\nclass Digraph:\n def __init__(self, infile):\n with open(infile) as f:\n lines = f.readlines()\n self.type, self.name = lines[0].split()[0:2]\n self.graph_style = lines[1]\n self.node_style = lines[2]\n self.edge_style = lines[3]\n\n self.nodes = dict()\n self.edges = set()\n self.label2id = dict()\n l = re.compile(r'label = \"(.*?)\"')\n c = re.compile(r'color = \"(.*?)\"')\n s = re.compile(r'style=\"(.*?)\"')\n for line in lines[4:]:\n line = line.strip()\n\n # read edges\n edge = tuple(line.split(\" -> \"))\n if len(edge) == 2:\n self.edges.add(edge)\n\n # read nodes\n elif \"[\" in line[:5]:\n node_id = line.split(\"[\")[0]\n label = l.search(line).groups()[0]\n color = c.search(line).groups()[0]\n style = s.search(line).groups()[0]\n self.nodes[node_id] = {\n \"label\": label,\n \"color\": color,\n \"style\": style,\n }\n self.label2id[label] = node_id\n\n def _order_edges(self):\n \"\"\"\n edges are sorted by\n 1) ascending target nodes and\n 2) descending source nodes\n \"\"\"\n ordered = []\n sources = sorted(set(int(e[0]) for e in list(self.edges)), reverse=True)\n targets = sorted(set(int(e[1]) for e in list(self.edges)))\n for target in targets:\n for source in sources:\n edge = (str(source), str(target))\n if edge in self.edges:\n ordered.append(edge)\n return ordered\n\n def write(self, fname):\n with open(fname, \"w\") as f:\n f.write(\" \".join([self."},"__index_level_0__":{"kind":"number","value":45,"string":"45"}}}],"truncated":true},"paginationData":{"pageIndex":0,"numItemsPerPage":100,"numTotalItems":1557,"offset":0,"length":100}},"jwt":"eyJhbGciOiJFZERTQSJ9.eyJyZWFkIjp0cnVlLCJwZXJtaXNzaW9ucyI6eyJyZXBvLmNvbnRlbnQucmVhZCI6dHJ1ZX0sImlhdCI6MTc3MDQxNDQ5Niwic3ViIjoiL2RhdGFzZXRzL0RhbkNpcC9sY2EtU3RhcnRpbmdQb2ludHMtZXhwYW5kZWQtZmlsdGVyZWQiLCJleHAiOjE3NzA0MTgwOTYsImlzcyI6Imh0dHBzOi8vaHVnZ2luZ2ZhY2UuY28ifQ.ZDFDyLUF_xW3nN8NZJ4M8PGZ4CiL9DaWRANg9VlX5DiEOP-rvH4KGuYZy0FxRwMyRJH8gJ4LhsD7UxcDSy5WBA","displayUrls":true,"splitSizeSummaries":[{"config":"default","split":"train","numRows":1557,"numBytesParquet":2734773}]},"dataset":"DanCip/lca-StartingPoints-expanded-filtered","isGated":false,"isPrivate":false,"hasParquetFormat":true,"author":{"_id":"6554e2dcfcb10ad33d88dcea","avatarUrl":"https://aifasthub.com/avatars/v1/production/uploads/6554e2dcfcb10ad33d88dcea/V4WnB358ciZ0Ry3APDF57.png","fullname":"Daniele Cipollone","name":"DanCip","type":"user","isPro":false,"isHf":false,"isHfAdmin":false,"isMod":false,"followerCount":2,"isUserFollowing":false},"compact":true,"isLoggedIn":false}">
Dataset Viewer
Auto-converted to Parquet Duplicate
idx
int64
2
7.85k
idx_lca
int64
0
223
offset
int64
165
54.4k
repo
stringclasses
54 values
commit_hash
stringclasses
100 values
target_file
stringclasses
118 values
line_type_lca
stringclasses
6 values
ground_truth
stringlengths
1
40
in_completions
bool
1 class
completion_type
stringclasses
6 values
non_dunder_count_intellij
int64
1
127
non_dunder_count_jedi
int64
1
128
start_with_
bool
1 class
first_occurrence
bool
2 classes
intellij_completions
listlengths
1
149
jedi_completions
listlengths
3
148
prefix
stringlengths
165
54.4k
intellij_completions_filtered
listlengths
1
123
prefix_truncated
stringlengths
165
1.92k
__index_level_0__
int64
1
5.53k
2
0
1,333
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
inproject
MergedProjectProfile
true
class
14
19
false
true
[ "FuzzerProfile", "List", "MergedProjectProfile", "logger", "None", "add_func_to_reached_and_clone", "FunctionProfile", "load_all_profiles", "read_fuzzer_data_file_to_profile", "Any", "Dict", "Optional", "Set", "Tuple" ]
[ { "name": "add_func_to_reached_and_clone", "type": "function" }, { "name": "Any", "type": "class" }, { "name": "copy", "type": "module" }, { "name": "Dict", "type": "class" }, { "name": "FunctionProfile", "type": "class" }, { "name": "fuzz_cfg_load", "type": "module" }, { "name": "fuzz_cov_load", "type": "module" }, { "name": "fuzz_utils", "type": "module" }, { "name": "FuzzerProfile", "type": "class" }, { "name": "List", "type": "class" }, { "name": "load_all_profiles", "type": "function" }, { "name": "logger", "type": "statement" }, { "name": "logging", "type": "module" }, { "name": "MergedProjectProfile", "type": "class" }, { "name": "Optional", "type": "class" }, { "name": "os", "type": "module" }, { "name": "read_fuzzer_data_file_to_profile", "type": "function" }, { "name": "Set", "type": "class" }, { "name": "Tuple", "type": "class" }, { "name": "__doc__", "type": "instance" }, { "name": "__file__", "type": "instance" }, { "name": "__name__", "type": "instance" }, { "name": "__package__", "type": "instance" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.
[ "FuzzerProfile", "List", "MergedProjectProfile", "logger", "None", "add_func_to_reached_and_clone", "FunctionProfile", "load_all_profiles", "read_fuzzer_data_file_to_profile", "Any", "Dict", "Optional", "Set", "Tuple" ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.
1
3
0
1,409
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
inproject
FuzzerProfile
true
class
14
19
false
true
[ "FuzzerProfile", "MergedProjectProfile", "List", "logger", "None", "add_func_to_reached_and_clone", "FunctionProfile", "load_all_profiles", "read_fuzzer_data_file_to_profile", "Any", "Dict", "Optional", "Set", "Tuple" ]
[ { "name": "add_func_to_reached_and_clone", "type": "function" }, { "name": "Any", "type": "class" }, { "name": "copy", "type": "module" }, { "name": "Dict", "type": "class" }, { "name": "FunctionProfile", "type": "class" }, { "name": "fuzz_cfg_load", "type": "module" }, { "name": "fuzz_cov_load", "type": "module" }, { "name": "fuzz_utils", "type": "module" }, { "name": "FuzzerProfile", "type": "class" }, { "name": "List", "type": "class" }, { "name": "load_all_profiles", "type": "function" }, { "name": "logger", "type": "statement" }, { "name": "logging", "type": "module" }, { "name": "MergedProjectProfile", "type": "class" }, { "name": "Optional", "type": "class" }, { "name": "os", "type": "module" }, { "name": "read_fuzzer_data_file_to_profile", "type": "function" }, { "name": "Set", "type": "class" }, { "name": "Tuple", "type": "class" }, { "name": "__doc__", "type": "instance" }, { "name": "__file__", "type": "instance" }, { "name": "__name__", "type": "instance" }, { "name": "__package__", "type": "instance" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.
[ "FuzzerProfile", "MergedProjectProfile", "List", "logger", "None", "add_func_to_reached_and_clone", "FunctionProfile", "load_all_profiles", "read_fuzzer_data_file_to_profile", "Any", "Dict", "Optional", "Set", "Tuple" ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.
2
5
0
2,009
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
inproject
extract_all_callsites
true
function
8
9
false
true
[ "extract_all_callsites", "CalltreeCallsite", "List", "logger", "Optional", "data_file_read_calltree", "extract_all_callsites_recursive", "print_ctcs_tree" ]
[ { "name": "CalltreeCallsite", "type": "class" }, { "name": "data_file_read_calltree", "type": "function" }, { "name": "extract_all_callsites", "type": "function" }, { "name": "extract_all_callsites_recursive", "type": "function" }, { "name": "List", "type": "class" }, { "name": "logger", "type": "statement" }, { "name": "logging", "type": "module" }, { "name": "Optional", "type": "class" }, { "name": "print_ctcs_tree", "type": "function" }, { "name": "__doc__", "type": "instance" }, { "name": "__file__", "type": "instance" }, { "name": "__name__", "type": "instance" }, { "name": "__package__", "type": "instance" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.
[ "extract_all_callsites", "CalltreeCallsite", "List", "logger", "Optional", "data_file_read_calltree", "extract_all_callsites_recursive", "print_ctcs_tree" ]
2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.
4
7
0
2,166
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
inproject
demangle_cpp_func
true
function
13
18
false
true
[ "List", "logger", "Optional", "demangle_cpp_func", "scan_executables_for_fuzz_introspector_logs", "data_file_read_yaml", "get_all_files_in_tree_with_regex", "get_target_coverage_url", "longest_common_prefix", "normalise_str", "safe_decode", "Any", "Dict" ]
[ { "name": "Any", "type": "class" }, { "name": "cxxfilt", "type": "module" }, { "name": "data_file_read_yaml", "type": "function" }, { "name": "demangle_cpp_func", "type": "function" }, { "name": "Dict", "type": "class" }, { "name": "get_all_files_in_tree_with_regex", "type": "function" }, { "name": "get_target_coverage_url", "type": "function" }, { "name": "List", "type": "class" }, { "name": "logger", "type": "statement" }, { "name": "logging", "type": "module" }, { "name": "longest_common_prefix", "type": "function" }, { "name": "normalise_str", "type": "function" }, { "name": "Optional", "type": "class" }, { "name": "os", "type": "module" }, { "name": "re", "type": "module" }, { "name": "safe_decode", "type": "function" }, { "name": "scan_executables_for_fuzz_introspector_logs", "type": "function" }, { "name": "yaml", "type": "module" }, { "name": "__doc__", "type": "instance" }, { "name": "__file__", "type": "instance" }, { "name": "__name__", "type": "instance" }, { "name": "__package__", "type": "instance" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.
[ "List", "logger", "Optional", "demangle_cpp_func", "scan_executables_for_fuzz_introspector_logs", "data_file_read_yaml", "get_all_files_in_tree_with_regex", "get_target_coverage_url", "longest_common_prefix", "normalise_str", "safe_decode", "Any", "Dict" ]
.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.
5
8
0
2,189
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
inproject
dst_function_name
true
statement
17
17
false
true
[ "depth", "cov_ct_idx", "cov_forward_reds", "cov_largest_blocked_func", "cov_link", "children", "cov_callsite_link", "cov_color", "cov_hitcount", "cov_parent", "dst_function_name", "dst_function_source_file", "hitcount", "parent_calltree_callsite", "src_function_name", "src_function_source_file", "src_linenumber", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "children", "type": "statement" }, { "name": "cov_callsite_link", "type": "statement" }, { "name": "cov_color", "type": "statement" }, { "name": "cov_ct_idx", "type": "statement" }, { "name": "cov_forward_reds", "type": "statement" }, { "name": "cov_hitcount", "type": "statement" }, { "name": "cov_largest_blocked_func", "type": "statement" }, { "name": "cov_link", "type": "statement" }, { "name": "cov_parent", "type": "statement" }, { "name": "depth", "type": "statement" }, { "name": "dst_function_name", "type": "statement" }, { "name": "dst_function_source_file", "type": "statement" }, { "name": "hitcount", "type": "statement" }, { "name": "parent_calltree_callsite", "type": "statement" }, { "name": "src_function_name", "type": "statement" }, { "name": "src_function_source_file", "type": "statement" }, { "name": "src_linenumber", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.
[ "depth", "cov_ct_idx", "cov_forward_reds", "cov_largest_blocked_func", "cov_link", "children", "cov_callsite_link", "cov_color", "cov_hitcount", "cov_parent", "dst_function_name", "dst_function_source_file", "hitcount", "parent_calltree_callsite", "src_function_name", "src_function_source_file", "src_linenumber" ]
.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.
6
10
0
2,668
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
random
cov_callsite_link
true
statement
17
17
false
true
[ "cov_link", "depth", "cov_color", "cov_ct_idx", "cov_callsite_link", "children", "cov_forward_reds", "cov_hitcount", "cov_largest_blocked_func", "cov_parent", "dst_function_name", "dst_function_source_file", "hitcount", "parent_calltree_callsite", "src_function_name", "src_function_source_file", "src_linenumber", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "children", "type": "statement" }, { "name": "cov_callsite_link", "type": "statement" }, { "name": "cov_color", "type": "statement" }, { "name": "cov_ct_idx", "type": "statement" }, { "name": "cov_forward_reds", "type": "statement" }, { "name": "cov_hitcount", "type": "statement" }, { "name": "cov_largest_blocked_func", "type": "statement" }, { "name": "cov_link", "type": "statement" }, { "name": "cov_parent", "type": "statement" }, { "name": "depth", "type": "statement" }, { "name": "dst_function_name", "type": "statement" }, { "name": "dst_function_source_file", "type": "statement" }, { "name": "hitcount", "type": "statement" }, { "name": "parent_calltree_callsite", "type": "statement" }, { "name": "src_function_name", "type": "statement" }, { "name": "src_function_source_file", "type": "statement" }, { "name": "src_linenumber", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.
[ "cov_link", "depth", "cov_color", "cov_ct_idx", "cov_callsite_link", "children", "cov_forward_reds", "cov_hitcount", "cov_largest_blocked_func", "cov_parent", "dst_function_name", "dst_function_source_file", "hitcount", "parent_calltree_callsite", "src_function_name", "src_function_source_file", "src_linenumber" ]
z_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.
8
12
0
2,749
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
infile
create_str_node_ctx_idx
true
function
7
7
false
true
[ "create_str_node_ctx_idx", "get_fuzz_blockers", "name", "create_fuzz_blocker_table", "html_create_dedicated_calltree_file", "__init__", "analysis_func", "create_calltree", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "analysis_func", "type": "function" }, { "name": "create_calltree", "type": "function" }, { "name": "create_fuzz_blocker_table", "type": "function" }, { "name": "create_str_node_ctx_idx", "type": "function" }, { "name": "get_fuzz_blockers", "type": "function" }, { "name": "html_create_dedicated_calltree_file", "type": "function" }, { "name": "name", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.cov_callsite_link link = node.cov_link ct_idx_str = self.
[ "create_str_node_ctx_idx", "get_fuzz_blockers", "name", "create_fuzz_blocker_table", "html_create_dedicated_calltree_file", "analysis_func", "create_calltree" ]
fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.cov_callsite_link link = node.cov_link ct_idx_str = self.
10
13
0
2,782
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
infile
cov_ct_idx
true
statement
17
17
false
true
[ "cov_ct_idx", "depth", "dst_function_name", "cov_forward_reds", "cov_link", "children", "cov_callsite_link", "cov_color", "cov_hitcount", "cov_largest_blocked_func", "cov_parent", "dst_function_source_file", "hitcount", "parent_calltree_callsite", "src_function_name", "src_function_source_file", "src_linenumber", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "children", "type": "statement" }, { "name": "cov_callsite_link", "type": "statement" }, { "name": "cov_color", "type": "statement" }, { "name": "cov_ct_idx", "type": "statement" }, { "name": "cov_forward_reds", "type": "statement" }, { "name": "cov_hitcount", "type": "statement" }, { "name": "cov_largest_blocked_func", "type": "statement" }, { "name": "cov_link", "type": "statement" }, { "name": "cov_parent", "type": "statement" }, { "name": "depth", "type": "statement" }, { "name": "dst_function_name", "type": "statement" }, { "name": "dst_function_source_file", "type": "statement" }, { "name": "hitcount", "type": "statement" }, { "name": "parent_calltree_callsite", "type": "statement" }, { "name": "src_function_name", "type": "statement" }, { "name": "src_function_source_file", "type": "statement" }, { "name": "src_linenumber", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.cov_callsite_link link = node.cov_link ct_idx_str = self.create_str_node_ctx_idx(str(node.
[ "cov_ct_idx", "depth", "dst_function_name", "cov_forward_reds", "cov_link", "children", "cov_callsite_link", "cov_color", "cov_hitcount", "cov_largest_blocked_func", "cov_parent", "dst_function_source_file", "hitcount", "parent_calltree_callsite", "src_function_name", "src_function_source_file", "src_linenumber" ]
rinting the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.cov_callsite_link link = node.cov_link ct_idx_str = self.create_str_node_ctx_idx(str(node.
11
28
0
5,388
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
inproject
FuzzerProfile
true
class
14
19
false
false
[ "FuzzerProfile", "MergedProjectProfile", "None", "List", "logger", "add_func_to_reached_and_clone", "FunctionProfile", "load_all_profiles", "read_fuzzer_data_file_to_profile", "Any", "Dict", "Optional", "Set", "Tuple" ]
[ { "name": "add_func_to_reached_and_clone", "type": "function" }, { "name": "Any", "type": "class" }, { "name": "copy", "type": "module" }, { "name": "Dict", "type": "class" }, { "name": "FunctionProfile", "type": "class" }, { "name": "fuzz_cfg_load", "type": "module" }, { "name": "fuzz_cov_load", "type": "module" }, { "name": "fuzz_utils", "type": "module" }, { "name": "FuzzerProfile", "type": "class" }, { "name": "List", "type": "class" }, { "name": "load_all_profiles", "type": "function" }, { "name": "logger", "type": "statement" }, { "name": "logging", "type": "module" }, { "name": "MergedProjectProfile", "type": "class" }, { "name": "Optional", "type": "class" }, { "name": "os", "type": "module" }, { "name": "read_fuzzer_data_file_to_profile", "type": "function" }, { "name": "Set", "type": "class" }, { "name": "Tuple", "type": "class" }, { "name": "__doc__", "type": "instance" }, { "name": "__file__", "type": "instance" }, { "name": "__name__", "type": "instance" }, { "name": "__package__", "type": "instance" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.cov_callsite_link link = node.cov_link ct_idx_str = self.create_str_node_ctx_idx(str(node.cov_ct_idx)) # Only display [function] link if we have, otherwhise show no [function] text. if node.dst_function_source_file.replace(" ", "") != "/": func_href = f"""<a href="{link}">[function]</a>""" else: func_href = "" if i > 0: previous_node = nodes[i - 1] if previous_node.depth == node.depth: calltree_html_string += "</div>" depth_diff = previous_node.depth - node.depth if depth_diff >= 1: closing_divs = "</div>" # To close "calltree-line-wrapper" closing_divs = "</div>" * (int(depth_diff) + 1) calltree_html_string += closing_divs calltree_html_string += f""" <div class="{color_to_be}-background coverage-line"> <span class="coverage-line-inner" data-calltree-idx="{ct_idx_str}"> {node.depth} <code class="language-clike"> {demangled_name} </code> <span class="coverage-line-filename"> {func_href} <a href="{callsite_link}"> [call site2] </a> <span class="calltree-idx">[calltree idx: {ct_idx_str}]</span> </span> </span> """ if i != len(nodes) - 1: next_node = nodes[i + 1] if next_node.depth > node.depth: calltree_html_string += f"""<div class="calltree-line-wrapper open level-{int(node.depth)}" style="padding-left: 16px">""" elif next_node.depth < node.depth: depth_diff = int(node.depth - next_node.depth) calltree_html_string += "</div>" * depth_diff calltree_html_string += "</div>" logger.info("Calltree created") # Write the HTML to a file called calltree_view_XX.html where XX is a counter. calltree_file_idx = 0 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" while os.path.isfile(calltree_html_file): calltree_file_idx += 1 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" self.html_create_dedicated_calltree_file( calltree_html_string, calltree_html_file, profile, ) return calltree_html_file def html_create_dedicated_calltree_file( self, calltree_html_string, filename, profile: fuzz_data_loader.
[ "FuzzerProfile", "MergedProjectProfile", "None", "List", "logger", "add_func_to_reached_and_clone", "FunctionProfile", "load_all_profiles", "read_fuzzer_data_file_to_profile", "Any", "Dict", "Optional", "Set", "Tuple" ]
" * (int(depth_diff) + 1) calltree_html_string += closing_divs calltree_html_string += f""" <div class="{color_to_be}-background coverage-line"> <span class="coverage-line-inner" data-calltree-idx="{ct_idx_str}"> {node.depth} <code class="language-clike"> {demangled_name} </code> <span class="coverage-line-filename"> {func_href} <a href="{callsite_link}"> [call site2] </a> <span class="calltree-idx">[calltree idx: {ct_idx_str}]</span> </span> </span> """ if i != len(nodes) - 1: next_node = nodes[i + 1] if next_node.depth > node.depth: calltree_html_string += f"""<div class="calltree-line-wrapper open level-{int(node.depth)}" style="padding-left: 16px">""" elif next_node.depth < node.depth: depth_diff = int(node.depth - next_node.depth) calltree_html_string += "</div>" * depth_diff calltree_html_string += "</div>" logger.info("Calltree created") # Write the HTML to a file called calltree_view_XX.html where XX is a counter. calltree_file_idx = 0 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" while os.path.isfile(calltree_html_file): calltree_file_idx += 1 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" self.html_create_dedicated_calltree_file( calltree_html_string, calltree_html_file, profile, ) return calltree_html_file def html_create_dedicated_calltree_file( self, calltree_html_string, filename, profile: fuzz_data_loader.
19
29
0
5,761
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
inproject
html_get_header
true
function
9
9
false
true
[ "html_create_table_head", "html_table_add_row", "html_get_header", "html_get_navbar", "List", "html_add_header_with_link", "html_get_table_of_contents", "Any", "Tuple" ]
[ { "name": "Any", "type": "class" }, { "name": "html_add_header_with_link", "type": "function" }, { "name": "html_create_table_head", "type": "function" }, { "name": "html_get_header", "type": "function" }, { "name": "html_get_navbar", "type": "function" }, { "name": "html_get_table_of_contents", "type": "function" }, { "name": "html_table_add_row", "type": "function" }, { "name": "List", "type": "class" }, { "name": "Tuple", "type": "class" }, { "name": "__doc__", "type": "instance" }, { "name": "__file__", "type": "instance" }, { "name": "__name__", "type": "instance" }, { "name": "__package__", "type": "instance" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.cov_callsite_link link = node.cov_link ct_idx_str = self.create_str_node_ctx_idx(str(node.cov_ct_idx)) # Only display [function] link if we have, otherwhise show no [function] text. if node.dst_function_source_file.replace(" ", "") != "/": func_href = f"""<a href="{link}">[function]</a>""" else: func_href = "" if i > 0: previous_node = nodes[i - 1] if previous_node.depth == node.depth: calltree_html_string += "</div>" depth_diff = previous_node.depth - node.depth if depth_diff >= 1: closing_divs = "</div>" # To close "calltree-line-wrapper" closing_divs = "</div>" * (int(depth_diff) + 1) calltree_html_string += closing_divs calltree_html_string += f""" <div class="{color_to_be}-background coverage-line"> <span class="coverage-line-inner" data-calltree-idx="{ct_idx_str}"> {node.depth} <code class="language-clike"> {demangled_name} </code> <span class="coverage-line-filename"> {func_href} <a href="{callsite_link}"> [call site2] </a> <span class="calltree-idx">[calltree idx: {ct_idx_str}]</span> </span> </span> """ if i != len(nodes) - 1: next_node = nodes[i + 1] if next_node.depth > node.depth: calltree_html_string += f"""<div class="calltree-line-wrapper open level-{int(node.depth)}" style="padding-left: 16px">""" elif next_node.depth < node.depth: depth_diff = int(node.depth - next_node.depth) calltree_html_string += "</div>" * depth_diff calltree_html_string += "</div>" logger.info("Calltree created") # Write the HTML to a file called calltree_view_XX.html where XX is a counter. calltree_file_idx = 0 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" while os.path.isfile(calltree_html_file): calltree_file_idx += 1 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" self.html_create_dedicated_calltree_file( calltree_html_string, calltree_html_file, profile, ) return calltree_html_file def html_create_dedicated_calltree_file( self, calltree_html_string, filename, profile: fuzz_data_loader.FuzzerProfile): """ Write a wrapped HTML file with the tags needed from fuzz-introspector We use this only for wrapping calltrees at the moment, however, down the line it makes sense to have an easy wrapper for other HTML pages too. """ complete_html_string = "" # HTML start html_header = fuzz_html_helpers.
[ "html_create_table_head", "html_table_add_row", "html_get_header", "html_get_navbar", "List", "html_add_header_with_link", "html_get_table_of_contents", "Any", "Tuple" ]
ode> <span class="coverage-line-filename"> {func_href} <a href="{callsite_link}"> [call site2] </a> <span class="calltree-idx">[calltree idx: {ct_idx_str}]</span> </span> </span> """ if i != len(nodes) - 1: next_node = nodes[i + 1] if next_node.depth > node.depth: calltree_html_string += f"""<div class="calltree-line-wrapper open level-{int(node.depth)}" style="padding-left: 16px">""" elif next_node.depth < node.depth: depth_diff = int(node.depth - next_node.depth) calltree_html_string += "</div>" * depth_diff calltree_html_string += "</div>" logger.info("Calltree created") # Write the HTML to a file called calltree_view_XX.html where XX is a counter. calltree_file_idx = 0 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" while os.path.isfile(calltree_html_file): calltree_file_idx += 1 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" self.html_create_dedicated_calltree_file( calltree_html_string, calltree_html_file, profile, ) return calltree_html_file def html_create_dedicated_calltree_file( self, calltree_html_string, filename, profile: fuzz_data_loader.FuzzerProfile): """ Write a wrapped HTML file with the tags needed from fuzz-introspector We use this only for wrapping calltrees at the moment, however, down the line it makes sense to have an easy wrapper for other HTML pages too. """ complete_html_string = "" # HTML start html_header = fuzz_html_helpers.
20
32
0
6,201
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
infile
create_fuzz_blocker_table
true
function
7
7
false
true
[ "get_fuzz_blockers", "name", "create_fuzz_blocker_table", "create_str_node_ctx_idx", "html_create_dedicated_calltree_file", "__init__", "analysis_func", "create_calltree", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "analysis_func", "type": "function" }, { "name": "create_calltree", "type": "function" }, { "name": "create_fuzz_blocker_table", "type": "function" }, { "name": "create_str_node_ctx_idx", "type": "function" }, { "name": "get_fuzz_blockers", "type": "function" }, { "name": "html_create_dedicated_calltree_file", "type": "function" }, { "name": "name", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.cov_callsite_link link = node.cov_link ct_idx_str = self.create_str_node_ctx_idx(str(node.cov_ct_idx)) # Only display [function] link if we have, otherwhise show no [function] text. if node.dst_function_source_file.replace(" ", "") != "/": func_href = f"""<a href="{link}">[function]</a>""" else: func_href = "" if i > 0: previous_node = nodes[i - 1] if previous_node.depth == node.depth: calltree_html_string += "</div>" depth_diff = previous_node.depth - node.depth if depth_diff >= 1: closing_divs = "</div>" # To close "calltree-line-wrapper" closing_divs = "</div>" * (int(depth_diff) + 1) calltree_html_string += closing_divs calltree_html_string += f""" <div class="{color_to_be}-background coverage-line"> <span class="coverage-line-inner" data-calltree-idx="{ct_idx_str}"> {node.depth} <code class="language-clike"> {demangled_name} </code> <span class="coverage-line-filename"> {func_href} <a href="{callsite_link}"> [call site2] </a> <span class="calltree-idx">[calltree idx: {ct_idx_str}]</span> </span> </span> """ if i != len(nodes) - 1: next_node = nodes[i + 1] if next_node.depth > node.depth: calltree_html_string += f"""<div class="calltree-line-wrapper open level-{int(node.depth)}" style="padding-left: 16px">""" elif next_node.depth < node.depth: depth_diff = int(node.depth - next_node.depth) calltree_html_string += "</div>" * depth_diff calltree_html_string += "</div>" logger.info("Calltree created") # Write the HTML to a file called calltree_view_XX.html where XX is a counter. calltree_file_idx = 0 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" while os.path.isfile(calltree_html_file): calltree_file_idx += 1 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" self.html_create_dedicated_calltree_file( calltree_html_string, calltree_html_file, profile, ) return calltree_html_file def html_create_dedicated_calltree_file( self, calltree_html_string, filename, profile: fuzz_data_loader.FuzzerProfile): """ Write a wrapped HTML file with the tags needed from fuzz-introspector We use this only for wrapping calltrees at the moment, however, down the line it makes sense to have an easy wrapper for other HTML pages too. """ complete_html_string = "" # HTML start html_header = fuzz_html_helpers.html_get_header( calltree=True, title=f"Fuzz introspector: { profile.get_key() }" ) html_header += '<div class="content-section calltree-content-section">' complete_html_string += html_header # Display fuzz blocker at top of page fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) fuzz_blocker_table = self.
[ "get_fuzz_blockers", "name", "create_fuzz_blocker_table", "create_str_node_ctx_idx", "html_create_dedicated_calltree_file", "analysis_func", "create_calltree" ]
calltree_html_string += f"""<div class="calltree-line-wrapper open level-{int(node.depth)}" style="padding-left: 16px">""" elif next_node.depth < node.depth: depth_diff = int(node.depth - next_node.depth) calltree_html_string += "</div>" * depth_diff calltree_html_string += "</div>" logger.info("Calltree created") # Write the HTML to a file called calltree_view_XX.html where XX is a counter. calltree_file_idx = 0 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" while os.path.isfile(calltree_html_file): calltree_file_idx += 1 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" self.html_create_dedicated_calltree_file( calltree_html_string, calltree_html_file, profile, ) return calltree_html_file def html_create_dedicated_calltree_file( self, calltree_html_string, filename, profile: fuzz_data_loader.FuzzerProfile): """ Write a wrapped HTML file with the tags needed from fuzz-introspector We use this only for wrapping calltrees at the moment, however, down the line it makes sense to have an easy wrapper for other HTML pages too. """ complete_html_string = "" # HTML start html_header = fuzz_html_helpers.html_get_header( calltree=True, title=f"Fuzz introspector: { profile.get_key() }" ) html_header += '<div class="content-section calltree-content-section">' complete_html_string += html_header # Display fuzz blocker at top of page fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) fuzz_blocker_table = self.
22
33
0
6,814
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
infile
create_str_node_ctx_idx
true
function
7
7
false
false
[ "get_fuzz_blockers", "name", "create_fuzz_blocker_table", "create_str_node_ctx_idx", "create_calltree", "__init__", "analysis_func", "html_create_dedicated_calltree_file", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "analysis_func", "type": "function" }, { "name": "create_calltree", "type": "function" }, { "name": "create_fuzz_blocker_table", "type": "function" }, { "name": "create_str_node_ctx_idx", "type": "function" }, { "name": "get_fuzz_blockers", "type": "function" }, { "name": "html_create_dedicated_calltree_file", "type": "function" }, { "name": "name", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.cov_callsite_link link = node.cov_link ct_idx_str = self.create_str_node_ctx_idx(str(node.cov_ct_idx)) # Only display [function] link if we have, otherwhise show no [function] text. if node.dst_function_source_file.replace(" ", "") != "/": func_href = f"""<a href="{link}">[function]</a>""" else: func_href = "" if i > 0: previous_node = nodes[i - 1] if previous_node.depth == node.depth: calltree_html_string += "</div>" depth_diff = previous_node.depth - node.depth if depth_diff >= 1: closing_divs = "</div>" # To close "calltree-line-wrapper" closing_divs = "</div>" * (int(depth_diff) + 1) calltree_html_string += closing_divs calltree_html_string += f""" <div class="{color_to_be}-background coverage-line"> <span class="coverage-line-inner" data-calltree-idx="{ct_idx_str}"> {node.depth} <code class="language-clike"> {demangled_name} </code> <span class="coverage-line-filename"> {func_href} <a href="{callsite_link}"> [call site2] </a> <span class="calltree-idx">[calltree idx: {ct_idx_str}]</span> </span> </span> """ if i != len(nodes) - 1: next_node = nodes[i + 1] if next_node.depth > node.depth: calltree_html_string += f"""<div class="calltree-line-wrapper open level-{int(node.depth)}" style="padding-left: 16px">""" elif next_node.depth < node.depth: depth_diff = int(node.depth - next_node.depth) calltree_html_string += "</div>" * depth_diff calltree_html_string += "</div>" logger.info("Calltree created") # Write the HTML to a file called calltree_view_XX.html where XX is a counter. calltree_file_idx = 0 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" while os.path.isfile(calltree_html_file): calltree_file_idx += 1 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" self.html_create_dedicated_calltree_file( calltree_html_string, calltree_html_file, profile, ) return calltree_html_file def html_create_dedicated_calltree_file( self, calltree_html_string, filename, profile: fuzz_data_loader.FuzzerProfile): """ Write a wrapped HTML file with the tags needed from fuzz-introspector We use this only for wrapping calltrees at the moment, however, down the line it makes sense to have an easy wrapper for other HTML pages too. """ complete_html_string = "" # HTML start html_header = fuzz_html_helpers.html_get_header( calltree=True, title=f"Fuzz introspector: { profile.get_key() }" ) html_header += '<div class="content-section calltree-content-section">' complete_html_string += html_header # Display fuzz blocker at top of page fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], "", fuzz_blockers) if fuzz_blocker_table is not None: complete_html_string += "<div class=\"report-box\">" complete_html_string += "<h1>Fuzz blockers</h1>" complete_html_string += fuzz_blocker_table complete_html_string += "</div>" # Display calltree complete_html_string += calltree_html_string complete_html_string += "</div></div></div></div>" # HTML end html_end = '</div>' blocker_idxs = [] for node in fuzz_blockers: blocker_idxs.append(self.
[ "get_fuzz_blockers", "name", "create_fuzz_blocker_table", "create_str_node_ctx_idx", "create_calltree", "analysis_func", "html_create_dedicated_calltree_file" ]
while os.path.isfile(calltree_html_file): calltree_file_idx += 1 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" self.html_create_dedicated_calltree_file( calltree_html_string, calltree_html_file, profile, ) return calltree_html_file def html_create_dedicated_calltree_file( self, calltree_html_string, filename, profile: fuzz_data_loader.FuzzerProfile): """ Write a wrapped HTML file with the tags needed from fuzz-introspector We use this only for wrapping calltrees at the moment, however, down the line it makes sense to have an easy wrapper for other HTML pages too. """ complete_html_string = "" # HTML start html_header = fuzz_html_helpers.html_get_header( calltree=True, title=f"Fuzz introspector: { profile.get_key() }" ) html_header += '<div class="content-section calltree-content-section">' complete_html_string += html_header # Display fuzz blocker at top of page fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], "", fuzz_blockers) if fuzz_blocker_table is not None: complete_html_string += "<div class=\"report-box\">" complete_html_string += "<h1>Fuzz blockers</h1>" complete_html_string += fuzz_blocker_table complete_html_string += "</div>" # Display calltree complete_html_string += calltree_html_string complete_html_string += "</div></div></div></div>" # HTML end html_end = '</div>' blocker_idxs = [] for node in fuzz_blockers: blocker_idxs.append(self.
23
34
0
6,847
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
infile
cov_ct_idx
true
statement
17
17
false
false
[ "cov_ct_idx", "depth", "cov_forward_reds", "dst_function_name", "dst_function_source_file", "children", "cov_callsite_link", "cov_color", "cov_hitcount", "cov_largest_blocked_func", "cov_link", "cov_parent", "hitcount", "parent_calltree_callsite", "src_function_name", "src_function_source_file", "src_linenumber", "__init__", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "children", "type": "statement" }, { "name": "cov_callsite_link", "type": "statement" }, { "name": "cov_color", "type": "statement" }, { "name": "cov_ct_idx", "type": "statement" }, { "name": "cov_forward_reds", "type": "statement" }, { "name": "cov_hitcount", "type": "statement" }, { "name": "cov_largest_blocked_func", "type": "statement" }, { "name": "cov_link", "type": "statement" }, { "name": "cov_parent", "type": "statement" }, { "name": "depth", "type": "statement" }, { "name": "dst_function_name", "type": "statement" }, { "name": "dst_function_source_file", "type": "statement" }, { "name": "hitcount", "type": "statement" }, { "name": "parent_calltree_callsite", "type": "statement" }, { "name": "src_function_name", "type": "statement" }, { "name": "src_function_source_file", "type": "statement" }, { "name": "src_linenumber", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.cov_callsite_link link = node.cov_link ct_idx_str = self.create_str_node_ctx_idx(str(node.cov_ct_idx)) # Only display [function] link if we have, otherwhise show no [function] text. if node.dst_function_source_file.replace(" ", "") != "/": func_href = f"""<a href="{link}">[function]</a>""" else: func_href = "" if i > 0: previous_node = nodes[i - 1] if previous_node.depth == node.depth: calltree_html_string += "</div>" depth_diff = previous_node.depth - node.depth if depth_diff >= 1: closing_divs = "</div>" # To close "calltree-line-wrapper" closing_divs = "</div>" * (int(depth_diff) + 1) calltree_html_string += closing_divs calltree_html_string += f""" <div class="{color_to_be}-background coverage-line"> <span class="coverage-line-inner" data-calltree-idx="{ct_idx_str}"> {node.depth} <code class="language-clike"> {demangled_name} </code> <span class="coverage-line-filename"> {func_href} <a href="{callsite_link}"> [call site2] </a> <span class="calltree-idx">[calltree idx: {ct_idx_str}]</span> </span> </span> """ if i != len(nodes) - 1: next_node = nodes[i + 1] if next_node.depth > node.depth: calltree_html_string += f"""<div class="calltree-line-wrapper open level-{int(node.depth)}" style="padding-left: 16px">""" elif next_node.depth < node.depth: depth_diff = int(node.depth - next_node.depth) calltree_html_string += "</div>" * depth_diff calltree_html_string += "</div>" logger.info("Calltree created") # Write the HTML to a file called calltree_view_XX.html where XX is a counter. calltree_file_idx = 0 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" while os.path.isfile(calltree_html_file): calltree_file_idx += 1 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" self.html_create_dedicated_calltree_file( calltree_html_string, calltree_html_file, profile, ) return calltree_html_file def html_create_dedicated_calltree_file( self, calltree_html_string, filename, profile: fuzz_data_loader.FuzzerProfile): """ Write a wrapped HTML file with the tags needed from fuzz-introspector We use this only for wrapping calltrees at the moment, however, down the line it makes sense to have an easy wrapper for other HTML pages too. """ complete_html_string = "" # HTML start html_header = fuzz_html_helpers.html_get_header( calltree=True, title=f"Fuzz introspector: { profile.get_key() }" ) html_header += '<div class="content-section calltree-content-section">' complete_html_string += html_header # Display fuzz blocker at top of page fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], "", fuzz_blockers) if fuzz_blocker_table is not None: complete_html_string += "<div class=\"report-box\">" complete_html_string += "<h1>Fuzz blockers</h1>" complete_html_string += fuzz_blocker_table complete_html_string += "</div>" # Display calltree complete_html_string += calltree_html_string complete_html_string += "</div></div></div></div>" # HTML end html_end = '</div>' blocker_idxs = [] for node in fuzz_blockers: blocker_idxs.append(self.create_str_node_ctx_idx(str(node.
[ "cov_ct_idx", "depth", "cov_forward_reds", "dst_function_name", "dst_function_source_file", "children", "cov_callsite_link", "cov_color", "cov_hitcount", "cov_largest_blocked_func", "cov_link", "cov_parent", "hitcount", "parent_calltree_callsite", "src_function_name", "src_function_source_file", "src_linenumber" ]
tml_file): calltree_file_idx += 1 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" self.html_create_dedicated_calltree_file( calltree_html_string, calltree_html_file, profile, ) return calltree_html_file def html_create_dedicated_calltree_file( self, calltree_html_string, filename, profile: fuzz_data_loader.FuzzerProfile): """ Write a wrapped HTML file with the tags needed from fuzz-introspector We use this only for wrapping calltrees at the moment, however, down the line it makes sense to have an easy wrapper for other HTML pages too. """ complete_html_string = "" # HTML start html_header = fuzz_html_helpers.html_get_header( calltree=True, title=f"Fuzz introspector: { profile.get_key() }" ) html_header += '<div class="content-section calltree-content-section">' complete_html_string += html_header # Display fuzz blocker at top of page fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], "", fuzz_blockers) if fuzz_blocker_table is not None: complete_html_string += "<div class=\"report-box\">" complete_html_string += "<h1>Fuzz blockers</h1>" complete_html_string += fuzz_blocker_table complete_html_string += "</div>" # Display calltree complete_html_string += calltree_html_string complete_html_string += "</div></div></div></div>" # HTML end html_end = '</div>' blocker_idxs = [] for node in fuzz_blockers: blocker_idxs.append(self.create_str_node_ctx_idx(str(node.
24
35
0
7,754
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
inproject
FuzzerProfile
true
class
14
19
false
false
[ "FuzzerProfile", "MergedProjectProfile", "List", "None", "logger", "add_func_to_reached_and_clone", "FunctionProfile", "load_all_profiles", "read_fuzzer_data_file_to_profile", "Any", "Dict", "Optional", "Set", "Tuple" ]
[ { "name": "add_func_to_reached_and_clone", "type": "function" }, { "name": "Any", "type": "class" }, { "name": "copy", "type": "module" }, { "name": "Dict", "type": "class" }, { "name": "FunctionProfile", "type": "class" }, { "name": "fuzz_cfg_load", "type": "module" }, { "name": "fuzz_cov_load", "type": "module" }, { "name": "fuzz_utils", "type": "module" }, { "name": "FuzzerProfile", "type": "class" }, { "name": "List", "type": "class" }, { "name": "load_all_profiles", "type": "function" }, { "name": "logger", "type": "statement" }, { "name": "logging", "type": "module" }, { "name": "MergedProjectProfile", "type": "class" }, { "name": "Optional", "type": "class" }, { "name": "os", "type": "module" }, { "name": "read_fuzzer_data_file_to_profile", "type": "function" }, { "name": "Set", "type": "class" }, { "name": "Tuple", "type": "class" }, { "name": "__doc__", "type": "instance" }, { "name": "__file__", "type": "instance" }, { "name": "__name__", "type": "instance" }, { "name": "__package__", "type": "instance" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.cov_callsite_link link = node.cov_link ct_idx_str = self.create_str_node_ctx_idx(str(node.cov_ct_idx)) # Only display [function] link if we have, otherwhise show no [function] text. if node.dst_function_source_file.replace(" ", "") != "/": func_href = f"""<a href="{link}">[function]</a>""" else: func_href = "" if i > 0: previous_node = nodes[i - 1] if previous_node.depth == node.depth: calltree_html_string += "</div>" depth_diff = previous_node.depth - node.depth if depth_diff >= 1: closing_divs = "</div>" # To close "calltree-line-wrapper" closing_divs = "</div>" * (int(depth_diff) + 1) calltree_html_string += closing_divs calltree_html_string += f""" <div class="{color_to_be}-background coverage-line"> <span class="coverage-line-inner" data-calltree-idx="{ct_idx_str}"> {node.depth} <code class="language-clike"> {demangled_name} </code> <span class="coverage-line-filename"> {func_href} <a href="{callsite_link}"> [call site2] </a> <span class="calltree-idx">[calltree idx: {ct_idx_str}]</span> </span> </span> """ if i != len(nodes) - 1: next_node = nodes[i + 1] if next_node.depth > node.depth: calltree_html_string += f"""<div class="calltree-line-wrapper open level-{int(node.depth)}" style="padding-left: 16px">""" elif next_node.depth < node.depth: depth_diff = int(node.depth - next_node.depth) calltree_html_string += "</div>" * depth_diff calltree_html_string += "</div>" logger.info("Calltree created") # Write the HTML to a file called calltree_view_XX.html where XX is a counter. calltree_file_idx = 0 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" while os.path.isfile(calltree_html_file): calltree_file_idx += 1 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" self.html_create_dedicated_calltree_file( calltree_html_string, calltree_html_file, profile, ) return calltree_html_file def html_create_dedicated_calltree_file( self, calltree_html_string, filename, profile: fuzz_data_loader.FuzzerProfile): """ Write a wrapped HTML file with the tags needed from fuzz-introspector We use this only for wrapping calltrees at the moment, however, down the line it makes sense to have an easy wrapper for other HTML pages too. """ complete_html_string = "" # HTML start html_header = fuzz_html_helpers.html_get_header( calltree=True, title=f"Fuzz introspector: { profile.get_key() }" ) html_header += '<div class="content-section calltree-content-section">' complete_html_string += html_header # Display fuzz blocker at top of page fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], "", fuzz_blockers) if fuzz_blocker_table is not None: complete_html_string += "<div class=\"report-box\">" complete_html_string += "<h1>Fuzz blockers</h1>" complete_html_string += fuzz_blocker_table complete_html_string += "</div>" # Display calltree complete_html_string += calltree_html_string complete_html_string += "</div></div></div></div>" # HTML end html_end = '</div>' blocker_idxs = [] for node in fuzz_blockers: blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx))) if len(blocker_idxs) > 0: html_end = "<script>" html_end += f"var fuzz_blocker_idxs = {json.dumps(blocker_idxs)};" html_end += "</script>" html_end += "<script src=\"prism.js\"></script>" html_end += "<script src=\"clike.js\"></script>" html_end += "<script src=\"calltree.js\"></script>" complete_html_string += html_end complete_html_string += "</body></html>" # Beautify and write HTML soup = bs(complete_html_string, 'lxml') pretty_html = soup.prettify() with open(filename, "w+") as cf: cf.write(pretty_html) def create_str_node_ctx_idx(self, cov_ct_idx): prefixed_zeros = "0" * (len("00000") - len(cov_ct_idx)) return f"{prefixed_zeros}{cov_ct_idx}" def get_fuzz_blockers( self, profile: fuzz_data_loader.
[ "FuzzerProfile", "MergedProjectProfile", "List", "None", "logger", "add_func_to_reached_and_clone", "FunctionProfile", "load_all_profiles", "read_fuzzer_data_file_to_profile", "Any", "Dict", "Optional", "Set", "Tuple" ]
ospector: { profile.get_key() }" ) html_header += '<div class="content-section calltree-content-section">' complete_html_string += html_header # Display fuzz blocker at top of page fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], "", fuzz_blockers) if fuzz_blocker_table is not None: complete_html_string += "<div class=\"report-box\">" complete_html_string += "<h1>Fuzz blockers</h1>" complete_html_string += fuzz_blocker_table complete_html_string += "</div>" # Display calltree complete_html_string += calltree_html_string complete_html_string += "</div></div></div></div>" # HTML end html_end = '</div>' blocker_idxs = [] for node in fuzz_blockers: blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx))) if len(blocker_idxs) > 0: html_end = "<script>" html_end += f"var fuzz_blocker_idxs = {json.dumps(blocker_idxs)};" html_end += "</script>" html_end += "<script src=\"prism.js\"></script>" html_end += "<script src=\"clike.js\"></script>" html_end += "<script src=\"calltree.js\"></script>" complete_html_string += html_end complete_html_string += "</body></html>" # Beautify and write HTML soup = bs(complete_html_string, 'lxml') pretty_html = soup.prettify() with open(filename, "w+") as cf: cf.write(pretty_html) def create_str_node_ctx_idx(self, cov_ct_idx): prefixed_zeros = "0" * (len("00000") - len(cov_ct_idx)) return f"{prefixed_zeros}{cov_ct_idx}" def get_fuzz_blockers( self, profile: fuzz_data_loader.
25
36
0
7,895
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
inproject
CalltreeCallsite
true
class
9
9
false
true
[ "extract_all_callsites", "List", "None", "logger", "Optional", "CalltreeCallsite", "data_file_read_calltree", "extract_all_callsites_recursive", "print_ctcs_tree" ]
[ { "name": "CalltreeCallsite", "type": "class" }, { "name": "data_file_read_calltree", "type": "function" }, { "name": "extract_all_callsites", "type": "function" }, { "name": "extract_all_callsites_recursive", "type": "function" }, { "name": "List", "type": "class" }, { "name": "logger", "type": "statement" }, { "name": "logging", "type": "module" }, { "name": "Optional", "type": "class" }, { "name": "print_ctcs_tree", "type": "function" }, { "name": "__doc__", "type": "instance" }, { "name": "__file__", "type": "instance" }, { "name": "__name__", "type": "instance" }, { "name": "__package__", "type": "instance" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.cov_callsite_link link = node.cov_link ct_idx_str = self.create_str_node_ctx_idx(str(node.cov_ct_idx)) # Only display [function] link if we have, otherwhise show no [function] text. if node.dst_function_source_file.replace(" ", "") != "/": func_href = f"""<a href="{link}">[function]</a>""" else: func_href = "" if i > 0: previous_node = nodes[i - 1] if previous_node.depth == node.depth: calltree_html_string += "</div>" depth_diff = previous_node.depth - node.depth if depth_diff >= 1: closing_divs = "</div>" # To close "calltree-line-wrapper" closing_divs = "</div>" * (int(depth_diff) + 1) calltree_html_string += closing_divs calltree_html_string += f""" <div class="{color_to_be}-background coverage-line"> <span class="coverage-line-inner" data-calltree-idx="{ct_idx_str}"> {node.depth} <code class="language-clike"> {demangled_name} </code> <span class="coverage-line-filename"> {func_href} <a href="{callsite_link}"> [call site2] </a> <span class="calltree-idx">[calltree idx: {ct_idx_str}]</span> </span> </span> """ if i != len(nodes) - 1: next_node = nodes[i + 1] if next_node.depth > node.depth: calltree_html_string += f"""<div class="calltree-line-wrapper open level-{int(node.depth)}" style="padding-left: 16px">""" elif next_node.depth < node.depth: depth_diff = int(node.depth - next_node.depth) calltree_html_string += "</div>" * depth_diff calltree_html_string += "</div>" logger.info("Calltree created") # Write the HTML to a file called calltree_view_XX.html where XX is a counter. calltree_file_idx = 0 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" while os.path.isfile(calltree_html_file): calltree_file_idx += 1 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" self.html_create_dedicated_calltree_file( calltree_html_string, calltree_html_file, profile, ) return calltree_html_file def html_create_dedicated_calltree_file( self, calltree_html_string, filename, profile: fuzz_data_loader.FuzzerProfile): """ Write a wrapped HTML file with the tags needed from fuzz-introspector We use this only for wrapping calltrees at the moment, however, down the line it makes sense to have an easy wrapper for other HTML pages too. """ complete_html_string = "" # HTML start html_header = fuzz_html_helpers.html_get_header( calltree=True, title=f"Fuzz introspector: { profile.get_key() }" ) html_header += '<div class="content-section calltree-content-section">' complete_html_string += html_header # Display fuzz blocker at top of page fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], "", fuzz_blockers) if fuzz_blocker_table is not None: complete_html_string += "<div class=\"report-box\">" complete_html_string += "<h1>Fuzz blockers</h1>" complete_html_string += fuzz_blocker_table complete_html_string += "</div>" # Display calltree complete_html_string += calltree_html_string complete_html_string += "</div></div></div></div>" # HTML end html_end = '</div>' blocker_idxs = [] for node in fuzz_blockers: blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx))) if len(blocker_idxs) > 0: html_end = "<script>" html_end += f"var fuzz_blocker_idxs = {json.dumps(blocker_idxs)};" html_end += "</script>" html_end += "<script src=\"prism.js\"></script>" html_end += "<script src=\"clike.js\"></script>" html_end += "<script src=\"calltree.js\"></script>" complete_html_string += html_end complete_html_string += "</body></html>" # Beautify and write HTML soup = bs(complete_html_string, 'lxml') pretty_html = soup.prettify() with open(filename, "w+") as cf: cf.write(pretty_html) def create_str_node_ctx_idx(self, cov_ct_idx): prefixed_zeros = "0" * (len("00000") - len(cov_ct_idx)) return f"{prefixed_zeros}{cov_ct_idx}" def get_fuzz_blockers( self, profile: fuzz_data_loader.FuzzerProfile, max_blockers_to_extract=999): """Gets a list of fuzz blockers""" blocker_list: List[fuzz_cfg_load.
[ "extract_all_callsites", "List", "None", "logger", "Optional", "CalltreeCallsite", "data_file_read_calltree", "extract_all_callsites_recursive", "print_ctcs_tree" ]
tml_string += html_header # Display fuzz blocker at top of page fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], "", fuzz_blockers) if fuzz_blocker_table is not None: complete_html_string += "<div class=\"report-box\">" complete_html_string += "<h1>Fuzz blockers</h1>" complete_html_string += fuzz_blocker_table complete_html_string += "</div>" # Display calltree complete_html_string += calltree_html_string complete_html_string += "</div></div></div></div>" # HTML end html_end = '</div>' blocker_idxs = [] for node in fuzz_blockers: blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx))) if len(blocker_idxs) > 0: html_end = "<script>" html_end += f"var fuzz_blocker_idxs = {json.dumps(blocker_idxs)};" html_end += "</script>" html_end += "<script src=\"prism.js\"></script>" html_end += "<script src=\"clike.js\"></script>" html_end += "<script src=\"calltree.js\"></script>" complete_html_string += html_end complete_html_string += "</body></html>" # Beautify and write HTML soup = bs(complete_html_string, 'lxml') pretty_html = soup.prettify() with open(filename, "w+") as cf: cf.write(pretty_html) def create_str_node_ctx_idx(self, cov_ct_idx): prefixed_zeros = "0" * (len("00000") - len(cov_ct_idx)) return f"{prefixed_zeros}{cov_ct_idx}" def get_fuzz_blockers( self, profile: fuzz_data_loader.FuzzerProfile, max_blockers_to_extract=999): """Gets a list of fuzz blockers""" blocker_list: List[fuzz_cfg_load.
26
37
0
8,028
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
inproject
extract_all_callsites
true
function
8
9
false
false
[ "extract_all_callsites", "CalltreeCallsite", "List", "logger", "extract_all_callsites_recursive", "data_file_read_calltree", "print_ctcs_tree", "Optional" ]
[ { "name": "CalltreeCallsite", "type": "class" }, { "name": "data_file_read_calltree", "type": "function" }, { "name": "extract_all_callsites", "type": "function" }, { "name": "extract_all_callsites_recursive", "type": "function" }, { "name": "List", "type": "class" }, { "name": "logger", "type": "statement" }, { "name": "logging", "type": "module" }, { "name": "Optional", "type": "class" }, { "name": "print_ctcs_tree", "type": "function" }, { "name": "__doc__", "type": "instance" }, { "name": "__file__", "type": "instance" }, { "name": "__name__", "type": "instance" }, { "name": "__package__", "type": "instance" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.cov_callsite_link link = node.cov_link ct_idx_str = self.create_str_node_ctx_idx(str(node.cov_ct_idx)) # Only display [function] link if we have, otherwhise show no [function] text. if node.dst_function_source_file.replace(" ", "") != "/": func_href = f"""<a href="{link}">[function]</a>""" else: func_href = "" if i > 0: previous_node = nodes[i - 1] if previous_node.depth == node.depth: calltree_html_string += "</div>" depth_diff = previous_node.depth - node.depth if depth_diff >= 1: closing_divs = "</div>" # To close "calltree-line-wrapper" closing_divs = "</div>" * (int(depth_diff) + 1) calltree_html_string += closing_divs calltree_html_string += f""" <div class="{color_to_be}-background coverage-line"> <span class="coverage-line-inner" data-calltree-idx="{ct_idx_str}"> {node.depth} <code class="language-clike"> {demangled_name} </code> <span class="coverage-line-filename"> {func_href} <a href="{callsite_link}"> [call site2] </a> <span class="calltree-idx">[calltree idx: {ct_idx_str}]</span> </span> </span> """ if i != len(nodes) - 1: next_node = nodes[i + 1] if next_node.depth > node.depth: calltree_html_string += f"""<div class="calltree-line-wrapper open level-{int(node.depth)}" style="padding-left: 16px">""" elif next_node.depth < node.depth: depth_diff = int(node.depth - next_node.depth) calltree_html_string += "</div>" * depth_diff calltree_html_string += "</div>" logger.info("Calltree created") # Write the HTML to a file called calltree_view_XX.html where XX is a counter. calltree_file_idx = 0 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" while os.path.isfile(calltree_html_file): calltree_file_idx += 1 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" self.html_create_dedicated_calltree_file( calltree_html_string, calltree_html_file, profile, ) return calltree_html_file def html_create_dedicated_calltree_file( self, calltree_html_string, filename, profile: fuzz_data_loader.FuzzerProfile): """ Write a wrapped HTML file with the tags needed from fuzz-introspector We use this only for wrapping calltrees at the moment, however, down the line it makes sense to have an easy wrapper for other HTML pages too. """ complete_html_string = "" # HTML start html_header = fuzz_html_helpers.html_get_header( calltree=True, title=f"Fuzz introspector: { profile.get_key() }" ) html_header += '<div class="content-section calltree-content-section">' complete_html_string += html_header # Display fuzz blocker at top of page fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], "", fuzz_blockers) if fuzz_blocker_table is not None: complete_html_string += "<div class=\"report-box\">" complete_html_string += "<h1>Fuzz blockers</h1>" complete_html_string += fuzz_blocker_table complete_html_string += "</div>" # Display calltree complete_html_string += calltree_html_string complete_html_string += "</div></div></div></div>" # HTML end html_end = '</div>' blocker_idxs = [] for node in fuzz_blockers: blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx))) if len(blocker_idxs) > 0: html_end = "<script>" html_end += f"var fuzz_blocker_idxs = {json.dumps(blocker_idxs)};" html_end += "</script>" html_end += "<script src=\"prism.js\"></script>" html_end += "<script src=\"clike.js\"></script>" html_end += "<script src=\"calltree.js\"></script>" complete_html_string += html_end complete_html_string += "</body></html>" # Beautify and write HTML soup = bs(complete_html_string, 'lxml') pretty_html = soup.prettify() with open(filename, "w+") as cf: cf.write(pretty_html) def create_str_node_ctx_idx(self, cov_ct_idx): prefixed_zeros = "0" * (len("00000") - len(cov_ct_idx)) return f"{prefixed_zeros}{cov_ct_idx}" def get_fuzz_blockers( self, profile: fuzz_data_loader.FuzzerProfile, max_blockers_to_extract=999): """Gets a list of fuzz blockers""" blocker_list: List[fuzz_cfg_load.CalltreeCallsite] = list() # Extract all callsites in calltree and exit early if none all_callsites = fuzz_cfg_load.
[ "extract_all_callsites", "CalltreeCallsite", "List", "logger", "extract_all_callsites_recursive", "data_file_read_calltree", "print_ctcs_tree", "Optional" ]
profile, max_blockers_to_extract=12 ) fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], "", fuzz_blockers) if fuzz_blocker_table is not None: complete_html_string += "<div class=\"report-box\">" complete_html_string += "<h1>Fuzz blockers</h1>" complete_html_string += fuzz_blocker_table complete_html_string += "</div>" # Display calltree complete_html_string += calltree_html_string complete_html_string += "</div></div></div></div>" # HTML end html_end = '</div>' blocker_idxs = [] for node in fuzz_blockers: blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx))) if len(blocker_idxs) > 0: html_end = "<script>" html_end += f"var fuzz_blocker_idxs = {json.dumps(blocker_idxs)};" html_end += "</script>" html_end += "<script src=\"prism.js\"></script>" html_end += "<script src=\"clike.js\"></script>" html_end += "<script src=\"calltree.js\"></script>" complete_html_string += html_end complete_html_string += "</body></html>" # Beautify and write HTML soup = bs(complete_html_string, 'lxml') pretty_html = soup.prettify() with open(filename, "w+") as cf: cf.write(pretty_html) def create_str_node_ctx_idx(self, cov_ct_idx): prefixed_zeros = "0" * (len("00000") - len(cov_ct_idx)) return f"{prefixed_zeros}{cov_ct_idx}" def get_fuzz_blockers( self, profile: fuzz_data_loader.FuzzerProfile, max_blockers_to_extract=999): """Gets a list of fuzz blockers""" blocker_list: List[fuzz_cfg_load.CalltreeCallsite] = list() # Extract all callsites in calltree and exit early if none all_callsites = fuzz_cfg_load.
27
41
0
9,121
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
infile
get_fuzz_blockers
true
function
7
7
false
false
[ "get_fuzz_blockers", "create_fuzz_blocker_table", "name", "create_str_node_ctx_idx", "html_create_dedicated_calltree_file", "__init__", "analysis_func", "create_calltree", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "analysis_func", "type": "function" }, { "name": "create_calltree", "type": "function" }, { "name": "create_fuzz_blocker_table", "type": "function" }, { "name": "create_str_node_ctx_idx", "type": "function" }, { "name": "get_fuzz_blockers", "type": "function" }, { "name": "html_create_dedicated_calltree_file", "type": "function" }, { "name": "name", "type": "statement" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.cov_callsite_link link = node.cov_link ct_idx_str = self.create_str_node_ctx_idx(str(node.cov_ct_idx)) # Only display [function] link if we have, otherwhise show no [function] text. if node.dst_function_source_file.replace(" ", "") != "/": func_href = f"""<a href="{link}">[function]</a>""" else: func_href = "" if i > 0: previous_node = nodes[i - 1] if previous_node.depth == node.depth: calltree_html_string += "</div>" depth_diff = previous_node.depth - node.depth if depth_diff >= 1: closing_divs = "</div>" # To close "calltree-line-wrapper" closing_divs = "</div>" * (int(depth_diff) + 1) calltree_html_string += closing_divs calltree_html_string += f""" <div class="{color_to_be}-background coverage-line"> <span class="coverage-line-inner" data-calltree-idx="{ct_idx_str}"> {node.depth} <code class="language-clike"> {demangled_name} </code> <span class="coverage-line-filename"> {func_href} <a href="{callsite_link}"> [call site2] </a> <span class="calltree-idx">[calltree idx: {ct_idx_str}]</span> </span> </span> """ if i != len(nodes) - 1: next_node = nodes[i + 1] if next_node.depth > node.depth: calltree_html_string += f"""<div class="calltree-line-wrapper open level-{int(node.depth)}" style="padding-left: 16px">""" elif next_node.depth < node.depth: depth_diff = int(node.depth - next_node.depth) calltree_html_string += "</div>" * depth_diff calltree_html_string += "</div>" logger.info("Calltree created") # Write the HTML to a file called calltree_view_XX.html where XX is a counter. calltree_file_idx = 0 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" while os.path.isfile(calltree_html_file): calltree_file_idx += 1 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" self.html_create_dedicated_calltree_file( calltree_html_string, calltree_html_file, profile, ) return calltree_html_file def html_create_dedicated_calltree_file( self, calltree_html_string, filename, profile: fuzz_data_loader.FuzzerProfile): """ Write a wrapped HTML file with the tags needed from fuzz-introspector We use this only for wrapping calltrees at the moment, however, down the line it makes sense to have an easy wrapper for other HTML pages too. """ complete_html_string = "" # HTML start html_header = fuzz_html_helpers.html_get_header( calltree=True, title=f"Fuzz introspector: { profile.get_key() }" ) html_header += '<div class="content-section calltree-content-section">' complete_html_string += html_header # Display fuzz blocker at top of page fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], "", fuzz_blockers) if fuzz_blocker_table is not None: complete_html_string += "<div class=\"report-box\">" complete_html_string += "<h1>Fuzz blockers</h1>" complete_html_string += fuzz_blocker_table complete_html_string += "</div>" # Display calltree complete_html_string += calltree_html_string complete_html_string += "</div></div></div></div>" # HTML end html_end = '</div>' blocker_idxs = [] for node in fuzz_blockers: blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx))) if len(blocker_idxs) > 0: html_end = "<script>" html_end += f"var fuzz_blocker_idxs = {json.dumps(blocker_idxs)};" html_end += "</script>" html_end += "<script src=\"prism.js\"></script>" html_end += "<script src=\"clike.js\"></script>" html_end += "<script src=\"calltree.js\"></script>" complete_html_string += html_end complete_html_string += "</body></html>" # Beautify and write HTML soup = bs(complete_html_string, 'lxml') pretty_html = soup.prettify() with open(filename, "w+") as cf: cf.write(pretty_html) def create_str_node_ctx_idx(self, cov_ct_idx): prefixed_zeros = "0" * (len("00000") - len(cov_ct_idx)) return f"{prefixed_zeros}{cov_ct_idx}" def get_fuzz_blockers( self, profile: fuzz_data_loader.FuzzerProfile, max_blockers_to_extract=999): """Gets a list of fuzz blockers""" blocker_list: List[fuzz_cfg_load.CalltreeCallsite] = list() # Extract all callsites in calltree and exit early if none all_callsites = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) if len(all_callsites) == 0: return blocker_list # Filter nodes that has forward reds. Extract maximum max_blockers_to_extract nodes. nodes_sorted_by_red_ahead = sorted(all_callsites, key=lambda x: x.cov_forward_reds, reverse=True) for node in nodes_sorted_by_red_ahead: if node.cov_forward_reds == 0 or len(blocker_list) >= max_blockers_to_extract: break blocker_list.append(node) return blocker_list def create_fuzz_blocker_table( self, profile: fuzz_data_loader.FuzzerProfile, tables: List[str], calltree_file_name: str, fuzz_blockers=None) -> Optional[str]: """ Creates HTML string for table showing fuzz blockers. """ logger.info("Creating fuzz blocker table") # Get the fuzz blockers if fuzz_blockers is None: fuzz_blockers = self.
[ "get_fuzz_blockers", "create_fuzz_blocker_table", "name", "create_str_node_ctx_idx", "html_create_dedicated_calltree_file", "analysis_func", "create_calltree" ]
ee.js\"></script>" complete_html_string += html_end complete_html_string += "</body></html>" # Beautify and write HTML soup = bs(complete_html_string, 'lxml') pretty_html = soup.prettify() with open(filename, "w+") as cf: cf.write(pretty_html) def create_str_node_ctx_idx(self, cov_ct_idx): prefixed_zeros = "0" * (len("00000") - len(cov_ct_idx)) return f"{prefixed_zeros}{cov_ct_idx}" def get_fuzz_blockers( self, profile: fuzz_data_loader.FuzzerProfile, max_blockers_to_extract=999): """Gets a list of fuzz blockers""" blocker_list: List[fuzz_cfg_load.CalltreeCallsite] = list() # Extract all callsites in calltree and exit early if none all_callsites = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) if len(all_callsites) == 0: return blocker_list # Filter nodes that has forward reds. Extract maximum max_blockers_to_extract nodes. nodes_sorted_by_red_ahead = sorted(all_callsites, key=lambda x: x.cov_forward_reds, reverse=True) for node in nodes_sorted_by_red_ahead: if node.cov_forward_reds == 0 or len(blocker_list) >= max_blockers_to_extract: break blocker_list.append(node) return blocker_list def create_fuzz_blocker_table( self, profile: fuzz_data_loader.FuzzerProfile, tables: List[str], calltree_file_name: str, fuzz_blockers=None) -> Optional[str]: """ Creates HTML string for table showing fuzz blockers. """ logger.info("Creating fuzz blocker table") # Get the fuzz blockers if fuzz_blockers is None: fuzz_blockers = self.
30
42
0
9,537
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
inproject
html_create_table_head
true
function
9
9
false
true
[ "html_table_add_row", "html_get_header", "html_create_table_head", "html_get_table_of_contents", "html_get_navbar", "html_add_header_with_link", "Any", "List", "Tuple" ]
[ { "name": "Any", "type": "class" }, { "name": "html_add_header_with_link", "type": "function" }, { "name": "html_create_table_head", "type": "function" }, { "name": "html_get_header", "type": "function" }, { "name": "html_get_navbar", "type": "function" }, { "name": "html_get_table_of_contents", "type": "function" }, { "name": "html_table_add_row", "type": "function" }, { "name": "List", "type": "class" }, { "name": "Tuple", "type": "class" }, { "name": "__doc__", "type": "instance" }, { "name": "__file__", "type": "instance" }, { "name": "__name__", "type": "instance" }, { "name": "__package__", "type": "instance" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.cov_callsite_link link = node.cov_link ct_idx_str = self.create_str_node_ctx_idx(str(node.cov_ct_idx)) # Only display [function] link if we have, otherwhise show no [function] text. if node.dst_function_source_file.replace(" ", "") != "/": func_href = f"""<a href="{link}">[function]</a>""" else: func_href = "" if i > 0: previous_node = nodes[i - 1] if previous_node.depth == node.depth: calltree_html_string += "</div>" depth_diff = previous_node.depth - node.depth if depth_diff >= 1: closing_divs = "</div>" # To close "calltree-line-wrapper" closing_divs = "</div>" * (int(depth_diff) + 1) calltree_html_string += closing_divs calltree_html_string += f""" <div class="{color_to_be}-background coverage-line"> <span class="coverage-line-inner" data-calltree-idx="{ct_idx_str}"> {node.depth} <code class="language-clike"> {demangled_name} </code> <span class="coverage-line-filename"> {func_href} <a href="{callsite_link}"> [call site2] </a> <span class="calltree-idx">[calltree idx: {ct_idx_str}]</span> </span> </span> """ if i != len(nodes) - 1: next_node = nodes[i + 1] if next_node.depth > node.depth: calltree_html_string += f"""<div class="calltree-line-wrapper open level-{int(node.depth)}" style="padding-left: 16px">""" elif next_node.depth < node.depth: depth_diff = int(node.depth - next_node.depth) calltree_html_string += "</div>" * depth_diff calltree_html_string += "</div>" logger.info("Calltree created") # Write the HTML to a file called calltree_view_XX.html where XX is a counter. calltree_file_idx = 0 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" while os.path.isfile(calltree_html_file): calltree_file_idx += 1 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" self.html_create_dedicated_calltree_file( calltree_html_string, calltree_html_file, profile, ) return calltree_html_file def html_create_dedicated_calltree_file( self, calltree_html_string, filename, profile: fuzz_data_loader.FuzzerProfile): """ Write a wrapped HTML file with the tags needed from fuzz-introspector We use this only for wrapping calltrees at the moment, however, down the line it makes sense to have an easy wrapper for other HTML pages too. """ complete_html_string = "" # HTML start html_header = fuzz_html_helpers.html_get_header( calltree=True, title=f"Fuzz introspector: { profile.get_key() }" ) html_header += '<div class="content-section calltree-content-section">' complete_html_string += html_header # Display fuzz blocker at top of page fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], "", fuzz_blockers) if fuzz_blocker_table is not None: complete_html_string += "<div class=\"report-box\">" complete_html_string += "<h1>Fuzz blockers</h1>" complete_html_string += fuzz_blocker_table complete_html_string += "</div>" # Display calltree complete_html_string += calltree_html_string complete_html_string += "</div></div></div></div>" # HTML end html_end = '</div>' blocker_idxs = [] for node in fuzz_blockers: blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx))) if len(blocker_idxs) > 0: html_end = "<script>" html_end += f"var fuzz_blocker_idxs = {json.dumps(blocker_idxs)};" html_end += "</script>" html_end += "<script src=\"prism.js\"></script>" html_end += "<script src=\"clike.js\"></script>" html_end += "<script src=\"calltree.js\"></script>" complete_html_string += html_end complete_html_string += "</body></html>" # Beautify and write HTML soup = bs(complete_html_string, 'lxml') pretty_html = soup.prettify() with open(filename, "w+") as cf: cf.write(pretty_html) def create_str_node_ctx_idx(self, cov_ct_idx): prefixed_zeros = "0" * (len("00000") - len(cov_ct_idx)) return f"{prefixed_zeros}{cov_ct_idx}" def get_fuzz_blockers( self, profile: fuzz_data_loader.FuzzerProfile, max_blockers_to_extract=999): """Gets a list of fuzz blockers""" blocker_list: List[fuzz_cfg_load.CalltreeCallsite] = list() # Extract all callsites in calltree and exit early if none all_callsites = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) if len(all_callsites) == 0: return blocker_list # Filter nodes that has forward reds. Extract maximum max_blockers_to_extract nodes. nodes_sorted_by_red_ahead = sorted(all_callsites, key=lambda x: x.cov_forward_reds, reverse=True) for node in nodes_sorted_by_red_ahead: if node.cov_forward_reds == 0 or len(blocker_list) >= max_blockers_to_extract: break blocker_list.append(node) return blocker_list def create_fuzz_blocker_table( self, profile: fuzz_data_loader.FuzzerProfile, tables: List[str], calltree_file_name: str, fuzz_blockers=None) -> Optional[str]: """ Creates HTML string for table showing fuzz blockers. """ logger.info("Creating fuzz blocker table") # Get the fuzz blockers if fuzz_blockers is None: fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) if len(fuzz_blockers) == 0: return None html_table_string = "<p class='no-top-margin'>The followings nodes " \ "represent call sites where fuzz blockers occur</p>" tables.append(f"myTable{len(tables)}") html_table_string += fuzz_html_helpers.
[ "html_table_add_row", "html_get_header", "html_create_table_head", "html_get_table_of_contents", "html_get_navbar", "html_add_header_with_link", "Any", "List", "Tuple" ]
idx)) return f"{prefixed_zeros}{cov_ct_idx}" def get_fuzz_blockers( self, profile: fuzz_data_loader.FuzzerProfile, max_blockers_to_extract=999): """Gets a list of fuzz blockers""" blocker_list: List[fuzz_cfg_load.CalltreeCallsite] = list() # Extract all callsites in calltree and exit early if none all_callsites = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) if len(all_callsites) == 0: return blocker_list # Filter nodes that has forward reds. Extract maximum max_blockers_to_extract nodes. nodes_sorted_by_red_ahead = sorted(all_callsites, key=lambda x: x.cov_forward_reds, reverse=True) for node in nodes_sorted_by_red_ahead: if node.cov_forward_reds == 0 or len(blocker_list) >= max_blockers_to_extract: break blocker_list.append(node) return blocker_list def create_fuzz_blocker_table( self, profile: fuzz_data_loader.FuzzerProfile, tables: List[str], calltree_file_name: str, fuzz_blockers=None) -> Optional[str]: """ Creates HTML string for table showing fuzz blockers. """ logger.info("Creating fuzz blocker table") # Get the fuzz blockers if fuzz_blockers is None: fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) if len(fuzz_blockers) == 0: return None html_table_string = "<p class='no-top-margin'>The followings nodes " \ "represent call sites where fuzz blockers occur</p>" tables.append(f"myTable{len(tables)}") html_table_string += fuzz_html_helpers.
31
45
0
10,653
ossf__fuzz-introspector
4867924b714a7789f94fbcde53713a29ceab7272
post-processing/analyses/fuzz_calltree_analysis.py
inproject
html_table_add_row
true
function
9
9
false
true
[ "html_create_table_head", "html_get_header", "List", "html_get_table_of_contents", "html_table_add_row", "html_add_header_with_link", "html_get_navbar", "Any", "Tuple" ]
[ { "name": "Any", "type": "class" }, { "name": "html_add_header_with_link", "type": "function" }, { "name": "html_create_table_head", "type": "function" }, { "name": "html_get_header", "type": "function" }, { "name": "html_get_navbar", "type": "function" }, { "name": "html_get_table_of_contents", "type": "function" }, { "name": "html_table_add_row", "type": "function" }, { "name": "List", "type": "class" }, { "name": "Tuple", "type": "class" }, { "name": "__doc__", "type": "instance" }, { "name": "__file__", "type": "instance" }, { "name": "__name__", "type": "instance" }, { "name": "__package__", "type": "instance" } ]
# Copyright 2022 Fuzz Introspector Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Logic related to calltree analysis""" import os import logging import json from typing import ( List, Tuple, Optional, Set, ) import fuzz_analysis import fuzz_data_loader import fuzz_utils import fuzz_cfg_load import fuzz_html_helpers # For pretty printing the html code: from bs4 import BeautifulSoup as bs logger = logging.getLogger(name=__name__) class FuzzCalltreeAnalysis(fuzz_analysis.AnalysisInterface): def __init__(self): self.name = "FuzzCalltreeAnalysis" logger.info("Creating FuzzCalltreeAnalysis") def analysis_func(self, toc_list: List[Tuple[str, str, int]], tables: List[str], project_profile: fuzz_data_loader.MergedProjectProfile, profiles: List[fuzz_data_loader.FuzzerProfile], basefolder: str, coverage_url: str, conclusions) -> str: """ Creates the HTML of the calltree. Returns the HTML as a string. """ logger.info("Not implemented") return "" def create_calltree(self, profile: fuzz_data_loader.FuzzerProfile) -> str: logger.info("In calltree") # Generate HTML for the calltree calltree_html_string = "<div class='section-wrapper'>" calltree_html_string += "<h1>Fuzzer calltree</h1>" nodes = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) for i in range(len(nodes)): node = nodes[i] demangled_name = fuzz_utils.demangle_cpp_func(node.dst_function_name) # We may not want to show certain functions at times, e.g. libc functions # in case it bloats the calltree # libc_funcs = { "free" } libc_funcs: Set[str] = set() avoid = len([fn for fn in libc_funcs if fn in demangled_name]) > 0 if avoid: continue # Prepare strings needed in the HTML color_to_be = node.cov_color callsite_link = node.cov_callsite_link link = node.cov_link ct_idx_str = self.create_str_node_ctx_idx(str(node.cov_ct_idx)) # Only display [function] link if we have, otherwhise show no [function] text. if node.dst_function_source_file.replace(" ", "") != "/": func_href = f"""<a href="{link}">[function]</a>""" else: func_href = "" if i > 0: previous_node = nodes[i - 1] if previous_node.depth == node.depth: calltree_html_string += "</div>" depth_diff = previous_node.depth - node.depth if depth_diff >= 1: closing_divs = "</div>" # To close "calltree-line-wrapper" closing_divs = "</div>" * (int(depth_diff) + 1) calltree_html_string += closing_divs calltree_html_string += f""" <div class="{color_to_be}-background coverage-line"> <span class="coverage-line-inner" data-calltree-idx="{ct_idx_str}"> {node.depth} <code class="language-clike"> {demangled_name} </code> <span class="coverage-line-filename"> {func_href} <a href="{callsite_link}"> [call site2] </a> <span class="calltree-idx">[calltree idx: {ct_idx_str}]</span> </span> </span> """ if i != len(nodes) - 1: next_node = nodes[i + 1] if next_node.depth > node.depth: calltree_html_string += f"""<div class="calltree-line-wrapper open level-{int(node.depth)}" style="padding-left: 16px">""" elif next_node.depth < node.depth: depth_diff = int(node.depth - next_node.depth) calltree_html_string += "</div>" * depth_diff calltree_html_string += "</div>" logger.info("Calltree created") # Write the HTML to a file called calltree_view_XX.html where XX is a counter. calltree_file_idx = 0 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" while os.path.isfile(calltree_html_file): calltree_file_idx += 1 calltree_html_file = f"calltree_view_{calltree_file_idx}.html" self.html_create_dedicated_calltree_file( calltree_html_string, calltree_html_file, profile, ) return calltree_html_file def html_create_dedicated_calltree_file( self, calltree_html_string, filename, profile: fuzz_data_loader.FuzzerProfile): """ Write a wrapped HTML file with the tags needed from fuzz-introspector We use this only for wrapping calltrees at the moment, however, down the line it makes sense to have an easy wrapper for other HTML pages too. """ complete_html_string = "" # HTML start html_header = fuzz_html_helpers.html_get_header( calltree=True, title=f"Fuzz introspector: { profile.get_key() }" ) html_header += '<div class="content-section calltree-content-section">' complete_html_string += html_header # Display fuzz blocker at top of page fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) fuzz_blocker_table = self.create_fuzz_blocker_table(profile, [], "", fuzz_blockers) if fuzz_blocker_table is not None: complete_html_string += "<div class=\"report-box\">" complete_html_string += "<h1>Fuzz blockers</h1>" complete_html_string += fuzz_blocker_table complete_html_string += "</div>" # Display calltree complete_html_string += calltree_html_string complete_html_string += "</div></div></div></div>" # HTML end html_end = '</div>' blocker_idxs = [] for node in fuzz_blockers: blocker_idxs.append(self.create_str_node_ctx_idx(str(node.cov_ct_idx))) if len(blocker_idxs) > 0: html_end = "<script>" html_end += f"var fuzz_blocker_idxs = {json.dumps(blocker_idxs)};" html_end += "</script>" html_end += "<script src=\"prism.js\"></script>" html_end += "<script src=\"clike.js\"></script>" html_end += "<script src=\"calltree.js\"></script>" complete_html_string += html_end complete_html_string += "</body></html>" # Beautify and write HTML soup = bs(complete_html_string, 'lxml') pretty_html = soup.prettify() with open(filename, "w+") as cf: cf.write(pretty_html) def create_str_node_ctx_idx(self, cov_ct_idx): prefixed_zeros = "0" * (len("00000") - len(cov_ct_idx)) return f"{prefixed_zeros}{cov_ct_idx}" def get_fuzz_blockers( self, profile: fuzz_data_loader.FuzzerProfile, max_blockers_to_extract=999): """Gets a list of fuzz blockers""" blocker_list: List[fuzz_cfg_load.CalltreeCallsite] = list() # Extract all callsites in calltree and exit early if none all_callsites = fuzz_cfg_load.extract_all_callsites(profile.function_call_depths) if len(all_callsites) == 0: return blocker_list # Filter nodes that has forward reds. Extract maximum max_blockers_to_extract nodes. nodes_sorted_by_red_ahead = sorted(all_callsites, key=lambda x: x.cov_forward_reds, reverse=True) for node in nodes_sorted_by_red_ahead: if node.cov_forward_reds == 0 or len(blocker_list) >= max_blockers_to_extract: break blocker_list.append(node) return blocker_list def create_fuzz_blocker_table( self, profile: fuzz_data_loader.FuzzerProfile, tables: List[str], calltree_file_name: str, fuzz_blockers=None) -> Optional[str]: """ Creates HTML string for table showing fuzz blockers. """ logger.info("Creating fuzz blocker table") # Get the fuzz blockers if fuzz_blockers is None: fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) if len(fuzz_blockers) == 0: return None html_table_string = "<p class='no-top-margin'>The followings nodes " \ "represent call sites where fuzz blockers occur</p>" tables.append(f"myTable{len(tables)}") html_table_string += fuzz_html_helpers.html_create_table_head( tables[-1], [ ("Amount of callsites blocked", "Total amount of callsites blocked"), ("Calltree index", "Index in call tree where the fuzz blocker is."), ("Parent function", "Function in which the call site that blocks resides."), ("Callsite", ""), ("Largest blocked function", "This is the function with highest cyclomatiic complexity amongst" "all of the functions that are blocked. As such, it's a way of " "highlighting a potentially important function being blocked") ], sort_by_column=0, sort_order="desc" ) for node in fuzz_blockers: link_prefix = "0" * (5 - len(str(node.cov_ct_idx))) node_link = "%s?scrollToNode=%s%s" % ( calltree_file_name, link_prefix, node.cov_ct_idx ) html_table_string += fuzz_html_helpers.
[ "html_create_table_head", "html_get_header", "List", "html_get_table_of_contents", "html_table_add_row", "html_add_header_with_link", "html_get_navbar", "Any", "Tuple" ]
: fuzz_data_loader.FuzzerProfile, tables: List[str], calltree_file_name: str, fuzz_blockers=None) -> Optional[str]: """ Creates HTML string for table showing fuzz blockers. """ logger.info("Creating fuzz blocker table") # Get the fuzz blockers if fuzz_blockers is None: fuzz_blockers = self.get_fuzz_blockers( profile, max_blockers_to_extract=12 ) if len(fuzz_blockers) == 0: return None html_table_string = "<p class='no-top-margin'>The followings nodes " \ "represent call sites where fuzz blockers occur</p>" tables.append(f"myTable{len(tables)}") html_table_string += fuzz_html_helpers.html_create_table_head( tables[-1], [ ("Amount of callsites blocked", "Total amount of callsites blocked"), ("Calltree index", "Index in call tree where the fuzz blocker is."), ("Parent function", "Function in which the call site that blocks resides."), ("Callsite", ""), ("Largest blocked function", "This is the function with highest cyclomatiic complexity amongst" "all of the functions that are blocked. As such, it's a way of " "highlighting a potentially important function being blocked") ], sort_by_column=0, sort_order="desc" ) for node in fuzz_blockers: link_prefix = "0" * (5 - len(str(node.cov_ct_idx))) node_link = "%s?scrollToNode=%s%s" % ( calltree_file_name, link_prefix, node.cov_ct_idx ) html_table_string += fuzz_html_helpers.
34
64
1
4,330
vanheeringen-lab__seq2science
d5ff9782c8f6c4cd989f74684154c508b7c65127
docs/scripts/clean_dags.py
infile
type
true
statement
17
16
false
true
[ "edges", "nodes", "label2id", "name", "type", "__init__", "_get_node_id", "_order_edges", "color_node", "edge_style", "graph_style", "hide_node", "node_style", "remove_edge", "remove_node", "transitive_reduction", "write", "for", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init_subclass__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__doc__", "__module__" ]
[ { "name": "color_node", "type": "function" }, { "name": "edge_style", "type": "statement" }, { "name": "edges", "type": "statement" }, { "name": "graph_style", "type": "statement" }, { "name": "hide_node", "type": "function" }, { "name": "label2id", "type": "statement" }, { "name": "name", "type": "statement" }, { "name": "node_style", "type": "statement" }, { "name": "nodes", "type": "statement" }, { "name": "remove_edge", "type": "function" }, { "name": "remove_node", "type": "function" }, { "name": "transitive_reduction", "type": "function" }, { "name": "type", "type": "statement" }, { "name": "write", "type": "function" }, { "name": "_get_node_id", "type": "function" }, { "name": "_order_edges", "type": "function" }, { "name": "__annotations__", "type": "statement" }, { "name": "__class__", "type": "property" }, { "name": "__delattr__", "type": "function" }, { "name": "__dict__", "type": "statement" }, { "name": "__dir__", "type": "function" }, { "name": "__doc__", "type": "statement" }, { "name": "__eq__", "type": "function" }, { "name": "__format__", "type": "function" }, { "name": "__getattribute__", "type": "function" }, { "name": "__hash__", "type": "function" }, { "name": "__init__", "type": "function" }, { "name": "__init_subclass__", "type": "function" }, { "name": "__module__", "type": "statement" }, { "name": "__ne__", "type": "function" }, { "name": "__new__", "type": "function" }, { "name": "__reduce__", "type": "function" }, { "name": "__reduce_ex__", "type": "function" }, { "name": "__repr__", "type": "function" }, { "name": "__setattr__", "type": "function" }, { "name": "__sizeof__", "type": "function" }, { "name": "__slots__", "type": "statement" }, { "name": "__str__", "type": "function" } ]
import re import networkx as nx rules_to_keep = { # "0.13 0.6 0.85", # yellow # "0.09 0.6 0.85", # brown # "0.28 0.6 0.85", # green # "0.04 0.6 0.85", # red # "0.00 0.6 0.85", # cherry # "0.63 0.6 0.85", # purple # "0.59 0.6 0.85", # dark blue # "0.58 0.6 0.85", # blue # "0.49 0.6 0.85", # teal # input "get_genome": "0.49 0.6 0.85", # teal "ena2fastq_SE": "0.49 0.6 0.85", # teal "ena2fastq_PE": "0.49 0.6 0.85", # teal "sra2fastq_SE": "0.49 0.6 0.85", # teal "sra2fastq_PE": "0.49 0.6 0.85", # teal # fastq "fastp_SE": "0.13 0.6 0.85", # yellow "fastp_PE": "0.13 0.6 0.85", # yellow "trimgalore_SE": "0.13 0.6 0.85", # yellow "trimgalore_PE": "0.13 0.6 0.85", # yellow "merge_replicates": "0.13 0.6 0.85", # yellow # align "bowtie2_align": "0.13 0.6 0.85", # yellow "bwa_mem": "0.13 0.6 0.85", # yellow "bwa_mem2": "0.13 0.6 0.85", # yellow "hisat2_align": "0.13 0.6 0.85", # yellow "minimap2_align": "0.13 0.6 0.85", # yellow "star_align": "0.13 0.6 0.85", # yellow "mark_duplicates": "0.13 0.6 0.85", # yellow "sieve_bam": "0.13 0.6 0.85", # yellow # peak counting "macs2_callpeak": "0.13 0.6 0.85", # yellow "call_peak_genrich": "0.13 0.6 0.85", # yellow "hmmratac": "0.13 0.6 0.85", # yellow "create_SNAP_object": "0.13 0.6 0.85", # yellow # gene counting/quantification "htseq_count": "0.13 0.6 0.85", # yellow "featurecounts": "0.13 0.6 0.85", # yellow "salmon_quant": "0.13 0.6 0.85", # yellow # trackhub "bam_bigwig": "0.00 0.6 0.85", # cherry "peak_bigpeak": "0.00 0.6 0.85", # cherry "bedgraph_bigwig": "0.00 0.6 0.85", # cherry "trackhub": "0.00 0.6 0.85", # cherry # multiqc "multiqc": "0.63 0.6 0.85", # purple # peak files "coverage_table": "0.28 0.6 0.85", # green "onehot_peaks": "0.28 0.6 0.85", # green "create_bins_SNAP_object": "0.28 0.6 0.85", # green # gene files "gene_id2name": "0.28 0.6 0.85", # green "tpm_matrix": "0.28 0.6 0.85", # green "count_matrix": "0.28 0.6 0.85", # green "txi_count_matrix": "0.28 0.6 0.85", # green "pytxi_count_matrix": "0.28 0.6 0.85", # green "citeseqcount": "0.28 0.6 0.85", # green "kallistobus_count": "0.28 0.6 0.85", # green # other "gimme_maelstrom": "0.28 0.6 0.85", # green "deseq2": "0.28 0.6 0.85", # green "dexseq_count_matrix": "0.28 0.6 0.85", # green } class Digraph: def __init__(self, infile): with open(infile) as f: lines = f.readlines() self.type, self.name = lines[0].split()[0:2] self.graph_style = lines[1] self.node_style = lines[2] self.edge_style = lines[3] self.nodes = dict() self.edges = set() self.label2id = dict() l = re.compile(r'label = "(.*?)"') c = re.compile(r'color = "(.*?)"') s = re.compile(r'style="(.*?)"') for line in lines[4:]: line = line.strip() # read edges edge = tuple(line.split(" -> ")) if len(edge) == 2: self.edges.add(edge) # read nodes elif "[" in line[:5]: node_id = line.split("[")[0] label = l.search(line).groups()[0] color = c.search(line).groups()[0] style = s.search(line).groups()[0] self.nodes[node_id] = { "label": label, "color": color, "style": style, } self.label2id[label] = node_id def _order_edges(self): """ edges are sorted by 1) ascending target nodes and 2) descending source nodes """ ordered = [] sources = sorted(set(int(e[0]) for e in list(self.edges)), reverse=True) targets = sorted(set(int(e[1]) for e in list(self.edges))) for target in targets: for source in sources: edge = (str(source), str(target)) if edge in self.edges: ordered.append(edge) return ordered def write(self, fname): with open(fname, "w") as f: f.write(" ".join([self.
[ "edges", "nodes", "label2id", "name", "type", "color_node", "edge_style", "graph_style", "hide_node", "node_style", "remove_edge", "remove_node", "transitive_reduction", "write", "for" ]
8 0.6 0.85", # green "deseq2": "0.28 0.6 0.85", # green "dexseq_count_matrix": "0.28 0.6 0.85", # green } class Digraph: def __init__(self, infile): with open(infile) as f: lines = f.readlines() self.type, self.name = lines[0].split()[0:2] self.graph_style = lines[1] self.node_style = lines[2] self.edge_style = lines[3] self.nodes = dict() self.edges = set() self.label2id = dict() l = re.compile(r'label = "(.*?)"') c = re.compile(r'color = "(.*?)"') s = re.compile(r'style="(.*?)"') for line in lines[4:]: line = line.strip() # read edges edge = tuple(line.split(" -> ")) if len(edge) == 2: self.edges.add(edge) # read nodes elif "[" in line[:5]: node_id = line.split("[")[0] label = l.search(line).groups()[0] color = c.search(line).groups()[0] style = s.search(line).groups()[0] self.nodes[node_id] = { "label": label, "color": color, "style": style, } self.label2id[label] = node_id def _order_edges(self): """ edges are sorted by 1) ascending target nodes and 2) descending source nodes """ ordered = [] sources = sorted(set(int(e[0]) for e in list(self.edges)), reverse=True) targets = sorted(set(int(e[1]) for e in list(self.edges))) for target in targets: for source in sources: edge = (str(source), str(target)) if edge in self.edges: ordered.append(edge) return ordered def write(self, fname): with open(fname, "w") as f: f.write(" ".join([self.
45
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
2
Size of downloaded dataset files:
2.73 MB
Size of the auto-converted Parquet files:
2.73 MB
Number of rows:
1,557

Collection including DanCip/lca-StartingPoints-expanded-filtered