Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apk安装失败 #72

Open
wa-heng opened this issue Mar 29, 2023 · 19 comments
Open

apk安装失败 #72

wa-heng opened this issue Mar 29, 2023 · 19 comments

Comments

@wa-heng
Copy link

wa-heng commented Mar 29, 2023

使用自己的apk加固后安装和作者提供的app-release-protect.apk都安装失败,报解析安装包失败,请问该怎么解决,麻烦了,谢谢

@maoabc
Copy link
Owner

maoabc commented Mar 29, 2023

看使用说明,本来提供例子是给人分析看效果的,安装请自己签名

@wa-heng wa-heng closed this as completed Mar 31, 2023
@wa-heng wa-heng reopened this Mar 31, 2023
@wa-heng
Copy link
Author

wa-heng commented Mar 31, 2023

我使用一个只有MainActivaty的简单项目测试,看着比你的demo还要简单很多,使用java -jar nmm-protect-xxx.jar input.apk命令,没有添加加固过滤规则文件,安装时过了权限要求步骤,点继续后报安装失败,请问是我的环境还是需要写过滤文件有误,对java版本、gradle版本这些有要求不,麻烦解答,谢谢

@maoabc
Copy link
Owner

maoabc commented Mar 31, 2023

你看下日志从哪崩溃的,应该跟加固androidx库有关系,跳过加固那些类。我改了loadLibrary调用位置后会导致加固androidx库的一些类在so加载前初始化。

@maoabc
Copy link
Owner

maoabc commented Mar 31, 2023

最开始把loadlibrary放在application里没问题,后面单独放在自己添加的类里(NatvieUtils),这种情况下我之前调试就遇到androidx里一个enum报找不到本地方法错误。按理说任何情况下新增加进去的NatvieUtils的静态初始化方法会第一时间执行,不会出现so没加载情况,目前不清楚具体原因,不过遇到这种一般跳过那些类就正常了。

@wa-heng
Copy link
Author

wa-heng commented Apr 23, 2023

你好,我的项目minsdk是24,加固后安装报Failure [INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2],改minsdk=21就正常,如果我我需要将minSDK升级的话,请问是否需要更新DexOpcodes.h和InterpC-portable.cpp这些指令相关的代码

@maoabc
Copy link
Owner

maoabc commented Apr 23, 2023

不用改其他,看源码里有这个部分的注释,你需要在AndroidManifest.xml里增加android:extractNativeLibs="true",如果没加这个参数就不能压缩so,且so需要4k对齐。

@maoabc
Copy link
Owner

maoabc commented Apr 23, 2023

不压缩so加上so对齐(需要对齐跟mmap系统调用有关),apk安装后就不会解压so,安装后占用空间小些但apk本身会增大。

@wa-heng
Copy link
Author

wa-heng commented Jun 15, 2023

大佬,再麻烦您一下,我现在加固自定义EditText,派生的EditText重写了public boolean onTouchEvent(MotionEvent event)方法,只要加固该方法就会导致弹不出键盘;而加固自定义的Listview,也是也是onTouchEvent方法,会导致列表滑动卡顿,请问你有遇到这个问题吗

@maoabc
Copy link
Owner

maoabc commented Jun 15, 2023

没遇到过,卡顿看看是不是太多数组操作,数组操作多可以适当提取一下,把数组操作提取到单独的方法中别加固。你可以只加固onTouchEvent这个方法,然后开启debug把日志发来,一般情况除了字符串常量池部分操作指令(ldc)没法正确模拟,其他都没什么问题。

@wa-heng
Copy link
Author

wa-heng commented Jun 16, 2023

我测试了下发现,我的自定义MyEditText控件的父类控件(另一个继承自EditText的自定义控件)没有实现onTouchEvent,它的爷爷类EditText才有实现onTouchEvent,我在父类实现了onTouchEvent后就正常了。
那这个问题是不是有可能是跳转父类方法出异常了
public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}

@wa-heng
Copy link
Author

wa-heng commented Jun 16, 2023

========================= 父类重载了onTouchEvent的 =========================
####|invoke-super args=2 @0x55cc {regs=0x0032 0}
####set argument args[1]=7fee8fee48
####|invoke-super args=2 @0x0308 {regs=0x0010 0}
####set argument args[1]=7fee8f29a8
####|move-result v1 (v1=0x00000001)
####|return v1
####|move-result v3 (v3=0x00000001)
####|sget-object v0,sfield@0x56eb
####+ SGET '4564'=0x000000a5
####|const-string v1 string@0x055c
####|invoke-virtual args=2 @0x5d80 {regs=0x0010 0}
####set argument args[1]=000000b5

========================= 父类没有重载onTouchEvent的 =========================
####|invoke-super args=2 @0x0308 {regs=0x0032 0}
####set argument args[1]=7fee8fee48
####|move-result v3 (v3=0x00000001)
####|sget-object v0,sfield@0x56eb
####+ SGET '4564'=0x000000a1
####|const-string v1 string@0x055d
####|invoke-virtual args=2 @0x5d7f {regs=0x0010 0}
####set argument args[1]=000000b9

@maoabc
Copy link
Owner

maoabc commented Jun 16, 2023 via email

@maoabc
Copy link
Owner

maoabc commented Jun 16, 2023

public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}
就只加固这个也会出问题吗?

@maoabc
Copy link
Owner

maoabc commented Jun 16, 2023

下面那个包含const-string指令的方法是哪里的?

@maoabc
Copy link
Owner

maoabc commented Jun 16, 2023

先别管父类,你MyEditText 的onTouchEvent 重载后,加固跟没加固会有差别?
如果自定义View只是
public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}
看执行日志是正确执行了,且返回true。但是后面那个const-string跟得到静态域指令是哪里的方法?要排除的话只加固onTouchEvent就行,其他方法一律不处理,排除干扰。

@maoabc
Copy link
Owner

maoabc commented Jun 16, 2023

move-result v3 (v3=0x00000001)
####|sget-object v0,sfield@0x56eb
####+ SGET '4564'=0x000000a5
####|const-string v1 string@0x055c
####|invoke-virtual args=2 @0x5d80 {regs=0x0010 0}
####set argument args[1]=000000b5
不知道这个方法是哪的,两个字符串传递调用另外的方法,如果那个方法里有用到==来对比字符串,那么肯定会有问题。invoke系列指令出问题概率不大。

@wa-heng
Copy link
Author

wa-heng commented Jun 16, 2023

那两个const string是我加的日志,为了方便看onTouchEvent指令的开始和结束,方法内容为了排查问题,我只留了
public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}

我本来想给你一个demo,但是我测试demo是可以的,等我再排查下我的项目有什么问题再来,谢谢了

@wa-heng
Copy link
Author

wa-heng commented Jun 16, 2023

最后找到只要加混淆就有问题,不使用混淆就好了
minifyEnabled false

@maoabc
Copy link
Owner

maoabc commented Jun 16, 2023

嗯,那是混淆时导致一些代码逻辑出问题,而不是加固了。
目前加固已知的问题就是const-string有问题,但是java规范一直强调不能使用==比较字符串,所以一般忽略这种情况。性能问题最大就是数组相关操作,再就是一些指令边界判断有问题导致崩溃(一般靠跳过一些方法避免,如果能定位到具体指令就修复)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants