❶ android项目里如何混淆自己打的jar包或者防止被反编译
Android之防止反编译技巧:
1. 判断程序是否运行在模拟器上
boolean isRunningInEmualtor() {
boolean qemuKernel = false;
Process process = null;
DataOutputStream os = null;
try{
process = Runtime.getRuntime().exec("getprop ro.kernel.qemu");
os = new DataOutputStream(process.getOutputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream(),"GBK"));
os.writeBytes("exit\n");
os.flush();
process.waitFor();
// getprop ro.kernel.qemu == 1 在模拟器
// getprop ro.proct.model == "sdk" 在模拟器
// getprop ro.build.tags == "test-keys" 在模拟器
qemuKernel = (Integer.valueOf(in.readLine()) == 1);
Log.d("com.droider.checkqemu", "检测到模拟器:" + qemuKernel);
} catch (Exception e){
qemuKernel = false;
Log.d("com.droider.checkqemu", "run failed" + e.getMessage());
} finally {
try{
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {
}
Log.d("com.droider.checkqemu", "run finally");
}
return qemuKernel;
}
2. 检测keystore签名,再与之前得做比较
public int getSignature(String packageName) {
PackageManager pm = this.getPackageManager();
PackageInfo pi = null;
int sig = 0;
try {
pi = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
Signature[] s = pi.signatures;
sig = s[0].hashCode();
} catch (Exception e1) {
sig = 0;
e1.printStackTrace();
}
return sig;
}
3. 检测包名,版本名和版本号,然后做判断:
private String getAppInfo() {
try {
String pkName = this.getPackageName();
String versionName = this.getPackageManager().getPackageInfo(
pkName, 0).versionName;
int versionCode = this.getPackageManager()
.getPackageInfo(pkName, 0).versionCode;
return pkName + " " + versionName + " " + versionCode;
} catch (Exception e) {
}
return null;
}
4. 把jpg图片写成是png格式得图片 但是最新版本的apktool已经修复了
5. 花指令,影响jd-gui 但是最新版本的jd-gui已经修复
private static final char[] wJ = "0123456789abcdef".toCharArray();
public static String imsi = "204046330839890";
public static String p = "0";
public static String keyword = "电话";
public static String tranlateKeyword = "%E7%94%B5%E8%AF%9D";
在每个类里面加入 如上字段。。。。
https://***/ 一个第三方得”爱加密“网站 1.需要使用官方的打包key工具打包后上传到"爱加密"网站进行处理,然后到网站上面下载,下载后还要用"爱加密"的打包工具再次进行打包即可。
❷ android源码被混淆了怎么还原
android源码被混淆了还原方法为:
1、得到 classes.dex文件;直接用机器上的解压软件 打开 .apk 文件,解压出 classes.dex 文件。
2、还原.jar文件;这一步需要用到一个工具 dex2jar (谷歌的代码库里有http://code.google.com/p/dex2jar/)下载完了,解压,然后把第一步的 产物(即那个classes.dex文件)放到 dex2jar的解压目录(解压目录里 有 dex2jar.bat 文件,检查一下,没有的话说明目录不对)。
3、查看.jar文件;这一步就是传统的 反编译 了,需要工具辅助,这里用到的工具是jd-gui(http://java.decompiler.free.fr/?q=jdgui)下载系统对应的版本,解压,(xp系统)会看到一个 .exe文件,没错就是 单文件绿色版,双击,选择 第二步 生成的 .jar,即可。
❸ 我把android.jar包进行反编译,为什么只有方法而没有实现
1、混淆安卓自带了混淆法,具体请网络关键词:proguard,但是混淆只是加大了反编译的难度,可以这么说,即便混淆了,只要有足够的耐心,破解指日可待。2、使用linux的静态链接so库这类似于windows平台的dll库,如果使用了so库,那么这个安卓程序几乎不可能被反编译到原来的代码,所以,重要的代码可以放入so库。但是,道高一尺,魔高一丈,即便是so库,也还是会有法能破解,但是,要获得真正的源码,几乎不可能无源代码的安卓APK反编译、修改,只有你想不到,没有做不到@@724949472
❹ android 怎么实现只混淆自己的代码,而不混淆第3方jar包
1. 新建一个工程会看到项目下边有这样proguard-project.txt一个文件,这个对混淆代码很重要,如果不小心删掉了,没关系,从其他地方拷贝一个过来
2. 最重要的就是在proguard-project.txt添加混淆的申明了:
a. 把所有的jar包都申明进来,例如:
-libraryjars libs/apns_1.0.6.jar
-libraryjars libs/armeabi/libBaiMapSDK_v2_3_1.so
-libraryjars libs/armeabi/liblocSDK4.so
-libraryjars libs/mapapi_v2_3_1.jar
-libraryjars libs/core.jar
-libraryjars libs/gesture-imageview.jar
-libraryjars libs/gson-2.0.jar
-libraryjars libs/infogracesound.jar
-libraryjars libs/locSDK_4.0.jar
-libraryjars libs/ormlite-android-4.48.jar
-libraryjars libs/ormlite-core-4.48.jar
-libraryjars libs/universal-image-loader-1.9.0.jar
b. 将你不需要混淆的部分申明进来,因为有些类经过混淆会导致程序编译不通过,如下:
-keep public class * extends android.app.Fragment
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class * extends android.support.v4.**
-keep public class com.android.vending.licensing.ILicensingService
--以上都是API里边的类,最好都要避免混淆
有些很特殊的,例如网络地图,你需要添加以下申明:
-keep class com..** { *; }
-keep class vi.com.gdi.bgl.android.**{*;}
根据我的经验,一般model最好避免混淆(model无关紧要,不混淆也没多大关系)如:
-keep class com.bank.pingan.model.** { *; }
下面在贴上关于Umeng分享统计的避免混淆的申明
-dontwarn android.support.v4.**
-dontwarn org.apache.commons.net.**
-dontwarn com.tencent.**
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclasseswithmembers class * {
public <init>(android.content.Context);
}
-dontshrink
-dontoptimize
-dontwarn com.google.android.maps.**
-dontwarn android.webkit.WebView
-dontwarn com.umeng.**
-dontwarn com.tencent.weibo.sdk.**
-dontwarn com.facebook.**
-keep enum com.facebook.**
-keepattributes Exceptions,InnerClasses,Signature
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep public interface com.facebook.**
-keep public interface com.tencent.**
-keep public interface com.umeng.socialize.**
-keep public interface com.umeng.socialize.sensor.**
-keep public interface com.umeng.scrshot.**
-keep public class com.umeng.socialize.* {*;}
-keep public class javax.**
-keep public class android.webkit.**
-keep class com.facebook.**
-keep class com.umeng.scrshot.**
-keep public class com.tencent.** {*;}
-keep class com.umeng.socialize.sensor.**
-keep class com.tencent.mm.sdk.openapi.WXMediaMessage {*;}
-keep class com.tencent.mm.sdk.openapi.** implements com.tencent.mm.sdk.openapi.WXMediaMessage$IMediaObject {*;}
-keep class im.yixin.sdk.api.YXMessage {*;}
-keep class im.yixin.sdk.api.** implements im.yixin.sdk.api.YXMessage$YXMessageData{*;}
-keep public class [your_pkg].R$*{
public static final int *;
}
3.以上工作完成,混淆工作就完成了一大半了,最后需要做的就是在project.properties文件中加上混淆文件申明了,如下
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
4. OK, 最后一步,打签名包测试,如果有问题,仔细看下Log也许有得类不能混淆,那么你得加入到proguard-project.txt文件中
-------以上就是混淆代码的全过程了
❺ android ant混淆编译打包生成jar文件,如何将jni生成的lib**.so库文件同时打包
在混淆配置文件中添加这句
-keepclasseswithmembernames class * {
native <methods>;
}
❻ 如何让用Android studio 导出jar包并混淆和aar
首先说明我使用的android studio
版本是0.4.因为现在android studio的bug还不较多,所以你的版本能不能正常使用我就不敢说了。
如果你只是单纯的想使用actionbarsherlock的话,引用是十分简单的dependencies {
// compile fileTree(dir: 'libs', include: '*.aar')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile 'com.android.support:support-v4:18.0.+'
}
不过官方也出了一个兼容包,也非常的不错。so 没必要非得要使用actionbarsherlock。
然后重新编译一下项目就行了。(ps
引用第三方jar包,请看我的第一行注释,你只要新建一个libs的文件夹,然后把想要jar包复制到文件夹下,接着把注释那句复制到build文件中,修改一下(*.aar
-> *.jar)就可以了)。
但是我们要是使用本地的自定义的aar文件,请看我的实现过程,如果你有更好的请转告小弟共同进步
第一步 :生成aar文件
我的方法是通过maven-android-plugin来生成的,如果你使用过actionbarsherlock以前的版本的话,这个工具应该不陌生,如果你连maven
都不知道的话,建议好好学习一下maven,虽然现在gradle很火 ,但是我还是最喜欢maven。
关于具体生成步骤不久不详细说了,文章最后贴出几个网址供大家学习使用,放心我按顺序给你们,只要一步一步的来绝对能成功
1 把你的maven版本提升到3.1.1
2 去github上clone下来
maven-android-sdk-deployer 这个项目
3 通过maven-android-plugin生成一个android项目
mvn archetype:generate \
-DarchetypeArtifactId=android-quickstart \
-DarchetypeGroupId=de.akquinet.android.archetypes \
-DarchetypeVersion=1.0.11 \
-DgroupId=your.company \
-DartifactId=my-android-application
如果不能够编译我们可能要修改一下pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.lee.study.android</groupId>
<artifactId>NiMa</artifactId>
<version>0.0.1</version>
<packaging>aar</packaging>
<name>NiMa</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<platform.version> 4.1.1.4
</platform.version>
<android.plugin.version>3.8.0</android.plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>${android.plugin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<platform>16</platform>
<path>E:\android_work\sdk\</path>
</sdk>
</configuration>
</plugin>
</plugins>
</build>
</project>
上面都是我的pom,修改了打包类型和插件版本以及添加了sdk位置。
然后执行打包命令,就可以生成aar文件了,如果你是已经有写好的类库的话,可以尝试这修改成maven形式的。
第二步
导入到android studio中 创建libs文件夹,放入想要导入的文件
1 修改build.gradle ,依然是给出我的大家可以按照自己的项目对比修改
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenLocal()
mavenCentral()
flatDir {
dirs 'libs'
}
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 18
}
}
dependencies {
// compile fileTree(dir: 'libs', include: '*.aar') compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile 'com.jayway.maven.plugins.android.generation2.samples.libraryprojects:aar-lib1:1.0.0@aar'
//compile 'com.lee.study.android:NiMa:0.0.1@aar' compile 'com.android.support:support-v4:18.0.+'
}
android {
compileOptions.encoding = "UTF-8"
}
repositories
添加了 flatDir , dependencies 里面添加了 依赖的aar文件。
如果你做到这一步,重新编译一下依赖就添加好了,我目前的版本添加完了aar访问aar中的资源文件是不成问题的,但是不能访问到aar中的
类文件。如果你和我一样不幸的话,请看下一步
2 手动的添加class.jar文件到android -studio
选中项目F4 ,可以查看到详细的依赖关系
❼ Android第三方类库中的jar包不被混淆
假如你的项目中有这样一个image类库, 打开image类库下的build.gradle文件,查看里面有哪些 引用包 ,如果lib里面也有包, lib中的也需要查看
假如现在,让 最后一个" compile'com.blankj:utilcode:1.9.8 '" 不被混淆
打开图中的 External Libraries 文件, 我们导入的所有的第三方jar包都在里面
找到" compile'com.blankj:utilcode:1.9.8 '"
查看包名,在混淆文件中添加
所有的jar包都依次写上 -keep class "jar包名" ,就ok了
--注意事项--
1.保证实体类不被混淆
2.保证第三方的jar包不被混淆,类似于,友盟,地图,等等,配置的时候,就把混淆文件也过来,免得再回去找
3.添加基础混淆配置,网上有很多的实例
################ 以下直接到 proguard-rules.pro文件中,实体类,第三方部分,需修改####################
❽ 如何使用Android Studio打包混淆的Jar
使用AS打包混淆Jar包,网络一下,一片一片的,但是很多都是零零散散的写得不是很详细或是直接拷贝,按照他们的教程测试总不是很顺利,所以这里我就把我个人学习AS打包混淆Jar的成果总结出来,希望对大家有帮助。个人觉得写得还是比较详细的
使用gradle混淆打包Jar
使用AS开发项目,引入第三方库是非常方便的,我们只需要在build.gradle中配置一行代码就可以轻松引入我们需要的开发库。那么gradle可以帮我们混淆打包Jar吗?答案是当然可以!
那么我们如何打包Jar呢?其实我们在编译项目的时候,AS已经帮我们在目录build/intermediates/bundles/release/classes.jar打好了Jar。那么我们需要做的就是把Jar进行混淆的工作了。这里以个人项目bannerDemo为例,混淆步骤如下:
在你的library的build.gradle文件中加入如下代码:
task makeJar(type: proguard.gradle.ProGuardTask, dependsOn: "build") {
// 未混淆的jar路径
injars 'build/intermediates/bundles/release/classes.jar'
// 混淆后的jar输出路径
outjars 'build/outputs/cocolove2-banner-1.1.0.jar'
// 混淆协议
configuration 'proguard-rules.pro'}
配置混淆协议
1.我们先把AS自带的协议配置进来中文注释,笔者添加
# This is a configuration file for ProGuard.# http://proguard.sourceforge.net/index.html#manual/usage.html## Starting with version 2.2 of the Android plugin for Gradle, these files are no longer used. Newer# versions are distributed with the plugin and unpacked at build time. Files in this directory are# no longer maintained.#表示混淆时不使用大小写混合类名-dontusemixedcaseclassnames#表示不跳过library中的非public的类-#打印混淆的详细信息-verbose# Optimization is turned off by default. Dex does not like code run# through the ProGuard optimize and preverify steps (and performs some# of these optimizations on its own).-dontoptimize##表示不进行校验,这个校验作用 在java平台上的-dontpreverify# Note that if you want to enable optimization, you cannot just# include optimization flags in your own project configuration file;# instead you will need to point to the# "proguard-android-optimize.txt" file instead of this one from your# project.properties file.-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService-keep public class com.android.vending.licensing.ILicensingService# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native-keepclasseswithmembernames class * {
native <methods>;
}# keep setters in Views so that animations can still work.# see http://proguard.sourceforge.net/manual/examples.html#beans-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}# We want to keep methods in Activity that could be used in the XML attribute onClick-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}# The support library contains references to newer platform versions.# Don't warn about those in case this app is linking against an older# platform version. We know about them, and they are safe.-dontwarn android.support.**# Understand the @Keep support annotation.-keep class android.support.annotation.Keep-keep @android.support.annotation.Keep class * {*;}-keepclasseswithmembers class * {
@android.support.annotation.Keep <methods>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <init>(...);
}
2.AS自带的配置文档还是不够的,我们还需要加入如下配置
这里只展示基本操作,在实际开发中可能需要更多依赖,要根据具体情况引入自己需要的依赖包
#下面代码中的xx是指我个人的配置路径,涉及个人信息,这里以xx代替
#引入依赖包rt.jar(jdk路径)
-libraryjars /xxx/xx/xx/jdk1.8.0_77.jdk/Contents/Home/jre/lib/rt.jar
#引入依赖包android.jar(android SDK路径)
-libraryjars /xx/xx/xx/Android/sdk/platforms/android-24/android.jar
#如果用到Appcompat包,需要引入
-libraryjars /xxx/xxx/xx/xxx/MyApplication/library-banner/build/intermediates/exploded-aar/com.android.support/appcompat-v7/24.1.1/jars/classes.jar
-libraryjars /xx/xx/xx/xx/MyApplication/library-banner/build/intermediates/exploded-aar/com.android.support/support-v4/24.1.1/jars/classes.jar
#忽略警告
-ignorewarnings
#保证是独立的jar,没有任何项目引用,如果不写就会认为我们所有的代码是无用的,从而把所有的代码压缩掉,导出一个空的jar
-dontshrink
#保护泛型
-keepattributes Signature
3.加入自己不想混淆的配置根据实际需求配置
-keep class com.cocolove2.library_banner.view.**{*;}
在命令行执行命令混淆Jar,提示BUILD SUCCESFUL表示成功!
//mac./gradlew makeJar//windowsgradlew makeJar
示例展示
我这里以混淆library-banner库为例
1.首先我们要看看下我们的buildTool的配置,如下图:
混淆报错解决办法个人遇到的
proguard5.2.1下载地址
阅读