Skip to content

Commit

Permalink
some helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
SkelSec committed May 1, 2024
1 parent 78a5175 commit c00f101
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion aiowinreg/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.0.11"
__version__ = "0.0.12"
__banner__ = \
"""
# aiowinreg %s
Expand Down
15 changes: 14 additions & 1 deletion aiowinreg/ahive.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ntpath
import io

from aiowinreg.filestruct.header import NTRegistryHeadr
from aiowinreg.filestruct.hbin import NTRegistryHbin
Expand All @@ -9,7 +10,7 @@
from aiowinreg.filestruct.lh import NTRegistryLH
from aiowinreg.filestruct.ri import NTRegistryRI
from aiowinreg.filestruct.vk import REGTYPE

from aiowinreg.utils.afile import ABuffer, AFile

class AIOWinRegHive:
"""
Expand All @@ -26,6 +27,18 @@ def __init__(self, reader, root_hbin = None, is_file = True):

self.__cells_lookup = {}
self.__key_lookup = {}

@staticmethod
def from_bytes(data:bytes, root_hbin:NTRegistryHbin = None, is_file:bool = True):
return AIOWinRegHive(ABuffer(io.BytesIO(data)), root_hbin = root_hbin, is_file = is_file)

@staticmethod
def from_buffer(buff: io.BytesIO, root_hbin:NTRegistryHbin = None, is_file:bool = True):
return AIOWinRegHive(ABuffer(buff), root_hbin = root_hbin, is_file = is_file)

@staticmethod
def from_file(file_path:str, root_hbin:NTRegistryHbin = None):
return AIOWinRegHive(AFile(file_path), root_hbin=root_hbin, is_file = True)

async def close(self):
"""Closes the hive"""
Expand Down
19 changes: 16 additions & 3 deletions aiowinreg/hive.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import ntpath
import io

from aiowinreg.filestruct.header import NTRegistryHeadr
from aiowinreg.filestruct.hbin import NTRegistryHbin
Expand All @@ -14,16 +15,28 @@


class AIOWinRegHive:
def __init__(self, reader, root_hbin = None, is_file = True):
def __init__(self, reader:io.BytesIO, root_hbin:NTRegistryHbin = None, is_file:bool = True):
self.reader = reader
self.header = None
self.root = None
self.header:NTRegistryHeadr = None
self.root:NTRegistryNK = None
self.root_hbin = root_hbin
self.is_file = is_file
if root_hbin is not None:
self.header = NTRegistryHeadr()
self.__cells_lookup = {}
self.__key_lookup = {}

@staticmethod
def from_bytes(data:bytes, root_hbin:NTRegistryHbin = None, is_file:bool = True):
return AIOWinRegHive(io.BytesIO(data), root_hbin = root_hbin, is_file = is_file)

@staticmethod
def from_buffer(buff: io.BytesIO, root_hbin:NTRegistryHbin = None, is_file:bool = True):
return AIOWinRegHive(buff, root_hbin = root_hbin, is_file = is_file)

@staticmethod
def from_file(file_path:str, root_hbin:NTRegistryHbin = None):
return AIOWinRegHive(open(file_path, 'rb'), root_hbin=root_hbin, is_file = True)

def close(self):
self.reader.close()
Expand Down
14 changes: 13 additions & 1 deletion aiowinreg/utils/afile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io

class AFile:
"""
Expand All @@ -16,4 +17,15 @@ async def read(self, n = -1):
async def close(self):
return self.fd.close()


class ABuffer:
def __init__(self, buffer:io.BytesIO):
self.fd = buffer

async def seek(self, pos, whence = 0):
return self.fd.seek(pos, whence)

async def read(self, n = -1):
return self.fd.read(n)

async def close(self):
return self.fd.close()

0 comments on commit c00f101

Please sign in to comment.