Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple minor bugs #379

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cle/backends/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def __init__(
self._binary_stream: BufferedReader = binary_stream
if self.binary is not None:
self.binary_basename = os.path.basename(self.binary)
elif hasattr(self._binary_stream, "name"):
elif hasattr(self._binary_stream, "name") and type(self._binary_stream.name) is str:
self.binary_basename = os.path.basename(self._binary_stream.name)
else:
self.binary_basename = str(self._binary_stream)
Expand Down
13 changes: 8 additions & 5 deletions cle/backends/java/apk.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
class Apk(Soot):
"""
Backend for lifting Apk's to Soot.
Note that Soot doesn't support loading APK files from streams.
"""

is_default = True # let CLE automatically use this backend
Expand Down Expand Up @@ -134,7 +135,9 @@ def _set_lifecycle(self, apk_parser):
class_names = getter()
self.components[key], self.callbacks[key] = self._extract_lifecycle(class_names, key)

def _extract_lifecycle(self, cls_name: List[str], component_kind: str) -> Tuple[List[SootClass], List[SootMethod]]:
def _extract_lifecycle(
self, class_names: List[str], component_kind: str
) -> Tuple[List[SootClass], List[SootMethod]]:
"""
Extract components with callbacks from class names and component kind.
Use general callback name for each component by component kind
Expand All @@ -147,10 +150,10 @@ def _extract_lifecycle(self, cls_name: List[str], component_kind: str) -> Tuple[

components = []
callbacks = []

for cls in cls_name:
components.append(self.classes[cls])
callbacks.extend(self.get_callbacks(cls, callback[component_kind]))
for cls in class_names:
if cls in self.classes.keys():
components.append(self.classes[cls])
callbacks.extend(self.get_callbacks(cls, callback[component_kind]))

return components, callbacks

Expand Down
10 changes: 8 additions & 2 deletions cle/backends/java/soot.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ def get_soot_class(self, cls_name, none_if_missing=False):
else:
raise CLEError('Class "%s" does not exist.' % cls_name)

def get_soot_method(self, thing, class_name=None, params=(), none_if_missing=False):
def get_soot_method(self, thing, class_name=None, params=(), return_type=None, none_if_missing=False):
"""
Get Soot method object.

:param thing: Descriptor or the method, or name of the method.
:param str class_name: Name of the class. If not specified, class name can be parsed from method_name.
:param params: The method parameters
:param return_type: The methods return type
:return: Soot method that satisfy the criteria.
"""

Expand All @@ -131,6 +133,7 @@ def get_soot_method(self, thing, class_name=None, params=(), none_if_missing=Fal
"class_name": thing.class_name,
"name": thing.name,
"params": thing.params,
"return_type": thing.ret,
}

elif isinstance(thing, (str, bytes)):
Expand All @@ -149,6 +152,7 @@ def get_soot_method(self, thing, class_name=None, params=(), none_if_missing=Fal
"class_name": class_name,
"name": method_name,
"params": params,
"return_type": return_type,
}

else:
Expand Down Expand Up @@ -190,13 +194,15 @@ def get_soot_method(self, thing, class_name=None, params=(), none_if_missing=Fal
return methods[0]

@staticmethod
def _description_matches_soot_method(soot_method, name=None, class_name=None, params=()):
def _description_matches_soot_method(soot_method, name=None, class_name=None, params=(), return_type=None):
if name and soot_method.name != name:
return False
if class_name and soot_method.class_name != class_name:
return False
if soot_method.params != params:
return False
if soot_method.ret != return_type:
return False
return True

@property
Expand Down