Skip to content

Commit

Permalink
Fix some issues raised by mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
twizmwazin committed Jan 9, 2024
1 parent 625e95f commit 8fa68c0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
8 changes: 1 addition & 7 deletions pysoot/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class PySootError(Exception):
pass

Expand All @@ -7,10 +6,5 @@ class ParameterError(PySootError):
pass


class JythonClientException(PySootError):
class JavaNotFoundError(PySootError):
pass


class RecvException(PySootError):
pass

6 changes: 4 additions & 2 deletions pysoot/lifter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import subprocess

from .errors import ParameterError
from .errors import JavaNotFoundError, ParameterError
from .soot_manager import SootManager


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
14 changes: 7 additions & 7 deletions pysoot/sootir/soot_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
)


Expand Down Expand Up @@ -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())
)


Expand Down Expand Up @@ -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_,
Expand Down Expand Up @@ -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_,
Expand All @@ -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_,
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pysoot/sootir/soot_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion pysoot/sootir/soot_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .soot_value import SootValue


NAME_TO_CLASS = {}
NAME_TO_CLASS: dict[str, type[SootStmt]] = {}


@dataclass(frozen=True)
Expand Down

0 comments on commit 8fa68c0

Please sign in to comment.