Android簽名工廠

來源:互聯網
上載者:User

隨手寫的一個簽名程式,Linux核心監聽(監聽檔案夾內檔案的變化),只要將你的檔案尾碼改成unsigned.apk放入到監聽的目錄即可快速簽名。

希望對需要天天簽名而煩惱的人有用哈。

 

 http://weibo.com/myzoooo

 

C代碼

#include <unistd.h> 

#include <sys/inotify.h> 

#include <stdio.h> 

#include <string.h> 

 

#define MAX_BUF_SIZE 1024 

#define CHECK_PATH "/home/ffly/Desktop" 

 

int check_name(char *apk_name); 

int sign_apk(char *apk_name,char *apk_path); 

 

int check_dir(char *path) 

    int fd, wd; 

    int len, index; 

    char buffer[MAX_BUF_SIZE]; 

    struct inotify_event *event; 

    fd = inotify_init(); 

    if(fd < 0){ 

        printf("Failed to initialize inotify.\n"); 

        return 1; 

    } 

    wd = inotify_add_watch(fd, path,IN_CLOSE_WRITE | IN_MOVED_TO); 

    if(wd < 0){ 

        printf("Can't add watch for %s", path); 

        return 1; 

    } 

    while(len = read(fd, buffer, MAX_BUF_SIZE)){ 

        index = 0; 

        while(index < len){ 

            event = (struct inotify_event *)(buffer+index); 

            if(event->wd != wd) 

                continue; 

            if((event -> mask & IN_CLOSE_WRITE) || (event -> mask & IN_MOVED_TO)){ 

        int boolean; 

        char pathbuff[512]; 

        boolean = check_name(event->name); 

        sprintf(pathbuff,"%s/%s",CHECK_PATH,event->name); 

        if(boolean){ 

            sign_apk(event->name,pathbuff); 

        } 

        } 

            index += sizeof(struct inotify_event)+event->len; 

        } 

    } 

    return 0; 

 

int check_name(char *apk_name){ 

    int len,fix_len,idx,j,count; 

    char a,b; 

    char fix[] = "unsigned.apk"; 

    len = strlen(apk_name); 

    fix_len = strlen(fix); 

    count =0; 

    if(len<=fix_len) 

        return 0; 

    for(idx = len-fix_len,j = 0;idx<len;idx++,j++){ 

 

        a = apk_name[idx]; 

        b = fix[j]; 

        if(a == b){ 

            count++; 

        }else{ 

            count =0; 

            j=0; 

        } 

         if(count == fix_len) 

                   return 1; 

    } 

    return 0; 

 

int sign_apk(char *apk_name,char *apk_path){ 

    pid_t child_id; 

    child_id  = fork(); 

    char new_path_buf[512]; 

    sprintf(new_path_buf,"%s-signed.apk",apk_path); 

    printf("signed fileName:%s\n",apk_name); 

 

    if(child_id==0){  

        execl("/usr/bin/jarsigner","jarsigner","-storepass","ffly20110811","-keystore","/home/ffly/bin/lib/signapk_key/ffly.keystore","-signedjar",new_path_buf,apk_path,"ffly.keystore",(char *)0); 

    } 

     

    return 0; 

 

int main(){ 

    check_dir(CHECK_PATH); 

    return 0; 

}   

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.