❶ 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下載地址
閱讀