struct.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package aapt
  2. // Aapt represents aapt util
  3. type Aapt struct {
  4. binPath string
  5. }
  6. // AppInfo represents application's info
  7. type AppInfo struct {
  8. PackageName string
  9. VersionName string
  10. VersionCode int
  11. MinSDKVersion int
  12. TargetSDKVersion int
  13. UsesAndroidPermission []string // like android.permission.USE_FINGERPRINT
  14. UsesCustomPermission []string // like com.htc.launcher.permission.UPDATE_SHORTCUT
  15. LaunchActivity []string // it is possible have more than one launch activity
  16. AppLabel map[string]string // NoLocale and ru-RU and so on
  17. MetaData map[string]string // for example: "meta-data: name='com.android.vending.splits' resource='res/xml/splits0.xml'"
  18. IsSplitBase bool // when "meta-data: name='com.android.vending.splits.required'" presents
  19. Debuggable bool
  20. TestOnly bool
  21. NativeCode map[string]struct{} // Empty struct takes 0 bytes in memory
  22. }
  23. // Resources represents application's resources
  24. type Resources struct {
  25. // android:array
  26. Array map[string][][2]string
  27. // android:string
  28. String map[string][][2]string
  29. }
  30. // BinPath returns path to aapt's bin file
  31. func (aapt Aapt) BinPath() string {
  32. return aapt.binPath
  33. }
  34. // XmlStringsManifest returns dump for strings of AndroidManifest.xml
  35. func (aapt Aapt) XmlStringsManifest(apkFile string) ([]byte, error) {
  36. cmd := []string{"xmlstrings", apkFile, "AndroidManifest.xml"}
  37. return aapt.RunSync("dump", cmd...)
  38. }
  39. // removeFilesFrom removes files from apk files
  40. func (aapt Aapt) removeFilesFrom(apkAarJar string, files ...string) ([]byte, error) {
  41. return aapt.RunSync("r", append([]string{apkAarJar}, files...)...)
  42. }
  43. // RemoveSignature removes apk's V1 signature
  44. func (aapt Aapt) RemoveSignature(zipFile string) ([]byte, error) {
  45. sign, err := findApkSignature(zipFile)
  46. if err != nil {
  47. return nil, err
  48. }
  49. return aapt.removeFilesFrom(zipFile, sign...)
  50. }
  51. // DumpAppInfo returns raw app info dump. See ParseAppInfoDumpFromBytes
  52. func (aapt Aapt) DumpAppInfo(apkFile string) ([]byte, error) {
  53. return aapt.RunSync("dump", "--include-meta-data", "badging", apkFile)
  54. }
  55. // DumpResources returns raw app resources dump. See ParseDumpResourcesFromBytes
  56. func (aapt Aapt) DumpResources(apkFile string) ([]byte, error) {
  57. return aapt.RunSync("dump", "--values", "resources", apkFile)
  58. }
  59. // Version returns aapt's version
  60. func (aapt Aapt) Version() ([]byte, error) {
  61. return aapt.RunSync("version")
  62. }