Skip to content

Add method reference for check_sequence#520

Merged
haeter525 merged 2 commits into
ev-flow:masterfrom
zinwang:add_method_reference_for_check_sequence
Jun 11, 2023
Merged

Add method reference for check_sequence#520
haeter525 merged 2 commits into
ev-flow:masterfrom
zinwang:add_method_reference_for_check_sequence

Conversation

@zinwang

@zinwang zinwang commented Jun 9, 2023

Copy link
Copy Markdown
Contributor

check_sequence

The algorithm of check_sequence

The function check_sequence checks if mutual_parent calls any first method before any second method. If Yes, check_sequence records the mapping between mutual_parent and the matched methods and returns True.

Here is the process of check_sequence.

1. Initialize the variable state as False.

2. Iterate the method pairs formed by first_method_list and second_method_list.

3. From mutual_parent, find method calls that call any method in the pair. Then collect them into the list seq_table.

4. Check if the length of seq_table is less than 2.
    - If True, continue to the next iteration.
    
5. Sort seq_table according to the offsets of the method calls. Then name the sorted list as method_list_need_check.

6. Check if the method pair is a sublist of method_list_need_check.
    - If True, 
        - Set state to True.
        - Record the mapping between mutual_parent and the method pair in quark_analysis.
        
7. Return state.

Here is the flowchart of check_sequence.

The code of check_sequence

def check_sequence(
        self, mutual_parent, first_method_list, second_method_list
    ):
        """
        Check if the first function appeared before the second function.

        :param mutual_parent: function that call the first function and second functions at the same time.
        :param first_method_list: the first show up function, which is a MethodAnalysis
        :param second_method_list: the second show up function, which is a MethodAnalysis
        :return: True or False
        """
        state = False

        for first_call_method in first_method_list:
            for second_call_method in second_method_list:

                seq_table = [
                    (call, number)
                    for call, number in self.apkinfo.lowerfunc(mutual_parent)
                    if call in (first_call_method, second_call_method)
                ]

                # sorting based on the value of the number
                if len(seq_table) < 2:
                    # Not Found sequence in same_method
                    continue
                seq_table.sort(key=operator.itemgetter(1))
                # seq_table would look like: [(getLocation, 1256), (sendSms, 1566), (sendSms, 2398)]

                method_list_need_check = [x[0] for x in seq_table]
                sequence_pattern_method = [
                    first_call_method,
                    second_call_method,
                ]

                if tools.contains(
                    sequence_pattern_method, method_list_need_check
                ):
                    state = True

                    # Record the mapping between the parent function and the wrapper method
                    self.quark_analysis.parent_wrapper_mapping[
                        mutual_parent.full_name
                    ] = self.apkinfo.get_wrapper_smali(
                        mutual_parent, first_call_method, second_call_method
                    )

        return state

@zinwang zinwang added documentation Improvements or additions to documentation pr-processing-state-05 labels Jun 9, 2023
@zinwang zinwang requested a review from haeter525 June 9, 2023 13:57
@zinwang zinwang self-assigned this Jun 9, 2023
@codecov-commenter

codecov-commenter commented Jun 9, 2023

Copy link
Copy Markdown

Codecov Report

Patch and project coverage have no change.

Comparison is base (b3a249b) 79.19% compared to head (4197a2c) 79.19%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #520   +/-   ##
=======================================
  Coverage   79.19%   79.19%           
=======================================
  Files          63       63           
  Lines        4960     4960           
=======================================
  Hits         3928     3928           
  Misses       1032     1032           
Flag Coverage Δ
unittests 79.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@haeter525 haeter525 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! @haeter525 approves.

@haeter525 haeter525 merged commit 745f3c0 into ev-flow:master Jun 11, 2023
@zinwang zinwang deleted the add_method_reference_for_check_sequence branch January 20, 2024 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation pr-processing-state-05

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants