Repository URL to install this package:
|
Version:
1:0.0.2-5.fc43 ▾
|
import os
import json
from pathlib import Path
import platform
def get_user_config_path():
"""Get the path to the user's config file based on platform following IDA's user directories."""
if idausr := os.getenv('IDAUSR'):
config_dir = Path(idausr)
else:
system = platform.system()
if system == "Windows":
# On Windows, use the %APPDATA%\Hex-Rays\IDA Pro directory
config_dir = Path(os.getenv('APPDATA')) / "Hex-Rays" / "IDA Pro"
else:
# On macOS and Linux, use ~/.idapro
config_dir = Path.home() / ".idapro"
# Return the full path to the config file (now in JSON format)
user_config_path = config_dir / "ida-config.json"
return user_config_path
def create_default_config(user_config_path):
"""Create a default config file in JSON format."""
# Create a default JSON config structure
default_config = {
"Paths": {
"ida-install-dir": ""
}
}
# Create the directory if it doesn't exist
user_config_path.parent.mkdir(parents=True, exist_ok=True)
# Write the default config to the user-specific config file
with user_config_path.open('w') as configfile:
json.dump(default_config, configfile, indent=4)
print(f"Default config file created at {user_config_path}")
return default_config
def load_config():
"""Load the user-specific config from JSON file."""
user_config_path = get_user_config_path()
if not user_config_path.exists():
# If the config file doesn't exist, create it with default values
config = create_default_config(user_config_path)
else:
# If the config file exists, load it
with user_config_path.open('r') as configfile:
config = json.load(configfile)
return config
def set_ida_install_dir(new_path):
"""Set the IDA installation directory in the user-specific JSON config file."""
pass
def get_ida_install_dir():
"""Retrieve the IDA installation directory."""
return os.environ.get('IDADIR', '/opt/ida90/libexec/idapro')