Add --mangle switch for mangling password before hashing
[hashcat.git] / src / ext_xnvctrl.c
1 /**
2 * Authors.....: Jens Steube <jens.steube@gmail.com>
3 * License.....: MIT
4 */
5
6 #include <ext_xnvctrl.h>
7
8 int xnvctrl_init (XNVCTRL_PTR *xnvctrl)
9 {
10 if (!xnvctrl) return -1;
11
12 memset (xnvctrl, 0, sizeof (XNVCTRL_PTR));
13
14 #ifdef _WIN
15
16 // unsupport platform?
17 return -1;
18
19 #elif _POSIX
20
21 xnvctrl->lib_x11 = dlopen ("libX11.so", RTLD_LAZY);
22
23 if (xnvctrl->lib_x11 == NULL)
24 {
25 if (data.quiet == 0) log_info ("WARNING: Failed loading the X11 library: %s", dlerror());
26 if (data.quiet == 0) log_info (" Please install libx11-dev package.");
27 if (data.quiet == 0) log_info ("");
28
29 return -1;
30 }
31
32 xnvctrl->lib_xnvctrl = dlopen ("libXNVCtrl.so", RTLD_LAZY);
33
34 if (xnvctrl->lib_xnvctrl == NULL)
35 {
36 if (data.quiet == 0) log_info ("WARNING: Failed loading the XNVCTRL library: %s", dlerror());
37 if (data.quiet == 0) log_info (" Please install libxnvctrl-dev package.");
38 if (data.quiet == 0) log_info ("");
39
40 return -1;
41 }
42
43 HC_LOAD_FUNC2 (xnvctrl, XOpenDisplay, XOPENDISPLAY, lib_x11, X11, 0);
44 HC_LOAD_FUNC2 (xnvctrl, XCloseDisplay, XCLOSEDISPLAY, lib_x11, X11, 0);
45
46 HC_LOAD_FUNC2 (xnvctrl, XNVCTRLQueryTargetAttribute, XNVCTRLQUERYTARGETATTRIBUTE, lib_xnvctrl, XNVCTRL, 0);
47 HC_LOAD_FUNC2 (xnvctrl, XNVCTRLSetTargetAttribute, XNVCTRLSETTARGETATTRIBUTE, lib_xnvctrl, XNVCTRL, 0);
48
49 #endif
50
51 return 0;
52 }
53
54 void xnvctrl_close (XNVCTRL_PTR *xnvctrl)
55 {
56 if (xnvctrl)
57 {
58 #if _POSIX
59
60 if (xnvctrl->lib_x11)
61 {
62 dlclose (xnvctrl->lib_x11);
63 }
64
65 if (xnvctrl->lib_xnvctrl)
66 {
67 dlclose (xnvctrl->lib_xnvctrl);
68 }
69
70 #endif
71
72 myfree (xnvctrl);
73 }
74 }
75
76 int hm_XNVCTRL_XOpenDisplay (XNVCTRL_PTR *xnvctrl)
77 {
78 if (xnvctrl == NULL) return -1;
79
80 if (xnvctrl->XOpenDisplay == NULL) return -1;
81
82 void *dpy = xnvctrl->XOpenDisplay (NULL);
83
84 if (dpy == NULL)
85 {
86 xnvctrl->dpy = NULL;
87
88 return -1;
89 }
90
91 xnvctrl->dpy = dpy;
92
93 return 0;
94 }
95
96 void hm_XNVCTRL_XCloseDisplay (XNVCTRL_PTR *xnvctrl)
97 {
98 if (xnvctrl == NULL) return;
99
100 if (xnvctrl->XCloseDisplay == NULL) return;
101
102 if (xnvctrl->dpy == NULL) return;
103
104 xnvctrl->XCloseDisplay (xnvctrl->dpy);
105 }
106
107 int get_fan_control (XNVCTRL_PTR *xnvctrl, int gpu, int *val)
108 {
109 if (xnvctrl == NULL) return -1;
110
111 if (xnvctrl->XNVCTRLQueryTargetAttribute == NULL) return -1;
112
113 if (xnvctrl->dpy == NULL) return -1;
114
115 int rc = xnvctrl->XNVCTRLQueryTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_GPU, gpu, 0, NV_CTRL_GPU_COOLER_MANUAL_CONTROL, val);
116
117 if (!rc) return -1;
118
119 return 0;
120 }
121
122 int set_fan_control (XNVCTRL_PTR *xnvctrl, int gpu, int val)
123 {
124 if (xnvctrl == NULL) return -1;
125
126 if (xnvctrl->XNVCTRLSetTargetAttribute == NULL) return -1;
127
128 if (xnvctrl->dpy == NULL) return -1;
129
130 int cur;
131
132 int rc = get_fan_control (xnvctrl, gpu, &cur);
133
134 if (rc == -1) return -1;
135
136 xnvctrl->XNVCTRLSetTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_GPU, gpu, 0, NV_CTRL_GPU_COOLER_MANUAL_CONTROL, val);
137
138 rc = get_fan_control (xnvctrl, gpu, &cur);
139
140 if (rc == -1) return -1;
141
142 if (cur != val) return -1;
143
144 return 0;
145 }
146
147 int get_core_threshold (XNVCTRL_PTR *xnvctrl, int gpu, int *val)
148 {
149 if (xnvctrl == NULL) return -1;
150
151 if (xnvctrl->XNVCTRLQueryTargetAttribute == NULL) return -1;
152
153 if (xnvctrl->dpy == NULL) return -1;
154
155 int rc = xnvctrl->XNVCTRLQueryTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_GPU, gpu, 0, NV_CTRL_GPU_CORE_THRESHOLD, val);
156
157 if (!rc) return -1;
158
159 return 0;
160 }
161
162 int get_fan_speed_current (XNVCTRL_PTR *xnvctrl, int gpu, int *val)
163 {
164 if (xnvctrl == NULL) return -1;
165
166 if (xnvctrl->XNVCTRLQueryTargetAttribute == NULL) return -1;
167
168 if (xnvctrl->dpy == NULL) return -1;
169
170 int rc = xnvctrl->XNVCTRLQueryTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_COOLER, gpu, 0, NV_CTRL_THERMAL_COOLER_CURRENT_LEVEL, val);
171
172 if (!rc) return -1;
173
174 return 0;
175 }
176
177 int get_fan_speed_target (XNVCTRL_PTR *xnvctrl, int gpu, int *val)
178 {
179 if (xnvctrl == NULL) return -1;
180
181 if (xnvctrl->XNVCTRLQueryTargetAttribute == NULL) return -1;
182
183 if (xnvctrl->dpy == NULL) return -1;
184
185 int rc = xnvctrl->XNVCTRLQueryTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_COOLER, gpu, 0, NV_CTRL_THERMAL_COOLER_LEVEL, val);
186
187 if (!rc) return -1;
188
189 return 0;
190 }
191
192 int set_fan_speed_target (XNVCTRL_PTR *xnvctrl, int gpu, int val)
193 {
194 if (xnvctrl == NULL) return -1;
195
196 if (xnvctrl->XNVCTRLSetTargetAttribute == NULL) return -1;
197
198 if (xnvctrl->dpy == NULL) return -1;
199
200 int cur;
201
202 int rc = get_fan_speed_target (xnvctrl, gpu, &cur);
203
204 if (rc == -1) return -1;
205
206 xnvctrl->XNVCTRLSetTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_COOLER, gpu, 0, NV_CTRL_THERMAL_COOLER_LEVEL, val);
207
208 rc = get_fan_speed_target (xnvctrl, gpu, &cur);
209
210 if (rc == -1) return -1;
211
212 if (cur != val) return -1;
213
214 return 0;
215 }