mirror of
https://github.com/Ed1s0nZ/PrivHunterAI.git
synced 2025-05-05 10:17:01 +00:00
Update tools.go
This commit is contained in:
parent
2cf5962f56
commit
9b172c3555
93
tools.go
93
tools.go
@ -2,9 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -152,32 +152,22 @@ func generateHTTPRequest(input string) (string, error) {
|
|||||||
// 构建 Header
|
// 构建 Header
|
||||||
var headerLines []string
|
var headerLines []string
|
||||||
for key, values := range req.Header {
|
for key, values := range req.Header {
|
||||||
|
if strings.ToLower(key) == "content-length" {
|
||||||
|
continue // 跳过 Content-Length
|
||||||
|
}
|
||||||
if len(values) > 0 {
|
if len(values) > 0 {
|
||||||
// 将多个值用逗号分隔
|
// 将多个值用逗号分隔
|
||||||
headerLines = append(headerLines, fmt.Sprintf("%s: %s", key, strings.Join(values, ",")))
|
headerLines = append(headerLines, fmt.Sprintf("%s: %s", key, strings.Join(values, ",")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 特殊处理 Origin 和 Referer
|
decodedBytes, err := base64.StdEncoding.DecodeString(req.Body)
|
||||||
if val, ok := req.Header["Origin"]; ok && len(val) > 0 {
|
if err != nil {
|
||||||
origin := val[0]
|
fmt.Println("解码错误:", err)
|
||||||
parsedOrigin, err := url.Parse(origin)
|
|
||||||
if err == nil {
|
|
||||||
headerLines = append(headerLines, fmt.Sprintf("Origin: %s", parsedOrigin.String()))
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if val, ok := req.Header["Referer"]; ok && len(val) > 0 {
|
|
||||||
referer := val[0]
|
|
||||||
parsedReferer, err := url.Parse(referer)
|
|
||||||
if err == nil {
|
|
||||||
headerLines = append(headerLines, fmt.Sprintf("Referer: %s", parsedReferer.String()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果 Body 不为空,计算 Content-Length
|
// 如果 Body 不为空,计算 Content-Length
|
||||||
if req.Body != "" {
|
if string(decodedBytes) != "" {
|
||||||
contentLength := len(req.Body)
|
contentLength := len(string(decodedBytes))
|
||||||
headerLines = append(headerLines, fmt.Sprintf("Content-Length: %d", contentLength))
|
headerLines = append(headerLines, fmt.Sprintf("Content-Length: %d", contentLength))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,9 +178,72 @@ func generateHTTPRequest(input string) (string, error) {
|
|||||||
buffer.WriteString(line + "\n")
|
buffer.WriteString(line + "\n")
|
||||||
}
|
}
|
||||||
if req.Body != "" {
|
if req.Body != "" {
|
||||||
buffer.WriteString("\n" + req.Body)
|
buffer.WriteString("\n" + string(decodedBytes))
|
||||||
} else {
|
} else {
|
||||||
buffer.WriteString("\n\n")
|
buffer.WriteString("\n\n")
|
||||||
}
|
}
|
||||||
return buffer.String(), nil
|
return buffer.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Levenshtein 计算两个字符串的Levenshtein距离
|
||||||
|
func Levenshtein(a, b string) int {
|
||||||
|
lenA := len(a)
|
||||||
|
lenB := len(b)
|
||||||
|
if lenA == 0 {
|
||||||
|
return lenB
|
||||||
|
}
|
||||||
|
if lenB == 0 {
|
||||||
|
return lenA
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建距离矩阵
|
||||||
|
dist := make([][]int, lenA+1)
|
||||||
|
for i := range dist {
|
||||||
|
dist[i] = make([]int, lenB+1)
|
||||||
|
dist[i][0] = i
|
||||||
|
}
|
||||||
|
for j := 0; j <= lenB; j++ {
|
||||||
|
dist[0][j] = j
|
||||||
|
}
|
||||||
|
|
||||||
|
// 填充距离矩阵
|
||||||
|
for i := 1; i <= lenA; i++ {
|
||||||
|
for j := 1; j <= lenB; j++ {
|
||||||
|
cost := 1
|
||||||
|
if a[i-1] == b[j-1] {
|
||||||
|
cost = 0
|
||||||
|
}
|
||||||
|
dist[i][j] = min(
|
||||||
|
dist[i-1][j]+1, // 删除
|
||||||
|
dist[i][j-1]+1, // 插入
|
||||||
|
dist[i-1][j-1]+cost, // 替换
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dist[lenA][lenB]
|
||||||
|
}
|
||||||
|
|
||||||
|
// min 返回三个整数中的最小值
|
||||||
|
func min(a, b, c int) int {
|
||||||
|
if a < b {
|
||||||
|
if a < c {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
if b < c {
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringSimilarity 计算两个字符串的相似度 (0-1之间)
|
||||||
|
func StringSimilarity(a, b string) float64 {
|
||||||
|
distance := Levenshtein(a, b)
|
||||||
|
maxLength := len(a)
|
||||||
|
if len(b) > maxLength {
|
||||||
|
maxLength = len(b)
|
||||||
|
}
|
||||||
|
return 1.0 - float64(distance)/float64(maxLength)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user