AutoHotkey Community

It is currently May 27th, 2012, 10:18 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: July 8th, 2009, 10:18 pm 
Offline

Joined: November 10th, 2007, 3:30 am
Posts: 93
Location: Second star to the right.... watching you.
Can someone please upload a copy of the compiled exe for reg2ahk?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 9th, 2009, 1:02 pm 
Offline

Joined: February 7th, 2009, 11:28 pm
Posts: 384
I wrote the function below to open registry paths with Registry Workshop, however, it splits the input strings into AHK compliant parts in order to use AHK RegRead's to check if the registry key or value exists, and if not to trim the path to the nearest subkey. I used it with RegShot logs and with reg-files from RegFromApp logs (but only upto the subkeys in the latter case). It may be of some use to someone who wants to convert reg-files to AHK compliant registry paths. Since I'm familiar with my own code, I can modify it accordingly later on today if someone is still looking for that.

Code:
OpenWithRegWksp(regString)
{
  SetBatchLines, -1
  SetTitleMatchMode, 2
  SendMode, Input

  StringSplit, regPath, regString,`n,`r][%A_Space%
  RegExMatch(regPath1,"i)(HKLM|HKCR|HKCU|HKU|HKCC|HKEY_LOCAL_MACHINE|HKEY_USERS|HKEY_CURRENT_USER|HKEY_CLASSES_ROOT|HKEY_CURRENT_CONFIG)\\(?:((.*)\\(.*?)(?::\s)(.*)|.*))", rPath)
  If (rPath1 = "") ;if no rootkey present, run editor without path
  {
    IfWinExist, Registry Workshop
      WinActivate
    Else Run %A_ProgramFiles%\Registry Workshop\RegWorkshop.exe
    Return
  }
  If (rPath3 != "") ;If reg values available, check with AHK
  {
    rSteps:=0      
    RegRead, exists, %rPath1%, %rPath3%, %rPath4%   
    If !Errorlevel
    {
      SelectedPath:= rPath1 . "\" . rPath3
      Loop %rPath1%,%rPath3%,2
        rSteps++    
      If (rPath4 = "(Default)") || (rPath4 = "")
        rPath4:= SelectedPath ;this is specific to regWksp
      Else
      {
        Loop %rPath1%,%rPath3%
          rNames.= A_LoopRegName . "`n"
        StringTrimRight,rNames,rNames,1
        Sort,rNames
        Loop,Parse,rNames,`n
        {
          rSteps++               
          If (A_LoopField = rPath4)
            Break
        }
      }
    }
    Else rPath4=
  }
  Else rPath3:= rPath2  ;update variable names to match
  While SelectedPath = ""
  {   
    Loop %rPath1%, %rPath3%, 1  ; checks if key exists
    {
      SelectedPath:= rPath1 "\" rPath3
        Break
    }
    RegExMatch(rPath3,".*(?=\\)",rPath3)
  }
  IfWinNotExist, Registry Workshop
    Run, "%A_ProgramFiles%\Registry Workshop\RegWorkshop.exe" /g "%SelectedPath%"
  Else setPath:= 1
  WinWait, Registry Workshop
  If hRegWksp:= WinExist("Registry Workshop")
  {
    IfWinNotActive, ahk_id %hRegWksp%
      WinActivate, ahk_id %hRegWksp%
    WinWaitActive, ahk_id %hRegWksp%
  }   
  If setPath
  {
    ControlSetText, Edit1, %SelectedPath%, ahk_id %hRegWksp%
    ControlClick, ToolbarWindow323, ahk_id %hRegWksp%
  }
  If rPath4
  {
    ControlFocus, ATL:0050C4901, ahk_id %hRegWksp%
    Send {Left}{Down %rSteps%}
  }
}
Return

_________________
Hardware: 1.8 GHz laptop with 4 GB ram, Windows XP/SP3
Software: Prevx, Privatefirewall, KeyScrambler.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 10th, 2009, 9:09 am 
Offline

Joined: February 7th, 2009, 11:28 pm
Posts: 384
This works on reg-files I exported in windows reg-file v5.00 format. but it's not finished-- that is, i think it works, but i haven't had time to test it fully, especially my regwrite tries with it were minimal. but it should be good enough that any AHK can customize/debug it for his reg2ahk conversion needs.


Code:
/*
Either select a reg-file a Windows explorer Window (folder view with address needed), and press Win+X to convert the selected (focused) file, or specify the "filepath" below and run script
*/

;filepath:= "C:\example.reg"

#NoEnv
#SingleInstance, Force
SendMode, Input
SetBatchLines, -1
;AutoTrim, Off

If filepath !=
  Goto, RegConvert

GroupAdd, Explore, ahk_class CabinetWClass
GroupAdd, Explore, ahk_class ExploreWClass
Return

#IfWinActive ahk_group Explore
#x::
ControlGetText, dir, Edit1, A
ControlGet, file, List, Focused Col1, SysListView321, A
filepath:= StrLen(dir)=3 ? dir . file : dir . "\" . file
;StringTrimRight, filename, file, 4
;StringTrimRight, partpath, filepath, 4

RegConvert:

FileRead, regFile, %filepath%
If ( NumGet( regFile,0,"UShort" ) = 0xFEFF )
  regFile:= UTOA( &regFile+2 )

Loop,Parse,regFile,`n,`r
{
  If (A_Index == 1)
  {
    If (A_LoopField != "Windows Registry Editor Version 5.00")
    {
      MsgBox,4,Label not detected: "Windows Registry Editor Version 5.00",This script is only designed to work with "Windows Registry Editor Version 5.00" reg-files.`nContinue anyway?,20
      IfMsgBox No
        ExitApp
    }
  }
  ;ASSUMPTION 1: only and all lines for registry keys begin with [
  Else If (SubStr(A_LoopField,1,1) == "[")
  {
    bs:= InStr(A_LoopField, "\" ), root:= SubStr(A_LoopField,2,bs-2), sub:= SubStr(A_LoopField, bs+1)
    StringTrimRight,sub,sub,1 ;to remove ]
    vType:= "REG_EXPAND_SZ" ;is this type to add subkey?
    regAHK.= "`n" . root . "," . sub
    previous:=1 ;used to track sequence of extraction (1=root/sub, 2=value, 3=multi-line value)
    Continue
  }
  Else If (A_LoopField != "")
  {
    ;ASSUMPTION 2: only and all non-empty* lines for registry values and data begin with either @ or ". (*keys with only default value are considered empty)
 
    ;ASSUMPTION 3: value name and data are separated by the first equality sign preceded by @ or ", and succeeded by ", dword:, or hex*:, where the * stands for either no character or a hexadecimal value enclosed in brackets.
    ;In case of the hex values, the leading 0x common to them all(?) is no present. That is, value name-data delimiters consist of @=", @=dword:, @=hex, "=hex, and "=dword:, where the hex deliminters, if extended rightward, include values such as "=hex:, @=hex(0):, "=hex(b):, "=hex(747a756b): and so forth, but always end with :

    ;if multi-line value, grab it and append it to previous data
    If (previous==3)
      $pattern = U)^(\s+)(?P<Data>.*)(?P<Multi>\\?)$
    Else $pattern = U)^["@](?P<Name>.*)(?:["@]?=(?P<Type>["]|dword:|hex.*:))(?P<Data>.*)(?P<Multi>["\\]?)$
   
    RegExMatch( A_LoopField, $pattern, v)
    ;MSGBOX vName: %vName%`n`nvType: %vType%`n`nvData: %vData%`n`nvMulti: %vMulti%`n`n`n`nALF)%A_LoopField%
    ;define reg value type (needed for regWrite)
    If (vMulti=="\")
    {
      If (previous==3)
      {
        regAHK.= vData
        Continue
      }
      vType:= "REG_MULTI_SZ"
    }
    Else If (vType == """")
    {
      ;ASSUMPTION 4 (still to check this...):  double backslashes only occur REG_SZ values of describing file or program paths
      StringReplace,vData,vData,\\,\,All
      vType:= "REG_SZ"
    }
    Else
    {
      vType:= (vType=="dword:") ? "REG_DWORD" : "REG_BINARY"
     
      /*
      ;statements below were included as examples or a base for
      ;manipulating dword and hex data (for example to compare to another format)
      ;presently, the dword condition would add spaces between paits binary data
      If (vType == "REG_DWORD")
        vData:= RegExReplace(vData, "..(?=.)", "$0 ")
     
      ;the condition below may be used to represent decimal data values as hexadecimals
      Else If (vType == "REG_BINARY")
      {
        SetFormat, IntegerFast, H
        vData:= % "0x" SubStr("00000000" SubStr(vData+0, 3), -7)
        SetFormat, IntegerFast, D
      }
      */
    }
    regAHK.= "`n" . vType . "," . root . "," . sub . "," . vName . "," . vData
    previous:= (vMulti=="\") ? 3 : 2
  }
  ;if blank line, zero tracking
  Else previous=
}
MsgBox % regAHK
;FileAppend, regAHK, RegConversion.txt
regFile:="", regAHK:="", root:="", sub:="", vName:="", vData:="", vType:="", vMulti:=""
Return


UTOA( pUnicode )
{    ;Unicode to Ansi
   VarSetCapacity( Ansi,(nSz:=DllCall( "lstrlenW", UInt,pUnicode )+1) )
   DllCall( "WideCharToMultiByte", Int,0, Int,0, UInt,pUnicode, UInt,nSz, Str,Ansi, UInt,nSz, Int,0, Int,0 )
   Return Ansi
}


;function below is not used by the script, but I left it in because it may be useful in related matters. It splits registry paths into root, subkey, value name and value data. it checks local registry for the inputed value or subkey, and in the former case, returns the local value if it exists but differs from the input string.
RegEntrySplit(RegString="")
{
  global
  RegExMatch(RegString,"i)^(HKLM|HKCR|HKCU|HKU|HKCC|HKEY_LOCAL_MACHINE|HKEY_USERS|HKEY_CURRENT_USER|HKEY_CLASSES_ROOT|HKEY_CURRENT_CONFIG)\\(?:((.*)\\(.*?)(?::\s)(.*)|.*))", rPath)
  root:= rPath1
  If rPath3 <>
  {
    sub:= rPath3
    vname:= rPath4
    val:= rPath5
    If SubStr(val,1,1) = """" && SubStr(val, 0,1) = """"
      StringMid,val,val,2,% StrLen(val)-2  ;remove excess "

    RegRead, valNow, %root%, %sub%, %vname%
    If valNow <>
      Return root "`n" sub "`n" vname "`n" val "`n" valNow
    Else Return 0
  }
  Else
  {
    sub:= rPath2, keycount:= 0
    Loop %root%, %sub%, 1  ; checks if key exists
      keycount++
    If (keycount > 0)
      Return root "`n" sub
    Else Return 0
  }
}

_________________
Hardware: 1.8 GHz laptop with 4 GB ram, Windows XP/SP3
Software: Prevx, Privatefirewall, KeyScrambler.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 15th, 2009, 7:05 am 
Offline

Joined: November 10th, 2007, 3:30 am
Posts: 93
Location: Second star to the right.... watching you.
pajenn, thanks, I'll check this out and if it suits my needs I can work on it a bit and try and make it complete. Thanks for posting.
-pax


Report this post
Top
 Profile  
Reply with quote  
 Post subject: alternative REG2AHK
PostPosted: October 29th, 2009, 2:48 pm 
Offline

Joined: October 16th, 2008, 11:36 am
Posts: 7
Or check over here: http://www.autohotkey.com/forum/topic139.html

works like a charm to me.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 29th, 2009, 9:05 pm 
Offline

Joined: February 7th, 2009, 11:28 pm
Posts: 384
I rewrote the earlier script a while back, but didn't post it because of several issues I wasn't sure about:

1. AHK supports REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ, REG_DWORD, or REG_BINARY value types. I wasn't sure what to do about all the others -- currently I have the script set to record the non-supported value types as a hex expressions, but I also included commented-out string expressions for some of them at the bottom of the script.

2. The function returns reg values in CSV format (supported by AHK Parsing Loop) in the same order that RegWrite uses: ValueType, RootKey, SubKey, ValueName, Value

But I haven't tested it beyond the tests I needed to write a seemingly working script.

3. There are special cases such as quotation marks in reg-files are escaped: "" = \"\" in at least some value types, whereas AHK doesn't use escaped quotes. And backslashes themselves are escaped. I added a RegExReplace command to deal with the escaped quotes and backslashes:
vData := RegExReplace(vData,"\\([""\\])",$1)
and another to change line breaks, but there are probably more transformation that are needed.

So this is what I have, but it needs more work. I'm sure it has some bugs, but I'll update it over time (slowly) as I use it:

Code:
;INPUT: "path" to a reg-file
;OUTPUT: Comma separated values (CSV) containing ValueType, RootKey, SubKey, ValueName, Value intended for use with AHK's RegRead and RegWrite commands
;NOTE: AHK's Parsing loop can read CSV

reg2ahk(path,parseValues="True")
{
  SetBatchLines -1
  If (! FileExist(path) || SubStr(path,-3) != ".reg")
    Return 0
 
  FileRead, regFile, %path%
  If ( NumGet( regFile,0,"UShort" ) = 0xFEFF )
    regFile := UTOA( &regFile+2 )
   
  ;check reg-file version
  If ! RegExMatch(regFile,"U)^(REGEDIT4|Windows Registry Editor Version 5.00)",regVersion)
    Return 0

  rPos = 1
  While % rPos := RegExMatch(regFile,"`amsU)^\[(?P<Root>.*)(\\(?P<Sub>.*))?]\R(?P<Values>.*)(?=(^\[|(?-m)$))",r,rPos+StrLen(r))
  {
    If (parseValues == "False")
      regAHK .= rRoot "\" rSub "`n`t" rValues "`n"
    Else If rValues
    {
      vPos = 1
      While % vPos := RegExMatch(rValues,"`amsU)(^(?P<Name>[""].*[""])=|^@=)(?P<Type>dword:|hex.*:|)(?P<Data>.*)(?<!\\)(\r|(?-m)$)",v,vPos+StrLen(v))
      {
        If vType = ;or hex(1): but never seen it used
          vType = "REG_SZ"
        Else If vType In dword:,hex(4): ;technically hex(4) = REG_DWORD_LITTLE_ENDIAN
          vType = "REG_DWORD"
        Else If (vType == "hex:") ;or hex(3): but never seen it used
          vType = "REG_BINARY"
        Else If (vType == "hex(7):") 
          vType = "REG_MULTI_SZ"
        Else If (vType == "hex(2):")
          vType = "REG_EXPAND_SZ"
        Else vType := """0x" . RegExReplace(vType,"hex\((.*)\):","$1") . """" ;unsupported types
       
      ;special cases - there are probably more that I don't know about      
        vData := RegExReplace(vData,"\\([""\\])",$1)
        ;If vType in "REG_BINARY","REG_MULTI_SZ","REG_EXPAND_SZ"
        vData := RegExReplace(vData,"\\\R\s","\n")
      vData := ( SubStr(vData,1,1) != """" && SubStr(vData,0) != """" ) ? """" . vData . """" : vData
      vName := ( SubStr(vName,1,1) != """" && SubStr(vName,0) != """" ) ? """" . vName . """" : vName
        regAHK .= vType ",""" rRoot """,""" rSub """," vName "," vData "`n"
      }
    }
    Else regAHK .= """" . """,""" rRoot """,""" rSub """,""" . """,""" . """`n"
  }
  Return regAHK
}

;Unicode to Ansi by SKAN: http://www.autohotkey.com/forum/viewtopic.php?p=247525#247525
UTOA( pUnicode ) ;Unicode to Ansi
{   
  VarSetCapacity( Ansi,(nSz :=DllCall( "lstrlenW", UInt,pUnicode )+1) )
  DllCall( "WideCharToMultiByte", Int,0, Int,0, UInt,pUnicode, UInt,nSz, Str,Ansi, UInt,nSz, Int,0, Int,0 )
  Return Ansi
}

/*
   ;The following value types can be added to the function by replacing Else vType := ... with the list below but they are not supported by AHK

        ;note: AHK does not support the value types below
        Else If (vType == "hex(0):")
          vType = "REG_NONE"
        Else If (vType == "hex(5):")
          vType = "REG_DWORD_BIG_ENDIAN"       
        Else If (vType == "hex(6):")
          vType = "REG_LINK"
        Else If (vType == "hex(8):")
          vType = "REG_RESOURCE_LIST"
        Else If (vType == "hex(9):")
          vType = "REG_FULL_RESOURCE_DESCRIPTOR"
        Else If (vType == "hex(a):")
          vType = "REG_RESOURCE_REQUIREMENTS_LIST"
        Else If (vType == "hex(b):")
          vType = "REG_QWORD"
        Else vType := """0x" . RegExReplace(vType,"hex\((.*)\):","$1") . """"

_________________
Hardware: 1.8 GHz laptop with 4 GB ram, Windows XP/SP3
Software: Prevx, Privatefirewall, KeyScrambler.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Maestr0 and 63 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group