📚 OpenRCE is preserved as a read-only archive. Launched at RECon Montreal in 2005. Registration and posting are disabled.








Flag: Tornado! Hurricane!

 Forums >>  IDA Pro  >>  IDAPython multithreading problem

Topic created on: March 25, 2011 16:21 CDT by dolex .

I'm using IDA 6.0 with IDAPython 1.4.3, and I need to create thread from the .py script.
My code looks like this:
import time, thread

def test_proc(msg):

    while True:

        print msg
        time.sleep(1)

thread.start_new_thread(test_proc, ("Test", ))

But it doesn't work properly: created thread freezes immediately after the script execution.
So, anybody knows some working solution, to run background thread from python code in IDA?

  aking1012     March 28, 2011 10:17.20 CDT
There's a talk from the guy that made IDArub on how to get single-threaded IDA to act as a sort of multithreaded server here: http://video.google.com/videoplay?docid=-7853301741351589832#
  
Not sure if it's helpful for you, but you could look at his code.  He talks about some of the challenges like what you are dealing with.

  pedram     March 28, 2011 12:04.42 CDT
If you are trying to make a socket server out of IDA then you can use the code IDAconnector.hpp from IDA Sync as a reference (http://www.openrce.org/downloads/details/2).

The crucial lines are:


// create an invisble window for hooking messages received by our socket.
    if ((socket_hwnd = CreateWindowEx(0, "STATIC", PLUGIN_NAME, 0, 0, 0, 0, 0, 0, 0, 0, 0)) == NULL)

...

// register the callback function for our invisible window.
    if (SetWindowLong(socket_hwnd, GWL_WNDPROC, (long) socket_proc_wrapper) == 0)

...

// make the socket a non-blocking asynchronous socket hooked with our socket_proc handler.
    if (WSAAsyncSelect(connection, socket_hwnd, SOCKET_MSG, FD_READ | FD_CLOSE) == SOCKET_ERROR)


You can make these calls from Python as well.

-pedram

  dolex     March 28, 2011 14:56.31 CDT
aking1012, pedram
Thanks for your answers.

I already solved the problem by writing a small DLL, that makes CreateThread() + PyRun_SimpleString("my_module.foo()").

I need in thread creation for running XMLRPC server to dispatch callback events from Ubigraph:
http://dl.dropbox.com/u/22903093/Ubigraph_and_IDA.gif
http://dl.dropbox.com/u/22903093/Worspace.JPG

  cseagle     March 29, 2011 16:35.11 CDT
Creating additional threads in Ida is a really bad idea. Ida does no locking/synchronization around database accesses because it assumes only one thread. If you are doing any database modifications from your new thread there is a good chance you will end up corrupting your database at some point.

  dolex     March 29, 2011 19:32.20 CDT
cseagle
I know, my thread doesn't modify database, i use it only for navigation in disassembly window (idc.Jump).

  cseagle     April 3, 2011 11:49.24 CDT
Actually, I need to update my previous post. In digging through the SDK, I learned that hex-Rays inserted a synchronization mechanism beginning with SDK 5.5.  Read through kernwin.hpp and look for execute_sync and exec_request_t. Threads wishing to interact with the database can create a request objec, and queue it with IDa's main thread. If all you do is read the database, you should use the MFF_READ flag to execute_sync.

Note: Registration is required to post to the forums.

There are 31,328 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06
Question about memor...
Dec/12


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit