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 | 460d1b4 | 2017-01-10 15:37:17 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | // Transforms the class. This throws an exception if something goes wrong. |
| 31 | public static native void doCommonClassRedefinition(Class<?> target, |
| 32 | byte[] classfile, |
| 33 | byte[] dexfile) throws Exception; |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame^] | 34 | |
| 35 | public static void doMultiClassRedefinition(CommonClassDefinition... defs) throws Exception { |
| 36 | ArrayList<Class<?>> classes = new ArrayList<>(); |
| 37 | ArrayList<byte[]> class_files = new ArrayList<>(); |
| 38 | ArrayList<byte[]> dex_files = new ArrayList<>(); |
| 39 | |
| 40 | for (CommonClassDefinition d : defs) { |
| 41 | classes.add(d.target); |
| 42 | class_files.add(d.class_file_bytes); |
| 43 | dex_files.add(d.dex_file_bytes); |
| 44 | } |
| 45 | doCommonMultiClassRedefinition(classes.toArray(new Class<?>[0]), |
| 46 | class_files.toArray(new byte[0][]), |
| 47 | dex_files.toArray(new byte[0][])); |
| 48 | } |
| 49 | |
| 50 | public static native void doCommonMultiClassRedefinition(Class<?>[] targets, |
| 51 | byte[][] classfiles, |
| 52 | byte[][] dexfiles) throws Exception; |
Alex Light | 460d1b4 | 2017-01-10 15:37:17 +0000 | [diff] [blame] | 53 | } |