[mobile]patch apk后重打包重签名

30 篇文章 2 订阅
2 篇文章 1 订阅

patch apk后重打包重签名

有很多时候想要逆向分析一个apk文件,单纯的静态分析不能解决我们的需求,我们需要patch一下apk的库文件(比如patch反调试),或是修改java源码等,我们希望修改之后重新打包成apk,然后装入实机调试,那么就需要将其重打包重签名。

工具
java环境

java环境是必不可少的,后面的所有工具都依赖java环境。

apk tools

下载apk tools

https://ibotpeaches.github.io/Apktool/install/

以windows平台来讲,需要下载的内容有两个,分别是途中画红框的,bat 脚本和apktool.jar 将bat脚本拷贝下来保存为apktool.bat并与apktool.jar放在一个目录下,我连测试用apk也放在了一起:

##### Android Studio

生成签名文件用,官网下载即可:https://developer.android.com/studio

然后一顿下一步安装即可,没什么坑。

解包
.\apktool.bat d .\test.apk

运行上述脚本进行解包:

解包好之后会出现test文件夹,里面都是apk包中的内容:

patch文件

这里我是patch了一下库文件,原本库文件中有ptrace反调试,被我nop掉了,然后将patch后的so文件与原文件替换:

重打包

patch之后我们想重新做成apk文件,首先要进行重打包。

再返回apktool目录,运行下面指令重打包:

.\apktool.bat b test -o new_test.apk   //test:文件夹名  new_test.apk重打包后的名字

发现多了一个new_test.apk,这就是重打包好的apk文件:

但目前还无法正常安装,因为还没有为其签名。

生成签名文件

想要重打包成可以正常安装的apk文件,我们还需要为其签名,这时我们需要准备一个签名文件,可以使用Android Studio来生成

首先用Android Studio打开apk,然后头部菜单中的build->Generate Signed APK

选择apk:

新建一个key store password:

然后输入秘钥信息,选择保存路径,下面的密码设置一下(我两个密码设置的一样,反正我也分不清哪个是干啥的),之后签名的时候会用到,alias是秘钥别名,起了别名之后也记住了,之后会用到,下面的certificate 中至少写一行就可以了(参照网上攻略所说,并不是专业搞Android的,马马虎虎吧):

新版的Android studio会报这个错:

不用管 ,直接ok,会自动给你改成新的秘钥格式,然后什么都不用碰,直接下一步,然后完成即可:

生成的秘钥文件:

给apk签名

给apk签名用到java环境中的jarsigner,如果java环境安装没有问题的话,是自动有的,使用命令如下:

jarsigner.exe -verbose -keystore .\testSign.jks -signedjar test_finish.apk .\new_test.apk cat -digestalg SHA1 -sigalg MD5withRSA 
//.\testSign.jks  签名文件
//test_finish.apk 给签名玩生成的apk起个名
//.\new_test.apk  要签名的apk
//cat      		  之前生成签名文件时设置的别名

然后还需要输入一下之前设置的密码:
在这里插入图片描述
之后就自动申城了签名好的apk:

安装测试

安装成功,并且成功将反调试patch调了。

参考资料

Android Studio生成签名文件:https://m.imooc.com/article/details?article_id=73361

重打包重签名:https://www.jianshu.com/p/792a08d5452c

https://www.jianshu.com/p/db709a280d9a

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 Kivy 打包 APK,您需要遵循以下步骤: 1. 安装 Kivy 和 Buildozer 您需要运行以下命令来安装 Kivy 和 Buildozer: ``` pip install kivy pip install buildozer ``` 2. 创建一个 Kivy 应用程序 创建一个 Kivy 应用程序,并确保它可以在本地计算机上运行。 3. 配置 buildozer.spec 文件 在您的 Kivy 应用程序目录中创建一个名为 buildozer.spec 的文件,并配置以下选项: ``` [app] # (str) Title of your application title = My Application # (str) Package name package.name = myapp # (str) Package domain (needed for android/ios packaging) package.domain = org.test # (str) Source code where the main.py live source.dir = . # (list) Source files to include (let empty to include all the files) source.include_exts = py,png,jpg,kv,atlas # (list) List of inclusions using pattern matching #source.include_patterns = assets/*,images/*.png # (list) Source files to exclude (let empty to not exclude anything) #source.exclude_exts = spec # (list) List of directory to exclude #source.exclude_dirs = tests, bin # (list) List of exclusions using pattern matching #source.exclude_patterns = license,images/*/*.jpg # (str) Application versioning (method 1) version = 0.1 # (str) Application versioning (method 2) # version.regex = __version__ = ['"](.*)['"] # version.filename = %(source.dir)s/main.py # (list) Application requirements requirements = kivy # (str) Custom source folders for requirements # (it's relative to the current directory) #source.custom_kivy = ../kivy # (list) Permissions android.permissions = INTERNET # (str) Android logcat filters to use android.logcat_filters = *:S python:D # (str) Android entry point android.entrypoint = org.test.myapp.myapp # (int) Target Android API, should be as high as possible. #android.api = 27 # (int) Minimum API your APK will support. android.minapi = 21 # (int) Android SDK version to use android.sdk = 20 # (str) Android NDK version to use #android.ndk = 19b # (bool) Use --private data storage (True) or --dir public storage (False) #android.private_storage = True # (str) Android NDK directory (if empty, it will be automatically downloaded.) #android.ndk_path = # (str) Android SDK directory (if empty, it will be automatically downloaded.) #android.sdk_path = # (str) python-for-android git clone directory (if empty, it will be automatically cloned from github) #android.p4a_dir = # (list) python-for-android whitelist #android.whitelist = # (str) OUYA Console category. Should be one of GAME or APP # If you leave this blank, OUYA will classify your app as "unknown". #android.ouya.category = GAME # (str) Filename of OUYA Console icon. It must be a 732x412 png image. #android.ouya.icon.filename = %(source.dir)s/data/icon-ouya-console.png # (str) XML file to include as an intent filters in <activity> tag #android.manifest.intent_filters = # (list) Android additionnal libraries #android.add_libs = libs/android/*.so # (list) Add Java jars #android.add_jars = foo.jar,bar.jar # (str) JNI directory containing the Android.mk file to use #android.jni_directory = None # (str) java directory containing the Android.mk file to use #android.java_directory = None # (bool) Use --bootstrap when building the Android app #android.bootstrap = False # (str) Path to a custom AndroidManifest.xml #android.manifest.custom = # (str) If you need to insert variables into your AndroidManifest.xml file, # you can do so with the manifestPlaceholders property. # See: https://developer.android.com/studio/build/manifest-build-variables.html #android.manifest.placeholders = # (str) Path to a custom build.py file #android.build.custom_dir = # (str) Path to a custom __init__.py file to use as __init__.py for the whole build #android.build.source_init = # (list) List of Java classes to add to the build process (can be java or aars) #android.add_classpaths = foo.jar,bar.jar # (list) List of Java classes to add to the build process (can be java or aars) #android.add_aars = foo.jar,bar.jar # (list) Gradle dependencies to add (currently works only with sdl2 bootstrap) #android.gradle_dependencies = # (str) Set the gradle version (default is 2.2.0) #android.gradle_version = 2.2.0 # (bool) If True, attempt to run the app on the device via adb #android.try_build_ext = False # (str) iOS bundle identifier #ios.bundle_identifier = org.test.myapp # (str) iOS App Store ID #ios.app_store_id = # (str) iOS SDK to use #ios.sdk = 10.1 # (str) The name of the certificate to use for signing the debug version of the app # Get a list of available identities: buildozer ios list_identities #ios.codesign.debug = "iPhone Developer" # (str) The name of the certificate to use for signing the release version of the app #ios.codesign.release = %(ios.codesign.debug)s # (str) The path to the provisioning profile to use for the debug version of the app # Get a list of available provisioning profiles: buildozer ios list_profiles #ios.provisioning_profile_debug = # (str) The path to the provisioning profile to use for the release version of the app #ios.provisioning_profile_release = # (bool) Compile with the SaleorSDK #ios.use_salesforce_mobile_sdk = False # (list) Icon files #icon.filename = %(source.dir)s/data/icon.png #icon.filename = %(source.dir)s/data/icon-256.png #icon.filename = %(source.dir)s/data/icon-512.png #icon.filename = %(source.dir)s/data/icon-1024.png # (str) Keystore location (if you want to enable signing with a custom keystore) #android.sign.keystore = # (str) Keystore alias (if you want to enable signing with a custom keystore) #android.sign.alias = # (str) Keystore password (if you want to enable signing with a custom keystore) #android.sign.keystore_password = # (str) Key password (if you want to enable signing with a custom keystore) #android.sign.key_password = # (int) Number of permissions to prompt in the ``Permissions`` popup #android.max_permissions = 5 # (str) Bootstrap to use. Choices: sdl2, pygame #p4a.bootstrap = sdl2 # (int) Number of times to retry retrieving the Android SDK before giving up #android.sdk_retry = 0 # (bool) Stop on first error encountered when compiling/building the python part of the project. #stop_on_first_error = False # (bool) Log output of p4a to files #log_level = 2 #log_dir = logs #log_name = p4a_build.log # (list) List of package names to be included in the final package. # Some android app store require this. #android.add_packages = # (list) Used to copy files into the App (useful to copy obb data, licensing stuff, etc.) Must be a list of tuples #android.add_files = # (list) List of Java classes to add to the build process #android.add_java_classes = # (list) List of Java files to add to the build process #android.add_javas = # (str) Path to a custom AndroidManifest.xml (template to generate the actual AndroidManifest.xml) #android.manifest.template = # (str) Path to a custom toolchain .zip file (can be used to use a pre-built library) #android.toolchain = # (str) Path to a custom obb file #android.obb.filename = # (str) Path to a custom obb file that should be put into the assets directory. This file will be read by the app at runtime. #android.obb.main = # (str) Path to a custom obb file that should be put into the assets directory. This file will be read by the app at runtime. #android.obb.patch = # (bool) Enables Android App Bundle format #android.bundle.enable = False # (str) Specifies the format to use for the Android App Bundle. Choices are: # universal: generates a fat APK that works on all devices # split: generates an APK per ABI and on that only contains the resources for that ABI. #android.bundle.mode = universal # (list) List of split options to apply # android.bundle.split_config = abi # (list) List of obfuscation options to apply #android.obfuscation = # (str) Path to the python for android git checkout to use for the build #p4a.source_dir = # (str) Path to the android ndk to use for the build #android.ndk_path = # (str) Path to the android sdk to use for the build #android.sdk_path = # (str) Path to the ant directory for the build #android.ant_path = # (str) Path to the android build tools directory #android.build_tools_path = # (bool) If True, automatically accept SDK license #android.accept_sdk_license = False # (bool) If True, no other SDK packages will be downloaded #android.no_sdk_packages = False # (str) Android theme to use for the app #android.theme = # (bool) Copy library instead of making a libpymodules.so #android.copy_libs = False # (bool) Use a black background #ios.black_background = False # (str) URL scheme to use for the iOS app #ios.url_scheme = # (str) Bundle name for the iOS app #ios.bundle_name = # (str) The entitlements file to use #ios.entitlements = # (str) The entitlements file to use for the debug version of the app #ios.entitlements.debug = # (str) The entitlements file to use for the release version of the app #ios.entitlements.release = # (str) The path to the entitlements file to use #ios.entitlements.path = # (str) The development team to use for signing the app #ios.development_team = # (str) The development team to use for signing the debug version of the app #ios.development_team.debug = # (str) The development team to use for signing the release version of the app #ios.development_team.release = # (str) The provisioning profile to use for the debug version of the app #ios.provisioning_profile_debug = # (str) The provisioning profile to use for the release version of the app #ios.provisioning_profile_release = # (list) URL Schemes to use for the app #ios.url_schemes = # (list) iOS frameworks to link against #ios.frameworks = # (list) iOS frameworks to weakly link against #ios.frameworks.weak = # (list) iOS libraries to link against #ios.libraries = # (list) iOS libraries to weakly link against #ios.libraries.weak = # (bool) Enable bitcode support #ios.enable_bitcode = False # (str) The path to the entitlements file to use for the watch extension #ios.watch_extension_entitlements = # (str) The path to the provisioning profile to use for the watch extension #ios.watch_extension_provisioning_profile = # (list) iOS icon files to be used #ios.icons = # (str) The background color of the application's icon #ios.icon_background_color = # (str) The mask to use for the application's icon #ios.icon_mask = # (list) iOS assets to include #ios.assets_directory = # (str) iCloud entitlements file to use for the project #ios.icloud_entitlements = # (bool) Whether the app should be uploaded to TestFlight on build #ios.testflight.upload = False # (str) API Key for TestFlight #ios.testflight.api_token = # (str) Team Token for TestFlight #ios.testflight.team_token = # (str) Distribution lists for TestFlight #ios.testflight.distribution_lists = # (list) Any other custom Xcode build settings to use #ios.pbxproj_variables = ``` 您需要根据您的应用程序进行相应的更改。 4. 创建一个虚拟环境 在您的项目目录中创建一个虚拟环境: ``` python3 -m venv myenv ``` 5. 激活虚拟环境 激活虚拟环境: ``` source myenv/bin/activate ``` 6. 初始化 buildozer 初始化 buildozer: ``` buildozer init ``` 7. 编辑 buildozer.spec 文件 编辑 buildozer.spec 文件,并确保您已经配置了正确的选项。 8. 打包 APK 运行以下命令来打包 APK: ``` buildozer -v android debug ``` 这将创建一个名为 myapp-0.1-debug.apkAPK 文件。 注意:在打包 APK 之前,请确保您已经按照 Kivy 官方文档中的说明正确地配置了 Android SDK 和 NDK。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值