[Open source] Android apk One-click Generate confusing File script sharing (Python)

Source: Internet
Author: User


There is a need for the project to be done today. To confuse our apk.

Then spent an afternoon studying, and Python wrote a one-click generated script.




Principle:

My development environment is that ADT Bundle is an integrated development environment for the Android SDK with Proguard.


You only need to export the code when you open the comment in project.properties.

Then choose Export exported apk will be automatically confused,Proguard default is to confuse all the code, but this often causes some problems.


The focus is on the preparation of confusion rules. Sum up on three articles:

1 Android comes with Class library can not be confused

2 third-party jars cannot be confused

3 Do not confuse yourself with the reflected part


The script will help you complete the first and second steps.

The main is to use your third-party package, automatically scan the third-party jar inside the package name, and then generate rule statements, avoid confusion.

When using, you need to put

"D:\workspace\Family\libs"

Replace the Libs directory with your own Android app.

Then you can run it with one click. The resulting file is the tt.txt of the E-packing directory by default.


When you're done, manually add the code that you need to avoid confusing (if any).

Then copy the generated text into "Proguard-project.txt" and it's OK.




The code is as follows:


#coding =utf-8 "Created on 2015-05-19 @author: From childhood" Import Osimport zipfile def getfilelist (dir, fileList): Newdir = Dir if Os.path.isfile (dir): Filelist.append (dir) elif Os.path.isdir (dir): for S in Os.listdir (dir)                : #如果需要忽略某些文件夹, use the following code #if s = = "xxx": #continue if S.endswith (' jar '): Newdir=os.path.join (dir,s) getfilelist (Newdir, fileList) else:contin UE return FileList list = getfilelist (' D:\workspace\Family\libs ', []) PackageName Set = Set () F = open (' E:/tt.txt ', ' w+ ') # writes a relatively fixed profile f.write (' #设置混淆压缩比率 0-7 ' + ' \ n ') f.write ('-optimizationpasses 5 ' + ' \ n ') f . Write ('-dontusemixedcaseclassnames ' + ' \ n ') f.write ('-dontskipnonpubliclibraryclasses ' + ' \ n ') f.write ('- Dontpreverify ' + ' \ n ') f.write ('-verbose ' + ' \ n ') #进行优化, I don't know very well, what does it mean F.write ('-optimizations!code/simplification/ arithmetic,!field/*,!class/merging/* ' + ' \ n ') F.write ('-keepattributes sourcefile,linenumbertable ' + ' \ n ') f.write (' #不混淆四大组件 ' + ' \ n ') f.write ('-keep public class * extends Android.app.Activity ' + ' \ n ') f.write ('-keep public class * extends android.app.Application ' + ' \ n ') f.write ('-keep public Class * extends Android.app.Service ' + ' \ n ') f.write ('-keep public class * extends Android.content.BroadcastReceiver ' + ' \ n ') f.write ('-keep public class * extends Android.content.ContentProvider ' + ' \ n ') f.write ('-keep public class * extends Android Oid.app.backup.BackupAgentHelper ' + ' \ n ') f.write ('-keep public class * extends android.preference.Preference ' + ' \ n ') F.write ('-keep public class Com.android.vending.licensing.ILicensingService ' + ' \ n ') # below is the function part f.write (' #不混淆一些特殊函数 ' + ' \ n ') f.write ('-keepclasseswithmembernames class * {' + ' \ n ') f.write (' native <methods>; ' + ' \ n ') f.write ('} ' + ' \ n ') F.write ('-keepclasseswithmembers class * {' + ' \ n ') f.write (' Public <init> (Android.content.Context, Android.util.AttributeSet), ' + ' \ n ') f.write ('} ' + ' \ n ') F.writE ('-keepclasseswithmembers class * {' + ' \ n ') f.write (' Public <init> (Android.content.Context, Android.util.AttributeSet, int), ' + ' \ n ') f.write ('} ' + ' \ n ') f.write ('-keepclassmembers class * extends android.app.Activity {' + ' \ n ') f.write (' public void * (Android.view.View); ' + ' \ n ') f.write ('} ' + ' \ n ') f.write ('- Keepclassmembers enum * {' + ' \ n ') f.write (' public static **[] values (); ' + ' \ n ') f.write (' public static * * VALUEOF (Java.lan g.string), ' + ' \ n ') f.write ('} ' + ' \ n ') f.write ('-keep class * implements Android.os.Parcelable {' + ' \ n ') f.write (' Public St        atic final Android.os.parcelable$creator *; ' + ' \ n ') f.write ('} ' + ' \ n ') f.write (' #第三方jar包的不混淆配置 ' + ' \ n ') for E in list:    Prepos = E.rfind ("\ \") Jarfile = E[prepos + 1:] strtagfile = '-libraryjars libs/' + jarfile # write Libraryjars F.write (strtagfile + ' \ n ') # remains without confusing print (strtagfile) # calculation package Name strpackagename = "" Z=zipfile. ZipFile (' D:\workspace\Family\libs ' + ' \ \ ' +jarfile) names=z.namelist () # Add theThere is a class name path to the collection #listPackage. Update (Names[0:2]) for name in names: #listItem = name if Name.endswith (' cl               "): #print (name) name = Name[:name.rfind ('/')] ListItem = Name.replace ('/', '. ')              LISTITEM2 = Listitem[:listitem.rfind ('. ')]              #listItem = listitem[:] Packagenameset.add (LISTITEM2) #获取到一个合法的包名, but the meaningless part needs to be removed, then put into the function to detect in this collection #print (LISTITEM2) # writes the parameter of the not confusing part #遍历经过计算的结果得出for Packname in packagenameset: #packname = Packnam    e[:p ackname.rfind ('. ')] Print (packname) strtagfile = "-dontwarn" + Packname + ". * *" f.write (strtagfile + ' \ n ') Strtagfile = "-keep C    Lass "+ Packname +". **{*;} "                                 F.write (strtagfile + ' \ n ') #print (Packagenameset) f.close ()






Ps:python language is really good for lazy people like me.




The text/from childhood


QQ Group Program Life 241300694

Website: www.dqqdo.com

Watercress Address: http://www.douban.com/people/zmobs/




[Open source] Android apk One-click Generate confusing File script sharing (Python)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.