-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwrapwininet.cpp
46 lines (35 loc) · 1.78 KB
/
wrapwininet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "headers\wrapwininet.h"
#include "headers\utilities.h"
static void wrapInternetConnectW(void *wrapcxt, OUT void **user_data)
{
THREAD_STATE *thread = (THREAD_STATE *)drmgr_get_tls_field(dr_get_current_drcontext(), traceClientptr->tls_idx);
LPCWSTR path = (LPCWSTR)drwrap_get_arg(wrapcxt, 1);
DWORD port = (DWORD)drwrap_get_arg(wrapcxt, 2);
b64_wstring_arg(path, thread->stringbuf);
dr_fprintf(thread->f, "ARG,%d,"ADDR_FMT","ADDR_FMT",M,1,%s@", 1, drwrap_get_func(wrapcxt), thread->sourceInstruction, thread->stringbuf);
dr_fprintf(thread->f, "ARG,%d,"ADDR_FMT","ADDR_FMT",E,0,%d@", 2, drwrap_get_func(wrapcxt), thread->sourceInstruction, port);
}
static void wrapHTTPOpenReqW(void *wrapcxt, OUT void **user_data)
{
THREAD_STATE *thread = (THREAD_STATE *)drmgr_get_tls_field(dr_get_current_drcontext(), traceClientptr->tls_idx);
LPCWSTR verb = (LPCWSTR)drwrap_get_arg(wrapcxt, 1);
LPCWSTR objname = (LPCWSTR)drwrap_get_arg(wrapcxt, 2);
if (!verb)
dr_fprintf(thread->f, "ARG,%d,"ADDR_FMT","ADDR_FMT",M,0,%s@", 1, drwrap_get_func(wrapcxt), thread->sourceInstruction, "GET");
else
{
b64_wstring_arg(verb, thread->stringbuf);
dr_fprintf(thread->f, "ARG,%d,"ADDR_FMT","ADDR_FMT",M,1,%s@", 1, drwrap_get_func(wrapcxt), thread->sourceInstruction, thread->stringbuf);
}
b64_wstring_arg(objname, thread->stringbuf);
dr_fprintf(thread->f, "ARG,%d,"ADDR_FMT","ADDR_FMT",E,1,%s@", 2, drwrap_get_func(wrapcxt), thread->sourceInstruction, thread->stringbuf);
}
void wrap_wininet(module_handle_t handle)
{
app_pc towrap = (app_pc)dr_get_proc_address(handle, "InternetConnectW");
if (towrap != NULL)
drwrap_wrap(towrap, wrapInternetConnectW, NULL);
towrap = (app_pc)dr_get_proc_address(handle, "HttpOpenRequestW");
if (towrap != NULL)
drwrap_wrap(towrap, wrapHTTPOpenReqW, NULL);
}