Ghidra逆向工具配置 MacOS 的启动台显示(Python)



写在前面

通过 ghidra 工具, 但是只能用命令行启动, 不太舒服, 写个脚本生成 MacOS 的 app 格式并导入启动台.

不算复杂, 主要是解析包的一些元信息还有裁剪软件图标(通过 MacOS 自带的 API)

脚本

python 复制代码
#!/opt/homebrew/bin/python3

import os
import re
import subprocess as sp

base_path = "/Applications"
app_name = "Ghidra"
exec_file = "ghidraRun"

target_path = f"{base_path}/{app_name}.app/Contents"

if not os.path.exists(target_path):
    print(f"{target_path} not exists, creating.")
    cmd = f"mkdir -p {target_path}/{{MacOS,Resources}}"
    os.system(cmd)

""" target layout
.
└── Contents
    ├── Info.plist
    ├── MacOS
    │   └── ghidraRun -> /opt/homebrew/bin/ghidraRun
    └── Resources
        └── logo.icns
"""

# 0. get meta Info
_, brew_prefix = sp.getstatusoutput("brew --prefix")
_, brew_info = sp.getstatusoutput(f"brew info {app_name}")
if brew_info.find("Not installed") != -1:
    print(f"{app_name} not installed, install...")
    os.system(f"brew install {app_name}")

version_num = re.match(r"==>.*?(\d+\.\d+\.\d+)[\s,]", brew_info).group(1)
exec_dir = re.findall(r"==> Artifacts\s(.*?)\(Binary", brew_info)[0].strip()
installed_dir = exec_dir[: exec_dir.rfind("/")]
img_file = f"{installed_dir}/docs/images/GHIDRA_1.png"


# 1. create soft link
src_exec = f"{brew_prefix}/bin/{exec_file}"
print(f"create soft link : {src_exec} => {target_path}/MacOS/{exec_file}")
os.system(f"ln -s {src_exec} {target_path}/MacOS/{exec_file}")

# 2. create icon by using sips
print(f"resize png file {img_file}")
tmp_img_file = "tmp.png"
os.system(f"sips -z 512 512 {img_file} -o {target_path}/{tmp_img_file}")
icns_file = "logo.icns"
print(f"generate icns file {icns_file}")
os.system(
    f"sips -s format icns {target_path}/{tmp_img_file} -o {target_path}/Resources/{icns_file}"
)
os.system(f"rm {target_path}/{tmp_img_file}")


# 3. create Info.plist
info_plist = f"""<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleName</key>
	<string>{app_name}</string>
	<key>CFBundleExecutable</key>
	<string>{exec_file}</string>
	<key>CFBundleIdentifier</key>
	<string>org.{app_name}</string>
	<key>CFBundleDisplayName</key>
	<string>{app_name}</string>
	<key>CFBundleVersion</key>
	<string>{version_num}</string>
	<key>CFBundleIconFile</key>
	<string>{icns_file}</string>
</dict>
</plist>"""

print(f"write info.plist to {target_path}/Info.plist")
with open(f"{target_path}/Info.plist", "w") as f:
    f.write(info_plist)

更新地址;

可以放在任意位置, 执行之后应该就会出现火龙的标志了:

相关推荐
秀儿还能再秀32 分钟前
淘宝母婴购物数据可视化分析(基于脱敏公开数据集)
python·数据分析·学习笔记·数据可视化
计算机老学长1 小时前
基于Python的商品销量的数据分析及推荐系统
开发语言·python·数据分析
千益1 小时前
玩转python:系统设计模式在Python项目中的应用
python·设计模式
&白帝&2 小时前
Java @PathVariable获取路径参数
java·开发语言·python
Shepherdppz2 小时前
python量化交易——金融数据管理最佳实践——使用qteasy大批量自动拉取金融数据
python·金融·量化交易
互联网杂货铺3 小时前
python+pytest 接口自动化测试:参数关联
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest
筱涵哥3 小时前
Python默认参数详细教程:默认参数位置错误,动态默认值,__defaults__属性,动态默认值处理,从入门到实战的保姆级教程
开发语言·python
yzztin3 小时前
Python 导包和依赖路径问题
python
pk_xz1234563 小时前
介绍如何基于现有的可运行STGCN(Spatial-Temporal Graph Convolutional Network)模型代码进行交通流预测的改动
python
用户8134411823613 小时前
Python基础
python