6
6
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7
7
# See the License for the specific language governing permissions and limitations under the License.
8
8
9
+ import importlib .util
9
10
import argparse
10
11
import pathlib
11
12
import logging
12
13
import sys
13
14
14
15
16
+ SUPPORTED_JEP_VERSION = "4.2.0"
17
+
15
18
logger = logging .getLogger (__name__ )
16
19
17
20
handler = logging .StreamHandler ()
@@ -28,20 +31,80 @@ def main(args):
28
31
if args .debug :
29
32
logger .setLevel (logging .DEBUG )
30
33
34
+ jep_spec = importlib .util .find_spec ("jep" )
35
+ if jep_spec is None :
36
+ logger .error (
37
+ "Jep is not installed. Please install Jep version %s before configuring Ghidrathon." , SUPPORTED_JEP_VERSION
38
+ )
39
+ return - 1
40
+
41
+ jep_version_file : pathlib .path = pathlib .Path (jep_spec .origin ).parent / "version.py"
42
+ if not all ((jep_version_file .exists (), jep_version_file .is_file ())):
43
+ logger .error (
44
+ "Jep file %s is not valid. Please verify your Jep install is correct before configuring Ghidrathon." ,
45
+ jep_version_file ,
46
+ )
47
+ return - 1
48
+
49
+ logger .debug ('Verifying Jep version.py file located at "%s".' , jep_version_file )
50
+
51
+ if SUPPORTED_JEP_VERSION not in jep_version_file .read_text (encoding = "utf-8" ):
52
+ logger .error (
53
+ "Jep version is not supported. Please install Jep version %s before configuring Ghidrathon." ,
54
+ SUPPORTED_JEP_VERSION ,
55
+ )
56
+ return - 1
57
+
31
58
install_path : pathlib .Path = args .ghidrathon_install_directory
32
59
if not all ((install_path .exists (), install_path .is_dir ())):
33
- logger .error ('"%s" does not exist or is not a directory.' , str (install_path ))
60
+ logger .error (
61
+ 'Ghidra install directory "%s" is not valid. Please specify the absolute path of your Ghidra install directory.' ,
62
+ install_path ,
63
+ )
34
64
return - 1
35
65
66
+ python_path : pathlib .Path = pathlib .Path ("None" if not sys .executable else sys .executable )
67
+ if not all ((python_path .exists (), python_path .is_file ())):
68
+ logger .error (
69
+ 'sys.executable value "%s" is not valid. Please verify your Python environment is correct before configuring Ghidrathon.' ,
70
+ python_path ,
71
+ )
72
+ return - 1
73
+
74
+ logger .debug ('Using Python interpreter located at "%s".' , python_path )
75
+
36
76
save_path : pathlib .Path = install_path / "ghidrathon.save"
37
77
try :
38
- save_path .write_text (sys .executable , encoding = "utf-8" )
78
+ save_path .write_text (str (python_path ), encoding = "utf-8" )
79
+ except Exception as e :
80
+ logger .error ('Failed to write "%s" to "%s" (%s).' , python_path , save_path , e )
81
+ return - 1
82
+
83
+ try :
84
+ logger .debug ("Python configuration:" )
85
+ logger .debug ("Python %s" , sys .version )
86
+
87
+ for k , v in {
88
+ "sys.executable" : sys .executable ,
89
+ "sys._base_executable" : sys ._base_executable ,
90
+ "sys.prefix" : sys .prefix ,
91
+ "sys.base_prefix" : sys .base_prefix ,
92
+ "sys.exec_prefix" : sys .exec_prefix ,
93
+ "sys.base_exec_prefix" : sys .base_exec_prefix ,
94
+ }.items ():
95
+ logger .debug ('%s: "%s"' , k , v )
39
96
except Exception as e :
40
- logger .error ('Failed to write "%s" to "%s" (%s).' , sys .executable , str (save_path ), e )
97
+ logger .error (
98
+ "Failed to verify Python environment (%s). Please verify your Python environment is correct before configuring Ghidrathon." ,
99
+ e ,
100
+ )
41
101
return - 1
42
102
43
- logger .debug ('Wrote "%s" to "%s".' , sys .executable , str (save_path ))
44
- logger .info ("Please restart Ghidra for these changes to take effect." )
103
+ logger .debug ('Wrote "%s" to "%s".' , python_path , save_path )
104
+ logger .info (
105
+ 'Ghidrathon has been configured to use the Python interpreter located at "%s". Please restart Ghidra for these changes to take effect.' ,
106
+ python_path ,
107
+ )
45
108
46
109
return 0
47
110
0 commit comments