Mass APK-signer

Discussion in 'Android Hacks and Help' started by raidzero, Jul 20, 2010.

  1. raidzero
    Offline

    raidzero n00b. Theme Developer Premium Member Developer

    Joined:
    Apr 15, 2010
    Messages:
    1,054
    Likes Received:
    3
    Trophy Points:
    0
    Location:
    Denver, CO
    I made this because I wanted to sign all my apk's at once after being zipaligned. I share it because that's what I do..

    Directions: put your unsigned APK's in unsigned. run sign.bat, signed versions of apks will be in signed directory.

    Code:
    @ECHO OFF
    Title RZ Mass-APK signer
    
    
    cd unsigned 
    
    ECHO .apk's are now being signed. The signed versions will be in signed/
    echo.
    
    for /F "tokens=*" %%A in ('dir /b *.apk') do echo Now signing %%A.. && java -jar ..\signapk.jar ..\testkey.x509.pem ..\testkey.pk8 %%A ..\signed\%%A
    
    echo Done!
    
    PAUSE
    EXIT
    
    Hope it helps someone.

    Not sure where it should be posted so mods please move it where it belongs ;)


    Warning from CVPCS:

    Attached Files:

  2. Drew408
    Offline

    Drew408 New Member

    Joined:
    May 11, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    any idea on how this would be done in linux/ubuntu? any help would be greatly appreciated!
  3. raidzero
    Offline

    raidzero n00b. Theme Developer Premium Member Developer

    Joined:
    Apr 15, 2010
    Messages:
    1,054
    Likes Received:
    3
    Trophy Points:
    0
    Location:
    Denver, CO
    Not sure, I do not have a linux machine handy but it'd look something liek this:

    Code:
    #!/bin/sh
    
    
    cd unsigned 
    
    ECHO apk's are now being signed. The signed versions will be in signed/
    echo
    
     ls *.apk | awk '{print$7}' > apklist
    
    while read apk; do echo Now signing $apk.. && java -jar ../signapk.jar ../testkey.x509.pem ../testkey.pk8 $apk ../signed\$apk < apklist
    
    echo Done!
    
    the awk statement will need to be adjusted to your environment
  4. Drew408
    Offline

    Drew408 New Member

    Joined:
    May 11, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    I am pretty new to developing and Im afraid I dont know how to adjust awk...anywhere you can point me?

    From what i do know i created a script

    #!/bin/bash
    cd /unsigned
    find . -name "*.apk" -exec java -jar /home/andrew/sign/signapk.jar /home/andrew/sign/certificate.pem /home/andrew/sign/key.pk8 {} \;
    echo 'APKs signed';
    echo $?

    there are four apks in the folder and I recieve this


    Usage: signapk [-w] publickey.x509[.pem] privatekey.pk8 input.jar output.jar
    Usage: signapk [-w] publickey.x509[.pem] privatekey.pk8 input.jar output.jar
    Usage: signapk [-w] publickey.x509[.pem] privatekey.pk8 input.jar output.jar
    Usage: signapk [-w] publickey.x509[.pem] privatekey.pk8 input.jar output.jar
    APKs signed
    0

    Im thinking there is a problem with the input and output...i need to direct the -exec command to (input.apk) and (output.apk) of selected files... if that makes sense.

    I tried your script but i dont know how to set awk up

    another script was

    find . -name "*.apk" | xargs java -jar /home/andrew/sign/signapk.jar /home/andrew/sign/testkey.x509.pem /home/andrew/sign/testkey.pk8

    that didnt work neither. Thank you for the help!
  5. raidzero
    Offline

    raidzero n00b. Theme Developer Premium Member Developer

    Joined:
    Apr 15, 2010
    Messages:
    1,054
    Likes Received:
    3
    Trophy Points:
    0
    Location:
    Denver, CO

    go to the directory with the apks and do
    Code:
    ls *.apk | awk '{print$7}'
    
    see which column of data is printed,. it will be the seventh one. if that is one with the file names then it should be okay, if not, change 7 to the correct column of data.
  6. Drew408
    Offline

    Drew408 New Member

    Joined:
    May 11, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    I cd to my unsigned apk folder and perform

    ls *.apk | awk '{print$7}'
    then it returns this



    andrew@development-laptop:~/sign/unsigned$ ls *.apk | awk '{print$7}'

    andrew@development-laptop:~/sign/unsigned$

    The folder only contained one apk...the more apks i have in the folder the bigger the gap between...for example...

    andrew@development-laptop:~/sign/unsigned$ ls *.apk | awk '{print$7}'






    andrew@development-laptop:~/sign/unsigned$

    That is with six apks. something is happening but it is not showing up.

    when i manually enter your original code step by step, the terminal just hangs at a blinking cursor.
  7. raidzero
    Offline

    raidzero n00b. Theme Developer Premium Member Developer

    Joined:
    Apr 15, 2010
    Messages:
    1,054
    Likes Received:
    3
    Trophy Points:
    0
    Location:
    Denver, CO
    post your output if just
    Code:
    ls *.apk
    
    awk is used in this case to only print the seventh column of data, there may not be seven columns, so it returns nothing.
  8. Drew408
    Offline

    Drew408 New Member

    Joined:
    May 11, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    andrew@development-laptop:~/sign/unsigned$ ls *.apk
    AccountAndSyncSettings.apk
    that is with one apk


    andrew@development-laptop:~/sign/unsigned$ ls *.apk
    AccountAndSyncSettings.apk CalendarGoogle.apk ChromeToPhone.apk
    ApplicationsProvider.apk CalendarProvider.apk Contacts.apk
    BBToolkit.apk CameraGoogle.apk ContactsProvider.apk
    Bluetooth.apk CarHomeGoogle.apk DefaultContainerService.apk
    Browser.apk CarHomeLauncher.apk
    Calculator.apk CertInstaller.apk

    that is with 16 apks

    andrew@development-laptop:~/sign/unsigned$ ls *.apk | awk '{print$7}'
















    andrew@development-laptop:~/sign/unsigned$

    that is awk with 16 apks....more than 7.
    Thank you for the quick replies!
  9. raidzero
    Offline

    raidzero n00b. Theme Developer Premium Member Developer

    Joined:
    Apr 15, 2010
    Messages:
    1,054
    Likes Received:
    3
    Trophy Points:
    0
    Location:
    Denver, CO
    ooh my mistake it should be
    Code:
    ls -l *.apk | awk '{print$N}'
    
    where N is the Nth column of data printed by ls
  10. Drew408
    Offline

    Drew408 New Member

    Joined:
    May 11, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    andrew@development-laptop:~/sign/unsigned$ ls *.apk | awk '{print$0}'
    AccountAndSyncSettings.apk
    ApplicationsProvider.apk
    BBToolkit.apk
    Bluetooth.apk
    Browser.apk
    Calculator.apk
    CalendarGoogle.apk
    CalendarProvider.apk
    CameraGoogle.apk
    CarHomeGoogle.apk
    CarHomeLauncher.apk
    CertInstaller.apk
    ChromeToPhone.apk
    Contacts.apk
    ContactsProvider.apk
    DefaultContainerService.apk
    andrew@development-laptop:~/sign/unsigned$

    this is what happens when i use 0


    andrew@development-laptop:~/sign/unsigned$ ls *.apk | awk '{print$N}'
    AccountAndSyncSettings.apk
    ApplicationsProvider.apk
    BBToolkit.apk
    Bluetooth.apk
    Browser.apk
    Calculator.apk
    CalendarGoogle.apk
    CalendarProvider.apk
    CameraGoogle.apk
    CarHomeGoogle.apk
    CarHomeLauncher.apk
    CertInstaller.apk
    ChromeToPhone.apk
    Contacts.apk
    ContactsProvider.apk
    DefaultContainerService.apk
    andrew@development-laptop:~/sign/unsigned$

    this is with N...signing now...let you know
    does the 0 or N make a difference if it is giving me the same results?


    i will try fin
  11. raidzero
    Offline

    raidzero n00b. Theme Developer Premium Member Developer

    Joined:
    Apr 15, 2010
    Messages:
    1,054
    Likes Received:
    3
    Trophy Points:
    0
    Location:
    Denver, CO
    let me give an example, all I have available to me at this time is AIX (Unix)

    Code:
    # ls -l *.apk                                                                   
    total 24872                                                                
    -rw-rw-rw-   1 samba    staff        385201 Jul 27 14:36 Browser.apk       
    -rw-rw-rw-   1 samba    staff        334092 Jul 27 14:39 Camera.apk        
    -rw-rw-rw-   1 samba    staff        658509 Jul 27 14:45 Contacts.apk      
    -rw-rw-rw-   1 samba    staff        969791 Jul 22 11:46 Email.apk         
    -rw-rw-rw-   1 samba    staff        525396 Jul 10 11:59 Gallery3D.apk     
    -rw-rw-rw-   1 samba    staff        566089 Jul 27 14:11 Gmail.apk         
    -rw-rw-rw-   1 samba    staff       3059265 Jul 27 14:22 LatinImeGoogle.apk
    -rw-rw-rw-   1 samba    staff       4808120 Jul 27 14:55 Launcher2.apk     
    -rw-rw-rw-   1 samba    staff        623922 Jul 27 14:59 Mms.apk           
    -rw-rw-rw-   1 samba    staff        784213 Jul 27 14:29 Vending.apk       
    
    in my case, the file name is in the 9th column, so to get that info to a file that can be processed line by line, I use awk:

    Code:
    # ls -l *.apk | awk '{print$9}'        
    Browser.apk                            
    Camera.apk                             
    Contacts.apk                           
    Email.apk                              
    Gallery3D.apk                          
    Gmail.apk                              
    LatinImeGoogle.apk                     
    Launcher2.apk                          
    Mms.apk                                
    Vending.apk                            
    
    hope it helps

    though what you did will work for this application, my example shows how to use it correctly ;) also so you know how to take columns of data and process them
  12. Drew408
    Offline

    Drew408 New Member

    Joined:
    May 11, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    sorry for all the questions...but this is driving me crazy.
    in your case it will only sign file in column 9...or all files through column 9? I am confused because anytime I run awk with a print$ higher than one i get a bunch of blank spaces. Just to make it clear. I am trying to sign all apks within a certain folder instead of having to sign them one by one....Thank you.
  13. Drew408
    Offline

    Drew408 New Member

    Joined:
    May 11, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    wait a minute..ok its COLUMN...not ROW. in my case it is 8
  14. Drew408
    Offline

    Drew408 New Member

    Joined:
    May 11, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    ok so now that I have the column number figured out....sorry about that...when i cd to unsigned folder and use ls *.apk | awk '{print$8}' i get no results but if i do
    ls -l *.apk | awk '{print$8}' it returns all the *.apk's in the folder. when running the original script should I use the -l option?
  15. raidzero
    Offline

    raidzero n00b. Theme Developer Premium Member Developer

    Joined:
    Apr 15, 2010
    Messages:
    1,054
    Likes Received:
    3
    Trophy Points:
    0
    Location:
    Denver, CO

    yes you need the -l, if the output is not formatted awk wont even see any columns
  16. Drew408
    Offline

    Drew408 New Member

    Joined:
    May 11, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    ok cool. so here is the updated script



    #!/bin/sh


    cd ~/sign/unsigned

    echo "apk's" are now being signed.
    echo

    ls -l *.apk | awk '{print$8}' > apklist

    while read apk; do echo Now signing $apk.. && java -jar /home/andrew/sign/signapk.jar /home/andrew/sign/testkey.x509.pem /home/andrew/sign/testkey.pk8 $apk /home/andrew/sign/signed\$apk < apklist
    done
    echo Done!

    Im calling the script "a" for now... so this is what I get back in the Terminal

    andrew@development-laptop:~$ a
    apk's are now being signed.

    Then the cursor hangs with no directory just a blank space. an apklist document is created in my unsigned folder. Thats about it.
  17. raidzero
    Offline

    raidzero n00b. Theme Developer Premium Member Developer

    Joined:
    Apr 15, 2010
    Messages:
    1,054
    Likes Received:
    3
    Trophy Points:
    0
    Location:
    Denver, CO

    I don't know, I will have to load up a linux environment and try it. I will be doing that later in the week (parts for a desktop computer will be arriving on Thursday :-D)
  18. Drew408
    Offline

    Drew408 New Member

    Joined:
    May 11, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    Thanks for all your help! Update me if you figure it out. And i will research in the mean time.
Search tags for this page

apk signer

,

error: signapk.jar failed: return code 1

,
online apk signer
,
online sign apk/
,
online sign for unsigned apk
,
sign apk online
,
sign apk truc tuyen
,
signapk.jar
,
signapk.jar failed: return code 1
,
signer.apk
,

testkey.x509.pem

,
usage: signapk publickey.x509[.pem] privatekey.pk8 input.jar