Skip to content

Commit

Permalink
fix signature verification & simplify command capture
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
1024mb committed Jun 23, 2024
1 parent 4aa02a2 commit eccf701
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 38 deletions.
65 changes: 27 additions & 38 deletions Application-source/APK-Info.au3
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_Res_Comment=Shows info about Android Package Files (APK/APKS)
#AutoIt3Wrapper_Res_Description=APK-Info
#AutoIt3Wrapper_Res_Fileversion=1.39
#AutoIt3Wrapper_Res_Fileversion=1.40
#AutoIt3Wrapper_Res_LegalCopyright=NONE
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#pragma compile(AutoItExecuteAllowed True)
Expand Down Expand Up @@ -1168,6 +1168,16 @@ EndFunc ;==>_Run

Func _RunBatch($label, $cmd, $name)
ProgressSet(0, $label & '...')
If $bIsAPKS Then
If not FileExists($sAPKSTempPath) Then
DirCreate($sAPKSTempPath)
EndIf
Else
If not FileExists($tempPath) Then
DirCreate($tempPath)
EndIf
EndIf

If $bIsAPKS Then
RunWait($cmd & ' > "' & $sAPKSTempPath & '\' & $name & '.txt" 2>&1', $ScriptDir, @SW_HIDE)
Else
Expand Down Expand Up @@ -1209,14 +1219,8 @@ EndFunc ;==>_LoadSignature
Func _getSignature($prmAPK, $load)
$output = ''
If $load == 1 Then
_RunBatch('apksigner', @ComSpec & ' /C ' & $sAPKSignerPath & ' verify --v --print-certs "' & $prmAPK & '"', "apksigner")
If $bIsAPKS Then
$output = FileRead($sAPKSTempPath & '\apksigner.txt')
FileDelete($sAPKSTempPath & '\apksigner.txt')
Else
$output = FileRead($tempPath & '\apksigner.txt')
FileDelete($tempPath & '\apksigner.txt')
EndIf
$process = _Run('apksigner', $sAPKSignerPath & ' verify --v --print-certs "' & $prmAPK & '"', $STDERR_CHILD + $STDOUT_CHILD)
$output &= StringStripWS(_readAll($process, 'apksigner'), $STR_STRIPLEADING + $STR_STRIPTRAILING) & @CRLF

If $output == '' Or StringInStr($output, 'java.lang.UnsupportedClassVersionError') Or StringInStr($output, 'Unsupported major.minor version') Then
$output = $strNeedJava & @CRLF & @CRLF & $output
Expand Down Expand Up @@ -2077,34 +2081,19 @@ Func _adb()
EndIf
EndFunc ;==>_adb

Func _readAll($process, $error, $stdout = True)
ProgressSet(0, $error & '...')
$output = ''
$max = 32 * 1000
$timeout = TimerInit()
$timer = TimerInit()
$last = 0
While 1
$time = TimerDiff($timeout)
If $time > $max Then ExitLoop
If $stdout Then
$bin = StdoutRead($process, False, True)
Else
$bin = StderrRead($process, False, True)
EndIf
If @error Then ExitLoop
If StringLen($bin) > 0 Then
$timeout = TimerInit()
$output &= BinaryToString($bin, $SB_UTF8)
Else
$check = Round(TimerDiff($timer) / 500)
If $check <> $last Then
$last = $check
ProgressSet($time * 100 / $max, $error & '... ' & Round($time / 1000))
EndIf
EndIf
WEnd
ProgressSet(100, $error & '... OK')
Func _readAll($process, $title, $stdout = True)
ProgressSet(0, $title & "...")
ProcessWaitClose($process, 600)
$output = ""
If $stdout Then
$bin = StdoutRead($process, False, True)
Else
$bin = StderrRead($process, False, True)
EndIf

$output &= BinaryToString($bin, $SB_UTF8)

ProgressSet(100, $title & '... OK')
Return $output
EndFunc ;==>_readAll

Expand Down Expand Up @@ -2286,7 +2275,7 @@ Func setToolsPath()
EndIf

If $bAPKSignerFound == False And FileExists(StringStripWS($sPathItem, $STR_STRIPLEADING + $STR_STRIPTRAILING) & "\apksigner.bat") Then
$sAPKSignerPath = 'apksigner'
$sAPKSignerPath = 'apksigner.bat'
$bAPKSignerFound = True
EndIf

Expand Down
5 changes: 5 additions & 0 deletions Documents/Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
*** 1.40
- Fixed signature verification
- Simplified command output capturing


*** 1.39
- Refactor some code.
- App will exit now if 7-zip is missing or if both aapt and appt2 are missing.
Expand Down

0 comments on commit eccf701

Please sign in to comment.