首页
社区
课程
招聘
关于在dll中限制post数据次数的问题?
发表于: 2014-7-5 13:40 3306

关于在dll中限制post数据次数的问题?

2014-7-5 13:40
3306
post是用的libcurl,
情况1:放在单独一个exe中测试

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
int WriteToLog(char* str);
void  postdata(int flag)
{
    GetMacAddress(g_strMacAdress);
    USES_CONVERSION;
    char *pMac=T2A(g_strMacAdress);
    char fullAdress[MAX_PATH]={0};
    if(flag==1)
    {
        strcat(fullAdress,"&name=钟欣桐");
    }
    else if(flag==2)
    {
        strcat(fullAdress,"&name=张柏芝");
    }
    else if(flag==3)
    {
        strcat(fullAdress,"&name=陈文媛");
    }
    else if(flag==4)
    {
        strcat(fullAdress,"&name=颜颖思");
    }
    else if(flag==5)
    {
        strcat(fullAdress,"&name=章子怡");
    }
    else
    {
        strcat(fullAdress,“&name=陈冠希”);
    }
    CURL *curl;  
    CURLcode res;  
    //FILE *fptr;  
    struct curl_slist *http_header = NULL;  
  
    //if ((fptr = fopen(FILENAME, "w")) == NULL) {  
    //    fprintf(stderr, "fopen file error: %s\n", FILENAME);  
    //   exit(1);  
    //}  
    curl = curl_easy_init(); 
    if(flag==0)
    {
        curl_easy_setopt(curl, CURLOPT_URL, POSTURL2);  
    }
    else
    {
        curl_easy_setopt(curl, CURLOPT_URL, POSTURL);  
    }
    WriteToLog("post函数内部");
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, fullAdress);  
    curl_easy_setopt(curl, CURLOPT_POST, 1);  
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);  
    curl_easy_setopt(curl, CURLOPT_HEADER, 1);  
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);  
    res = curl_easy_perform(curl);  
    curl_easy_cleanup(curl);  
    WriteToLog("post函数退出");
}
#define LOGFILE "D:\\log.txt"
  
int WriteToLog(char* str)
{
    FILE* log;
    log = fopen(LOGFILE, "a+");
    if (log == NULL){
        OutputDebugString(L"Log file open failed.");
        return -1;
    }
    fprintf(log, "%s\n", str);
    fclose(log);
    return 0;
}
//////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////post部分限制///////////////////////////
//软件是否初次运行增加注册表项
BOOL IsFirstRun()
{
    HKEY hKey;
    LPCTSTR lpRun=_T("Software\\Microsoft\\Windows\\CurrentVersion\\test");
    long lRet = RegOpenKeyEx(HKEY_CURRENT_USER, lpRun, 0, KEY_WRITE, &hKey);
    if(lRet==ERROR_SUCCESS)
    {
        //g_firstrun=false;
        return false;
    }
    else
    {
        //第一次运行
        if(ERROR_SUCCESS==RegCreateKey(HKEY_CURRENT_USER,_T("Software\\Microsoft\\Windows\\CurrentVersion\\test"),&hKey))
        {
            DWORD nCount=1;
            RegSetValueEx(hKey,_T("tj"),0,REG_DWORD,(BYTE*)&nCount,sizeof(DWORD));
            //创建当前时间、日期
            TCHAR szCurrentDataTime[MAX_PATH]={0};
            SYSTEMTIME systm;
            GetLocalTime(&systm);
            wsprintf(szCurrentDataTime,_T("%4d年%d月%d日"),systm.wYear,systm.wMonth,systm.wDay);
            lRet=RegSetValueEx(hKey,L"data",0,REG_SZ,(BYTE*)szCurrentDataTime,/*lstrlen(szCurrentDataTime)*sizeof(TCHAR)*/MAX_PATH);
            if(lRet==ERROR_SUCCESS)
            {
                WriteToLog("成功");
            }
            else
            {
                WriteToLog("失败");
            }
            RegCloseKey(hKey);
            return true;
        }
        else
        {
            return false;
        }
    }
}
  
BOOL tjLimited()
{
    IsFirstRun();
    //创建当前时间、日期
    TCHAR szCurrentDataTime[MAX_PATH]={0};
    SYSTEMTIME systm;
    GetLocalTime(&systm);
    wsprintf(szCurrentDataTime,_T("%4d年%d月%d日"),systm.wYear,systm.wMonth,systm.wDay);
    HKEY hKey;
    TCHAR szData[MAX_PATH]={0};
    DWORD nCount=0;
    DWORD dType=REG_SZ;
    DWORD dTypecount=REG_DWORD;
    DWORD dReturn=MAX_PATH;
    LPCTSTR lpRun=_T("Software\\Microsoft\\Windows\\CurrentVersion\\test");
    long lRet = RegOpenKeyEx(HKEY_CURRENT_USER, lpRun, 0, KEY_WRITE|KEY_READ, &hKey);
    if(lRet==ERROR_SUCCESS)
    {
        //继续下层
        lRet=RegQueryValueEx(hKey,L"tj",NULL,(LPDWORD)(&dTypecount),(LPBYTE)&nCount,&dReturn);
        if(lRet==ERROR_SUCCESS)
        {
            dReturn=MAX_PATH;
            lRet=RegQueryValueEx(hKey,L"data",NULL,&dType,(LPBYTE)szData,&dReturn);
            DWORD n=GetLastError();
            if(lRet==ERROR_SUCCESS)
            {
                //WriteToLog("chenggong");
            }
            else
            {
  
                //WriteToLog("shibai");
            }
            //自增
            ++nCount;
            RegSetValueEx(hKey,L"tj",0,REG_DWORD,(BYTE*)&nCount,sizeof(DWORD));
            if(lstrcmp(szData,szCurrentDataTime))
            {
                WriteToLog("位置2");
                lstrcpy(szData,szCurrentDataTime);
                nCount=0;
                //更新注册表
                DWORD count=2;
                RegSetValueEx(hKey,L"data",0,REG_SZ,(BYTE*)szCurrentDataTime,lstrlen(szCurrentDataTime)*sizeof(TCHAR*));
                RegSetValueEx(hKey,L"tj",0,REG_DWORD,(BYTE*)&count,sizeof(DWORD));
                return true;
            }
            else
            {
                //只判断点击次数
                if(nCount>2)
                {
                    WriteToLog("超过次数啦");
                    return false;
                }
                else
                {
                    ///////////////////////////////////日志打印////////////
                    //char log[10]={0};
                    //sprintf(log,"%d",nCount);
                    //char fulllog[50]={0};
                    //strcpy(fulllog,"post数据");
                    //strcat(fulllog,log);
                    //WriteToLog(fulllog);
                    ////////////////////////////////////////////////////////
                    return true;
                }
            }
  
        }
        else
        {
            //没有内容,进行添加
            //DWORD n=GetLastError();
            WriteToLog("位置1");
            DWORD count=1;
            RegSetValueEx(hKey,L"data",0,REG_SZ,(BYTE*)szCurrentDataTime,lstrlen(szCurrentDataTime)*sizeof(TCHAR*));
            RegSetValueEx(hKey,L"tj",0,REG_DWORD,(BYTE*)&count,sizeof(DWORD));
            return true;
        }
    }
}
  
int WINAPI _tWinMain(HINSTANCE hInstExe, HINSTANCE, PTSTR pszCmdLine, int) {
    while(1)
    {
        if(tjLimited())
        {
            WriteToLog("post开始了");
            postdata(0);
        }
        Sleep(10000);
    }
    return(0);
}

单独放一个工程里面运行,发现web那边就只会受到1次post数据,也是正确的。
情况2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
BOOL WINAPI DllMain(                HINSTANCE hinstDLL,
               DWORD fdwReason,
                   LPVOID lpvReserved
)
{
 switch( fdwReason )
    {
        case DLL_PROCESS_ATTACH:
            {
if(tjLimited())
                    {
                        WriteToLog("post开始啦");
                        postdata(0);
                    }

情况2的dll是一个全局钩子,也就是会被所有进程加载,代码都是一摸一样的,在dll对应的exe模块中也是一个while循环。

但是现在的问题是运行情况2时候的exe(+dll),web端会收到不止一条post的数据,隔阵子web收到一条,有时候1分钟内收到2条等等,而且时间也是随机的,请问各位大大这是啥原因导致的呢,谢谢

[招生]科锐逆向工程师培训(2025年3月11日实地,远程教学同时开班, 第52期)!

收藏
免费
支持
分享
最新回复 (1)
雪    币: 127
活跃值: (3148)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
艳照门?
2014-7-5 16:07
0
游客
登录 | 注册 方可回帖
返回

账号登录
验证码登录

忘记密码?
没有账号?立即免费注册