• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 <stdint.h>
17 #include <dlfcn.h>
18 #include <stdio.h>
19 
20 
21 int g_strcpyTime = 100;
22 static void *g_handle = NULL;
23 
GetHandle(void)24 static void GetHandle(void)
25 {
26     if (g_handle != NULL) {
27         return;
28     }
29 #if defined(__LP64__)
30     g_handle = dlopen("/system/lib64/chipset-pub-sdk/libsec_shared.z.so", RTLD_LAZY);
31 #else
32     g_handle = dlopen("/system/lib/chipset-pub-sdk/libsec_shared.z.so", RTLD_LAZY);
33 #endif
34 }
35 
strcpy_s(char * strDest,size_t destMax,const char * strSrc)36 int strcpy_s(char *strDest, size_t destMax, const char *strSrc)
37 {
38     GetHandle();
39     if (g_handle == NULL) {
40         printf("dlopen failed\n");
41     }
42     if (g_strcpyTime == 0) {
43         return -1;
44     }
45 
46     static int (*func)(char *strDest, size_t destMax, const char *strSrc) = NULL;
47     if (func == NULL) {
48         func = (int (*)(char *strDest, size_t destMax, const char *strSrc))dlsym(g_handle, "strcpy_s");
49     }
50     if (func == NULL) {
51         printf("dlsym strcpy_s failed\n");
52         return -1;
53     }
54 
55     return func(strDest, destMax, strSrc);
56 }