AutoHotkey结合 7z 和 keytool 一键查看apk文件的签名信息

网上下载的 apk,想核实是否被修改过,可以通过签名信息来查看,常规操作比较复杂,于是有了此文。

1、压缩软件打开apk,解压到临时文件夹 c:\tmp

  7z 用命令行可直接完成 7z.exe x c:\tesk.apk d:\aa.7z -oc:\tmp

2、用Java jdk自带的 keytool 查看信息。用命令行 keytool.exe -printcert -file c:\tmp\META-INF\CERT.RSA 来获取

(附上最新的jdk官方下载地址,keytool在 jdk-15\bin目录下,keytool 本想单独提取出来,简单尝试后失败了

此步骤用 AutoHotkey 执行,可直接用 msgbox 显示结果,效果如下:

 

 

 

3、删除解压的临时文件夹c:\tmp

代码如下(AutoHotkey v2 a102版):

#SingleInstance Force
;定义几个文件路径
fpApk := "c:\Users\Administrator\Desktop\tcandroid3.apk"
fp7z := "d:\AA\TC\soft\7-Zip\7z.exe"
fpKeytool := "d:\Soft\jdk-15\bin\keytool.exe"
dir := "c:\tmp" ;临时解压目录

;解压
RunWait(format("{1} x {2} -o{3}", fp7z,fpApk,dir))
;keytool 执行并返回签名信息
fpRsa := dir . "\META-INF\CERT.RSA"
res := cmdExec(format("{1} -printcert -file {2}", fpKeytool,fpRsa))
;删除临时文件夹
DirDelete(dir, 1)
;显示签名信息
msgbox(res)
return

cmdExec(strCode, callback:="", encode:="CP936")
{ ;  GAHK32 ; Modified version : SKAN 05-Jul-2013  http://goo.gl/j8XJXY
    dllcall("CreatePipe", "uintp",hPipeRead, "uintp",hPipeWrite, "uint",0, "uint",0)
    dllcall("SetHandleInformation", "uint",hPipeWrite, "uint",1, "uint",1)
    ; STARTUPINFO          http://goo.gl/fZf24
    VarSetCapacity(STARTUPINFO, 68, 0 )
    numput(68,         STARTUPINFO,  0)      ; cbSize
    numput(0x100,      STARTUPINFO, 44)      ; dwFlags    =>  STARTF_USESTDHANDLES = 0x100
    numput(hPipeWrite, STARTUPINFO, 60)      ; hStdOutput
    numput(hPipeWrite, STARTUPINFO, 64)      ; hStdError
    ; PROCESS_INFORMATION  http://goo.gl/b9BaI
    VarSetCapacity(PROCESS_INFORMATION, 16)
    if !dllcall("CreateProcess", "uint",0, "uint",&strCode, "uint",0, "uint",0, "uint",1, "uint",0x08000000, "uint",0, "uint",0, "uint",&STARTUPINFO, "uint",&PROCESS_INFORMATION)
    { ;http://goo.gl/USC5a
        dllcall("CloseHandle", "uint",hPipeWrite)
        dllcall("CloseHandle", "uint",hPipeRead)
        dllcall("SetLastError", "int",-1)
        return ""
    }
    hProcess := numget(PROCESS_INFORMATION, 0)
    hThread := numget(PROCESS_INFORMATION, 4)
    dllcall("CloseHandle", "uint",hPipeWrite)
    VarSetCapacity(Buffer, 4096, 0), nSz := 0
    while(dllcall("ReadFile", "uint",hPipeRead, "uint",&Buffer, "uint",4094, "uintp",nSz, "uint",0))
    {
        sThis := strget(&Buffer, nSz, encode)
        sRes .= sThis
        if isobject(callback)
            callback.call(A_Index,sThis)
    }
    dllcall("GetExitCodeProcess", "uint",hProcess, "uintp",ExitCode)
    dllcall("CloseHandle", "uint",hProcess )
    dllcall("CloseHandle", "uint",hThread  )
    dllcall("CloseHandle", "uint",hPipeRead)
    dllcall("SetLastError", "uint",ExitCode)
    return isobject(callback) ? callback.call(0,sRes) : sRes
}

 

posted @ 2020-10-19 23:22  火冷  阅读(508)  评论(0编辑  收藏  举报