Nodejs parsing apk

Source: Internet
Author: User
Tags unpack

Catalog on Project re-github: Https://github.com/chen2009277025/nodejs_apkTool

Nodejs is understandable is the emerging back-end language, because his development language is the Javascript,javascript language of their own advantage, let Nodejs rapid fire across the river.

A lot of Nodejs development plug-in springing up, such as the file operation of the FS, the database to solve the link of various middleware, MySQL, Mongoose and so on.

But for now I haven't found out about Nodejs parsing apk, which is not very popular, but for some projects this need is really important. In fact, the need to install a good Java environment, at least java1.6.

Android will have a library file is used to read the APK signature and information library, and what we have to do here is to use Nodejs to call these library files, these operations into a sub-operation, the use of people only need to care how to interact with our middleware to get the data they want, Without needing to care about what was done in the middle.

The general apk is compressed in a certain compression format, we can use the extension of the apk suffix to rar or zip or even tar.gz and then extract the image inside the static resource file.

However, the Applicationcontext.xml file is not visible at this time, or the class file inside it can not be seen.


This apktool is useful at this time:


Nodejs_apktool is a tool written in Nodejs for apk processing.

1. Can read the APK to read the signature, the apk inside the Appkey,appid,

2. Can unpack APK, package

3. Can write to the specified Appid,appkey

Use:


Apktoolpath: This is the absolute path to your project, such as:/users/chenjianhui/node_apktool,node_apktool is my project name

Sign: Is the project want to hit the inside of the APK signature, the signature is a company-related files, the creation of this file can go to the major search engines can search how to generate

Sign_path: Signed path, System absolute path

Sign_password: Signed password to prevent someone from decrypting your password

Sign_align: Signature aliases, which are set when you create a signature

Apktool's setting

Apktool.settings = {

Apktoolpath: "",

Sign: {

Sign_path: "",

Sign_password: "",

Sign_align: ""

}

};


See the code in my test case for specific use

/** * created by chen on 15-7-30. */var apktool = require (".. /index ") Var fs = require (" FS ");apktool.settings.apktoolpath = "/Users/chenjianhui/ Webstormprojects/node_apktool ";//unpack apk//extract apk package Apktool.apktool_unpack ("/users/chenjianhui/documents/ apktest/pet.apk ","/users/chenjianhui/documents/apktest ", Function (Err,result) {         if (Err) {Console.log ("error:" +err);}         console.log (Result)});/*//pack apk//packaging Apkapktool.apktool_ Pack ("/home/chen/youyuan_test", "/home/chen/youyuan_unsign.apk", function (Err,result) {    if (ERR) {Console.log ("error:" +err);}     console.log (Result)}); *///here are the parameters that need to be written to the APK, such as channel number, version number, Appkey,appid, and so on//var params  = {//    channel_name: "Com_channel_bs",//    channel_val: " Default ",//    permissioNs:[],//    appkey_name: "Com_appkey_bs",//    appkey: ",//     appid_name: "Com_appid_bs",//    appid: "//}////apktool.handle_manifest ("/home/ Chen/youyuan_test ", Params,function (Err,result) {//        if (err) { Console.log (err);}         console.log (Result)//})/*//read the version information in the APK//This method is useful, Because by going to applicationcontext.xml inside to find version number is a very unscientific approach,//and may not be able to find apktool.getversionofapk ("/home/chen/youyuan_test", function (Err,result) {}) *//* to re-sign the APK, sign the APK into its own apk, the APK is its own apktool.resigned_apk ("/home/chen/youyuan_ unsign.apk ","/home/chen/youyuan_sign.apk ","/home/chen/android.keystore "," Haoxin "," Android ", function (Err,result ) {    if (err) {        console.log (err);         logger.writeerr (ERR);         return;  &nbsP; }    console.log (result);}); *//*//Read Signature Apktool.readsign ("/home/chen/youyuan_sign.apk", function (Err,result) {    if (err) { Logger.writeerr (err); return;}     console.log (result);     console.log (result.data.MD5);     console.log (result.data.SHA1);     console.log (result.data. owner);}) *//* This is the decompression configuration, Var pack_param = {    unpack_folder: "/home/chen/haoxin_test",  //Extract directory     desi_dir: "/home/chen/haoxin_2"   //compression target};// It's something you need to wear. Channel number and version good information var manifest_param = {    channel_name: "Com_channel_bs" ,     channel_val: "Default",    permissions:[],     Appkey_name: "Com_appkey_bs",     appkey: "1231",     appid_name: "COM_ Appid_bs ",     appid:" 12121 "};VAR SIGN_PARAM =&NBsp {    sign_file: "/home/chen/android.keystore",     password: "Haoxin",     sign_align: "Android"}apktool.handle_apk ("/home/chen/youyuan.apk", Pack_param,manifest_ Param,sign_param,function (Err,result) {    if (err) {Console.log (err); return;}     console.log (result);     console.log ( result.data["owner");}) */////var path =  "/home/chen";////console.log (Fs.existssync (path));////get MD5, this is get apk  MD5 method//apktool.getmd5 ("/users/chenjianhui/documents/apktest/pet.apk", Function (Err,result) {//     if (Err)//    {//        console.log ( ERR);//        return;//    }//     console.log (result);//})

There is also room to modify, such as our apk needs permissions, due to the time of the problem, I did not give the tool to add or remove permissions to the function,

If it is possible to write this function as a Web, users upload the apk directly, manually enter the channel number of their own product ID and other information, manually select the required permissions, you can download the signature of their own apk

This article is from the "Silent Chen Gui" blog, please make sure to keep this source http://snaile.blog.51cto.com/8061810/1727234

Nodejs parsing apk

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.