Skip to content

Commit 842ca82

Browse files
committed
add additional checks to ghidrathon_configure.py
1 parent b0bef60 commit 842ca82

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

Diff for: .github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
Rename-Item -Path "./dist/$((Get-ChildItem -Path "./dist").Name)" -NewName "Ghidrathon.zip"
7171
tar -xf ./dist/Ghidrathon.zip -C ../tmp/ghidra/ghidra_PUBLIC/Ghidra/Extensions/
7272
- name: Set Ghidrathon Python interpreter
73-
run: python util/ghidrathon_configure.py ../tmp/ghidra/ghidra_PUBLIC
73+
run: python util/ghidrathon_configure.py ../tmp/ghidra/ghidra_PUBLIC -d
7474
- name: Run tests
7575
run: |
7676
../tmp/ghidra/ghidra_PUBLIC/support/analyzeHeadless ${{ github.workspace }}/../tmp/ghidra test -Import ${{ github.workspace }}/../tmp/ghidra/ghidra_PUBLIC/GPL/DemanglerGnu/os/linux_x86_64/demangler_gnu_v2_24 -PostScript ${{ github.workspace }}/data/python/tests/hello.py -PostScript ${{ github.workspace }}/data/python/tests/runall.py

Diff for: util/ghidrathon_configure.py

+48-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
77
# See the License for the specific language governing permissions and limitations under the License.
88

9+
import importlib
910
import argparse
1011
import pathlib
1112
import logging
1213
import sys
1314

1415

16+
SUPPORTED_JEP_VERSION = "4.2.0"
17+
1518
logger = logging.getLogger(__name__)
1619

1720
handler = logging.StreamHandler()
@@ -28,20 +31,60 @@ def main(args):
2831
if args.debug:
2932
logger.setLevel(logging.DEBUG)
3033

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+
3158
install_path: pathlib.Path = args.ghidrathon_install_directory
3259
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+
)
3472
return -1
3573

74+
logger.debug('Using Python interpreter located at "%s".', python_path)
75+
3676
save_path: pathlib.Path = install_path / "ghidrathon.save"
3777
try:
38-
save_path.write_text(sys.executable, encoding="utf-8")
78+
save_path.write_text(str(python_path), encoding="utf-8")
3979
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)
4181
return -1
4282

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+
)
4588

4689
return 0
4790

0 commit comments

Comments
 (0)