• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Android笔记apk嵌套

android 搞代码 3年前 (2022-03-01) 28次浏览 已收录 0个评论

a.apk-主利用 b.apk-被启动利用

次要思维:把b.apk放到assets目录下,因为有大小限度(1M),所以改名成b.mp3(因为mp3,jpg,png,mp4等不会查看,不会限度大小),而后在用的时候再改回来

1.具体实现:
public void intallApp(Context context) {
try {
String path = context.getFilesDir().getAbsolutePath()+ "/b.apk";  //从assets中解压到这个目录

File f = new File(path);
if (!f.exists()) {
f.createNewFile();
}
InputStream is = context.getAssets().open("b.mp3");//assets里的文件在利用装置后依然存在于apk文件中
inputStreamToFile(is, f);
String cmd = "chmod 777 " + f.getAbsolutePath();
Runtime.getRuntime().exec(cmd);
cmd = "chmod 777 " + f.getParent();
Runtime.getRuntime().exec(cmd);
// 尝试晋升上2级的父文件夹权限,在浏览插件下载到手机存储时,刚好用到了2级目录
// /data/data/packagename/files/这个目录上面所有的层级目录都须要晋升权限,才可装置apk,弹出装置界面
cmd = "chmod 777 " + new File(f.getParent()).getParent();
Runtime.getRuntime().exec(cmd);
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);

String type = "application/vnd.android.package-archive";
/* 设置intent的file与MimeType */
intent.setDataAndType(Uri.fromFile(f), type);
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}


public void inputStreamToFile(InputStream inputStream,File file){
///InputStream inputStream = null;
OutputStream outputStream = null;
try {
// read this file into InputStream
//inputStream = new FileInputStream("test.txt");
 
// write the inputStream to a FileOutputStream
outputStream = new FileOutputStream(file);
 
int read = 0;
byte[] bytes = new byte[1024];
 
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
 
System.out.println("Done!");
 
} catch (IOException e) {
e.printStackTrace();
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (outputStream != null) {
try {
// outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
 
}
}
}
2.如果是启动已装置的利用,实现如下:
public boolean startApp(Context context, String packageName) {
//String packageName = "XXX";
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
PackageManager pm = context.getPackageManager();
List<ResolveInfo> listInfos = pm.queryIntentActivities(intent, 0);
String className = null;
for (ResolveInfo info : listInfos) {
if (packageName.equals(info.activityInfo.packageName)) {
className = info.activityInfo.name;
break;
}
}
if (className != null && className.length() > 0) {
intent.setComponent(new ComponentName(packageName, className));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
context.startActivity(intent);
return true;
}
return false;
}

如果你晓得包名,还晓得作为启动的那activity的类名,就更简略了,就能够省掉下面查找的过程,间接启动。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Android笔记apk嵌套
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址