forked from redxu/sihook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.c
182 lines (166 loc) · 3.15 KB
/
utils.c
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
#include <string.h>
#include <stdio.h>
#include "const.h"
#include "utils.h"
GetU8FlagFn GetU8Flag = NULL;
//输出调试信息
void WINAPI OutputDebugStringEx(LPCTSTR lpcFormatText, ...)
{
char szBuffer[1024];
va_list argptr;
va_start(argptr, lpcFormatText);
vsprintf(szBuffer, lpcFormatText, argptr);
va_end(argptr);
OutputDebugString(szBuffer);
}
//获取短标题
char* GetSiSwTitle(const char* lpc,char* title)
{
int i,len;
int skip_flag;
int index;
skip_flag=0;
i = index = 0;
len = strlen(lpc);
while(i<len)
{
if(lpc[i] == '(')
{
skip_flag++;
}
else if(lpc[i] == ')')
{
skip_flag--;
i++;
continue;
}
if(skip_flag == 0)
{
title[index++] = lpc[i];
}
i++;
}
title[index] = '\0';
return title;
}
static const char* strstri(const char* str,const char* subStr)
{
int len = strlen(subStr);
if(len == 0)
{
return NULL;
}
while(*str)
{
if(strncasecmp(str, subStr, len) == 0)
{
return str;
}
++str;
}
return NULL;
}
//获取文件类型
//0 无类型默认
//1 *.c *.cpp *.cxx *.cs
//2 *.h *.hpp *.hxx *.inc
//3 *.txt *.text *.doc
//4 *.php *.php3 *.htm *.js
//5 *.pas *.vb *.pb *.vbs
int GetColorIndex(const char* filename)
{
const char *p = NULL;
//type 1
p = strstri(filename,".c");
if(p != NULL)
return 1;
p = strstri(filename,".cpp");
if(p != NULL)
return 1;
p = strstri(filename,".cxx");
if(p != NULL)
return 1;
p = strstri(filename,".cs");
if(p != NULL)
return 1;
//type 2
p = strstri(filename,".h");
if(p != NULL)
return 2;
p = strstri(filename,".hpp");
if(p != NULL)
return 2;
p = strstri(filename,".hxx");
if(p != NULL)
return 2;
p = strstri(filename,".inc");
if(p != NULL)
return 2;
//type 3
p = strstri(filename,".txt");
if(p != NULL)
return 3;
p = strstri(filename,".text");
if(p != NULL)
return 3;
p = strstri(filename,".doc");
if(p != NULL)
return 3;
//type 4
p = strstri(filename,".php");
if(p != NULL)
return 4;
p = strstri(filename,".php3");
if(p != NULL)
return 4;
p = strstri(filename,".htm");
if(p != NULL)
return 4;
p = strstri(filename,".js");
if(p != NULL)
return 4;
//type 5
p = strstri(filename,".pas");
if(p != NULL)
return 5;
p = strstri(filename,".pb");
if(p != NULL)
return 5;
p = strstri(filename,".vbs");
if(p != NULL)
return 5;
p = strstri(filename,".vb");
if(p != NULL)
return 5;
return 0;
}
/**
* 检查是否加载了siutf8插件
* @return [0-未加载 1-已加载]
*/
int CheckUtf8Loaded(void)
{
static int loaded = -1;
if(loaded != -1)
return loaded;
HMODULE hmod = GetModuleHandle(SI_DLLNAME_UTF8);
if(hmod == NULL)
{
loaded = 0;
OutputDebugString("siutf8.dll未加载!");
return loaded;
}
GetU8Flag = (GetU8FlagFn)GetProcAddress(hmod, "FindU8FlagFromLink");
if(GetU8Flag == NULL)
{
loaded = 0;
OutputDebugString("FindU8FlagFromLink函数未找到!");
return loaded;
}
else
{
loaded = 1;
OutputDebugStringEx("FindU8FlagFromLink addr: 0x%p", GetU8Flag);
}
return loaded;
}