Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
Print more info and make it neater.
Browse files Browse the repository at this point in the history
  • Loading branch information
klauspost committed Jan 5, 2021
1 parent 0bedc90 commit 38583ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/klauspost/ryzen-master-vbs-patch

go 1.14

require github.com/klauspost/cpuid/v2 v2.0.3
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s=
github.com/klauspost/cpuid/v2 v2.0.3 h1:DNljyrHyxlkk8139OXIAAauCwV8eQGDD6Z8YqnDXdZw=
github.com/klauspost/cpuid/v2 v2.0.3/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
"io/ioutil"
"os"
"path/filepath"

"github.com/klauspost/cpuid/v2"
)

var patterns = []struct {
Expand Down Expand Up @@ -82,7 +84,7 @@ func main() {
switch err {
case nil:
default:
fmt.Println(err)
fmt.Printf("\nError: %v", err)
os.Exit(1)
}
}
Expand All @@ -91,7 +93,10 @@ func main() {
var errCannotPatch = errors.New("no byte sequence not found")

func patch(in string, out string) error {
fmt.Printf("Reading %q\n", in)
if cpuid.CPU.BrandName != "" {
fmt.Printf("* Host CPU: %s\n\n", cpuid.CPU.BrandName)
}
fmt.Printf("Reading %q\n\n", in)
b, err := ioutil.ReadFile(in)
if err != nil {
return err
Expand All @@ -101,6 +106,9 @@ func patch(in string, out string) error {
fmt.Printf("%d. Checking patch for %q. ", i, pattern.desc)
fmt.Println("Matching byte sequences:", c, "(should be 1)")
if c != 1 {
if c = bytes.Count(b, pattern.replace); c > 0 {
fmt.Println(" -> Found", c, "replacement pattern(s). Is this already patched?\n")
}
continue
}
b = bytes.Replace(b, pattern.search, pattern.replace, -1)
Expand Down

0 comments on commit 38583ae

Please sign in to comment.