Skip to content

Commit bd96357

Browse files
author
Valentin Obst
committed
tolerate duplicate enum values, keep first name that was seen
1 parent 4ac261c commit bd96357

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

volatility3/framework/objects/__init__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -593,17 +593,19 @@ def _generate_inverse_choices(cls, choices: Dict[str, int]) -> Dict[int, str]:
593593
inverse_choices: Dict[int, str] = {}
594594
for k, v in choices.items():
595595
if v in inverse_choices:
596-
# Technically this shouldn't be a problem, but since we inverse cache
597-
# and can't map one value to two possibilities we throw an exception during build
598-
# We can remove/work around this if it proves a common issue
599-
raise ValueError(
600-
f"Enumeration value {v} duplicated as {k} and {inverse_choices[v]}"
596+
vollog.log(
597+
constants.LOGLEVEL_VVV,
598+
f"Enumeration value {v} duplicated as {k}. Keeping name {inverse_choices[v]}",
601599
)
600+
continue
602601
inverse_choices[v] = k
603602
return inverse_choices
604603

605604
def lookup(self, value: int = None) -> str:
606-
"""Looks up an individual value and returns the associated name."""
605+
"""Looks up an individual value and returns the associated name.
606+
607+
If multiple identifiers map to the same value, the first matching identifier will be returned
608+
"""
607609
if value is None:
608610
return self.lookup(self)
609611
if value in self._inverse_choices:
@@ -640,7 +642,10 @@ class VolTemplateProxy(interfaces.objects.ObjectInterface.VolTemplateProxy):
640642

641643
@classmethod
642644
def lookup(cls, template: interfaces.objects.Template, value: int) -> str:
643-
"""Looks up an individual value and returns the associated name."""
645+
"""Looks up an individual value and returns the associated name.
646+
647+
If multiple identifiers map to the same value, the first matching identifier will be returned
648+
"""
644649
_inverse_choices = Enumeration._generate_inverse_choices(
645650
template.vol["choices"]
646651
)

0 commit comments

Comments
 (0)