Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca818e199a | ||
|
|
0a5f669442 | ||
|
|
b56ed1c270 |
62
README.md
62
README.md
@@ -1,4 +1,5 @@
|
|||||||
# go-clamav
|
# go-clamav
|
||||||
|
[](https://pkg.go.dev/github.com/ca110us/go-clamav?tab=doc)
|
||||||
|
|
||||||
go-clamav is go wrapper for [libclamav](https://docs.clamav.net/manual/Development/libclamav.html)
|
go-clamav is go wrapper for [libclamav](https://docs.clamav.net/manual/Development/libclamav.html)
|
||||||
|
|
||||||
@@ -35,7 +36,66 @@ sudo cmake --build . --target install
|
|||||||
For other Linux distributions, see [clamav documentation](https://docs.clamav.net/manual/Installing/Installing-from-source-Unix.html)
|
For other Linux distributions, see [clamav documentation](https://docs.clamav.net/manual/Installing/Installing-from-source-Unix.html)
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
Refer to the `example` directory
|
```bash
|
||||||
|
$ cd example && cat main.go
|
||||||
|
```
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
clamav "github.com/ca110us/go-clamav"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// new clamav instance
|
||||||
|
c := new(clamav.Clamav)
|
||||||
|
err := c.Init(clamav.SCAN_OPTIONS{
|
||||||
|
General: 0,
|
||||||
|
Parse: clamav.CL_SCAN_PARSE_ARCHIVE | clamav.CL_SCAN_PARSE_ELF,
|
||||||
|
Heuristic: 0,
|
||||||
|
Mail: 0,
|
||||||
|
Dev: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// free clamav memory
|
||||||
|
defer c.Free()
|
||||||
|
|
||||||
|
// load db
|
||||||
|
signo, err := c.LoadDB("./db", uint(clamav.CL_DB_DIRECTORY))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Println("db load succeed:", signo)
|
||||||
|
|
||||||
|
// compile engine
|
||||||
|
err = c.CompileEngine()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.EngineSetNum(clamav.CL_ENGINE_MAX_SCANSIZE, 1024*1024*40)
|
||||||
|
c.EngineSetNum(clamav.CL_ENGINE_MAX_SCANTIME, 9000)
|
||||||
|
// fmt.Println(c.EngineGetNum(clamav.CL_ENGINE_MAX_SCANSIZE))
|
||||||
|
|
||||||
|
// scan
|
||||||
|
scanned, virusName, ret := c.ScanFile("./test_file/nmap")
|
||||||
|
fmt.Println(scanned, virusName, ret)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ go run main.go
|
||||||
|
|
||||||
|
db load succeed: 9263
|
||||||
|
209 YARA.Unix_Packer_UpxDetail.UNOFFICIAL Virus(es) detected
|
||||||
|
```
|
||||||
|
|
||||||
## Reference
|
## Reference
|
||||||
[mirtchovski/clamav](https://github.com/mirtchovski/clamav)
|
[mirtchovski/clamav](https://github.com/mirtchovski/clamav)
|
||||||
|
|||||||
64
README_CN.md
64
README_CN.md
@@ -1,4 +1,5 @@
|
|||||||
# go-clamav
|
# go-clamav
|
||||||
|
[](https://pkg.go.dev/github.com/ca110us/go-clamav?tab=doc)
|
||||||
|
|
||||||
go-clamav 是 go 语言对 [libclamav](https://docs.clamav.net/manual/Development/libclamav.html) 的封装
|
go-clamav 是 go 语言对 [libclamav](https://docs.clamav.net/manual/Development/libclamav.html) 的封装
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@ apt-get update && apt-get install -y \
|
|||||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
||||||
```
|
```
|
||||||
|
|
||||||
Download the source from the clamav [downloads page](https://www.clamav.net/downloads)
|
从 clamav 官方下载源码 [downloads page](https://www.clamav.net/downloads)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar xzf clamav-[ver].tar.gz
|
tar xzf clamav-[ver].tar.gz
|
||||||
@@ -35,7 +36,66 @@ sudo cmake --build . --target install
|
|||||||
其他 Linux 发行版参照 [clamav documentation](https://docs.clamav.net/manual/Installing/Installing-from-source-Unix.html)
|
其他 Linux 发行版参照 [clamav documentation](https://docs.clamav.net/manual/Installing/Installing-from-source-Unix.html)
|
||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
参考 `example` 目录
|
```bash
|
||||||
|
$ cd example && cat main.go
|
||||||
|
```
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
clamav "github.com/ca110us/go-clamav"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// new clamav instance
|
||||||
|
c := new(clamav.Clamav)
|
||||||
|
err := c.Init(clamav.SCAN_OPTIONS{
|
||||||
|
General: 0,
|
||||||
|
Parse: clamav.CL_SCAN_PARSE_ARCHIVE | clamav.CL_SCAN_PARSE_ELF,
|
||||||
|
Heuristic: 0,
|
||||||
|
Mail: 0,
|
||||||
|
Dev: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// free clamav memory
|
||||||
|
defer c.Free()
|
||||||
|
|
||||||
|
// load db
|
||||||
|
signo, err := c.LoadDB("./db", uint(clamav.CL_DB_DIRECTORY))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Println("db load succeed:", signo)
|
||||||
|
|
||||||
|
// compile engine
|
||||||
|
err = c.CompileEngine()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.EngineSetNum(clamav.CL_ENGINE_MAX_SCANSIZE, 1024*1024*40)
|
||||||
|
c.EngineSetNum(clamav.CL_ENGINE_MAX_SCANTIME, 9000)
|
||||||
|
// fmt.Println(c.EngineGetNum(clamav.CL_ENGINE_MAX_SCANSIZE))
|
||||||
|
|
||||||
|
// scan
|
||||||
|
scanned, virusName, ret := c.ScanFile("./test_file/nmap")
|
||||||
|
fmt.Println(scanned, virusName, ret)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ go run main.go
|
||||||
|
|
||||||
|
db load succeed: 9263
|
||||||
|
209 YARA.Unix_Packer_UpxDetail.UNOFFICIAL Virus(es) detected
|
||||||
|
```
|
||||||
|
|
||||||
## 参考
|
## 参考
|
||||||
[mirtchovski/clamav](https://github.com/mirtchovski/clamav)
|
[mirtchovski/clamav](https://github.com/mirtchovski/clamav)
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ func (c *Clamav) CompileEngine() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNum sets a number in the specified field of the engine configuration.
|
// EngineSetNum sets a number in the specified field of the engine configuration.
|
||||||
// Certain fields accept only 32-bit numbers, silently truncating the higher bits
|
// Certain fields accept only 32-bit numbers, silently truncating the higher bits
|
||||||
// of the engine config. See dat.go for more information.
|
// of the engine config. See dat.go for more information.
|
||||||
func (c *Clamav) EngineSetNum(field EngineField, num uint64) error {
|
func (c *Clamav) EngineSetNum(field EngineField, num uint64) error {
|
||||||
@@ -162,7 +162,7 @@ func (c *Clamav) EngineSetNum(field EngineField, num uint64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNum acquires a number from the specified field of the engine configuration. Tests show that
|
// EngineGetNum acquires a number from the specified field of the engine configuration. Tests show that
|
||||||
// the ClamAV library will not overflow 32-bit fields, so a GetNum on a 32-bit field can safely be
|
// the ClamAV library will not overflow 32-bit fields, so a GetNum on a 32-bit field can safely be
|
||||||
// cast to uint32.
|
// cast to uint32.
|
||||||
func (c *Clamav) EngineGetNum(field EngineField) (uint64, error) {
|
func (c *Clamav) EngineGetNum(field EngineField) (uint64, error) {
|
||||||
@@ -183,7 +183,7 @@ func (c *Clamav) Free() int {
|
|||||||
return int(C.cl_engine_free((*C.struct_cl_engine)(c.engine)))
|
return int(C.cl_engine_free((*C.struct_cl_engine)(c.engine)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScanMapCb scans custom data
|
// ScanMapCB scans custom data
|
||||||
func (c *Clamav) ScanMapCB(fmap *Fmap, fileName string, context interface{}) (uint, string, error) {
|
func (c *Clamav) ScanMapCB(fmap *Fmap, fileName string, context interface{}) (uint, string, error) {
|
||||||
var scanned C.ulong
|
var scanned C.ulong
|
||||||
var virusName *C.char
|
var virusName *C.char
|
||||||
@@ -235,7 +235,7 @@ func (c *Clamav) ScanFile(path string) (uint, string, error) {
|
|||||||
return 0, "", Strerr(ret)
|
return 0, "", Strerr(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScanFileCb scans a single file for viruses using the ClamAV databases and using callbacks from
|
// ScanFileCB scans a single file for viruses using the ClamAV databases and using callbacks from
|
||||||
// ClamAV to read/resolve file data. The callbacks can be used to scan files in memory, to scan multiple
|
// ClamAV to read/resolve file data. The callbacks can be used to scan files in memory, to scan multiple
|
||||||
// files inside archives, etc. The function returns the number of bytes
|
// files inside archives, etc. The function returns the number of bytes
|
||||||
// read from the file (if found), the virus name and an error code.
|
// read from the file (if found), the virus name and an error code.
|
||||||
|
|||||||
@@ -38,14 +38,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.EngineSetNum(clamav.CL_ENGINE_MAX_SCANSIZE, 1024*1024*40)
|
c.EngineSetNum(clamav.CL_ENGINE_MAX_SCANSIZE, 1024*1024*40)
|
||||||
c.EngineSetNum(clamav.CL_ENGINE_PCRE_MAX_FILESIZE, 1024*1024*20)
|
|
||||||
c.EngineSetNum(clamav.CL_ENGINE_MAX_SCANTIME, 9000)
|
c.EngineSetNum(clamav.CL_ENGINE_MAX_SCANTIME, 9000)
|
||||||
c.EngineSetNum(clamav.CL_ENGINE_PCRE_MATCH_LIMIT, 1000)
|
// fmt.Println(c.EngineGetNum(clamav.CL_ENGINE_MAX_SCANSIZE))
|
||||||
c.EngineSetNum(clamav.CL_ENGINE_PCRE_RECMATCH_LIMIT, 500)
|
|
||||||
|
|
||||||
// fmt.Println(c.EngineGetNum(clamav.CL_ENGINE_PCRE_RECMATCH_LIMIT))
|
|
||||||
|
|
||||||
// scan
|
// scan
|
||||||
scanned, msg, err := c.ScanFile("./test_file/nmap")
|
scanned, virusName, ret := c.ScanFile("./test_file/nmap")
|
||||||
fmt.Println(scanned, msg, err)
|
fmt.Println(scanned, virusName, ret)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user