【问题标题】:How to analyze leak trace of obfuscated 3rd party library code如何分析混淆的 3rd 方库代码的泄漏痕迹
【发布时间】:2021-02-02 22:37:40
【问题描述】:

我发现了内存泄漏(使用 LeakCanary),但泄漏跟踪中的代码被混淆了。我在代码混淆方面没有太多经验,我想知道是否有办法对其进行去混淆,或者可能对第三个库代码禁用代码混淆?

我使用的第三个库代码是yandex-ads-sdk。泄漏痕迹:

2020-10-20 12:03:00.931 D/LeakCanary: ​
┬───
│ GC Root: System class
│
├─ com.yandex.metrica.impl.ob.dr class
│    Leaking: NO (a class is never leaking)
│    ↓ static dr.a
│                ~
├─ com.yandex.metrica.impl.ob.dr instance
│    Leaking: UNKNOWN
│    Retaining 125 bytes in 5 objects
│    f instance of com.example.Application
│    ↓ dr.h
│         ~
├─ com.yandex.metrica.impl.ob.bj instance
│    Leaking: UNKNOWN
│    Retaining 1538 bytes in 60 objects
│    q instance of com.example.MainActivity with mDestroyed = false
│    a instance of com.example.Application
│    ↓ bj.n
│         ~
├─ com.yandex.metrica.impl.ob.aao instance
│    Leaking: UNKNOWN
│    Retaining 249 bytes in 13 objects
│    ↓ aao.i
│          ~
├─ com.yandex.metrica.uiaccessor.a instance
│    Leaking: UNKNOWN
│    Retaining 12 bytes in 1 objects
│    ↓ a.b
│        ~
├─ com.yandex.metrica.uiaccessor.a$1 instance
│    Leaking: UNKNOWN
│    Retaining 368482 bytes in 3462 objects
│    Anonymous subclass of androidx.fragment.app.FragmentManager$FragmentLifecycleCallbacks
│    a instance of com.example.MainActivity with mDestroyed = true
│    ↓ a$1.a
│          ~
╰→ com.example.MainActivity instance
​     Leaking: YES (ObjectWatcher was watching this because com.example.MainActivity received
​     Activity#onDestroy() callback and Activity#mDestroyed is true)
​     Retaining 368470 bytes in 3461 objects
​     key = 5b3ef21a-0cf4-4dae-b329-9dd2e9d2657e
​     watchDurationMillis = 5398
​     retainedDurationMillis = 397
​     mApplication instance of com.example.Application
​     mBase instance of android.app.ContextImpl, not wrapping known Android context

METADATA

Build.VERSION.SDK_INT: 26
Build.MANUFACTURER: samsung
LeakCanary version: 2.5
App process name: com.example.app
Stats: LruCache[maxSize=3000,hits=2461,misses=58027,hitRate=4%]
RandomAccess[bytes=2861846,reads=58027,travel=20176117749,range=13550252,size=16944114]
Analysis duration: 32101 ms

【问题讨论】:

    标签: android obfuscation leakcanary yandex-metrika


    【解决方案1】:

    不幸的是,Yandex 库被混淆了,您需要映射文件才能对泄漏跟踪进行去混淆(参见 https://square.github.io/leakcanary/changelog/#deobfuscating-hprof-files

    如果你想进一步挖掘,你可以下载 mobmetricalib AAR on Maven central (direct link 然后使用 JD-GUI 反编译字节码。它仍然会被混淆但你可以导航它。例如,这里的泄漏轨迹底部的 a 类的内容:

    package com.yandex.metrica.uiaccessor;
    
    import android.app.Activity;
    import android.support.annotation.NonNull;
    import android.support.annotation.Nullable;
    import android.support.v4.app.FragmentActivity;
    import android.support.v4.app.FragmentManager;
    
    public class a implements b {
      @NonNull
      private final a a;
      
      @Nullable
      private FragmentManager.FragmentLifecycleCallbacks b;
      
      public a(@NonNull a parama) throws Throwable {
        this
          .a = parama;
      }
      
      public void b(@NonNull Activity paramActivity) throws Throwable {
        if (paramActivity instanceof FragmentActivity) {
          if (this.b == null)
            this
              .b = new FragmentLifecycleCallback(this.a, paramActivity); 
          ((FragmentActivity)paramActivity)
            .getSupportFragmentManager()
            .unregisterFragmentLifecycleCallbacks(this.b);
          ((FragmentActivity)paramActivity).getSupportFragmentManager().registerFragmentLifecycleCallbacks(this.b, true);
        } 
      }
      
      public void a(@NonNull Activity paramActivity) throws Throwable {
        if (paramActivity instanceof FragmentActivity && this.b != null)
          ((FragmentActivity)paramActivity).getSupportFragmentManager().unregisterFragmentLifecycleCallbacks(this.b); 
      }
      
      public static interface a {
        void a(@NonNull Activity param1Activity);
      }
    }
    

    我建议通过泄漏跟踪与图书馆的所有者联系,并要求他们修复它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-18
      • 2012-12-16
      • 2017-03-01
      • 2014-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      相关资源
      最近更新 更多