2 * A program to modify a registry file.
4 * Copyright (C) 2007 Alan Nisota
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "loader/registry.c"
29 #define mp_msg(t, l, m, args...) fprintf(stderr, m, ##args)
31 #define mp_msg(t, l, ...) fprintf(stderr, __VA_ARGS__)
36 static void remove_key(long handle
, const char* name
) {
40 fullname
= build_keyname(handle
, name
);
41 len
= strlen(fullname
);
42 for (i
=0; i
< reg_size
;) {
43 if (!strncmp(regs
[i
].name
, fullname
, len
)) {
46 memmove(®s
[i
], ®s
[i
+1], --reg_size
*sizeof(struct reg_value
));
55 static void parse_key(char *raw
, HKEY
*root
, char *path
, char *key
) {
57 tmpkey
= strrchr(raw
, '\\');
58 if (tmpkey
== raw
|| tmpkey
== NULL
) {
59 printf("Couldn't process key \"%s\"\n", raw
);
62 start
= strchr(raw
, '\\');
63 if (start
== raw
|| start
== NULL
) {
64 printf("Couldn't process key \"%s\"\n", raw
);
67 if (strncmp(raw
, "HKEY_CURRENT_USER\\", 18) == 0 ||
68 strncmp(raw
, "HKCU\\", 5) == 0) {
69 *root
= HKEY_CURRENT_USER
;
70 } else if (strncmp(raw
, "HKEY_LOCAL_MACHINE\\", 19) == 0 ||
71 strncmp(raw
, "HKLM\\", 5) == 0) {
72 *root
= HKEY_LOCAL_MACHINE
;
74 printf("Couldn't process key \"%s\"\n", raw
);
77 strncpy(key
, tmpkey
+ 1, strlen(tmpkey
)-1);
78 key
[strlen(tmpkey
)-1] = 0;
81 while(*(tmpkey
-1) == '\\')
83 strncpy(path
, start
, tmpkey
- start
);
84 path
[tmpkey
- start
] = 0;
87 int main(int argc
, char *argv
[]) {
90 char c
, path
[256], key
[256], *value
= NULL
;
93 int list
= 0, del
= 0;
95 static struct option Long_Options
[] = {
96 {"registry", 1, 0, 'r'},
104 c
= getopt_long(argc
, argv
, "r:lk:v:t:id", Long_Options
, &Option_Index
);
109 localregpathname
= optarg
;
115 parse_key(optarg
, &root
, path
, key
);
121 if (!strcmp(optarg
, "string"))
123 else if (!strcmp(optarg
, "dword"))
131 if (localregpathname
== NULL
|| (! list
&& ! root
)) {
132 printf("Must specify '-r' and either '-k' or '-l'\n");
135 if (del
&& (list
|| value
)) {
136 printf("Can't specify '-d' along with '-l' or '-v'\n");
140 insert_handle(HKEY_LOCAL_MACHINE
, "HKLM");
141 insert_handle(HKEY_CURRENT_USER
, "HKCU");
145 sprintf(tmpname
, "%s\\%s", path
, key
);
146 remove_key(root
, tmpname
);
151 for (i
=0; i
< reg_size
; i
++) {
152 if (regs
[i
].type
== DIR) {
153 printf("Directory: %s\n", regs
[i
].name
);
154 } else if (regs
[i
].type
== REG_DWORD
) {
155 DWORD v
= *(DWORD
*)regs
[i
].value
;
156 printf("%s :: %08x type: DWORD\n", regs
[i
].name
, v
);
157 } else if (regs
[i
].type
== REG_SZ
) {
158 printf("%s :: '%s' len: %d type: String\n",
159 regs
[i
].name
, regs
[i
].value
, regs
[i
].len
);
161 printf("%s :: '%s' len: %d type: %08x\n",
162 regs
[i
].name
, regs
[i
].value
, regs
[i
].len
, regs
[i
].type
);
167 RegCreateKeyExA(root
, path
, 0, 0, 0, 0, 0, &newkey
, &status
);
171 if (type
== REG_DWORD
) {
173 v
= strtoul(value
, NULL
, 0);
176 len
= strlen(value
)+1;
177 printf("%08x -- %d\n", *value
, len
);
178 RegSetValueExA(newkey
, key
, 0, type
, value
, len
);