Skip to content

Commit

Permalink
将结果写入result目录中
Browse files Browse the repository at this point in the history
  • Loading branch information
Zjackky committed Oct 6, 2024
1 parent 55b6818 commit 17aed70
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
8 changes: 8 additions & 0 deletions FindFile/FindFile_Java.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ func FindFileByJava(dir string, outputfile string, rules []string) {
Check(err)

// 创建或打开输出文件,以追加模式写入
basedir := "./results/"

err1 := os.MkdirAll(basedir, os.ModePerm)
if err1 != nil {
fmt.Println("Error creating directory:", err)
return
}
outputfile = basedir + outputfile
outputFile, err := os.OpenFile(outputfile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
Check(err)
defer outputFile.Close() // 确保文件在函数返回前被关闭
Expand Down
7 changes: 7 additions & 0 deletions FindFile/FindFile_PHP.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ func FindFileByPHP(dir string, outputfile string, rules []string) {
Check(err)

// 创建或打开输出文件,以追加模式写入
basedir := "./results/"
err1 := os.MkdirAll(basedir, os.ModePerm)
if err1 != nil {
fmt.Println("Error creating directory:", err)
return
}
outputfile = basedir + outputfile
outputFile, err := os.OpenFile(outputfile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
Check(err)
defer outputFile.Close() // 确保文件在函数返回前被关闭
Expand Down
16 changes: 15 additions & 1 deletion Java-Code/Frame_Analysis/Frame_Analysiser.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,21 @@ func FrameAnalysiser(dir string) {
}

output := strings.Join(result, "\n")
err = ioutil.WriteFile("Frame_Analysiser.txt", []byte(output), 0644)
// 创建或打开输出文件,以追加模式写入
basedir := "./results/"

// 检查目录是否存在
if _, err := os.Stat(basedir); os.IsNotExist(err) {
// 如果目录不存在,则创建
err := os.MkdirAll(basedir, os.ModePerm)
if err != nil {
fmt.Println("Error creating directory:", err)
return
}
}
outputfile := "Frame_Analysiser.txt"
outputfile = basedir + outputfile
err = ioutil.WriteFile(outputfile, []byte(output), 0644)
if err != nil {
log.Fatal(err)
}
Expand Down
18 changes: 16 additions & 2 deletions Java-Code/Sql/Sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,22 @@ func Sqlcheck(dir string) {

// writeToFile 函数用于将信息写入文件
func writeToFile(filename string, lines []string) {
// 打开文件,如果文件不存在则创建,如果存在则追加写入
outputFile, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)

// 创建或打开输出文件,以追加模式写入
basedir := "./results/"

// 检查目录是否存在
if _, err := os.Stat(basedir); os.IsNotExist(err) {
// 如果目录不存在,则创建
err := os.MkdirAll(basedir, os.ModePerm)
if err != nil {
fmt.Println("Error creating directory:", err)
return
}
}

outputfile := basedir + filename // 打开文件,如果文件不存在则创建,如果存在则追加写入
outputFile, err := os.OpenFile(outputfile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
check(err)
defer outputFile.Close()

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ https://zjackky.github.io/post/develop-codescan-zwcz53.html

* 开源

**2024/10/7**

* 将扫描结果写入result目录中

## 鸣谢

Expand Down

0 comments on commit 17aed70

Please sign in to comment.