• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *   http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <dlfcn.h>
17 #include <link.h>
18 #include <stdlib.h>
19 #include "functionalext.h"
20 
header_handler(struct dl_phdr_info * info,size_t size,void * data)21 static int header_handler(struct dl_phdr_info *info, size_t size, void *data)
22 {
23     void *addrhead = (void *)(info->dlpi_addr + info->dlpi_phdr[0].p_vaddr);
24     if ((strcmp(info->dlpi_name, "/data/libtest.so") == 0) && (addrhead != NULL)) {
25         return 1;
26     }
27     return 0;
28 }
29 
30 /**
31  * @tc.name      : dl_iterate_phdr_0100
32  * @tc.desc      : The parameter is valid, get the starting address of the dynamic library loaded in the memory.
33  * @tc.level     : Level 0
34  */
dl_iterate_phdr_0100(void)35 void dl_iterate_phdr_0100(void)
36 {
37     system("cp /system/lib/libutils.z.so /data/libtest.so");
38     void *handle = dlopen("/data/libtest.so", RTLD_NOW);
39     int ret = 0;
40     ret = dl_iterate_phdr(header_handler, NULL);
41     EXPECT_EQ("dl_iterate_phdr_0100", (int)ret, 1);
42     system("rm -rf /data/libtest.so");
43     exit(EXIT_SUCCESS);
44 }
45 
main(int argc,char * argv[])46 int main(int argc, char *argv[])
47 {
48     dl_iterate_phdr_0100();
49     return t_status;
50 }