📄 fhandler_registry.cc
字号:
/* We get here if `buf' contains valid data. */ if (*buf == 0) strcpy (dir->__d_dirent->d_name, DEFAULT_VALUE_NAME); else strcpy (dir->__d_dirent->d_name, buf); dir->__d_position++; if (dir->__d_position & REG_ENUM_VALUES_MASK) dir->__d_position += 0x10000; res = dir->__d_dirent;out: syscall_printf ("%p = readdir (%p)", &dir->__d_dirent, dir); return res;}__off64_tfhandler_registry::telldir (DIR * dir){ return dir->__d_position & REG_POSITION_MASK;}voidfhandler_registry::seekdir (DIR * dir, __off64_t loc){ /* Unfortunately cannot simply set __d_position due to transition from sub-keys to * values. */ rewinddir (dir); while (loc > (dir->__d_position & REG_POSITION_MASK)) if (!readdir (dir)) break;}voidfhandler_registry::rewinddir (DIR * dir){ if (dir->__d_u.__d_data.__handle != INVALID_HANDLE_VALUE) { (void) RegCloseKey ((HKEY) dir->__d_u.__d_data.__handle); dir->__d_u.__d_data.__handle = INVALID_HANDLE_VALUE; } dir->__d_position = 0; return;}intfhandler_registry::closedir (DIR * dir){ int res = 0; if (dir->__d_u.__d_data.__handle != INVALID_HANDLE_VALUE && RegCloseKey ((HKEY) dir->__d_u.__d_data.__handle) != ERROR_SUCCESS) { __seterrno (); res = -1; } syscall_printf ("%d = closedir (%p)", res, dir); return 0;}intfhandler_registry::open (path_conv * pc, int flags, mode_t mode){ int pathlen; const char *file; HKEY handle; int res = fhandler_virtual::open (pc, flags, mode); if (!res) goto out; const char *path; path = get_name () + proc_len + 1 + registry_len; if (!*path) { if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) { set_errno (EEXIST); res = 0; goto out; } else if (flags & O_WRONLY) { set_errno (EISDIR); res = 0; goto out; } else { flags |= O_DIROPEN; goto success; } } path++; pathlen = strlen (path); file = path + pathlen - 1; if (SLASH_P (*file) && pathlen > 1) file--; while (!SLASH_P (*file)) file--; file++; if (file == path) { for (int i = 0; registry_listing[i]; i++) if (path_prefix_p (registry_listing[i], path, strlen (registry_listing[i]))) { if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) { set_errno (EEXIST); res = 0; goto out; } else if (flags & O_WRONLY) { set_errno (EISDIR); res = 0; goto out; } else { flags |= O_DIROPEN; goto success; } } if (flags & O_CREAT) { set_errno (EROFS); res = 0; goto out; } else { set_errno (ENOENT); res = 0; goto out; } } if (flags & O_WRONLY) { set_errno (EROFS); res = 0; goto out; } handle = open_key (path, KEY_READ, true); if (handle == (HKEY) INVALID_HANDLE_VALUE) { res = 0; goto out; } set_io_handle (handle); if (pathmatch (file, DEFAULT_VALUE_NAME)) value_name = cstrdup (""); else value_name = cstrdup (file); if (!fill_filebuf ()) { RegCloseKey (handle); res = 0; goto out; } if (flags & O_APPEND) position = filesize; else position = 0;success: res = 1; set_flags ((flags & ~O_TEXT) | O_BINARY); set_open_status ();out: syscall_printf ("%d = fhandler_registry::open (%p, %d)", res, flags, mode); return res;}intfhandler_registry::close (){ int res = fhandler_virtual::close (); if (res != 0) return res; HKEY handle = (HKEY) get_handle (); if (handle != (HKEY) INVALID_HANDLE_VALUE) { if (RegCloseKey (handle) != ERROR_SUCCESS) { __seterrno (); res = -1; } } if (value_name) cfree (value_name); return res;}boolfhandler_registry::fill_filebuf (){ DWORD type, size; LONG error; HKEY handle = (HKEY) get_handle (); if (handle != HKEY_PERFORMANCE_DATA) { error = RegQueryValueEx (handle, value_name, NULL, &type, NULL, &size); if (error != ERROR_SUCCESS) { if (error != ERROR_FILE_NOT_FOUND) { seterrno_from_win_error (__FILE__, __LINE__, error); return false; } goto value_not_found; } bufalloc = size; filebuf = (char *) malloc (bufalloc); error = RegQueryValueEx (handle, value_name, NULL, NULL, (BYTE *) filebuf, &size); if (error != ERROR_SUCCESS) { seterrno_from_win_error (__FILE__, __LINE__, error); return true; } filesize = size; } else { bufalloc = 0; do { bufalloc += 1000; filebuf = (char *) realloc (filebuf, bufalloc); error = RegQueryValueEx (handle, value_name, NULL, &type, (BYTE *) filebuf, &size); if (error != ERROR_SUCCESS && error != ERROR_MORE_DATA) { if (error != ERROR_FILE_NOT_FOUND) { seterrno_from_win_error (__FILE__, __LINE__, error); return true; } goto value_not_found; } } while (error == ERROR_MORE_DATA); filesize = size; } return true;value_not_found: DWORD buf_size = MAX_PATH; char buf[buf_size]; int index = 0; while (ERROR_SUCCESS == (error = RegEnumKeyEx (handle, index++, buf, &buf_size, NULL, NULL, NULL, NULL)) || (error == ERROR_MORE_DATA)) { if (pathmatch (buf, value_name)) { set_errno (EISDIR); return false; } buf_size = MAX_PATH; } if (error != ERROR_NO_MORE_ITEMS) { seterrno_from_win_error (__FILE__, __LINE__, error); return false; } set_errno (ENOENT); return false;}/* Auxillary member function to open registry keys. */static HKEYopen_key (const char *name, REGSAM access, bool isValue){ HKEY hKey = (HKEY) INVALID_HANDLE_VALUE; HKEY hParentKey = (HKEY) INVALID_HANDLE_VALUE; bool parentOpened = false; char component[MAX_PATH]; while (*name) { const char *anchor = name; while (*name && !SLASH_P (*name)) name++; strncpy (component, anchor, name - anchor); component[name - anchor] = '\0'; if (*name) name++; if (*name == 0 && isValue == true) goto out; if (hParentKey != (HKEY) INVALID_HANDLE_VALUE) { REGSAM effective_access = KEY_READ; if ((strchr (name, '/') == NULL && isValue == true) || *name == 0) effective_access = access; LONG error = RegOpenKeyEx (hParentKey, component, 0, effective_access, &hKey); if (error != ERROR_SUCCESS) { hKey = (HKEY) INVALID_HANDLE_VALUE; seterrno_from_win_error (__FILE__, __LINE__, error); return hKey; } if (parentOpened) RegCloseKey (hParentKey); hParentKey = hKey; parentOpened = true; } else { for (int i = 0; registry_listing[i]; i++) if (pathmatch (component, registry_listing[i])) hKey = registry_keys[i]; if (hKey == (HKEY) INVALID_HANDLE_VALUE) return hKey; hParentKey = hKey; } }out: return hKey;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -