|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Get all APIs from https://www.hex-rays.com/products/ida/support/idapython_docs |
| 4 | +# Will dump idaapi.api, idc.api & idautils.api |
| 5 | + |
| 6 | +import requests |
| 7 | + |
| 8 | +from html.parser import HTMLParser |
| 9 | +from html.entities import name2codepoint |
| 10 | + |
| 11 | +hasFunc = False |
| 12 | +hasArg = False |
| 13 | +functions = dict() |
| 14 | +curFunc = "" |
| 15 | + |
| 16 | +class MyHTMLParser(HTMLParser): |
| 17 | + # https://docs.python.org/3/library/html.parser.html |
| 18 | + def handle_starttag(self, tag, attrs): |
| 19 | + global hasFunc, hasArg, functions, curFunc |
| 20 | + for attr in attrs: |
| 21 | + if attr[1] == "summary-sig-name": |
| 22 | + hasFunc = True |
| 23 | + if attr[1] == "summary-sig-arg": |
| 24 | + hasArg = True |
| 25 | + |
| 26 | + def handle_endtag(self, tag): |
| 27 | + global hasFunc, hasArg, functions, curFunc |
| 28 | + if hasFunc == True: |
| 29 | + hasFunc = False |
| 30 | + if hasArg == True: |
| 31 | + hasArg = False |
| 32 | + |
| 33 | + def handle_data(self, data): |
| 34 | + global hasFunc, hasArg, functions, curFunc |
| 35 | + if hasFunc == True: |
| 36 | + functions[data] = [] |
| 37 | + curFunc = data |
| 38 | + if hasArg == True: |
| 39 | + functions[curFunc].append(data) |
| 40 | + |
| 41 | +idaapi_urls=[ |
| 42 | +#"ida_allins", // no functions |
| 43 | +"ida_auto", |
| 44 | +"ida_bytes", |
| 45 | +"ida_dbg", |
| 46 | +"ida_diskio", |
| 47 | +"ida_entry", |
| 48 | +"ida_enum", |
| 49 | +"ida_expr", |
| 50 | +"ida_fixup", |
| 51 | +"ida_fpro", |
| 52 | +"ida_frame", |
| 53 | +"ida_funcs", |
| 54 | +"ida_gdl", |
| 55 | +"ida_graph", |
| 56 | +"ida_hexrays", |
| 57 | +"ida_ida", |
| 58 | +"ida_idaapi", |
| 59 | +"ida_idc" |
| 60 | +"ida_idd", |
| 61 | +"ida_idp", |
| 62 | +"ida_kernwin", |
| 63 | +"ida_lines", |
| 64 | +"ida_loader", |
| 65 | +"ida_moves", |
| 66 | +"ida_nalt", |
| 67 | +"ida_name", |
| 68 | +"ida_netnode", |
| 69 | +"ida_offset", |
| 70 | +"ida_pro", |
| 71 | +"ida_problems", |
| 72 | +"ida_range", |
| 73 | +"ida_registry", |
| 74 | +"ida_search", |
| 75 | +"ida_segment", |
| 76 | +"ida_segregs", |
| 77 | +"ida_strlist", |
| 78 | +"ida_struct", |
| 79 | +"ida_typeinf", |
| 80 | +"ida_tryblks", |
| 81 | +"ida_ua", |
| 82 | +"ida_xref", |
| 83 | +] |
| 84 | + |
| 85 | +def write_api(apis, fn): |
| 86 | + data = "" |
| 87 | + for api in sorted(apis): |
| 88 | + data += api + "\n" |
| 89 | + with open(fn, "w") as f: |
| 90 | + f.write(data) |
| 91 | + print(f"Done writing api to {fn}") |
| 92 | + |
| 93 | +def get_api(urls, module): |
| 94 | + global hasFunc, hasArg, functions, curFunc |
| 95 | + hasFunc = False |
| 96 | + hasArg = False |
| 97 | + functions = dict() |
| 98 | + curFunc = "" |
| 99 | + apis = set() |
| 100 | + for u in urls: |
| 101 | + url = f"https://www.hex-rays.com/products/ida/support/idapython_docs/{u}-module.html" |
| 102 | + print(f"Getting API from {url}...") |
| 103 | + resp = requests.get(url) |
| 104 | + parser = MyHTMLParser() |
| 105 | + parser.feed(resp.text) |
| 106 | + for func_name, func_arg in functions.items(): |
| 107 | + arg_str = "" |
| 108 | + for idx, arg in enumerate(func_arg): |
| 109 | + if idx == 0: |
| 110 | + arg_str += f"{arg}" |
| 111 | + else: |
| 112 | + arg_str += f", {arg}" |
| 113 | + apis.add(f"{module}.{func_name}({arg_str})") |
| 114 | + return apis |
| 115 | + |
| 116 | +# get API for idaapi |
| 117 | +idaapis = get_api(idaapi_urls, "idaapi") |
| 118 | +write_api(idaapis, "idaapi.api") |
| 119 | +# get API for idautils |
| 120 | +urls = ["idautils"] |
| 121 | +idautilsapis = get_api(urls, "idautils") |
| 122 | +write_api(idautilsapis, "idautils.api") |
| 123 | +# get api for idc |
| 124 | +urls = ["idc"] |
| 125 | +idcapis = get_api(urls, "idc") |
| 126 | +write_api(idcapis, "idc.api") |
0 commit comments