Skip to content

Commit f0e64b0

Browse files
authored
Merge pull request #8 from MeitarR/python2-support
Python2 support
2 parents 2210042 + 58dff97 commit f0e64b0

9 files changed

Lines changed: 35 additions & 27 deletions

File tree

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# IDACode
2-
IDACode makes it easy to execute and debug Python 3 scripts in your IDA environment without leaving Visual Studio Code. The VS Code extension can be found on the [marketplace](https://marketplace.visualstudio.com/items?itemName=Layle.idacode).
2+
IDACode makes it easy to execute and debug Python scripts in your IDA environment without leaving Visual Studio Code. The VS Code extension can be found on the [marketplace](https://marketplace.visualstudio.com/items?itemName=Layle.idacode).
33
IDACode is still in a very early state and bugs are to be expected. Please open a new issue if you encounter any issues.
44

55
## Features
@@ -8,14 +8,14 @@ IDACode is still in a very early state and bugs are to be expected. Please open
88
* **Compatibility**: IDACode does not require you to modify your scripts in a specific way. All scripts can be executed from within IDA without changes.
99
* **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.
1010

11-
IDACode only supports Python 3. If there's a need for Python 2 compatibility please vote [here](https://github.com/ioncodes/idacode/issues/3).
11+
IDACode supports both Python 2 and Python 3!
1212

1313
## Setup
1414
To set up the dependencies for the IDA plugin run:
1515

1616
```sh
1717
# make sure to use the correct Python version
18-
python3 -m pip install --user debugpy tornado
18+
python -m pip install --user debugpy tornado
1919
```
2020

2121
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.
@@ -51,7 +51,7 @@ Ensure that the workspace folder is the folder that your main scripts are locate
5151
Once you are connected you are able to select `Execute script in IDA`.
5252

5353
## Debugging
54-
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 3 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:
54+
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:
5555

5656
```py
5757
name = idc.get_segm_name(segment)
@@ -65,4 +65,5 @@ It is also important that attaching a debugger will create a new debugger instan
6565
![demo](idacode/images/preview.gif)
6666

6767
## Contributors
68-
* [mrexodia](https://github.com/mrexodia)
68+
* [mrexodia](https://github.com/mrexodia)
69+
* [MeitarR](https://github.com/MeitarR)

ida/idacode.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import sys
2-
if sys.version_info < (3, 3):
3-
print("[IDACode] Python 2.7 is not (yet) supported, vote at https://github.com/ioncodes/idacode/issues/3")
4-
sys.exit()
52

63
import idacode_utils.plugin as plugin
74

ida/idacode_utils/__init__.py

Whitespace-only changes.

ida/idacode_utils/dbg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ def bp(*args):
1414
break
1515
if condition:
1616
if message:
17-
print(f"[IDACode] {message}")
17+
print("[IDACode] {message}".format(message=message))
1818
api.breakpoint()

ida/idacode_utils/plugin.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
import socket, sys, os, threading, inspect, asyncio, subprocess
1+
import socket, sys, os, threading, inspect, subprocess
22
try:
33
import tornado, debugpy
44
except ImportError:
5-
print("[IDACode] Dependencies missing, run: python3 -m pip install --user debugpy tornado")
5+
print("[IDACode] Dependencies missing, run: python -m pip install --user debugpy tornado")
66
sys.exit()
77
import idaapi
88
import idacode_utils.dbg as dbg
99
import idacode_utils.hooks as hooks
1010
import idacode_utils.settings as settings
1111
from idacode_utils.socket_handler import SocketHandler
1212

13-
VERSION = "0.1.2"
13+
VERSION = "0.1.3"
1414
initialized = False
1515

1616
def setup_patches():
1717
hooks.install()
1818
sys.executable = settings.PYTHON
1919

2020
def create_socket_handler():
21-
asyncio.set_event_loop(asyncio.new_event_loop())
21+
if sys.version_info >= (3, 4):
22+
import asyncio
23+
asyncio.set_event_loop(asyncio.new_event_loop())
2224
app = tornado.web.Application([
2325
(r"/ws", SocketHandler),
2426
])
2527
server = tornado.httpserver.HTTPServer(app)
26-
print(f"[IDACode] Listening on {settings.HOST}:{settings.PORT}")
28+
print("[IDACode] Listening on {address}:{port}".format(address=settings.HOST, port=settings.PORT))
2729
server.listen(address=settings.HOST, port=settings.PORT)
2830

2931
def start_server():
@@ -34,7 +36,7 @@ def start_server():
3436
def get_python_versions():
3537
settings_version = subprocess.check_output([settings.PYTHON, "-c", "import sys; print(sys.version + sys.platform)"])
3638
settings_version = settings_version.decode("utf-8", "ignore").strip()
37-
ida_version = f"{sys.version}{sys.platform}"
39+
ida_version = "{}{}".format(sys.version, sys.platform)
3840
return (settings_version, ida_version)
3941

4042
class IDACode(idaapi.plugin_t):
@@ -53,14 +55,14 @@ def init(self):
5355
settings_version, ida_version = get_python_versions()
5456
if settings_version != ida_version:
5557
print("[IDACode] settings.PYTHON version mismatch, aborting load:")
56-
print(f"[IDACode] IDA interpreter: {ida_version}")
57-
print(f"[IDACode] settings.PYTHON: {settings_version}")
58+
print("[IDACode] IDA interpreter: {}".format(ida_version))
59+
print("[IDACode] settings.PYTHON: {}".format(settings_version))
5860
return idaapi.PLUGIN_SKIP
5961
else:
60-
print(f"[IDACode] settings.PYTHON ({settings.PYTHON}) does not exist, aborting load")
62+
print("[IDACode] settings.PYTHON ({}) does not exist, aborting load".format(settings.PYTHON))
6163
print("[IDACode] To fix this issue, modify idacode_utils/settings.py to point to the python executable")
6264
return idaapi.PLUGIN_SKIP
63-
print(f"[IDACode] Plugin version {VERSION}")
65+
print("[IDACode] Plugin version {}".format(VERSION))
6466
print("[IDACode] Plugin loaded, use Edit -> Plugins -> IDACode to start the server")
6567
return idaapi.PLUGIN_OK
6668

ida/idacode_utils/socket_handler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ def start_debug_server():
1616
if settings.LOGGING:
1717
tmp_path = tempfile.gettempdir()
1818
debugpy.log_to(tmp_path)
19-
print(f"[IDACode] Logging to {tmp_path} with pattern debugpy.*.log")
19+
print("[IDACode] Logging to {} with pattern debugpy.*.log".format(tmp_path))
2020
debugpy.listen((settings.HOST, settings.DEBUG_PORT))
21-
print(f"[IDACode] IDACode debug server listening on {settings.HOST}:{settings.DEBUG_PORT}")
21+
print("[IDACode] IDACode debug server listening on {address}:{port}".format(address=settings.HOST, port=settings.DEBUG_PORT))
2222

2323
class SocketHandler(tornado.websocket.WebSocketHandler):
2424
def open(self):
@@ -30,7 +30,7 @@ def on_message(self, message):
3030
if message["event"] == "set_workspace":
3131
path = message["path"]
3232
hooks.set_script_folder(path)
33-
print(f"[IDACode] Set workspace folder to {path}")
33+
print("[IDACode] Set workspace folder to {}".format(path))
3434
elif message["event"] == "attach_debugger":
3535
start_debug_server()
3636
self.write_message({
@@ -39,13 +39,13 @@ def on_message(self, message):
3939
elif message["event"] == "execute_script":
4040
script = message["path"]
4141
env = create_env()
42-
print(f"[IDACode] Executing {script}")
42+
print("[IDACode] Executing {}".format(script))
4343
idaapi.execute_sync(
4444
lambda: idaapi.IDAPython_ExecScript(script, env),
4545
idaapi.MFF_WRITE
4646
)
4747
else:
48-
print(f"[IDACode] Invalid event {message['event']}")
48+
print("[IDACode] Invalid event {}".format(message['event']))
4949

5050
def on_close(self):
5151
print("[IDACode] Client disconnected")

idacode/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@
1313
### 0.1.2
1414

1515
- Enhanced UX
16-
- Added configuration checks
16+
- Added configuration checks
17+
18+
### 0.1.3
19+
20+
- Added support for Python 2

idacode/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ IDACode doesn't support host to VM communication unless the VM uses a shared vol
5050
### 0.1.2
5151

5252
- Enhanced UX
53-
- Added configuration checks
53+
- Added configuration checks
54+
55+
### 0.1.3
56+
57+
- Added support for Python 2

idacode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "IDACode",
44
"description": "Run and debug your IDA scripts from VS Code",
55
"icon": "images/icon.png",
6-
"version": "0.1.2",
6+
"version": "0.1.3",
77
"publisher": "Layle",
88
"license": "SEE LICENSE IN LICENSE.md",
99
"preview": true,

0 commit comments

Comments
 (0)