Skip to content

Commit

Permalink
remove explicit dependence on typing_extensions, as we can do self-re…
Browse files Browse the repository at this point in the history
…ferencing type hints using 'from __future__ import annotations'..however note that typing_extensions is still installed by some underlying package.
  • Loading branch information
ehrenb committed Apr 27, 2024
1 parent b8545d8 commit 99afe72
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
25 changes: 12 additions & 13 deletions androguard/core/analysis/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from loguru import logger
import networkx as nx
from typing_extensions import Self

BasicOPCODES = set()
for i in dex.BRANCH_DEX_OPCODES:
Expand Down Expand Up @@ -264,7 +263,7 @@ def get_last(self) -> dex.Instruction:
"""
return list(self.get_instructions())[-1]

def get_next(self) -> Self:
def get_next(self) -> DEXBasicBlock:
"""
Get next basic blocks
Expand All @@ -273,7 +272,7 @@ def get_next(self) -> Self:
"""
return self.childs

def get_prev(self) -> Self:
def get_prev(self) -> DEXBasicBlock:
"""
Get previous basic blocks
Expand All @@ -282,7 +281,7 @@ def get_prev(self) -> Self:
"""
return self.fathers

def set_fathers(self, f: Self) -> None:
def set_fathers(self, f: DEXBasicBlock) -> None:
self.fathers.append(f)

def get_last_length(self) -> int:
Expand All @@ -307,7 +306,7 @@ def set_childs(self, values: list[int]) -> None:
if c[2] is not None:
c[2].set_fathers((c[1], c[0], self))

def push(self, i: Self) -> None:
def push(self, i: DEXBasicBlock) -> None:
self.nb_instructions += 1
idx = self.end
self.last_length = i.get_length()
Expand Down Expand Up @@ -1154,7 +1153,7 @@ def add_field(self, field_analysis: FieldAnalysis) -> None:
# # Propagate ExternalField to ExternalClass
# self.orig_class.add_method(field_analysis.get_field())

def add_field_xref_read(self, method: MethodAnalysis, classobj: Self, field: dex.EncodedField, off: int) -> None:
def add_field_xref_read(self, method: MethodAnalysis, classobj: ClassAnalysis, field: dex.EncodedField, off: int) -> None:
"""
Add a Field Read to this class
Expand All @@ -1168,7 +1167,7 @@ def add_field_xref_read(self, method: MethodAnalysis, classobj: Self, field: dex
self._fields[field] = FieldAnalysis(field)
self._fields[field].add_xref_read(classobj, method, off)

def add_field_xref_write(self, method: MethodAnalysis, classobj: Self, field: dex.EncodedField, off: int) -> None:
def add_field_xref_write(self, method: MethodAnalysis, classobj: ClassAnalysis, field: dex.EncodedField, off: int) -> None:
"""
Add a Field Write to this class in a given method
Expand All @@ -1182,7 +1181,7 @@ def add_field_xref_write(self, method: MethodAnalysis, classobj: Self, field: de
self._fields[field] = FieldAnalysis(field)
self._fields[field].add_xref_write(classobj, method, off)

def add_method_xref_to(self, method1: MethodAnalysis, classobj: Self, method2: MethodAnalysis, offset: int) -> None:
def add_method_xref_to(self, method1: MethodAnalysis, classobj: ClassAnalysis, method2: MethodAnalysis, offset: int) -> None:
"""
:param MethodAnalysis method1: the calling method
Expand All @@ -1198,7 +1197,7 @@ def add_method_xref_to(self, method1: MethodAnalysis, classobj: Self, method2: M

self._methods[method1.get_method()].add_xref_to(classobj, method2, offset)

def add_method_xref_from(self, method1: MethodAnalysis, classobj: Self, method2: MethodAnalysis, offset: int) -> None:
def add_method_xref_from(self, method1: MethodAnalysis, classobj: ClassAnalysis, method2: MethodAnalysis, offset: int) -> None:
"""
:param MethodAnalysis method1:
Expand All @@ -1213,7 +1212,7 @@ def add_method_xref_from(self, method1: MethodAnalysis, classobj: Self, method2:

self._methods[method1.get_method()].add_xref_from(classobj, method2, offset)

def add_xref_to(self, ref_kind: REF_TYPE, classobj: Self, methodobj: MethodAnalysis, offset: int) -> None:
def add_xref_to(self, ref_kind: REF_TYPE, classobj: ClassAnalysis, methodobj: MethodAnalysis, offset: int) -> None:
"""
Creates a crossreference to another class.
XrefTo means, that the current class calls another class.
Expand All @@ -1232,7 +1231,7 @@ def add_xref_to(self, ref_kind: REF_TYPE, classobj: Self, methodobj: MethodAnaly
"""
self.xrefto[classobj].add((ref_kind, methodobj, offset))

def add_xref_from(self, ref_kind: REF_TYPE, classobj: Self, methodobj: MethodAnalysis, offset: int) -> None:
def add_xref_from(self, ref_kind: REF_TYPE, classobj: ClassAnalysis, methodobj: MethodAnalysis, offset: int) -> None:
"""
Creates a crossreference from this class.
XrefFrom means, that the current class is called by another class.
Expand All @@ -1245,7 +1244,7 @@ def add_xref_from(self, ref_kind: REF_TYPE, classobj: Self, methodobj: MethodAna
"""
self.xreffrom[classobj].add((ref_kind, methodobj, offset))

def get_xref_from(self) -> dict[Self, tuple[REF_TYPE, MethodAnalysis, int]]:
def get_xref_from(self) -> dict[ClassAnalysis, tuple[REF_TYPE, MethodAnalysis, int]]:
"""
Returns a dictionary of all classes calling the current class.
This dictionary contains also information from which method the class is accessed.
Expand All @@ -1271,7 +1270,7 @@ def get_xref_from(self) -> dict[Self, tuple[REF_TYPE, MethodAnalysis, int]]:
"""
return self.xreffrom

def get_xref_to(self) -> dict[Self, tuple[REF_TYPE, MethodAnalysis, int]]:
def get_xref_to(self) -> dict[ClassAnalysis, tuple[REF_TYPE, MethodAnalysis, int]]:
"""
Returns a dictionary of all classes which are called by the current class.
This dictionary contains also information about the method which is called.
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ PyQt5-Qt5 = [
]
pyyaml = "*"
oscrypto = ">=1.3.0"
typing_extensions = "*"

[tool.setuptools.package_data]
"androguard.core.api_specific_resources" = ["aosp_permissions/*.json", "api_permission_mappings/*.json"]
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ matplotlib
networkx
PyQt5
pyyaml
oscrypto>=1.3.0
typing_extensions
oscrypto>=1.3.0

0 comments on commit 99afe72

Please sign in to comment.