-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:esafirm/gadb
- Loading branch information
Showing
5 changed files
with
168 additions
and
19 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,44 @@ | ||
package adb | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"regexp" | ||
) | ||
|
||
const ANALYZER = "apkanalyzer" | ||
|
||
type CommandReturn struct { | ||
Output []byte | ||
Error error | ||
} | ||
|
||
func checkInPath() { | ||
_, err := exec.LookPath(ANALYZER) | ||
if err != nil { | ||
fmt.Println(ANALYZER + " is not in the path") | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func Manifest(apkPath string) CommandReturn { | ||
checkInPath() | ||
|
||
output, err := exec.Command(ANALYZER, "manifest", "print", apkPath).CombinedOutput() | ||
return CommandReturn{output, err} | ||
} | ||
|
||
func PackageName(apkPath string) (string, error) { | ||
checkInPath() | ||
|
||
output, err := exec.Command(ANALYZER, "manifest", "print", apkPath).CombinedOutput() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
r, _ := regexp.Compile("package=\"(.*)\"") | ||
result := r.FindStringSubmatch(string(output)) | ||
|
||
return result[1], nil | ||
} |
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
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,45 @@ | ||
// Copyright © 2019 Esa Firman esafirm21@gmail.com | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
analyzer "github.com/esafirm/gadb/apkanalyzer" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var pakcageCmd = &cobra.Command{ | ||
Use: "package [apk]", | ||
Short: "Print package name from the APK", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) == 0 { | ||
fmt.Println("You must provide the APK") | ||
return | ||
} | ||
|
||
pakckageName, err := analyzer.PackageName(args[0]) | ||
if err != nil { | ||
fmt.Printf("Package name: %s", pakckageName) | ||
} else { | ||
panic(err) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(pakcageCmd) | ||
} |