7

Proguard を使用して Android アプリケーションを難読化しています。すべて正常に動作しますが、エラー レポートからスタック トレースをたどるのに苦労しています。

難読化されたコードの抜粋は次のとおりです。

    private ez a(x paramx)
  {
    return (ez)this.J.get(paramx);
  }

  private void a(com.b.a.f paramf)
  {
    Iterator localIterator = this.K.iterator();
    while (true)
    {
      if (!localIterator.hasNext())
        return;
      em localem = (em)localIterator.next();
      if (localem.a((int)(this.i / this.m - 202.0F), (int)(202.0F + (this.i + this.n) / this.m), (int)(this.j / this.m - 202.0F), (int)(202.0F + (this.j + this.o) / this.m)))
        localem.a(paramf, this.m, this.i, this.j);
    }
  }

  private void a(com.b.a.f paramf, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    Iterator localIterator = this.J.entrySet().iterator();
    while (true)
    {
      if (!localIterator.hasNext())
        return;
      ez localez = (ez)((Map.Entry)localIterator.next()).getValue();
      if (localez.a(paramInt1, paramInt2, paramInt3, paramInt4))
        localez.a(paramf, this.k, this.m, this.i, this.j);
    }
  }

上記の 3 つのメソッド (同じクラスから取得) はすべて同じ名前 = 'a' を持っていることに気付くでしょう。もちろん、パラメータが異なるため、実行時に問題は発生しません。ただし、難読化されたスタック トレースでは次のようになります。

java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
at java.util.concurrent.CopyOnWriteArrayList.get(CopyOnWriteArrayList.java:117)
at uk.co.ionage.ionage.co.a(Unknown Source)
at uk.co.ionage.ionage.co.g(Unknown Source)
at uk.co.ionage.ionage.n.b(Unknown Source)
at uk.co.ionage.ionage.n.a(Unknown Source)
at uk.co.ionage.ionage.co.a(Unknown Source)
at uk.co.ionage.ionage.co.a(Unknown Source)
at uk.co.ionage.ionage.Gameplay.a(Unknown Source)
at uk.co.ionage.ionage.cn.run(Unknown Source)

これは問題です。それがどの「a」メソッドを指しているのかわかりません。retrace.bat を使用すると、「a」という名前のすべてのメソッドが一覧表示されます。

これが私のproguard.configです:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-dontwarn android.support.**
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with
#fields. Proguard removes such information by default, so configure it to keep
#all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.gameanalytics.android.** { *; }
##---------------End: proguard configuration for Gson ----------

JSON/GSON の使用をサポートするために最後に少し追加したことを除いて、これは非常に一般的です。

プロガードにすべてのメソッドに別の名前を付けるオプションを追加できますか?

4

1 に答える 1

15

行番号が欠落しているため、スタック トレースがあいまいになっています。これらの ProGuard オプションを使用してそれらを保持できます。

-renamesourcefileattribute MyApplication
-keepattributes SourceFile,LineNumberTable

ProGuard のマニュアル > ReTrace >使用法を参照してください。

ProGuard のマニュアル > 例 >有用なスタック トレースの生成を参照してください。

または、一意の名前を割り当てることもできます。

-useuniqueclassmembernames

でも。メソッド名は最初からオーバーロードできますが、ProGuard はそれを変更しません。

補足: Android SDK の最近のバージョンでは、project.properties を適切に設定すると、構成のデフォルト部分が自動的に適用されます。

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
于 2013-07-28T13:47:06.873 に答える