Skip to content

Commit

Permalink
Added warnings for loaded classes (#403)
Browse files Browse the repository at this point in the history
* Added warnings for loaded classes

* Fix unittests
  • Loading branch information
TheDauntless committed Feb 17, 2021
1 parent 26f277d commit 8abb553
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
14 changes: 12 additions & 2 deletions objection/commands/android/hooking.py
Expand Up @@ -52,7 +52,9 @@ def _should_dump_return_value(args: list) -> bool:

def show_android_classes(args: list = None) -> None:
"""
Show the currently loaded classes.
Show the currently loaded classes.
Note that Java classes are only loaded when they are used,
so not all classes may be present.
:param args:
:return:
Expand Down Expand Up @@ -269,7 +271,9 @@ def set_method_return_value(args: list = None) -> None:

def search_class(args: list) -> None:
"""
Searches the current Android application for a class.
Searches the currently loaded classes for a class.
Note that Java classes are only loaded when they are used,
so if you don't get results, the class might not have been used yet.
:param args:
:return:
Expand All @@ -279,6 +283,9 @@ def search_class(args: list) -> None:
click.secho('Usage: android hooking search classes <name>', bold=True)
return

click.secho('Note that Java classes are only loaded when they are used,'
' so if the expected class has not been found, it might not have been loaded yet.', fg='yellow')

search = args[0]
found = 0

Expand Down Expand Up @@ -311,6 +318,9 @@ def search_methods(args: list) -> None:
class_filter = args[1] if len(clean_argument_flags(args)) > 1 else None
found = 0

click.secho('Note that Java classes are only loaded when they are used,'
' so if the expected class has not been found, it might not have been loaded yet.', fg='yellow')

if not class_filter:
click.secho('Warning, searching all classes may take some time and in some cases, '
'crash the target application.', fg='yellow')
Expand Down
17 changes: 11 additions & 6 deletions tests/commands/android/test_hooking.py
Expand Up @@ -241,7 +241,7 @@ def test_search_class_handles_empty_data(self, mock_api):
with capture(search_class, ['com.foo.bar']) as o:
output = o

self.assertEqual(output, '\nFound 0 classes\n')
self.assertEqual(output, 'Note that Java classes are only loaded when they are used, so if the expected class has not been found, it might not have been loaded yet.\n\nFound 0 classes\n')

@mock.patch('objection.state.connection.state_connection.get_api')
def test_search_class(self, mock_api):
Expand All @@ -253,7 +253,8 @@ def test_search_class(self, mock_api):
with capture(search_class, ['com.foo.bar']) as o:
output = o

expected_output = """com.foo.bar
expected_output = """Note that Java classes are only loaded when they are used, so if the expected class has not been found, it might not have been loaded yet.
com.foo.bar
com.foo.bar.baz
Found 2 classes
Expand All @@ -279,7 +280,8 @@ def test_search_class_handles_empty_data_with_no_filter(self, mock_confirm, mock
with capture(search_methods, ['hteeteepee']) as o:
output = o

expected_output = """Warning, searching all classes may take some time and in some cases, crash the target application.
expected_output = """Note that Java classes are only loaded when they are used, so if the expected class has not been found, it might not have been loaded yet.
Warning, searching all classes may take some time and in some cases, crash the target application.
Found 0 classes, searching methods (this may take some time)...
Found 0 methods
Expand All @@ -295,7 +297,8 @@ def test_search_class_handles_empty_data_with_filter(self, mock_api):
with capture(search_methods, ['hteeteepee', 'com.foo']) as o:
output = o

expected_output = """Found 0 classes, searching methods (this may take some time)...
expected_output = """Note that Java classes are only loaded when they are used, so if the expected class has not been found, it might not have been loaded yet.
Found 0 classes, searching methods (this may take some time)...
Filtering classes with com.foo
Found 0 methods
Expand All @@ -315,7 +318,8 @@ def test_search_class_with_no_filter(self, mock_confirm, mock_api):
with capture(search_methods, ['hteeteepee']) as o:
output = o

expected_output = """Warning, searching all classes may take some time and in some cases, crash the target application.
expected_output = """Note that Java classes are only loaded when they are used, so if the expected class has not been found, it might not have been loaded yet.
Warning, searching all classes may take some time and in some cases, crash the target application.
Found 1 classes, searching methods (this may take some time)...
invoke_hteeteepee_method
Expand All @@ -338,7 +342,8 @@ def test_search_class_with_filter(self, mock_confirm, mock_api):
with capture(search_methods, ['hteeteepee', 'com.test']) as o:
output = o

expected_output = """Found 2 classes, searching methods (this may take some time)...
expected_output = """Note that Java classes are only loaded when they are used, so if the expected class has not been found, it might not have been loaded yet.
Found 2 classes, searching methods (this may take some time)...
Filtering classes with com.test
invoke_hteeteepee_method
Expand Down

0 comments on commit 8abb553

Please sign in to comment.