@@ -375,7 +375,7 @@ public static async Task<bool> SignApk(string path, string pemData, Dictionary<s
375375 QAVSWebserver . patchStatus . currentOperation = "Aligning apk" ;
376376 QAVSWebserver . BroadcastPatchingStatus ( ) ;
377377 Logger . Log ( "Aligning Apk" ) ;
378- if ( ! ApkAligner . AlignApk ( path ) )
378+ if ( ! await ApkAligner . AlignApk ( path ) )
379379 {
380380 Logger . Log ( "Aligning failed... Aborting" , LoggingType . Warning ) ;
381381 return false ;
@@ -388,12 +388,12 @@ public static async Task<bool> SignApk(string path, string pemData, Dictionary<s
388388
389389 Logger . Log ( "Make APK Signature Scheme v2" ) ;
390390 FileStream fs = new FileStream ( path , FileMode . Open ) ;
391- using FileMemory memory = new FileMemory ( fs ) ;
391+ await using FileMemory memory = new FileMemory ( fs ) ;
392392 TempFile t = new TempFile ( ) ;
393- using FileStream tmp = new FileStream ( t . Path , FileMode . Create ) ;
394- using FileMemory outMemory = new FileMemory ( tmp ) ;
393+ await using FileStream tmp = new FileStream ( t . Path , FileMode . Create ) ;
394+ await using FileMemory outMemory = new FileMemory ( tmp ) ;
395395 memory . Position = memory . Length ( ) - 22 ;
396- while ( memory . ReadInt ( ) != EndOfCentralDirectory . SIGNATURE )
396+ while ( await memory . ReadInt ( ) != EndOfCentralDirectory . SIGNATURE )
397397 {
398398 memory . Position -= 4 + 1 ;
399399 }
@@ -402,7 +402,8 @@ public static async Task<bool> SignApk(string path, string pemData, Dictionary<s
402402 EndOfCentralDirectory eocd ;
403403 try
404404 {
405- eocd = new EndOfCentralDirectory ( memory ) ;
405+ eocd = new EndOfCentralDirectory ( ) ;
406+ await eocd . Populate ( memory ) ;
406407 }
407408 catch ( Exception e )
408409 {
@@ -414,8 +415,8 @@ public static async Task<bool> SignApk(string path, string pemData, Dictionary<s
414415 var cd = eocd . OffsetOfCD ;
415416 memory . Position = cd - 16 - 8 ;
416417
417- var d = memory . ReadULong ( ) ;
418- var d2 = memory . ReadString ( 16 ) ;
418+ var d = await memory . ReadULong ( ) ;
419+ var d2 = await memory . ReadString ( 16 ) ;
419420 var section1 = await GetSectionDigests ( fs , 0 , cd ) ;
420421 var section3 = await GetSectionDigests ( fs , cd , eocdPosition ) ;
421422 var section4 = await GetSectionDigests ( fs , eocdPosition , fs . Length ) ;
@@ -444,7 +445,7 @@ public static async Task<bool> SignApk(string path, string pemData, Dictionary<s
444445
445446 signedData . Certificates . Add ( cert . GetEncoded ( ) ) ;
446447
447- signedData . Write ( memorySignedData ) ;
448+ await signedData . Write ( memorySignedData ) ;
448449 signer . SignedData = signedDataMs . ToArray ( ) ;
449450 ISigner signerType = SignerUtilities . GetSigner ( "SHA256WithRSA" ) ;
450451 signerType . Init ( true , privateKey ) ;
@@ -455,18 +456,19 @@ public static async Task<bool> SignApk(string path, string pemData, Dictionary<s
455456 block . Signers . Add ( signer ) ;
456457
457458 APKSigningBlock signingBlock = new APKSigningBlock ( ) ;
458- signingBlock . Values . Add ( block . ToIDValuePair ( ) ) ;
459+ signingBlock . Values . Add ( await block . ToIDValuePair ( ) ) ;
459460
460461 fs . Position = 0 ;
461- outMemory . WriteBytes ( memory . ReadBytes ( cd ) ) ;
462- signingBlock . Write ( outMemory ) ;
462+ await outMemory . WriteBytes ( await memory . ReadBytes ( cd ) ) ;
463+ await signingBlock . Write ( outMemory ) ;
463464 eocd . OffsetOfCD = ( int ) tmp . Position ;
464- outMemory . WriteBytes ( memory . ReadBytes ( ( int ) ( eocdPosition - cd ) ) ) ;
465- eocd . Write ( outMemory ) ;
465+ await outMemory . WriteBytes ( await memory . ReadBytes ( ( int ) ( eocdPosition - cd ) ) ) ;
466+ await eocd . Write ( outMemory ) ;
466467
467468 fs . Close ( ) ;
468469 tmp . Close ( ) ;
469470 if ( File . Exists ( path ) ) File . Delete ( path ) ;
471+
470472 File . Move ( t . Path , path ) ;
471473 return true ;
472474 }
0 commit comments