-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wcedla
committed
Nov 17, 2023
0 parents
commit 32f5d73
Showing
30 changed files
with
2,192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[中文](README.md) | [English](README_en.md) | ||
|
||
# AndroidApexTools | ||
|
||
一个帮助解包android的apex包,并支持重新打包成apex的工具 | ||
|
||
> 项目地址:https://github.com/wcedla/AndroidApexTools | ||
## 功能说明 | ||
|
||
> <font style="color:red">当前仅支持linux和wsl子系统,测试环境为win10的wsl2的ubuntu 22.04</font> | ||
### 1. 解包 | ||
|
||
```shell | ||
cd 当前脚本存放位置 | ||
sudo python3 ./deapexer.py extract ./foo.apex | ||
``` | ||
|
||
解包后会在当前脚本路径生成manifest和payload两个文件夹,manifest文件夹里面的内容一般不需要修改,payload就是原apex里面img解包后的文件,可以修改 | ||
|
||
### 2. 打包 | ||
|
||
```shell | ||
cd 当前脚本存放位置 | ||
sudo python3 ./apexer.py --api 33 ./bar.apex | ||
``` | ||
|
||
确保当前路径存在manifest和payload文件夹,api参数表示这个apex的android api版本,是必填项 | ||
|
||
|
||
> 注意:重新打包后的apex签名和系统签名不一致,需要核心破解 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
[中文](README.md) | [English](README_en.md) | ||
|
||
- # AndroidApexTools | ||
|
||
A tool to help unpack and repack Android apex packages | ||
|
||
> Project address: https://github.com/wcedla/AndroidApexTools | ||
## **Features** | ||
|
||
> Currently only supports Linux and WSL subsystem, tested on Ubuntu 22.04 in WSL2 on Win10 | ||
### **1. Unpack** | ||
|
||
```shell | ||
cd path/to/script | ||
sudo python3 ./deapexer.py extract ./foo.apex | ||
``` | ||
|
||
After unpacking, manifest and payload folders will be generated under the script path. The manifest folder contains metadata that usually doesn't need modification. The payload folder contains the extracted img files from the original apex, which can be modified. | ||
|
||
### **2. Repack** | ||
|
||
```shell | ||
cd path/to/script | ||
sudo python3 ./apexer.py --api 33 ./bar.apex | ||
``` | ||
|
||
Make sure there are manifest and payload folders under the current path. The api parameter specifies the Android api version for this apex and is required. | ||
|
||
> Note: The repacked apex will have a different signature from the system signature and needs core patch to work. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright (C) 2018 The Android Open Source Project | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import apex_manifest_pb2 | ||
from google.protobuf import message | ||
from google.protobuf.json_format import MessageToJson | ||
import zipfile | ||
|
||
class ApexManifestError(Exception): | ||
|
||
def __init__(self, errmessage): | ||
# Apex Manifest parse error (extra fields) or if required fields not present | ||
self.errmessage = errmessage | ||
|
||
|
||
def ValidateApexManifest(manifest_pb): | ||
# Checking required fields | ||
if manifest_pb.name == "": | ||
raise ApexManifestError("'name' field is required.") | ||
if manifest_pb.version == 0: | ||
raise ApexManifestError("'version' field is required.") | ||
if manifest_pb.noCode and (manifest_pb.preInstallHook or | ||
manifest_pb.postInstallHook): | ||
raise ApexManifestError( | ||
"'noCode' can't be true when either preInstallHook or postInstallHook is set" | ||
) | ||
|
||
def ParseApexManifest(file): | ||
try: | ||
with open(file, "rb") as f: | ||
manifest_pb = apex_manifest_pb2.ApexManifest() | ||
manifest_pb.ParseFromString(f.read()) | ||
return manifest_pb | ||
except message.DecodeError as err: | ||
raise ApexManifestError(err) | ||
|
||
def fromApex(apexFilePath): | ||
with zipfile.ZipFile(apexFilePath, 'r') as apexFile: | ||
with apexFile.open('apex_manifest.pb') as manifestFile: | ||
manifest = apex_manifest_pb2.ApexManifest() | ||
manifest.ParseFromString(manifestFile.read()) | ||
return manifest | ||
|
||
def toJsonString(manifest): | ||
return MessageToJson(manifest, indent=2) |
Oops, something went wrong.