-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApk.h
More file actions
63 lines (47 loc) · 2.33 KB
/
Apk.h
File metadata and controls
63 lines (47 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef APKPARSER_APK_H
#define APKPARSER_APK_H
#include <androidfw/AssetManager.h>
#include <io/File.h>
#include <xml/XmlDom.h>
#include <json.hpp>
#include <set>
namespace apkparser {
constexpr static const char kApkResourceTablePath[] = "resources.arsc";
constexpr static const char kAndroidManifestPath[] = "AndroidManifest.xml";
class Apk {
private:
std::unique_ptr<aapt::io::IFileCollection> collection_;
std::unique_ptr<android::AssetManager> assetManager_;
public:
Apk(std::unique_ptr<aapt::io::IFileCollection> collection,
std::unique_ptr<android::AssetManager> assetManager)
: collection_(std::move(collection)), assetManager_(std::move(assetManager)){};
~Apk() = default;
android::AssetManager* GetAssetManager() const { return assetManager_.get(); }
aapt::io::IFileCollection* GetFileCollection() const { return collection_.get(); }
/// @brief zip格式加载apk、即使resources.arsc、AndroidManifest.xml不存在,也可以加载
/// @param path apk路径
/// @return 失败返回nullptr
static std::unique_ptr<Apk> LoadApkFromPath(const std::string& path);
/// @brief 解析manifest 和 application-label
/// @return 失败返回nullptr, 没有resources.arsc和AndroidManifest.xml返回空字符串
std::unique_ptr<std::pair<std::string, std::map<std::string, std::string>>> GetManifest() const;
/// @brief 获取resource.arsc中的字符串池
/// @return 失败返回nullptr, 没有resources.arsc或其中没有字符串,返回空字符串列表
std::unique_ptr<std::list<std::string>> GetStrings() const;
/// @brief 解析所有dex的class和string
/// @return 永远不会返回nullptr, 没有dex返回空列表
std::unique_ptr<std::pair<std::set<std::string>, std::set<std::string>>> ParseDexes() const;
/// @brief 执行所有的任务, 并返回json
/// @return 某个任务失败返回nullptr
std::unique_ptr<nlohmann::json> DoAllTasks() const;
// 删除字符串中的\r \n \t 空格
static std::string TrimString(std::string str) {
str.erase(std::remove(str.begin(), str.end(), '\r'), str.end());
str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());
str.erase(std::remove(str.begin(), str.end(), '\t'), str.end());
return str;
}
};
} // namespace apkparser
#endif // APKPARSER_APK_H