main.cpp
3.18 KB
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
/* Copyright (C) 2010-2012 kaosu (qiupf2000@gmail.com)
* This file is part of the Interactive Text Hooker.
* Interactive Text Hooker 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include <windows.h>
#define ITH_TLS
#include <ITH\ITH_TLS.h>
#include <ITH\ntdll.h>
//#include "sha.h"
#include "socket.h"
#include "arithmetic.h"
//#include "tls.h"
#include <ITH\mem.h>
HANDLE hHeap;
//DNSCache* dns;
BOOL WINAPI DllMain(HANDLE hModule, DWORD reason, LPVOID lpReserved)
{
switch(reason)
{
case DLL_PROCESS_ATTACH:
{
LdrDisableThreadCalloutsForDll(hModule);
DWORD LowFragmentHeap=2;
hHeap=RtlCreateHeap(0x1002,0,0,0,0,0);
RtlSetHeapInformation(hHeap,HeapCompatibilityInformation,&LowFragmentHeap,sizeof(LowFragmentHeap));
}
break;
case DLL_PROCESS_DETACH:
RtlDestroyHeap(hHeap);
hHeap = 0;
break;
}
return TRUE;
}
ITH_TLS_SERVICE DWORD ITH_TLS_API ITH_TLS_Init()
{
WSADATA wsa;
WSAStartup(MAKEWORD(2,2),&wsa);
//dns = new DNSCache;
//dns->Insert(DNSInitTableName[0],DNSInitTableAddr[0]);
return 0;
}
ITH_TLS_SERVICE DWORD ITH_TLS_API ITH_TLS_Cleanup()
{
//delete dns;
//dns = 0;
WSACleanup();
return 0;
}
ITH_TLS_SERVICE HashCalculator* ITH_TLS_API ITH_TLS_NewHashCalculator(HashType type)
{
switch (type)
{
case HashTypeMD5:
return new MD5Calc;
break;
case HashTypeSHA1:
return new SHA1Calc;
break;
case HashTypeSHA256:
return new SHA256Calc;
break;
default:
return 0;
}
}
ITH_TLS_SERVICE DWORD ITH_TLS_API ITH_TLS_DestroyHashCalculator(HashCalculator* hash)
{
delete hash;
return 0;
}
ITH_TLS_SERVICE TransportSocket* ITH_TLS_API ITH_TLS_NewSocket(DWORD secure)
{
if (secure == 0) return new TransportSocket;
else return new SecureSocket;
}
ITH_TLS_SERVICE DWORD ITH_TLS_API ITH_TLS_DestroySocket(TransportSocket* socket)
{
delete socket;
return 0;
}
ITH_TLS_SERVICE DWORD ITH_TLS_API ITH_TLS_RSAEncrypt(void* key, void* data, void* out, DWORD len_in_bytes)
{
if (len_in_bytes > 0x100) return -1;
static BYTE commong_exp[4] = {1,0,1,0}; //0x10001
BYTE *key_tmp, *data_tmp;
DWORD tmp_len = 0x10;
while (len_in_bytes > tmp_len) tmp_len <<= 1;
key_tmp = new BYTE[tmp_len];
data_tmp = new BYTE[tmp_len];
memcpy(key_tmp, key, len_in_bytes);
memset(key_tmp + len_in_bytes, 0, tmp_len - len_in_bytes);
memcpy(data_tmp, data, len_in_bytes);
memset(data_tmp + len_in_bytes, 0, tmp_len - len_in_bytes);
exp_mod(data_tmp, commong_exp, key_tmp, data_tmp, len_in_bytes, 4, len_in_bytes);
memcpy(out, data_tmp, len_in_bytes);
delete key_tmp;
delete data_tmp;
return 0;
}