Android APK multi-channel verification tool-No tool, only source code is provided

Source: Internet
Author: User

The principle is based on the multi-channel packaging tool in the previous article. We use apktool to decompress the APK file to be verified, read androidmanifest. XML, and output the package when we read the channel number line.

The source code is as follows:

Main. Java

Package COM. market5577.channelverifytool; public class main {public static void main (string [] ARGs) {system. out. println ("============= code by H3C ================="); system. out. println ("= ** = channel verification tool = ** ="); If (ARGs. length! = 1) {system. out. println ("= Error = usage: Java-jar ChannelV. jar apkdirectory ==== "); system. out. println ("= info = example: Java-jar ChannelV. jar/apps ====== "); return;} string APK = ARGs [0]; splitapk sp = new splitapk (APK); SP. mysplit ();}}

Splitapk. Java

Package COM. market5577.channelverifytool; import Java. io. bufferedreader; import Java. io. file; import Java. io. filereader; import Java. io. ioexception; import Java. io. inputstreamreader; import Java. util. hashmap; public class splitapk {hashmap <string, string> qudao = new hashmap <string, string> (); // channel number, channel name string curpath; // The current folder path is string apkdirectory; Public splitapk (string directory) {This. curpath = new File (""). getabsolutepath (); this.apk directory = directory;} public void mysplit () {file dire = new file (apkdirectory); If (! Dire. exists () {system. out. println ("this file is not available"); return;} If (dire. isdirectory () {file [] sonfile = dire. listfiles (); For (File file: sonfile) {modifyxudao (file. getabsolutepath () ;}} else {modifyxudao (apkdirectory);} system. out. println ("==== over ===");}/*** apktool decompress the APK, replace the channel value ** @ throws exception */private void modifyxudao (string apkname) {// extract/C and run the specified command in the string, and then terminate string cmdunpack = "cmd. EXE/C Java-jar apktool. jar D-F-s "+ apkname; runcmd (cmdunpack); string [] apkfilepath = apkname. split ("\\\\"); string paiapkname = apkfilepath [apkfilepath. length-1]; string dir = paiapkname. split (". APK ") [0]; file packdir = new file (DIR); // obtain the decompressed APK directory string f_mani = packdir. getabsolutepath () + "\ androidmanifest. XML "; File Manifest = new file (f_mani); For (INT I = 0; I <10; I ++) {If (M Anifest. exists () {break;} Try {thread. Sleep (1000);} catch (interruptedexception e) {e. printstacktrace () ;}} if (! Manifest. exists () {system. out. println ("==== Verification Failed ====");}/** traverse the map, copy the manifese, package the modification, and sign the map, stored in the corresponding folder */bufferedreader BR = NULL; filereader Fr = NULL; string Keyline = NULL; try {Fr = new filereader (manifest); BR = new bufferedreader (FR ); string line = NULL; while (line = BR. readline ())! = NULL) {If (line. contains ("\" baidumobad_channel \ "") {// key code === I am using the Baidu statistics Tool Keyline = line ;}} catch (exception E) {e. printstacktrace (); system. out. println ("==== Verification Failed ====");} finally {try {If (fr! = NULL) {Fr. Close () ;}if (BR! = NULL) {Br. Close () ;}catch (ioexception e) {e. printstacktrace () ;}} if (Keyline! = NULL) {string TMPS [] = Keyline. split ("\\\" "); system. out. println ("read channel:" + TMPS [3]);} else {system. out. println ("==== Verification Failed, please close ====") ;}// Delete the midway through file string primary key = string. format ("cmd.exe/c rd/S/Q % s", DIR); runcmd (primary key );} /*** Run Command ** @ Param cmd */Public void runcmd (string cmd) {runtime RT = runtime. getruntime (); bufferedreader BR = NULL; inputstreamreader ISR = NULL; try {PROCESS p = Rt.exe C (CMD); // P. waitfor (); ISR = new inputstreamreader (P. getinputstream (); BR = new bufferedreader (ISR); string MSG = NULL; while (MSG = BR. readline ())! = NULL) {system. Out. println (MSG) ;}} catch (exception e) {e. printstacktrace () ;}finally {try {If (ISR! = NULL) {ISR. Close () ;}if (BR! = NULL) {Br. Close () ;}} catch (ioexception e) {e. printstacktrace ();}}}}

After the jar is generated, write a batch:

@ Echo off: Set/P Var = Please drag APK: Java-jar cverify. jar % var % Java-jar cverify. jar c: \ Users \ Harris \ Desktop \ repacktool \ apkecho. & Echo press any key to exit... & pause> nulexit

This tool supports drag-in of files and folders ~

Full text

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.