Changeset 1505

Show
Ignore:
Timestamp:
01/13/08 16:40:07 (8 months ago)
Author:
common
Message:

libemu

  • emu_profile introduces an api for storing function calls and parameters
    storing return values is todo, as well as dumping/rereading the profiles
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libemu/trunk/include/emu/Makefile.am

    r1315 r1505  
    2525include_HEADERS += emu_shellcode.h 
    2626include_HEADERS += emu_source.h 
     27include_HEADERS += emu_stack.h 
    2728include_HEADERS += emu_string.h 
    2829include_HEADERS += emu_track.h 
  • libemu/trunk/include/emu/environment/Makefile.am

    r1436 r1505  
    44 
    55SUBDIRS = win32 linux 
     6include_HEADERS = emu_profile.h 
    67 
  • libemu/trunk/include/emu/environment/win32/emu_env_w32.h

    r1442 r1505  
    3131struct emu_env_w32_dll; 
    3232struct emu_env_w32_dll_export; 
     33struct emu_profile; 
    3334 
    3435/** 
     
    5152         */ 
    5253        uint32_t        baseaddr; 
     54 
     55        struct emu_profile *profile; 
    5356}; 
    5457 
  • libemu/trunk/src/Makefile.am

    r1436 r1505  
    2424libemu_la_SOURCES += emu_list.c 
    2525libemu_la_SOURCES += emu_queue.c 
     26libemu_la_SOURCES += emu_stack.c 
    2627libemu_la_SOURCES += emu_shellcode.c 
    2728libemu_la_SOURCES += emu_source.c 
     
    7879libemu_la_SOURCES += libdasm.c libdasm.h opcode_tables.h 
    7980 
     81libemu_la_SOURCES += environment/emu_profile.c 
    8082libemu_la_SOURCES += environment/win32/emu_env_w32.c 
    8183libemu_la_SOURCES += environment/win32/emu_env_w32_dll.c 
  • libemu/trunk/src/environment/win32/emu_env_w32.c

    r1442 r1505  
    3434#include "emu/emu_memory.h" 
    3535#include "emu/emu_hashtable.h" 
     36#include "emu/environment/emu_profile.h" 
    3637#include "emu/environment/win32/emu_env_w32.h" 
    3738#include "emu/environment/win32/emu_env_w32_dll.h" 
     
    151152        struct emu_env_w32 *env = (struct emu_env_w32 *)malloc(sizeof(struct emu_env_w32)); 
    152153        memset(env,0,sizeof(struct emu_env_w32)); 
     154        env->profile = emu_profile_new(); 
    153155        env->emu = e; 
    154156        // write TEB and linklist 
  • libemu/trunk/src/environment/win32/env_w32_dll_export_kernel32_hooks.c

    r1367 r1505  
    4949#include "emu/emu_hashtable.h" 
    5050#include "emu/emu_string.h" 
     51#include "emu/environment/emu_profile.h" 
    5152#include "emu/environment/win32/emu_env_w32.h" 
    5253#include "emu/environment/win32/emu_env_w32_dll.h" 
     
    6667        POP_DWORD(c, &eip_save); 
    6768 
     69         
     70         
    6871/* 
    6972BOOL CloseHandle( 
     
    7174); 
    7275*/ 
     76        emu_profile_function_add(env->profile, "CloseHandle"); 
    7377 
    7478        uint32_t object; 
    7579        POP_DWORD(c, &object); 
     80        emu_profile_argument_add_int(env->profile, "Handle", "hObject", object); 
    7681 
    7782        emu_cpu_eip_set(c, eip_save); 
     
    102107); 
    103108*/ 
     109        emu_profile_function_add(env->profile, "CreateFile"); 
    104110 
    105111        uint32_t filename; 
    106112        POP_DWORD(c, &filename); 
     113        emu_profile_argument_add_ref(env->profile, "LPCTSTR", "lpFileName", filename); 
     114        emu_profile_argument_add_string(env->profile, "", "", ""); 
     115 
    107116 
    108117        uint32_t desiredaccess; 
    109118        POP_DWORD(c, &desiredaccess); 
     119        emu_profile_argument_add_int(env->profile, "DWORD", "dwDesiredAccess", desiredaccess); 
    110120 
    111121        uint32_t sharemode; 
    112122        POP_DWORD(c, &sharemode); 
     123        emu_profile_argument_add_int(env->profile, "DWORD", "dwShareMode", sharemode); 
    113124 
    114125        uint32_t securityattr; 
    115126        POP_DWORD(c, &securityattr); 
    116  
    117         uint32_t createdisp; 
     127        emu_profile_argument_add_ref(env->profile, "LPSECURITY_ATTRIBUTES", "lpSecurityAttributes", securityattr); 
     128        emu_profile_argument_add_int(env->profile, "", "", 0); 
     129 
     130    uint32_t createdisp; 
    118131        POP_DWORD(c, &createdisp); 
     132        emu_profile_argument_add_int(env->profile, "DWORD", "dwCreationDisposition", createdisp); 
    119133 
    120134        uint32_t flagsandattr; 
    121135        POP_DWORD(c, &flagsandattr); 
     136        emu_profile_argument_add_int(env->profile, "DWORD", "dwFlagsAndAttributes", flagsandattr); 
    122137 
    123138        uint32_t templatefile; 
    124139        POP_DWORD(c, &templatefile); 
     140        emu_profile_argument_add_int(env->profile, "Handle", "hTemplateFile", templatefile); 
    125141 
    126142        emu_cpu_eip_set(c, eip_save); 
     
    135151 
    136152        struct emu_cpu *c = emu_cpu_get(env->emu); 
     153        struct emu_memory *m = emu_memory_get(env->emu); 
    137154 
    138155        uint32_t eip_save; 
     
    153170);*/ 
    154171 
    155         uint32_t imagename; 
    156         POP_DWORD(c, &imagename); 
    157  
    158         uint32_t cmdline; 
    159         POP_DWORD(c, &cmdline); 
    160  
    161         uint32_t process; 
    162         POP_DWORD(c, &process); 
    163  
    164         uint32_t thread; 
    165         POP_DWORD(c, &thread); 
     172        emu_profile_function_add(env->profile, "CreateProcess"); 
     173 
     174        uint32_t p_imagename; 
     175        POP_DWORD(c, &p_imagename); 
     176        emu_profile_argument_add_ref(env->profile, "LPCWSTR", "pszImageName", p_imagename); 
     177        emu_profile_argument_add_string(env->profile, "",  "", ""); 
     178 
     179        uint32_t p_cmdline; 
     180        POP_DWORD(c, &p_cmdline); 
     181        emu_profile_argument_add_ref(env->profile, "LPCWSTR", "pszCmdLine", p_cmdline); 
     182 
     183        struct emu_string *command = emu_string_new(); 
     184        emu_memory_read_string(m, p_cmdline, command, 1024); 
     185        emu_profile_argument_add_string(env->profile, "","", emu_string_char(command)); 
     186//      emu_string_free(command); 
     187 
     188 
     189        uint32_t p_process; 
     190        POP_DWORD(c, &p_process); 
     191        emu_profile_argument_add_ref(env->profile, "LPSECURITY_ATTRIBUTES", "psaProcess", p_process); 
     192        emu_profile_argument_add_string(env->profile, "", "", ""); 
     193 
     194 
     195        uint32_t p_thread; 
     196        POP_DWORD(c, &p_thread); 
     197        emu_profile_argument_add_ref(env->profile, "LPSECURITY_ATTRIBUTES", "psaThread", p_thread); 
     198        emu_profile_argument_add_string(env->profile, "", "", ""); 
     199 
    166200 
    167201        uint32_t inherithandles; 
    168202        POP_DWORD(c, &inherithandles); 
     203        emu_profile_argument_add_int(env->profile, "BOOL", "fInheritHandles", inherithandles); 
     204 
    169205 
    170206        uint32_t create; 
    171207        POP_DWORD(c, &create); 
     208        emu_profile_argument_add_int(env->profile, "DWORD", "fdwCreate", create); 
    172209 
    173210        uint32_t environment; 
    174211        POP_DWORD(c, &environment); 
     212        emu_profile_argument_add_ref(env->profile, "LPVOID", "pvEnvironment", environment); 
     213        emu_profile_argument_add_string(env->profile, "", "", ""); 
     214 
    175215 
    176216        uint32_t cwd; 
    177217        POP_DWORD(c, &cwd); 
     218        emu_profile_argument_add_ref(env->profile, "LPWSTR", "pszCurDir", cwd); 
     219        emu_profile_argument_add_string(env->profile, "", "", ""); 
     220 
    178221 
    179222        uint32_t p_startinfo; 
    180223        POP_DWORD(c, &p_startinfo); 
     224        emu_profile_argument_add_ref(env->profile, "LPSTARTUPINFOW", "psiStartInfo", p_startinfo); 
     225 
     226        STARTUPINFO *si = malloc(sizeof(STARTUPINFO)); 
     227        emu_memory_read_block(m, p_startinfo, si, sizeof(STARTUPINFO)); 
     228 
     229        emu_profile_argument_start(env->profile, "", ""); 
     230        emu_profile_argument_add_int(env->profile, "DWORD",  "cb"                               , si->cb);                                                    
     231        emu_profile_argument_add_int(env->profile, "LPTSTR", "lpReserved"               , (unsigned int)si->lpReserved); 
     232        emu_profile_argument_add_int(env->profile, "LPTSTR", "lpDesktop"                , (unsigned int)si->lpDesktop); 
     233        emu_profile_argument_add_int(env->profile, "LPTSTR", "lpTitle"                  , (unsigned int)si->lpTitle); 
     234        emu_profile_argument_add_int(env->profile, "DWORD",  "dwX"                              , si->dwX); 
     235        emu_profile_argument_add_int(env->profile, "DWORD",  "dwY"                              , si->dwY); 
     236        emu_profile_argument_add_int(env->profile, "DWORD",  "dwXSize"                  , si->dwXSize); 
     237        emu_profile_argument_add_int(env->profile, "DWORD",  "dwYSize"                  , si->dwYSize); 
     238        emu_profile_argument_add_int(env->profile, "DWORD",  "dwXCountChars"    , si->dwXCountChars); 
     239        emu_profile_argument_add_int(env->profile, "DWORD",  "dwYCountChars"    , si->dwYCountChars); 
     240        emu_profile_argument_add_int(env->profile, "DWORD",  "dwFillAttribute"  , si->dwFillAttribute); 
     241        emu_profile_argument_add_int(env->profile, "DWORD",  "dwFlags"                  , si->dwFlags); 
     242        emu_profile_argument_add_int(env->profile, "WORD",   "wShowWindow"              , si->wShowWindow); 
     243        emu_profile_argument_add_int(env->profile, "WORD",   "cbReserved2"              , si->cbReserved2); 
     244        emu_profile_argument_add_int(env->profile, "LPBYTE", "lpReserved2"              , (unsigned int)si->lpReserved2); 
     245        emu_profile_argument_add_int(env->profile, "HANDLE", "hStdInput"                , si->hStdInput);                                             
     246        emu_profile_argument_add_int(env->profile, "HANDLE", "hStdOutput"               , si->hStdOutput);                                            
     247        emu_profile_argument_add_int(env->profile, "HANDLE", "hStdError"                , si->hStdError);                                            
     248        emu_profile_argument_end(env->profile); 
     249         
    181250 
    182251        uint32_t p_procinfo; 
    183252        POP_DWORD(c, &p_procinfo); 
     253        emu_profile_argument_add_ref(env->profile, "PROCESS_INFORMATION", "pProcInfo",0x52f74c); 
     254 
     255        PROCESS_INFORMATION *pi = malloc(sizeof(PROCESS_INFORMATION)); 
     256        emu_memory_read_block(m, p_procinfo, pi, sizeof(PROCESS_INFORMATION)); 
     257 
     258        emu_profile_argument_start(env->profile, "", ""); 
     259        emu_profile_argument_add_int(env->profile, "DWORD", "hProcess"          ,pi->dwProcessId); 
     260        emu_profile_argument_add_int(env->profile, "DWORD", "hThread"                   ,pi->dwThreadId); 
     261        emu_profile_argument_add_int(env->profile, "HANDLE", "dwProcessId"              ,pi->hProcess); 
     262        emu_profile_argument_add_int(env->profile, "HANDLE", "dwThreadId"               ,pi->hThread); 
     263        emu_profile_argument_end(env->profile); 
     264 
    184265 
    185266 
     
    187268        emu_cpu_reg32_set(c, eax, 0); 
    188269 
    189         struct emu_memory *m = emu_memory_get(env->emu); 
    190     PROCESS_INFORMATION *pi = malloc(sizeof(PROCESS_INFORMATION)); 
    191         emu_memory_read_block(m, p_procinfo, pi, sizeof(PROCESS_INFORMATION)); 
     270         
    192271 
    193272        pi->dwProcessId = 4711; 
     
    198277        emu_memory_write_block(m, p_procinfo, pi, sizeof(PROCESS_INFORMATION)); 
    199278 
    200         STARTUPINFO *si = malloc(sizeof(STARTUPINFO)); 
    201         emu_memory_read_block(m, p_startinfo, si, sizeof(STARTUPINFO)); 
    202  
    203         printf("CreateProcess(pszImageName=%x, pszCmdLine=%x, psaProcess=%x, psaThread=%x, fInheritHandles=%i, fdwCreate=%i, pvEnvironment=%x, pszCurDir=%x, psiStartInfo=%x, pProcInfo=%x)\n",  
    204                    imagename, cmdline, process, thread, inherithandles, create, environment, cwd, p_startinfo, p_procinfo); 
    205  
    206         printf("PROCESS_INFORMATION\n" 
    207                    "{\n" 
    208                    "\tHANDLE hProcess=%i;\n" 
    209                    "\tHANDLE hThread=%i;\n" 
    210                    "\tDWORD dwProcessId=%i;\n" 
    211                    "\tDWORD dwThreadId=%i;\n" 
    212                    "}\n", 
    213                    pi->dwProcessId,  
    214                    pi->dwThreadId,  
    215                    pi->hProcess,  
    216                    pi->hThread); 
    217  
    218  
    219         printf("STARTUPINFO {\n" 
    220                    "\tDWORD cb=%i;\n" 
    221                    "\tLPTSTR lpReserved=0x%08x;\n" 
    222                    "\tLPTSTR lpDesktop=0x%08x;\n" 
    223                    "\tLPTSTR lpTitle=0x%08x;\n" 
    224                    "\tDWORD dwX=%i;\n" 
    225                    "\tDWORD dwY=%i;\n" 
    226                    "\tDWORD dwXSize=%i;\n" 
    227                    "\tDWORD dwYSize=%i;\n" 
    228                    "\tDWORD dwXCountChars=%i;\n" 
    229                    "\tDWORD dwYCountChars=%i;\n" 
    230                    "\tDWORD dwFillAttribute=%i;\n" 
    231                    "\tDWORD dwFlags=%i;\n" 
    232                    "\tWORD wShowWindow=%i;\n" 
    233                    "\tWORD cbReserved2=%i;\n" 
    234                    "\tLPBYTE lpReserved2=0x08%x;\n" 
    235                    "\tHANDLE hStdInput=%i;\n" 
    236                    "\tHANDLE hStdOutput=%i;\n" 
    237                    "\tHANDLE hStdError=%i;\n" 
    238                    "}\n", 
    239                    si->cb, 
    240                    (unsigned int)si->lpReserved, 
    241                    (unsigned int)si->lpDesktop, 
    242                    (unsigned int)si->lpTitle, 
    243                    si->dwX, 
    244                    si->dwY, 
    245                    si->dwXSize, 
    246                    si->dwYSize, 
    247                    si->dwXCountChars, 
    248                    si->dwYCountChars, 
    249                    si->dwFillAttribute, 
    250                    si->dwFlags, 
    251                    si->wShowWindow, 
    252                    si->cbReserved2, 
    253                    (unsigned int)si->lpReserved2, 
    254                    si->hStdInput, 
    255                    si->hStdOutput, 
    256                    si->hStdError); 
    257279 
    258280        fflush(NULL); 
    259281 
    260282#ifdef HAVE_INTERACTIVE_HOOKS 
    261 // the code is meant to be an example how one could do it 
    262         pid_t pid; 
    263         if ((pid = fork()) == 0) 
    264         { // child 
    265  
    266                 dup2(si->hStdInput,  fileno(stdin)); 
    267                 dup2(si->hStdOutput, fileno(stdout)); 
    268                 dup2(si->hStdError,  fileno(stderr)); 
    269  
    270         system("/opt/cmd/bin/cmdexe.pl -p winxp -l /opt/cmd/var/log/cmd/"); 
    271                 exit(EXIT_SUCCESS); 
    272         }else 
    273         { // parent  
    274                 pi->hProcess = pid; 
    275                 emu_memory_write_block(m, p_procinfo, pi, sizeof(PROCESS_INFORMATION)); 
     283        if (emu_string_char(command) != NULL && strncasecmp(emu_string_char(command), "cmd", 3) == 0) 
     284        { 
     285         
     286        // the code is meant to be an example how one could do it 
     287                pid_t pid; 
     288                if ((pid = fork()) == 0) 
     289                { // child 
     290         
     291                        dup2(si->hStdInput,  fileno(stdin)); 
     292                        dup2(si->hStdOutput, fileno(stdout)); 
     293                        dup2(si->hStdError,  fileno(stderr)); 
     294         
     295                        system("/opt/cmd/bin/cmdexe.pl -p winxp -l /opt/cmd/var/log/cmd/"); 
     296                        exit(EXIT_SUCCESS); 
     297                }else 
     298                { // parent  
     299                        pi->hProcess = pid; 
     300                        emu_memory_write_block(m, p_procinfo, pi, sizeof(PROCESS_INFORMATION)); 
     301                } 
    276302        } 
    277303#endif 
    278  
     304        emu_string_free(command); 
     305        free(pi); 
     306        free(si); 
    279307        emu_cpu_eip_set(c, eip_save); 
    280308        return 0; 
     
    298326 
    299327*/ 
     328        emu_profile_function_add(env->profile, "DeleteFile"); 
    300329        uint32_t filename; 
    301330        POP_DWORD(c, &filename); 
     331        emu_profile_argument_add_ref(env->profile, "LPCTSTR", "lpFileName", filename); 
     332        emu_profile_argument_add_string(env->profile, "", "", ""); 
    302333 
    303334        emu_cpu_eip_set(c, eip_save); 
     
    457488int32_t env_w32_hook_GetProcAddress(struct emu_env_w32 *env, struct emu_env_w32_dll_export *ex) 
    458489{ 
    459         printf("Hook me Captain Cook!\n"); 
    460         printf("%s:%i %s\n",__FILE__,__LINE__,__FUNCTION__); 
    461  
    462         struct emu_cpu *c = emu_cpu_get(env->emu); 
     490        struct emu_cpu *c = emu_cpu_get(env->emu); 
     491        struct emu_memory *mem = emu_memory_get(env->emu); 
    463492 
    464493        uint32_t eip_save; 
     
    471500); 
    472501*/ 
    473  
     502        emu_profile_function_add(env->profile, "GetProcAddress"); 
     503         
    474504 
    475505        uint32_t module;// = emu_cpu_reg32_get(c, esp); 
    476506        POP_DWORD(c, &module); 
    477  
    478         printf("module ptr is %08x\n", module); 
     507        emu_profile_argument_add_int(env->profile, "HMODULE", "hModule", module); 
     508 
     509//      printf("module ptr is %08x\n", module); 
    479510 
    480511        uint32_t p_procname; 
    481512        POP_DWORD(c, &p_procname); 
     513        emu_profile_argument_add_ref(env->profile, "LPCSTR", "lpProcName", p_procname); 
     514         
    482515 
    483516        struct emu_string *procname = emu_string_new(); 
    484         struct emu_memory *mem = emu_memory_get(env->emu); 
    485517        emu_memory_read_string(mem, p_procname, procname, 256); 
    486  
     518        emu_profile_argument_add_string(env->profile, "", "", emu_string_char(procname)); 
    487519 
    488520        printf("procname name is '%s'\n", emu_string_char(procname)); 
     
    537569); 
    538570*/ 
     571        emu_profile_function_add(env->profile, "GetSystemDirectory"); 
     572 
    539573        uint32_t p_buffer; 
    540574        POP_DWORD(c, &p_buffer); 
     575        emu_profile_argument_add_ref(env->profile, "LPTSTR", "lpBuffer", p_buffer); 
     576        emu_profile_argument_add_string(env->profile, "", "", ""); 
    541577 
    542578        uint32_t size; 
    543579        POP_DWORD(c, &size); 
     580        emu_profile_argument_add_int(env->profile, "UINT", "uSize", size); 
     581 
    544582 
    545583        emu_memory_write_block(emu_memory_get(env->emu), p_buffer, "c:\\WINDOWS\\system32\x00", 20); 
     
    658696int32_t env_w32_hook_LoadLibrayA(struct emu_env_w32 *env, struct emu_env_w32_dll_export *ex) 
    659697{ 
    660         printf("Hook me Captain Cook!\n"); 
    661         printf("%s:%i %s\n",__FILE__,__LINE__,__FUNCTION__); 
     698 
     699 
     700 
     701        struct emu_cpu *c = emu_cpu_get(env->emu); 
     702 
     703        uint32_t eip_save; 
     704        POP_DWORD(c, &eip_save); 
    662705 
    663706/* HMODULE WINAPI LoadLibrary(LPCTSTR lpFileName); */ 
    664707 
    665         struct emu_cpu *c = emu_cpu_get(env->emu); 
    666  
    667         uint32_t eip_save; 
    668         POP_DWORD(c, &eip_save); 
     708        emu_profile_function_add(env->profile, "LoadLibraryA"); 
    669709 
    670710        uint32_t dllname_ptr;// = emu_cpu_reg32_get(c, esp); 
    671          
    672         POP_DWORD(c, &dllname_ptr); 
     711    POP_DWORD(c, &dllname_ptr); 
     712        emu_profile_argument_add_ref(env->profile, "LPCTSTR", "lpFileName", dllname_ptr); 
     713         
    673714 
    674715    struct emu_string *dllstr = emu_string_new(); 
     
    676717    emu_memory_read_string(mem, dllname_ptr, dllstr, 256); 
    677718 
     719 
    678720        char *dllname = emu_string_char(dllstr); 
     721        emu_profile_argument_add_string(env->profile, "", "", dllname); 
     722 
    679723 
    680724        int i; 
     
    827871); 
    828872*/ 
     873        emu_profile_function_add(env->profile, "WaitForSingleObject"); 
    829874 
    830875        uint32_t handle; 
    831876        POP_DWORD(c, &handle); 
     877        emu_profile_argument_add_int(env->profile, "HANDLE", "hHandle", handle); 
    832878 
    833879        uint32_t msecs; 
    834880        POP_DWORD(c, &msecs); 
     881        emu_profile_argument_add_int(env->profile, "DWORD", "dwMilliseconds", msecs); 
    835882 
    836883        printf("WaitForSingleObject(hHandle=%i,  dwMilliseconds=%i)\n", handle, msecs); 
     
    870917); 
    871918*/ 
    872  
    873         uint32_t cmdline_ptr; 
    874         POP_DWORD(c, &cmdline_ptr); 
     919        emu_profile_function_add(env->profile, "WinExec"); 
     920 
     921        uint32_t p_cmdline; 
     922        POP_DWORD(c, &p_cmdline); 
     923        emu_profile_argument_add_ref(env->profile, "LPCSTR", "lpCmdLine", p_cmdline); 
     924 
     925        struct emu_string *cmdstr = emu_string_new(); 
     926        emu_memory_read_string(emu_memory_get(env->emu), p_cmdline, cmdstr, 256); 
     927        emu_profile_argument_add_string(env->profile, "", "", emu_string_char(cmdstr)); 
     928        emu_string_free(cmdstr); 
     929 
    875930 
    876931        uint32_t show; 
    877932        POP_DWORD(c, &show); 
    878  
    879  
    880     struct emu_string *cmdstr = emu_string_new(); 
    881     emu_memory_read_string(emu_memory_get(env->emu), cmdline_ptr, cmdstr, 256); 
    882         printf("WinExec %s\n", emu_string_char(cmdstr)); 
    883         emu_string_free(cmdstr); 
     933        emu_profile_argument_add_int(env->profile, "UINT", "uCmdShow", show); 
     934         
     935 
     936 
    884937 
    885938        emu_cpu_reg32_set(c, eax, 32); 
  • libemu/trunk/src/environment/win32/env_w32_dll_export_urlmon_hooks.c

    r1367 r1505  
    4141#include "emu/emu_hashtable.h" 
    4242#include "emu/emu_string.h" 
     43#include "emu/environment/emu_profile.h" 
    4344#include "emu/environment/win32/emu_env_w32.h" 
    4445#include "emu/environment/win32/emu_env_w32_dll.h" 
     
    6667); 
    6768*/ 
     69        emu_profile_function_add(env->profile, "URLDownloadToFile"); 
     70 
    6871        uint32_t p_caller; 
    6972        POP_DWORD(c, &p_caller); 
     73        emu_profile_argument_add_ref(env->profile, "LPUNKNOWN", "pCaller", p_caller); 
     74        emu_profile_argument_add_string(env->profile, "", "", "");  
    7075 
    7176        uint32_t p_url; 
    7277        POP_DWORD(c, &p_url); 
     78        emu_profile_argument_add_ref(env->profile, "LPCTSTR", "szURL", p_url); 
     79 
     80    struct emu_string *url = emu_string_new(); 
     81        emu_memory_read_string(c->mem, p_url, url, 512); 
     82        emu_profile_argument_add_string(env->profile, "", "", emu_string_char(url));  
     83 
    7384 
    7485        uint32_t p_filename; 
    7586        POP_DWORD(c, &p_filename); 
     87        emu_profile_argument_add_ref(env->profile, "LPCTSTR", "szFileName", p_filename); 
     88 
     89        struct emu_string *filename = emu_string_new(); 
     90        emu_memory_read_string(c->mem, p_filename, filename, 512); 
     91        emu_profile_argument_add_string(env->profile, "", "", emu_string_char(filename));  
    7692 
    7793        uint32_t reserved; 
    7894        POP_DWORD(c, &reserved); 
     95        emu_profile_argument_add_int(env->profile, "DWORD", "dwReserved", reserved); 
    7996 
    8097        uint32_t statuscallbackfn; 
    8198        POP_DWORD(c, &statuscallbackfn); 
     99        emu_profile_argument_add_int(env->profile, "LPBINDSTATUSCALLBACK", "lpfnCB", statuscallbackfn); 
    82100 
    83101 
    84102 
    85         struct emu_string *url = emu_string_new(); 
    86         emu_memory_read_string(c->mem, p_url, url, 512); 
    87  
    88         struct emu_string *filename = emu_string_new(); 
    89         emu_memory_read_string(c->mem, p_filename, filename, 512); 
    90103 
    91104 
    92         printf(" %s -> %s\n", emu_string_char(url), emu_string_char(filename)); 
     105 
     106//      printf(" %s -> %s\n", emu_string_char(url), emu_string_char(filename)); 
    93107 
    94108        emu_string_free(url); 
  • libemu/trunk/src/environment/win32/env_w32_dll_export_ws2_32_hooks.c

    r1367 r1505  
    4848#include "emu/emu_hashtable.h" 
    4949#include "emu/emu_string.h" 
     50#include "emu/environment/emu_profile.h" 
    5051#include "emu/environment/win32/emu_env_w32.h" 
    5152#include "emu/environment/win32/emu_env_w32_dll.h" 
     
    5556int32_t env_w32_hook_accept(struct emu_env_w32 *env, struct emu_env_w32_dll_export *ex) 
    5657{ 
    57         printf("Hook me Captain Cook!\n"); 
    58         printf("%s:%i %s\n",__FILE__,__LINE__,__FUNCTION__); 
    59  
    6058        struct emu_cpu *c = emu_cpu_get(env->emu); 
    6159 
     
    7068);*/ 
    7169 
    72         uint32_t s; 
    73         POP_DWORD(c, &s); 
     70        emu_profile_function_add(env->profile, "accept"); 
     71 
     72        uint32_t s; 
     73        POP_DWORD(c, &s); 
     74        emu_profile_argument_add_int(env->profile, "SOCKET", "s", s); 
    7475 
    7576        uint32_t addr; 
    7677        POP_DWORD(c, &addr); 
     78        emu_profile_argument_add_ref(env->profile, "sockaddr *", "addr", addr); 
     79        emu_profile_argument_start(env->profile, "", ""); 
     80        emu_profile_argument_end(env->profile); 
    7781 
    7882        uint32_t addrlen; 
    7983        POP_DWORD(c, &addrlen); 
     84        emu_profile_argument_add_ref(env->profile, "int", "addrlen", addrlen); 
     85        emu_profile_argument_add_int(env->profile, "", "", 0); 
    8086 
    8187        printf("accept(s=%i, addr=%x, addrlen=%i);\n", s, addr, addrlen); 
     
    98104int32_t env_w32_hook_bind(struct emu_env_w32 *env, struct emu_env_w32_dll_export *ex) 
    99105{ 
    100         printf("Hook me Captain Cook!\n"); 
    101         printf("%s:%i %s\n",__FILE__,__LINE__,__FUNCTION__); 
    102  
    103106        struct emu_cpu *c = emu_cpu_get(env->emu); 
    104107 
     
    112115  const struct sockaddr* name, 
    113116  int namelen 
    114 ); */ 
    115  
    116         uint32_t s; 
    117         POP_DWORD(c, &s); 
     117);  
     118*/ 
     119 
     120        emu_profile_function_add(env->profile, "bind"); 
     121        uint32_t s; 
     122        POP_DWORD(c, &s); 
     123 
    118124 
    119125        uint32_t name; 
    120126        POP_DWORD(c, &name); 
    121127         
    122         uint32_t namelen; 
    123         POP_DWORD(c, &namelen); 
    124  
    125         printf("bind(s=%i, name=%x, namelen=%i\n", s, name, namelen); 
    126  
     128         
     129 
     130/* 
     131struct sockaddr_in { 
     132    short            sin_family;   // e.g. AF_INET 
     133    unsigned short   sin_port;     // e.g. htons(3490) 
     134    struct in_addr   sin_addr;     // see struct in_addr, below 
     135    char             sin_zero[8];  // zero this if you want to 
     136}; 
     137 
     138struct in_addr { 
     139    unsigned long s_addr;  // load with inet_aton() 
     140}; 
     141*/ 
    127142        struct sockaddr sa; 
     143         
    128144        emu_memory_read_block(emu_memory_get(env->emu), name, &sa, sizeof(struct sockaddr)); 
    129145        if (sa.sa_family == AF_INET) 
    130146        { 
    131                 printf("host %s port %i\n",  
    132                    inet_ntoa(*(struct in_addr *)&((struct sockaddr_in *)&sa)->sin_addr), 
    133                    ntohs(((struct sockaddr_in *)&sa)->sin_port)); 
     147                struct sockaddr_in *si = (struct sockaddr_in *)&sa; 
     148                emu_profile_argument_add_ref(env->profile, "sockaddr_in *", "name", name); 
     149                emu_profile_argument_start(env->profile, "", ""); 
     150                emu_profile_argument_add_int(env->profile, "short", "sin_family", si->sin_family); 
     151                emu_profile_argument_add_port(env->profile, "unsigned short", "sin_port", si->sin_port); 
     152                emu_profile_argument_start(env->profile, "in_addr", "sin_addr"); 
     153                emu_profile_argument_add_ip(env->profile, "unsigned long", "s_addr", si->sin_addr.s_addr); 
     154                emu_profile_argument_end(env->profile); 
     155                emu_profile_argument_add_string(env->profile, "char", "sin_zero", "       "); 
     156                emu_profile_argument_end(env->profile); 
     157 
     158        }else 
     159        { 
     160                emu_profile_argument_start(env->profile, "sockaddr *", "name"); 
     161                emu_profile_argument_end(env->profile); 
    134162        } 
     163 
     164 
     165 
     166        uint32_t namelen; 
     167        POP_DWORD(c, &namelen); 
     168 
     169        printf("bind(s=%i, name=%x, namelen=%i\n", s, name, namelen); 
     170 
    135171 
    136172        int retval = 0; 
     
    162198); 
    163199*/ 
    164         uint32_t s; 
    165         POP_DWORD(c, &s); 
     200        emu_profile_function_add(env->profile, "closesocket"); 
     201        uint32_t s; 
     202        POP_DWORD(c, &s); 
     203        emu_profile_argument_add_int(env->profile, "SOCKET", "s", s); 
    166204 
    167205#ifdef HAVE_INTERACTIVE_HOOKS 
     
    194232) 
    195233*/ 
    196         uint32_t s; 
    197         POP_DWORD(c, &s); 
     234        emu_profile_function_add(env->profile, "connect"); 
     235        uint32_t s; 
     236        POP_DWORD(c, &s); 
     237        emu_profile_argument_add_int(env->profile, "SOCKET", "s", s); 
    198238 
    199239        uint32_t name; 
    200240        POP_DWORD(c, &name); 
     241        struct sockaddr sa; 
     242 
     243        emu_memory_read_block(emu_memory_get(env->emu), name, &sa, sizeof(struct sockaddr)); 
     244        if (sa.sa_family == AF_INET) 
     245        { 
     246                struct sockaddr_in *si = (struct sockaddr_in *)&sa; 
     247                emu_profile_argument_add_ref(env->profile, "sockaddr_in *", "name", name); 
     248                emu_profile_argument_start(env->profile, "", ""); 
     249                emu_profile_argument_add_int(env->profile, "short", "sin_family", si->sin_family); 
     250                emu_profile_argument_add_port(env->profile, "unsigned short", "sin_port", si->sin_port); 
     251                emu_profile_argument_start(env->profile, "in_addr", "sin_addr"); 
     252                emu_profile_argument_add_ip(env->profile, "unsigned long", "s_addr", si->sin_addr.s_addr); 
     253                emu_profile_argument_end(env->profile); 
     254                emu_profile_argument_add_string(env->profile, "char", "sin_zero", "       "); 
     255                emu_profile_argument_end(env->profile); 
     256 
     257        }else 
     258        { 
     259                emu_profile_argument_start(env->profile, "sockaddr *", "name"); 
     260                emu_profile_argument_end(env->profile); 
     261        } 
    201262 
    202263        uint32_t namelen; 
    203264        POP_DWORD(c, &namelen); 
    204  
    205         struct sockaddr sa; 
    206         emu_memory_read_block(emu_memory_get(env->emu), name, &sa, sizeof(struct sockaddr)); 
    207         printf("host %s port %i\n",  
    208                    inet_ntoa(*(struct in_addr *)&((struct sockaddr_in *)&sa)->sin_addr), 
    209                    ntohs(((struct sockaddr_in *)&sa)->sin_port)); 
    210  
     265        emu_profile_argument_add_int(env->profile, "int", "namelen", namelen); 
    211266 
    212267        int retval = 0; 
     
    242297); 
    243298*/ 
    244  
    245         uint32_t s; 
    246         POP_DWORD(c, &s); 
     299        emu_profile_function_add(env->profile, "listen"); 
     300 
     301 
     302        uint32_t s; 
     303        POP_DWORD(c, &s); 
     304        emu_profile_argument_add_int(env->profile, "SOCKET", "s", s); 
    247305 
    248306        uint32_t backlog; 
    249307        POP_DWORD(c, &backlog); 
     308        emu_profile_argument_add_int(env->profile, "int", "backlog", backlog); 
    250309 
    251310        printf("listen(s=%i,  backlog=%i)\n", s,  backlog); 
     
    477536); */ 
    478537 
     538        emu_profile_function_add(env->profile, "WSASocket"); 
     539 
    479540        uint32_t af; 
    480541        POP_DWORD(c, &af); 
     542        emu_profile_argument_add_int(env->profile, "int", "af", af); 
     543 
     544 
    481545 
    482546        uint32_t type; 
    483547        POP_DWORD(c, &type); 
     548        emu_profile_argument_add_int(env->profile, "int", "type", type); 
    484549 
    485550        uint32_t protocol; 
    486551        POP_DWORD(c, &protocol); 
     552        emu_profile_argument_add_int(env->profile, "int", "protocol", protocol); 
    487553 
    488554        uint32_t protocolinfo; 
    489555        POP_DWORD(c, &protocolinfo); 
     556        emu_profile_argument_add_int(env->profile, "LPWSAPROTOCOL_INFO", "lpProtocolInfo", protocolinfo); 
     557 
    490558 
    491559        uint32_t group; 
    492560        POP_DWORD(c, &group); 
     561        emu_profile_argument_add_int(env->profile, "GROUP", "g", group); 
     562 
    493563 
    494564        uint32_t flags; 
    495565        POP_DWORD(c, &flags); 
     566        emu_profile_argument_add_int(env->profile, "DWORD", "dwFlags", flags); 
     567 
    496568 
    497569        printf("SOCKET WSASocket(af=%i, type=%i, protocol=%i, lpProtocolInfo=%x, group=%i, dwFlags=%i);\n", 
     
    529601); 
    530602*/ 
    531  
     603        emu_profile_function_add(env->profile, "WSAStartup"); 
     604         
    532605        uint32_t wsaversionreq; 
    533606        POP_DWORD(c, &wsaversionreq); 
    534607        printf("WSAStartup version %x\n", wsaversionreq); 
     608        emu_profile_argument_add_int(env->profile, "WORD", "wVersionRequested", wsaversionreq); 
    535609 
    536610        uint32_t wsadata; 
    537611        POP_DWORD(c, &wsadata); 
     612        emu_profile_argument_add_int(env->profile, "LPWSADATA", "lpWSAData", wsadata); 
    538613 
    539614