From 647860f1707438ededaf39d323db4a9a57afe403 Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Thu, 7 Aug 2025 08:05:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=B8=85=E7=90=86=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=AE=BF=E9=97=AE=E7=9A=84=E6=AD=BB=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除项目中无法访问的死代码: - 移除 Scanner.go 中的 logScanPlan 函数 - 移除 match_engine.go 中的 containsPort 和 IsPortMatch 函数 - 清理相关的未使用导入:strings、strconv 优化效果: - 减少约60行无用代码 - 消除编译器 unreachable func 警告 - 提升代码可维护性和可读性 - 优化二进制文件大小 这些函数在参数精简过程中失去了调用者,成为死代码。 移除后核心功能保持完整,通过完整测试验证。 --- Core/Scanner.go | 19 ------------ Core/portfinger/match_engine.go | 53 --------------------------------- 2 files changed, 72 deletions(-) diff --git a/Core/Scanner.go b/Core/Scanner.go index 8d14612..fc1db36 100644 --- a/Core/Scanner.go +++ b/Core/Scanner.go @@ -6,7 +6,6 @@ import ( "github.com/shadow1ng/fscan/common/i18n" "github.com/shadow1ng/fscan/webscan/lib" "strconv" - "strings" "sync" "sync/atomic" ) @@ -140,24 +139,6 @@ func prepareScanTasks(targets []common.HostInfo, pluginsToRun []string, isCustom return tasks } -// logScanPlan 输出扫描计划信息 -func logScanPlan(tasks []ScanTask) { - // 统计每个插件的目标数量 - pluginCounts := make(map[string]int) - for _, task := range tasks { - pluginCounts[task.pluginName]++ - } - - // 构建扫描计划信息 - var planInfo strings.Builder - planInfo.WriteString("扫描计划:\n") - - for plugin, count := range pluginCounts { - planInfo.WriteString(fmt.Sprintf(" - %s: %d 个目标\n", plugin, count)) - } - - common.LogBase(planInfo.String()) -} // 调度单个扫描任务 func scheduleScanTask(pluginName string, target common.HostInfo, ch *chan struct{}, wg *sync.WaitGroup) { diff --git a/Core/portfinger/match_engine.go b/Core/portfinger/match_engine.go index c785730..180f73c 100644 --- a/Core/portfinger/match_engine.go +++ b/Core/portfinger/match_engine.go @@ -3,7 +3,6 @@ package portfinger import ( "fmt" "regexp" - "strconv" "strings" "github.com/shadow1ng/fscan/common" @@ -95,49 +94,6 @@ func (p *Probe) getSoftMatch(data string) (softMatch Match, err error) { return softMatch, nil } -// containsPort 检查指定端口是否在探测器的端口范围内(私有方法) -func (p *Probe) containsPort(testPort int) bool { - common.LogDebug(fmt.Sprintf("检查端口 %d 是否在探测器端口范围内: %s", testPort, p.Ports)) - - // 检查单个端口 - ports := strings.Split(p.Ports, ",") - for _, port := range ports { - port = strings.TrimSpace(port) - cmpPort, err := strconv.Atoi(port) - if err == nil && testPort == cmpPort { - common.LogDebug(fmt.Sprintf("端口 %d 匹配单个端口", testPort)) - return true - } - } - - // 检查端口范围 - for _, port := range ports { - port = strings.TrimSpace(port) - if strings.Contains(port, "-") { - portRange := strings.Split(port, "-") - if len(portRange) != 2 { - common.LogDebug("无效的端口范围格式: " + port) - continue - } - - start, err1 := strconv.Atoi(strings.TrimSpace(portRange[0])) - end, err2 := strconv.Atoi(strings.TrimSpace(portRange[1])) - - if err1 != nil || err2 != nil { - common.LogDebug(fmt.Sprintf("解析端口范围失败: %s", port)) - continue - } - - if testPort >= start && testPort <= end { - common.LogDebug(fmt.Sprintf("端口 %d 在范围 %d-%d 内", testPort, start, end)) - return true - } - } - } - - common.LogDebug(fmt.Sprintf("端口 %d 不在探测器端口范围内", testPort)) - return false -} // MatchPattern 检查响应是否与匹配规则匹配 func (m *Match) MatchPattern(response []byte) bool { @@ -161,13 +117,4 @@ func (m *Match) MatchPattern(response []byte) bool { return matched } -// IsPortMatch 检查探测器是否适用于指定端口 -func (p *Probe) IsPortMatch(port int) bool { - // 如果没有指定端口范围,认为适用于所有端口 - if p.Ports == "" { - return true - } - - return p.containsPort(port) -}