REG MULTI SZ Reader: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.)
(UNICODE compatible)
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{|align=right
{{PageAuthor|KiCHiK}}
|<small>Author: [[{{ns:2}}:KiCHiK|KiCHiK]] ([[{{ns:3}}:KiCHiK|talk]], [[{{ns:-1}}:Contributions/KiCHiK|contrib]])</small>
 
|}
<br style="clear:both;">
== Description ==
== Description ==
I wrote this script to help rpetges in [http://forums.winamp.com/showthread.php?s=&threadid=131154 this forum thread]. It reads a registry value of the type REG_MULTI_SZ and prints it out. Don't forget to edit where it says "Edit this!" when you test this script. The values must point to a REG_MULTI_SZ value or the example will spit out an error.
I wrote this script to help rpetges in [http://forums.winamp.com/showthread.php?s=&threadid=131154 this forum thread]. It reads a registry value of the type REG_MULTI_SZ and prints it out. Don't forget to edit where it says "Edit this!" when you test this script. The values must point to a REG_MULTI_SZ value or the example will spit out an error.
Line 22: Line 20:
!define HKEY_CURRENT_CONFIG      0x80000005
!define HKEY_CURRENT_CONFIG      0x80000005
!define HKEY_DYN_DATA            0x80000006
!define HKEY_DYN_DATA            0x80000006
 
!define KEY_QUERY_VALUE          0x0001
!define KEY_QUERY_VALUE          0x0001
!define KEY_ENUMERATE_SUB_KEYS  0x0008
!define KEY_ENUMERATE_SUB_KEYS  0x0008
 
!define REG_NONE                0
!define REG_NONE                0
!define REG_SZ                  1
!define REG_SZ                  1
Line 35: Line 33:
!define REG_LINK                6
!define REG_LINK                6
!define REG_MULTI_SZ            7
!define REG_MULTI_SZ            7
 
!define RegOpenKeyEx    "Advapi32::RegOpenKeyExA(i, t, i, i, i) i"
!define RegOpenKeyEx    "Advapi32::RegOpenKeyEx(i, t, i, i, *i) i"
!define RegQueryValueEx  "Advapi32::RegQueryValueExA(i, t, i, i, i, i) i"
!define RegQueryValueEx  "Advapi32::RegQueryValueEx(i, t, i, *i, i, *i) i"
!define RegCloseKey      "Advapi32::RegCloseKeyA(i) i"
!define RegCloseKey      "Advapi32::RegCloseKey(i) i"
 
####### Edit this!
####### Edit this!
 
!define ROOT_KEY        ${HKEY_CURRENT_USER}
!define ROOT_KEY        ${HKEY_LOCAL_MACHINE}
!define SUB_KEY          "Software\Joe Software"
!define SUB_KEY          "SYSTEM\CurrentControlSet\Control\Lsa"
!define VALUE            "Strings"
!define VALUE            "Security Packages"
 
####### Stop editing
####### Stop editing
 
Section "Read"
Section "Read"
   StrCpy $0 ""
   StrCpy $0 ""
Line 54: Line 52:
   StrCpy $3 ""
   StrCpy $3 ""
   SetPluginUnload alwaysoff
   SetPluginUnload alwaysoff
  System::Call "*(i) i (0) .r0"
  System::Call "*(i) i (0) .r1"
  System::Call "*(i) i (0) .r2"
   System::Call "${RegOpenKeyEx}(${ROOT_KEY}, '${SUB_KEY}', \
   System::Call "${RegOpenKeyEx}(${ROOT_KEY}, '${SUB_KEY}', \
     0, ${KEY_QUERY_VALUE}|${KEY_ENUMERATE_SUB_KEYS}, r0) .r3"
     0, ${KEY_QUERY_VALUE}|${KEY_ENUMERATE_SUB_KEYS}, .r0) .r3"
 
   StrCmp $3 0 goon
   StrCmp $3 0 goon
     MessageBox MB_OK|MB_ICONSTOP "Can't open registry key! ($3)"
     MessageBox MB_OK|MB_ICONSTOP "Can't open registry key! ($3)"
Line 65: Line 60:
goon:
goon:


  System::Call "*$0(&i4 .r4)"
   System::Call "${RegQueryValueEx}(r0, '${VALUE}', 0, .r1, 0, .r2) .r3"
   System::Call "${RegQueryValueEx}(r4, '${VALUE}', 0, r1, 0, r2) .r3"
 
   StrCmp $3 0 read
   StrCmp $3 0 read
     MessageBox MB_OK|MB_ICONSTOP "Can't query registry value! ($3)"
     MessageBox MB_OK|MB_ICONSTOP "Can't query registry value size! ($3)"
     Goto done
     Goto done
 
read:
read:
 
   System::Call "*$1(&i4 .r3)"
   StrCmp $1 ${REG_MULTI_SZ} multisz
 
     MessageBox MB_OK|MB_ICONSTOP "Registry value no REG_MULTI_SZ! ($3)"
  StrCmp $3 ${REG_MULTI_SZ} multisz
     MessageBox MB_OK|MB_ICONSTOP "Registry value no SZ_MULTI_SZ! ($3)"
     Goto done
     Goto done
 
multisz:
multisz:
 
   System::Call "*$2(&i4 .r3)"
   StrCmp $2 0 0 multiszalloc
 
  StrCmp $3 0 0 multiszalloc
     MessageBox MB_OK|MB_ICONSTOP "Registry value empty! ($3)"
     MessageBox MB_OK|MB_ICONSTOP "Registry value empty! ($3)"
     Goto done
     Goto done
 
multiszalloc:
multiszalloc:


  System::Free $1
   System::Alloc $2
   System::Alloc $3
   Pop $1
   Pop $1
 
   StrCmp $1 0 0 multiszget
   StrCmp $1 0 0 multiszget
     MessageBox MB_OK|MB_ICONSTOP "Can't allocate enough memory! ($3)"
     MessageBox MB_OK|MB_ICONSTOP "Can't allocate enough memory! ($3)"
     Goto done
     Goto done
 
multiszget:
multiszget:
 
   System::Call "${RegQueryValueEx}(r4, '${VALUE}', 0, 0, r1, r2) .r3"
   System::Call "${RegQueryValueEx}(r0, '${VALUE}', 0, n, r1, r2) .r3"
 
   StrCmp $3 0 multiszprocess
   StrCmp $3 0 multiszprocess
     MessageBox MB_OK|MB_ICONSTOP "Can't query registry value! ($3)[2]"
     MessageBox MB_OK|MB_ICONSTOP "Can't query registry value data! ($3)"
     Goto done
     Goto done
 
multiszprocess:
multiszprocess:
  StrCpy $4 $1
  IntOp $6 $4 + $2
 


   StrCpy $4 $1
   ;REG_MULTI_SZ is double null terminated, change the size so the loop does not have to worry about it
!ifdef NSIS_UNICODE
  IntOp $6 $6 - 2
!else
  IntOp $6 $6 - 1
!endif


   loop:
   loop:
 
    System::Call "*$4(&t${NSIS_MAX_STRLEN} .r3)"
    System::Call "*$4(&t${NSIS_MAX_STRLEN} .r3)"
    StrLen $5 $3
    StrCmp $3 "" done
    IntOp $5 $5 + 1 ;arnold
    DetailPrint $3
!ifdef NSIS_UNICODE   
    StrLen $5 $3
    IntOp $5 $5 * 2 ;WCHAR
    IntOp $4 $4 + $5
!endif
    IntOp $4 $4 + 1
    IntOp $4 $4 + $5
    Goto loop
    DetailPrint $3
 
    IntCmp $4 $6 0 loop
done:
done:
 
  System::Free $2
   System::Free $1
   System::Free $1
 
   StrCmp $0 0 noClose
   StrCmp $0 0 noClose
     System::Call "${RegCloseKey}(r0)"
     System::Call "${RegCloseKey}(r0)"
 
noClose:
noClose:
  SetPluginUnload manual
SectionEnd</highlight-nsis>


  SetPluginUnload manual
[[Category:System Plugin Examples]]
  System::Free $0
SectionEnd
</highlight-nsis>

Latest revision as of 20:29, 6 March 2009

Author: KiCHiK (talk, contrib)


Description

I wrote this script to help rpetges in this forum thread. It reads a registry value of the type REG_MULTI_SZ and prints it out. Don't forget to edit where it says "Edit this!" when you test this script. The values must point to a REG_MULTI_SZ value or the example will spit out an error.

OutFile "REG_MULTI_SZ Reader.exe"
 
Name "REG_MULTI_SZ Reader"
 
ShowInstDetails show
 
!define HKEY_CLASSES_ROOT        0x80000000
!define HKEY_CURRENT_USER        0x80000001
!define HKEY_LOCAL_MACHINE       0x80000002
!define HKEY_USERS               0x80000003
!define HKEY_PERFORMANCE_DATA    0x80000004
!define HKEY_PERFORMANCE_TEXT    0x80000050
!define HKEY_PERFORMANCE_NLSTEXT 0x80000060
!define HKEY_CURRENT_CONFIG      0x80000005
!define HKEY_DYN_DATA            0x80000006
 
!define KEY_QUERY_VALUE          0x0001
!define KEY_ENUMERATE_SUB_KEYS   0x0008
 
!define REG_NONE                 0
!define REG_SZ                   1
!define REG_EXPAND_SZ            2
!define REG_BINARY               3
!define REG_DWORD                4
!define REG_DWORD_LITTLE_ENDIAN  4
!define REG_DWORD_BIG_ENDIAN     5
!define REG_LINK                 6
!define REG_MULTI_SZ             7
 
!define RegOpenKeyEx     "Advapi32::RegOpenKeyEx(i, t, i, i, *i) i"
!define RegQueryValueEx  "Advapi32::RegQueryValueEx(i, t, i, *i, i, *i) i"
!define RegCloseKey      "Advapi32::RegCloseKey(i) i"
 
####### Edit this!
 
!define ROOT_KEY         ${HKEY_LOCAL_MACHINE}
!define SUB_KEY          "SYSTEM\CurrentControlSet\Control\Lsa"
!define VALUE            "Security Packages"
 
####### Stop editing
 
Section "Read"
  StrCpy $0 ""
  StrCpy $1 ""
  StrCpy $2 ""
  StrCpy $3 ""
  SetPluginUnload alwaysoff
  System::Call "${RegOpenKeyEx}(${ROOT_KEY}, '${SUB_KEY}', \
    0, ${KEY_QUERY_VALUE}|${KEY_ENUMERATE_SUB_KEYS}, .r0) .r3"
 
  StrCmp $3 0 goon
    MessageBox MB_OK|MB_ICONSTOP "Can't open registry key! ($3)"
    Goto done
goon:
 
  System::Call "${RegQueryValueEx}(r0, '${VALUE}', 0, .r1, 0, .r2) .r3"
 
  StrCmp $3 0 read
    MessageBox MB_OK|MB_ICONSTOP "Can't query registry value size! ($3)"
    Goto done
 
read:
 
  StrCmp $1 ${REG_MULTI_SZ} multisz
    MessageBox MB_OK|MB_ICONSTOP "Registry value no REG_MULTI_SZ! ($3)"
    Goto done
 
multisz:
 
  StrCmp $2 0 0 multiszalloc
    MessageBox MB_OK|MB_ICONSTOP "Registry value empty! ($3)"
    Goto done
 
multiszalloc:
 
  System::Alloc $2
  Pop $1
 
  StrCmp $1 0 0 multiszget
    MessageBox MB_OK|MB_ICONSTOP "Can't allocate enough memory! ($3)"
    Goto done
 
multiszget:
 
  System::Call "${RegQueryValueEx}(r0, '${VALUE}', 0, n, r1, r2) .r3"
 
  StrCmp $3 0 multiszprocess
    MessageBox MB_OK|MB_ICONSTOP "Can't query registry value data! ($3)"
    Goto done
 
multiszprocess:
 
  StrCpy $4 $1
 
  IntOp $6 $4 + $2
 
 
  ;REG_MULTI_SZ is double null terminated, change the size so the loop does not have to worry about it
!ifdef NSIS_UNICODE 
  IntOp $6 $6 - 2
!else
  IntOp $6 $6 - 1
!endif
 
  loop:
     System::Call "*$4(&t${NSIS_MAX_STRLEN} .r3)"
     StrLen $5 $3
     IntOp $5 $5 + 1 ;arnold
!ifdef NSIS_UNICODE    
     IntOp $5 $5 * 2 ;WCHAR
!endif
     IntOp $4 $4 + $5
     DetailPrint $3
     IntCmp $4 $6 0 loop
 
done:
 
  System::Free $1
 
  StrCmp $0 0 noClose
    System::Call "${RegCloseKey}(r0)"
 
noClose:
 
  SetPluginUnload manual
SectionEnd