forked from 418sec/ExtAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdater.py
105 lines (90 loc) · 3.83 KB
/
updater.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""
ExtAnalysis - Browser Extension Analysis Framework
Copyright (C) 2019 - 2020 Tuhinshubhra
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import core.core as core
import core.scans as scan
import logging, traceback
import core.helper as helper
import os
import sys
import tempfile
import subprocess
def check():
'''
Check for update
'''
print('==== ExtAnalysis Update Check ====')
core.updatelog('Current Version: ' + core.version)
current_version = int(core.version.replace('.', ''))
core.updatelog('Getting new version from github')
v = scan.source_code(core.version_url)
if v[0]:
# Successfully acquired source code
try:
# validate version
latest_version = int(v[1].replace('.', '').replace('\n', ''))
core.updatelog('Latest version: ' + v[1])
if latest_version > current_version:
# Update available
update_prompt = input('New Version available! Update Now? (y/n): ').lower()
if update_prompt == 'y':
# update it
update()
else:
core.updatelog('Update cancled! Make sure update the app later')
core.handle_exit()
elif latest_version == current_version:
print("you're already on the latest version!")
core.handle_exit()
else:
print('The script was tampered with and i don\'t like it!')
core.handle_exit()
except Exception as e:
core.updatelog('Invalid response from github')
logging.error(traceback.format_exc())
core.handle_exit()
else:
core.updatelog('Something went wrong while getting version from github')
core.handle_exit()
def update():
'''
Updates ExtAnalysis
1. Create the updater child script and save it to temp directory
2. End self process and start the child script
'''
print("\n[i] Creating Updater file")
child_script = open(helper.fixpath(core.path + '/db/updater.py'), 'r')
child_script = child_script.read()
src = child_script.replace('<current_extanalysis_directory>', core.path.replace('\\', '\\\\'))
src = src.replace('<github_zip_url>', core.github_zip)
print('[i] Moving updater file to temp directory')
temp_dir = tempfile.gettempdir()
updater_script = helper.fixpath(temp_dir + '/update_extanalysis.py')
f = open(updater_script, 'w+')
f.write(src)
f.close()
python_loc = sys.executable
print('[i] Starting Updater script')
if sys.platform == 'win32':
os.chdir(temp_dir)
command = [python_loc, 'update_extanalysis.py']
subprocess.Popen(command, creationflags=subprocess.CREATE_NEW_CONSOLE, shell=False)
print('[i] Killing self... Next time we meet I will be a better version of myself ;)')
exit()
else:
os.chdir(temp_dir)
command = ['x-terminal-emulator', '-e', python_loc, updater_script]
subprocess.Popen(command, shell=False)
print('[i] Killing self... Next time we meet I will be a better version of myself ;)')
exit()