Skip to content

Commit

Permalink
Merge pull request #2454 from mandiant/fix/ida9idalib
Browse files Browse the repository at this point in the history
Fix IDA 9.0 / idalib
  • Loading branch information
mr-tz authored Oct 9, 2024
2 parents 6a12ab8 + f2c329b commit 1f7f24c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
### Bug Fixes

- extractor: fix exception when PE extractor encounters unknown architecture #2440 @Tamir-K
- IDA Pro: rename ida to idapro module for plugin and idalib in IDA 9.0 #2453 @mr-tz

### capa Explorer Web

Expand Down
2 changes: 1 addition & 1 deletion capa/features/extractors/ida/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def find_byte_sequence(start: int, end: int, seq: bytes) -> Iterator[int]:
return

while True:
ea, _ = ida_bytes.bin_search3(start, end, patterns, ida_bytes.BIN_SEARCH_FORWARD)
ea, _ = ida_bytes.bin_search(start, end, patterns, ida_bytes.BIN_SEARCH_FORWARD)
if ea == idaapi.BADADDR:
break
start = ea + 1
Expand Down
12 changes: 8 additions & 4 deletions capa/features/extractors/ida/idalib.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

def is_idalib_installed() -> bool:
try:
return importlib.util.find_spec("ida") is not None
return importlib.util.find_spec("idapro") is not None
except ModuleNotFoundError:
return False

Expand All @@ -44,13 +44,17 @@ def get_idalib_user_config_path() -> Optional[Path]:
def find_idalib() -> Optional[Path]:
config_path = get_idalib_user_config_path()
if not config_path:
logger.error("IDA Pro user configuration does not exist, please make sure you've installed idalib properly.")
return None

config = json.loads(config_path.read_text(encoding="utf-8"))

try:
ida_install_dir = Path(config["Paths"]["ida-install-dir"])
except KeyError:
logger.error(
"IDA Pro user configuration does not contain location of IDA Pro installation, please make sure you've installed idalib properly."
)
return None

if not ida_install_dir.exists():
Expand All @@ -73,7 +77,7 @@ def find_idalib() -> Optional[Path]:
if not idalib_path.exists():
return None

if not (idalib_path / "ida" / "__init__.py").is_file():
if not (idalib_path / "idapro" / "__init__.py").is_file():
return None

return idalib_path
Expand All @@ -96,7 +100,7 @@ def has_idalib() -> bool:

def load_idalib() -> bool:
try:
import ida
import idapro

return True
except ImportError:
Expand All @@ -106,7 +110,7 @@ def load_idalib() -> bool:

sys.path.append(idalib_path.absolute().as_posix())
try:
import ida # noqa: F401 unused import
import idapro # noqa: F401 unused import

return True
except ImportError:
Expand Down
4 changes: 2 additions & 2 deletions capa/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def get_extractor(
if not idalib.load_idalib():
raise RuntimeError("failed to load IDA idalib module.")

import ida
import idapro
import ida_auto

import capa.features.extractors.ida.extractor
Expand All @@ -333,7 +333,7 @@ def get_extractor(
# so as not to screw up structured output.
with capa.helpers.stdout_redirector(io.BytesIO()):
with console.status("analyzing program...", spinner="dots"):
if ida.open_database(str(input_path), run_auto_analysis=True):
if idapro.open_database(str(input_path), run_auto_analysis=True):
raise RuntimeError("failed to analyze input file")

logger.debug("idalib: waiting for analysis...")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ known_first_party = [
"binaryninja",
"flirt",
"ghidra",
"ida",
"idapro",
"ida_ida",
"ida_auto",
"ida_bytes",
Expand Down

0 comments on commit 1f7f24c

Please sign in to comment.