1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import java.util.Base64; 18 19 class Verification { 20 // Jasmin program: 21 // 22 // .source Transform.java 23 // .class Transform 24 // .super java/lang/Object 25 // .method <init>()V 26 // .limit stack 1 27 // .limit locals 1 28 // aload_0 29 // invokespecial java/lang/Object/<init>()V 30 // return 31 // .end method 32 // .method sayHi(Ljava/lang/String;)V 33 // .limit stack 1 34 // .limit locals 2 35 // aload_1 36 // areturn 37 // .end method 38 private static final byte[] CLASS_BYTES = Base64.getDecoder().decode( 39 "yv66vgADAC0ADgoADQAHBwAIAQAQamF2YS9sYW5nL09iamVjdAEAClNvdXJjZUZpbGUBAAY8aW5p" + 40 "dD4BAAVzYXlIaQwABQAKAQAJVHJhbnNmb3JtAQAEQ29kZQEAAygpVgEADlRyYW5zZm9ybS5qYXZh" + 41 "AQAVKExqYXZhL2xhbmcvU3RyaW5nOylWBwADACAAAgANAAAAAAACAAAABQAKAAEACQAAABEAAQAB" + 42 "AAAABSq3AAGxAAAAAAABAAYADAABAAkAAAAOAAEAAgAAAAIrsAAAAAAAAQAEAAAAAgAL"); 43 44 // Smali program: 45 // 46 // .class LTransform; 47 // .super Ljava/lang/Object; 48 // .source "Transform.java" 49 // # direct methods 50 // .method constructor <init>()V 51 // .registers 1 52 // invoke-direct {p0}, Ljava/lang/Object;-><init>()V 53 // return-void 54 // .end method 55 // # virtual methods 56 // .method public sayHi(Ljava/lang/String;)V 57 // .registers 2 58 // return-object p1 59 // .end method 60 private static final byte[] DEX_BYTES = Base64.getDecoder().decode( 61 "ZGV4CjAzNQClOAc4ZDMXaHMezhYcqZxcjUeVCWRYUkooAgAAcAAAAHhWNBIAAAAAAAAAAJQBAAAI" + 62 "AAAAcAAAAAQAAACQAAAAAgAAAKAAAAAAAAAAAAAAAAMAAAC4AAAAAQAAANAAAAA4AQAA8AAAAPAA" + 63 "AAD4AAAABQEAABkBAAAtAQAAPQEAAEABAABEAQAAAQAAAAIAAAADAAAABQAAAAUAAAADAAAAAAAA" + 64 "AAYAAAADAAAATAEAAAAAAAAAAAAAAAABAAcAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAEAAAA" + 65 "AAAAAIYBAAAAAAAABjxpbml0PgALTFRyYW5zZm9ybTsAEkxqYXZhL2xhbmcvT2JqZWN0OwASTGph" + 66 "dmEvbGFuZy9TdHJpbmc7AA5UcmFuc2Zvcm0uamF2YQABVgACVkwABXNheUhpAAABAAAAAgAAAAAA" + 67 "AAAAAAAAAQABAAEAAAAAAAAABAAAAHAQAgAAAA4AAgACAAAAAAAAAAAAAQAAABEBAAABAQCAgATc" + 68 "AgEB9AIMAAAAAAAAAAEAAAAAAAAAAQAAAAgAAABwAAAAAgAAAAQAAACQAAAAAwAAAAIAAACgAAAA" + 69 "BQAAAAMAAAC4AAAABgAAAAEAAADQAAAAAiAAAAgAAADwAAAAARAAAAEAAABMAQAAAxAAAAIAAABU" + 70 "AQAAASAAAAIAAABcAQAAACAAAAEAAACGAQAAABAAAAEAAACUAQAA"); 71 doTest(Transform t)72 public static void doTest(Transform t) { 73 t.sayHi("Verification"); 74 try { 75 Main.doCommonClassRedefinition(Transform.class, CLASS_BYTES, DEX_BYTES); 76 } catch (Exception e) { 77 System.out.println( 78 "Transformation error : " + e.getClass().getName() + "(" + e.getMessage() + ")"); 79 } 80 t.sayHi("Verification"); 81 } 82 } 83