ioncodes / idacode

An integration for IDA and VS Code which connects both to easily execute and debug IDAPython scripts.
725 stars 77 forks source link

Imported module not updated #36

Closed Xartrick closed 1 year ago

Xartrick commented 1 year ago

Description

Imported modules do not reload when edited, keeping changes from being applied to main script.

How to reproduce

  1. Create imported_module.py

    def call_me():
    return 'Foo'
  2. Create main.py

    
    from imported_module import call_me

print(call_me())


3. Start IDACode from IDA

[IDACode] Listening on 127.0.0.1:7065


4. Connect IDACode from VSCode

[IDACode] Client connected [IDACode] Set workspace folder to c:\ida_code_bug


5. Save `main.py` to trigger code execution

[IDACode] Executing c:\ida_code_bug\main.py Foo


6. Edit `call_me` in `imported_module.py` to return `Bar`
```python
def call_me():
    return 'Bar'
[IDACode] Executing c:\ida_code_bug\imported_module.py
  1. Save main.py to trigger code execution
    [IDACode] Executing c:\ida_code_bug\main.py
    Foo

Expected result

call_me function should returns Bar.

Related issues

Xartrick commented 1 year ago

After more digging, this seems to be a known behavior, see Loading your own modules from your IDAPython scripts with idaapi.require() – Hex Rays.

Solution

from idaapi import require
require('imported_module')

from imported_module import call_me

print(call_me())

This can be closed or kept open for future reference.

ioncodes commented 1 year ago

Thanks for letting me know! I'll reference this issue in the README!