fscan/main.go
ZacharyZcR 4cd8ed5668 feat: 完成本地插件架构统一迁移
迁移所有本地插件到统一Plugin接口架构:
- socks5proxy/systemdservice: 网络代理和Linux服务持久化
- winregistry/winservice/winschtask/winstartup/winwmi: Windows持久化套件
- 所有插件消除BaseLocalPlugin继承,统一使用Plugin接口
- 保持原有功能完整性,支持跨平台编译标记
- 删除过度设计的继承体系,实现直接简洁实现
2025-08-26 14:39:53 +08:00

68 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"context"
"fmt"
"os"
"github.com/shadow1ng/fscan/app"
"github.com/shadow1ng/fscan/common"
// 导入插件
_ "github.com/shadow1ng/fscan/plugins/services" // 服务扫描插件
_ "github.com/shadow1ng/fscan/plugins/web" // Web扫描插件
_ "github.com/shadow1ng/fscan/plugins/local" // 本地扫描插件
)
func main() {
// 创建应用容器
container := app.NewContainer()
// 第一阶段:基础初始化(插件系统)
if err := container.Initialize(); err != nil {
handleError("基础初始化失败", err)
}
defer container.Cleanup()
// 第二阶段:解析配置
var info common.HostInfo
common.Flag(&info)
// 第三阶段日志初始化依赖于flag解析
logInit := &app.LoggerInitializer{}
if err := logInit.Initialize(); err != nil {
handleError("日志初始化失败", err)
}
// 第四阶段:参数解析和验证
if err := common.Parse(&info); err != nil {
handleError("参数解析失败", err)
}
// 第五阶段:输出系统初始化
outputInit := &app.OutputInitializer{}
if err := outputInit.Initialize(); err != nil {
handleError("输出初始化失败", err)
}
// 第六阶段:执行扫描
ctx := context.Background()
if err := container.RunScan(ctx, info); err != nil {
handleError("扫描失败", err)
}
}
func handleError(msg string, err error) {
// 检查是否是应用程序错误
if appErr, ok := err.(*app.AppError); ok {
common.LogError(fmt.Sprintf("%s: %s", msg, appErr.Message))
if appErr.Cause != nil {
common.LogError(fmt.Sprintf("详细错误: %v", appErr.Cause))
}
os.Exit(appErr.Code)
} else {
common.LogError(fmt.Sprintf("%s: %v", msg, err))
os.Exit(1)
}
}