Best Syzkaller code snippet using main.saveLog
ipfsPin.go
Source:ipfsPin.go
...20 ticker := time.NewTicker(time.Second * time.Duration(n))21 sum := 022 for range ticker.C {23 sum++24 saveLog(fmt.Sprintf("æ§è¡æ¬¡æ°ï¼%v", sum))25 data := getList()26 batchShell(data)27 }28}29func batchShell(d []string) {30 // æ¹éæ§è¡æ·»å å½ä»¤31 for _, cid := range d {32 //execCommand(string(cid))33 shell := fmt.Sprintf("crust tools ipfs pin add %v", cid)34 res := execCommand(shell)35 status := strings.Contains(res, "recursively")36 if status {37 // å¦ææåå°±ä¸æ¥38 saveLog(fmt.Sprintf("æ·»å æåï¼CIDï¼%v", cid))39 innerIp := execCommand("/sbin/ifconfig -a|grep inet|grep -vE '127.0.0.1|inet6|172'|awk '{print $2}'|tr -d \"addr:\" | uniq")40 syncCid(cid, innerIp)41 }42 }43}44func saveLog(s string) {45 // è®°å½logæ¥å¿46 tm := time.Now().Format("2006-01-02 15:04:05")47 f, err := os.OpenFile("log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)48 defer func() {49 if err = f.Close(); err != nil {50 return51 }52 }()53 if err != nil {54 return55 }56 str := tm + "\t" + s + "\n"57 _, err = f.WriteString(str)58 if err != nil {59 return60 }61}62func execCommand(c string) string {63 // æ§è¡å½ä»¤å¹¶è¿åç»æ64 cmd := exec.Command("/bin/bash", "-c", c)65 stdout, _ := cmd.StdoutPipe()66 saveLog("å¼å§æ§è¡å½ä»¤ï¼" + c)67 if err := cmd.Start(); err != nil {68 msg := "å¼å§æ§è¡å¤±è´¥ï¼" + err.Error()69 fmt.Println(msg)70 saveLog(msg)71 return ""72 }73 out, _ := ioutil.ReadAll(stdout)74 defer func() {75 if err := stdout.Close(); err != nil {76 return77 }78 }()79 if err := cmd.Wait(); err != nil {80 msg := "æ§è¡çå¾
失败ï¼" + err.Error()81 fmt.Println(msg)82 saveLog(msg)83 return ""84 }85 sOut := strings.TrimSuffix(string(out), "\n")86 saveLog("æ§è¡ç»æï¼" + sOut)87 return sOut88}89type FileList struct {90 Success bool `json:"success"`91 Code string `json:"code"`92 Message interface{} `json:"message"`93 Data []string `json:"data"`94}95func getList() []string {96 // è·åå表97 client := &http.Client{98 Timeout: time.Second * 3,99 }100 url := "https://www.infin.cloud/web/user-file/not-ping-file-cid-list"101 req, _ := http.NewRequest(http.MethodGet, url, nil)102 resp, err := client.Do(req)103 if err != nil {104 msg := "è·åå表ï¼è¯·æ±å¤±è´¥"105 saveLog(fmt.Sprintf("%v", err))106 saveLog(msg)107 fmt.Println(msg)108 return nil109 }110 saveLog(fmt.Sprintf("è·åå表ï¼è¯·æ±æå"))111 fmt.Println("è·åå表ï¼è¯·æ±æå")112 defer func() {113 if err := resp.Body.Close(); err != nil {114 return115 }116 }()117 body, err := ioutil.ReadAll(resp.Body)118 if err != nil {119 msg := "è·åå表ï¼è§£æååºå¤±è´¥"120 saveLog(fmt.Sprintf("%v", err))121 saveLog(msg)122 fmt.Println(msg)123 return nil124 }125 var lst FileList126 err = json.Unmarshal([]byte(string(body)), &lst)127 if err != nil {128 msg := "è·åå表ï¼è§£æåæ°å¤±è´¥"129 fmt.Println(msg)130 saveLog(msg)131 return nil132 }133 if lst.Success == true {134 msg := "è·åå表ï¼è§£æåæ°æå"135 saveLog(msg)136 fmt.Println(msg)137 }138 saveLog(fmt.Sprintf("%v", lst.Data))139 return lst.Data140}141func syncCid(c string, ip string) {142 // ä¸æ¥CID143 client := &http.Client{144 Timeout: time.Second * 3,145 }146 fmt.Println(ip)147 url := fmt.Sprintf("https://www.infin.cloud/web/user-file/local-ping-sync?cid=%v&ip=%v", c, ip)148 req, err := http.NewRequest(http.MethodGet, url, nil)149 if err != nil {150 msg := "ä¸æ¥CIDï¼reqæ建失败"151 saveLog(fmt.Sprintf("%v", err))152 saveLog(msg)153 fmt.Println(msg)154 return155 }156 resp, err := client.Do(req)157 if err != nil {158 msg := "ä¸æ¥CIDï¼è¯·æ±å¤±è´¥"159 saveLog(fmt.Sprintf("%v", err))160 saveLog(msg)161 fmt.Println(msg)162 return163 }164 body, _ := ioutil.ReadAll(resp.Body)165 saveLog("ä¸æ¥æå:" + string(body))166 fmt.Println(string(body))167 defer func() {168 if err := resp.Body.Close(); err != nil {169 return170 }171 }()172}...
procDaemon.go
Source:procDaemon.go
...17func init() {18 if _, err := os.Stat(workPath); err != nil {19 err := os.MkdirAll(workPath, 0644)20 if err != nil {21 saveLog("ç®å½å建é误ï¼" + err.Error())22 os.Exit(1)23 }24 }25}26func main() {27 var msg string28 if len(os.Args) != 2 {29 msg = "åæ°é误ï¼è¯·éæ°è¾å
¥"30 fmt.Println(msg)31 return32 }33 switch os.Args[1] {34 case "start":35 pid := getPid()36 if pid != "" && pid != "0" {37 return38 }39 cmd := Daemon()40 if cmd == nil {41 log.Println("æå¡å¯å¨å¤±è´¥ï¼")42 return43 }44 case "status":45 pid, _ := strconv.Atoi(getPid())46 proc, err := os.FindProcess(pid)47 if err != nil || pid == 0 {48 fmt.Println("procDaemon æªå¯å¨")49 return50 }51 if proc != nil {52 fmt.Println("procDaemon å·²å¯å¨")53 return54 }55 case "stop":56 msg = "procDaemon å·²éåºï¼"57 pid, _ := strconv.Atoi(getPid())58 proc, err := os.FindProcess(pid)59 if err != nil || pid == 0 {60 fmt.Println("procDaemon æªå¯å¨")61 return62 }63 err = proc.Kill()64 if err != nil {65 fmt.Println("procDaemon éåºå¤±è´¥")66 return67 }68 setPid("0")69 fmt.Println(msg)70 saveLog(msg)71 case "--daemon":72 // åå°çä¸å¡ä»£ç 73 wg.Add(1)74 ch1 := make(chan int, 1)75 go clock(2, ch1)76 for i := range ch1 {77 saveLog(fmt.Sprintf("æ§è¡æ¬¡æ°ï¼%v", i))78 }79 wg.Wait()80 }81}82func getPid() string {83 pidFile, err := os.OpenFile(PidPath, os.O_CREATE|os.O_RDONLY, 0444)84 if err != nil {85 saveLog("è·åPIDåºç°é误ï¼" + err.Error())86 return ""87 }88 defer func() {89 if err = pidFile.Close(); err != nil {90 return91 }92 }()93 pid, err := ioutil.ReadAll(pidFile)94 if err != nil {95 saveLog("转æ¢PIDåºç°é误ï¼" + err.Error())96 return ""97 }98 return string(pid)99}100func setPid(s string) {101 pidFile, err := os.OpenFile(PidPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0444)102 if err != nil {103 saveLog("设置PIDåºç°é误ï¼" + err.Error())104 return105 }106 defer func() {107 if err = pidFile.Close(); err != nil {108 return109 }110 }()111 _, err = pidFile.WriteString(s)112 if err != nil {113 return114 }115}116func Daemon() *exec.Cmd {117 if os.Getppid() != 1 {118 var msg string119 filepath := os.Args[0]120 cmd := exec.Command(filepath, "--daemon")121 if err := cmd.Start(); err != nil {122 msg = "æå¡å¯å¨å¤±è´¥ï¼" + err.Error()123 saveLog(msg)124 return nil125 }126 msg = fmt.Sprintf("æå¡pid=%d:å¼å§è¿è¡...", cmd.Process.Pid)127 saveLog(msg)128 pidStr := strconv.Itoa(cmd.Process.Pid)129 setPid(pidStr)130 fmt.Println("procDaemon å·²å¯å¨ï¼")131 os.Exit(0)132 return cmd133 }134 return nil135}136func clock(n int, c chan<- int) {137 // n:å®æ¶é´é138 defer wg.Done()139 ticker := time.NewTicker(time.Second * time.Duration(n))140 sum := 0141 for range ticker.C {142 sum++143 c <- sum144 }145}146func saveLog(s string) {147 // è®°å½logæ¥å¿148 tm := time.Now().Format("2006-01-02 15:04:05")149 f, err := os.OpenFile(LogPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)150 defer func() {151 if err = f.Close(); err != nil {152 return153 }154 }()155 if err != nil {156 return157 }158 str := tm + "\t" + s + "\n"159 _, err = f.WriteString(str)160 if err != nil {...
main.go
Source:main.go
...18 barkKey = "test"19 var wg sync.WaitGroup20 wg.Add(1)21 nyc, _ := time.LoadLocation("Asia/Shanghai")22 saveLog(barkPush("æµè¯åé", barkKey, "æµè¯"))23 c := cron.New(cron.WithLocation(nyc))24 _, err := c.AddFunc("0/5 7-22 * * MON-FRI", getlubu)25 if err != nil {26 saveLog(err.Error())27 return28 }29 getlubu()30 c.Start()31 wg.Wait()32 saveLog("å·²ç»æè¿è¡")33}34func getlubu() {35 saveLog("å¼å§è·åçä»·\n")36 // Request the HTML page.37 res, err := http.Get("https://www.boc.cn/sourcedb/whpj/")38 if err != nil {39 log.Fatal(err)40 }41 defer func(Body io.ReadCloser) {42 err := Body.Close()43 if err != nil {44 log.Fatal(err)45 }46 }(res.Body)47 if res.StatusCode != 200 {48 log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)49 }50 // Load the HTML document51 doc, err := goquery.NewDocumentFromReader(res.Body)52 if err != nil {53 log.Fatal(err)54 }55 gong := "body > div.wrapper > div.BOC_main > div.publish > div:nth-child(3) > table > tbody > tr:nth-child("56 namegps := ") > td:nth-child(1)"57 salegps := ") > td:nth-child(2)"58 buygps := ") > td:nth-child(4)"59 timegps := ") > td:nth-child(8)"60 for i := 2; i < 30; i++ {61 name := gong + strconv.Itoa(i) + namegps62 nameText := doc.Find(name).Text()63 if nameText == "å¢å¸" {64 saleName := gong + strconv.Itoa(1) + ") > th:nth-child(2)"65 buyName := gong + strconv.Itoa(1) + ") > th:nth-child(4)"66 timeName := gong + strconv.Itoa(1) + ") > th:nth-child(8)"67 saleDom := gong + strconv.Itoa(i) + salegps68 buyDom := gong + strconv.Itoa(i) + buygps69 timeDom := gong + strconv.Itoa(i) + timegps70 saleNameText := doc.Find(saleName).Text()71 buyNameText := doc.Find(buyName).Text()72 timeNameText := doc.Find(timeName).Text()73 saleText := doc.Find(saleDom).Text()74 buyText := doc.Find(buyDom).Text()75 timeText := doc.Find(timeDom).Text()76 PriceBody := saleNameText + ": " + saleText + "\n" + buyNameText + ": " + buyText + "\n"77 body := PriceBody + timeNameText + ": " + timeText78 if lastPrice != PriceBody {79 saveLog(barkPush(body, barkKey, nameText))80 lastPrice = PriceBody81 }82 break83 }84 if i == 29 {85 result, _ := ioutil.ReadAll(res.Body)86 saveLog(string(result))87 saveLog(barkPush("è²ä¼¼è¢«å°äº", barkKey, nameText))88 }89 }90 saveLog("ç»æè·åçä»·\n")91}92//计ç®ä¸¤ä¸ªæ¶é´ç¸å·®å¤å°ç§93func timeDiff(start, end time.Time) int {94 return int(end.Sub(start).Seconds())95}
saveLog
Using AI Code Generation
1import (2func main() {3 f, err := os.Create("log.txt")4 if err != nil {5 log.Fatal(err)6 }7 saveLog(f)8}9import (10func saveLog(f *os.File) {11 log.SetOutput(f)12 log.Println("This is a test log entry")13}
saveLog
Using AI Code Generation
1import (2func main() {3 main.saveLog("Hello")4}5import (6func main() {7 main.saveLog("Hello")8}9import (10func main() {11 main.saveLog("Hello")12}13import (14func main() {15 main.saveLog("Hello")16}17import (18func main() {19 main.saveLog("Hello")20}21import (22func main() {23 main.saveLog("Hello")24}25import (26func main() {27 main.saveLog("Hello")28}29import (30func main() {31 main.saveLog("Hello")32}33import (34func main() {35 main.saveLog("Hello")36}37import (38func main() {39 main.saveLog("Hello")40}41import (42func main() {43 main.saveLog("Hello")44}45import (46func main() {47 main.saveLog("Hello")48}49import (50func main() {51 main.saveLog("Hello")52}
saveLog
Using AI Code Generation
1import (2func main() {3 err = saveLog("Error")4 if err != nil {5 log.Fatal(err)6 }7}8import (9func saveLog(logType string) error {10 f, err := os.OpenFile("log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)11 if err != nil {12 }13 defer f.Close()14 if _, err := f.WriteString(fmt.Sprintf("%s15", logType)); err != nil {16 }17}18Your name to display (optional):19Your name to display (optional):
saveLog
Using AI Code Generation
1import (2func saveLog() {3 log.Println("hello from saveLog")4}5import (6func saveLog() {7 log.Println("hello from saveLog")8}9import (10func saveLog() {11 log.Println("hello from saveLog")12}13import (14func saveLog() {15 log.Println("hello from saveLog")16}17import (18func saveLog() {19 log.Println("hello from saveLog")20}21import (22func saveLog() {23 log.Println("hello from saveLog")24}25import (26func saveLog() {27 log.Println("hello from saveLog")28}29import (30func saveLog() {31 log.Println("hello from saveLog")32}33import (34func saveLog() {35 log.Println("hello from saveLog")36}37import (38func saveLog() {39 log.Println("hello from saveLog")40}41import (42func saveLog() {43 log.Println("hello from saveLog")44}45import (46func saveLog() {47 log.Println("hello from saveLog")48}49import (50func saveLog() {51 log.Println("hello
saveLog
Using AI Code Generation
1import "fmt"2func main() {3 var log = Log{"", "2.go"}4 log.saveLog()5}6import "fmt"7func main() {8 var log = Log{"", "3.go"}9 log.saveLog()10}11import "fmt"12func main() {13 var log = Log{"", "4.go"}14 log.saveLog()15}16import "fmt"17func main() {18 var log = Log{"", "5.go"}19 log.saveLog()20}21import "fmt"22func main() {23 var log = Log{"", "6.go"}24 log.saveLog()25}26import "fmt"27func main() {28 var log = Log{"", "7.go"}29 log.saveLog()30}31import "fmt"32func main() {33 var log = Log{"", "8.go"}34 log.saveLog()35}36import "fmt"37func main() {38 var log = Log{"", "9.go"}39 log.saveLog()40}41import "fmt"42func main() {43 var log = Log{"", "10.go"}44 log.saveLog()45}46import "fmt"47func main() {48 var log = Log{"", "11.go"}49 log.saveLog()50}51import "fmt"52func main() {53 var log = Log{"", "12.go"}54 log.saveLog()55}
saveLog
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, playground")4 var log = NewLog()5 log.saveLog("test")6}7import (8func main() {9 fmt.Println("Hello, playground")10 var log = NewLog()11 log.saveLog("test")12}13import (14func main() {15 fmt.Println("Hello, playground")16 var log = NewLog()17 log.saveLog("test")18}19import (20func main() {21 fmt.Println("Hello, playground")22 var log = NewLog()23 log.saveLog("test")24}25import (26func main() {27 fmt.Println("Hello, playground")28 var log = NewLog()29 log.saveLog("test")30}31import (32func main() {33 fmt.Println("Hello, playground")34 var log = NewLog()35 log.saveLog("test")36}37import (38func main() {39 fmt.Println("Hello, playground")40 var log = NewLog()41 log.saveLog("test")42}43import (44func main() {45 fmt.Println("Hello, playground")46 var log = NewLog()47 log.saveLog("test")48}49import (50func main() {51 fmt.Println("Hello, playground")52 var log = NewLog()53 log.saveLog("test")54}
saveLog
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, playground")4 saveLog("Hello, playground")5}6func saveLog(logData string) {7 log.Println(logData)8}
saveLog
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, playground")4}5import (6func main() {7 fmt.Println("Hello, playground")8}9import (10func main() {11 fmt.Println("Hello, playground")12}13import (14func main() {15 fmt.Println("Hello, playground")16}17import (18func main() {19 fmt.Println("Hello, playground")20}21import (22func main() {23 fmt.Println("Hello, playground")24}25import (26func main() {27 fmt.Println("Hello, playground")28}29import (30func main() {31 fmt.Println("Hello, playground")32}
saveLog
Using AI Code Generation
1import (2func main() {3 main.saveLog("test")4}5func main() {6 http.HandleFunc("/", hello)7 http.ListenAndServe(":8080", nil)8}9func hello(w http.ResponseWriter, r *http.Request) {10 fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))11}12func main() {13 http.HandleFunc("/", hello)14 http.ListenAndServe(":8080", nil)15}16var hello = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {17 fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))18})19func main() {20 http.HandleFunc("/", hello)21 http.ListenAndServe(":8080", nil)22}23func hello(w http.ResponseWriter, r *http.Request) {24 fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))25}26var hello = http.HandlerFunc(hello)27func main() {28 http.HandleFunc("/", hello)29 http.ListenAndServe(":8080", nil)30}31func hello(w http.ResponseWriter, r *http.Request) {32 fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))33}34var hello = http.HandlerFunc(hello)
saveLog
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello from 2.go")4 SaveLog1.SaveLog("This is a test log message")5}6import (7func main() {8 fmt.Println("Hello from 3.go")9 SaveLog1.SaveLog("This is a test log message")10}11import (12func main() {13 fmt.Println("Hello from 1.go")14 SaveLog1.SaveLog("This is a test log message")15}16import (17func main() {18 fmt.Println("Hello from 2.go")
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!