Android签名工厂
随手写的一个签名程序,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;
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>