Skip to content

Commit

Permalink
merged #24, #17 and implemented #23
Browse files Browse the repository at this point in the history
  • Loading branch information
ioncodes committed May 18, 2021
1 parent 68474f6 commit 69abd5f
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 15 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ IDACode is still in a very early state and bugs are to be expected. Please open
* **Speed**: Quickly create and execute scripts.
* **Debugging**: Attach a Python debugger at any time.
* **Compatibility**: IDACode does not require you to modify your scripts in a specific way. All scripts can be executed from within IDA without changes.
* **Modularity**: IDACode does not make extensive use of safe wrappers for thread synchronization, this allows you to import any module from any path at any given time. Instead IDACode synchronizes the script execution thread with IDAs main thread to avoid performance and unexpected issues.
* **Modularity**: IDACode does not make extensive use of safe wrappers for thread synchronization, this allows you to import any module from any path at any given time. Instead IDACode synchronizes the script execution thread with IDAs main thread to avoid performance and unexpected issues.
* **Syncing**: As IDACode uses `debugpy` for communication, it syncs the output window naturally with VS Code's output panel.

IDACode supports both Python 2 and Python 3!

Expand All @@ -15,7 +16,8 @@ To set up the dependencies for the IDA plugin run:

```sh
# make sure to use the correct Python version
python -m pip install --user debugpy tornado
# it seems that there's an issue with the latest debugpy version (issue #19)
python -m pip install --user debugpy===1.0.0rc2 tornado
```

Either clone this repository or download a release package from [here](https://github.com/ioncodes/idacode/releases). `ida.zip` reflects the contents of the `ida` folder in this repository. Copy all files into IDAs plugin directory.
Expand Down Expand Up @@ -53,14 +55,14 @@ Ensure that the workspace folder is the folder that your main scripts are locate
Once you are connected you are able to select `Execute script in IDA`.

## Debugging
IDACode uses VS Code's remote debugger to connect to IDA. All VS Code features are supported. However, you have to specify the scripts entrypoint by using Python builtin functionality: `breakpoint`. This instruction tells the debugger to pause execution, if there's no debugger present it will just ignore the function. When executing `breakpoint` in IDA, IDACode gives you additional features such as logging and conditionals which are not present in the normal builtin function. Here's an example:
IDACode uses VS Code's remote debugger to connect to IDA. All VS Code features are supported. However, you have to specify the scripts entrypoint by using Python builtin functionality: `breakpoint`. This instruction tells the debugger to pause execution, if there's no debugger present it will just ignore the function. IDACode imports a helper package called `dbg` which implements an overload of `breakpoint` called `bp`. This function supports logging and conditionals:

```py
name = idc.get_segm_name(segment)
breakpoint(name==".text", f"found {name} at {segment}")
dbg.bp(name==".text", f"found {name} at {segment}")
```

Please also note that a `breakpoint()` call should never occur at the end of a file, it must always be before any other line of code as it breaks on the _next_ instruction in your code.
Please also note that a `breakpoint()` call should never occur at the end of a file, it must always be before any other line of code as it breaks on the _next_ instruction in your code. Also note that if you decide to use the `dbg` package you must either remove all references or use the variable `__idacode__` as conditional before executing it as a normal IDA script.
It is also important that attaching a debugger will create a new debugger instance. In most cases this is not what you want. If you disconnect from the debugger use VS Code's remote debugger to connect back.

## Demo
Expand All @@ -70,4 +72,5 @@ It is also important that attaching a debugger will create a new debugger instan
* [mrexodia](https://github.com/mrexodia)
* [MeitarR](https://github.com/MeitarR)
* [Plutoberth](https://github.com/Plutoberth)
* [OevreFlataeker](https://github.com/OevreFlataeker)
* [OevreFlataeker](https://github.com/OevreFlataeker)
* [RolfRolles](https://github.com/RolfRolles)
4 changes: 2 additions & 2 deletions ida/idacode_utils/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
if sys.version_info >= (3, 4):
import asyncio

VERSION = "0.2.2"
VERSION = "0.3.0"
initialized = False

def setup_patches():
hooks.install()
sys.executable = settings.PYTHON
#sys.executable = settings.PYTHON

def create_socket_handler():
if sys.version_info >= (3, 4):
Expand Down
2 changes: 1 addition & 1 deletion ida/idacode_utils/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
HOST = "127.0.0.1"
PORT = 7065
DEBUG_PORT = 7066
PYTHON = "C:\\Python37\\python37.exe"
PYTHON = "C:\\Program Files\\IDA 7.5\\python38\\python.exe"
LOGGING = False
4 changes: 2 additions & 2 deletions ida/idacode_utils/socket_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
def create_env():
return {
"dbg": dbg,
"breakpoint": dbg.bp,
"idacode": True,
"__idacode__": True,
"__name__": "__main__"
}

Expand All @@ -18,6 +17,7 @@ def start_debug_server():
tmp_path = tempfile.gettempdir()
debugpy.log_to(tmp_path)
print("[IDACode] Logging to {} with pattern debugpy.*.log".format(tmp_path))
debugpy.configure({ "python": settings.PYTHON })
debugpy.listen((settings.HOST, settings.DEBUG_PORT))
print("[IDACode] IDACode debug server listening on {address}:{port}".format(address=settings.HOST, port=settings.DEBUG_PORT))

Expand Down
9 changes: 7 additions & 2 deletions idacode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
### 0.1.4

- Added "Save on execute" support in settings

### 0.2.0

- Added "Execute on save" support in settings
Expand All @@ -31,4 +31,9 @@

### 0.2.2

- Updated README
- Updated README

### 0.3.0

- Fixed Python 2 support (PR #17)
- Fixed issue where debugpy would attempt to spawn the current process (Issue #23)
7 changes: 6 additions & 1 deletion idacode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,9 @@ IDACode doesn't support host to VM communication unless the VM uses a shared vol

### 0.2.2

- Updated README
- Updated README

### 0.3.0

- Fixed Python 2 support (PR #17)
- Fixed issue where debugpy would attempt to spawn the current process (Issue #23)
2 changes: 1 addition & 1 deletion idacode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "IDACode",
"description": "Run and debug your IDA scripts from VS Code",
"icon": "images/icon.png",
"version": "0.2.2",
"version": "0.3.0",
"publisher": "Layle",
"license": "SEE LICENSE IN LICENSE.md",
"preview": true,
Expand Down
3 changes: 3 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import sys

print(sys.path)

0 comments on commit 69abd5f

Please sign in to comment.