-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathob-idapython.el
32 lines (26 loc) · 1.22 KB
/
ob-idapython.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
;;; ob-idapython.el --- Org Babel support for executing IDA Python code -*- lexical-binding: t; -*-
(require 'ob)
(require 'ob-eval)
(defvar org-babel-default-header-args:idapython
'((:results . "none"))
"Default arguments for executing IDA Python code.")
(defun org-babel-execute:idapython (body params)
"Execute a block of IDA Python code with Babel."
(let* ((host (or (cdr (assoc :host params)) "localhost"))
(port (or (cdr (assoc :port params)) 4000))
(temp-file (make-temp-file "idapython-code-" nil ".py"))
(result-file (make-temp-file "idapython-result-" nil ".txt")))
(with-temp-file temp-file
(insert body))
(let ((command (format "curl -X POST -F 'code=@%s' -F 'result=@%s' http://%s:%d/execute"
temp-file result-file host port)))
(shell-command-to-string command))))
(defun org-babel-prep-session:idapython (_session _params)
"Return an error because IDA Python does not support sessions."
(error "IDA Python does not support sessions"))
(defun org-babel-edit-prep:idapython (info)
"Prepare the environment for editing an IDAPython code block."
(let ((lang (car info)))
(set (make-local-variable 'major-mode) 'python-mode)))
(provide 'ob-idapython)
;;; ob-idapython.el ends here