David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +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 | |
| 17 | #include <fstream> |
| 18 | |
| 19 | #include "base/unix_file/fd_file.h" |
David Sehr | 79e2607 | 2018-04-06 17:58:50 -0700 | [diff] [blame] | 20 | #include "base/zip_archive.h" |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 21 | #include "common_runtime_test.h" |
| 22 | #include "dex/art_dex_file_loader.h" |
Mathieu Chartier | 396dc08 | 2018-08-06 12:29:57 -0700 | [diff] [blame] | 23 | #include "dex/class_accessor-inl.h" |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 24 | #include "dex/dex_file-inl.h" |
| 25 | #include "exec_utils.h" |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 26 | |
| 27 | namespace art { |
| 28 | |
| 29 | class HiddenApiTest : public CommonRuntimeTest { |
| 30 | protected: |
| 31 | std::string GetHiddenApiCmd() { |
| 32 | std::string file_path = GetTestAndroidRoot(); |
| 33 | file_path += "/bin/hiddenapi"; |
| 34 | if (kIsDebugBuild) { |
| 35 | file_path += "d"; |
| 36 | } |
| 37 | if (!OS::FileExists(file_path.c_str())) { |
| 38 | LOG(FATAL) << "Could not find binary " << file_path; |
| 39 | UNREACHABLE(); |
| 40 | } |
| 41 | return file_path; |
| 42 | } |
| 43 | |
| 44 | std::unique_ptr<const DexFile> RunHiddenApi(const ScratchFile& light_greylist, |
| 45 | const ScratchFile& dark_greylist, |
| 46 | const ScratchFile& blacklist, |
| 47 | const std::vector<std::string>& extra_args, |
| 48 | ScratchFile* out_dex) { |
| 49 | std::string error; |
David Brazdil | 4572ade | 2018-01-17 09:26:47 +0000 | [diff] [blame] | 50 | std::unique_ptr<ZipArchive> jar( |
| 51 | ZipArchive::Open(GetTestDexFileName("HiddenApi").c_str(), &error)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 52 | if (jar == nullptr) { |
| 53 | LOG(FATAL) << "Could not open test file " << GetTestDexFileName("HiddenApi") << ": " << error; |
| 54 | UNREACHABLE(); |
| 55 | } |
David Brazdil | 4572ade | 2018-01-17 09:26:47 +0000 | [diff] [blame] | 56 | std::unique_ptr<ZipEntry> jar_classes_dex(jar->Find("classes.dex", &error)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 57 | if (jar_classes_dex == nullptr) { |
| 58 | LOG(FATAL) << "Could not find classes.dex in test file " << GetTestDexFileName("HiddenApi") |
| 59 | << ": " << error; |
| 60 | UNREACHABLE(); |
| 61 | } else if (!jar_classes_dex->ExtractToFile(*out_dex->GetFile(), &error)) { |
| 62 | LOG(FATAL) << "Could not extract classes.dex from test file " |
| 63 | << GetTestDexFileName("HiddenApi") << ": " << error; |
| 64 | UNREACHABLE(); |
| 65 | } |
| 66 | |
| 67 | std::vector<std::string> argv_str; |
| 68 | argv_str.push_back(GetHiddenApiCmd()); |
| 69 | argv_str.insert(argv_str.end(), extra_args.begin(), extra_args.end()); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 70 | argv_str.push_back("encode"); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 71 | argv_str.push_back("--dex=" + out_dex->GetFilename()); |
| 72 | argv_str.push_back("--light-greylist=" + light_greylist.GetFilename()); |
| 73 | argv_str.push_back("--dark-greylist=" + dark_greylist.GetFilename()); |
| 74 | argv_str.push_back("--blacklist=" + blacklist.GetFilename()); |
| 75 | int return_code = ExecAndReturnCode(argv_str, &error); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 76 | if (return_code == 0) { |
| 77 | return OpenDex(*out_dex); |
| 78 | } else { |
| 79 | LOG(ERROR) << "HiddenApi binary exited with unexpected return code " << return_code; |
| 80 | return nullptr; |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 81 | } |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | std::unique_ptr<const DexFile> OpenDex(const ScratchFile& file) { |
| 85 | ArtDexFileLoader dex_loader; |
| 86 | std::string error_msg; |
| 87 | |
| 88 | File fd(file.GetFilename(), O_RDONLY, /* check_usage */ false); |
| 89 | if (fd.Fd() == -1) { |
| 90 | LOG(FATAL) << "Unable to open file '" << file.GetFilename() << "': " << strerror(errno); |
| 91 | UNREACHABLE(); |
| 92 | } |
| 93 | |
| 94 | std::unique_ptr<const DexFile> dex_file(dex_loader.OpenDex( |
| 95 | fd.Release(), /* location */ file.GetFilename(), /* verify */ false, |
| 96 | /* verify_checksum */ true, /* mmap_shared */ false, &error_msg)); |
| 97 | if (dex_file.get() == nullptr) { |
| 98 | LOG(FATAL) << "Open failed for '" << file.GetFilename() << "' " << error_msg; |
| 99 | UNREACHABLE(); |
| 100 | } else if (!dex_file->IsStandardDexFile()) { |
| 101 | LOG(FATAL) << "Expected a standard dex file '" << file.GetFilename() << "'"; |
| 102 | UNREACHABLE(); |
| 103 | } |
| 104 | |
| 105 | return dex_file; |
| 106 | } |
| 107 | |
| 108 | std::ofstream OpenStream(const ScratchFile& file) { |
| 109 | std::ofstream ofs(file.GetFilename(), std::ofstream::out); |
| 110 | if (ofs.fail()) { |
| 111 | LOG(FATAL) << "Open failed for '" << file.GetFilename() << "' " << strerror(errno); |
| 112 | UNREACHABLE(); |
| 113 | } |
| 114 | return ofs; |
| 115 | } |
| 116 | |
| 117 | const DexFile::ClassDef& FindClass(const char* desc, const DexFile& dex_file) { |
Mathieu Chartier | 396dc08 | 2018-08-06 12:29:57 -0700 | [diff] [blame] | 118 | const DexFile::TypeId* type_id = dex_file.FindTypeId(desc); |
| 119 | CHECK(type_id != nullptr) << "Could not find class " << desc; |
| 120 | const DexFile::ClassDef* found = dex_file.FindClassDef(dex_file.GetIndexForTypeId(*type_id)); |
| 121 | CHECK(found != nullptr) << "Could not find class " << desc; |
| 122 | return *found; |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 123 | } |
| 124 | |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 125 | HiddenApiAccessFlags::ApiList GetFieldHiddenFlags(const char* name, |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 126 | uint32_t expected_visibility, |
| 127 | const DexFile::ClassDef& class_def, |
| 128 | const DexFile& dex_file) { |
Mathieu Chartier | 396dc08 | 2018-08-06 12:29:57 -0700 | [diff] [blame] | 129 | ClassAccessor accessor(dex_file, class_def); |
| 130 | CHECK(accessor.HasClassData()) << "Class " << accessor.GetDescriptor() << " has no data"; |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 131 | |
Mathieu Chartier | 396dc08 | 2018-08-06 12:29:57 -0700 | [diff] [blame] | 132 | for (const ClassAccessor::Field& field : accessor.GetFields()) { |
| 133 | const DexFile::FieldId& fid = dex_file.GetFieldId(field.GetIndex()); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 134 | if (strcmp(name, dex_file.GetFieldName(fid)) == 0) { |
Mathieu Chartier | 396dc08 | 2018-08-06 12:29:57 -0700 | [diff] [blame] | 135 | const uint32_t actual_visibility = field.GetAccessFlags() & kAccVisibilityFlags; |
| 136 | CHECK_EQ(actual_visibility, expected_visibility) |
| 137 | << "Field " << name << " in class " << accessor.GetDescriptor(); |
| 138 | return field.DecodeHiddenAccessFlags(); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
| 142 | LOG(FATAL) << "Could not find field " << name << " in class " |
| 143 | << dex_file.GetClassDescriptor(class_def); |
| 144 | UNREACHABLE(); |
| 145 | } |
| 146 | |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 147 | HiddenApiAccessFlags::ApiList GetMethodHiddenFlags(const char* name, |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 148 | uint32_t expected_visibility, |
| 149 | bool expected_native, |
| 150 | const DexFile::ClassDef& class_def, |
| 151 | const DexFile& dex_file) { |
Mathieu Chartier | 396dc08 | 2018-08-06 12:29:57 -0700 | [diff] [blame] | 152 | ClassAccessor accessor(dex_file, class_def); |
| 153 | CHECK(accessor.HasClassData()) << "Class " << accessor.GetDescriptor() << " has no data"; |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 154 | |
Mathieu Chartier | 396dc08 | 2018-08-06 12:29:57 -0700 | [diff] [blame] | 155 | for (const ClassAccessor::Method& method : accessor.GetMethods()) { |
| 156 | const DexFile::MethodId& mid = dex_file.GetMethodId(method.GetIndex()); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 157 | if (strcmp(name, dex_file.GetMethodName(mid)) == 0) { |
Mathieu Chartier | 396dc08 | 2018-08-06 12:29:57 -0700 | [diff] [blame] | 158 | CHECK_EQ(expected_native, method.MemberIsNative()) |
| 159 | << "Method " << name << " in class " << accessor.GetDescriptor(); |
| 160 | const uint32_t actual_visibility = method.GetAccessFlags() & kAccVisibilityFlags; |
| 161 | CHECK_EQ(actual_visibility, expected_visibility) |
| 162 | << "Method " << name << " in class " << accessor.GetDescriptor(); |
| 163 | return method.DecodeHiddenAccessFlags(); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
| 167 | LOG(FATAL) << "Could not find method " << name << " in class " |
| 168 | << dex_file.GetClassDescriptor(class_def); |
| 169 | UNREACHABLE(); |
| 170 | } |
| 171 | |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 172 | HiddenApiAccessFlags::ApiList GetIFieldHiddenFlags(const DexFile& dex_file) { |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 173 | return GetFieldHiddenFlags("ifield", kAccPublic, FindClass("LMain;", dex_file), dex_file); |
| 174 | } |
| 175 | |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 176 | HiddenApiAccessFlags::ApiList GetSFieldHiddenFlags(const DexFile& dex_file) { |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 177 | return GetFieldHiddenFlags("sfield", kAccPrivate, FindClass("LMain;", dex_file), dex_file); |
| 178 | } |
| 179 | |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 180 | HiddenApiAccessFlags::ApiList GetIMethodHiddenFlags(const DexFile& dex_file) { |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 181 | return GetMethodHiddenFlags( |
| 182 | "imethod", 0, /* native */ false, FindClass("LMain;", dex_file), dex_file); |
| 183 | } |
| 184 | |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 185 | HiddenApiAccessFlags::ApiList GetSMethodHiddenFlags(const DexFile& dex_file) { |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 186 | return GetMethodHiddenFlags( |
| 187 | "smethod", kAccPublic, /* native */ false, FindClass("LMain;", dex_file), dex_file); |
| 188 | } |
| 189 | |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 190 | HiddenApiAccessFlags::ApiList GetINMethodHiddenFlags(const DexFile& dex_file) { |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 191 | return GetMethodHiddenFlags( |
| 192 | "inmethod", kAccPublic, /* native */ true, FindClass("LMain;", dex_file), dex_file); |
| 193 | } |
| 194 | |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 195 | HiddenApiAccessFlags::ApiList GetSNMethodHiddenFlags(const DexFile& dex_file) { |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 196 | return GetMethodHiddenFlags( |
| 197 | "snmethod", kAccProtected, /* native */ true, FindClass("LMain;", dex_file), dex_file); |
| 198 | } |
| 199 | }; |
| 200 | |
| 201 | TEST_F(HiddenApiTest, InstanceFieldNoMatch) { |
| 202 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 203 | OpenStream(light_greylist) << "LMain;->ifield:LBadType1;" << std::endl; |
| 204 | OpenStream(dark_greylist) << "LMain;->ifield:LBadType2;" << std::endl; |
| 205 | OpenStream(blacklist) << "LMain;->ifield:LBadType3;" << std::endl; |
| 206 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 207 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 208 | ASSERT_EQ(HiddenApiAccessFlags::kWhitelist, GetIFieldHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | TEST_F(HiddenApiTest, InstanceFieldLightGreylistMatch) { |
| 212 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 213 | OpenStream(light_greylist) << "LMain;->ifield:I" << std::endl; |
| 214 | OpenStream(dark_greylist) << "LMain;->ifield:LBadType2;" << std::endl; |
| 215 | OpenStream(blacklist) << "LMain;->ifield:LBadType3;" << std::endl; |
| 216 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 217 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 218 | ASSERT_EQ(HiddenApiAccessFlags::kLightGreylist, GetIFieldHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | TEST_F(HiddenApiTest, InstanceFieldDarkGreylistMatch) { |
| 222 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 223 | OpenStream(light_greylist) << "LMain;->ifield:LBadType1;" << std::endl; |
| 224 | OpenStream(dark_greylist) << "LMain;->ifield:I" << std::endl; |
| 225 | OpenStream(blacklist) << "LMain;->ifield:LBadType3;" << std::endl; |
| 226 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 227 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 228 | ASSERT_EQ(HiddenApiAccessFlags::kDarkGreylist, GetIFieldHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | TEST_F(HiddenApiTest, InstanceFieldBlacklistMatch) { |
| 232 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 233 | OpenStream(light_greylist) << "LMain;->ifield:LBadType1;" << std::endl; |
| 234 | OpenStream(dark_greylist) << "LMain;->ifield:LBadType2;" << std::endl; |
| 235 | OpenStream(blacklist) << "LMain;->ifield:I" << std::endl; |
| 236 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 237 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 238 | ASSERT_EQ(HiddenApiAccessFlags::kBlacklist, GetIFieldHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | TEST_F(HiddenApiTest, InstanceFieldTwoListsMatch1) { |
| 242 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 243 | OpenStream(light_greylist) << "LMain;->ifield:LBadType1;" << std::endl; |
| 244 | OpenStream(dark_greylist) << "LMain;->ifield:I" << std::endl; |
| 245 | OpenStream(blacklist) << "LMain;->ifield:I" << std::endl; |
| 246 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 247 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | TEST_F(HiddenApiTest, InstanceFieldTwoListsMatch2) { |
| 251 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 252 | OpenStream(light_greylist) << "LMain;->ifield:I" << std::endl; |
| 253 | OpenStream(dark_greylist) << "LMain;->ifield:LBadType2;" << std::endl; |
| 254 | OpenStream(blacklist) << "LMain;->ifield:I" << std::endl; |
| 255 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 256 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | TEST_F(HiddenApiTest, InstanceFieldTwoListsMatch3) { |
| 260 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 261 | OpenStream(light_greylist) << "LMain;->ifield:I" << std::endl; |
| 262 | OpenStream(dark_greylist) << "LMain;->ifield:I" << std::endl; |
| 263 | OpenStream(blacklist) << "LMain;->ifield:LBadType3;" << std::endl; |
| 264 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 265 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | TEST_F(HiddenApiTest, StaticFieldNoMatch) { |
| 269 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 270 | OpenStream(light_greylist) << "LMain;->sfield:LBadType1;" << std::endl; |
| 271 | OpenStream(dark_greylist) << "LMain;->sfield:LBadType2;" << std::endl; |
| 272 | OpenStream(blacklist) << "LMain;->sfield:LBadType3;" << std::endl; |
| 273 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 274 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 275 | ASSERT_EQ(HiddenApiAccessFlags::kWhitelist, GetSFieldHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | TEST_F(HiddenApiTest, StaticFieldLightGreylistMatch) { |
| 279 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 280 | OpenStream(light_greylist) << "LMain;->sfield:Ljava/lang/Object;" << std::endl; |
| 281 | OpenStream(dark_greylist) << "LMain;->sfield:LBadType2;" << std::endl; |
| 282 | OpenStream(blacklist) << "LMain;->sfield:LBadType3;" << std::endl; |
| 283 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 284 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 285 | ASSERT_EQ(HiddenApiAccessFlags::kLightGreylist, GetSFieldHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | TEST_F(HiddenApiTest, StaticFieldDarkGreylistMatch) { |
| 289 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 290 | OpenStream(light_greylist) << "LMain;->sfield:LBadType1;" << std::endl; |
| 291 | OpenStream(dark_greylist) << "LMain;->sfield:Ljava/lang/Object;" << std::endl; |
| 292 | OpenStream(blacklist) << "LMain;->sfield:LBadType3;" << std::endl; |
| 293 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 294 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 295 | ASSERT_EQ(HiddenApiAccessFlags::kDarkGreylist, GetSFieldHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | TEST_F(HiddenApiTest, StaticFieldBlacklistMatch) { |
| 299 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 300 | OpenStream(light_greylist) << "LMain;->sfield:LBadType1;" << std::endl; |
| 301 | OpenStream(dark_greylist) << "LMain;->sfield:LBadType2;" << std::endl; |
| 302 | OpenStream(blacklist) << "LMain;->sfield:Ljava/lang/Object;" << std::endl; |
| 303 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 304 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 305 | ASSERT_EQ(HiddenApiAccessFlags::kBlacklist, GetSFieldHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | TEST_F(HiddenApiTest, StaticFieldTwoListsMatch1) { |
| 309 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 310 | OpenStream(light_greylist) << "LMain;->sfield:LBadType1;" << std::endl; |
| 311 | OpenStream(dark_greylist) << "LMain;->sfield:Ljava/lang/Object;" << std::endl; |
| 312 | OpenStream(blacklist) << "LMain;->sfield:Ljava/lang/Object;" << std::endl; |
| 313 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 314 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | TEST_F(HiddenApiTest, StaticFieldTwoListsMatch2) { |
| 318 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 319 | OpenStream(light_greylist) << "LMain;->sfield:Ljava/lang/Object;" << std::endl; |
| 320 | OpenStream(dark_greylist) << "LMain;->sfield:LBadType2;" << std::endl; |
| 321 | OpenStream(blacklist) << "LMain;->sfield:Ljava/lang/Object;" << std::endl; |
| 322 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 323 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | TEST_F(HiddenApiTest, StaticFieldTwoListsMatch3) { |
| 327 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 328 | OpenStream(light_greylist) << "LMain;->sfield:Ljava/lang/Object;" << std::endl; |
| 329 | OpenStream(dark_greylist) << "LMain;->sfield:Ljava/lang/Object;" << std::endl; |
| 330 | OpenStream(blacklist) << "LMain;->sfield:LBadType3;" << std::endl; |
| 331 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 332 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | TEST_F(HiddenApiTest, InstanceMethodNoMatch) { |
| 336 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 337 | OpenStream(light_greylist) << "LMain;->imethod(LBadType1;)V" << std::endl; |
| 338 | OpenStream(dark_greylist) << "LMain;->imethod(LBadType2;)V" << std::endl; |
| 339 | OpenStream(blacklist) << "LMain;->imethod(LBadType3;)V" << std::endl; |
| 340 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 341 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 342 | ASSERT_EQ(HiddenApiAccessFlags::kWhitelist, GetIMethodHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | TEST_F(HiddenApiTest, InstanceMethodLightGreylistMatch) { |
| 346 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 347 | OpenStream(light_greylist) << "LMain;->imethod(J)V" << std::endl; |
| 348 | OpenStream(dark_greylist) << "LMain;->imethod(LBadType2;)V" << std::endl; |
| 349 | OpenStream(blacklist) << "LMain;->imethod(LBadType3;)V" << std::endl; |
| 350 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 351 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 352 | ASSERT_EQ(HiddenApiAccessFlags::kLightGreylist, GetIMethodHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | TEST_F(HiddenApiTest, InstanceMethodDarkGreylistMatch) { |
| 356 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 357 | OpenStream(light_greylist) << "LMain;->imethod(LBadType1;)V" << std::endl; |
| 358 | OpenStream(dark_greylist) << "LMain;->imethod(J)V" << std::endl; |
| 359 | OpenStream(blacklist) << "LMain;->imethod(LBadType3;)V" << std::endl; |
| 360 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 361 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 362 | ASSERT_EQ(HiddenApiAccessFlags::kDarkGreylist, GetIMethodHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | TEST_F(HiddenApiTest, InstanceMethodBlacklistMatch) { |
| 366 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 367 | OpenStream(light_greylist) << "LMain;->imethod(LBadType1;)V" << std::endl; |
| 368 | OpenStream(dark_greylist) << "LMain;->imethod(LBadType2;)V" << std::endl; |
| 369 | OpenStream(blacklist) << "LMain;->imethod(J)V" << std::endl; |
| 370 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 371 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 372 | ASSERT_EQ(HiddenApiAccessFlags::kBlacklist, GetIMethodHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | TEST_F(HiddenApiTest, InstanceMethodTwoListsMatch1) { |
| 376 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 377 | OpenStream(light_greylist) << "LMain;->imethod(LBadType1;)V" << std::endl; |
| 378 | OpenStream(dark_greylist) << "LMain;->imethod(J)V" << std::endl; |
| 379 | OpenStream(blacklist) << "LMain;->imethod(J)V" << std::endl; |
| 380 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 381 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | TEST_F(HiddenApiTest, InstanceMethodTwoListsMatch2) { |
| 385 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 386 | OpenStream(light_greylist) << "LMain;->imethod(J)V" << std::endl; |
| 387 | OpenStream(dark_greylist) << "LMain;->imethod(LBadType2;)V" << std::endl; |
| 388 | OpenStream(blacklist) << "LMain;->imethod(J)V" << std::endl; |
| 389 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 390 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | TEST_F(HiddenApiTest, InstanceMethodTwoListsMatch3) { |
| 394 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 395 | OpenStream(light_greylist) << "LMain;->imethod(J)V" << std::endl; |
| 396 | OpenStream(dark_greylist) << "LMain;->imethod(J)V" << std::endl; |
| 397 | OpenStream(blacklist) << "LMain;->imethod(LBadType3;)V" << std::endl; |
| 398 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 399 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | TEST_F(HiddenApiTest, StaticMethodNoMatch) { |
| 403 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 404 | OpenStream(light_greylist) << "LMain;->smethod(LBadType1;)V" << std::endl; |
| 405 | OpenStream(dark_greylist) << "LMain;->smethod(LBadType2;)V" << std::endl; |
| 406 | OpenStream(blacklist) << "LMain;->smethod(LBadType3;)V" << std::endl; |
| 407 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 408 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 409 | ASSERT_EQ(HiddenApiAccessFlags::kWhitelist, GetSMethodHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | TEST_F(HiddenApiTest, StaticMethodLightGreylistMatch) { |
| 413 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 414 | OpenStream(light_greylist) << "LMain;->smethod(Ljava/lang/Object;)V" << std::endl; |
| 415 | OpenStream(dark_greylist) << "LMain;->smethod(LBadType2;)V" << std::endl; |
| 416 | OpenStream(blacklist) << "LMain;->smethod(LBadType3;)V" << std::endl; |
| 417 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 418 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 419 | ASSERT_EQ(HiddenApiAccessFlags::kLightGreylist, GetSMethodHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | TEST_F(HiddenApiTest, StaticMethodDarkGreylistMatch) { |
| 423 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 424 | OpenStream(light_greylist) << "LMain;->smethod(LBadType1;)V" << std::endl; |
| 425 | OpenStream(dark_greylist) << "LMain;->smethod(Ljava/lang/Object;)V" << std::endl; |
| 426 | OpenStream(blacklist) << "LMain;->smethod(LBadType3;)V" << std::endl; |
| 427 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 428 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 429 | ASSERT_EQ(HiddenApiAccessFlags::kDarkGreylist, GetSMethodHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | TEST_F(HiddenApiTest, StaticMethodBlacklistMatch) { |
| 433 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 434 | OpenStream(light_greylist) << "LMain;->smethod(LBadType1;)V" << std::endl; |
| 435 | OpenStream(dark_greylist) << "LMain;->smethod(LBadType2;)V" << std::endl; |
| 436 | OpenStream(blacklist) << "LMain;->smethod(Ljava/lang/Object;)V" << std::endl; |
| 437 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 438 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 439 | ASSERT_EQ(HiddenApiAccessFlags::kBlacklist, GetSMethodHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | TEST_F(HiddenApiTest, StaticMethodTwoListsMatch1) { |
| 443 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 444 | OpenStream(light_greylist) << "LMain;->smethod(LBadType1;)V" << std::endl; |
| 445 | OpenStream(dark_greylist) << "LMain;->smethod(Ljava/lang/Object;)V" << std::endl; |
| 446 | OpenStream(blacklist) << "LMain;->smethod(Ljava/lang/Object;)V" << std::endl; |
| 447 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 448 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | TEST_F(HiddenApiTest, StaticMethodTwoListsMatch2) { |
| 452 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 453 | OpenStream(light_greylist) << "LMain;->smethod(Ljava/lang/Object;)V" << std::endl; |
| 454 | OpenStream(dark_greylist) << "LMain;->smethod(LBadType2;)V" << std::endl; |
| 455 | OpenStream(blacklist) << "LMain;->smethod(Ljava/lang/Object;)V" << std::endl; |
| 456 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 457 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | TEST_F(HiddenApiTest, StaticMethodTwoListsMatch3) { |
| 461 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 462 | OpenStream(light_greylist) << "LMain;->smethod(Ljava/lang/Object;)V" << std::endl; |
| 463 | OpenStream(dark_greylist) << "LMain;->smethod(Ljava/lang/Object;)V" << std::endl; |
| 464 | OpenStream(blacklist) << "LMain;->smethod(LBadType3;)V" << std::endl; |
| 465 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 466 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | TEST_F(HiddenApiTest, InstanceNativeMethodNoMatch) { |
| 470 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 471 | OpenStream(light_greylist) << "LMain;->inmethod(LBadType1;)V" << std::endl; |
| 472 | OpenStream(dark_greylist) << "LMain;->inmethod(LBadType2;)V" << std::endl; |
| 473 | OpenStream(blacklist) << "LMain;->inmethod(LBadType3;)V" << std::endl; |
| 474 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 475 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 476 | ASSERT_EQ(HiddenApiAccessFlags::kWhitelist, GetINMethodHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | TEST_F(HiddenApiTest, InstanceNativeMethodLightGreylistMatch) { |
| 480 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 481 | OpenStream(light_greylist) << "LMain;->inmethod(C)V" << std::endl; |
| 482 | OpenStream(dark_greylist) << "LMain;->inmethod(LBadType2;)V" << std::endl; |
| 483 | OpenStream(blacklist) << "LMain;->inmethod(LBadType3;)V" << std::endl; |
| 484 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 485 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 486 | ASSERT_EQ(HiddenApiAccessFlags::kLightGreylist, GetINMethodHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | TEST_F(HiddenApiTest, InstanceNativeMethodDarkGreylistMatch) { |
| 490 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 491 | OpenStream(light_greylist) << "LMain;->inmethod(LBadType1;)V" << std::endl; |
| 492 | OpenStream(dark_greylist) << "LMain;->inmethod(C)V" << std::endl; |
| 493 | OpenStream(blacklist) << "LMain;->inmethod(LBadType3;)V" << std::endl; |
| 494 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 495 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 496 | ASSERT_EQ(HiddenApiAccessFlags::kDarkGreylist, GetINMethodHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | TEST_F(HiddenApiTest, InstanceNativeMethodBlacklistMatch) { |
| 500 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 501 | OpenStream(light_greylist) << "LMain;->inmethod(LBadType1;)V" << std::endl; |
| 502 | OpenStream(dark_greylist) << "LMain;->inmethod(LBadType2;)V" << std::endl; |
| 503 | OpenStream(blacklist) << "LMain;->inmethod(C)V" << std::endl; |
| 504 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 505 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 506 | ASSERT_EQ(HiddenApiAccessFlags::kBlacklist, GetINMethodHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | TEST_F(HiddenApiTest, InstanceNativeMethodTwoListsMatch1) { |
| 510 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 511 | OpenStream(light_greylist) << "LMain;->inmethod(LBadType1;)V" << std::endl; |
| 512 | OpenStream(dark_greylist) << "LMain;->inmethod(C)V" << std::endl; |
| 513 | OpenStream(blacklist) << "LMain;->inmethod(C)V" << std::endl; |
| 514 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 515 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | TEST_F(HiddenApiTest, InstanceNativeMethodTwoListsMatch2) { |
| 519 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 520 | OpenStream(light_greylist) << "LMain;->inmethod(C)V" << std::endl; |
| 521 | OpenStream(dark_greylist) << "LMain;->inmethod(LBadType2;)V" << std::endl; |
| 522 | OpenStream(blacklist) << "LMain;->inmethod(C)V" << std::endl; |
| 523 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 524 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | TEST_F(HiddenApiTest, InstanceNativeMethodTwoListsMatch3) { |
| 528 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 529 | OpenStream(light_greylist) << "LMain;->inmethod(C)V" << std::endl; |
| 530 | OpenStream(dark_greylist) << "LMain;->inmethod(C)V" << std::endl; |
| 531 | OpenStream(blacklist) << "LMain;->inmethod(LBadType3;)V" << std::endl; |
| 532 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 533 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | TEST_F(HiddenApiTest, StaticNativeMethodNoMatch) { |
| 537 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 538 | OpenStream(light_greylist) << "LMain;->snmethod(LBadType1;)V" << std::endl; |
| 539 | OpenStream(dark_greylist) << "LMain;->snmethod(LBadType2;)V" << std::endl; |
| 540 | OpenStream(blacklist) << "LMain;->snmethod(LBadType3;)V" << std::endl; |
| 541 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 542 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 543 | ASSERT_EQ(HiddenApiAccessFlags::kWhitelist, GetSNMethodHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | TEST_F(HiddenApiTest, StaticNativeMethodLightGreylistMatch) { |
| 547 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 548 | OpenStream(light_greylist) << "LMain;->snmethod(Ljava/lang/Integer;)V" << std::endl; |
| 549 | OpenStream(dark_greylist) << "LMain;->snmethod(LBadType2;)V" << std::endl; |
| 550 | OpenStream(blacklist) << "LMain;->snmethod(LBadType3;)V" << std::endl; |
| 551 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 552 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 553 | ASSERT_EQ(HiddenApiAccessFlags::kLightGreylist, GetSNMethodHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | TEST_F(HiddenApiTest, StaticNativeMethodDarkGreylistMatch) { |
| 557 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 558 | OpenStream(light_greylist) << "LMain;->snmethod(LBadType1;)V" << std::endl; |
| 559 | OpenStream(dark_greylist) << "LMain;->snmethod(Ljava/lang/Integer;)V" << std::endl; |
| 560 | OpenStream(blacklist) << "LMain;->snmethod(LBadType3;)V" << std::endl; |
| 561 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 562 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 563 | ASSERT_EQ(HiddenApiAccessFlags::kDarkGreylist, GetSNMethodHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | TEST_F(HiddenApiTest, StaticNativeMethodBlacklistMatch) { |
| 567 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 568 | OpenStream(light_greylist) << "LMain;->snmethod(LBadType1;)V" << std::endl; |
| 569 | OpenStream(dark_greylist) << "LMain;->snmethod(LBadType2;)V" << std::endl; |
| 570 | OpenStream(blacklist) << "LMain;->snmethod(Ljava/lang/Integer;)V" << std::endl; |
| 571 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 572 | ASSERT_NE(dex_file.get(), nullptr); |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 573 | ASSERT_EQ(HiddenApiAccessFlags::kBlacklist, GetSNMethodHiddenFlags(*dex_file)); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | TEST_F(HiddenApiTest, StaticNativeMethodTwoListsMatch1) { |
| 577 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 578 | OpenStream(light_greylist) << "LMain;->snmethod(LBadType1;)V" << std::endl; |
| 579 | OpenStream(dark_greylist) << "LMain;->snmethod(Ljava/lang/Integer;)V" << std::endl; |
| 580 | OpenStream(blacklist) << "LMain;->snmethod(Ljava/lang/Integer;)V" << std::endl; |
| 581 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 582 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | TEST_F(HiddenApiTest, StaticNativeMethodTwoListsMatch2) { |
| 586 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 587 | OpenStream(light_greylist) << "LMain;->snmethod(Ljava/lang/Integer;)V" << std::endl; |
| 588 | OpenStream(dark_greylist) << "LMain;->snmethod(LBadType2;)V" << std::endl; |
| 589 | OpenStream(blacklist) << "LMain;->snmethod(Ljava/lang/Integer;)V" << std::endl; |
| 590 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 591 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | TEST_F(HiddenApiTest, StaticNativeMethodTwoListsMatch3) { |
| 595 | ScratchFile dex, light_greylist, dark_greylist, blacklist; |
| 596 | OpenStream(light_greylist) << "LMain;->snmethod(Ljava/lang/Integer;)V" << std::endl; |
| 597 | OpenStream(dark_greylist) << "LMain;->snmethod(Ljava/lang/Integer;)V" << std::endl; |
| 598 | OpenStream(blacklist) << "LMain;->snmethod(LBadType3;)V" << std::endl; |
| 599 | auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); |
David Brazdil | 003e64b | 2018-06-27 13:20:52 +0100 | [diff] [blame] | 600 | ASSERT_EQ(dex_file.get(), nullptr); |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | } // namespace art |