Skip to content

Commit

Permalink
Changes to make vsapm the preferred APM back-end (#736)
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz authored May 13, 2023
1 parent 2ce8685 commit 44765f0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dfvfs/lib/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
TYPE_INDICATOR_VSHADOW])

# The preferred back-ends.
PREFERRED_APM_BACK_END = TYPE_INDICATOR_TSK_PARTITION
PREFERRED_APM_BACK_END = TYPE_INDICATOR_APM
PREFERRED_EXT_BACK_END = TYPE_INDICATOR_EXT
PREFERRED_FAT_BACK_END = TYPE_INDICATOR_TSK
PREFERRED_GPT_BACK_END = TYPE_INDICATOR_GPT
Expand Down
15 changes: 10 additions & 5 deletions dfvfs/vfs/apm_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
class APMDirectory(directory.Directory):
"""File system directory that uses pyvsapm."""

_STATUS_FLAG_IS_VALID = 0x00000001
_STATUS_FLAG_IS_ALLOCATED = 0x00000002

def _EntriesGenerator(self):
"""Retrieves directory entries.
Expand All @@ -25,8 +28,10 @@ def _EntriesGenerator(self):
location == self._file_system.LOCATION_ROOT):
vsapm_volume = self._file_system.GetAPMVolume()

for partition_index in range(vsapm_volume.number_of_partitions):
apm_entry_index = partition_index + 1
yield apm_path_spec.APMPathSpec(
entry_index=entry_index, location=f'/p{apm_entry_index:d}',
parent=self.path_spec.parent)
for partition_index, partition in enumerate(vsapm_volume.partitions):
if (partition.status_flags & self._STATUS_FLAG_IS_VALID and
partition.status_flags & self._STATUS_FLAG_IS_ALLOCATED):
apm_entry_index = partition_index + 1
yield apm_path_spec.APMPathSpec(
entry_index=entry_index, location=f'/p{apm_entry_index:d}',
parent=self.path_spec.parent)
2 changes: 1 addition & 1 deletion tests/analyzer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def testGetVolumeSystemTypeIndicatorsAPM(self):

path_spec = os_path_spec.OSPathSpec(location=test_file)

expected_type_indicators = [definitions.TYPE_INDICATOR_TSK_PARTITION]
expected_type_indicators = [definitions.PREFERRED_APM_BACK_END]
type_indicators = analyzer.Analyzer.GetVolumeSystemTypeIndicators(path_spec)
self.assertEqual(type_indicators, expected_type_indicators)

Expand Down
23 changes: 19 additions & 4 deletions tests/helpers/source_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,29 @@ def testScanOnAPM(self):
self.assertEqual(
scan_context.source_type, definitions.SOURCE_TYPE_STORAGE_MEDIA_IMAGE)

scan_node = self._GetTestScanNode(scan_context)
scan_node = scan_context.GetRootScanNode()
self.assertIsNotNone(scan_node)
self.assertEqual(scan_node.type_indicator, definitions.TYPE_INDICATOR_OS)
self.assertEqual(len(scan_node.sub_nodes), 1)

scan_node = scan_node.sub_nodes[0]
self.assertIsNotNone(scan_node)
self.assertEqual(scan_node.type_indicator, definitions.TYPE_INDICATOR_RAW)
self.assertEqual(len(scan_node.sub_nodes), 1)

scan_node = scan_node.sub_nodes[0]
self.assertIsNotNone(scan_node)
self.assertEqual(
scan_node.type_indicator, definitions.TYPE_INDICATOR_TSK_PARTITION)
scan_node.type_indicator, definitions.PREFERRED_APM_BACK_END)

self.assertEqual(len(scan_node.sub_nodes), 5)
if scan_node.type_indicator == definitions.TYPE_INDICATOR_TSK_PARTITION:
self.assertEqual(len(scan_node.sub_nodes), 5)
scan_node = scan_node.sub_nodes[3]
else:
self.assertEqual(len(scan_node.sub_nodes), 1)
scan_node = scan_node.sub_nodes[0]

scan_node = scan_node.sub_nodes[3].GetSubNodeByLocation('/')
scan_node = scan_node.GetSubNodeByLocation('/')
self.assertIsNotNone(scan_node)
self.assertEqual(
scan_node.type_indicator, definitions.PREFERRED_HFS_BACK_END)
Expand Down
2 changes: 1 addition & 1 deletion tests/vfs/apm_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def testEntriesGenerator(self):
self.assertIsNotNone(directory)

entries = list(directory.entries)
self.assertEqual(len(entries), 2)
self.assertEqual(len(entries), 1)


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions tests/volume/apm_volume_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def testIterateVolumes(self):
volume_system.Open(self._apm_path_spec)

self.assertEqual(volume_system.number_of_sections, 0)
self.assertEqual(volume_system.number_of_volumes, 2)
self.assertEqual(volume_system.number_of_volumes, 1)

self.assertEqual(volume_system.volume_identifiers, ['p1', 'p2'])
self.assertEqual(volume_system.volume_identifiers, ['p1'])

volume = volume_system.GetVolumeByIndex(0)
self.assertIsNotNone(volume)
Expand Down

0 comments on commit 44765f0

Please sign in to comment.