FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
patchdiff2/win_fct.cpp at master · CrackerCat/patchdiff2 · GitHub
CrackerCat
/
patchdiff2
Public
forked from
cseagle/patchdiff2
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
patchdiff2
/
win_fct.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
320 lines (252 loc) · 8.2 KB
Breadcrumbs
patchdiff2
/
win_fct.cpp
Copy path
File metadata and controls
320 lines (252 loc) · 8.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*
Patchdiff2
Portions (C) 2010 - 2011 Nicolas Pouvesle
Portions (C) 2007 - 2009 Tenable Network Security, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
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/>.
*/
//
Must be included before idp.hpp
#
include
<
Windows.h
>
#
include
"
precomp.h
"
#
include
"
win_fct.h
"
#
include
"
system.h
"
struct
ipc_data
{
HANDLE
shared;
idata_t
*memory;
HANDLE
slock;
HANDLE
rlock;
HANDLE
process;
};
typedef
struct
ipc_data
ipc_data_t
;
/*
------------------------------------------------
*/
/*
function : os_execute_command
*/
/*
description: Executes a command by creating a
*/
/*
new process
*/
/*
------------------------------------------------
*/
int
os_execute_command
(
char
*cmd,
bool
close,
void
*data) {
STARTUPINFO
si;
PROCESS_INFORMATION
pi;
int
ret = -
1
;
ipc_data_t
*id = (
ipc_data_t
*)data;
ZeroMemory
( &si,
sizeof
(
STARTUPINFO
) );
si.
cb
=
sizeof
(
STARTUPINFO
);
si.
hStdError
=
GetStdHandle
(
STD_ERROR_HANDLE
);
si.
hStdOutput
=
GetStdHandle
(
STD_OUTPUT_HANDLE
);
si.
hStdInput
=
GetStdHandle
(
STD_INPUT_HANDLE
);
si.
dwFlags
|=
STARTF_USESTDHANDLES
;
if
(
CreateProcess
(
NULL
,
cmd,
//
command line
NULL
,
//
process security
NULL
,
//
thread security
FALSE
,
//
inherit handles-yes
0
,
//
creation flags
NULL
,
//
environment block
NULL
,
//
current directory
&si,
//
startup info
&pi)) {
//
process info (out){
if
(close) {
/*
we wait until the process finished (IE: sig file is generated)
*/
if
(
WaitForSingleObject
( pi.
hProcess
,
INFINITE
) ==
WAIT_OBJECT_0
) {
ret =
0
;
}
CloseHandle
(pi.
hProcess
);
}
else
{
id->
process
= pi.
hProcess
;
ret =
0
;
}
CloseHandle
(pi.
hThread
);
}
return
ret;
}
/*
------------------------------------------------
*/
/*
function : os_check_process
*/
/*
description: checks process state
*/
/*
------------------------------------------------
*/
static
bool
os_check_process
(
void
*handle) {
DWORD
exitcode;
if
(
GetExitCodeProcess
((
HANDLE
)handle, &exitcode) && exitcode ==
STILL_ACTIVE
) {
return
true
;
}
return
false
;
}
/*
------------------------------------------------
*/
/*
function : os_copy_to_clipboard
*/
/*
description: Copies data to clipboard
*/
/*
------------------------------------------------
*/
void
os_copy_to_clipboard
(
char
*data) {
}
/*
------------------------------------------------
*/
/*
function : os_get_pid
*/
/*
description: Returns process ID
*/
/*
------------------------------------------------
*/
long
os_get_pid
() {
return
(
long
)
GetCurrentProcessId
();
}
/*
------------------------------------------------
*/
/*
function : os_unlink
*/
/*
description: removes a link to a file
*/
/*
------------------------------------------------
*/
int
os_unlink
(
const
char
*path) {
return
_unlink
(path);
}
/*
------------------------------------------------
*/
/*
function : os_tempnam
*/
/*
description: returns a temporary file name
*/
/*
------------------------------------------------
*/
void
os_tempnam
(
char
*data,
size_t
size,
char
*suffix) {
char
tmp[
MAX_PATH
];
char
name[
MAX_PATH
];
GetTempPath
(
sizeof
(tmp), tmp);
GetTempFileName
(tmp,
NULL
,
0
, name);
qsnprintf
(data, size,
"
%s%s
"
, name, (suffix) ? suffix:
"
"
);
}
/*
------------------------------------------------
*/
/*
function : os_ipc_send
*/
/*
description: Sends data on pipe
*/
/*
------------------------------------------------
*/
bool
os_ipc_send
(
void
*data,
int
type,
idata_t
*d) {
ipc_data_t
*id = (
ipc_data_t
*)data;
HANDLE
lock;
memcpy
(id->
memory
, d,
sizeof
(*id->
memory
));
lock = (type ==
IPC_SERVER
) ? id->
slock
: id->
rlock
;
return
SetEvent
(lock) ==
TRUE
;
}
/*
------------------------------------------------
*/
/*
function : os_ipc_recv
*/
/*
description: Receives data on pipe
*/
/*
------------------------------------------------
*/
bool
os_ipc_recv
(
void
*data,
int
type,
idata_t
*d) {
ipc_data_t
*id = (
ipc_data_t
*)data;
HANDLE
lock;
DWORD
ret;
lock = (type ==
IPC_SERVER
) ? id->
rlock
: id->
slock
;
if
(id->
process
) {
while
(
1
) {
ret =
WaitForSingleObject
((
HANDLE
)lock,
1000
);
if
(ret ==
WAIT_OBJECT_0
) {
break
;
}
if
(ret !=
WAIT_TIMEOUT
|| !
os_check_process
(id->
process
)) {
return
false
;
}
}
}
else
{
if
(
WaitForSingleObject
((
HANDLE
)lock,
INFINITE
) !=
WAIT_OBJECT_0
) {
return
false
;
}
}
memcpy
(d, id->
memory
,
sizeof
(*d));
return
true
;
}
/*
------------------------------------------------
*/
/*
function : os_ipc_init
*/
/*
description: Inits interprocess communication
*/
/*
------------------------------------------------
*/
bool
os_ipc_init
(
void
** data,
long
pid,
int
type) {
char
name[
512
];
ipc_data_t
*id;
id = (
ipc_data_t
*)
qalloc
(
sizeof
(*id));
if
(!id) {
return
false
;
}
memset
(id,
'
\0
'
,
sizeof
(*id));
qsnprintf
(name,
sizeof
(name),
"
pdiff2_slock%u
"
, pid);
id->
slock
=
CreateEvent
(
NULL
,
false
,
false
, name);
if
(!id->
slock
) {
goto
error;
}
qsnprintf
(name,
sizeof
(name),
"
pdiff2_rlock%u
"
, pid);
id->
rlock
=
CreateEvent
(
NULL
,
false
,
false
, name);
if
(!id->
rlock
) {
goto
error;
}
qsnprintf
(name,
sizeof
(name),
"
pdiff2_sharedmemory%u
"
, pid);
if
(type ==
IPC_SERVER
) {
id->
shared
=
CreateFileMapping
(
INVALID_HANDLE_VALUE
,
NULL
,
PAGE_READWRITE
,
0
,
sizeof
(
idata_t
), name);
if
(!id->
shared
) {
goto
error;
}
}
else
{
id->
shared
=
OpenFileMapping
(
FILE_MAP_ALL_ACCESS
,
false
,name);
if
(!id->
shared
) {
goto
error;
}
}
id->
memory
= (
idata_t
*)
MapViewOfFile
(id->
shared
,
FILE_MAP_ALL_ACCESS
,
0
,
0
,
sizeof
(
idata_t
));
if
(!id->
memory
) {
goto
error;
}
*data = (
void
*)id;
return
true
;
error:
if
(id->
slock
) {
CloseHandle
(id->
slock
);
}
if
(id->
rlock
) {
CloseHandle
(id->
rlock
);
}
if
(id->
shared
) {
CloseHandle
(id->
shared
);
}
qfree
(id);
return
false
;
}
/*
------------------------------------------------
*/
/*
function : os_ipc_close
*/
/*
description: Closes IPC
*/
/*
------------------------------------------------
*/
bool
os_ipc_close
(
void
*data) {
ipc_data_t
*id = (
ipc_data_t
*)data;
if
(id->
slock
) {
SetEvent
(id->
slock
);
CloseHandle
(id->
slock
);
}
if
(id->
rlock
) {
SetEvent
(id->
rlock
);
CloseHandle
(id->
rlock
);
}
if
(id->
memory
) {
UnmapViewOfFile
((
void
*)id->
memory
);
}
if
(id->
shared
) {
CloseHandle
(id->
shared
);
}
if
(id->
process
) {
CloseHandle
(id->
process
);
}
return
true
;
}
/*
------------------------------------------------
*/
/*
function : os_get_pref_int
*/
/*
description: Gets system preferences (integer)
*/
/*
------------------------------------------------
*/
bool
os_get_pref_int
(
const
char
*name,
int
*i) {
HKEY
key;
DWORD
type;
DWORD
size;
int
tmp;
long
ret;
ret =
RegOpenKeyEx
(
HKEY_LOCAL_MACHINE
,
"
SOFTWARE
\\
Tenable
\\
PatchDiff2
"
,
0
,
KEY_READ
, &key);
if
(ret !=
ERROR_SUCCESS
) {
return
false
;
}
size =
sizeof
(tmp);
ret =
RegQueryValueEx
(key, name,
NULL
, &type, (
LPBYTE
)&tmp, &size);
RegCloseKey
(key);
if
(ret !=
ERROR_SUCCESS
|| type !=
REG_DWORD
) {
return
false
;
}
*i = tmp;
return
true
;
}
Back
|
FazBrowse Home
|
New Git URL