1+ /*
2+ The MIT License (MIT)
3+
4+ Copyright (c) 2020 Klaus Post
5+
6+ Permission is hereby granted, free of charge, to any person obtaining a copy
7+ of this software and associated documentation files (the "Software"), to deal
8+ in the Software without restriction, including without limitation the rights
9+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ copies of the Software, and to permit persons to whom the Software is
11+ furnished to do so, subject to the following conditions:
12+
13+ The above copyright notice and this permission notice shall be included in
14+ all copies or substantial portions of the Software.
15+
16+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ THE SOFTWARE.
23+ */
24+
125package main
226
327import (
@@ -10,6 +34,27 @@ import (
1034 "path/filepath"
1135)
1236
37+ var patterns = []struct {
38+ desc string
39+ search , replace []byte
40+ }{
41+ {
42+ desc : "Ryzen Master v.1.5 -> v2.2" ,
43+ search : []byte {0x44 , 0x39 , 0x6D , 0xA8 , 0x0F , 0x84 , 0xF7 },
44+ replace : []byte {0x44 , 0x39 , 0x6D , 0xA8 , 0x90 , 0xe9 , 0xf7 },
45+ },
46+ {
47+ desc : "Ryzen Master v2.3 -> ?" ,
48+ search : []byte {0x44 , 0x39 , 0xad , 0xf8 , 0 , 0 , 0 , 0x0f , 0x84 },
49+ replace : []byte {0x44 , 0x39 , 0xad , 0xf8 , 0 , 0 , 0 , 0x90 , 0xe9 },
50+ },
51+ {
52+ desc : "Ryzen Master Threadripper" ,
53+ search : []byte {0x00 , 0x39 , 0x7D , 0x90 , 0x0F , 0x84 , 0xE8 , 0x00 },
54+ replace : []byte {0x00 , 0x39 , 0x7D , 0x90 , 0x90 , 0xE9 , 0xE8 , 0x00 },
55+ },
56+ }
57+
1358func init () {
1459 flag .Usage = func () {
1560 fmt .Println ("Usage: ryzen-master-vbs-patch [-p=patched] \" AMD Ryzen Master.exe\" " )
@@ -23,100 +68,39 @@ func main() {
2368 flag .Parse ()
2469 args := flag .Args ()
2570 if len (args ) == 0 {
26- flag .Usage ()
27- return
71+ args = []string {"AMD Ryzen Master.exe" }
2872 }
2973
3074 for _ , f := range args {
3175 dir , file := filepath .Split (f )
3276 err := patch (filepath .Join (dir , file ), filepath .Join (dir , * prefix + file ))
3377 switch err {
3478 case nil :
35- case errCannotPatch :
36- fmt .Println (err )
37- err = patchAlt (filepath .Join (dir , file ), filepath .Join (dir , * prefix + file ))
38- if err == errCannotPatch {
39- fmt .Println (err )
40- fmt .Println ("Skipping file..." )
41- } else if err != nil {
42- fmt .Println (err )
43- os .Exit (1 )
44- }
4579 default :
4680 fmt .Println (err )
4781 os .Exit (1 )
4882 }
4983 }
5084}
5185
52- var errCannotPatch = errors .New ("byte sequence not found" )
53-
54- var search = []byte {0x44 , 0x39 , 0x6D , 0xA8 , 0x0F , 0x84 , 0xF7 }
55- var replace = []byte {0x44 , 0x39 , 0x6D , 0xA8 , 0x90 , 0xe9 , 0xf7 }
86+ var errCannotPatch = errors .New ("no byte sequence not found" )
5687
5788func patch (in string , out string ) error {
58- fmt .Println ( "Applying v2 patch on " , in )
89+ fmt .Printf ( "Reading %q \n " , in )
5990 b , err := ioutil .ReadFile (in )
6091 if err != nil {
6192 return err
6293 }
63- c := bytes .Count (b , search )
64- fmt .Println ("Matching byte sequences:" , c , "(should be 1)" )
65- if c != 1 {
66- return errCannotPatch
67- }
68- b = bytes .Replace (b , search , replace , - 1 )
69- fmt .Println ("Writing to" , out )
70- err = ioutil .WriteFile (out , b , 0 )
71- if err != nil {
72- return err
73- }
74- return nil
75- }
76-
77- var searchAlt = []byte {0x00 , 0x39 , 0x7D , 0x90 , 0x0F , 0x84 , 0xE8 , 0x00 }
78- var replaceAlt = []byte {0x00 , 0x39 , 0x7D , 0x90 , 0x90 , 0xE9 , 0xE8 , 0x00 }
79-
80- func patchAlt (in string , out string ) error {
81- fmt .Println ("Applying alternative patch on" , in )
82- b , err := ioutil .ReadFile (in )
83- if err != nil {
84- return err
85- }
86- c := bytes .Count (b , searchAlt )
87- fmt .Println ("Matching byte sequences:" , c , "(should be 1)" )
88- if c != 1 {
89- return errCannotPatch
90- }
91- b = bytes .Replace (b , searchAlt , replaceAlt , - 1 )
92- fmt .Println ("Writing to" , out )
93- err = ioutil .WriteFile (out , b , 0 )
94- if err != nil {
95- return err
94+ for i , pattern := range patterns {
95+ c := bytes .Count (b , pattern .search )
96+ fmt .Printf ("%d. Checking patch for %q. " , i , pattern .desc )
97+ fmt .Println ("Matching byte sequences:" , c , "(should be 1)" )
98+ if c != 1 {
99+ continue
100+ }
101+ b = bytes .Replace (b , pattern .search , pattern .replace , - 1 )
102+ fmt .Printf ("Writing to %q\n " , out )
103+ return ioutil .WriteFile (out , b , os .ModePerm )
96104 }
97- return nil
105+ return errCannotPatch
98106}
99-
100- /*
101- The MIT License (MIT)
102-
103- Copyright (c) 2020 Klaus Post
104-
105- Permission is hereby granted, free of charge, to any person obtaining a copy
106- of this software and associated documentation files (the "Software"), to deal
107- in the Software without restriction, including without limitation the rights
108- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
109- copies of the Software, and to permit persons to whom the Software is
110- furnished to do so, subject to the following conditions:
111-
112- The above copyright notice and this permission notice shall be included in
113- all copies or substantial portions of the Software.
114-
115- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
116- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
117- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
118- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
119- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
120- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
121- THE SOFTWARE.
122- */
0 commit comments