From 8fa68c05bd5794e09a7c9cff18f9d05c700b1682 Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Tue, 9 Jan 2024 13:59:16 -0700 Subject: [PATCH] Fix some issues raised by mypy --- pysoot/errors.py | 8 +------- pysoot/lifter.py | 6 ++++-- pysoot/sootir/soot_expr.py | 14 +++++++------- pysoot/sootir/soot_method.py | 4 ++-- pysoot/sootir/soot_statement.py | 2 +- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/pysoot/errors.py b/pysoot/errors.py index a2012f0..6229a8a 100644 --- a/pysoot/errors.py +++ b/pysoot/errors.py @@ -1,4 +1,3 @@ - class PySootError(Exception): pass @@ -7,10 +6,5 @@ class ParameterError(PySootError): pass -class JythonClientException(PySootError): +class JavaNotFoundError(PySootError): pass - - -class RecvException(PySootError): - pass - diff --git a/pysoot/lifter.py b/pysoot/lifter.py index 4f179db..41e6579 100644 --- a/pysoot/lifter.py +++ b/pysoot/lifter.py @@ -2,7 +2,7 @@ import logging import subprocess -from .errors import ParameterError +from .errors import JavaNotFoundError, ParameterError from .soot_manager import SootManager @@ -57,7 +57,7 @@ def __init__(self, input_file=None, input_format="jar", ir_format="shimple", add self._get_ir() - def _get_ir(self): + def _get_ir(self) -> None: config = {} settings = ["input_file", "input_format", "ir_format", "android_sdk", "soot_classpath", "main_class"] for s in settings: @@ -87,3 +87,5 @@ def _get_java_home() -> str: for line in result.stderr.splitlines(): if "java.home" in line: return line.split('=')[1].strip() + + raise JavaNotFoundError diff --git a/pysoot/sootir/soot_expr.py b/pysoot/sootir/soot_expr.py index 8d9b061..e2a948b 100644 --- a/pysoot/sootir/soot_expr.py +++ b/pysoot/sootir/soot_expr.py @@ -188,7 +188,7 @@ def from_ir(type_, expr_name, ir_subvalue): return SootNewMultiArrayExpr( type_, str(ir_subvalue.getBaseType()), - (SootValue.from_ir(size) for size in ir_subvalue.getSizes()), + tuple(SootValue.from_ir(size) for size in ir_subvalue.getSizes()), ) @@ -219,7 +219,7 @@ def __str__(self): def from_ir(type_, expr_name, ir_subvalue): # FIXME: this 0 is wrong, we need to figure out the right value! return SootPhiExpr( - type_, ((SootValue.from_ir(v.getValue()), 0) for v in ir_subvalue.getArgs()) + type_, tuple((SootValue.from_ir(v.getValue()), 0) for v in ir_subvalue.getArgs()) ) @@ -328,7 +328,7 @@ def __str__(self): def from_ir(type_, expr_name, ir_expr): args = tuple([SootValue.from_ir(arg) for arg in ir_expr.getArgs()]) called_method = ir_expr.getMethod() - params = (str(param) for param in called_method.getParameterTypes()) + params = tuple(str(param) for param in called_method.getParameterTypes()) return SootInterfaceInvokeExpr( type=type_, @@ -357,7 +357,7 @@ def __str__(self): def from_ir(type_, expr_name, ir_expr): args = tuple(SootValue.from_ir(arg) for arg in ir_expr.getArgs()) called_method = ir_expr.getMethod() - params = (str(param) for param in called_method.getParameterTypes()) + params = tuple(str(param) for param in called_method.getParameterTypes()) return SootSpecialInvokeExpr( type=type_, @@ -382,9 +382,9 @@ def __str__(self): @staticmethod def from_ir(type_, expr_name, ir_expr): - args = (SootValue.from_ir(arg) for arg in ir_expr.getArgs()) + args = tuple(SootValue.from_ir(arg) for arg in ir_expr.getArgs()) called_method = ir_expr.getMethod() - params = (str(param) for param in called_method.getParameterTypes()) + params = tuple(str(param) for param in called_method.getParameterTypes()) return SootStaticInvokeExpr( type=type_, @@ -396,7 +396,7 @@ def from_ir(type_, expr_name, ir_expr): @dataclass(frozen=True) -class SootInstanceOfExpr(SootValue): +class SootInstanceOfExpr(SootExpr): __slots__ = ["check_type", "value"] # TODO: replace with dataclass in Python 3.10 check_type: str value: SootValue diff --git a/pysoot/sootir/soot_method.py b/pysoot/sootir/soot_method.py index 7aebb7c..43cd645 100644 --- a/pysoot/sootir/soot_method.py +++ b/pysoot/sootir/soot_method.py @@ -7,7 +7,7 @@ from frozendict import frozendict from jpype.types import JClass -from .soot_expr import SootPhiExpr, NAME_TO_CLASS +from .soot_expr import SootPhiExpr from .soot_block import SootBlock from .soot_value import SootValue from . import convert_soot_attributes @@ -123,7 +123,7 @@ def from_ir(class_name, ir_method): ) # TODO: Are we supposed to do something with this? - params = (str(p) for p in ir_method.getParameterTypes()) + params = tuple(str(p) for p in ir_method.getParameterTypes()) attrs = convert_soot_attributes(ir_method.getModifiers()) exceptions = tuple(e.getName() for e in ir_method.getExceptions()) rt = str(ir_method.getReturnType()) diff --git a/pysoot/sootir/soot_statement.py b/pysoot/sootir/soot_statement.py index 28a40f5..7a063ef 100644 --- a/pysoot/sootir/soot_statement.py +++ b/pysoot/sootir/soot_statement.py @@ -7,7 +7,7 @@ from .soot_value import SootValue -NAME_TO_CLASS = {} +NAME_TO_CLASS: dict[str, type[SootStmt]] = {} @dataclass(frozen=True)