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
|
// Copyright © 2010 sss
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "commonheaders.h"
wstring new_key;
HANDLE new_key_hcnt = NULL;
HANDLE new_key_hcnt_mutex = NULL;
bool _terminate = false;
BOOL isProtoMetaContacts(HANDLE hContact);
int RecvMsgSvc(WPARAM w, LPARAM l)
{
CCSDATA *ccs = (CCSDATA*)l;
if (!ccs)
return CallService(MS_PROTO_CHAINRECV, w, l);
PROTORECVEVENT *pre = (PROTORECVEVENT*)(ccs->lParam);
if (!pre)
return CallService(MS_PROTO_CHAINRECV, w, l);
char *msg = pre->szMessage;
if (!msg)
return CallService(MS_PROTO_CHAINRECV, w, l);
HANDLE hContact = ccs->hContact;
if(isProtoMetaContacts(hContact))
hContact = metaGetMostOnline(hContact);
return CallService(MS_PROTO_CHAINRECV, w, l);
}
char *send_msg = NULL;
int SendMsgSvc(WPARAM w, LPARAM l)
{
CCSDATA *ccs = (CCSDATA*)l;
if (!ccs)
return CallService(MS_PROTO_CHAINSEND, w, l);
char *msg = (char*)(ccs->lParam);
if (!msg)
return CallService(MS_PROTO_CHAINSEND, w, l);
HANDLE hContact = ccs->hContact;
if(isProtoMetaContacts(hContact))
hContact = metaGetMostOnline(hContact);
TCHAR *tmp = mir_a2t(msg);
wstring str = tmp;
mir_free(tmp);
int i = 0;
char setting[32];
mir_snprintf(setting, 31, "szSourceWord%d", i);
TCHAR *buf = UniGetContactSettingUtf(NULL, szReplacerModuleName, setting, _T(""));
wstring::size_type p1 = 0;
while(_tcslen(buf) > 0)
{
mir_snprintf(setting, 31, "szTargetWords%d", i);
TCHAR *buf2 = UniGetContactSettingUtf(NULL, szReplacerModuleName, setting, _T(""));
wstring tmp = buf2;
mir_free(buf2);
wstring::size_type p1 = 0, p2 = 0, end = 0;
p1 = tmp.find(_T("†")); //nice delimiter
int c = 0;
TCHAR *words[1024]; //fucked msvc does not support variable massive size (
for(;;)
{
if(p1 == wstring::npos)
break;
if(!c)
{
words[c] = mir_wstrdup(tmp.substr(0, p1).c_str());
p2 = end = p1;
}
else
{
p2 = tmp.find(_T("†"), p1+1);
if(p2 < end || p2 == p1)
break;
else if(p2 == wstring::npos)
break;
p1++;
words[c] = mir_wstrdup(tmp.substr(p1, p2-p1).c_str());
end = p2;
}
p1 = p2;
c++;
}
if(c)
{
p1 = 0;
wstring::size_type end = 0;
while((p1 = str.find(buf), p1) != wstring::npos)
{
if(p1 < end)
break;
int p = (c>1)?(rand()%(c-1)):0;
str.replace(p1, (wstring::size_type)_tcslen(buf), words[p]);
p1+=_tcslen(words[p]);
end = p1;
}
}
mir_free(buf);
for(int cc = 0; cc < c; cc++)
mir_free(words[cc]);
i++;
mir_snprintf(setting, 31, "szSourceWord%d", i);
buf = UniGetContactSettingUtf(NULL, szReplacerModuleName, setting, _T(""));
}
ccs->lParam = (LPARAM)mir_utf8encodeW(str.c_str());
return CallService(MS_PROTO_CHAINSEND, w, l);
}
int HookSendMsg(WPARAM w, LPARAM l)
{
HANDLE hContact = (HANDLE)w;
if(isProtoMetaContacts(hContact))
hContact = metaGetMostOnline(hContact);
if(!DBGetContactSettingByte(hContact, szReplacerModuleName, "GPGEncryption", 0))
return 0;
if(bAppendTags)
{
if(!l)
return 0;
BYTE Msgs = DBGetContactSettingByte(hContact, szReplacerModuleName, "MsgsForTagging", 0);
if(!Msgs)
return 0;
DBEVENTINFO * dbei = (DBEVENTINFO*)l;
if((dbei->eventType == EVENTTYPE_MESSAGE) && (dbei->flags & DBEF_SENT))
{
char *msg = (char*)dbei->pBlob;
TCHAR *tmp = mir_utf8decodeW(msg);
wstring str = tmp;
mir_free(tmp);
str.insert(0, outopentag);
str.append(outclosetag);
char *msg2 = mir_utf8encodeW(str.c_str());
mir_free(dbei->pBlob);
dbei->pBlob = (PBYTE)msg2;
dbei->cbBlob = strlen(msg2)+1;
DBWriteContactSettingByte(hContact, szReplacerModuleName, "MsgsForTagging", Msgs - 1);
}
}
return 0;
}
|