{"action":"created","issue":{"url":"https://api.github.com/repos/DynamoRIO/dynamorio/issues/1866","repository_url":"https://api.github.com/repos/DynamoRIO/dynamorio","labels_url":"https://api.github.com/repos/DynamoRIO/dynamorio/issues/1866/labels{/name}","comments_url":"https://api.github.com/repos/DynamoRIO/dynamorio/issues/1866/comments","events_url":"https://api.github.com/repos/DynamoRIO/dynamorio/issues/1866/events","html_url":"https://github.com/DynamoRIO/dynamorio/issues/1866","id":130855088,"number":1866,"title":"Error loading a client in Windows 7 using python27.dll","user":{"login":"0ca","id":5008707,"avatar_url":"https://avatars.githubusercontent.com/u/5008707?v=3","gravatar_id":"","url":"https://api.github.com/users/0ca","html_url":"https://github.com/0ca","followers_url":"https://api.github.com/users/0ca/followers","following_url":"https://api.github.com/users/0ca/following{/other_user}","gists_url":"https://api.github.com/users/0ca/gists{/gist_id}","starred_url":"https://api.github.com/users/0ca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/0ca/subscriptions","organizations_url":"https://api.github.com/users/0ca/orgs","repos_url":"https://api.github.com/users/0ca/repos","events_url":"https://api.github.com/users/0ca/events{/privacy}","received_events_url":"https://api.github.com/users/0ca/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/DynamoRIO/dynamorio/labels/OpSys-Windows","name":"OpSys-Windows","color":"FFFFFF"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2016-02-02T23:39:48Z","updated_at":"2016-02-04T05:55:30Z","closed_at":null,"body":"Hi, \r\n\r\nI 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\r\n\r\nBut I am having problems using the python library in a DynamoRio client.\r\n\r\nI modified the bbcount.c example to include and call one function of python:\r\n```C\r\n#include <stddef.h> /* for offsetof */\r\n#include \"dr_api.h\"\r\n#include \"drmgr.h\"\r\n#include \"drreg.h\"\r\n#include <Python.h>\r\n\r\n#ifdef WINDOWS\r\n# define DISPLAY_STRING(msg) dr_messagebox(msg)\r\n#else\r\n# define DISPLAY_STRING(msg) dr_printf(\"%s\\n\", msg);\r\n#endif\r\n\r\n#define NULL_TERMINATE(buf) buf[(sizeof(buf)/sizeof(buf[0])) - 1] = '\\0'\r\n\r\n#define TESTALL(mask, var) (((mask) & (var)) == (mask))\r\n#define TESTANY(mask, var) (((mask) & (var)) != 0)\r\n\r\n/* we only have a global count */\r\nstatic int global_count;\r\n\r\n#ifdef SHOW_RESULTS\r\n/* some meta-stats: static (not per-execution) */\r\nstatic int bbs_eflags_saved;\r\nstatic int bbs_no_eflags_saved;\r\n#endif\r\n\r\nstatic void\r\nevent_exit(void)\r\n{\r\n#ifdef SHOW_RESULTS\r\n    char msg[512];\r\n    int len;\r\n    len = dr_snprintf(msg, sizeof(msg)/sizeof(msg[0]),\r\n                      \"Instrumentation results:\\n\"\r\n                      \"%10d basic block executions\\n\"\r\n                      \"%10d basic blocks needed flag saving\\n\"\r\n                      \"%10d basic blocks did not\\n\",\r\n                      global_count, bbs_eflags_saved, bbs_no_eflags_saved);\r\n    DR_ASSERT(len > 0);\r\n    NULL_TERMINATE(msg);\r\n    DISPLAY_STRING(msg);\r\n#endif /* SHOW_RESULTS */\r\n    drreg_exit();\r\n    drmgr_exit();\r\n}\r\n\r\nstatic dr_emit_flags_t\r\nevent_app_instruction(void *drcontext, void *tag, instrlist_t *bb, instr_t *inst,\r\n                      bool for_trace, bool translating, void *user_data)\r\n{\r\n#ifdef SHOW_RESULTS\r\n    bool aflags_dead;\r\n#endif\r\n\r\n    if (!drmgr_is_first_instr(drcontext, inst))\r\n        return DR_EMIT_DEFAULT;\r\n\r\n#ifdef VERBOSE\r\n    dr_printf(\"in dynamorio_basic_block(tag=\"PFX\")\\n\", tag);\r\n# ifdef VERBOSE_VERBOSE\r\n    instrlist_disassemble(drcontext, tag, bb, STDOUT);\r\n# endif\r\n#endif\r\n\r\n#ifdef SHOW_RESULTS\r\n    if (drreg_are_aflags_dead(drcontext, inst, &aflags_dead) == DRREG_SUCCESS &&\r\n        !aflags_dead)\r\n        bbs_eflags_saved++;\r\n    else\r\n        bbs_no_eflags_saved++;\r\n#endif\r\n\r\n    /* We demonstrate how to use drreg for aflags save/restore here.\r\n     * We could use drx_insert_counter_update instead of drreg.\r\n     * Xref sample opcodes.c as an example of using drx_insert_counter_update.\r\n     */\r\n    if (drreg_reserve_aflags(drcontext, bb, inst) != DRREG_SUCCESS)\r\n        DR_ASSERT(false && \"fail to reserve aflags!\");\r\n    /* racy update on the counter for better performance */\r\n    instrlist_meta_preinsert\r\n        (bb, inst,\r\n         INSTR_CREATE_inc(drcontext, OPND_CREATE_ABSMEM\r\n                          ((byte *)&global_count, OPSZ_4)));\r\n    if (drreg_unreserve_aflags(drcontext, bb, inst) != DRREG_SUCCESS)\r\n        DR_ASSERT(false && \"fail to unreserve aflags!\");\r\n\r\n#if defined(VERBOSE) && defined(VERBOSE_VERBOSE)\r\n    dr_printf(\"Finished instrumenting dynamorio_basic_block(tag=\"PFX\")\\n\", tag);\r\n    instrlist_disassemble(drcontext, tag, bb, STDOUT);\r\n#endif\r\n    return DR_EMIT_DEFAULT;\r\n}\r\n\r\nDR_EXPORT void\r\ndr_client_main(client_id_t id, int argc, const char *argv[])\r\n{\r\n\tif (argc ==3)  //So it is never called\r\n\t\tPyCallable_Check(NULL);\r\n    drreg_options_t ops = {sizeof(ops), 1 /*max slots needed: aflags*/, false};\r\n    dr_set_client_name(\"DynamoRIO Sample Client 'bbcount'\",\r\n                       \"http://dynamorio.org/issues\");\r\n    if (!drmgr_init() || drreg_init(&ops) != DRREG_SUCCESS)\r\n        DR_ASSERT(false);\r\n\r\n    /* register events */\r\n    dr_register_exit_event(event_exit);\r\n    if (!drmgr_register_bb_instrumentation_event(NULL, event_app_instruction, NULL))\r\n        DR_ASSERT(false);\r\n\r\n    /* make it easy to tell, by looking at log file, which client executed */\r\n    dr_log(NULL, LOG_ALL, 1, \"Client 'bbcount' initializing\\n\");\r\n#ifdef SHOW_RESULTS\r\n    /* also give notification to stderr */\r\n    if (dr_is_notify_on()) {\r\n# ifdef WINDOWS\r\n        /* ask for best-effort printing to cmd window.  must be called at init. */\r\n        dr_enable_console_printing();\r\n# endif\r\n        dr_fprintf(STDERR, \"Client bbcount is running\\n\");\r\n    }\r\n#endif\r\n}\r\n```\r\n\r\nAnd after this change the client is not working anymore:\r\ndrrun.exe -c ..\\samples\\bin\\bbcount.dll -- notepad.exe\r\n\r\nI get the following error:\r\n```\r\nApplication C:\\Windows\\System32\\notepad.exe (1160). \r\nUnable to load client library: bbcount.dll \r\nUnable to locate imports of client library.\r\n```\r\n\r\nIt seeems that DynamoRio has some problems loading python27.dll.\r\n\r\nA very similar unsolved error:\r\nhttps://groups.google.com/forum/embed/#!topic/dynamorio-users/YfsrzBoNpPw\r\n\r\nI think these error in the log are the most representative:\r\n```\r\nprivload_process_imports: unable to load import lib SHELL32.dll\r\nprivload_load_finalize: failed to process imports python27.dll\r\n```\r\n\r\nThe log generated:\r\n```\r\nglobal log file fd=88\r\nDynamoRIO version 6.1.0, build 6, (c) DynamoRIO developers\r\nRunning: C:\\Windows\\system32\\arp.exe\r\nApp cmdline: arp.exe\r\nDynamoRIO 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\r\nDynamoRIO built on: Feb  1 2016 23:48:46\r\nDYNAMORIO_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;\"\r\n...\r\nAfter removing, module lists are:\r\nPEB LoaderData:\r\n\tLength = 88\r\n\tInitialized = 1\r\n\tSsHandle = 0x0000000000000000\r\nInLoadOrder:\r\n\t0  0x00000000ff160000 0x00000000ff16417c 0xa000 C:\\Windows\\system32\\arp.exe arp.exe\r\n\t1  0x00000000773a0000 0x0000000000000000 0x1a9000 C:\\Windows\\SYSTEM32\\ntdll.dll ntdll.dll\r\n\t2  0x0000000077180000 0x0000000077195ea0 0x11f000 C:\\Windows\\system32\\kernel32.dll kernel32.dll\r\n\t3  0x000007fefd630000 0x000007fefd6330e0 0x6b000 C:\\Windows\\system32\\KERNELBASE.dll KERNELBASE.dll\r\n\t4  0x000007fefef80000 0x000007fefef825a0 0x9f000 C:\\Windows\\system32\\msvcrt.dll msvcrt.dll\r\n\t5  0x000007fef9a70000 0x000007fef9a75390 0xb000 C:\\Windows\\system32\\snmpapi.dll snmpapi.dll\r\n\t6  0x000007fefdf50000 0x000007fefdf51070 0x4d000 C:\\Windows\\system32\\WS2_32.dll WS2_32.dll\r\n\t7  0x000007feff470000 0x000007feff4bed50 0x12d000 C:\\Windows\\system32\\RPCRT4.dll RPCRT4.dll\r\n\t8  0x000007fefee10000 0x000007fefee11504 0x8000 C:\\Windows\\system32\\NSI.dll NSI.dll\r\n\t9  0x000007fefdae0000 0x000007fefdb00760 0xdb000 C:\\Windows\\system32\\ADVAPI32.dll ADVAPI32.dll\r\n\t10  0x000007fefe040000 0x000007fefe0460e8 0x1f000 C:\\Windows\\SYSTEM32\\sechost.dll sechost.dll\r\n\t11  0x000007fefb150000 0x000007fefb1598bc 0x27000 C:\\Windows\\system32\\IPHLPAPI.DLL IPHLPAPI.DLL\r\n\t12  0x000007fefb100000 0x000007fefb101198 0xb000 C:\\Windows\\system32\\WINNSI.DLL WINNSI.DLL\r\n\t13  0x00000000772a0000 0x00000000772ba2c8 0xfa000 C:\\Windows\\system32\\USER32.dll USER32.dll\r\n\t14  0x000007feff020000 0x000007feff02b03c 0x67000 C:\\Windows\\system32\\GDI32.dll GDI32.dll\r\n\t15  0x000007feff090000 0x000007feff091080 0xe000 C:\\Windows\\system32\\LPK.dll LPK.dll\r\n\t16  0x000007feff300000 0x000007feff37a874 0xc9000 C:\\Windows\\system32\\USP10.dll USP10.dll\r\n\t17  0x000007fefd180000 0x000007fefd181118 0x57000 C:\\Windows\\system32\\apphelp.dll apphelp.dll\r\n\t18  0x000007feee160000 0x000007feee16b030 0x467000 C:\\Windows\\AppPatch\\AppPatch64\\AcXtrnal.DLL AcXtrnal.DLL\r\n\t19  0x000007fefdbc0000 0x000007fefdbc1010 0x2e000 C:\\Windows\\system32\\IMM32.DLL IMM32.DLL\r\n\t20  0x000007feff5a0000 0x000007feff5a1064 0x109000 C:\\Windows\\system32\\MSCTF.dll MSCTF.dll\r\n...\r\n```\r\n\r\nThe complete log 300kb is here:\r\nhttps://www.sendspace.com/file/o7lb4p\r\n\r\nPlatform: Windows 7 SP1 x64 bits\r\nVersion: DynamoRIO-Windows-6.1.0-RC1\r\n\r\nAny ideas?\r\n"},"comment":{"url":"https://api.github.com/repos/DynamoRIO/dynamorio/issues/comments/179659725","html_url":"https://github.com/DynamoRIO/dynamorio/issues/1866#issuecomment-179659725","issue_url":"https://api.github.com/repos/DynamoRIO/dynamorio/issues/1866","id":179659725,"user":{"login":"derekbruening","id":6509618,"avatar_url":"https://avatars.githubusercontent.com/u/6509618?v=3","gravatar_id":"","url":"https://api.github.com/users/derekbruening","html_url":"https://github.com/derekbruening","followers_url":"https://api.github.com/users/derekbruening/followers","following_url":"https://api.github.com/users/derekbruening/following{/other_user}","gists_url":"https://api.github.com/users/derekbruening/gists{/gist_id}","starred_url":"https://api.github.com/users/derekbruening/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/derekbruening/subscriptions","organizations_url":"https://api.github.com/users/derekbruening/orgs","repos_url":"https://api.github.com/users/derekbruening/repos","events_url":"https://api.github.com/users/derekbruening/events{/privacy}","received_events_url":"https://api.github.com/users/derekbruening/received_events","type":"User","site_admin":false},"created_at":"2016-02-04T05:55:29Z","updated_at":"2016-02-04T05:55:29Z","body":"You were running 64-bit originally, does the 64-bit shunimpl.dll entry also fail (you said \"Windows 7 x86\" above)?  Does loading the 64-bit python27.dll by itself load shunimpl.dll?\r\n\r\nWhat does Dependency Walker or \"dumpbin /imports\" say about python27.dll and its imports?  I.e., what do other tools say about this forwarder?"}}