Alex Light | 460d1b4 | 2017-01-10 15:37:17 +0000 | [diff] [blame] | 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 | |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 17 | import java.util.ArrayList; |
Alex Light | 460d1b4 | 2017-01-10 15:37:17 +0000 | [diff] [blame] | 18 | public class Main { |
| 19 | |
| 20 | public static void main(String[] args) { |
| 21 | System.loadLibrary(args[1]); |
| 22 | NewName.doTest(new Transform()); |
| 23 | DifferentAccess.doTest(new Transform()); |
| 24 | NewInterface.doTest(new Transform2()); |
| 25 | MissingInterface.doTest(new Transform2()); |
| 26 | ReorderInterface.doTest(new Transform2()); |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 27 | MultiRedef.doTest(new Transform(), new Transform2()); |
Alex Light | 6ac5750 | 2017-01-19 15:05:06 -0800 | [diff] [blame^] | 28 | MultiRetrans.doTest(new Transform(), new Transform2()); |
Alex Light | 460d1b4 | 2017-01-10 15:37:17 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | // Transforms the class. This throws an exception if something goes wrong. |
| 32 | public static native void doCommonClassRedefinition(Class<?> target, |
| 33 | byte[] classfile, |
| 34 | byte[] dexfile) throws Exception; |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 35 | |
| 36 | public static void doMultiClassRedefinition(CommonClassDefinition... defs) throws Exception { |
| 37 | ArrayList<Class<?>> classes = new ArrayList<>(); |
| 38 | ArrayList<byte[]> class_files = new ArrayList<>(); |
| 39 | ArrayList<byte[]> dex_files = new ArrayList<>(); |
| 40 | |
| 41 | for (CommonClassDefinition d : defs) { |
| 42 | classes.add(d.target); |
| 43 | class_files.add(d.class_file_bytes); |
| 44 | dex_files.add(d.dex_file_bytes); |
| 45 | } |
| 46 | doCommonMultiClassRedefinition(classes.toArray(new Class<?>[0]), |
| 47 | class_files.toArray(new byte[0][]), |
| 48 | dex_files.toArray(new byte[0][])); |
| 49 | } |
| 50 | |
Alex Light | 6ac5750 | 2017-01-19 15:05:06 -0800 | [diff] [blame^] | 51 | public static void addMultiTransformationResults(CommonClassDefinition... defs) throws Exception { |
| 52 | for (CommonClassDefinition d : defs) { |
| 53 | addCommonTransformationResult(d.target.getCanonicalName(), |
| 54 | d.class_file_bytes, |
| 55 | d.dex_file_bytes); |
| 56 | } |
| 57 | } |
| 58 | |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 59 | public static native void doCommonMultiClassRedefinition(Class<?>[] targets, |
| 60 | byte[][] classfiles, |
| 61 | byte[][] dexfiles) throws Exception; |
Alex Light | 6ac5750 | 2017-01-19 15:05:06 -0800 | [diff] [blame^] | 62 | public static native void doCommonClassRetransformation(Class<?>... target) throws Exception; |
| 63 | public static native void enableCommonRetransformation(boolean enable); |
| 64 | public static native void addCommonTransformationResult(String target_name, |
| 65 | byte[] class_bytes, |
| 66 | byte[] dex_bytes); |
Alex Light | 460d1b4 | 2017-01-10 15:37:17 +0000 | [diff] [blame] | 67 | } |