1 | #!/bin/bash |
---|
2 | #/** |
---|
3 | #@file Registry.lib |
---|
4 | #@brief Librería o clase Registry |
---|
5 | #@class Boot |
---|
6 | #@brief Funciones para gestión del registro de Windows. |
---|
7 | #@version 1.0.1 |
---|
8 | #@warning License: GNU GPLv3+ |
---|
9 | #*/ |
---|
10 | |
---|
11 | |
---|
12 | #/** |
---|
13 | # ogAddRegistryKey path_mountpoint str_hive str_keyname |
---|
14 | #@brief Añade una nueva clave al registro de Windows. |
---|
15 | #@param path_mountpoint directorio donde está montado el sistema Windows |
---|
16 | #@param str_hive sección del registro |
---|
17 | #@param str_keyname nombre de la clave |
---|
18 | #@return (nada) |
---|
19 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
20 | #@exception OG_ERR_NOTFOUND Fichero de registro no encontrado. |
---|
21 | #@note hive = { default, sam, security, software, system, components } |
---|
22 | #@warning Requisitos: chntpw |
---|
23 | #@warning El sistema de archivos de Windows debe estar montada previamente. |
---|
24 | #@version 1.0.1 - Nueva función |
---|
25 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
26 | #@date 2011-05-25 |
---|
27 | #*/ ## |
---|
28 | function ogAddRegistryKey () |
---|
29 | { |
---|
30 | # Variables locales. |
---|
31 | local FILE |
---|
32 | |
---|
33 | # Si se solicita, mostrar ayuda. |
---|
34 | if [ "$*" == "help" ]; then |
---|
35 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_key" \ |
---|
36 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey'" |
---|
37 | return |
---|
38 | fi |
---|
39 | # Error si no se reciben 3 parámetros. |
---|
40 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
41 | # Camino del fichero de registro. |
---|
42 | FILE=$(ogGetHivePath "$1" "$2") || return $? |
---|
43 | |
---|
44 | # Añadir nueva clave. |
---|
45 | chntpw "$FILE" << EOT &> /dev/null |
---|
46 | cd ${3%\\*} |
---|
47 | nk ${3##*\\} |
---|
48 | q |
---|
49 | y |
---|
50 | EOT |
---|
51 | } |
---|
52 | |
---|
53 | #/** |
---|
54 | # ogAddRegistryValue path_mountpoint str_hive str_valuename [str_valuetype] |
---|
55 | #@brief Añade un nuevo valor al registro de Windows, indicando su tipo de datos. |
---|
56 | #@param path_mountpoint directorio donde está montado el sistema Windows |
---|
57 | #@param str_hive sección del registro |
---|
58 | #@param str_valuename nombre del valor |
---|
59 | #@param str_valuetype tipo de datos del valor (opcional) |
---|
60 | #@return (nada) |
---|
61 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
62 | #@exception OG_ERR_NOTFOUND Fichero de registro no encontrado. |
---|
63 | #@note hive = { DEFAULT, SAM, SECURITY, SOFTWARE, SYSTEM, COMPONENTS } |
---|
64 | #@note valuetype = { STRING, BINARY, DWORD }, por defecto: STRING |
---|
65 | #@warning Requisitos: chntpw |
---|
66 | #@warning El sistema de archivos de Windows debe estar montada previamente. |
---|
67 | #@version 1.0.1 - Nueva función |
---|
68 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
69 | #@date 2011-05-25 |
---|
70 | #*/ ## |
---|
71 | function ogAddRegistryValue () |
---|
72 | { |
---|
73 | # Variables locales. |
---|
74 | local FILE TYPE |
---|
75 | |
---|
76 | # Si se solicita, mostrar ayuda. |
---|
77 | if [ "$*" == "help" ]; then |
---|
78 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_valuename [str_valuetype]" \ |
---|
79 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1'" \ |
---|
80 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1' DWORD" |
---|
81 | return |
---|
82 | fi |
---|
83 | # Error si no se reciben 3 o 4 parámetros. |
---|
84 | [ $# == 3 -o $# == 4 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
85 | # Camino del fichero de registro. |
---|
86 | FILE=$(ogGetHivePath "$1" "$2") || return $? |
---|
87 | case "$4" in |
---|
88 | string|STRING|"") TYPE=1 ;; |
---|
89 | binary|BINARY) TYPE=3 ;; |
---|
90 | dword|DWORD) TYPE=4 ;; |
---|
91 | *) ogRaiseError $OG_ERR_OUTOFLIMIT "$4" |
---|
92 | return $? ;; |
---|
93 | esac |
---|
94 | |
---|
95 | # Devolver el dato del valor de registro. |
---|
96 | # /* (comentario Doxygen) |
---|
97 | chntpw "$FILE" << EOT &> /dev/null |
---|
98 | cd ${3%\\*} |
---|
99 | nv $TYPE ${3##*\\} |
---|
100 | q |
---|
101 | y |
---|
102 | EOT |
---|
103 | # (comentario Doxygen) */ |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | #/** |
---|
108 | # ogDeleteRegistryKey path_mountpoint str_hive str_keyname |
---|
109 | #@brief Elimina una clave del registro de Windows con todo su contenido. |
---|
110 | #@param path_mountpoint directorio donde está montado el sistema Windows |
---|
111 | #@param str_hive sección del registro |
---|
112 | #@param str_keyname nombre de la clave |
---|
113 | #@return (nada) |
---|
114 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
115 | #@exception OG_ERR_NOTFOUND Fichero de registro no encontrado. |
---|
116 | #@note hive = { default, sam, security, software, system, components } |
---|
117 | #@warning Requisitos: chntpw |
---|
118 | #@warning El sistema de archivos de Windows debe estar montada previamente. |
---|
119 | #@warning La clave debe estar vacía para poder ser borrada. |
---|
120 | #@version 1.0.1 - Nueva función |
---|
121 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
122 | #@date 2011-05-25 |
---|
123 | #*/ ## |
---|
124 | function ogDeleteRegistryKey () |
---|
125 | { |
---|
126 | # Variables locales. |
---|
127 | local FILE |
---|
128 | |
---|
129 | # Si se solicita, mostrar ayuda. |
---|
130 | if [ "$*" == "help" ]; then |
---|
131 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_key" \ |
---|
132 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey'" |
---|
133 | return |
---|
134 | fi |
---|
135 | # Error si no se reciben 3 parámetros. |
---|
136 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
137 | # Camino del fichero de registro. |
---|
138 | FILE=$(ogGetHivePath "$1" "$2") || return $? |
---|
139 | |
---|
140 | # Añadir nueva clave. |
---|
141 | chntpw "$FILE" << EOT &> /dev/null |
---|
142 | cd ${3%\\*} |
---|
143 | dk ${3##*\\} |
---|
144 | q |
---|
145 | y |
---|
146 | EOT |
---|
147 | } |
---|
148 | |
---|
149 | |
---|
150 | #/** |
---|
151 | # ogDeleteRegistryValue path_mountpoint str_hive str_valuename |
---|
152 | #@brief Elimina un valor del registro de Windows. |
---|
153 | #@param path_mountpoint directorio donde está montado el sistema Windows |
---|
154 | #@param str_hive sección del registro |
---|
155 | #@param str_valuename nombre del valor |
---|
156 | #@return (nada) |
---|
157 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
158 | #@exception OG_ERR_NOTFOUND Fichero de registro no encontrado. |
---|
159 | #@note hive = { default, sam, security, software, system, components } |
---|
160 | #@warning Requisitos: chntpw |
---|
161 | #@warning El sistema de archivos de Windows debe estar montada previamente. |
---|
162 | #@version 1.0.1 - Nueva función |
---|
163 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
164 | #@date 2011-05-25 |
---|
165 | #*/ ## |
---|
166 | function ogDeleteRegistryValue () |
---|
167 | { |
---|
168 | # Variables locales. |
---|
169 | local FILE |
---|
170 | |
---|
171 | # Si se solicita, mostrar ayuda. |
---|
172 | if [ "$*" == "help" ]; then |
---|
173 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_valuename" \ |
---|
174 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1'" |
---|
175 | return |
---|
176 | fi |
---|
177 | # Error si no se reciben 3 parámetros. |
---|
178 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
179 | # Camino del fichero de registro. |
---|
180 | FILE=$(ogGetHivePath "$1" "$2") || return $? |
---|
181 | |
---|
182 | # Devolver el dato del valor de registro. |
---|
183 | # /* (comentario Doxygen) |
---|
184 | chntpw "$FILE" << EOT &> /dev/null |
---|
185 | cd ${3%\\*} |
---|
186 | dv ${3##*\\} |
---|
187 | q |
---|
188 | y |
---|
189 | EOT |
---|
190 | # (comentario Doxygen) */ |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
194 | #/** |
---|
195 | # ogGetHivePath path_mountpoint str_hive |
---|
196 | #@brief Función básica que devuelve el camino del fichero con una sección del registro. |
---|
197 | #@param path_mountpoint directorio donde está montado el sistema Windows |
---|
198 | #@param str_hive sección del registro |
---|
199 | #@return str_path - camino del fichero de registro |
---|
200 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
201 | #@exception OG_ERR_NOTFOUND Fichero de registro no encontrado. |
---|
202 | #@note hive = { DEFAULT, SAM, SECURITY, SOFTWARE, SYSTEM, COMPONENTS } |
---|
203 | #@warning El sistema de archivos de Windows debe estar montada previamente. |
---|
204 | #@version 1.0.1 - Nueva función |
---|
205 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
206 | #@date 2011-05-18 |
---|
207 | #*/ ## |
---|
208 | function ogGetHivePath () |
---|
209 | { |
---|
210 | # Variables locales. |
---|
211 | local FILE FILENT FILEXP |
---|
212 | |
---|
213 | # Si se solicita, mostrar ayuda. |
---|
214 | if [ "$*" == "help" ]; then |
---|
215 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive" |
---|
216 | "$FUNCNAME /mnt/sda1 SOFTWARE => /mnt/sda1/WINDOWS/System32/config/SOFTWARE" |
---|
217 | return |
---|
218 | fi |
---|
219 | # Error si no se reciben 2 parámetros. |
---|
220 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
221 | |
---|
222 | # Camino del fichero de registro en NT/2000 o XP/Vista/7. |
---|
223 | FILENT=$(ogGetPath "/$1/winnt/system32/config/$2") |
---|
224 | [ -f $FILENT ] && FILE="$FILENT" |
---|
225 | FILEXP=$(ogGetPath "/$1/windows/system32/config/$2") |
---|
226 | [ -f $FLEHXP ] && FILE="$FILEXP" |
---|
227 | [ ! -f $FILE ] && ogRaiseError OG_ERR_NOTFOUND "$1,$2" && return $? |
---|
228 | |
---|
229 | echo "$FILE" |
---|
230 | } |
---|
231 | |
---|
232 | |
---|
233 | #/** |
---|
234 | # ogGetRegistryValue path_mountpoint str_hive str_valuename |
---|
235 | #@brief Devuelve el dato de un valor del registro de Windows. |
---|
236 | #@param path_mountpoint directorio donde está montado el sistema Windows |
---|
237 | #@param str_hive sección del registro |
---|
238 | #@param str_valuename nombre del valor |
---|
239 | #@return str_valuedata - datos del valor. |
---|
240 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
241 | #@exception OG_ERR_NOTFOUND Fichero de registro no encontrado. |
---|
242 | #@note hive = { default, sam, security, software, system, components } |
---|
243 | #@warning Requisitos: chntpw, awk |
---|
244 | #@warning El sistema de archivos de Windows debe estar montado previamente. |
---|
245 | #@version 0.9 - Adaptación para OpenGNSys. |
---|
246 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
247 | #@date 2009-09-11 |
---|
248 | #*/ ## |
---|
249 | function ogGetRegistryValue () |
---|
250 | { |
---|
251 | # Variables locales. |
---|
252 | local FILE |
---|
253 | |
---|
254 | # Si se solicita, mostrar ayuda. |
---|
255 | if [ "$*" == "help" ]; then |
---|
256 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_valuename" \ |
---|
257 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1' ==> 1" |
---|
258 | return |
---|
259 | fi |
---|
260 | # Error si no se reciben 3 parámetros. |
---|
261 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
262 | # Camino del fichero de registro. |
---|
263 | FILE=$(ogGetHivePath "$1" "$2") || return $? |
---|
264 | |
---|
265 | # Devolver el dato del valor de registro. |
---|
266 | # /* (comentario Doxygen) |
---|
267 | chntpw "$FILE" << EOT 2> /dev/null | awk '/> Value/ {getline;print $0;}' |
---|
268 | cd ${3%\\*} |
---|
269 | cat ${3##*\\} |
---|
270 | q |
---|
271 | EOT |
---|
272 | # (comentario Doxygen) */ |
---|
273 | } |
---|
274 | |
---|
275 | |
---|
276 | #/** |
---|
277 | # ogListRegistryKeys path_mountpoint str_hive str_key |
---|
278 | #@brief Lista los nombres de subclaves de una determinada clave del registro de Windows. |
---|
279 | #@param path_mountpoint directorio donde está montado el sistema Windows |
---|
280 | #@param str_hive sección del registro |
---|
281 | #@param str_key clave de registro |
---|
282 | #@return str_subkey ... - lista de subclaves |
---|
283 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
284 | #@exception OG_ERR_NOTFOUND Fichero de registro no encontrado. |
---|
285 | #@note hive = { default, sam, security, software, system, components } |
---|
286 | #@warning Requisitos: chntpw, awk |
---|
287 | #@warning El sistema de archivos de Windows debe estar montado previamente. |
---|
288 | #@version 0.9 - Adaptación para OpenGNSys. |
---|
289 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
290 | #@date 2009-09-23 |
---|
291 | #*/ ## |
---|
292 | function ogListRegistryKeys () |
---|
293 | { |
---|
294 | # Variables locales. |
---|
295 | local FILE |
---|
296 | |
---|
297 | # Si se solicita, mostrar ayuda. |
---|
298 | if [ "$*" == "help" ]; then |
---|
299 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_key" \ |
---|
300 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\Windows\CurrentVersion'" |
---|
301 | return |
---|
302 | fi |
---|
303 | # Error si no se reciben 3 parámetros. |
---|
304 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
305 | |
---|
306 | # Camino del fichero de registro. |
---|
307 | FILE=$(ogGetHivePath "$1" "$2") || return $? |
---|
308 | |
---|
309 | # Devolver la lista de claves de registro. |
---|
310 | chntpw "$FILE" << EOT 2> /dev/null | awk 'BEGIN {FS="[<>]"} $1~/^ $/ {print $2}' |
---|
311 | ls $3 |
---|
312 | q |
---|
313 | EOT |
---|
314 | } |
---|
315 | |
---|
316 | |
---|
317 | #/** |
---|
318 | # ogListRegistryValues path_mountpoint str_hive str_key |
---|
319 | #@brief Lista los nombres de valores de una determinada clave del registro de Windows. |
---|
320 | #@param path_mountpoint directorio donde está montado el sistema Windows |
---|
321 | #@param str_hive sección del registro |
---|
322 | #@param str_key clave de registro |
---|
323 | #@return str_value ... - lista de valores |
---|
324 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
325 | #@exception OG_ERR_NOTFOUND Fichero de registro no encontrado. |
---|
326 | #@note hive = { default, sam, security, software, system, components } |
---|
327 | #@warning Requisitos: chntpw, awk |
---|
328 | #@warning El sistema de archivos de Windows debe estar montado previamente. |
---|
329 | #@version 1.0.1 - Nueva función. |
---|
330 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
331 | #@date 2011-05-26 |
---|
332 | #*/ ## |
---|
333 | function ogListRegistryValues () |
---|
334 | { |
---|
335 | # Variables locales. |
---|
336 | local FILE |
---|
337 | |
---|
338 | # Si se solicita, mostrar ayuda. |
---|
339 | if [ "$*" == "help" ]; then |
---|
340 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_key" \ |
---|
341 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\Windows\CurrentVersion'" |
---|
342 | return |
---|
343 | fi |
---|
344 | # Error si no se reciben 3 parámetros. |
---|
345 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
346 | # Camino del fichero de registro. |
---|
347 | FILE=$(ogGetHivePath "$1" "$2") || return $? |
---|
348 | |
---|
349 | # Devolver la lista de claves de registro. |
---|
350 | chntpw "$FILE" << EOT 2> /dev/null | awk 'BEGIN {FS="[<>]"} $1~/REG_/ {print $2}' |
---|
351 | ls $3 |
---|
352 | q |
---|
353 | EOT |
---|
354 | } |
---|
355 | |
---|
356 | |
---|
357 | #/** |
---|
358 | # ogSetRegistryValue path_mountpoint str_hive str_valuename str_valuedata |
---|
359 | #@brief Establece el dato asociado a un valor del registro de Windows. |
---|
360 | #@param path_mountpoint directorio donde está montado el sistema Windows |
---|
361 | #@param str_hive sección del registro |
---|
362 | #@param str_valuename nombre del valor de registro |
---|
363 | #@param str_valuedata dato del valor de registro |
---|
364 | #@return (nada) |
---|
365 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
366 | #@exception OG_ERR_NOTFOUND Fichero de registro no encontrado. |
---|
367 | #@note hive = { default, sam, security, software, system, components } |
---|
368 | #@warning Requisitos: chntpw |
---|
369 | #@warning El sistema de archivos de Windows debe estar montado previamente. |
---|
370 | #@version 0.9 - Adaptación para OpenGNSys. |
---|
371 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
372 | #@date 2009-09-24 |
---|
373 | #*/ ## |
---|
374 | function ogSetRegistryValue () |
---|
375 | { |
---|
376 | # Variables locales. |
---|
377 | local FILE |
---|
378 | |
---|
379 | # Si se solicita, mostrar ayuda. |
---|
380 | if [ "$*" == "help" ]; then |
---|
381 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_valuename str_data" |
---|
382 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1' 1" |
---|
383 | return |
---|
384 | fi |
---|
385 | # Error si no se reciben 4 parámetros. |
---|
386 | [ $# == 4 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
387 | # Camino del fichero de registro. |
---|
388 | FILE=$(ogGetHivePath "$1" "$2") || return $? |
---|
389 | |
---|
390 | # Cambiar el dato del valor de registro. |
---|
391 | chntpw "$FILE" << EOT &> /dev/null |
---|
392 | cd ${3%\\*} |
---|
393 | ed ${3##*\\} |
---|
394 | $4 |
---|
395 | q |
---|
396 | y |
---|
397 | EOT |
---|
398 | } |
---|
399 | |
---|