記事一覧はこちら

androidのapkを改造する方法

Java - Androidのリバースエンジニアリング方法 - Qiita [キータ] これで9割OK。 後は自作のアプリを逆コンパイルして、この命令はこういう内容で と頑張って読む。

Sony Ericsson xperia series Home.apk コンパイルエラーの解決 | 所感 ~android~ apkをビルドする時にレイアウトファイルうんぬんのエラーが出たらここ。 サンプルが1例だけだらか心配だけど、「1つ上の兄弟ノード」の値をそのままコピペでok。機械的に出来る。

ここからが自作部分。 コピペで使える、ログに任意の値を書き出すメソッド。 staticだからどこからでも使える。.smaliのファイルの先頭にコピペする。多分constructorの次がいいと思う。#direct methodsがあるクラスの方がいいと思う。

# direct methods

.method public static decodeEverything(Ljava/lang/String;Ljava/lang/String;)V
    .locals 2
    .parameter "key"
    .parameter "log"

    .prologue
    .line 7
    new-instance v0, Ljava/lang/StringBuilder;

    const-string v1, "String["

    invoke-direct {v0, v1}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v0, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    const-string v1, "]"

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    invoke-static {p0, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    .line 8
    return-void
.end method

.method public static decodeEverything(Ljava/lang/String;Ljava/util/List;)V
    .locals 4
    .parameter "key"
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/lang/String;",
            "Ljava/util/List",
            "<",
            "Ljava/lang/String;",
            ">;)V"
        }
    .end annotation

    .prologue
    .line 24
    .local p1, target:Ljava/util/List;,"Ljava/util/List<Ljava/lang/String;>;"
    new-instance v0, Ljava/lang/StringBuffer;

    invoke-direct {v0}, Ljava/lang/StringBuffer;-><init>()V

    .line 25
    .local v0, sb:Ljava/lang/StringBuffer;
    invoke-interface {p1}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v2

    :goto_0
    invoke-interface {v2}, Ljava/util/Iterator;->hasNext()Z

    move-result v3

    if-nez v3, :cond_0

    .line 31
    new-instance v2, Ljava/lang/StringBuilder;

    const-string v3, "List<string>["

    invoke-direct {v2, v3}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v0}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v3

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    const-string v3, "]"

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-static {p0, v2}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    .line 32
    return-void

    .line 25
    :cond_0
    invoke-interface {v2}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Ljava/lang/String;

    .line 26
    .local v1, t:Ljava/lang/String;
    invoke-virtual {v0}, Ljava/lang/StringBuffer;->length()I

    move-result v3

    if-eqz v3, :cond_1

    .line 27
    const-string v3, ","

    invoke-virtual {v0, v3}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    .line 29
    :cond_1
    invoke-virtual {v0, v1}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    goto :goto_0
.end method

.method public static decodeEverything(Ljava/lang/String;[B)V
    .locals 6
    .parameter "key"
    .parameter "target"

    .prologue
    .line 10
    new-instance v2, Ljava/lang/StringBuffer;

    invoke-direct {v2}, Ljava/lang/StringBuffer;-><init>()V

    .line 11
    .local v2, sb:Ljava/lang/StringBuffer;
    array-length v4, p1

    const/4 v3, 0x0

    :goto_0
    if-lt v3, v4, :cond_0

    .line 14
    new-instance v3, Ljava/lang/StringBuilder;

    const-string v4, "byte[1/2]["

    invoke-direct {v3, v4}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v2}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    const-string v4, "]"

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v3

    invoke-static {p0, v3}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    .line 16
    :try_start_0
    new-instance v3, Ljava/lang/StringBuilder;

    const-string v4, "byte[2/2]["

    invoke-direct {v3, v4}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    new-instance v4, Ljava/lang/String;

    const-string v5, "utf-8"

    invoke-direct {v4, p1, v5}, Ljava/lang/String;-><init>([BLjava/lang/String;)V

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    const-string v4, "]"

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v3

    invoke-static {p0, v3}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I
    :try_end_0
    .catch Ljava/io/UnsupportedEncodingException; {:try_start_0 .. :try_end_0} :catch_0

    .line 22
    :goto_1
    return-void

    .line 11
    :cond_0
    aget-byte v0, p1, v3

    .line 12
    .local v0, b:B
    and-int/lit16 v5, v0, 0xff

    invoke-static {v5}, Ljava/lang/Integer;->toHexString(I)Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v5}, Ljava/lang/String;->toUpperCase()Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v2, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    .line 11
    add-int/lit8 v3, v3, 0x1

    goto :goto_0

    .line 17
    .end local v0           #b:B
    :catch_0
    move-exception v1

    .line 18
    .local v1, e:Ljava/io/UnsupportedEncodingException;
    invoke-virtual {v1}, Ljava/io/UnsupportedEncodingException;->printStackTrace()V

    .line 19
    const-string v3, "byte[2/2]decode-error"

    invoke-static {p0, v3}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    goto :goto_1
.end method

使い方はこの二行だけ。当然クラス名は適切な配置場所に変更。

    const-string v3, "pixiv-a(BB)-引数1"
    invoke-static {v3, p1}, Lnet/pixiv/android/lib/a;->decodeEverything(Ljava/lang/String;[B)V

元コードはこんな感じ

package ***;
import java.io.UnsupportedEncodingException;
public class DecodeEverything {
    public static void decodeEverything(String key,String log){
        android.util.Log.e(key,"String["+log+"]");
    }
    public static void decodeEverything(String key,byte[] target){
        StringBuffer sb = new StringBuffer();
        for ( byte b : target ){
            sb.append(Integer.toHexString( 0xFF & (int)b ).toUpperCase());
        }
        android.util.Log.e(key,"byte[1/2]["+sb.toString()+"]");
        try {
            android.util.Log.e(key,"byte[2/2]["+new String(target,"utf-8")+"]");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            android.util.Log.e(key,"byte[2/2]decode-error");
        }

    }
    public static void decodeEverything(String key,java.util.List<String> target){
        StringBuffer sb = new StringBuffer();
        for(String t:target){
            if(sb.length()!=0){
                sb.append(",");
            }
            sb.append(t);
        }
        android.util.Log.e(key,"List<string>["+sb.toString()+"]");
    }
}