// pvfbinsearch 在 PVF 指定前缀的成员里按字节模式搜索(支持 UTF-16LE/ANSI),用于定位字符串表。 package main import ( "bytes" "encoding/hex" "flag" "fmt" "strings" platformpvf "longheng.io/server/internal/platform/pvf" ) func main() { pvfPath := flag.String("pvf", "", "input PVF") prefix := flag.String("prefix", "", "path prefix filter") patternHex := flag.String("hex", "", "hex byte pattern") max := flag.Int("max", 20, "max matches") flag.Parse() if *pvfPath == "" || *patternHex == "" { fmt.Println("need -pvf and -hex") return } pattern, err := hex.DecodeString(strings.ReplaceAll(*patternHex, " ", "")) if err != nil { panic(err) } archive, err := platformpvf.Open(*pvfPath) if err != nil { panic(err) } found := 0 scanned := 0 archive.RangePaths(func(path string) bool { if *prefix != "" && !strings.HasPrefix(path, *prefix) { return true } file, ok := archive.FindFile(path) if !ok { return true } raw, err := archive.FileRaw(file.Index) if err != nil { return true } scanned++ if idx := bytes.Index(raw, pattern); idx >= 0 { found++ fmt.Printf("MATCH %s offset=%d size=%d\n", path, idx, len(raw)) if found >= *max { return false } } return true }) fmt.Printf("scanned=%d found=%d\n", scanned, found) }