1 /*
2  * Copyright (C) 2018 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 #ifndef ART_LIBDEXFILE_EXTERNAL_INCLUDE_ART_API_DEX_FILE_EXTERNAL_H_
18 #define ART_LIBDEXFILE_EXTERNAL_INCLUDE_ART_API_DEX_FILE_EXTERNAL_H_
19 
20 // Dex file external API
21 
22 #include <sys/types.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 // This is the stable C ABI that backs art_api::dex below. Structs and functions
29 // may only be added here. C++ users should use dex_file_support.h instead.
30 
31 // Opaque wrapper for an std::string allocated in libdexfile which must be freed
32 // using ExtDexFileFreeString.
33 struct ExtDexFileString;
34 
35 // Returns an ExtDexFileString initialized to the given string.
36 const struct ExtDexFileString* ExtDexFileMakeString(const char* str, size_t size);
37 
38 // Returns a pointer to the underlying null-terminated character array and its
39 // size for the given ExtDexFileString.
40 const char* ExtDexFileGetString(const struct ExtDexFileString* ext_string, /*out*/ size_t* size);
41 
42 // Frees an ExtDexFileString.
43 void ExtDexFileFreeString(const struct ExtDexFileString* ext_string);
44 
45 struct ExtDexFileMethodInfo {
46   int32_t offset;
47   int32_t len;
48   const struct ExtDexFileString* name;
49 };
50 
51 struct ExtDexFile;
52 
53 // See art_api::dex::DexFile::OpenFromMemory. Returns true on success.
54 int ExtDexFileOpenFromMemory(const void* addr,
55                              /*inout*/ size_t* size,
56                              const char* location,
57                              /*out*/ const struct ExtDexFileString** error_msg,
58                              /*out*/ struct ExtDexFile** ext_dex_file);
59 
60 // See art_api::dex::DexFile::OpenFromFd. Returns true on success.
61 int ExtDexFileOpenFromFd(int fd,
62                          off_t offset,
63                          const char* location,
64                          /*out*/ const struct ExtDexFileString** error_msg,
65                          /*out*/ struct ExtDexFile** ext_dex_file);
66 
67 // See art_api::dex::DexFile::GetMethodInfoForOffset. Returns true on success.
68 int ExtDexFileGetMethodInfoForOffset(struct ExtDexFile* ext_dex_file,
69                                      int64_t dex_offset,
70                                      int with_signature,
71                                      /*out*/ struct ExtDexFileMethodInfo* method_info);
72 
73 typedef void ExtDexFileMethodInfoCallback(const struct ExtDexFileMethodInfo* ext_method_info,
74                                           void* user_data);
75 
76 // See art_api::dex::DexFile::GetAllMethodInfos.
77 void ExtDexFileGetAllMethodInfos(struct ExtDexFile* ext_dex_file,
78                                  int with_signature,
79                                  ExtDexFileMethodInfoCallback* method_info_cb,
80                                  void* user_data);
81 
82 // Frees an ExtDexFile.
83 void ExtDexFileFree(struct ExtDexFile* ext_dex_file);
84 
85 #ifdef __cplusplus
86 }  // extern "C"
87 #endif
88 
89 #endif  // ART_LIBDEXFILE_EXTERNAL_INCLUDE_ART_API_DEX_FILE_EXTERNAL_H_
90