3 * A program to modify a registry file.
5 * Copyright (C) 2007 Alan Nisota
7 * This file is part of MPlayer, a free movie player.
9 * MPlayer is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * MPlayer is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with MPlayer; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "loader/registry.c"
30 #define mp_msg(t, l, m, args...) fprintf(stderr, m, ##args)
32 #define mp_msg(t, l, ...) fprintf(stderr, __VA_ARGS__)
37 static void remove_key(long handle
, const char* name
) {
41 fullname
= build_keyname(handle
, name
);
42 len
= strlen(fullname
);
43 for (i
=0; i
< reg_size
;) {
44 if (!strncmp(regs
[i
].name
, fullname
, len
)) {
47 memmove(®s
[i
], ®s
[i
+1], --reg_size
*sizeof(struct reg_value
));
56 void parse_key(char *raw
, HKEY
*root
, char *path
, char *key
) {
58 tmpkey
= strrchr(raw
, '\\');
59 if (tmpkey
== raw
|| tmpkey
== NULL
) {
60 printf("Couldn't process key \"%s\"\n", raw
);
63 start
= strchr(raw
, '\\');
64 if (start
== raw
|| start
== NULL
) {
65 printf("Couldn't process key \"%s\"\n", raw
);
68 if (strncmp(raw
, "HKEY_CURRENT_USER\\", 18) == 0 ||
69 strncmp(raw
, "HKCU\\", 5) == 0) {
70 *root
= HKEY_CURRENT_USER
;
71 } else if (strncmp(raw
, "HKEY_LOCAL_MACHINE\\", 19) == 0 ||
72 strncmp(raw
, "HKLM\\", 5) == 0) {
73 *root
= HKEY_LOCAL_MACHINE
;
75 printf("Couldn't process key \"%s\"\n", raw
);
78 strncpy(key
, tmpkey
+ 1, strlen(tmpkey
)-1);
79 key
[strlen(tmpkey
)-1] = 0;
82 while(*(tmpkey
-1) == '\\')
84 strncpy(path
, start
, tmpkey
- start
);
85 path
[tmpkey
- start
] = 0;
88 int main(int argc
, char *argv
[]) {
91 char c
, path
[256], key
[256], *value
= NULL
;
94 int list
= 0, del
= 0;
96 static struct option Long_Options
[] = {
97 {"registry", 1, 0, 'r'},
100 {"value", 1, 0, 'v'},
105 c
= getopt_long(argc
, argv
, "r:lk:v:t:id", Long_Options
, &Option_Index
);
110 localregpathname
= optarg
;
116 parse_key(optarg
, &root
, path
, key
);
122 if (!strcmp(optarg
, "string"))
124 else if (!strcmp(optarg
, "dword"))
132 if (localregpathname
== NULL
|| (! list
&& ! root
)) {
133 printf("Must specify '-r' and either '-k' or '-l'\n");
136 if (del
&& (list
|| value
)) {
137 printf("Can't specify '-d' along with '-l' or '-v'\n");
141 insert_handle(HKEY_LOCAL_MACHINE
, "HKLM");
142 insert_handle(HKEY_CURRENT_USER
, "HKCU");
146 sprintf(tmpname
, "%s\\%s", path
, key
);
147 remove_key(root
, tmpname
);
152 for (i
=0; i
< reg_size
; i
++) {
153 if (regs
[i
].type
== DIR) {
154 printf("Directory: %s\n", regs
[i
].name
);
155 } else if (regs
[i
].type
== REG_DWORD
) {
156 DWORD v
= *(DWORD
*)regs
[i
].value
;
157 printf("%s :: %08x type: DWORD\n", regs
[i
].name
, v
);
158 } else if (regs
[i
].type
== REG_SZ
) {
159 printf("%s :: '%s' len: %d type: String\n",
160 regs
[i
].name
, regs
[i
].value
, regs
[i
].len
);
162 printf("%s :: '%s' len: %d type: %08x\n",
163 regs
[i
].name
, regs
[i
].value
, regs
[i
].len
, regs
[i
].type
);
168 RegCreateKeyExA(root
, path
, 0, 0, 0, 0, 0, &newkey
, &status
);
172 if (type
== REG_DWORD
) {
174 v
= strtoul(value
, NULL
, 0);
177 len
= strlen(value
)+1;
178 printf("%08x -- %d\n", *value
, len
);
179 RegSetValueExA(newkey
, key
, 0, type
, value
, len
);