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
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,60 @@ 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
+ )
64
+ return - 1
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
+ )
34
72
return - 1
35
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" )
39
79
except Exception as e :
40
- logger .error ('Failed to write "%s" to "%s" (%s).' , sys . executable , str ( save_path ) , e )
80
+ logger .error ('Failed to write "%s" to "%s" (%s).' , python_path , save_path , e )
41
81
return - 1
42
82
43
- logger .debug ('Wrote "%s" to "%s".' , sys .executable , str (save_path ))
44
- logger .info ("Please restart Ghidra for these changes to take effect." )
83
+ logger .debug ('Wrote "%s" to "%s".' , python_path , save_path )
84
+ logger .info (
85
+ 'Ghidrathon has been configured to use the Python interpreter located at "%s". Please restart Ghidra for these changes to take effect.' ,
86
+ python_path ,
87
+ )
45
88
46
89
return 0
47
90
0 commit comments