| 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.1.0 | 
|---|
| 8 | #@warning License: GNU GPLv3+ | 
|---|
| 9 | #*/ | 
|---|
| 10 |  | 
|---|
| 11 |  | 
|---|
| 12 | # Función ficticia para lanzar chntpw con timeout de 5 s., evitando cuelgues del programa. | 
|---|
| 13 | function chntpw () | 
|---|
| 14 | { | 
|---|
| 15 | local CHNTPW | 
|---|
| 16 | CHNTPW=$(which drbl-chntpw) | 
|---|
| 17 | CHNTPW=${CHNTPW:-$(which chntpw)} | 
|---|
| 18 | timeout --foreground 5s $CHNTPW "$@" | 
|---|
| 19 | } | 
|---|
| 20 |  | 
|---|
| 21 |  | 
|---|
| 22 | #/** | 
|---|
| 23 | #         ogAddRegistryKey path_mountpoint str_hive str_keyname | 
|---|
| 24 | #@brief   Añade una nueva clave al registro de Windows. | 
|---|
| 25 | #@param   path_mountpoint  directorio donde está montado el sistema Windows | 
|---|
| 26 | #@param   str_hive         sección del registro | 
|---|
| 27 | #@param   str_keyname      nombre de la clave | 
|---|
| 28 | #@return  (nada) | 
|---|
| 29 | #@exception OG_ERR_FORMAT    Formato incorrecto. | 
|---|
| 30 | #@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado. | 
|---|
| 31 | #@note    hive = { default, sam, security, software, system, components } | 
|---|
| 32 | #@warning Requisitos: chntpw | 
|---|
| 33 | #@warning El sistema de archivos de Windows debe estar montada previamente. | 
|---|
| 34 | #@version 1.0.1 - Nueva función | 
|---|
| 35 | #@author  Ramon Gomez, ETSII Universidad de Sevilla | 
|---|
| 36 | #@date    2011-05-25 | 
|---|
| 37 | #*/ ## | 
|---|
| 38 | function ogAddRegistryKey () | 
|---|
| 39 | { | 
|---|
| 40 | # Variables locales. | 
|---|
| 41 | local FILE | 
|---|
| 42 |  | 
|---|
| 43 | # Si se solicita, mostrar ayuda. | 
|---|
| 44 | if [ "$*" == "help" ]; then | 
|---|
| 45 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_key" \ | 
|---|
| 46 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey'" | 
|---|
| 47 | return | 
|---|
| 48 | fi | 
|---|
| 49 | # Error si no se reciben 3 parámetros. | 
|---|
| 50 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? | 
|---|
| 51 | # Camino del fichero de registro. | 
|---|
| 52 | FILE=$(ogGetHivePath "$1" "$2") || return $? | 
|---|
| 53 |  | 
|---|
| 54 | # Añadir nueva clave. | 
|---|
| 55 | chntpw "$FILE" << EOT &> /dev/null | 
|---|
| 56 | cd ${3%\\*} | 
|---|
| 57 | nk ${3##*\\} | 
|---|
| 58 | q | 
|---|
| 59 | y | 
|---|
| 60 | EOT | 
|---|
| 61 | } | 
|---|
| 62 |  | 
|---|
| 63 | #/** | 
|---|
| 64 | #         ogAddRegistryValue path_mountpoint str_hive str_valuename [str_valuetype] | 
|---|
| 65 | #@brief   Añade un nuevo valor al registro de Windows, indicando su tipo de datos. | 
|---|
| 66 | #@param   path_mountpoint  directorio donde está montado el sistema Windows | 
|---|
| 67 | #@param   str_hive         sección del registro | 
|---|
| 68 | #@param   str_valuename    nombre del valor | 
|---|
| 69 | #@param   str_valuetype    tipo de datos del valor (opcional) | 
|---|
| 70 | #@return  (nada) | 
|---|
| 71 | #@exception OG_ERR_FORMAT    Formato incorrecto. | 
|---|
| 72 | #@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado. | 
|---|
| 73 | #@note    hive = { DEFAULT, SAM, SECURITY, SOFTWARE, SYSTEM, COMPONENTS } | 
|---|
| 74 | #@note    valuetype = { STRING, BINARY, DWORD }, por defecto: STRING | 
|---|
| 75 | #@warning Requisitos: chntpw | 
|---|
| 76 | #@warning El sistema de archivos de Windows debe estar montada previamente. | 
|---|
| 77 | #@version 1.0.1 - Nueva función | 
|---|
| 78 | #@author  Ramon Gomez, ETSII Universidad de Sevilla | 
|---|
| 79 | #@date    2011-05-25 | 
|---|
| 80 | #*/ ## | 
|---|
| 81 | function ogAddRegistryValue () | 
|---|
| 82 | { | 
|---|
| 83 | # Variables locales. | 
|---|
| 84 | local FILE TYPE | 
|---|
| 85 |  | 
|---|
| 86 | # Si se solicita, mostrar ayuda. | 
|---|
| 87 | if [ "$*" == "help" ]; then | 
|---|
| 88 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_valuename [str_valuetype]" \ | 
|---|
| 89 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1'" \ | 
|---|
| 90 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1' DWORD" | 
|---|
| 91 | return | 
|---|
| 92 | fi | 
|---|
| 93 | # Error si no se reciben 3 o 4 parámetros. | 
|---|
| 94 | [ $# == 3 -o $# == 4 ] || ogRaiseError $OG_ERR_FORMAT || return $? | 
|---|
| 95 | # Camino del fichero de registro. | 
|---|
| 96 | FILE=$(ogGetHivePath "$1" "$2") || return $? | 
|---|
| 97 | case "${4^^}" in | 
|---|
| 98 | STRING|"")  TYPE=1 ;; | 
|---|
| 99 | BINARY)     TYPE=3 ;; | 
|---|
| 100 | DWORD)      TYPE=4 ;; | 
|---|
| 101 | *)          ogRaiseError $OG_ERR_OUTOFLIMIT "$4" | 
|---|
| 102 | return $? ;; | 
|---|
| 103 | esac | 
|---|
| 104 |  | 
|---|
| 105 | # Devolver el dato del valor de registro. | 
|---|
| 106 | # /* (comentario Doxygen) | 
|---|
| 107 | chntpw "$FILE" << EOT &> /dev/null | 
|---|
| 108 | cd ${3%\\*} | 
|---|
| 109 | nv $TYPE ${3##*\\} | 
|---|
| 110 | q | 
|---|
| 111 | y | 
|---|
| 112 | EOT | 
|---|
| 113 | # (comentario Doxygen) */ | 
|---|
| 114 | } | 
|---|
| 115 |  | 
|---|
| 116 |  | 
|---|
| 117 | #/** | 
|---|
| 118 | #         ogDeleteRegistryKey path_mountpoint str_hive str_keyname | 
|---|
| 119 | #@brief   Elimina una clave del registro de Windows con todo su contenido. | 
|---|
| 120 | #@param   path_mountpoint  directorio donde está montado el sistema Windows | 
|---|
| 121 | #@param   str_hive         sección del registro | 
|---|
| 122 | #@param   str_keyname      nombre de la clave | 
|---|
| 123 | #@return  (nada) | 
|---|
| 124 | #@exception OG_ERR_FORMAT    Formato incorrecto. | 
|---|
| 125 | #@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado. | 
|---|
| 126 | #@note    hive = { default, sam, security, software, system, components } | 
|---|
| 127 | #@warning Requisitos: chntpw | 
|---|
| 128 | #@warning El sistema de archivos de Windows debe estar montada previamente. | 
|---|
| 129 | #@warning La clave debe estar vacía para poder ser borrada. | 
|---|
| 130 | #@version 1.0.1 - Nueva función | 
|---|
| 131 | #@author  Ramon Gomez, ETSII Universidad de Sevilla | 
|---|
| 132 | #@date    2011-05-25 | 
|---|
| 133 | #*/ ## | 
|---|
| 134 | function ogDeleteRegistryKey () | 
|---|
| 135 | { | 
|---|
| 136 | # Variables locales. | 
|---|
| 137 | local FILE | 
|---|
| 138 |  | 
|---|
| 139 | # Si se solicita, mostrar ayuda. | 
|---|
| 140 | if [ "$*" == "help" ]; then | 
|---|
| 141 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_key" \ | 
|---|
| 142 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey'" | 
|---|
| 143 | return | 
|---|
| 144 | fi | 
|---|
| 145 | # Error si no se reciben 3 parámetros. | 
|---|
| 146 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? | 
|---|
| 147 | # Camino del fichero de registro. | 
|---|
| 148 | FILE=$(ogGetHivePath "$1" "$2") || return $? | 
|---|
| 149 |  | 
|---|
| 150 | # Añadir nueva clave. | 
|---|
| 151 | chntpw "$FILE" << EOT &> /dev/null | 
|---|
| 152 | cd ${3%\\*} | 
|---|
| 153 | dk ${3##*\\} | 
|---|
| 154 | q | 
|---|
| 155 | y | 
|---|
| 156 | EOT | 
|---|
| 157 | } | 
|---|
| 158 |  | 
|---|
| 159 |  | 
|---|
| 160 | #/** | 
|---|
| 161 | #         ogDeleteRegistryValue path_mountpoint str_hive str_valuename | 
|---|
| 162 | #@brief   Elimina un valor del registro de Windows. | 
|---|
| 163 | #@param   path_mountpoint  directorio donde está montado el sistema Windows | 
|---|
| 164 | #@param   str_hive         sección del registro | 
|---|
| 165 | #@param   str_valuename    nombre del valor | 
|---|
| 166 | #@return  (nada) | 
|---|
| 167 | #@exception OG_ERR_FORMAT    Formato incorrecto. | 
|---|
| 168 | #@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado. | 
|---|
| 169 | #@note    hive = { default, sam, security, software, system, components } | 
|---|
| 170 | #@warning Requisitos: chntpw | 
|---|
| 171 | #@warning El sistema de archivos de Windows debe estar montada previamente. | 
|---|
| 172 | #@version 1.0.1 - Nueva función | 
|---|
| 173 | #@author  Ramon Gomez, ETSII Universidad de Sevilla | 
|---|
| 174 | #@date    2011-05-25 | 
|---|
| 175 | #*/ ## | 
|---|
| 176 | function ogDeleteRegistryValue () | 
|---|
| 177 | { | 
|---|
| 178 | # Variables locales. | 
|---|
| 179 | local FILE | 
|---|
| 180 |  | 
|---|
| 181 | # Si se solicita, mostrar ayuda. | 
|---|
| 182 | if [ "$*" == "help" ]; then | 
|---|
| 183 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_valuename" \ | 
|---|
| 184 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1'" | 
|---|
| 185 | return | 
|---|
| 186 | fi | 
|---|
| 187 | # Error si no se reciben 3 parámetros. | 
|---|
| 188 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? | 
|---|
| 189 | # Camino del fichero de registro. | 
|---|
| 190 | FILE=$(ogGetHivePath "$1" "$2") || return $? | 
|---|
| 191 |  | 
|---|
| 192 | # Devolver el dato del valor de registro. | 
|---|
| 193 | # /* (comentario Doxygen) | 
|---|
| 194 | chntpw "$FILE" << EOT &> /dev/null | 
|---|
| 195 | cd ${3%\\*} | 
|---|
| 196 | dv ${3##*\\} | 
|---|
| 197 | q | 
|---|
| 198 | y | 
|---|
| 199 | EOT | 
|---|
| 200 | # (comentario Doxygen) */ | 
|---|
| 201 | } | 
|---|
| 202 |  | 
|---|
| 203 |  | 
|---|
| 204 | #/** | 
|---|
| 205 | #         ogGetHivePath path_mountpoint [str_hive|str_user] | 
|---|
| 206 | #@brief   Función básica que devuelve el camino del fichero con una sección del registro. | 
|---|
| 207 | #@param   path_mountpoint  directorio donde está montado el sistema Windows | 
|---|
| 208 | #@param   str_hive         sección del registro | 
|---|
| 209 | #@return  str_path - camino del fichero de registro | 
|---|
| 210 | #@exception OG_ERR_FORMAT    Formato incorrecto. | 
|---|
| 211 | #@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado. | 
|---|
| 212 | #@note    hive = { DEFAULT, SAM, SECURITY, SOFTWARE, SYSTEM, COMPONENTS, NombreDeUsuario } | 
|---|
| 213 | #@warning El sistema de archivos de Windows debe estar montada previamente. | 
|---|
| 214 | #@version 1.0.1 - Nueva función | 
|---|
| 215 | #@author  Ramon Gomez, ETSII Universidad de Sevilla | 
|---|
| 216 | #@date    2011-05-18 | 
|---|
| 217 | #@version 1.1.0 - Soportar registro de un usuario local. | 
|---|
| 218 | #@author  Ramon Gomez, ETSII Universidad de Sevilla | 
|---|
| 219 | #@date    2015-10-14 | 
|---|
| 220 | #*/ ## | 
|---|
| 221 | function ogGetHivePath () | 
|---|
| 222 | { | 
|---|
| 223 | # Variables locales. | 
|---|
| 224 | local FILE HIVE | 
|---|
| 225 |  | 
|---|
| 226 | # Si se solicita, mostrar ayuda. | 
|---|
| 227 | if [ "$*" == "help" ]; then | 
|---|
| 228 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint [str_hive|str_user]" \ | 
|---|
| 229 | "$FUNCNAME /mnt/sda1 SOFTWARE  =>  /mnt/sda1/WINDOWS/System32/config/SOFTWARE" \ | 
|---|
| 230 | "$FUNCNAME /mnt/sda1 user1  =>  /mnt/sda1/Users/user1/NTUSER.DAT" | 
|---|
| 231 | return | 
|---|
| 232 | fi | 
|---|
| 233 | # Error si no se reciben 2 parámetros. | 
|---|
| 234 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? | 
|---|
| 235 |  | 
|---|
| 236 | # Camino del fichero de registro de usuario o de sistema (de menor a mayor prioridad). | 
|---|
| 237 | for FILE in $(ogGetPath "/$1/Documents and Settings/$2/NTUSER.DAT") \ | 
|---|
| 238 | $(ogGetPath "/$1/Users/$2/NTUSER.DAT") \ | 
|---|
| 239 | $(ogGetPath "/$1/winnt/system32/config/$2") \ | 
|---|
| 240 | $(ogGetPath "/$1/windows/system32/config/$2"); do | 
|---|
| 241 | [ -f "$FILE" ] && HIVE="$FILE" | 
|---|
| 242 | done | 
|---|
| 243 | # Error si no se encuentra el fichero de registro. | 
|---|
| 244 | [ -f "$HIVE" ] || ogRaiseError $OG_ERR_NOTFOUND "$1 $2" || return $? | 
|---|
| 245 |  | 
|---|
| 246 | echo "$HIVE" | 
|---|
| 247 | } | 
|---|
| 248 |  | 
|---|
| 249 |  | 
|---|
| 250 | #/** | 
|---|
| 251 | #         ogGetRegistryValue path_mountpoint str_hive str_valuename | 
|---|
| 252 | #@brief   Devuelve el dato de un valor del registro de Windows. | 
|---|
| 253 | #@param   path_mountpoint  directorio donde está montado el sistema Windows | 
|---|
| 254 | #@param   str_hive         sección del registro | 
|---|
| 255 | #@param   str_valuename    nombre del valor | 
|---|
| 256 | #@return  str_valuedata - datos del valor. | 
|---|
| 257 | #@exception OG_ERR_FORMAT    Formato incorrecto. | 
|---|
| 258 | #@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado. | 
|---|
| 259 | #@note    hive = { default, sam, security, software, system, components } | 
|---|
| 260 | #@warning Requisitos: chntpw, awk | 
|---|
| 261 | #@warning El sistema de archivos de Windows debe estar montado previamente. | 
|---|
| 262 | #@version 0.9 - Adaptación para OpenGNSys. | 
|---|
| 263 | #@author  Ramon Gomez, ETSII Universidad de Sevilla | 
|---|
| 264 | #@date    2009-09-11 | 
|---|
| 265 | #@version 1.1.0 - Soportar tipos BINARY (parejas hexadecimales separadas por espacio). | 
|---|
| 266 | #@author  Ramon Gomez, ETSII Universidad de Sevilla | 
|---|
| 267 | #@date    2015-09-28 | 
|---|
| 268 | #*/ ## | 
|---|
| 269 | function ogGetRegistryValue () | 
|---|
| 270 | { | 
|---|
| 271 | # Variables locales. | 
|---|
| 272 | local FILE | 
|---|
| 273 |  | 
|---|
| 274 | # Si se solicita, mostrar ayuda. | 
|---|
| 275 | if [ "$*" == "help" ]; then | 
|---|
| 276 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_valuename" \ | 
|---|
| 277 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1'  ==>  1" | 
|---|
| 278 | return | 
|---|
| 279 | fi | 
|---|
| 280 | # Error si no se reciben 3 parámetros. | 
|---|
| 281 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? | 
|---|
| 282 | # Camino del fichero de registro. | 
|---|
| 283 | FILE=$(ogGetHivePath "$1" "$2") || return $? | 
|---|
| 284 |  | 
|---|
| 285 | # Devolver el dato del valor de registro. | 
|---|
| 286 | # /* (comentario Doxygen) | 
|---|
| 287 | chntpw "$FILE" << EOT 2> /dev/null | awk '/> Value/ {if (index($0, "REG_BINARY") > 0) | 
|---|
| 288 | {data=""} | 
|---|
| 289 | else | 
|---|
| 290 | {getline; data=$0;} } | 
|---|
| 291 | /^:[0-9A-F]+ / {data=data""substr($0, 9, 48);} | 
|---|
| 292 | END {print data;}' | 
|---|
| 293 | cd ${3%\\*} | 
|---|
| 294 | cat ${3##*\\} | 
|---|
| 295 | q | 
|---|
| 296 | EOT | 
|---|
| 297 | # (comentario Doxygen) */ | 
|---|
| 298 | } | 
|---|
| 299 |  | 
|---|
| 300 |  | 
|---|
| 301 | #/** | 
|---|
| 302 | #         ogListRegistryKeys path_mountpoint str_hive str_key | 
|---|
| 303 | #@brief   Lista los nombres de subclaves de una determinada clave del registro de Windows. | 
|---|
| 304 | #@param   path_mountpoint  directorio donde está montado el sistema Windows | 
|---|
| 305 | #@param   str_hive         sección del registro | 
|---|
| 306 | #@param   str_key          clave de registro | 
|---|
| 307 | #@return  str_subkey ... - lista de subclaves | 
|---|
| 308 | #@exception OG_ERR_FORMAT    Formato incorrecto. | 
|---|
| 309 | #@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado. | 
|---|
| 310 | #@note    hive = { default, sam, security, software, system, components } | 
|---|
| 311 | #@warning Requisitos: chntpw, awk | 
|---|
| 312 | #@warning El sistema de archivos de Windows debe estar montado previamente. | 
|---|
| 313 | #@version 0.9 - Adaptación para OpenGNSys. | 
|---|
| 314 | #@author  Ramon Gomez, ETSII Universidad de Sevilla | 
|---|
| 315 | #@date    2009-09-23 | 
|---|
| 316 | #*/ ## | 
|---|
| 317 | function ogListRegistryKeys () | 
|---|
| 318 | { | 
|---|
| 319 | # Variables locales. | 
|---|
| 320 | local FILE | 
|---|
| 321 |  | 
|---|
| 322 | # Si se solicita, mostrar ayuda. | 
|---|
| 323 | if [ "$*" == "help" ]; then | 
|---|
| 324 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_key" \ | 
|---|
| 325 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\Windows\CurrentVersion'" | 
|---|
| 326 | return | 
|---|
| 327 | fi | 
|---|
| 328 | # Error si no se reciben 3 parámetros. | 
|---|
| 329 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? | 
|---|
| 330 |  | 
|---|
| 331 | # Camino del fichero de registro. | 
|---|
| 332 | FILE=$(ogGetHivePath "$1" "$2") || return $? | 
|---|
| 333 |  | 
|---|
| 334 | # Devolver la lista de claves de registro. | 
|---|
| 335 | chntpw "$FILE" << EOT 2> /dev/null | awk 'BEGIN {FS="[<>]"} $1~/^  $/ {print $2}' | 
|---|
| 336 | ls $3 | 
|---|
| 337 | q | 
|---|
| 338 | EOT | 
|---|
| 339 | } | 
|---|
| 340 |  | 
|---|
| 341 |  | 
|---|
| 342 | #/** | 
|---|
| 343 | #         ogListRegistryValues path_mountpoint str_hive str_key | 
|---|
| 344 | #@brief   Lista los nombres de valores de una determinada clave del registro de Windows. | 
|---|
| 345 | #@param   path_mountpoint  directorio donde está montado el sistema Windows | 
|---|
| 346 | #@param   str_hive         sección del registro | 
|---|
| 347 | #@param   str_key          clave de registro | 
|---|
| 348 | #@return  str_value ... - lista de valores | 
|---|
| 349 | #@exception OG_ERR_FORMAT    Formato incorrecto. | 
|---|
| 350 | #@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado. | 
|---|
| 351 | #@note    hive = { default, sam, security, software, system, components } | 
|---|
| 352 | #@warning Requisitos: chntpw, awk | 
|---|
| 353 | #@warning El sistema de archivos de Windows debe estar montado previamente. | 
|---|
| 354 | #@version 1.0.1 - Nueva función. | 
|---|
| 355 | #@author  Ramon Gomez, ETSII Universidad de Sevilla | 
|---|
| 356 | #@date    2011-05-26 | 
|---|
| 357 | #*/ ## | 
|---|
| 358 | function ogListRegistryValues () | 
|---|
| 359 | { | 
|---|
| 360 | # Variables locales. | 
|---|
| 361 | local FILE | 
|---|
| 362 |  | 
|---|
| 363 | # Si se solicita, mostrar ayuda. | 
|---|
| 364 | if [ "$*" == "help" ]; then | 
|---|
| 365 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_key" \ | 
|---|
| 366 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\Windows\CurrentVersion'" | 
|---|
| 367 | return | 
|---|
| 368 | fi | 
|---|
| 369 | # Error si no se reciben 3 parámetros. | 
|---|
| 370 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? | 
|---|
| 371 | # Camino del fichero de registro. | 
|---|
| 372 | FILE=$(ogGetHivePath "$1" "$2") || return $? | 
|---|
| 373 |  | 
|---|
| 374 | # Devolver la lista de claves de registro. | 
|---|
| 375 | chntpw "$FILE" << EOT 2> /dev/null | awk 'BEGIN {FS="[<>]"} $1~/REG_/ {print $2}' | 
|---|
| 376 | ls $3 | 
|---|
| 377 | q | 
|---|
| 378 | EOT | 
|---|
| 379 | } | 
|---|
| 380 |  | 
|---|
| 381 |  | 
|---|
| 382 | #/** | 
|---|
| 383 | #         ogSetRegistryValue path_mountpoint str_hive str_valuename str_valuedata | 
|---|
| 384 | #@brief   Establece el dato asociado a un valor del registro de Windows. | 
|---|
| 385 | #@param   path_mountpoint  directorio donde está montado el sistema Windows | 
|---|
| 386 | #@param   str_hive         sección del registro | 
|---|
| 387 | #@param   str_valuename    nombre del valor de registro | 
|---|
| 388 | #@param   str_valuedata    dato del valor de registro | 
|---|
| 389 | #@return  (nada) | 
|---|
| 390 | #@exception OG_ERR_FORMAT    Formato incorrecto. | 
|---|
| 391 | #@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado. | 
|---|
| 392 | #@note    hive = { default, sam, security, software, system, components } | 
|---|
| 393 | #@warning Requisitos: chntpw | 
|---|
| 394 | #@warning El sistema de archivos de Windows debe estar montado previamente. | 
|---|
| 395 | #@version 0.9 - Adaptación para OpenGNSys. | 
|---|
| 396 | #@author  Ramon Gomez, ETSII Universidad de Sevilla | 
|---|
| 397 | #@date    2009-09-24 | 
|---|
| 398 | #@version 1.1.0 - Soportar tipos BINARY (parejas hexadecimales separadas por espacio). | 
|---|
| 399 | #@author  Ramon Gomez, ETSII Universidad de Sevilla | 
|---|
| 400 | #@date    2015-09-28 | 
|---|
| 401 | #*/ ## | 
|---|
| 402 | function ogSetRegistryValue () | 
|---|
| 403 | { | 
|---|
| 404 | # Variables locales. | 
|---|
| 405 | local FILE i n tmpfile | 
|---|
| 406 |  | 
|---|
| 407 | # Si se solicita, mostrar ayuda. | 
|---|
| 408 | if [ "$*" == "help" ]; then | 
|---|
| 409 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_valuename str_data" \ | 
|---|
| 410 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Key\SubKey\StringValue' \"Abcde Fghij\"" \ | 
|---|
| 411 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Key\SubKey\DwordValue' 1" \ | 
|---|
| 412 | "$FUNCNAME /mnt/sda1 SOFTWARE '\Key\SubKey\BinaryValue' \"04 08 0C 10\"" | 
|---|
| 413 | return | 
|---|
| 414 | fi | 
|---|
| 415 | # Error si no se reciben 4 parámetros. | 
|---|
| 416 | [ $# == 4 ] || ogRaiseError $OG_ERR_FORMAT || return $? | 
|---|
| 417 | # Camino del fichero de registro. | 
|---|
| 418 | FILE=$(ogGetHivePath "$1" "$2") || return $? | 
|---|
| 419 |  | 
|---|
| 420 | # Fichero temporal para componer la entrada al comando "chntpw". | 
|---|
| 421 | tmpfile=/tmp/chntpw$$ | 
|---|
| 422 | trap "rm -f $tmpfile" 1 2 3 9 15 | 
|---|
| 423 |  | 
|---|
| 424 | # Comprobar tipo de datos del valor del registro. | 
|---|
| 425 | cat << EOT >$tmpfile | 
|---|
| 426 | ls ${3%\\*} | 
|---|
| 427 | q | 
|---|
| 428 | EOT | 
|---|
| 429 | if [ -n "$(chntpw "$FILE" < $tmpfile 2> /dev/null | grep "BINARY.*<${3##*\\}>")" ]; then | 
|---|
| 430 | # Procesar tipo binario (incluir nº de bytes y líneas de 16 parejas hexadecimales). | 
|---|
| 431 | [[ "$4 " =~ ^([0-9A-F]{2} )*$ ]] || ogRaiseError $OG_ERR_FORMAT "\"$4\"" || return $? | 
|---|
| 432 | let n=${#4}+1 | 
|---|
| 433 | cat << EOT >$tmpfile | 
|---|
| 434 | cd ${3%\\*} | 
|---|
| 435 | ed ${3##*\\} | 
|---|
| 436 | $[n/3] | 
|---|
| 437 | EOT | 
|---|
| 438 | # Formato de líneas hexadecimales:   :OFFSET  XX YY ZZ ... (hasta 16 parejas). | 
|---|
| 439 | for (( i=0; i<n; i+=48 )); do | 
|---|
| 440 | printf ":%05x  %s\n" $[i/3] "${4:$i:48}" >> $tmpfile | 
|---|
| 441 | done | 
|---|
| 442 | echo -e "s\nq\ny" >> $tmpfile | 
|---|
| 443 | else | 
|---|
| 444 | # Cambiar el dato del valor de registro para cadenas y bytes. | 
|---|
| 445 | cat << EOT >$tmpfile | 
|---|
| 446 | cd ${3%\\*} | 
|---|
| 447 | ed ${3##*\\} | 
|---|
| 448 | $4 | 
|---|
| 449 | q | 
|---|
| 450 | y | 
|---|
| 451 | EOT | 
|---|
| 452 |  | 
|---|
| 453 | fi | 
|---|
| 454 |  | 
|---|
| 455 | # Aplicar cambios. | 
|---|
| 456 | chntpw "$FILE" < $tmpfile &> /dev/null | 
|---|
| 457 | rm -f $tmpfile | 
|---|
| 458 | } | 
|---|
| 459 |  | 
|---|
| 460 |  | 
|---|