feat: Phase 5 dynamic string resolution via DexTrace#919
Draft
haeter525 wants to merge 2 commits into
Draft
Conversation
Adds opt-in dynamic_resolve=False parameter to Quark.__init__ that uses
DexTrace to execute encrypted string methods at analysis time, recovering
plaintext for Phase 5 keyword matching.
Core changes:
- _resolveStringCalls: two-phase resolver — (1) prior calls of methodCall,
(2) PyEval-scan of parentMethod's callers for String-returning calls when
the encryption function lives in a higher frame
- _dextrace_cached: LRU-cached per (apk_path, sig) to avoid re-executing
the same method across multiple keyword checks
- getMatchedKeywords: fixed Primitive('') guard, accepts parentMethod,
delegates to DexTrace only when no meaningful static primitives found
- checkParameterOnSingleMethod / check_parameter: thread parentMethod down
- CLI: --dynamic-resolve flag; setup.py: extras_require["dynamic"]
Verified: bianlian.apk auto_click_comfirm_button_on_dialog.json
static → 80% (Phase 5 FN: dilemmaexact() string not resolved)
dynamic → 100% (Phase 5 passes after DexTrace executes dilemmaexact())
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #919 +/- ##
==========================================
+ Coverage 81.31% 81.40% +0.09%
==========================================
Files 80 80
Lines 6946 6969 +23
==========================================
+ Hits 5648 5673 +25
+ Misses 1298 1296 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add DexTrace-based dynamic string resolution to resolve encrypted strings for Phase 5 keyword matching. The false negative on bianlian APK (80% → 100% confidence) is the motivating case.
How to Test
1. Install DexTrace (development install)
2. Install quark-engine with this branch
3. Download the sample APK
Download bianlian.zip (Password: infected) and extract
bianlian.apk.4. Save the detection rule
Save the following as
auto_click_comfirm_button_on_dialog.json:{ "crime": "Auto click button on system dialog", "permission": [], "api": [ { "class": "Landroid/view/accessibility/AccessibilityNodeInfo;", "method": "findAccessibilityNodeInfosByText", "descriptor": "(Ljava/lang/String;)Ljava/util/List;", "match_keywords": [ "android:id/button1" ] }, { "class": "Landroid/view/accessibility/AccessibilityNodeInfo;", "method": "performAction", "descriptor": "(I)Z" } ], "score": 10, "label": ["sms", "calllog", "collection"] }5. Run — compare static vs dynamic
The sample first calls the method
dilemmaexact()to compute a string, then takes it as the 2nd argument to call thefindButtonAndClickmethod:The method then calls the first API
findAccessibilityNodeInfosByTextwith this string to locate a button on the system dialog:Quark Analysis Without
--dynamic-resolve(static only)Since the string is dynamically computed, the Quark rule above cannot fully detect this behavior, resulting in an 80% confidence score.
Quark Analysis With
--dynamic-resolveWith the dynamic string resolution feature, Quark successfully resolves the string from the
dilemmaexact()method and identifies the target behavior with 100% confidence.