Skip to content

Commit

Permalink
Merge pull request #270 from yuvalmarciano/feature/override-shellbag-…
Browse files Browse the repository at this point in the history
…codepage

Allow passing different codepage as an argument to ShellBagUsrclassPlugin and ShellBagNtuserPlugin
  • Loading branch information
mkorman90 authored Jul 16, 2024
2 parents aaf9a2c + fe7c265 commit d8978cf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion regipy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .registry import *
__title__ = 'regipy'
__version__ = '4.2.1'
__version__ = '4.3.0'
12 changes: 6 additions & 6 deletions regipy/plugins/ntuser/shellbags_ntuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
logger = logging.getLogger(__name__)

NTUSER_SHELLBAG = '\\Software\\Microsoft\\Windows\\Shell\\BagMRU'
CODEPAGE = 'cp1252'
DEFAULT_CODEPAGE = 'cp1252'


class ShellBagNtuserPlugin(Plugin):
Expand Down Expand Up @@ -198,7 +198,7 @@ def _parse_shell_item_path_segment(self, shell_item):

return path_segment, full_path, location_description

def iter_sk(self, key, reg_path, base_path='', path=''):
def iter_sk(self, key, reg_path, codepage=DEFAULT_CODEPAGE, base_path='', path=''):
try:
import pyfwsi
except ModuleNotFoundError as ex:
Expand All @@ -223,7 +223,7 @@ def iter_sk(self, key, reg_path, base_path='', path=''):
slot = v.name
byte_stream = v.value
shell_items = pyfwsi.item_list()
shell_items.copy_from_byte_stream(byte_stream, ascii_codepage=CODEPAGE)
shell_items.copy_from_byte_stream(byte_stream, ascii_codepage=codepage)
for item in shell_items.items:
shell_type = self._get_shell_item_type(item)
value, full_path, location_description = self._parse_shell_item_path_segment(self, item)
Expand Down Expand Up @@ -283,10 +283,10 @@ def iter_sk(self, key, reg_path, base_path='', path=''):
self.entries.append(entry)
sk_reg_path = f'{reg_path}\\{value_name}'
sk = self.registry_hive.get_key(sk_reg_path)
self.iter_sk(sk, sk_reg_path, base_path, path)
self.iter_sk(sk, sk_reg_path, codepage, base_path, path)
path = base_path

def run(self):
def run(self, codepage=DEFAULT_CODEPAGE):

try:
import pyfwsi
Expand All @@ -298,6 +298,6 @@ def run(self):

try:
shellbag_ntuser_subkey = self.registry_hive.get_key(NTUSER_SHELLBAG)
self.iter_sk(shellbag_ntuser_subkey, NTUSER_SHELLBAG)
self.iter_sk(shellbag_ntuser_subkey, NTUSER_SHELLBAG, codepage=codepage)
except RegistryKeyNotFoundException as ex:
logger.error(f'Could not find {self.NAME} plugin data at: {NTUSER_SHELLBAG}: {ex}')
12 changes: 6 additions & 6 deletions regipy/plugins/usrclass/shellbags_usrclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
logger = logging.getLogger(__name__)

USRCLASS_SHELLBAG = '\\Local Settings\\Software\\Microsoft\\Windows\\Shell\\BagMRU'
CODEPAGE = 'cp1252'
DEFAULT_CODEPAGE = 'cp1252'


class ShellBagUsrclassPlugin(Plugin):
Expand Down Expand Up @@ -202,7 +202,7 @@ def _parse_shell_item_path_segment(self, shell_item):

return path_segment, full_path, location_description

def iter_sk(self, key, reg_path, base_path='', path=''):
def iter_sk(self, key, reg_path, codepage=DEFAULT_CODEPAGE, base_path='', path=''):
try:
import pyfwsi
except ModuleNotFoundError as ex:
Expand All @@ -227,7 +227,7 @@ def iter_sk(self, key, reg_path, base_path='', path=''):
slot = v.name
byte_stream = v.value
shell_items = pyfwsi.item_list()
shell_items.copy_from_byte_stream(byte_stream, ascii_codepage=CODEPAGE)
shell_items.copy_from_byte_stream(byte_stream, ascii_codepage=codepage)
for item in shell_items.items:
shell_type = self._get_shell_item_type(item)
value, full_path, location_description = self._parse_shell_item_path_segment(self, item)
Expand Down Expand Up @@ -287,10 +287,10 @@ def iter_sk(self, key, reg_path, base_path='', path=''):
self.entries.append(entry)
sk_reg_path = f'{reg_path}\\{value_name}'
sk = self.registry_hive.get_key(sk_reg_path)
self.iter_sk(sk, sk_reg_path, base_path, path)
self.iter_sk(sk, sk_reg_path, codepage, base_path, path)
path = base_path

def run(self):
def run(self, codepage=DEFAULT_CODEPAGE):

try:
import pyfwsi
Expand All @@ -302,6 +302,6 @@ def run(self):

try:
shellbag_usrclass_subkey = self.registry_hive.get_key(USRCLASS_SHELLBAG)
self.iter_sk(shellbag_usrclass_subkey, USRCLASS_SHELLBAG)
self.iter_sk(shellbag_usrclass_subkey, USRCLASS_SHELLBAG, codepage=codepage)
except RegistryKeyNotFoundException as ex:
logger.error(f'Could not find {self.NAME} plugin data at: {USRCLASS_SHELLBAG}: {ex}')

0 comments on commit d8978cf

Please sign in to comment.