/* * Copyright (c) 2021 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. * See the LICENSE file in the root of this repository for complete details. */ #ifndef HC_GEN_DECOMPILE_H #define HC_GEN_DECOMPILE_H #include #include #include "ast.h" namespace OHOS { namespace Hardware { class Decompile { public: explicit Decompile(const std::string &fileName); ~Decompile() = default; bool DoDecompile(); private: bool InitDecompileFile(); bool ReadFile(char *buffer, size_t readSize); uint32_t GetAlignSize(uint32_t size) const { if (isAlign_) { return (size + ALIGN_SIZE - 1) & (~(ALIGN_SIZE - 1)); } else { return size; } } bool ReadUint8(uint8_t &value); bool ReadUint16(uint16_t &value); bool ReadUint32(uint32_t &value); bool ReadUint64(uint64_t &value); bool ReadString(std::string &value); void SetAlign(bool isAlign); bool VerifyDecompileFile(); bool GetNextByteCode(uint32_t &byteCode); std::shared_ptr RebuildObject(uint8_t opCode); std::shared_ptr RebuildNode(); std::shared_ptr RebuildTerm(); std::shared_ptr RebuildNodeRefObject(); std::shared_ptr RebuildNumberObject(uint8_t opCode); std::shared_ptr RebuildArray(); std::shared_ptr RebuildStringObject(); std::shared_ptr RebuildAst(); bool isAlign_; std::string fileName_; std::ifstream file_; }; } // namespace Hardware } // namespace OHOS #endif // HC_GEN_DECOMPILE_H