| /* |
| * Copyright (C) 2016 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| import static art.Redefinition.doCommonClassRedefinition; |
| import java.util.Base64; |
| import java.util.OptionalLong; |
| public class Main { |
| |
| /** |
| * This is the base64 encoded class/dex. |
| * |
| * To regenerate these constants: |
| * 1) Update src-optional/java/util/OptionalLong.java |
| * 2) run convert-to-base64.sh script, specifying |
| * required parameters (path to d8 tool and path to android.jar; |
| * both can be found in Android sdk) |
| * 3) copy and paste base64 text below |
| * |
| */ |
| private static final byte[] CLASS_BYTES = Base64.getDecoder().decode( |
| "LyoKICogQ29weXJpZ2h0IChDKSAyMDIxIFRoZSBBbmRyb2lkIE9wZW4gU291cmNlIFByb2plY3QK" + |
| "ICoKICogTGljZW5zZWQgdW5kZXIgdGhlIEFwYWNoZSBMaWNlbnNlLCBWZXJzaW9uIDIuMCAodGhl" + |
| "ICJMaWNlbnNlIik7CiAqIHlvdSBtYXkgbm90IHVzZSB0aGlzIGZpbGUgZXhjZXB0IGluIGNvbXBs" + |
| "aWFuY2Ugd2l0aCB0aGUgTGljZW5zZS4KICogWW91IG1heSBvYnRhaW4gYSBjb3B5IG9mIHRoZSBM" + |
| "aWNlbnNlIGF0CiAqCiAqICAgICAgaHR0cDovL3d3dy5hcGFjaGUub3JnL2xpY2Vuc2VzL0xJQ0VO" + |
| "U0UtMi4wCiAqCiAqIFVubGVzcyByZXF1aXJlZCBieSBhcHBsaWNhYmxlIGxhdyBvciBhZ3JlZWQg" + |
| "dG8gaW4gd3JpdGluZywgc29mdHdhcmUKICogZGlzdHJpYnV0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Q29kZSgpIHsg" + |
| "cmV0dXJuIDA7IH0KICBwdWJsaWMgU3RyaW5nIHRvU3RyaW5nKCkgeyByZXR1cm4gIlJlZGVmaW5l" + |
| "ZCBPcHRpb25hbExvbmchIjsgfQp9Cg=="); |
| private static final byte[] DEX_BYTES = Base64.getDecoder().decode( |
| "ZGV4CjAzNQBVWRCACMU+HJ9PqTkRRt+Gpa1jx32x1C8kCQAAcAAAAHhWNBIAAAAAAAAAAGAIAAAw" + |
| "AAAAcAAAAA8AAAAwAQAADwAAAGwBAAADAAAAIAIAABMAAAA4AgAAAQAAANACAAA0BgAA8AIAAL4E" + |
| "AADMBAAA0QQAANsEAADjBAAA5wQAAO4EAADxBAAA9AQAAPgEAAD8BAAA/wQAAAMFAAAiBQAAPgUA" + |
| "AFIFAABoBQAAfAUAAJMFAACtBQAA0AUAAPMFAAASBgAAMQYAAFAGAABjBgAAfAYAAH8GAACDBgAA" + |
| "hwYAAIwGAACPBgAAkwYAAJoGAACiBgAArQYAALcGAADCBgAA0wYAANwGAADnBgAA6wYAAPMGAAD+" + |
| "BgAACwcAABMHAAAdBwAAJAcAAAYAAAAHAAAADAAAAA0AAAAOAAAADwAAABAAAAARAAAAEgAAABMA" + |
| "AAAUAAAAFQAAABcAAAAaAAAAHgAAAAYAAAAAAAAAAAAAAAcAAAABAAAAAAAAAAgAAAABAAAAkAQA" + |
| "AAkAAAABAAAAmAQAAAkAAAABAAAAoAQAAAoAAAAGAAAAAAAAAAoAAAAIAAAAAAAAAAsAAAAIAAAA" + |
| "kAQAAAoAAAAMAAAAAAAAABoAAAANAAAAAAAAABsAAAANAAAAkAQAABwAAAANAAAAqAQAAB0AAAAN" + |
| "AAAAsAQAAB4AAAAOAAAAAAAAAB8AAAAOAAAAuAQAAAgACAAFAAAACAAOACcAAAAIAAEALgAAAAQA" + |
| "CQADAAAACAAJAAIAAAAIAAkAAwAAAAgACgADAAAACAAGACAAAAAIAA4AIQAAAAgAAQAiAAAACAAA" + |
| "ACMAA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AAAAAAAAEAAAADwIAAAQAAAAAAAAAAEAAAAAAAAAAQAAADAA" + |
| "AABwAAAAAgAAAA8AAAAwAQAAAwAAAA8AAABsAQAABAAAAAMAAAAgAgAABQAAABMAAAA4AgAABgAA" + |
| "AAEAAADQAgAAASAAABIAAADwAgAAAyAAAAIAAACGBAAAARAAAAYAAACQBAAAAiAAADAAAAC+BAAA" + |
| "BCAAAAIAAADFBwAAACAAAAEAAADdBwAAAxAAAAIAAAA4CAAABiAAAAEAAABICAAAABAAAAEAAABg" + |
| "CAAA"); |
| |
| public static void main(String[] args) { |
| // OptionalLong is a class that is unlikely to be used by the time this test starts and is not |
| // likely to be changed in any meaningful way in the future. |
| OptionalLong ol = OptionalLong.of(0xDEADBEEF); |
| System.out.println("ol.toString() -> '" + ol.toString() + "'"); |
| System.out.println("Redefining OptionalLong!"); |
| doCommonClassRedefinition(OptionalLong.class, CLASS_BYTES, DEX_BYTES); |
| System.out.println("ol.toString() -> '" + ol.toString() + "'"); |
| } |
| } |