mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 14:06:44 +08:00
refactor: 将auto.json嵌入编译文件中
- 使用Go embed包将AV/EDR规则数据库嵌入到可执行文件 - 移除对外部auto.json文件的依赖 - 提高工具的便携性和独立性 - 将auto.json移动到avdetect插件目录 - 更新loadAVDatabase方法使用嵌入数据
This commit is contained in:
parent
4a33b89738
commit
1cfb21ed64
@ -3,6 +3,7 @@ package avdetect
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@ -18,6 +19,9 @@ import (
|
|||||||
"github.com/shadow1ng/fscan/plugins/local"
|
"github.com/shadow1ng/fscan/plugins/local"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed auto.json
|
||||||
|
var embeddedAVDatabase []byte
|
||||||
|
|
||||||
// AVDetectPlugin AV/EDR检测插件
|
// AVDetectPlugin AV/EDR检测插件
|
||||||
type AVDetectPlugin struct {
|
type AVDetectPlugin struct {
|
||||||
*local.BaseLocalPlugin
|
*local.BaseLocalPlugin
|
||||||
@ -325,41 +329,16 @@ func (p *AVDetectPlugin) ScanLocal(ctx context.Context, info *common.HostInfo) (
|
|||||||
|
|
||||||
// loadAVDatabase 加载AV/EDR数据库
|
// loadAVDatabase 加载AV/EDR数据库
|
||||||
func (p *AVDetectPlugin) loadAVDatabase() error {
|
func (p *AVDetectPlugin) loadAVDatabase() error {
|
||||||
// 尝试多个可能的配置文件路径
|
// 首先尝试使用嵌入的数据库
|
||||||
possiblePaths := []string{
|
common.LogDebug("使用嵌入的AV/EDR规则数据库")
|
||||||
p.configPath,
|
|
||||||
"auto.json",
|
|
||||||
filepath.Join(".", "auto.json"),
|
|
||||||
filepath.Join("config", "auto.json"),
|
|
||||||
filepath.Join("..", "auto.json"),
|
|
||||||
}
|
|
||||||
|
|
||||||
var configData []byte
|
|
||||||
var err error
|
|
||||||
var usedPath string
|
|
||||||
|
|
||||||
for _, path := range possiblePaths {
|
|
||||||
configData, err = os.ReadFile(path)
|
|
||||||
if err == nil {
|
|
||||||
usedPath = path
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
err := json.Unmarshal(embeddedAVDatabase, &p.avDatabase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("无法找到配置文件 auto.json: %v", err)
|
return fmt.Errorf("解析嵌入的AV数据库失败: %v", err)
|
||||||
}
|
|
||||||
|
|
||||||
common.LogDebug(fmt.Sprintf("使用配置文件: %s", usedPath))
|
|
||||||
|
|
||||||
// 解析JSON
|
|
||||||
err = json.Unmarshal(configData, &p.avDatabase)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("解析配置文件失败: %v", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(p.avDatabase) == 0 {
|
if len(p.avDatabase) == 0 {
|
||||||
return fmt.Errorf("配置文件为空或格式错误")
|
return fmt.Errorf("嵌入的AV数据库为空或格式错误")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user