This repository has been archived by the owner on Jun 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create an fs.FS implementation that lets us see into an APK file. * Add tests for apkfs * Add test file * Move ExpandApk into its own package so that it may be referenced from both the apk and fs packages
- Loading branch information
1 parent
bc62936
commit c10419b
Showing
7 changed files
with
345 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package expandapk | ||
|
||
const ( | ||
paxRecordsChecksumKey = "APK-TOOLS.checksum.SHA1" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package expandapk | ||
|
||
import ( | ||
"archive/tar" | ||
"encoding/base64" | ||
"encoding/hex" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func checksumFromHeader(header *tar.Header) ([]byte, error) { | ||
pax := header.PAXRecords | ||
if pax == nil { | ||
return nil, nil | ||
} | ||
|
||
hexsum, ok := pax[paxRecordsChecksumKey] | ||
if !ok { | ||
return nil, nil | ||
} | ||
|
||
if strings.HasPrefix(hexsum, "Q1") { | ||
// This is nonstandard but something we did at one point, handle it. | ||
// In other contexts, this Q1 prefix means "this is sha1 not md5". | ||
b64 := strings.TrimPrefix(hexsum, "Q1") | ||
|
||
checksum, err := base64.StdEncoding.DecodeString(b64) | ||
if err != nil { | ||
return nil, fmt.Errorf("decoding base64 checksum from header for %q: %w", header.Name, err) | ||
} | ||
|
||
return checksum, nil | ||
} | ||
|
||
checksum, err := hex.DecodeString(hexsum) | ||
if err != nil { | ||
return nil, fmt.Errorf("decoding hex checksum from header for %q: %w", header.Name, err) | ||
} | ||
|
||
return checksum, nil | ||
} |
Oops, something went wrong.