1
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze
Unit OS12: Scripting
12.2. The Registry
3
Roadmap for Section 12.2. Registry Fundamentals Registry Structure - - PDF document
Unit OS12: Scripting 12.2. The Registry Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Roadmap for Section 12.2. Registry Fundamentals Registry Structure Registry Limits Monitoring Registry
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze
3
4
Contains information NT requires to boot & configure System-wide application settings (e.g. install directory) Per-user settings (e.g. fonts, window placement, etc.)
Provides limited remote configuration, but not management
Changing some registry entries causes action, but only if something watching for changes
WMI provides remote management (described in next section)
Hardware description (built during boot process) Performance data
5
Custom application A Custom application B Performance tool
Windows Management Instrumentation High-performance provider interface Registry DLL provider
Pdh.dll Advapi32.dll
RegQueryValueEx
PerfLib System performance DLL Performance extension DLL High-performance data provider
Performance- monitoring applications Programming Interfaces
6
Most common Registry parameters can be adjusted using a graphical NT utility But, some advanced tuning and configuration options require modifying and/or adding registry data
Windows NT4/2000 had 2 tools (Regedt32.exe and Regedit.exe)
REGEDT32.EXE
Interprets NT-specific data types, NT permission lists
REGEDIT.EXE
Doesn’t understand NT-specific data types or security But has more thorough find capability
XP/2003: single combined Regedit.exe does everything No shortcuts for these tools
7
Can compare keys, load/unload hives, add/remove/query keys, and backup/restore (useful since NT Backup can only backup local registry hives)
8
During boot (to determine which drivers, configure the system) During login (to set user preferences, such as drive letter mappings, screen saver, wallpaper, etc.) When you start applications (to read app-specific settings and per- user settings)
When you install applications or drivers When you change system, user or application settings
Interesting to check your systems for “quietness” of Registry Should use Registry change notification Windows functions
Thread sleeps until a change is made to the part of the Registry they are interested in
9
Lab: run Regedit and examine
Keys are like directories Values are like files Values have data types – like a file type Data is like the contents of a file
REG_DWORD - 32-bit integer REG_SZ - string REG_MULTISZ – array of strings REG_BINARY – array of bytes to represent arbitrary data
Allows fine grained control as to who has what access
11
Really only two “roots”: HKLM and HKU
Link to HKLM\Software\Classes - file extension associations, COM class registrations
HKEY_LOCAL_MACHINE (HKLM)
System-global static and dynamic configuration
HKEY_USERS (HKU)
Root for the loaded (logged on) user profiles
HKEY_CURRENT_USER (HKCU)
Link to profile of the user accessing this key
HKEY_CURRENT_CONFIG (HKCC)
Link to subset of HKEY_LOCAL_MACHINE - has hardware profile information
HKEY_PERFORMANCE_DATA
12
HKEY_LOCAL_MACHINE\Hardware
Hardware configuration data, resource usage, etc. Completely volatile (not saved across boots)
HKEY_LOCAL_MACHINE\SAM
Local account & groups database (for NT4 domain controllers, served as the domain account database)
HKEY_LOCAL_MACHINE\Security
System-wide security policies (for NT4 domain controllers, served as the domain security policy database)
HKEY_LOCAL_MACHINE\Software
Per-machine software data not critical for booting
HKEY_LOCAL_MACHINE\System
Controls booting and running the system (config.sys functionality) Available during bootstrap
13
This is stored in \Documents and Settings\%USERNAME%\ntuser.dat
In NT 4 it was stored in \Winnt\Profiles\%USERNAME%
Note this is just a small part of your user profile, which includes your desktop, start menu, My Documents, etc.
When a user logs on interactively When a service process configured to run under a specific user account starts RUNAS (unless /NOPROFILE specified)
14
It is the profile for the System account
E.g. Change logon desktop settings are here because Winlogon runs under System
\Documents and Settings\Default User\Ntuser.dat
The starting user profile for users logging without a profile
This does not show up in the Registry because it is not loaded
Anyone with local administrative privileges can view your documents and settings and Registry information Can override with group policies
15
A hive is a piece of registry database stored in its own file System-wide configuration information is in %systemroot%\system32\config User profile (HKEY_CURRENT_USER\...) in \Documents and Settings\…\ntuser.dat
User profile is more than just the registry settings Entire directory under \Documents and Settings (e.g. start menu, My documents, temporary files, etc)
Profile for new users is in \Documents and Settings\Default User
Registry points to loaded hives at: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\hivelist
16
Windows Backup updates them when it backs up “System State”
17
Now limited to 200 MB or # of RAM, whichever is lower Limit is due to fact that entire SYSTEM hive is loaded into memory by NTLDR (discussed in Startup and Shutdown section)
This was because registry hives were read into paged pool when loaded
Explains why there was a system registry quota (see Control Panel- >System->Performance Tab - click on Virtual Memory “Change” button)
Limited number of terminal server users
Hives are accessed as memory mapped files
Views are mapped as necessary
Registry no longer in paged pool System registry quota is gone
18
Uses transaction logging to ensure structural integrity One .LOG file per registry hive Automatically used to recover corrupt registry hives other than SYSTEM
Prior to Windows XP the system keeps a backup version of System called System.Alt
NtLdr uses System.Alt of System is corrupt
On Windows XP, Ntldr knows how to apply the registry log files to the System hive in order to repair it in cases where the system crashed during updates
19
Allows application file system and Registry changes to be undone Changes committed only when associated transaction commits Relies on Distributed Transaction Coordinator (DTC) on Vista Server to enable multi-node transactions
Documented in Vista Beta 1 SDK CreateTransaction, SetCurrentTransaction, CommitTransaction, RollbackTransaction
20
21
Hooking isn’t supported by the kernel As of XP the system call table is write- protected by default if a system has <256 MB, requiring a trick
Driver can see and modify Registry behavior Latest version of Regmon comes with two drivers: one for Server 2003 and one for previous versions Defined in a DDK header file and used by antivirus products Application Regmon Driver Regmon GUI Registry Subsystem
22
Does not see direct calls to the native Registry API from kernel-mode code
System call numbers are assigned by scripts in the build process and can change between service packs All system call functions start with code like this:
MOVE SYSCALL # -> REGISTER EXECUTE SYSTEM CALL
Regmon reads the system call numbers out of the functions
23
HKCU=HKEY_CURRENT_USER (per-user settings) HKLM=HKEY_LOCAL_MACHINE (system wide settings)
24
Double clicking on a line does this
25
Process name or registry path (or partial name) Success/failure, read/write
26
Go to end of log and look backwards to where problem occurred or is evident and focused on the last things done Compare a good log with a bad log
Have to first massage log file to remove data that differs run to run
Delete first 3 columns (they are always different: line #, time, process id)
Easy to do with Excel by deleting columns
Then compare with FC (built in tool) or Windiff (Resource Kit)
27
Search for status “NOTFOUND”
Applications query a value’s size by passing a 0-length buffer They are returned the length of the data and the overflow error and then they allocate a correctly-sized buffer and repeat the operation
28
Most applications re-create user settings when run In this way, the data won’t be seen by the application
Can always rename the key back
29
30
Value read was 0 Value was 1 on other systems
31
User somehow disabled all toolbars and menus in Word No way to open files, change settings etc.
With Regmon, captured startup of Word Found location of user-specific settings for Word Deleted this Registry key Re-ran Word, which re-created user settings from scratch
32
Default internet connection was set, but wasn’t being dialed
33
Found references to ATT under a PhoneBook key Renamed ATT key and problem went away
User had previously installed the AT&T Dialer program, but had uninstalled it and created dial up connection manually
Note that uninstalls don’t clean up stuff in currently not loaded user profiles!
34
35
36
37
Installs its driver to logs Registry activity from boot time to \Windows\Regmon.log Stops logging when you run Regmon
Remember that it does not see direct calls to the native Registry API from kernel-mode code
38
e.g. An application may work when run as Administrator, but not as a normal user Regmon requires the DEBUG and LOAD_DRIVER privileges to execute
E.g. An Explorer shell extension is crashing Explorer during logon
Only way to have a process not be destroyed at log off is to have it run as a service or as a child of a service process
command
Resource Kit Can configure to start at system boot When you logon Regmon will still be running
39