Skip to content

Commit

Permalink
mend
Browse files Browse the repository at this point in the history
  • Loading branch information
Nariman committed May 27, 2024
1 parent 73eb5bd commit 44e4590
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
3 changes: 1 addition & 2 deletions dissect/thumbcache/c_thumbcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,4 @@
uint32 Unknown; // 0x28
}; // 0x2C
"""
c_thumbcache_index = cstruct()
c_thumbcache_index.load(c_thumbcache_index_def)
c_thumbcache_index = cstruct().load(c_thumbcache_index_def)
13 changes: 8 additions & 5 deletions dissect/thumbcache/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from datetime import datetime
from typing import BinaryIO, Iterator

from dissect.cstruct import Structure
from dissect.util import ts

from dissect.thumbcache.c_thumbcache import c_thumbcache_index
Expand All @@ -30,12 +29,12 @@ def __init__(self, fh: BinaryIO) -> None:
self._header = None

@property
def header(self) -> Structure:
def header(self) -> c_thumbcache_index.INDEX_HEADER_V1 | c_thumbcache_index.INDEX_HEADER_V2:
if self._header is None:
self._header = self._find_header(self.fh)
return self._header

def _find_header(self, fh: BinaryIO) -> Structure:
def _find_header(self, fh: BinaryIO) -> c_thumbcache_index.INDEX_HEADER_V1 | c_thumbcache_index.INDEX_HEADER_V2:
"""Searches for the header signature, and puts ``fh`` at the correct position.
From Windows 8.1 onward, the two fields seem to use a 64-bit format field
Expand Down Expand Up @@ -118,12 +117,16 @@ def __init__(self, fh: BinaryIO, type: ThumbnailType) -> None:
self._data = None

@property
def header(self) -> Structure:
def header(
self,
) -> c_thumbcache_index.VISTA_ENTRY | c_thumbcache_index.WINDOWS7_ENTRY | c_thumbcache_index.WINDOWS8_ENTRY:
if not self._header:
self._header = self._select_header()
return self._header

def _select_header(self) -> Structure:
def _select_header(
self,
) -> c_thumbcache_index.VISTA_ENTRY | c_thumbcache_index.WINDOWS7_ENTRY | c_thumbcache_index.WINDOWS8_ENTRY:
"""Selects header version according to the thumbnailtype."""
if self.type == ThumbnailType.WINDOWS_VISTA:
return c_thumbcache_index.VISTA_ENTRY(self.fh)
Expand Down
10 changes: 5 additions & 5 deletions dissect/thumbcache/thumbcache_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from typing import Any, BinaryIO

from dissect.cstruct import Structure

from dissect.thumbcache.c_thumbcache import c_thumbcache_index
from dissect.thumbcache.exceptions import (
InvalidSignatureError,
Expand Down Expand Up @@ -41,7 +39,7 @@ def __init__(self, fh: BinaryIO) -> None:
self._header = self._get_header_type(self.fh)
self._cached_entries: dict[int, ThumbcacheEntry] = {}

def _get_header_type(self, fh: BinaryIO) -> Structure:
def _get_header_type(self, fh: BinaryIO) -> c_thumbcache_index.CACHE_HEADER_VISTA | c_thumbcache_index.CACHE_HEADER:
tmp_header = c_thumbcache_index.CACHE_HEADER(fh)

if self._signature != tmp_header.Signature:
Expand All @@ -55,7 +53,7 @@ def _get_header_type(self, fh: BinaryIO) -> Structure:
return tmp_header

@property
def header(self) -> Structure:
def header(self) -> c_thumbcache_index.CACHE_HEADER_VISTA | c_thumbcache_index.CACHE_HEADER:
return self._header

@property
Expand Down Expand Up @@ -134,7 +132,9 @@ def __init__(self, fh: BinaryIO, type: ThumbnailType) -> None:

self._data = fh.read(self._header.Size - header_size)

def _get_header(self, thumbnail_type: ThumbnailType) -> type[Structure]:
def _get_header(
self, thumbnail_type: ThumbnailType
) -> type[c_thumbcache_index.CACHE_ENTRY_VISTA | c_thumbcache_index.CACHE_ENTRY]:
if thumbnail_type == ThumbnailType.WINDOWS_VISTA:
return c_thumbcache_index.CACHE_ENTRY_VISTA
else:
Expand Down

0 comments on commit 44e4590

Please sign in to comment.