1 /* 2 * Copyright (c) 2023 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 #ifndef SANITIZERD_ZIPHELPER_H 17 #define SANITIZERD_ZIPHELPER_H 18 #include <algorithm> 19 #include <string> 20 #include <vector> 21 #include <sys/types.h> 22 23 #include "reporter.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 constexpr unsigned SL_BUF_LEN = 512; 28 constexpr unsigned GZ_BUF_SIZE = 4096; 29 constexpr char GZ_SUFFIX[] = ".gz"; 30 constexpr unsigned BUF_SIZE = 1024; 31 constexpr unsigned MAX_PROCESS_PATH = 1024; 32 constexpr unsigned HASH_FACTOR = 16127; 33 constexpr unsigned MILLISEC_OF_PER_SEC = 1000; 34 constexpr unsigned MICROSEC_OF_PER_MILLISEC = 1000; 35 constexpr int MIN_APP_USERID = 10000; 36 constexpr uint32_t MAX_NAME_LENGTH = 4096; 37 constexpr int AID_ROOT = 0; 38 constexpr int AID_SYSTEM = 1000; 39 constexpr mode_t DEFAULT_LOG_FILE_MODE = 0666; 40 constexpr mode_t DEFAULT_LOG_DIR_MODE = 0775; 41 constexpr char CUSTOM_SANITIZER_LOG_PATH[] = "/data/log/faultlog/faultlogger/"; 42 constexpr char ROOT_FAULTLOG_LOG_PATH[] = "/data/log/faultlog/"; 43 const std::string DEVICE_OHOS_VERSION_PARAM = "hw_sc.build.os.version"; 44 const std::string EMPTY_PARAM = ""; 45 46 bool IsLinkFile(const std::string& sfilename); 47 bool GetRealPath(const std::string& fn, std::string& out); 48 bool ReadFileToString(const std::string& path, std::string& out); 49 std::vector<std::string> SplitString(const std::string& input, const std::string& regex); 50 unsigned HashString(const std::string& input); 51 bool IsModuleNameValid(const std::string& name); 52 std::string GetApplicationNameById(int32_t uid); 53 std::string GetApplicationVersion(int32_t uid, const std::string& bundleName); 54 void WriteCollectedData(T_SANITIZERD_PARAMS *params); 55 } // namespace HiviewDFX 56 } // namespace OHOS 57 58 #endif // SANITIZERD_ZIPHELPER_H 59 60