mirror of
https://github.com/thunderbrewhq/binana.git
synced 2026-05-02 20:54:03 +00:00
This commit is contained in:
parent
ac268a16c8
commit
2c2815ab0b
22 changed files with 2122 additions and 2 deletions
|
|
@ -4,6 +4,9 @@ import (
|
|||
_ "github.com/thunderbrewhq/binana/go/app/cmd/add_symbol"
|
||||
_ "github.com/thunderbrewhq/binana/go/app/cmd/lint"
|
||||
_ "github.com/thunderbrewhq/binana/go/app/cmd/make"
|
||||
_ "github.com/thunderbrewhq/binana/go/app/cmd/make_samples"
|
||||
_ "github.com/thunderbrewhq/binana/go/app/cmd/make_tokens"
|
||||
_ "github.com/thunderbrewhq/binana/go/app/cmd/query"
|
||||
"github.com/thunderbrewhq/binana/go/app/cmd/root"
|
||||
_ "github.com/thunderbrewhq/binana/go/app/cmd/tidy"
|
||||
|
||||
|
|
|
|||
68
go/app/cmd/make_samples/make-samples.go
Normal file
68
go/app/cmd/make_samples/make-samples.go
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
package make_samples
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/thunderbrewhq/binana/go/app"
|
||||
"github.com/thunderbrewhq/binana/go/app/cmd/root"
|
||||
"github.com/thunderbrewhq/binana/go/app/util"
|
||||
"github.com/thunderbrewhq/binana/go/app/util/dbutil"
|
||||
)
|
||||
|
||||
var make_samples_cmd = cobra.Command{
|
||||
Use: "make-samples",
|
||||
Run: run_make_samples_command,
|
||||
}
|
||||
|
||||
func init() {
|
||||
f := make_samples_cmd.Flags()
|
||||
f.StringP("source", "s", "", "required: source tree of sample binaries")
|
||||
f.StringP("output-file", "o", "", "write the database to a file")
|
||||
f.StringSlice("direct-mirror", nil, "list of direct mirror URLs that already contain the sample binaries")
|
||||
f.StringSlice("ipfs-gateway", nil, "list of IPFS gateways")
|
||||
f.StringP("format", "f", "json", "the format of the output database [json|parquet]")
|
||||
root.RootCmd.AddCommand(&make_samples_cmd)
|
||||
}
|
||||
|
||||
func run_make_samples_command(cmd *cobra.Command, args []string) {
|
||||
f := cmd.Flags()
|
||||
var (
|
||||
params util.MakeSampleDatabaseParams
|
||||
err error
|
||||
format string
|
||||
)
|
||||
params.Source, err = f.GetString("source")
|
||||
if err != nil {
|
||||
app.Fatal(err)
|
||||
}
|
||||
if params.Source == "" {
|
||||
cmd.Help()
|
||||
return
|
||||
}
|
||||
params.Output, err = f.GetString("output-file")
|
||||
if err != nil {
|
||||
app.Fatal(err)
|
||||
}
|
||||
format, err = f.GetString("format")
|
||||
if err != nil {
|
||||
app.Fatal(err)
|
||||
}
|
||||
switch format {
|
||||
case "json":
|
||||
params.Format = dbutil.DatabaseJSON
|
||||
case "parquet":
|
||||
params.Format = dbutil.DatabaseParquet
|
||||
default:
|
||||
app.Fatal("unknown format", format)
|
||||
}
|
||||
|
||||
params.DirectMirrors, err = f.GetStringSlice("direct-mirror")
|
||||
if err != nil {
|
||||
app.Fatal(err)
|
||||
}
|
||||
params.IPFSGateways, err = f.GetStringSlice("ipfs-gateway")
|
||||
if err != nil {
|
||||
app.Fatal(err)
|
||||
}
|
||||
|
||||
util.MakeSampleDatabase(¶ms)
|
||||
}
|
||||
57
go/app/cmd/make_tokens/make-tokens.go
Normal file
57
go/app/cmd/make_tokens/make-tokens.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package make_tokens
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/thunderbrewhq/binana/go/app"
|
||||
"github.com/thunderbrewhq/binana/go/app/cmd/root"
|
||||
"github.com/thunderbrewhq/binana/go/app/util"
|
||||
"github.com/thunderbrewhq/binana/go/app/util/dbutil"
|
||||
)
|
||||
|
||||
var make_tokens_cmd = cobra.Command{
|
||||
Use: "make-tokens",
|
||||
Run: run_make_tokens_command,
|
||||
}
|
||||
|
||||
func init() {
|
||||
f := make_tokens_cmd.Flags()
|
||||
f.StringP("source", "s", "", "required: source tree of sample binaries")
|
||||
f.StringP("output-file", "o", "", "write the database to a file")
|
||||
f.StringP("format", "f", "json", "the format of the output database [json|parquet]")
|
||||
root.RootCmd.AddCommand(&make_tokens_cmd)
|
||||
}
|
||||
|
||||
func run_make_tokens_command(cmd *cobra.Command, args []string) {
|
||||
f := cmd.Flags()
|
||||
var (
|
||||
params util.MakeTokenDatabaseParams
|
||||
err error
|
||||
format string
|
||||
)
|
||||
params.Source, err = f.GetString("source")
|
||||
if err != nil {
|
||||
app.Fatal(err)
|
||||
}
|
||||
if params.Source == "" {
|
||||
cmd.Help()
|
||||
return
|
||||
}
|
||||
params.Output, err = f.GetString("output-file")
|
||||
if err != nil {
|
||||
app.Fatal(err)
|
||||
}
|
||||
format, err = f.GetString("format")
|
||||
if err != nil {
|
||||
app.Fatal(err)
|
||||
}
|
||||
switch format {
|
||||
case "json":
|
||||
params.Format = dbutil.DatabaseJSON
|
||||
case "parquet":
|
||||
params.Format = dbutil.DatabaseParquet
|
||||
default:
|
||||
app.Fatal("unknown format", format)
|
||||
}
|
||||
|
||||
util.MakeTokenDatabase(¶ms)
|
||||
}
|
||||
72
go/app/cmd/query/query.go
Normal file
72
go/app/cmd/query/query.go
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
package query
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/thunderbrewhq/binana/go/app"
|
||||
"github.com/thunderbrewhq/binana/go/app/cmd/root"
|
||||
"github.com/thunderbrewhq/binana/go/app/util"
|
||||
)
|
||||
|
||||
var query_cmd = cobra.Command{
|
||||
Use: "q regexp",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Short: "query the token database for information",
|
||||
Run: run_query_cmd,
|
||||
}
|
||||
|
||||
func init() {
|
||||
f := query_cmd.Flags()
|
||||
f.Uint32("min-build", 0, "the minimum build to return tokens for")
|
||||
f.Uint32("max-build", math.MaxUint32, "the maximum build to return tokens for")
|
||||
f.StringSlice("program", nil, "a list of programs to return tokens for")
|
||||
f.StringSlice("os", nil, "a list of kernel names to return tokens for (windows, darwin, linux)")
|
||||
f.StringSlice("arch", nil, "a list of CPU architectures to return tokens for (ppc, 386, amd64)")
|
||||
f.String("present", "normal", "control the way tokens are presented to console (normal, name-only)")
|
||||
root.RootCmd.AddCommand(&query_cmd)
|
||||
}
|
||||
|
||||
func run_query_cmd(cmd *cobra.Command, args []string) {
|
||||
f := cmd.Flags()
|
||||
var (
|
||||
params util.QueryParams
|
||||
err error
|
||||
presentation_mode string
|
||||
)
|
||||
params.MinBuild, err = f.GetUint32("min-build")
|
||||
if err != nil {
|
||||
app.Fatal(err)
|
||||
}
|
||||
params.MaxBuild, err = f.GetUint32("max-build")
|
||||
if err != nil {
|
||||
app.Fatal(err)
|
||||
}
|
||||
params.Program, err = f.GetStringSlice("program")
|
||||
if err != nil {
|
||||
app.Fatal(err)
|
||||
}
|
||||
params.OS, err = f.GetStringSlice("os")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
params.Arch, err = f.GetStringSlice("arch")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
presentation_mode, err = f.GetString("present")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
switch presentation_mode {
|
||||
case "normal":
|
||||
params.Present = util.PresentQueryNormal
|
||||
case "name-only":
|
||||
params.Present = util.PresentQueryNameOnly
|
||||
default:
|
||||
cmd.Help()
|
||||
return
|
||||
}
|
||||
params.Token = args[0]
|
||||
util.Query(¶ms)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue