-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsysctl.c
84 lines (62 loc) · 1.68 KB
/
sysctl.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
/*++
Copyright (C) 2011, Velocity Limitless Organization
Licensed under the GNU General Public License v2.
File name:
sysctl.c
Abstract:
Hook sysctlbyname.
--*/
#include <voodoo.h>
PSYSCTL_BY_NAME pSysctlbyname;
//
// This one has to be done like this because of header craziness...
//
int
sysctlbyname(
__in const char *name,
__in void *oldp,
__in size_t *oldlenp,
__in void *newp,
__in size_t newlen
)
/*++
Routine Description:
Return a value from the system sysctl repository nodes.
Arguments:
name - Oid to get.
oldp - Pointer to buffer to store data in.
oldlenp - Length of buffer.
newp - Pointer to buffer for new Oid data.
newlen - Length of buffer.
Return Value:
0 if successful, -1 if not.
--*/
{
CHAR ModelData[] = MODEL_STRING;
CHAR MachineData[] = MACHINE_STRING;
INT ReturnValue = 0;
//
// Check to see if hooked function is initialized.
//
if(!pSysctlbyname)
pSysctlbyname = dlsym(RTLD_NEXT, "sysctlbyname");
//
// Do we handle these oids?
//
if(oldp && oldlenp) {
if(!strcmp(name, "hw.model")) {
strlcpy(oldp, ModelData, sizeof(ModelData));
} else if(!strcmp(name, "hw.machine")) {
strlcpy(oldp, MachineData, sizeof(ModelData));
}
} else if(!oldp && oldlenp) {
if(!strcmp(name, "hw.model")) {
*oldlenp = sizeof(ModelData);
} else if(!strcmp(name, "hw.machine")) {
*oldlenp = sizeof(MachineData);
}
} else {
ReturnValue = pSysctlbyname(name, oldp, oldlenp, newp, newlen);
}
return ReturnValue;
}