DynamoRIO / DynamoRIO/dynamorio
Error loading a client in Windows 7 using python27.dll
- Dominant language
- C
- Stars
- 3.2k
- Forks
- 629
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 31
Description
Hi,
I am trying to develop a DynamoRio client that exports a python API for Windows. Like this: https://github.com/JonathanSalwan/Triton/tree/master/src/tracer/pin
But I am having problems using the python library in a DynamoRio client.
I modified the bbcount.c example to include and call one function of python:
``` C
#include /* for offsetof */
#include "dr_api.h"
#include "drmgr.h"
#include "drreg.h"
#include
#ifdef WINDOWS
# define DISPLAY_STRING(msg) dr_messagebox(msg)
#else
# define DISPLAY_STRING(msg) dr_printf("%s\n", msg);
#endif
#define NULL_TERMINATE(buf) buf[(sizeof(buf)/sizeof(buf[0])) - 1] = '\0'
#define TESTALL(mask, var) (((mask) & (var)) == (mask))
#define TESTANY(mask, var) (((mask) & (var)) != 0)
/* we only have a global count */
static int global_count;
#ifdef SHOW_RESULTS
/* some meta-stats: static (not per-execution) */
static int bbs_eflags_saved;
static int bbs_no_eflags_saved;
#endif
static void
event_exit(void)
{
#ifdef SHOW_RESULTS
char msg[512];
int len;
len = dr_snprintf(msg, sizeof(msg)/sizeof(msg[0]),
"Instrumentation results:\n"
"%10d basic block executions\n"
"%10d basic blocks needed flag saving\n"
"%10d basic blocks did not\n",
global_count, bbs_eflags_saved, bbs_no_eflags_saved);
DR_ASSERT(len > 0);
NULL_TERMINATE(msg);
DISPLAY_STRING(msg);
#endif /* SHOW_RESULTS */
drreg_exit();
drmgr_exit();
}
static dr_emit_flags_t
event_app_instruction(void *drcontext, void *tag, instrlist_t *bb, instr_t *inst,
bool for_trace, bool translating, void *user_data)
{
#ifdef SHOW_RESULTS
bool aflags_dead;
#endif
if (!drmgr_is_first_instr(drcontext, inst))
return DR_EMIT_DEFAULT;
#ifdef VERBOSE
dr_printf("in dynamorio_basic_block(tag="PFX")\n", tag);
# ifdef VERBOSE_VERBOSE
instrlist_disassemble(drcontext, tag, bb, STDOUT);
# endif
#endif
#ifdef SHOW_RESULTS
if (drreg_are_aflags_dead(drcontext, inst, &aflags_dead) == DRREG_SUCCESS &&
!aflags_dead)
bbs_eflags_saved++;
else
bbs_no_eflags_saved++;
#endif
/* We demonstrate how to use drreg for aflags save/restore here.
* We could use drx_insert_counter_update instead of drreg.
* Xref sample opcodes.c as an example of using drx_insert_counter_update.
*/
if (drreg_reserve_aflags(drcontext, bb, inst) != DRREG_SUCCESS)
DR_ASSERT(false && "fail to reserve aflags!");
/* racy update on the counter for better performance */
instrlist_meta_preinsert
(bb, inst,
INSTR_CREATE_inc(drcontext, OPND_CREATE_ABSMEM
((byte *)&global_count, OPSZ_4)));
if (drreg_unreserve_aflags(drcontext, bb, inst) != DRREG_SUCCESS)
DR_ASSERT(false && "fail to unreserve aflags!");
#if defined(VERBOSE) && defined(VERBOSE_VERBOSE)
dr_printf("Finished instrumenting dynamorio_basic_block(tag="PFX")\n", tag);
instrlist_disassemble(drcontext, tag, bb, STDOUT);
#endif
return DR_EMIT_DEFAULT;
}
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
if (argc ==3) //So it is never called
PyCallable_Check(NULL);
drreg_options_t ops = {sizeof(ops), 1 /*max slots needed: aflags*/, false};
dr_set_client_name("DynamoRIO Sample Client 'bbcount'",
"http://dynamorio.org/issues");
if (!drmgr_init() || drreg_init(&ops) != DRREG_SUCCESS)
DR_ASSERT(false);
/* register events */
dr_register_exit_event(event_exit);
if (!drmgr_register_bb_instrumentation_event(NULL, event_app_instruction, NULL))
DR_ASSERT(false);
/* make it easy to tell, by looking at log file, which client executed */
dr_log(NULL, LOG_ALL, 1, "Client 'bbcount' initializing\n");
#ifdef SHOW_RESULTS
/* also give notification to stderr */
if (dr_is_notify_on()) {
# ifdef WINDOWS
/* ask for best-effort printing to cmd window. must be called at init. */
dr_enable_console_printing();
# endif
dr_fprintf(STDERR, "Client bbcount is running\n");
}
#endif
}
```
And after this change the client is not working anymore:
drrun.exe -c ..\samples\bin\bbcount.dll -- notepad.exe
I get the following error:
```
Application C:\Windows\System32\notepad.exe (1160).
Unable to load client library: bbcount.dll
Unable to locate imports of client library.
```
It seeems that DynamoRio has some problems loading python27.dll.
A very similar unsolved error:
https://groups.google.com/forum/embed/#!topic/dynamorio-users/YfsrzBoNpPw
I think these error in the log are the most representative:
```
privload_process_imports: unable to load import lib SHELL32.dll
privload_load_finalize: failed to process imports python27.dll
```
The log generated:
```
global log file fd=88
DynamoRIO version 6.1.0, build 6, (c) DynamoRIO developers
Running: C:\Windows\system32\arp.exe
App cmdline: arp.exe
DynamoRIO built with: -DINTERNAL -DDEBUG -DDRSTATS_DEMO -DX86 -DX64 -DWINDOWS -DCLIENT_INTERFACE -DAPP_EXPORTS -DKSTATS -DANNOTATIONS -DNOLIBC -DASSEMBLE_WITH_MASM -DHAVE_MEMINFO -DHAVE_MEMINFO_QUERY -DWINDOWS_PC_SAMPLE -DDYNAMORIO_IR_EXPORTS -DCUSTOM_TRACES -DCLIENT_SIDELINE -DDR_APP_EXPORTS -DDEBUG_MEMORY -DSTACK_GUARD_PAGE -DHEAP_ACCOUNTING -DDEADLOCK_AVOIDANCE -DSHARING_STUDY -DHASHTABLE_STATISTICS
DynamoRIO built on: Feb 1 2016 23:48:46
DYNAMORIO_OPTIONS: -code_api -probe_api "-loglevel" "2" -client_lib "C:\Users\default.WIN-18AK2O7UHSG\Downloads\DynamoRIO-Windows-6.1.0-RC1\DynamoRIO-Windows-6.1.0-RC1\samples\bin\bbcount.dll;0;"
...
After removing, module lists are:
PEB LoaderData:
Length = 88
Initialized = 1
SsHandle = 0x0000000000000000
InLoadOrder:
0 0x00000000ff160000 0x00000000ff16417c 0xa000 C:\Windows\system32\arp.exe arp.exe
1 0x00000000773a0000 0x0000000000000000 0x1a9000 C:\Windows\SYSTEM32\ntdll.dll ntdll.dll
2 0x0000000077180000 0x0000000077195ea0 0x11f000 C:\Windows\system32\kernel32.dll kernel32.dll
3 0x000007fefd630000 0x000007fefd6330e0 0x6b000 C:\Windows\system32\KERNELBASE.dll KERNELBASE.dll
4 0x000007fefef80000 0x000007fefef825a0 0x9f000 C:\Windows\system32\msvcrt.dll msvcrt.dll
5 0x000007fef9a70000 0x000007fef9a75390 0xb000 C:\Windows\system32\snmpapi.dll snmpapi.dll
6 0x000007fefdf50000 0x000007fefdf51070 0x4d000 C:\Windows\system32\WS2_32.dll WS2_32.dll
7 0x000007feff470000 0x000007feff4bed50 0x12d000 C:\Windows\system32\RPCRT4.dll RPCRT4.dll
8 0x000007fefee10000 0x000007fefee11504 0x8000 C:\Windows\system32\NSI.dll NSI.dll
9 0x000007fefdae0000 0x000007fefdb00760 0xdb000 C:\Windows\system32\ADVAPI32.dll ADVAPI32.dll
10 0x000007fefe040000 0x000007fefe0460e8 0x1f000 C:\Windows\SYSTEM32\sechost.dll sechost.dll
11 0x000007fefb150000 0x000007fefb1598bc 0x27000 C:\Windows\system32\IPHLPAPI.DLL IPHLPAPI.DLL
12 0x000007fefb100000 0x000007fefb101198 0xb000 C:\Windows\system32\WINNSI.DLL WINNSI.DLL
13 0x00000000772a0000 0x00000000772ba2c8 0xfa000 C:\Windows\system32\USER32.dll USER32.dll
14 0x000007feff020000 0x000007feff02b03c 0x67000 C:\Windows\system32\GDI32.dll GDI32.dll
15 0x000007feff090000 0x000007feff091080 0xe000 C:\Windows\system32\LPK.dll LPK.dll
16 0x000007feff300000 0x000007feff37a874 0xc9000 C:\Windows\system32\USP10.dll USP10.dll
17 0x000007fefd180000 0x000007fefd181118 0x57000 C:\Windows\system32\apphelp.dll apphelp.dll
18 0x000007feee160000 0x000007feee16b030 0x467000 C:\Windows\AppPatch\AppPatch64\AcXtrnal.DLL AcXtrnal.DLL
19 0x000007fefdbc0000 0x000007fefdbc1010 0x2e000 C:\Windows\system32\IMM32.DLL IMM32.DLL
20 0x000007feff5a0000 0x000007feff5a1064 0x109000 C:\Windows\system32\MSCTF.dll MSCTF.dll
...
```
The complete log 300kb is here:
https://www.sendspace.com/file/o7lb4p
Platform: Windows 7 SP1 x64 bits
Version: DynamoRIO-Windows-6.1.0-RC1
Any ideas?
Contributor guide
Assessment
This issue has not been assessed yet.