* fhandler.h (fhandler_base::set_name): Make virtual.

(class fhandler_registry): Add wow64 and prefix_len members.
	Declare set_name method.
	* fhandler_proc.cc (PROC_REGISTRY32): Define.
	(PROC_REGISTRY64): Define.
	(proc_listing): Add "registry32" and "registry64" elements.
	(proc_fhandlers): Add corresponding FH_REGISTRY values.
	* fhandler_registry.cc (registry_len): Drop static value in favor of
	class member prefix_len.  Use preifx_len instead of registry_len
	throughout.
	(fhandler_registry::set_name): Define.  Set wow64 and prefix_len
	according to directory prefix.
	(fhandler_registry::fhandler_registry): Set wow64 and prefix_len to
	default values.
	(open_key): Add wow64 argument.  Handle wow64 in call to RegOpenKeyEx.
	Use fhandler_registry member wow64 in this place throughout.
This commit is contained in:
Corinna Vinschen 2006-10-19 10:01:03 +00:00
parent d145878a07
commit 20f9af5348
4 changed files with 70 additions and 24 deletions

View File

@ -1,3 +1,22 @@
2006-10-19 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (fhandler_base::set_name): Make virtual.
(class fhandler_registry): Add wow64 and prefix_len members.
Declare set_name method.
* fhandler_proc.cc (PROC_REGISTRY32): Define.
(PROC_REGISTRY64): Define.
(proc_listing): Add "registry32" and "registry64" elements.
(proc_fhandlers): Add corresponding FH_REGISTRY values.
* fhandler_registry.cc (registry_len): Drop static value in favor of
class member prefix_len. Use preifx_len instead of registry_len
throughout.
(fhandler_registry::set_name): Define. Set wow64 and prefix_len
according to directory prefix.
(fhandler_registry::fhandler_registry): Set wow64 and prefix_len to
default values.
(open_key): Add wow64 argument. Handle wow64 in call to RegOpenKeyEx.
Use fhandler_registry member wow64 in this place throughout.
2006-10-19 Corinna Vinschen <corinna@vinschen.de> 2006-10-19 Corinna Vinschen <corinna@vinschen.de>
* fhandler_proc.cc: Drop superfluous definition of _WIN32_WINNT. * fhandler_proc.cc: Drop superfluous definition of _WIN32_WINNT.

View File

@ -139,7 +139,7 @@ class fhandler_base
class fhandler_base *archetype; class fhandler_base *archetype;
int usecount; int usecount;
void set_name (path_conv &pc); virtual void set_name (path_conv &pc);
int error () const {return pc.error;} int error () const {return pc.error;}
void set_error (int error) {pc.error = error;} void set_error (int error) {pc.error = error;}
bool exists () const {return pc.exists ();} bool exists () const {return pc.exists ();}
@ -1266,8 +1266,11 @@ class fhandler_registry: public fhandler_proc
{ {
private: private:
char *value_name; char *value_name;
DWORD wow64;
int prefix_len;
public: public:
fhandler_registry (); fhandler_registry ();
void set_name (path_conv &pc);
int exists(); int exists();
int readdir (DIR *, dirent *) __attribute__ ((regparm (3))); int readdir (DIR *, dirent *) __attribute__ ((regparm (3)));
_off64_t telldir (DIR *); _off64_t telldir (DIR *);

View File

@ -42,6 +42,8 @@ static const int PROC_UPTIME = 7; // /proc/uptime
static const int PROC_CPUINFO = 8; // /proc/cpuinfo static const int PROC_CPUINFO = 8; // /proc/cpuinfo
static const int PROC_PARTITIONS = 9; // /proc/partitions static const int PROC_PARTITIONS = 9; // /proc/partitions
static const int PROC_SELF = 10; // /proc/self static const int PROC_SELF = 10; // /proc/self
static const int PROC_REGISTRY32 = 11; // /proc/registry32
static const int PROC_REGISTRY64 = 12; // /proc/registry64
/* names of objects in /proc */ /* names of objects in /proc */
static const char *proc_listing[] = { static const char *proc_listing[] = {
@ -56,6 +58,8 @@ static const char *proc_listing[] = {
"cpuinfo", "cpuinfo",
"partitions", "partitions",
"self", "self",
"registry32",
"registry64",
NULL NULL
}; };
@ -76,6 +80,8 @@ static const DWORD proc_fhandlers[PROC_LINK_COUNT] = {
FH_PROC, FH_PROC,
FH_PROC, FH_PROC,
FH_PROC, FH_PROC,
FH_REGISTRY,
FH_REGISTRY,
}; };
/* name of the /proc filesystem */ /* name of the /proc filesystem */

View File

@ -25,7 +25,6 @@ details. */
#define _COMPILING_NEWLIB #define _COMPILING_NEWLIB
#include <dirent.h> #include <dirent.h>
static const int registry_len = sizeof ("registry") - 1;
/* If this bit is set in __d_position then we are enumerating values, /* If this bit is set in __d_position then we are enumerating values,
* else sub-keys. keeping track of where we are is horribly messy * else sub-keys. keeping track of where we are is horribly messy
* the bottom 16 bits are the absolute position and the top 15 bits * the bottom 16 bits are the absolute position and the top 15 bits
@ -84,7 +83,7 @@ static const int SPECIAL_DOT_FILE_COUNT =
/* Name given to default values */ /* Name given to default values */
static const char *DEFAULT_VALUE_NAME = "@"; static const char *DEFAULT_VALUE_NAME = "@";
static HKEY open_key (const char *name, REGSAM access, bool isValue); static HKEY open_key (const char *name, REGSAM access, DWORD wow64, bool isValue);
/* Returns 0 if path doesn't exist, >0 if path is a directory, /* Returns 0 if path doesn't exist, >0 if path is a directory,
* <0 if path is a file. * <0 if path is a file.
@ -105,7 +104,7 @@ fhandler_registry::exists ()
const char *path = get_name (); const char *path = get_name ();
debug_printf ("exists (%s)", path); debug_printf ("exists (%s)", path);
path += proc_len + registry_len + 1; path += proc_len + prefix_len + 1;
if (*path) if (*path)
path++; path++;
else else
@ -133,12 +132,12 @@ fhandler_registry::exists ()
goto out; goto out;
} }
hKey = open_key (path, KEY_READ, false); hKey = open_key (path, KEY_READ, wow64, false);
if (hKey != (HKEY) INVALID_HANDLE_VALUE) if (hKey != (HKEY) INVALID_HANDLE_VALUE)
file_type = 1; file_type = 1;
else else
{ {
hKey = open_key (path, KEY_READ, true); hKey = open_key (path, KEY_READ, wow64, true);
if (hKey == (HKEY) INVALID_HANDLE_VALUE) if (hKey == (HKEY) INVALID_HANDLE_VALUE)
return 0; return 0;
@ -186,9 +185,27 @@ out:
return file_type; return file_type;
} }
void
fhandler_registry::set_name (path_conv &in_pc)
{
if (strncasematch (in_pc.normalized_path, "/proc/registry32", 16))
{
wow64 = KEY_WOW64_32KEY;
prefix_len += 2;
}
else if (strncasematch (in_pc.normalized_path, "/proc/registry64", 16))
{
wow64 = KEY_WOW64_64KEY;
prefix_len += 2;
}
fhandler_base::set_name (in_pc);
}
fhandler_registry::fhandler_registry (): fhandler_registry::fhandler_registry ():
fhandler_proc () fhandler_proc ()
{ {
wow64 = 0;
prefix_len = sizeof ("registry") - 1;
} }
int int
@ -218,9 +235,9 @@ fhandler_registry::fstat (struct __stat64 *buf)
if (file_type != 0 && file_type != 2) if (file_type != 0 && file_type != 2)
{ {
HKEY hKey; HKEY hKey;
const char *path = get_name () + proc_len + registry_len + 2; const char *path = get_name () + proc_len + prefix_len + 2;
hKey = hKey =
open_key (path, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE, open_key (path, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE, wow64,
(file_type < 0) ? true : false); (file_type < 0) ? true : false);
if (hKey != (HKEY) INVALID_HANDLE_VALUE) if (hKey != (HKEY) INVALID_HANDLE_VALUE)
@ -279,7 +296,7 @@ fhandler_registry::readdir (DIR *dir, dirent *de)
DWORD buf_size = CYG_MAX_PATH; DWORD buf_size = CYG_MAX_PATH;
char buf[buf_size]; char buf[buf_size];
HANDLE handle; HANDLE handle;
const char *path = dir->__d_dirname + proc_len + 1 + registry_len; const char *path = dir->__d_dirname + proc_len + 1 + prefix_len;
LONG error; LONG error;
int res = ENMFILE; int res = ENMFILE;
@ -294,7 +311,7 @@ fhandler_registry::readdir (DIR *dir, dirent *de)
} }
if (dir->__handle == INVALID_HANDLE_VALUE && dir->__d_position == 0) if (dir->__handle == INVALID_HANDLE_VALUE && dir->__d_position == 0)
{ {
handle = open_key (path + 1, KEY_READ, false); handle = open_key (path + 1, KEY_READ, wow64, false);
dir->__handle = handle; dir->__handle = handle;
} }
if (dir->__handle == INVALID_HANDLE_VALUE) if (dir->__handle == INVALID_HANDLE_VALUE)
@ -406,7 +423,7 @@ fhandler_registry::open (int flags, mode_t mode)
goto out; goto out;
const char *path; const char *path;
path = get_name () + proc_len + 1 + registry_len; path = get_name () + proc_len + 1 + prefix_len;
if (!*path) if (!*path)
{ {
if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
@ -482,10 +499,10 @@ fhandler_registry::open (int flags, mode_t mode)
goto out; goto out;
} }
handle = open_key (path, KEY_READ, false); handle = open_key (path, KEY_READ, wow64, false);
if (handle == (HKEY) INVALID_HANDLE_VALUE) if (handle == (HKEY) INVALID_HANDLE_VALUE)
{ {
handle = open_key (path, KEY_READ, true); handle = open_key (path, KEY_READ, wow64, true);
if (handle == (HKEY) INVALID_HANDLE_VALUE) if (handle == (HKEY) INVALID_HANDLE_VALUE)
{ {
res = 0; res = 0;
@ -626,7 +643,7 @@ value_not_found:
/* Auxillary member function to open registry keys. */ /* Auxillary member function to open registry keys. */
static HKEY static HKEY
open_key (const char *name, REGSAM access, bool isValue) open_key (const char *name, REGSAM access, DWORD wow64, bool isValue)
{ {
HKEY hKey = (HKEY) INVALID_HANDLE_VALUE; HKEY hKey = (HKEY) INVALID_HANDLE_VALUE;
HKEY hParentKey = (HKEY) INVALID_HANDLE_VALUE; HKEY hParentKey = (HKEY) INVALID_HANDLE_VALUE;
@ -652,7 +669,8 @@ open_key (const char *name, REGSAM access, bool isValue)
effective_access = access; effective_access = access;
LONG LONG
error = error =
RegOpenKeyEx (hParentKey, component, 0, effective_access, &hKey); RegOpenKeyEx (hParentKey, component, 0, effective_access | wow64,
&hKey);
if (error != ERROR_SUCCESS) if (error != ERROR_SUCCESS)
{ {
hKey = (HKEY) INVALID_HANDLE_VALUE; hKey = (HKEY) INVALID_HANDLE_VALUE;