mirror of
https://github.com/mandiant/capa.git
synced 2025-12-12 15:49:46 -08:00
create function assert_never
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
# See the License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
import os
|
||||
from typing import NoReturn
|
||||
|
||||
_hex = hex
|
||||
|
||||
@@ -30,3 +31,7 @@ def is_runtime_ida():
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def assert_never(value: NoReturn) -> NoReturn:
|
||||
assert False, f'Unhandled value: {value} ({type(value).__name__})'
|
||||
|
||||
@@ -16,6 +16,8 @@ import functools
|
||||
import collections
|
||||
from enum import Enum
|
||||
|
||||
from capa.helpers import assert_never
|
||||
|
||||
try:
|
||||
from functools import lru_cache
|
||||
except ImportError:
|
||||
@@ -1090,7 +1092,7 @@ class RuleSet:
|
||||
rec(rule_name, child)
|
||||
else:
|
||||
# programming error
|
||||
raise Exception("programming error: unexpected node type: %s" % (node))
|
||||
assert_never(node)
|
||||
|
||||
for rule in rules:
|
||||
rule_name = rule.meta["name"]
|
||||
@@ -1195,7 +1197,7 @@ class RuleSet:
|
||||
easy_rules_by_feature = self._easy_basic_block_rules_by_feature
|
||||
hard_rule_names = self._hard_basic_block_rules
|
||||
else:
|
||||
raise Exception("programming error: unexpected scope")
|
||||
assert_never(scope)
|
||||
|
||||
candidate_rule_names = set()
|
||||
for feature in features:
|
||||
|
||||
Reference in New Issue
Block a user