Skip to content

Commit

Permalink
Merge pull request zackelia#3 from zackelia/windows
Browse files Browse the repository at this point in the history
Add Windows support
  • Loading branch information
zackelia committed Nov 17, 2020
2 parents f21e81d + a819089 commit 7836111
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ghidra-dark

ghidra-dark provides a simple to use installer to install the FlatLaf dark theme, custom colors for disassembly/decompilation in Ghidra, and some other helpful settings. The installer supports all public builds through version 9.2 on Linux and macOS.
ghidra-dark provides a simple to use installer to install the FlatLaf dark theme, custom colors for disassembly/decompilation in Ghidra, and some other helpful settings. The installer supports all public builds through version 9.2 on Windows, Linux, and macOS.

## Install

Expand Down
33 changes: 22 additions & 11 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@
help="The installation path for Ghidra")
args = parser.parse_args()

# Ghidra cannot be running during the installation, also ignore our own process
# if ghidra is in an argument
p = subprocess.run(["pgrep", "-f", "ghidra"], stdout=subprocess.PIPE)
if p.returncode == 0 and p.stdout.strip() != str(os.getpid()).encode():
if os.name == "nt":
find_ghidra = "WMIC path win32_process get Commandline"
launch_sh = "launch.bat"
install_dir = ";%INSTALL_DIR%"
cpath = "set CPATH="
else:
find_ghidra = "ps -ax"
launch_sh = "launch.sh"
install_dir = ":${INSTALL_DIR}/"
cpath = "CPATH="

out = subprocess.check_output(find_ghidra.split())
if b"ghidrarun" in out.lower():
print("Please close any running Ghidra instances")
exit(-1)

Expand Down Expand Up @@ -53,15 +62,17 @@
with open(flatlaf_path, "wb") as fp:
fp.write(response.read())

launch_sh_path = os.path.join(install_path, "support", "launch.sh")
launch_sh_path = os.path.join(install_path, "support", launch_sh)
launch_properties_path = os.path.join(install_path, "support", "launch.properties")
cpath_positions = []

# Add FlatLaf to the list of jar files
with fileinput.FileInput(launch_sh_path, inplace=True, backup=".bak") as fp:
for line in fp:
if line.strip().startswith("CPATH=") and "flatlaf" not in line:
print(f"{line.rstrip()[:-1]}:${{INSTALL_DIR}}/flatlaf-0.43.jar\"")
if line.strip().startswith(cpath) and "flatlaf" not in line:
if os.name == "nt":
print(f"{line.rstrip()}{install_dir}flatlaf-0.43.jar")
else:
print(f"{line.rstrip()[:-1]}{install_dir}flatlaf-0.43.jar\"")
else:
print(line, end="")

Expand All @@ -86,23 +97,23 @@
version_path = f".ghidra-{version}"

ghidra_home_path = os.path.join(Path.home(), ".ghidra", version_path)
perferences_path = os.path.join(ghidra_home_path, "preferences")
preferences_path = os.path.join(ghidra_home_path, "preferences")
code_browser_path = os.path.join(ghidra_home_path, "tools", "_code_browser.tcd")
code_browser_bak_path = os.path.join(ghidra_home_path, "tools", "_code_browser.tcd.bak")

print(f"Using Ghidra home path: {ghidra_home_path}")

# Check if the current L&f is system
using_system = False
with open(perferences_path, "r") as fp:
with open(preferences_path, "r") as fp:
for line in fp:
if "LastLookAndFeel=System" in line:
using_system = True
break

# Set the L&f to system
if not using_system:
with open(perferences_path, "a") as fp:
with open(preferences_path, "a") as fp:
fp.write("LastLookAndFeel=System\n")

# Backup the current tcd
Expand Down
2 changes: 1 addition & 1 deletion tcd_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def update(self, preferences):
element = element[0]
if isinstance(option, Wrapped):
for state in option.states:
e = [_ for _ in category.iter() if _.get("NAME") == state.name][0]
e = [_ for _ in element.iter() if _.get("NAME") == state.name][0]
e.set("VALUE", state.value)
else:
element.set("VALUE", option.value)
Expand Down

0 comments on commit 7836111

Please sign in to comment.