-
Notifications
You must be signed in to change notification settings - Fork 52
/
flag_create.go
94 lines (85 loc) · 1.88 KB
/
flag_create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"bytes"
"embed"
"errors"
"flag"
"fmt"
"io/fs"
"os"
"strings"
)
//go:embed frida-agent-example
var frida_agent_example embed.FS
var FlagCreate =flag.NewFlagSet("create",flag.ExitOnError)
func init(){
FlagCreate.Usage= func() {
fmt.Fprintf(FlagCreate.Output(), "============== 创建工程 使用方法:%s\n", "create pdir")
FlagCreate.PrintDefaults()
}
}
func FlagCreateMain(args []string)error{
if len(args)<1{
fmt.Println("解析目录失败")
FlagCreate.Usage()
return nil
}
create_dir:=args[0]
FlagCreate.Parse(args[1:])
if FlagCreate.Parsed(){
return NewCreate().Run(CreateParam{Dir: create_dir})
}
return errors.New("create命令解析失败")
}
type CreateParam struct {
Dir string
}
type Create struct {
}
func (l *Create) Run(param CreateParam) error {
if param.Dir==""{
return errors.New("还没有指定创建的目录")
}
err:=os.MkdirAll(param.Dir,os.ModePerm)
if err!=nil{
return err
}
err=fs.WalkDir(frida_agent_example,".", func(path string, d fs.DirEntry, err error) error {
if path=="."{
return nil
}
if d.IsDir(){
topath:=strings.ReplaceAll(path,"frida-agent-example",param.Dir)
err=os.MkdirAll(topath,os.ModePerm)
if err!=nil{
return err
}
}else{
o,err:=frida_agent_example.ReadFile(path)
if err!=nil{
return err
}
o=bytes.ReplaceAll(o,[]byte("frida-agent-example"), []byte(param.Dir))
topath:=strings.ReplaceAll(path,"frida-agent-example",param.Dir)
err=os.WriteFile(topath,o,os.ModePerm)
if err!=nil{
return err
}
}
return nil
})
if err!=nil{
return err
}
fmt.Println("创建工程成功:",param.Dir)
fmt.Println("执行以下命令")
fmt.Println()
fmt.Println("cd ",param.Dir)
fmt.Println("npm install")
fmt.Println("npm run watch")
fmt.Println("run _agent.js -name 通讯录")
return nil
}
func NewCreate() *Create {
return &Create{}
}