With the handwriting of a signature program, linuxlinux ((( changes to the files in the invigilator folder, you only need to change your file suffix to unsigned.apk and add it to the monitored directory to quickly sign the file.
I hope it will be useful to those who need signatures every day.
Http://weibo.com/myzoooo
C code
# 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, "javass-signed.apk", apk_path );
Printf ("signed fileName: % s \ n", apk_name );
If (child_id = 0 ){
Execl ("/usr/bin/jarsigner", "jarsigner", "-storepass", "ffly20151111","-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;
}