Placeholders in autotype target window REGEX?

Scott J
2012-01-19
2012-11-20
  • Scott J
    Scott J
    2012-01-19

    Is it possible to use field references, etc in an auto-type regex for a "Target Window" string?

    Here's what I'm trying to do:

    Essentially, I want to have "global vars" that I can reuse in all my auto-type regular expression matches.  All the browsers attach their name to the end of the window title like this:

    Somesite.com - your best place for something - Internet Explorer
    Somesite.com - your best place for something - Firefox
    Somesite.com - your best place for something - Google Chrome

    That's fine, but if I start using a new browser, I'd rather not have to go back through hundreds of auto-types to append the new browser name at the end.  Yes, I could probably end the REGEX with a wildcard and have it match any title, but that feels a bit risky to me where I might get overmatching, or I could completely disallow matching on a particular browser by not including it in the REGEX.  My solution was to do something like this

    1) Define an entry where the username is ONLY my browser regex,
    REF:U@I:17901055652525252522525252519AA4  ==> (Mozilla Firefox|Waterfox|Internet Explorer|Google Chrome)

    2) Then I just tack that field reference onto my window match and it matches any browser I have configured in the field reference. 
    Auto-type>Target Window = //Somesite.com - your best place for something.*{REF:U@I:17901055652525252522525252519AA4}//

    which would get expanded to become this REGEX
    //Somesite.com - your best place for something.*(Mozilla Firefox|Waterfox|Internet Explorer|Google Chrome)//

    When I want to start using browser X in the future, I only have to edit one place (REF:U@I:17901055652525252522525252519AA4) and it would propagate to all the matches I have setup.

    The problem is, it's not working.  The REGEX seems OK, since it works when entered directly.  Can anyone comment of this, if there's a better way to do it, or could be added in the future? 

     
  • Dominik Reichl
    Dominik Reichl
    2012-01-19

    What you described should work. I've tried it, and it worked fine for me.

    Hard to tell why it doesn't work in your case (maybe the reference is incorrect, …). If you post a sample database, I'll have a look at it.

    Best regards
    Dominik

     
  • Scott J
    Scott J
    2012-01-20

    Here's an XML export of the entries.  One is the "GLOBAL VAR", the other is a test using a reference to the GLOBAL VAR, and the third is an entry directly containing the regex that I would expect the referenced entry to ultimately expand to.

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <KeePassFile>
        <Meta>
            <Generator>KeePass</Generator>
            <DatabaseName>REGEX TEST</DatabaseName>
            <DatabaseNameChanged>2012-01-20T00:45:00Z</DatabaseNameChanged>
            <DatabaseDescription />
            <DatabaseDescriptionChanged>2012-01-20T00:45:00Z</DatabaseDescriptionChanged>
            <DefaultUserName />
            <DefaultUserNameChanged>2012-01-20T00:45:00Z</DefaultUserNameChanged>
            <MaintenanceHistoryDays>365</MaintenanceHistoryDays>
            <Color />
            <MasterKeyChanged>2012-01-20T00:45:00Z</MasterKeyChanged>
            <MasterKeyChangeRec>365</MasterKeyChangeRec>
            <MasterKeyChangeForce>-1</MasterKeyChangeForce>
            <MemoryProtection>
                <ProtectTitle>False</ProtectTitle>
                <ProtectUserName>False</ProtectUserName>
                <ProtectPassword>True</ProtectPassword>
                <ProtectURL>False</ProtectURL>
                <ProtectNotes>False</ProtectNotes>
            </MemoryProtection>
            <CustomIcons />
            <RecycleBinEnabled>True</RecycleBinEnabled>
            <RecycleBinUUID>UaZHnQaVwU+YSn1Yd0za2g==</RecycleBinUUID>
            <RecycleBinChanged>2012-01-20T00:45:00Z</RecycleBinChanged>
            <EntryTemplatesGroup>MmrIN29nfE+587mQ1dVS4A==</EntryTemplatesGroup>
            <EntryTemplatesGroupChanged>2012-01-20T00:45:00Z</EntryTemplatesGroupChanged>
            <HistoryMaxItems>10</HistoryMaxItems>
            <HistoryMaxSize>6291456</HistoryMaxSize>
            <LastSelectedGroup>Rpt2O3zBsEWFSYan3ufUVA==</LastSelectedGroup>
            <LastTopVisibleGroup>1vLPiC1WAkGkpoa+EcAyyw==</LastTopVisibleGroup>
            <Binaries />
            <CustomData />
        </Meta>
        <Root>
            <Group>
                <UUID>b+1YTR5Yb0mgvItipc/xHg==</UUID>
                <Name />
                <Notes />
                <IconID>48</IconID>
                <Times>
                    <LastModificationTime>2012-01-20T13:13:02Z</LastModificationTime>
                    <CreationTime>2012-01-20T13:13:02Z</CreationTime>
                    <LastAccessTime>2012-01-20T13:13:02Z</LastAccessTime>
                    <ExpiryTime>2012-01-18T14:09:24Z</ExpiryTime>
                    <Expires>False</Expires>
                    <UsageCount>0</UsageCount>
                    <LocationChanged>2012-01-20T13:13:02Z</LocationChanged>
                </Times>
                <IsExpanded>True</IsExpanded>
                <DefaultAutoTypeSequence />
                <EnableAutoType>null</EnableAutoType>
                <EnableSearching>null</EnableSearching>
                <LastTopVisibleEntry>AAAAAAAAAAAAAAAAAAAAAA==</LastTopVisibleEntry>
                <Entry>
                    <UUID>F5AQVWMq+keyel9t8IGapA==</UUID>
                    <IconID>0</IconID>
                    <ForegroundColor />
                    <BackgroundColor />
                    <OverrideURL />
                    <Tags />
                    <Times>
                        <LastModificationTime>2012-01-20T13:12:03Z</LastModificationTime>
                        <CreationTime>2012-01-17T13:26:05Z</CreationTime>
                        <LastAccessTime>2012-01-20T13:12:03Z</LastAccessTime>
                        <ExpiryTime>2012-01-20T00:45:00Z</ExpiryTime>
                        <Expires>False</Expires>
                        <UsageCount>19</UsageCount>
                        <LocationChanged>2012-01-17T13:26:05Z</LocationChanged>
                    </Times>
                    <String>
                        <Key>Notes</Key>
                        <Value>
    {REF:U@I:17901055632AFA47B27A5F6DF0819AA4}
    Use a reference to this entry's username to replace the browser string attached to the title of webpage windows. This makes it easy to change them all in case the browsers edit their title string.  It also allows me to use multiple match strings for IE/Firefox/Waterfox/etc
    Previously you would have used:
    //CHASE Home:.*(Mozilla Firefox|Waterfox|Internet Explorer)//
    Now use:
    //CHASE Home:.*{REF:U@I:17901055632AFA47B27A5F6DF0819AA4}//
    </Value>
                    </String>
                    <String>
                        <Key>Password</Key>
                        <Value />
                    </String>
                    <String>
                        <Key>Title</Key>
                        <Value>GLOBALVAR: Browser title match Regex</Value>
                    </String>
                    <String>
                        <Key>URL</Key>
                        <Value />
                    </String>
                    <String>
                        <Key>UserName</Key>
                        <Value>(Mozilla Firefox|Waterfox|Internet Explorer|Google Chrome)</Value>
                    </String>
                    <AutoType>
                        <Enabled>True</Enabled>
                        <DataTransferObfuscation>0</DataTransferObfuscation>
                    </AutoType>
                    <History />
                </Entry>
                <Entry>
                    <UUID>4GUqRxLZtkOdt9itzMJITg==</UUID>
                    <IconID>0</IconID>
                    <ForegroundColor />
                    <BackgroundColor />
                    <OverrideURL />
                    <Tags />
                    <Times>
                        <LastModificationTime>2012-01-20T13:11:54Z</LastModificationTime>
                        <CreationTime>2012-01-20T12:58:35Z</CreationTime>
                        <LastAccessTime>2012-01-20T13:11:54Z</LastAccessTime>
                        <ExpiryTime>2012-01-20T00:45:00Z</ExpiryTime>
                        <Expires>False</Expires>
                        <UsageCount>17</UsageCount>
                        <LocationChanged>2012-01-20T00:45:00Z</LocationChanged>
                    </Times>
                    <String>
                        <Key>Notes</Key>
                        <Value />
                    </String>
                    <String>
                        <Key>Password</Key>
                        <Value>OnruGbYMhybrEEBS8a7c</Value>
                    </String>
                    <String>
                        <Key>Title</Key>
                        <Value>google test using direct REGEX</Value>
                    </String>
                    <String>
                        <Key>URL</Key>
                        <Value>http://www.google.com</Value>
                    </String>
                    <String>
                        <Key>UserName</Key>
                        <Value>Direct REGEX worked</Value>
                    </String>
                    <AutoType>
                        <Enabled>True</Enabled>
                        <DataTransferObfuscation>0</DataTransferObfuscation>
                        <Association>
                            <Window>//Google.*(Mozilla Firefox|Waterfox|Internet Explorer|Google Chrome)//</Window>
                            <KeystrokeSequence>{UserName}{ENTER}</KeystrokeSequence>
                        </Association>
                    </AutoType>
                    <History />
                </Entry>
                <Entry>
                    <UUID>tZMYcYnJ402bOiUh9g+Yyw==</UUID>
                    <IconID>0</IconID>
                    <ForegroundColor />
                    <BackgroundColor />
                    <OverrideURL />
                    <Tags />
                    <Times>
                        <LastModificationTime>2012-01-20T13:11:44Z</LastModificationTime>
                        <CreationTime>2012-01-20T12:58:35Z</CreationTime>
                        <LastAccessTime>2012-01-20T13:11:44Z</LastAccessTime>
                        <ExpiryTime>2012-01-18T14:09:24Z</ExpiryTime>
                        <Expires>False</Expires>
                        <UsageCount>17</UsageCount>
                        <LocationChanged>2012-01-20T13:05:38Z</LocationChanged>
                    </Times>
                    <String>
                        <Key>Notes</Key>
                        <Value />
                    </String>
                    <String>
                        <Key>Password</Key>
                        <Value>OnruGbYMhybrEEBS8a7c</Value>
                    </String>
                    <String>
                        <Key>Title</Key>
                        <Value>google test of REGEX with field reference</Value>
                    </String>
                    <String>
                        <Key>URL</Key>
                        <Value>http://www.google.com</Value>
                    </String>
                    <String>
                        <Key>UserName</Key>
                        <Value>Hey - It worked with field reference in REGEX!</Value>
                    </String>
                    <AutoType>
                        <Enabled>True</Enabled>
                        <DataTransferObfuscation>0</DataTransferObfuscation>
                        <Association>
                            <Window>//Google.*{REF:U@I:17901055632AFA47B27A5F6DF0819AA4}//</Window>
                            <KeystrokeSequence>{UserName}{ENTER}</KeystrokeSequence>
                        </Association>
                    </AutoType>
                    <History />
                </Entry>
            </Group>
            <DeletedObjects />
        </Root>
    </KeePassFile>
    
     
  • Dominik Reichl
    Dominik Reichl
    2012-01-20

    Thanks. I've imported the XML file into an empty database (using KeePass 2.18). When pressing the global auto-type hot key while being on Google in Firefox, KeePass asks which of the two entries should be used (i.e. both match). In contrast, when creating a Google.txt text file and pressing the hot key, none of the two entries match. So, the behavior is exactly as you wanted it, isn't it?

    Best regards
    Dominik

     
  • Scott J
    Scott J
    2012-01-20

    Weird - what you've described is exactly what I'm looking for.  I'm running v2.17 right now and only get the one match (using the "direct" regex).

    I'll have to upgrade to v2.18 sometime this weekend and see if that makes it work.   Thanks for validating that it does/should work, so I've got some hope!

     
  • Scott J
    Scott J
    2012-02-04

    Dominik - Keefox had some issues with KP v2.18 so I delayed updating.  They just put out a tweaked KFox version, so I updated.  After the update to KP v2.18, the REGEX with field references as shown above are working perfectly!

    Thanks for checking it out.  If anyone else has issues, just update your version of KP. 

    Maybe the help page about REGEX usage could be updated to inform users that using place holders is possible, and give an example?  I'd gladly let you use the example I posted above.