Changeset 1526

Show
Ignore:
Timestamp:
01/15/08 14:33:04 (8 months ago)
Author:
common
Message:

libemu

  • introduce render_array, required for arrays (used in execve() on linux), emu_profile_argument_array_start & emu_profile_argument_array_end
  • profile alle required calls on linux
  • some minor fixes in sctest
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libemu/trunk/include/emu/environment/emu_profile.h

    r1507 r1526  
    4242        render_string, 
    4343        render_ip, 
    44         render_port 
     44        render_port, 
     45        render_array 
    4546}; 
    4647 
     
    6465                        emu_profile_argument_root *arguments; 
    6566                } tstruct; 
     67 
    6668                struct 
    6769                { 
     
    119121void emu_profile_argument_add_ip(struct emu_profile *profile, char *argtype,  char *argname, uint32_t value); 
    120122void emu_profile_argument_add_port(struct emu_profile *profile, char *argtype,  char *argname, uint32_t value); 
     123void emu_profile_argument_array_start(struct emu_profile* profile, const char* arraytype, const char* arrayname); 
     124void emu_profile_argument_array_end(struct emu_profile *profile); 
     125 
    121126 
    122127void emu_profile_function_add(struct emu_profile *profile, char *fnname); 
  • libemu/trunk/include/emu/environment/linux/emu_env_linux.h

    r1507 r1526  
    3939#include "emu/emu_hashtable.h" 
    4040 
     41struct emu_profile; 
    4142 
    4243struct emu_env_linux 
     
    4546        struct emu_hashtable *syscall_hooks_by_name; 
    4647        struct emu_env_linux_syscall *syscall_hooks; 
     48        struct emu_profile *profile; 
    4749}; 
    4850 
  • libemu/trunk/src/environment/emu_profile.c

    r1507 r1526  
    101101//      printf("%s %s\n", __PRETTY_FUNCTION__,  structname); 
    102102        struct emu_profile_argument *argument = emu_profile_argument_new(render_struct, structtype, structname); 
    103  
    104  
    105  
    106         emu_profile_argument_add(profile, argument); 
    107  
     103        emu_profile_argument_add(profile, argument); 
    108104        emu_stack_push(profile->argument_stack, argument); 
    109105} 
     
    113109{ 
    114110//      printf("%s %s\n", __PRETTY_FUNCTION__); 
     111        emu_stack_pop(profile->argument_stack); 
     112} 
     113 
     114void emu_profile_argument_array_start(struct emu_profile* profile, const char* arraytype, const char* arrayname) 
     115{ 
     116        struct emu_profile_argument *argument = emu_profile_argument_new(render_array, arraytype, arrayname); 
     117        emu_profile_argument_add(profile, argument); 
     118        emu_stack_push(profile->argument_stack, argument); 
     119} 
     120 
     121void emu_profile_argument_array_end(struct emu_profile *profile) 
     122{ 
    115123        emu_stack_pop(profile->argument_stack); 
    116124} 
     
    203211        argument->render = render; 
    204212 
    205         if (render == render_struct
     213        if (render == render_struct || render == render_array
    206214        { 
    207215                argument->value.tstruct.arguments = emu_profile_arguments_create(); 
     
    236244                break; 
    237245 
     246        case render_array: 
    238247        case render_struct: 
    239248                { 
     
    279288 
    280289                printf("%s };\n", indents(indent)); 
     290                break; 
     291 
     292        case render_array: 
     293                printf("%s %s %s = [\n", indents(indent), argument->argtype, argument->argname); 
     294                for (argumentit = emu_profile_arguments_first(argument->value.tstruct.arguments);  
     295                          !emu_profile_arguments_istail(argumentit);  
     296                          argumentit = emu_profile_arguments_next(argumentit)) 
     297                { 
     298                        emu_profile_argument_debug(argumentit,indent+1); 
     299                } 
     300                printf("%s ];\n", indents(indent)); 
    281301                break; 
    282302 
  • libemu/trunk/src/environment/linux/emu_env_linux.c

    r1507 r1526  
    3131 
    3232 
     33#include "emu/environment/emu_profile.h" 
    3334#include "emu/environment/linux/emu_env_linux.h" 
    3435#include "emu/environment/linux/env_linux_syscalls.h" 
     
    5253        } 
    5354 
     55        eel->profile = emu_profile_new(); 
     56 
    5457        return eel; 
    5558} 
     
    6063        emu_hashtable_free(eel->syscall_hooks_by_name); 
    6164        free(eel->syscall_hooks); 
     65        emu_profile_free(eel->profile); 
    6266        free(eel); 
    6367} 
  • libemu/trunk/src/environment/linux/env_linux_syscall_hooks.c

    r1476 r1526  
    3838#include "emu/emu_memory.h" 
    3939#include "emu/emu_string.h" 
    40  
     40#include "emu/environment/emu_profile.h" 
    4141#include "emu/environment/linux/emu_env_linux.h" 
    4242 
     
    4545        printf("sys_exit(2)\n"); 
    4646        struct emu_cpu *c = emu_cpu_get(env->emu); 
     47        emu_profile_function_add(env->profile, "exit"); 
     48        emu_profile_argument_add_ptr(env->profile, "int", "status", c->reg[ebx]); 
     49 
    4750        emu_cpu_reg32_set(c, eax, 0); 
    4851        return 0; 
     
    5356        printf("sys_fork(2)\n"); 
    5457        struct emu_cpu *c = emu_cpu_get(env->emu); 
     58        emu_profile_function_add(env->profile, "fork"); 
    5559        emu_cpu_reg32_set(c, eax, 4711); 
    5660        return 0; 
     
    5963int32_t env_linux_hook_execve(struct emu_env_linux *env, struct emu_env_linux_syscall *syscall) 
    6064{ 
    61         struct emu_cpu *c = emu_cpu_get(env->emu); 
     65        printf("execve\n"); 
     66        struct emu_cpu *c = emu_cpu_get(env->emu); 
     67 
     68        emu_profile_function_add(env->profile, "execve"); 
     69 
     70        emu_profile_argument_add_ptr(env->profile, "const char *", "dateiname", c->reg[ebx]); 
    6271        struct emu_string *name = emu_string_new(); 
    6372        emu_memory_read_string(emu_memory_get(c->emu), c->reg[ebx], name, 255); 
     73        emu_profile_argument_add_string(env->profile, "", "", emu_string_char(name)); 
     74//      emu_profile_argument_add_ptr(env->profile, "", "", c->reg[ecx]); 
     75        emu_profile_argument_array_start(env->profile, "const char *", "argv[]"); 
     76 
     77        uint32_t p_array = c->reg[ecx]; 
     78        uint32_t p_arg = -1; 
     79        emu_memory_read_dword(emu_memory_get(c->emu), p_array, &p_arg); 
     80        int i=1; 
     81        while (p_arg != 0) 
     82        { 
     83                emu_profile_argument_add_ptr(env->profile, "", "", p_array+((i-1)*4)); 
     84                emu_profile_argument_add_ptr(env->profile, "", "", p_arg); 
     85 
     86                struct emu_string *arg = emu_string_new(); 
     87                emu_memory_read_string(emu_memory_get(c->emu), p_arg, arg, 128); 
     88                emu_profile_argument_add_string(env->profile, "", "", emu_string_char(arg)); 
     89                emu_string_free(arg); 
     90                emu_memory_read_dword(emu_memory_get(c->emu), p_array+(i*4), &p_arg); 
     91                i++; 
     92        } 
     93        emu_profile_argument_add_ptr(env->profile, "", "", p_arg); 
     94        emu_profile_argument_add_none(env->profile); 
     95 
     96//      printf("arg is %s\n", emu_string_char(arg)); 
     97 
     98 
     99        emu_profile_argument_array_end(env->profile); 
     100 
     101    emu_profile_argument_add_ptr(env->profile, "const char *", "envp[]", c->reg[edx]); 
     102        emu_profile_argument_add_none(env->profile); 
     103 
     104 
    64105        printf("int execve (const char *dateiname=%08x={%s}, const char * argv[], const char *envp[]);\n",  
    65106                   c->reg[ebx], 
    66107                   emu_string_char(name)); 
     108 
     109 
    67110        emu_string_free(name); 
    68111        return 0; 
     
    75118 
    76119        printf("int dup2(int oldfd=%i, int newfd=%i);\n", c->reg[ebx], c->reg[ecx]); 
     120        emu_profile_function_add(env->profile, "dup2"); 
     121        emu_profile_argument_add_int(env->profile, "int", "oldfd", c->reg[ebx]); 
     122        emu_profile_argument_add_int(env->profile, "int", "newfd", c->reg[ecx]); 
     123 
    77124        emu_cpu_reg32_set(c, eax, c->reg[ecx]); 
    78125        return 0; 
     
    105152                           a[1], 
    106153                           a[2]); 
     154                emu_profile_function_add(env->profile, "socket"); 
     155                emu_profile_argument_add_int(env->profile, "int", "domain",     a[0]); 
     156                emu_profile_argument_add_int(env->profile, "int", "type",               a[1]); 
     157                emu_profile_argument_add_int(env->profile, "int", "protocol",   a[2]); 
     158 
    107159                emu_cpu_reg32_set(c, eax, 4); 
    108160                break; 
     
    110162        case 2: // SYS_BIND  
    111163                { 
    112                         struct sockaddr sa; 
    113                         memset(&sa, 0, sizeof(struct sockaddr)); 
    114                         emu_memory_read_block(emu_memory_get(c->emu), a[1], &sa, sizeof(struct sockaddr)); 
    115  
     164 
     165/* 
    116166                        printf("int bind(int sockfd=%i, struct sockaddr *my_addr=%08x={host %s port %i}, int addrlen);\n", 
    117167                                   a[0], 
    118168                                   a[1], inet_ntoa(*(struct in_addr *)&((struct sockaddr_in *)&sa)->sin_addr), ntohs(((struct sockaddr_in *)&sa)->sin_port)  
    119169                                  ); 
    120                 } 
    121                 emu_cpu_reg32_set(c, eax, 0); 
    122                 break; 
    123  
    124         case 3: // SYS_CONNECT  
    125                 { 
     170*/ 
     171                       emu_profile_function_add(env->profile, "bind"); 
     172 
     173                        emu_profile_argument_add_int(env->profile, "int", "sockfd", a[0]); 
     174 
     175 
    126176                        struct sockaddr sa; 
    127177                        memset(&sa, 0, sizeof(struct sockaddr)); 
    128178                        emu_memory_read_block(emu_memory_get(c->emu), a[1], &sa, sizeof(struct sockaddr)); 
    129179 
    130                         printf("int connect(int sockfd=%i, struct sockaddr *my_addr=%08x={host %s port %i}, int addrlen);\n", 
    131                                    a[0], 
    132                                    a[1], inet_ntoa(*(struct in_addr *)&((struct sockaddr_in *)&sa)->sin_addr), ntohs(((struct sockaddr_in *)&sa)->sin_port) 
    133                                   ); 
     180                        if ( sa.sa_family == AF_INET ) 
     181                        { 
     182                                struct sockaddr_in *si = (struct sockaddr_in *)&sa; 
     183                                emu_profile_argument_add_ptr(env->profile, "sockaddr_in *", "my_addr", a[1]); 
     184                                emu_profile_argument_struct_start(env->profile, "", ""); 
     185                                emu_profile_argument_add_int(env->profile, "short", "sin_family", si->sin_family); 
     186                                emu_profile_argument_add_port(env->profile, "unsigned short", "sin_port", si->sin_port); 
     187                                emu_profile_argument_struct_start(env->profile, "in_addr", "sin_addr"); 
     188                                emu_profile_argument_add_ip(env->profile, "unsigned long", "s_addr", si->sin_addr.s_addr); 
     189                                emu_profile_argument_struct_end(env->profile); 
     190                                emu_profile_argument_add_string(env->profile, "char", "sin_zero", "       "); 
     191                                emu_profile_argument_struct_end(env->profile); 
     192 
     193                        } 
     194                        else 
     195                        { 
     196                                emu_profile_argument_add_ptr(env->profile, "sockaddr *", "my_addr", a[1]); 
     197                                emu_profile_argument_struct_start(env->profile, "", ""); 
     198                                emu_profile_argument_struct_end(env->profile); 
     199                        } 
     200 
     201 
     202 
     203                        emu_profile_argument_add_int(env->profile, "int", "addrlen", a[2]); 
     204 
     205 
     206                } 
     207                emu_cpu_reg32_set(c, eax, 0); 
     208                break; 
     209 
     210        case 3: // SYS_CONNECT  
     211                { 
     212 
     213                        printf("connect\n"); 
     214                        emu_profile_function_add(env->profile, "connect"); 
     215                        emu_profile_argument_add_int(env->profile, "int", "sockfd", a[0]); 
     216 
     217                        struct sockaddr sa; 
     218                        memset(&sa, 0, sizeof(struct sockaddr)); 
     219                        emu_memory_read_block(emu_memory_get(c->emu), a[1], &sa, sizeof(struct sockaddr)); 
     220 
     221                        if (sa.sa_family == AF_INET) 
     222                        { 
     223                                struct sockaddr_in *si = (struct sockaddr_in *)&sa; 
     224                                emu_profile_argument_add_ptr(env->profile, "sockaddr_in *", "serv_addr", a[1]); 
     225                                emu_profile_argument_struct_start(env->profile, "", ""); 
     226                                emu_profile_argument_add_int(env->profile, "short", "sin_family", si->sin_family); 
     227                                emu_profile_argument_add_port(env->profile, "unsigned short", "sin_port", si->sin_port); 
     228                                emu_profile_argument_struct_start(env->profile, "in_addr", "sin_addr"); 
     229                                emu_profile_argument_add_ip(env->profile, "unsigned long", "s_addr", si->sin_addr.s_addr); 
     230                                emu_profile_argument_struct_end(env->profile); 
     231                                emu_profile_argument_add_string(env->profile, "char", "sin_zero", "       "); 
     232                                emu_profile_argument_struct_end(env->profile); 
     233 
     234                        }else 
     235                        { 
     236 
     237                                emu_profile_argument_add_ptr(env->profile, "sockaddr *", "serv_addr", a[1]); 
     238                                emu_profile_argument_struct_start(env->profile, "", ""); 
     239                                emu_profile_argument_struct_end(env->profile); 
     240                        } 
     241 
     242                        emu_profile_argument_add_int(env->profile, "int", "addrlen", a[2]); 
     243 
    134244 
    135245                } 
     
    140250                           a[0],  
    141251                           a[1]); 
     252                emu_profile_function_add(env->profile, "listen"); 
     253                emu_profile_argument_add_int(env->profile, "int", "s", a[0]); 
     254                emu_profile_argument_add_int(env->profile, "int", "backlog", a[1]); 
    142255                break; 
    143256 
     
    147260                           a[1], 
    148261                           a[2]); 
     262 
     263                emu_profile_function_add(env->profile, "accept"); 
     264                emu_profile_argument_add_int(env->profile, "int", "sockfd", a[0]); 
     265 
     266                struct sockaddr sa; 
     267                memset(&sa, 0, sizeof(struct sockaddr)); 
     268                emu_memory_read_block(emu_memory_get(c->emu), a[1], &sa, sizeof(struct sockaddr)); 
     269 
     270                emu_profile_argument_add_ptr(env->profile, "sockaddr_in *", "addr", a[1]); 
     271                emu_profile_argument_add_none(env->profile); 
     272 
     273                emu_profile_argument_add_ptr(env->profile, "int", "addrlen", a[2]); 
     274                emu_profile_argument_add_none(env->profile); 
     275 
     276 
    149277                emu_cpu_reg32_set(c, eax, 112); 
    150278                break; 
  • libemu/trunk/src/environment/win32/env_w32_dll_export_ws2_32_hooks.c

    r1507 r1526  
    155155        uint32_t namelen; 
    156156        POP_DWORD(c, &namelen); 
     157        emu_profile_argument_add_int(env->profile, "int", "namelen", namelen); 
    157158 
    158159        printf("bind(s=%i, name=%x, namelen=%i\n", s, name, namelen); 
  • libemu/trunk/testsuite/sctest.c

    r1508 r1526  
    5555#ifdef HAVE_LIBCARGOS 
    5656#include <cargos-lib.h> 
    57 #include <cargos-lib-static.h> 
    5857#endif 
    5958 
     
    18791878 
    18801879        emu_profile_debug(env->profile); 
     1880        emu_profile_debug(lenv->profile); 
    18811881         
    18821882        emu_env_w32_free(env); 
    18831883        emu_env_linux_free(lenv); 
    1884         emu_hashtable_free(eh); 
    1885         emu_graph_free(graph); 
     1884 
     1885        if (eh != NULL) 
     1886                emu_hashtable_free(eh); 
     1887 
     1888        if (graph != NULL) 
     1889                emu_graph_free(graph); 
    18861890        return 0; 
    18871891} 
     
    22692273        int static_offset = CODE_OFFSET; 
    22702274        emu_memory_write_block(mem, static_offset, opts.scode,  opts.size); 
    2271  
     2275         
    22722276 
    22732277 
     
    22752279        emu_cpu_eip_set(emu_cpu_get(e), static_offset); 
    22762280 
     2281        emu_cpu_reg32_set(emu_cpu_get(e), esp, 0x0012fe98); 
     2282 
     2283        free(opts.scode); 
    22772284        return 0; 
    22782285