From 244597d73678e6ccdab2eeb1067bdb251f3cb911 Mon Sep 17 00:00:00 2001 From: xuchenghua09 Date: Wed, 7 Sep 2022 15:20:38 +0800 Subject: [PATCH 1/2] unpacking_tool Signed-off-by: xuchenghua09 --- META-INF/unpacking_tool/MANIFEST.MF | 4 +- bundle.json | 27 ++++++ bundle.py | 52 ++++++++++++ packingTool.gni | 38 +++++++++ unpackingTool.sh | 124 ++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+), 2 deletions(-) create mode 100644 bundle.json create mode 100644 bundle.py create mode 100644 packingTool.gni create mode 100644 unpackingTool.sh diff --git a/META-INF/unpacking_tool/MANIFEST.MF b/META-INF/unpacking_tool/MANIFEST.MF index 49c41f2b..85a5bb4e 100644 --- a/META-INF/unpacking_tool/MANIFEST.MF +++ b/META-INF/unpacking_tool/MANIFEST.MF @@ -1,4 +1,4 @@ Manifest-Version: 1.0 Created-By: javac.py -Class-Path: fastjson_utils_java.jar -Main-Class: ohos.UncompressEntrance +Class-Path: fastjson-1.2.78.jar +Main-Class: ohos.UncompressEntrance \ No newline at end of file diff --git a/bundle.json b/bundle.json new file mode 100644 index 00000000..564f6e0b --- /dev/null +++ b/bundle.json @@ -0,0 +1,27 @@ +{ + "name": "packing_tool", + "version": "3.2", + "license": "Apache License 2.0", + "publishAs": "code-segment", + "description": "packing_tool for openharmony", + "segment": { + "destPath": "developtools/packing_tool" + }, + "keywords": [ + "packing", + "unpacking" + ], + "component": { + "name": "packing_tool", + "subsystem": "developtools", + "adapted_system_type": [ "mini", "small", "standard" ], + "deps": { + "components": [] + }, + "build": { + "sub_component": [ + "//developtools/packing_tool:packing_tool" + ] + } + } + } \ No newline at end of file diff --git a/bundle.py b/bundle.py new file mode 100644 index 00000000..d3aa8b8f --- /dev/null +++ b/bundle.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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. +""" +Archives a set of files. +""" + +import os +import sys +import argparse +import subprocess + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--haptobin', required=True) + parser.add_argument('--appUnpackingTool', required=True) + parser.add_argument('--haptobinOutput', required=True) + parser.add_argument('--unpackingToolOutput', required=True) + parser.add_argument('--outpath', required=True) + args = parser.parse_args() + root_dir = os.path.dirname(os.path.realpath(__file__)) + + # compile haptobin_tool.jar + hap_to_bin_shell_path = os.path.join(root_dir, "haptobin.sh") + command_haptobin = ['sh', hap_to_bin_shell_path, root_dir, args.haptobinOutput, args.outpath] + child_haptobin = subprocess.Popen(command_haptobin, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + out, err = child_haptobin.communicate() + if child_haptobin.returncode != 0: + raise Exception("compile haptobin java class failed!") + + # compile app_unpacking_tool.jar + unpacking_tool_shell_path = os.path.join(root_dir, "unpackingTool.sh") + command_unpacking_tool = ['sh', unpacking_tool_shell_path, root_dir, args.unpackingToolOutput, args.outpath] + child_unpacking_tool = subprocess.Popen(command_unpacking_tool, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + out, err = child_unpacking_tool.communicate() + if child_unpacking_tool.returncode != 0: + raise Exception("compile unpacking_tool java class failed!") + +if __name__ == '__main__': + sys.exit(main()) \ No newline at end of file diff --git a/packingTool.gni b/packingTool.gni new file mode 100644 index 00000000..fb4120e0 --- /dev/null +++ b/packingTool.gni @@ -0,0 +1,38 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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("//build/config/python.gni") +import("//build/templates/metadata/module_info.gni") + +template("packing_tool") { + action_with_pydeps(target_name) { + forward_variables_from(invoker, + [ + "sources", + "outputs", + ]) + script = "//developtools/packing_tool/build.py" + args = [ + "--haptobin", + rebase_path(sources[0], root_build_dir), + "--appUnpackingTool", + rebase_path(sources[1], root_build_dir), + "--haptobinOutput", + rebase_path(outputs[0], root_build_dir), + "--unpackingToolOutput", + rebase_path(outputs[1], root_build_dir), + "--outpath", + rebase_path(outputs[2], root_build_dir), + ] + } +} \ No newline at end of file diff --git a/unpackingTool.sh b/unpackingTool.sh new file mode 100644 index 00000000..e4f3d2e5 --- /dev/null +++ b/unpackingTool.sh @@ -0,0 +1,124 @@ +# !/usr/bin/env bash +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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. + +root_path=$1 +unpacking_tool_jar_path=$2 +out_path=$3 +final_path=$(pwd) +echo "root_path is ${root_path}" +echo ${unpacking_tool_jar_path} +echo ${out_path} +echo ${final_path} + +temp_path="." +jar_dir="jar" +jar_directory="$root_Path/$jar_dir" +fastjson_jar_file="fastjson-1.2.78.jar" +fastjson_jar_path="$jar_directory/$fastjson_jar_file" +unpacking_tool_jar_file="app_unpacking_tool.jar" +unpacking_tool_jar_path="$final_path/$out_path" + +echo $unpacking_tool_jar_path +# make out dir +if [ -d "$unpacking_tool_jar_path" ] + then + echo "$unpacking_tool_jar_path exist" + else + mkdir -p $unpacking_tool_jar_path +fi +temp_jar_path="$root_path/jar/$unpacking_tool_jar_file" +manifest_path="$root_path/META-INF/unpacking_tool/MANIFEST.MF" +echo ${manifest_path} +# compile java class +out_dir="$root_path/out/production/unpacking_tool" + +out_class="$temp_path/$out_dir" + +class_collection="" +java_collection="" +java_suffix=".java" +class_suffix=".class" +declare -a unpack_java=( + "BundleException" + "CommandParser" + "Log" + "ShowHelp" + "UncompressEntrance" + "Uncompress" + "UncompressVerify" + "Utility" + "HapInfo" + "ReqPermission" + "Distro" + "AbilityInfo" + "MetaData" + "MetaDataInfo" + "SkillInfo" + "UsedScene" + "PackInfo" + "FormInfo" + "ProfileInfo" + "AppInfo" + "DefPermission" + "DefPermissionGroup" + "CustomizeData" + "UncomperssResult" + "JsonUtil" + "JsInfo" + "DeviceConfig" + "CommonEvent" + "Shortcut" + "IntentInfo" + "ResourcesParser" + "DistroFilter" + "ApiVersion" + "ScreenShape" + "ScreenDensity" + "ScreenWindow" + "CountryCode" + "HapZipInfo" + "AbilityFormInfo" + "ModuleAbilityInfo" + "ModuleAppInfo" + "ModuleDeviceType" + "ModuleInfo" + "ModuleMetadataInfo" + "ModuleProfileInfo" + "ModuleResult" + "UriInfo" + "ExtensionAbilityInfo" + "ModuleAdaption" + "ModuleShortcut" + "Want" + "DefinePermission" + "ResourceIndexResult" + "FileUtils" +) + +unpack_java_length=${#unpack_java[@]} +for ((i=0; i<${unpack_java_length}; ++i)) +do + java_collection="${java_collection} ${root_path}/adapter/ohos/${unpack_java[$i]}${java_suffix}" +done + +compile_command="javac -source 1.8 -target 1.8 -cp $root_path/jar/fastjson-1.2.78.jar -d ${out_dir} ${java_collection}" +eval $compile_command + +# pack app_unpacking_tool.jar + +cd $out_dir +product_unpack_jar_command="jar -cvfm ${temp_jar_path} ${manifest_path} ./ohos" +eval $product_unpack_jar_command +copy_command="cp ${temp_jar_path} ${unpacking_tool_jar_path}" +eval ${copy_command} \ No newline at end of file -- Gitee From 09df319f7b0445ecba47acf76c69615868fc69e3 Mon Sep 17 00:00:00 2001 From: xuchenghua09 Date: Wed, 7 Sep 2022 15:48:10 +0800 Subject: [PATCH 2/2] format Signed-off-by: xuchenghua09 --- packingTool.gni | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packingTool.gni b/packingTool.gni index fb4120e0..56c0e1ea 100644 --- a/packingTool.gni +++ b/packingTool.gni @@ -35,4 +35,4 @@ template("packing_tool") { rebase_path(outputs[2], root_build_dir), ] } -} \ No newline at end of file +} -- Gitee