Skip to content

Commit 095ccd5

Browse files
author
Daniel Plohmann (jupiter)
committed
added update script to pull ApiVector DB from Malpedia
1 parent b8fa1b8 commit 095ccd5

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ ENV/
6262

6363
# other
6464
dbs/*.csv
65+
config.py

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Also, another blog post explaining how ApiVectors are constructed and stored: ht
1818
Version History
1919
---------------
2020

21+
* 2020-03-03: Added a script to pull the most recent ApiVector DB from Malpedia (requires Malpedia account / API token).
2122
* 2020-03-02: Ported to IDA 7.4 (THX to @jenfrie).
2223
* 2019-10-08: Workaround for broken filtering of the API view in IDA 7.3 (THX to @enzok for pointing this out).
2324
* 2019-08-22: Fixed a bug where missing type info in IDA would lead to a crash (now gives an error message instead).

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
nose
22
PIL
33
numpy
4+
requests

template.config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# set your Malpedia API token here
2+
APITOKEN = ""

update.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import re
2+
import os
3+
import sys
4+
import requests
5+
6+
try:
7+
import config
8+
except:
9+
print("create a config.py based on template.config.py and set your Malpedia API token!")
10+
sys.exit()
11+
12+
13+
def delete_existing_dbs():
14+
""" delete potentially existing old apivector db files """
15+
for filename in os.listdir("dbs"):
16+
if re.search(r"\d{4}-\d\d-\d\d-apivectors-v\d+\.csv", filename):
17+
os.remove("dbs" + os.sep + filename)
18+
19+
20+
def get_newest_db_version():
21+
""" find ApiVector DB files and return newest version number found """
22+
max_version = 0
23+
for filename in os.listdir("dbs"):
24+
version = re.search(r"\d{4}-\d\d-\d\d-apivectors-v(?P<version_number>\d+)\.csv", filename)
25+
if version:
26+
max_version = max(max_version, int(version.group("version_number")))
27+
return max_version
28+
29+
30+
def download_apivector_db():
31+
result = {
32+
"filename": "",
33+
"content": "",
34+
"version": 0
35+
}
36+
response = requests.get(
37+
'https://malpedia.caad.fkie.fraunhofer.de/api/list/apiscout/csv',
38+
headers={'Authorization': 'apitoken ' + config.APITOKEN},
39+
)
40+
if response.status_code == 200:
41+
result["filename"] = response.headers['Content-Disposition'].split("=")[1].strip()
42+
result["content"] = response.text
43+
version = re.search(r"\d{4}-\d\d-\d\d-apivectors-v(?P<version_number>\d+)\.csv", result["filename"])
44+
result["version"] = version
45+
else:
46+
print("Failed to download ApiVector DB, response code: ", response.status_code)
47+
return result
48+
49+
50+
def check_malpedia_version():
51+
remote_version = 0
52+
response = requests.get(
53+
'https://malpedia.caad.fkie.fraunhofer.de/api/get/version'
54+
)
55+
if response.status_code == 200:
56+
response_json = response.json()
57+
remote_version =response_json["version"]
58+
else:
59+
print("Failed to check Malpedia version, response code: ", response.status_code)
60+
return remote_version
61+
62+
63+
def main():
64+
db_version = get_newest_db_version()
65+
malpedia_version = check_malpedia_version()
66+
if db_version < malpedia_version:
67+
apivector_update = download_apivector_db()
68+
if apivector_update["version"]:
69+
delete_existing_dbs()
70+
update_db_path = "dbs" + os.sep + apivector_update["filename"]
71+
with open(update_db_path, "w") as fout:
72+
fout.write(apivector_update["content"])
73+
print("Downloaded and stored ApiVector DB file: ", update_db_path)
74+
else:
75+
print("ApiVector update download failed.")
76+
else:
77+
print("Your ApiVector DB is the most recent ({})".format(malpedia_version))
78+
79+
80+
if __name__ == "__main__":
81+
sys.exit(main())

0 commit comments

Comments
 (0)