Last active
February 9, 2016 13:14
-
-
Save tmr232/c846c65b192732acefcf to your computer and use it in GitHub Desktop.
Easily find GUIDs in the classes list in the registry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| Easily find GUIDs in the classes root | |
| #> | |
| Param( | |
| [Parameter(Mandatory=$true)] | |
| [string]$GUID, | |
| [switch] | |
| $all | |
| ) | |
| $IDPaths = @("AppID", "CLSID", "Interface") | |
| # Fix dashes | |
| $GUID = $GUID -replace "_","-" | |
| # Add braces as necessary | |
| if (-Not $GUID.StartsWith('{')) | |
| { | |
| $GUID = '{' + $GUID | |
| } | |
| if (-Not $GUID.EndsWith('}')) | |
| { | |
| $GUID = $GUID + '}' | |
| } | |
| foreach ($IDPath in $IDPaths) | |
| { | |
| Get-Item -Path "HKLM:\SOFTWARE\Classes\$($IDPath)\$($GUID)" -ErrorAction Ignore | |
| Get-ChildItem -Path "HKLM:\SOFTWARE\Classes\$($IDPath)\$($GUID)" -ErrorAction Ignore | |
| } | |
| if ($all) { | |
| echo " | |
| `n`n | |
| ******************************* | |
| Starting long search... | |
| ******************************* | |
| `n`n | |
| " | |
| pushd "HKLM:\SOFTWARE\Classes" | |
| ls -r $GUID | |
| popd | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| This is the IDAPython version of the `findguid.ps1` module. Allowing easy discovery of GUIDs in binaries. | |
| It depends on `rage` for Windows registry access. So use `pip install rage` to be able to use it. | |
| This code is published under the MIT license. | |
| The MIT License (MIT) | |
| Copyright (c) 2016 Tamir Bahar | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is | |
| furnished to do so, subject to the following conditions: | |
| The above copyright notice and this permission notice shall be included in all | |
| copies or substantial portions of the Software. | |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
| SOFTWARE. | |
| ''' | |
| import idaapi | |
| import uuid | |
| import rage | |
| import struct | |
| HKCR = rage.RegistryKey('HKEY_CLASSES_ROOT') | |
| ID_PATHS = ('AppID', "CLSID", 'Interface') | |
| def read_guid(ea=None): | |
| if ea is None: | |
| ea = idaapi.get_screen_ea() | |
| # Pay attention to the endian! | |
| return uuid.UUID(bytes_le=idaapi.get_many_bytes(ea, 16)) | |
| def format_guid(guid): | |
| return '{{{}}}'.format(guid) | |
| def find_guid(guid): | |
| for path in ID_PATHS: | |
| try: | |
| key = HKCR[path][guid] | |
| for name, value in key.values: | |
| yield name, value | |
| except: | |
| pass | |
| def show_guid(): | |
| guid = read_guid() | |
| print 'GUID: {}'.format(format_guid(guid)) | |
| print 'GUID: {{{}}}'.format(' ,'.join(map('0x{:X}'.format, struct.unpack('<LHHBBBBBBBB', guid.bytes_le)))) | |
| for name, value in find_guid(guid): | |
| print name, value | |
| def name_guid(ea=None): | |
| if ea is None: | |
| ea = idaapi.get_screen_ea() | |
| guid = read_guid(ea) | |
| for name, value in find_guid(format_guid(guid)): | |
| if not name: | |
| guid_name = 'GUID_{}'.format(value.value) | |
| break | |
| else: | |
| return | |
| idaapi.set_name(ea, guid_name, idaapi.SN_NOWARN | idaapi.SN_NOCHECK) | |
| # TODO: Convert the data to a GUID structure. | |
| idaapi.add_hotkey('Shift-G', show_guid) | |
| idaapi.add_hotkey('Ctrl-Shift-G', name_guid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment