Added the HKCR32, HKCR64, HKCU32, HKCU64, HKLM32 and HKLM64 root keys and the experimental HK*ANY root keys.
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6871 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
bcef20b32d
commit
94dd438510
9 changed files with 125 additions and 46 deletions
|
@ -158,8 +158,8 @@ static TCHAR * NSISCALL GetStringFromParm(int id_)
|
|||
#ifdef NSIS_SUPPORT_REGISTRYFUNCTIONS
|
||||
static HKEY NSISCALL GetRegRootKey(int RootKey)
|
||||
{
|
||||
if (RootKey != (int) HKSHCTX) return (HKEY) (UINT_PTR) RootKey;
|
||||
return (HKEY) ((UINT_PTR) HKEY_CURRENT_USER + g_exec_flags.all_user_var); // SHCTX: HKEY_CURRENT_USER + 1 == HKEY_LOCAL_MACHINE
|
||||
if (RootKey < 0) return (HKEY) (UINT_PTR) RootKey;
|
||||
return (HKEY) ((UINT_PTR) HKEY_CURRENT_USER + RootKey + g_exec_flags.all_user_var); // SHCTX[32|64|ANY]: HKEY_CURRENT_USER + 1 == HKEY_LOCAL_MACHINE
|
||||
}
|
||||
static HKEY NSISCALL RegOpenScriptKey(REGSAM RS)
|
||||
{
|
||||
|
@ -175,20 +175,20 @@ static HKEY NSISCALL RegCreateScriptKey(int RootKey, LPCTSTR SubKey, REGSAM RS)
|
|||
// RegDeleteKey on Win9x will delete a tree of keys, WinNT will only delete a key without subkeys.
|
||||
// RegDeleteKeyEx on 32-bit Windows accepts but ignores the KEY_WOW64_xxKEY flags and always uses the
|
||||
// one and only native key. Our RegKeyOpen will intentionally fail if a incompatible WoW64 flag is used.
|
||||
#define RegDeleteScriptKey(RootKey, SubKey, Flags) RegDeleteScriptKeyWorker(GetRegRootKey(RootKey), (SubKey), (Flags))
|
||||
static LONG NSISCALL RegDeleteScriptKeyWorker(HKEY hThisKey, LPCTSTR SubKey, UINT Flags)
|
||||
#define DRTF_ONLYIFNOSUBKEYS DELREGKEY_ONLYIFNOSUBKEYS
|
||||
static LONG NSISCALL DeleteRegTree(HKEY hThisKey, LPCTSTR SubKey, REGSAM SamviewAndFlags)
|
||||
{
|
||||
HKEY hKey;
|
||||
UINT onlyifempty = Flags;
|
||||
REGSAM viewsam = g_exec_flags.alter_reg_view; // Not using KEY_ALTERVIEW here because viewsam is also passed to RegDeleteKeyEx.
|
||||
LONG retval = RegKeyOpen(hThisKey, SubKey, KEY_ENUMERATE_SUB_KEYS|viewsam, &hKey);
|
||||
UINT onlyifempty = SamviewAndFlags & DRTF_ONLYIFNOSUBKEYS;
|
||||
REGSAM samview = SamviewAndFlags & (KEY_WOW64_32KEY|KEY_WOW64_64KEY);
|
||||
LONG retval = RegKeyOpen(hThisKey, SubKey, KEY_ENUMERATE_SUB_KEYS|samview, &hKey);
|
||||
if (retval == ERROR_SUCCESS)
|
||||
{
|
||||
TCHAR child[MAX_PATH+1]; // NB - don't change this to static (recursive function)
|
||||
while (RegEnumKey(hKey, 0, child, COUNTOF(child)) == ERROR_SUCCESS)
|
||||
{
|
||||
if (onlyifempty) return (RegCloseKey(hKey), !ERROR_SUCCESS);
|
||||
if ((retval = RegDeleteScriptKeyWorker(hKey, child, Flags)) != ERROR_SUCCESS) break;
|
||||
if ((retval = DeleteRegTree(hKey, child, SamviewAndFlags)) != ERROR_SUCCESS) break;
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
{
|
||||
|
@ -200,13 +200,20 @@ static LONG NSISCALL RegDeleteScriptKeyWorker(HKEY hThisKey, LPCTSTR SubKey, UIN
|
|||
myGetProcAddress(MGA_RegDeleteKeyEx);
|
||||
#endif
|
||||
if (RDKE)
|
||||
retval = RDKE(hThisKey, SubKey, viewsam, 0);
|
||||
retval = RDKE(hThisKey, SubKey, samview, 0);
|
||||
else
|
||||
retval = RegDeleteKey(hThisKey, SubKey);
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
static LONG NSISCALL RegDeleteScriptKey(int RootKey, LPCTSTR SubKey, REGSAM SamviewAndFlags)
|
||||
{
|
||||
HKEY hKey;
|
||||
SamviewAndFlags |= KEY_FROMSCRIPT;
|
||||
hKey = GetRegKeyAndSAM(GetRegRootKey(RootKey), &SamviewAndFlags);
|
||||
return hKey ? DeleteRegTree(hKey, SubKey, SamviewAndFlags) : ERROR_INVALID_HANDLE; // ERROR_CANTOPEN?
|
||||
}
|
||||
#endif//NSIS_SUPPORT_REGISTRYFUNCTIONS
|
||||
|
||||
// returns EXEC_ERROR on error
|
||||
|
@ -1219,7 +1226,7 @@ static int NSISCALL ExecuteEntry(entry *entry_)
|
|||
{
|
||||
TCHAR *buf2=GetStringFromParm(0x22);
|
||||
log_printf3(_T("DeleteRegKey: \"%s\\%s\""),rkn,buf2);
|
||||
res = RegDeleteScriptKey(rootkey,buf2,parm4 >> 1); // Shifting away the TOK_DELETEREGKEY bit, onlyifempty is now the bottom bit (">> 1" is 1 byte smaller than "& 2")
|
||||
res = RegDeleteScriptKey(rootkey,buf2,parm4 >> DELREGKEYFLAGSSHIFT); // SHR is 1 byte smaller than AND
|
||||
}
|
||||
if (res != ERROR_SUCCESS)
|
||||
exec_error++;
|
||||
|
|
|
@ -155,7 +155,7 @@ enum
|
|||
#endif
|
||||
|
||||
#ifdef NSIS_SUPPORT_REGISTRYFUNCTIONS
|
||||
EW_DELREG, // DeleteRegValue/DeleteRegKey: 4, [root key(int), KeyName, ValueName, ActionAndFlags]
|
||||
EW_DELREG, // DeleteRegValue/DeleteRegKey: 4, [root key(int), KeyName, ValueName, ActionAndFlags(DELREG*)]
|
||||
EW_WRITEREG, // Write Registry value: 5, [RootKey(int),KeyName,ItemName,ItemData,typelen]
|
||||
// typelen=1 for str, 2 for dword, 3 for binary, 0 for expanded str
|
||||
EW_READREGSTR, // ReadRegStr: 5 [output, rootkey(int), keyname, itemname, ==1?int::str]
|
||||
|
@ -504,13 +504,37 @@ typedef struct {
|
|||
# define ctlcolors ctlcolors32
|
||||
#endif
|
||||
|
||||
|
||||
// constants for myDelete (util.c)
|
||||
#define DEL_DIR 1
|
||||
#define DEL_RECURSE 2
|
||||
#define DEL_REBOOT 4
|
||||
#define DEL_SIMPLE 8
|
||||
|
||||
|
||||
#define REGROOTVIEW32 0x40000000
|
||||
#define REGROOTVIEW64 0x20000000
|
||||
#define REGROOTVIEWTOSAMVIEW(rv) ( ((UINT_PTR)(rv)&(REGROOTVIEW32|REGROOTVIEW64)) >> 21 ) // REGROOTVIEWxx to KEY_WOW64_xxKEY
|
||||
#define IsRegRootkeyForcedView(hKey) ( ((UINT_PTR) (hKey) & (REGROOTVIEW32|REGROOTVIEW64)) )
|
||||
#define MAKEREGROOTVIEW(r, fv) ( (HKEY) ((UINT_PTR)(r) | (fv)) )
|
||||
#define HKSHCTX ( (HKEY) 0 ) // Converted to HKCU or HKLM by GetRegRootKey
|
||||
#define HKSHCTX32 MAKEREGROOTVIEW(HKSHCTX, REGROOTVIEW32)
|
||||
#define HKSHCTX64 MAKEREGROOTVIEW(HKSHCTX, REGROOTVIEW64)
|
||||
#define HKCR32 MAKEREGROOTVIEW(HKEY_CLASSES_ROOT, REGROOTVIEW32)
|
||||
#define HKCR64 MAKEREGROOTVIEW(HKEY_CLASSES_ROOT, REGROOTVIEW64)
|
||||
#define HKCU32 MAKEREGROOTVIEW(HKEY_CURRENT_USER, REGROOTVIEW32)
|
||||
#define HKCU64 MAKEREGROOTVIEW(HKEY_CURRENT_USER, REGROOTVIEW64)
|
||||
#define HKLM32 MAKEREGROOTVIEW(HKEY_LOCAL_MACHINE, REGROOTVIEW32)
|
||||
#define HKLM64 MAKEREGROOTVIEW(HKEY_LOCAL_MACHINE, REGROOTVIEW64)
|
||||
#define HKSHCTXANY MAKEREGROOTVIEW(HKSHCTX, REGROOTVIEW32|REGROOTVIEW64)
|
||||
#define HKCRANY MAKEREGROOTVIEW(HKEY_CLASSES_ROOT, REGROOTVIEW32|REGROOTVIEW64)
|
||||
#define HKCUANY MAKEREGROOTVIEW(HKEY_CURRENT_USER, REGROOTVIEW32|REGROOTVIEW64)
|
||||
#define HKLMANY MAKEREGROOTVIEW(HKEY_LOCAL_MACHINE, REGROOTVIEW32|REGROOTVIEW64)
|
||||
#define DELREG_VALUE 0 // TOK_DELETEREGVALUE
|
||||
#define DELREG_KEY 1 // TOK_DELETEREGKEY
|
||||
#define DELREGKEY_ONLYIFNOSUBKEYS 1 // Shifted and stored as 2 in the binary for compatibility with <= 3.1
|
||||
#define DELREGKEYFLAGSSHIFT 1 // parm4 is shifted so exehead can remove the DELREG_KEY bit
|
||||
|
||||
|
||||
#ifdef NSIS_SUPPORT_CREATESHORTCUT
|
||||
#define CS_HK_MASK 0xffff0000 // HotKey
|
||||
|
@ -523,6 +547,7 @@ typedef struct {
|
|||
#define CS_II_MAX (CS_II_MASK >> CS_II_SHIFT)
|
||||
#endif
|
||||
|
||||
|
||||
// special escape characters used in strings: (we use control codes in order to minimize conflicts with normal characters)
|
||||
#define NS_LANG_CODE _T('\x01') // for a langstring
|
||||
#define NS_SHELL_CODE _T('\x02') // for a shell folder path
|
||||
|
|
|
@ -655,11 +655,25 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew)
|
|||
#endif
|
||||
|
||||
#define GetAltViewREGSAM() ( sizeof(void*) > 4 ? KEY_WOW64_32KEY : KEY_WOW64_64KEY )
|
||||
static HKEY GetRegKeyAndSAM(HKEY hKey, REGSAM*pRS)
|
||||
HKEY NSISCALL GetRegKeyAndSAM(HKEY hKey, REGSAM*pRS)
|
||||
{
|
||||
REGSAM sam = *pRS, otherview = GetAltViewREGSAM();
|
||||
REGSAM incompatsam = SystemSupportsAltRegView() ? 0 : otherview;
|
||||
if (sam & KEY_ALTERVIEW) sam |= g_exec_flags.alter_reg_view;
|
||||
const REGSAM samviewmask = (KEY_WOW64_32KEY|KEY_WOW64_64KEY);
|
||||
const REGSAM incompatsamview = SystemSupportsAltRegView() ? 0 : GetAltViewREGSAM();
|
||||
REGSAM sam = *pRS, incompatsam = incompatsamview;
|
||||
#ifdef C_ASSERT
|
||||
{C_ASSERT(REGROOTVIEWTOSAMVIEW(REGROOTVIEW32|REGROOTVIEW64) == (KEY_WOW64_32KEY|KEY_WOW64_64KEY));}
|
||||
#endif
|
||||
if ((sam & KEY_FORCEVIEW) && IsRegRootkeyForcedView(hKey))
|
||||
{
|
||||
REGSAM keysamview = REGROOTVIEWTOSAMVIEW(hKey);
|
||||
if (keysamview == samviewmask) keysamview = (g_exec_flags.alter_reg_view & ~incompatsamview); // HKxxANY tries to honor SetRegView
|
||||
sam &= ~samviewmask, sam |= (keysamview & ~(sizeof(void*) > 4 ? 0 : KEY_WOW64_32KEY)); // HKxx32 has the *_32KEY bit set but WinNT4&2000 cannot handle any KEY_WOW64_xxKEY flags.
|
||||
hKey = (HKEY) ( (UINT_PTR) hKey & ~(REGROOTVIEW32|REGROOTVIEW64) );
|
||||
}
|
||||
else if (sam & KEY_ALTERVIEW)
|
||||
{
|
||||
sam |= g_exec_flags.alter_reg_view; // We don't mask away the incompatsamview bits because the operation is supposed to fail if the view is not supported.
|
||||
}
|
||||
*pRS = sam & ~(NSIS_REGSAM_PRIVATEMASK); // Filter away internal flags
|
||||
return (incompatsam & sam) ? NULL : hKey; // Fail if the requested view is not supported
|
||||
}
|
||||
|
@ -678,8 +692,8 @@ void NSISCALL myRegGetStr(HKEY root, const TCHAR *sub, const TCHAR *name, TCHAR
|
|||
{
|
||||
HKEY hKey;
|
||||
DWORD cb = NSIS_MAX_STRLEN*sizeof(TCHAR), rt, ec;
|
||||
REGSAM viewsam = altview ? GetAltViewREGSAM() : 0;
|
||||
if ((ec = RegKeyOpen(root, sub, KEY_READ|viewsam, &hKey)) == ERROR_SUCCESS)
|
||||
REGSAM samview = altview ? GetAltViewREGSAM() : 0;
|
||||
if ((ec = RegKeyOpen(root, sub, KEY_READ|samview, &hKey)) == ERROR_SUCCESS)
|
||||
{
|
||||
ec = RegQueryValueEx(hKey, name, NULL, &rt, (LPBYTE)out, &cb);
|
||||
RegCloseKey(hKey);
|
||||
|
@ -1013,6 +1027,19 @@ const TCHAR * _RegKeyHandleToName(HKEY hKey)
|
|||
if (hKey == HKEY_PERFORMANCE_DATA) return _T("HKEY_PERFORMANCE_DATA");
|
||||
if (hKey == HKEY_CURRENT_CONFIG) return _T("HKEY_CURRENT_CONFIG");
|
||||
if (hKey == HKEY_DYN_DATA) return _T("HKEY_DYN_DATA");
|
||||
if (hKey == HKSHCTX) return _T("HKSHCTX");
|
||||
if (hKey == HKSHCTX32) return _T("HKSHCTX32");
|
||||
if (hKey == HKSHCTX64) return _T("HKSHCTX64");
|
||||
if (hKey == HKCR32) return _T("HKCR32");
|
||||
if (hKey == HKCR64) return _T("HKCR64");
|
||||
if (hKey == HKCU32) return _T("HKCU32");
|
||||
if (hKey == HKCU64) return _T("HKCU64");
|
||||
if (hKey == HKLM32) return _T("HKLM32");
|
||||
if (hKey == HKLM64) return _T("HKLM64");
|
||||
if (hKey == HKSHCTXANY) return _T("HKSHCTXANY");
|
||||
if (hKey == HKCRANY) return _T("HKCRANY");
|
||||
if (hKey == HKCUANY) return _T("HKCUANY");
|
||||
if (hKey == HKLMANY) return _T("HKLMANY");
|
||||
return _T("HK??");
|
||||
}
|
||||
|
||||
|
|
|
@ -42,9 +42,14 @@ TCHAR * NSISCALL mystrcat(TCHAR *out, const TCHAR *concat);
|
|||
TCHAR * NSISCALL mystrstr(TCHAR *a, TCHAR *b);
|
||||
|
||||
|
||||
#ifndef KEY_CREATE_LINK
|
||||
#define KEY_CREATE_LINK 0x0020
|
||||
#endif
|
||||
#define KEY_FORCEVIEW KEY_CREATE_LINK // Our private flag used by RegKey* to indicate that we want it to handle HKLM[32|64] style root keys. Cannot be set if the HKEY is a real handle!
|
||||
#define KEY_ALTERVIEW SYNCHRONIZE // Our private flag used by RegKey* to indicate that we want it to apply g_exec_flags.alter_reg_view. (MSDN:"Registry keys do not support the SYNCHRONIZE standard access right")
|
||||
#define KEY_FROMSCRIPT (KEY_ALTERVIEW) // Use this flag for registry operations from a .nsi script
|
||||
#define NSIS_REGSAM_PRIVATEMASK (KEY_FROMSCRIPT|KEY_ALTERVIEW)
|
||||
#define KEY_FROMSCRIPT (KEY_FORCEVIEW|KEY_ALTERVIEW) // Use this flag for registry operations from a .nsi script
|
||||
#define NSIS_REGSAM_PRIVATEMASK (KEY_FROMSCRIPT|KEY_FORCEVIEW|KEY_ALTERVIEW)
|
||||
HKEY NSISCALL GetRegKeyAndSAM(HKEY hKey, REGSAM*pRS);
|
||||
LONG NSISCALL RegKeyOpen(HKEY hBase, LPCTSTR SubKey, REGSAM RS, HKEY*phKey);
|
||||
LONG NSISCALL RegKeyCreate(HKEY hBase, LPCTSTR SubKey, REGSAM RS, HKEY*phKey);
|
||||
void NSISCALL myRegGetStr(HKEY root, const TCHAR *sub, const TCHAR *name, TCHAR *out, UINT altview);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue