@@ -15,6 +15,7 @@ public class MessageDeobfuscationTest : TestBase {
1515 "Exception" ,
1616 " at MessageDeobfuscation.Class.NestedClass.Method(String )" ,
1717 " at MessageDeobfuscation.Program.Main()" ) ;
18+ readonly string _password = "password" ;
1819
1920 public MessageDeobfuscationTest ( ITestOutputHelper outputHelper ) : base ( outputHelper ) { }
2021
@@ -96,6 +97,23 @@ public static IEnumerable<object[]> RenameModeAndExpectedObfuscatedOutput() =>
9697 }
9798 } ;
9899
100+ [ Fact ]
101+ [ Trait ( "Category" , "Protection" ) ]
102+ public async Task CheckRandomPassword ( ) {
103+ string actualPassword1 = null , actualPassword2 = null ;
104+ await RunDeobfuscationWithPassword ( true , "0" , Array . Empty < string > ( ) , outputPath => {
105+ actualPassword1 = File . ReadAllText ( Path . Combine ( outputPath , CoreComponent . PasswordFileName ) ) ;
106+ Assert . True ( Guid . TryParse ( actualPassword1 , out _ ) ) ;
107+ return Task . Delay ( 0 ) ;
108+ } ) ;
109+ await RunDeobfuscationWithPassword ( true , "1" , Array . Empty < string > ( ) , outputPath => {
110+ actualPassword2 = File . ReadAllText ( Path . Combine ( outputPath , CoreComponent . PasswordFileName ) ) ;
111+ Assert . True ( Guid . TryParse ( actualPassword2 , out _ ) ) ;
112+ return Task . Delay ( 0 ) ;
113+ } ) ;
114+ Assert . NotEqual ( actualPassword1 , actualPassword2 ) ;
115+ }
116+
99117 [ Fact ]
100118 [ Trait ( "Category" , "Protection" ) ]
101119 [ Trait ( "Protection" , "rename" ) ]
@@ -105,36 +123,40 @@ public async Task MessageDeobfuscationWithPassword() {
105123 " at oQmpV$y2k2b9P3d6GP1cxGPuRtKaNIZvZcKpZXSfKFG8.CE8t0VDPQk9$jgv1XuRwt1k.FhsPrCLqIAaPKe7abGklvY4(String )" ,
106124 " at EbUjRcrC76NnA7RJlhQffrfp$vMGHdDfqtVFtWrAOPyD.xgIw9voebB21PlxPFA_hs60()"
107125 } ;
108- string password = "password" ;
109- await Run (
110- "MessageDeobfuscation.exe" ,
111- expectedObfuscatedOutput ,
112- new SettingItem < Protection > ( "rename" ) {
113- [ "mode" ] = "reversible" ,
114- [ "password" ] = password ,
115- [ "renPdb" ] = "true"
116- } ,
117- "Password" ,
118- postProcessAction : outputPath => {
119- var deobfuscator = new MessageDeobfuscator ( password ) ;
120- var deobfuscatedMessage = deobfuscator . DeobfuscateMessage ( string . Join ( Environment . NewLine , expectedObfuscatedOutput ) ) ;
126+ await RunDeobfuscationWithPassword ( false , "" , expectedObfuscatedOutput , outputPath => {
127+ var deobfuscator = new MessageDeobfuscator ( _password ) ;
128+ var deobfuscatedMessage =
129+ deobfuscator . DeobfuscateMessage ( string . Join ( Environment . NewLine , expectedObfuscatedOutput ) ) ;
121130
122- void CheckName ( string expectedName , string obfuscatedName ) {
123- var name = deobfuscator . DeobfuscateSymbol ( obfuscatedName , true ) ;
124- Assert . Equal ( expectedName , name ) ;
125- }
131+ void CheckName ( string expectedName , string obfuscatedName ) {
132+ var name = deobfuscator . DeobfuscateSymbol ( obfuscatedName , true ) ;
133+ Assert . Equal ( expectedName , name ) ;
134+ }
126135
127- CheckName ( "MessageDeobfuscation.Class" , "oQmpV$y2k2b9P3d6GP1cxGPuRtKaNIZvZcKpZXSfKFG8" ) ;
128- CheckName ( "NestedClass" , "CE8t0VDPQk9$jgv1XuRwt1k" ) ;
129- CheckName ( "Method" , "jevJU4p4yNrAYGqN7GkRWaI" ) ;
130- CheckName ( "Field" , "3IS4xsnUsvDQZop6e4WmNVw" ) ;
131- CheckName ( "Property" , "917VMBMNYHd0kfnnNkgeJ10" ) ;
132- CheckName ( "Event" , "AIyINk7kgFLFc73Md8Nu8Z0" ) ;
136+ CheckName ( "MessageDeobfuscation.Class" , "oQmpV$y2k2b9P3d6GP1cxGPuRtKaNIZvZcKpZXSfKFG8" ) ;
137+ CheckName ( "NestedClass" , "CE8t0VDPQk9$jgv1XuRwt1k" ) ;
138+ CheckName ( "Method" , "jevJU4p4yNrAYGqN7GkRWaI" ) ;
139+ CheckName ( "Field" , "3IS4xsnUsvDQZop6e4WmNVw" ) ;
140+ CheckName ( "Property" , "917VMBMNYHd0kfnnNkgeJ10" ) ;
141+ CheckName ( "Event" , "AIyINk7kgFLFc73Md8Nu8Z0" ) ;
133142
134- Assert . Equal ( _expectedDeobfuscatedOutput , deobfuscatedMessage ) ;
135- return Task . Delay ( 0 ) ;
136- }
137- ) ;
143+ Assert . Equal ( _expectedDeobfuscatedOutput , deobfuscatedMessage ) ;
144+ return Task . Delay ( 0 ) ;
145+ } ) ;
138146 }
147+
148+ async Task RunDeobfuscationWithPassword ( bool generatePassword , string suffix , string [ ] expectedObfuscatedOutput , Func < string , Task > postProcessAction ) => await Run (
149+ "MessageDeobfuscation.exe" ,
150+ expectedObfuscatedOutput ,
151+ new SettingItem < Protection > ( "rename" ) {
152+ [ "mode" ] = "reversible" ,
153+ [ "password" ] = _password ,
154+ [ "generatePassword" ] = generatePassword . ToString ( ) ,
155+ [ "renPdb" ] = "true" ,
156+ } ,
157+ $ "Password_{ ( generatePassword ? $ "Random{ suffix } " : $ "Hardcoded{ suffix } ") } ",
158+ checkOutput : ! generatePassword ,
159+ postProcessAction : postProcessAction
160+ ) ;
139161 }
140162}
0 commit comments