Last active
June 28, 2020 13:14
-
-
Save PaulSec/6beab513af069646a5355f66f2bb2329 to your computer and use it in GitHub Desktop.
MainActivty.java used for my blog post about Android Instrumentation with Smali
This file contains 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
package com.example.myapplication; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.util.Base64; | |
import android.util.Log; | |
import java.security.SecureRandom; | |
import javax.crypto.Cipher; | |
import javax.crypto.spec.IvParameterSpec; | |
import javax.crypto.spec.SecretKeySpec; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
byte[] encrypted = Base64.decode("ENCRYPTED_PLACEHOLDER", Base64.DEFAULT); | |
byte[] key = Base64.decode("KEY_PLACEHOLDER", Base64.DEFAULT); | |
byte[] iv = Base64.decode("IV_PLACEHOLDER", Base64.DEFAULT); | |
Log.i("My Activity", "During the activity, w00t"); | |
try { | |
Cipher instance = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC"); | |
instance.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, "AES"), new IvParameterSpec(iv), new SecureRandom()); | |
Log.i("My Activity", "IV = " + new String(iv)); | |
Log.i("My Activity", "ENCRYPTED = " + new String(encrypted)); | |
Log.i("My Activity", "KEY = " + new String(key)); | |
byte[] res = instance.doFinal(encrypted); | |
System.out.println(new String(res)); | |
System.out.println("My Activity: " + res.toString()); | |
} catch (Exception e) { | |
Log.i("My Activity", "Exception: " + e.toString()); | |
} | |
} | |
} |
This file contains 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
.class public Lcom/example/myapplication/MainActivity; | |
.super Landroid/support/v7/app/AppCompatActivity; | |
.source "MainActivity.java" | |
# direct methods | |
.method public constructor <init>()V | |
.locals 0 | |
.line 23 | |
invoke-direct {p0}, Landroid/support/v7/app/AppCompatActivity;-><init>()V | |
return-void | |
.end method | |
# virtual methods | |
.method protected onCreate(Landroid/os/Bundle;)V | |
.locals 9 | |
.param p1, "savedInstanceState" # Landroid/os/Bundle; | |
.line 27 | |
invoke-super {p0, p1}, Landroid/support/v7/app/AppCompatActivity;->onCreate(Landroid/os/Bundle;)V | |
.line 28 | |
const v0, 0x7f09001c | |
invoke-virtual {p0, v0}, Lcom/example/myapplication/MainActivity;->setContentView(I)V | |
.line 31 | |
const-string v0, "PLACEHOLDER_ENCRYPTED" | |
const/4 v1, 0x0 | |
invoke-static {v0, v1}, Landroid/util/Base64;->decode(Ljava/lang/String;I)[B | |
move-result-object v0 | |
.line 32 | |
.local v0, "encrypted":[B | |
const-string v2, "PLACEHOLDER_KEY" | |
invoke-static {v2, v1}, Landroid/util/Base64;->decode(Ljava/lang/String;I)[B | |
move-result-object v2 | |
.line 33 | |
.local v2, "key":[B | |
const-string v3, "PLACEHOLDER_IV" | |
invoke-static {v3, v1}, Landroid/util/Base64;->decode(Ljava/lang/String;I)[B | |
move-result-object v3 | |
.line 34 | |
.local v3, "iv":[B | |
const-string v4, "My Activity" | |
const-string v5, "During the activity, w00t" | |
invoke-static {v4, v5}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I | |
.line 41 | |
:try_start_0 | |
const-string v4, "AES/CBC/PKCS5Padding" | |
const-string v5, "BC" | |
invoke-static {v4, v5}, Ljavax/crypto/Cipher;->getInstance(Ljava/lang/String;Ljava/lang/String;)Ljavax/crypto/Cipher; | |
move-result-object v4 | |
.line 42 | |
.local v4, "instance":Ljavax/crypto/Cipher; | |
const/4 v5, 0x2 | |
new-instance v6, Ljavax/crypto/spec/SecretKeySpec; | |
const-string v7, "AES" | |
invoke-direct {v6, v2, v7}, Ljavax/crypto/spec/SecretKeySpec;-><init>([BLjava/lang/String;)V | |
new-instance v7, Ljavax/crypto/spec/IvParameterSpec; | |
invoke-direct {v7, v3}, Ljavax/crypto/spec/IvParameterSpec;-><init>([B)V | |
new-instance v8, Ljava/security/SecureRandom; | |
invoke-direct {v8}, Ljava/security/SecureRandom;-><init>()V | |
invoke-virtual {v4, v5, v6, v7, v8}, Ljavax/crypto/Cipher;->init(ILjava/security/Key;Ljava/security/spec/AlgorithmParameterSpec;Ljava/security/SecureRandom;)V | |
.line 45 | |
const-string v5, "My Activity" | |
new-instance v6, Ljava/lang/StringBuilder; | |
invoke-direct {v6}, Ljava/lang/StringBuilder;-><init>()V | |
const-string v7, "IV = " | |
invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; | |
invoke-static {v3, v1}, Landroid/util/Base64;->encodeToString([BI)Ljava/lang/String; | |
move-result-object v1 | |
invoke-virtual {v6, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; | |
invoke-virtual {v6}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; | |
move-result-object v1 | |
invoke-static {v5, v1}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I | |
.line 46 | |
const-string v1, "My Activity" | |
new-instance v5, Ljava/lang/StringBuilder; | |
invoke-direct {v5}, Ljava/lang/StringBuilder;-><init>()V | |
const-string v6, "ENCRYPTED = " | |
invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; | |
new-instance v6, Ljava/lang/String; | |
invoke-direct {v6, v3}, Ljava/lang/String;-><init>([B)V | |
invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; | |
invoke-virtual {v5}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; | |
move-result-object v5 | |
invoke-static {v1, v5}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I | |
.line 47 | |
const-string v1, "My Activity" | |
new-instance v5, Ljava/lang/StringBuilder; | |
invoke-direct {v5}, Ljava/lang/StringBuilder;-><init>()V | |
const-string v6, "KEY= " | |
invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; | |
new-instance v6, Ljava/lang/String; | |
invoke-direct {v6, v2}, Ljava/lang/String;-><init>([B)V | |
invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; | |
invoke-virtual {v5}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; | |
move-result-object v5 | |
invoke-static {v1, v5}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I | |
.line 49 | |
invoke-virtual {v4, v0}, Ljavax/crypto/Cipher;->doFinal([B)[B | |
move-result-object v1 | |
.line 50 | |
.local v1, "res":[B | |
new-instance v5, Ljava/lang/String; | |
invoke-virtual {v4, v1}, Ljavax/crypto/Cipher;->doFinal([B)[B | |
move-result-object v6 | |
const-string v7, "UTF-8" | |
invoke-direct {v5, v6, v7}, Ljava/lang/String;-><init>([BLjava/lang/String;)V | |
.line 53 | |
.local v5, "result":Ljava/lang/String; | |
const-string v6, "My Activity" | |
new-instance v7, Ljava/lang/StringBuilder; | |
invoke-direct {v7}, Ljava/lang/StringBuilder;-><init>()V | |
const-string v8, "My Activity: " | |
invoke-virtual {v7, v8}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; | |
invoke-virtual {v7, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; | |
invoke-virtual {v7}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; | |
move-result-object v7 | |
invoke-static {v6, v7}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I | |
:try_end_0 | |
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0 | |
.line 56 | |
goto :goto_0 | |
.line 54 | |
.end local v1 # "res":[B | |
.end local v4 # "instance":Ljavax/crypto/Cipher; | |
.end local v5 # "result":Ljava/lang/String; | |
:catch_0 | |
move-exception v1 | |
.line 55 | |
.local v1, "e":Ljava/lang/Exception; | |
const-string v4, "My Activity" | |
new-instance v5, Ljava/lang/StringBuilder; | |
invoke-direct {v5}, Ljava/lang/StringBuilder;-><init>()V | |
const-string v6, "Exception: " | |
invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; | |
invoke-virtual {v1}, Ljava/lang/Exception;->toString()Ljava/lang/String; | |
move-result-object v6 | |
invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; | |
invoke-virtual {v5}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; | |
move-result-object v5 | |
invoke-static {v4, v5}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I | |
.line 57 | |
.end local v1 # "e":Ljava/lang/Exception; | |
:goto_0 | |
return-void | |
.end method |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment