Changeset 1526
- Timestamp:
- 01/15/08 14:33:04 (8 months ago)
- Files:
-
- libemu/trunk/include/emu/environment/emu_profile.h (modified) (3 diffs)
- libemu/trunk/include/emu/environment/linux/emu_env_linux.h (modified) (2 diffs)
- libemu/trunk/src/environment/emu_profile.c (modified) (5 diffs)
- libemu/trunk/src/environment/linux/emu_env_linux.c (modified) (3 diffs)
- libemu/trunk/src/environment/linux/env_linux_syscall_hooks.c (modified) (9 diffs)
- libemu/trunk/src/environment/win32/env_w32_dll_export_ws2_32_hooks.c (modified) (1 diff)
- libemu/trunk/testsuite/sctest.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libemu/trunk/include/emu/environment/emu_profile.h
r1507 r1526 42 42 render_string, 43 43 render_ip, 44 render_port 44 render_port, 45 render_array 45 46 }; 46 47 … … 64 65 emu_profile_argument_root *arguments; 65 66 } tstruct; 67 66 68 struct 67 69 { … … 119 121 void emu_profile_argument_add_ip(struct emu_profile *profile, char *argtype, char *argname, uint32_t value); 120 122 void emu_profile_argument_add_port(struct emu_profile *profile, char *argtype, char *argname, uint32_t value); 123 void emu_profile_argument_array_start(struct emu_profile* profile, const char* arraytype, const char* arrayname); 124 void emu_profile_argument_array_end(struct emu_profile *profile); 125 121 126 122 127 void emu_profile_function_add(struct emu_profile *profile, char *fnname); libemu/trunk/include/emu/environment/linux/emu_env_linux.h
r1507 r1526 39 39 #include "emu/emu_hashtable.h" 40 40 41 struct emu_profile; 41 42 42 43 struct emu_env_linux … … 45 46 struct emu_hashtable *syscall_hooks_by_name; 46 47 struct emu_env_linux_syscall *syscall_hooks; 48 struct emu_profile *profile; 47 49 }; 48 50 libemu/trunk/src/environment/emu_profile.c
r1507 r1526 101 101 // printf("%s %s\n", __PRETTY_FUNCTION__, structname); 102 102 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); 108 104 emu_stack_push(profile->argument_stack, argument); 109 105 } … … 113 109 { 114 110 // printf("%s %s\n", __PRETTY_FUNCTION__); 111 emu_stack_pop(profile->argument_stack); 112 } 113 114 void 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 121 void emu_profile_argument_array_end(struct emu_profile *profile) 122 { 115 123 emu_stack_pop(profile->argument_stack); 116 124 } … … 203 211 argument->render = render; 204 212 205 if (render == render_struct )213 if (render == render_struct || render == render_array) 206 214 { 207 215 argument->value.tstruct.arguments = emu_profile_arguments_create(); … … 236 244 break; 237 245 246 case render_array: 238 247 case render_struct: 239 248 { … … 279 288 280 289 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)); 281 301 break; 282 302 libemu/trunk/src/environment/linux/emu_env_linux.c
r1507 r1526 31 31 32 32 33 #include "emu/environment/emu_profile.h" 33 34 #include "emu/environment/linux/emu_env_linux.h" 34 35 #include "emu/environment/linux/env_linux_syscalls.h" … … 52 53 } 53 54 55 eel->profile = emu_profile_new(); 56 54 57 return eel; 55 58 } … … 60 63 emu_hashtable_free(eel->syscall_hooks_by_name); 61 64 free(eel->syscall_hooks); 65 emu_profile_free(eel->profile); 62 66 free(eel); 63 67 } libemu/trunk/src/environment/linux/env_linux_syscall_hooks.c
r1476 r1526 38 38 #include "emu/emu_memory.h" 39 39 #include "emu/emu_string.h" 40 40 #include "emu/environment/emu_profile.h" 41 41 #include "emu/environment/linux/emu_env_linux.h" 42 42 … … 45 45 printf("sys_exit(2)\n"); 46 46 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 47 50 emu_cpu_reg32_set(c, eax, 0); 48 51 return 0; … … 53 56 printf("sys_fork(2)\n"); 54 57 struct emu_cpu *c = emu_cpu_get(env->emu); 58 emu_profile_function_add(env->profile, "fork"); 55 59 emu_cpu_reg32_set(c, eax, 4711); 56 60 return 0; … … 59 63 int32_t env_linux_hook_execve(struct emu_env_linux *env, struct emu_env_linux_syscall *syscall) 60 64 { 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]); 62 71 struct emu_string *name = emu_string_new(); 63 72 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 64 105 printf("int execve (const char *dateiname=%08x={%s}, const char * argv[], const char *envp[]);\n", 65 106 c->reg[ebx], 66 107 emu_string_char(name)); 108 109 67 110 emu_string_free(name); 68 111 return 0; … … 75 118 76 119 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 77 124 emu_cpu_reg32_set(c, eax, c->reg[ecx]); 78 125 return 0; … … 105 152 a[1], 106 153 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 107 159 emu_cpu_reg32_set(c, eax, 4); 108 160 break; … … 110 162 case 2: // SYS_BIND 111 163 { 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 /* 116 166 printf("int bind(int sockfd=%i, struct sockaddr *my_addr=%08x={host %s port %i}, int addrlen);\n", 117 167 a[0], 118 168 a[1], inet_ntoa(*(struct in_addr *)&((struct sockaddr_in *)&sa)->sin_addr), ntohs(((struct sockaddr_in *)&sa)->sin_port) 119 169 ); 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 126 176 struct sockaddr sa; 127 177 memset(&sa, 0, sizeof(struct sockaddr)); 128 178 emu_memory_read_block(emu_memory_get(c->emu), a[1], &sa, sizeof(struct sockaddr)); 129 179 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 134 244 135 245 } … … 140 250 a[0], 141 251 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]); 142 255 break; 143 256 … … 147 260 a[1], 148 261 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 149 277 emu_cpu_reg32_set(c, eax, 112); 150 278 break; libemu/trunk/src/environment/win32/env_w32_dll_export_ws2_32_hooks.c
r1507 r1526 155 155 uint32_t namelen; 156 156 POP_DWORD(c, &namelen); 157 emu_profile_argument_add_int(env->profile, "int", "namelen", namelen); 157 158 158 159 printf("bind(s=%i, name=%x, namelen=%i\n", s, name, namelen); libemu/trunk/testsuite/sctest.c
r1508 r1526 55 55 #ifdef HAVE_LIBCARGOS 56 56 #include <cargos-lib.h> 57 #include <cargos-lib-static.h>58 57 #endif 59 58 … … 1879 1878 1880 1879 emu_profile_debug(env->profile); 1880 emu_profile_debug(lenv->profile); 1881 1881 1882 1882 emu_env_w32_free(env); 1883 1883 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); 1886 1890 return 0; 1887 1891 } … … 2269 2273 int static_offset = CODE_OFFSET; 2270 2274 emu_memory_write_block(mem, static_offset, opts.scode, opts.size); 2271 2275 2272 2276 2273 2277 … … 2275 2279 emu_cpu_eip_set(emu_cpu_get(e), static_offset); 2276 2280 2281 emu_cpu_reg32_set(emu_cpu_get(e), esp, 0x0012fe98); 2282 2283 free(opts.scode); 2277 2284 return 0; 2278 2285
