MCPcopy Create free account
hub / github.com/GPTScan/GPTScan / convert_output

Function convert_output

src/utils.py:80–223  ·  view source on GitHub ↗
(origin_output:Dict, scan_rules:List[Dict], cg:CallGraph, base_dir:str)

Source from the content-addressed store, hash-verified

78
79
80def convert_output(origin_output:Dict, scan_rules:List[Dict], cg:CallGraph, base_dir:str) -> Dict:
81 res = {
82 "version": "1.1.0",
83 "success": True,
84 "message": None,
85 "results": [
86
87 ]
88 }
89 # logger.info("Output before clean")
90 # logger.info(origin_output)
91 origin_output = clean_the_origin_output(origin_output)
92 # logger.info("Output after clean")
93 # logger.info(origin_output)
94
95 for filename in origin_output:
96 for contract in origin_output[filename]:
97 for functionA in origin_output[filename][contract]:
98 for functionB_sig in origin_output[filename][contract][functionA]:
99 for vul_type in origin_output[filename][contract][functionA][functionB_sig]:
100 if "StaticAnalysis" in origin_output[filename][contract][functionA][functionB_sig][vul_type] and origin_output[filename][contract][functionA][functionB_sig][vul_type]["StaticAnalysis"] != False:
101 detail = cg.get_function_detail(filename, contract, functionA)
102 start_line = int(detail['loc']['start'].split(":")[0])
103 end_line = int(detail['loc']['end'].split(":")[0])
104 rel_path = os.path.abspath(filename)
105
106 for rule in scan_rules:
107 if vul_type == rule["name"]:
108 title = rule["output"]["title"]
109 description = rule["output"]["description"]
110 recommendation = rule["output"]["recommendation"]
111 break
112 if functionB_sig == "__ONLY_FUNCTION__":
113 result = {
114 "code": vul_type,
115 "severity": "HIGH",
116 "title": title,
117 "description": description,
118 "recommendation": recommendation,
119 "affectedFiles": [
120 {
121 "filePath": rel_path,
122 "range": {
123 "start": {
124 "line": start_line
125 },
126 "end": {
127 "line": end_line
128 }
129 },
130 "highlights": []
131 }
132 ]
133 }
134
135 res["results"].append(result)
136 else:
137 try:

Callers

nothing calls this directly

Calls 2

clean_the_origin_outputFunction · 0.85
get_function_detailMethod · 0.80

Tested by

no test coverage detected