Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add install.py, update README, remove false positive errors, remove i… #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ The presence of this hash does not mean that the demangling failed; some demangl
In the Python environment used by IDA, run
```
pip install -r requirements.txt
python3 install.py
```



## Manual Installation

2. Copy [`ida_rust_untangler.py`](ida_rust_untangler.py) into your IDA plugins directory.

The exact location of the IDA plugins directory will vary by operating system, as well as the location of your IDA user directory (`$IDAUSR`). By default, they are in the following locations:
Expand Down
17 changes: 16 additions & 1 deletion ida_rust_untangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import rust_demangler
from rust_demangler.rust import TypeNotFoundError
import re

import idaapi
import idautils
Expand Down Expand Up @@ -84,14 +85,28 @@ def run(self, _arg):
pass

def demangle_action(self):
def search(input_str):
pattern = r"(::[a-z,0-9)]{17})$"
match = re.search(pattern, input_str)

if match:
return match.group(0)
else:
return None

for func_address in idautils.Functions():
func_name = idaapi.get_func_name(func_address)
func_object = idaapi.get_func(func_address)

if not func_name.startswith("_ZN"):
continue

logger.debug(f"{func_address:#x}, {func_name}")
try:
demangled_name = rust_demangler.demangle(func_name)
logger.info(f"Demangled: {func_address:#x}, {demangled_name}")
identifier_full = search(demangled_name)
if identifier_full:
demangled_name = demangled_name.replace(identifier_full, "")

# Automatically replace invalid characters with `_` (via SN_NOCHECK),
# and automatically append a numerical suffix to the name if it already exists (via SN_FORCE).
Expand Down
73 changes: 73 additions & 0 deletions install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/python3

import os
import shutil
import sys
import json

"""
Installs the ida-rust-untangler plugin into your IDA plugins user directory :
On Windows: %APPDATA%/Hex-Rays/IDA Pro
On Linux and Mac: $HOME/.idapro

Install: $ python3 install.py
"""


ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
INSTALL = ["ida_rust_untangler.py"]

#### Debug
ERASE_CONFIG = True
#####

def install(where: str) -> int:
# Remove old files
for file in INSTALL:
base = os.path.basename(file)
if os.path.exists(os.path.join(where, base)):
dst = os.path.join(where, os.path.basename(file))
if os.path.isdir(dst):
shutil.rmtree(dst)
else:
os.remove(dst)

# install
for file in INSTALL:
src = os.path.abspath(os.path.join(ROOT_DIR, file))
dst = os.path.join(where, os.path.basename(file))

print(f'[install.py] Creating "{dst}"')
is_dir = os.path.isdir(src)
if is_dir:
shutil.copytree(src, dst, dirs_exist_ok=True)
else:
shutil.copy(src, dst)

return 0


def main():
# find IDA installation
if os.name == "posix":
ida_plugins_dir = os.path.expandvars("/$HOME/.idapro/plugins")
cache_dir = os.path.expandvars("/$HOME/.idasync/")
elif os.name == "nt":
ida_plugins_dir = os.path.expandvars("%APPDATA%/Hex-Rays/IDA Pro/plugins")
cache_dir = os.path.expandvars("%APPDATA%/IDASync/")
else:
print(f"[install.py] Could not retrieve IDA install folder on OS {os.name}")
exit(1)

# make sure the "plugins" dir exists
os.makedirs(ida_plugins_dir, exist_ok=True)

ret = install(ida_plugins_dir)
if ret == 0:
print("[install.py] Done Installing Plugin")
else:
print("[install.py] Error installing")


if __name__ == "__main__":
main()