-
Notifications
You must be signed in to change notification settings - Fork 5
/
secapp.c
224 lines (192 loc) · 3.72 KB
/
secapp.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
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
214
215
216
217
218
219
220
221
222
223
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <stdarg.h>
#include <locale.h>
#include <time.h>
#include <errno.h>
#include <seclib.h>
#include "project.h"
// Process starting function
void StartProcess()
{
// Start the server
Debug("StartProcess() Begin.\n");
Debug("StartProcess() End.\n");
}
// Process termination function
void StopProcess()
{
// Stop the server
Debug("StopProcess() Begin.\n");
Debug("StopProcess() End.\n");
}
// Service test
void service_test(UINT num, char **arg)
{
Print("Starting...\n");
StartProcess();
Print("Service started.\n");
Print("Press Enter key to stop the service.\n");
GetLine(NULL, 0);
Print("Stopping...\n");
StopProcess();
Print("Service stopped.\n");
}
// Test function definition list
void test(UINT num, char **arg)
{
if (true)
{
Print("Test! %u\n", IsX64());
Temp_TestFunction("Nekosan");
return;
}
}
typedef void (TEST_PROC)(UINT num, char **arg);
typedef struct TEST_LIST
{
char *command_str;
TEST_PROC *proc;
} TEST_LIST;
TEST_LIST test_list[] =
{
{ "test", test },
{ "ss", service_test },
};
// Test function
void TestMain(char *cmd)
{
char tmp[MAX_SIZE];
bool first = true;
bool exit_now = false;
Print("Test Program\n");
#ifdef OS_WIN32
MsSetEnableMinidump(false);
#endif // OS_WIN32
while (true)
{
Print("TEST>");
if (first && StrLen(cmd) != 0 && g_memcheck == false)
{
first = false;
StrCpy(tmp, sizeof(tmp), cmd);
exit_now = true;
Print("%s\n", cmd);
}
else
{
GetLine(tmp, sizeof(tmp));
}
Trim(tmp);
if (StrLen(tmp) != 0)
{
UINT i, num;
bool b = false;
TOKEN_LIST *token = ParseCmdLine(tmp);
char *cmd = token->Token[0];
if (!StrCmpi(cmd, "exit") || !StrCmpi(cmd, "quit") || !StrCmpi(cmd, "q"))
{
FreeToken(token);
break;
}
else
{
num = sizeof(test_list) / sizeof(TEST_LIST);
for (i = 0;i < num;i++)
{
if (!StrCmpi(test_list[i].command_str, cmd))
{
char **arg = Malloc(sizeof(char *) * (token->NumTokens - 1));
UINT j;
for (j = 0;j < token->NumTokens - 1;j++)
{
arg[j] = CopyStr(token->Token[j + 1]);
}
test_list[i].proc(token->NumTokens - 1, arg);
for (j = 0;j < token->NumTokens - 1;j++)
{
Free(arg[j]);
}
Free(arg);
b = true;
Print("\n");
break;
}
}
if (b == false)
{
Print("Invalid Command: %s\n\n", cmd);
}
}
FreeToken(token);
if (exit_now)
{
break;
}
}
}
Print("Exiting...\n\n");
}
// Entry point
int main(int argc, char *argv[])
{
bool memchk = false;
UINT i;
char cmd[MAX_SIZE];
char *s;
bool is_service_mode = false;
cmd[0] = 0;
if (argc >= 2)
{
char *second_arg = argv[1];
if (StrCmpi(second_arg, "start") == 0 || StrCmpi(second_arg, "stop") == 0 || StrCmpi(second_arg, "execsvc") == 0 || StrCmpi(second_arg, "help") == 0 ||
(second_arg[0] == '/' && StrCmpi(second_arg, "/memcheck") != 0))
{
// service mode
is_service_mode = true;
}
if (is_service_mode == false)
{
for (i = 1;i < (UINT)argc;i++)
{
s = argv[i];
if (s[0] == '/')
{
if (!StrCmpi(s, "/memcheck"))
{
memchk = true;
}
}
else
{
StrCpy(cmd, sizeof(cmd), &s[0]);
}
}
}
}
if (is_service_mode == false)
{
// Test mode
//MayaquaMinimalMode();
SetHamMode();
InitMayaqua(memchk, true, argc, argv);
EnableProbe(false);
InitCedar();
SetHamMode();
TestMain(cmdline);
FreeCedar();
FreeMayaqua();
}
else
{
// Service mode
#ifdef OS_WIN32
return MsService("SECAPP", StartProcess, StopProcess, 0, argv[1]);
#else // OS_WIN32
return UnixService(argc, argv, "secapp", StartProcess, StopProcess);
#endif // OS_WIN32
}
return 0;
}