()
| 105 | |
| 106 | |
| 107 | def simple_cli(): |
| 108 | start_time = time.time() |
| 109 | |
| 110 | parser = argparse.ArgumentParser( |
| 111 | prog='GPTScan', |
| 112 | description='GPTScan is an AI based smart contract vulnerability scanner.') |
| 113 | parser.add_argument("-s", "--source", help="The source code directory", required=True) |
| 114 | # not need ast, compile first |
| 115 | # parser.add_argument("-a", "--ast", help="The AST directory", required=True) |
| 116 | parser.add_argument("-o", "--output", help="The output file", required=True) |
| 117 | parser.add_argument("-k", "--gptkey", help="The OpenAI API key", required=True) |
| 118 | |
| 119 | |
| 120 | scan_rules = load_all_rules() |
| 121 | console.log(f"Loaded [bold green]{len(scan_rules)}[/bold green] rules") |
| 122 | |
| 123 | source_dir = parser.parse_args().source |
| 124 | |
| 125 | try: |
| 126 | falcon_instance = compile_project(source_dir) |
| 127 | except: |
| 128 | console.log(traceback.format_exc()) |
| 129 | console.log("Compile [bold red]failed[/bold red].") |
| 130 | console.log("[yellow]Since the compilation is failed, some static analysis tool may not be enabled, which may cause lower precision and recall.[/yellow]") |
| 131 | falcon_instance = None |
| 132 | output_file = parser.parse_args().output |
| 133 | gptkey = parser.parse_args().gptkey |
| 134 | |
| 135 | os.environ["OPENAI_API_KEY"] = gptkey |
| 136 | |
| 137 | import analyze_pipeline |
| 138 | import chatgpt_api |
| 139 | |
| 140 | res, cg, meta_data = analyze_pipeline.ask_whether_has_vul_with_scenario_v9( |
| 141 | source_dir, scan_rules) |
| 142 | final_result = {} |
| 143 | # logger.info(res) |
| 144 | for file in res: |
| 145 | with open(file) as f: |
| 146 | source = f.read().splitlines() |
| 147 | for contract in res[file]: |
| 148 | for function1 in res[file][contract]: |
| 149 | |
| 150 | # I think should first ask for function 1 |
| 151 | # this is a key value map for vul -> result |
| 152 | function1_tmp_result = {} |
| 153 | |
| 154 | for function2 in res[file][contract][function1]: |
| 155 | confirmed_vuls = {} |
| 156 | for vul in res[file][contract][function1][function2]["data"]: |
| 157 | meta_data["rules_types_for_static"].add(vul["name"]) |
| 158 | # if the rule need static check |
| 159 | if "static" in vul: |
| 160 | # if need static check |
| 161 | |
| 162 | # if function1 is not asked yet, ask for function1 first |
| 163 | if vul["name"] not in function1_tmp_result: |
| 164 | function1_detail = cg.get_function_detail(file, contract, function1) |
nothing calls this directly
no test coverage detected