@@ -45,9 +45,6 @@ public ResourceResolver(ModuleDefMD module, ResourceResolver oldOne) {
4545 }
4646
4747 public void Find ( ISimpleDeobfuscator simpleDeobfuscator ) {
48- var additionalTypes = new string [ ] {
49- "System.String" ,
50- } ;
5148 foreach ( var type in module . Types ) {
5249 if ( type . BaseType == null || type . BaseType . FullName != "System.Object" )
5350 continue ;
@@ -59,10 +56,8 @@ public void Find(ISimpleDeobfuscator simpleDeobfuscator) {
5956 if ( ! DotNetUtils . IsMethod ( method , "System.Reflection.Assembly" , "(System.Object,System.ResolveEventArgs)" ) &&
6057 ! DotNetUtils . IsMethod ( method , "System.Reflection.Assembly" , "(System.Object,System.Object)" ) )
6158 continue ;
62- if ( method . Body . ExceptionHandlers . Count != 0 )
63- continue ;
64- var initMethod = GetResourceDecrypterInitMethod ( method , additionalTypes , true ) ??
65- GetResourceDecrypterInitMethod ( method , additionalTypes , false ) ;
59+ var initMethod = GetResourceDecrypterInitMethod ( method , true ) ??
60+ GetResourceDecrypterInitMethod ( method , false ) ;
6661 if ( initMethod == null )
6762 continue ;
6863
@@ -72,14 +67,14 @@ public void Find(ISimpleDeobfuscator simpleDeobfuscator) {
7267 }
7368 }
7469
75- MethodDef GetResourceDecrypterInitMethod ( MethodDef method , string [ ] additionalTypes , bool checkResource ) {
76- if ( encryptedResource . CouldBeResourceDecrypter ( method , additionalTypes , checkResource ) )
70+ MethodDef GetResourceDecrypterInitMethod ( MethodDef method , bool checkResource ) {
71+ if ( encryptedResource . CouldBeResourceDecrypter ( method , null , checkResource ) )
7772 return method ;
7873
7974 foreach ( var calledMethod in DotNetUtils . GetCalledMethods ( module , method ) ) {
8075 if ( ! DotNetUtils . IsMethod ( calledMethod , "System.Void" , "()" ) )
8176 continue ;
82- if ( encryptedResource . CouldBeResourceDecrypter ( calledMethod , additionalTypes , checkResource ) )
77+ if ( encryptedResource . CouldBeResourceDecrypter ( calledMethod , null , checkResource ) )
8378 return calledMethod ;
8479 }
8580
@@ -157,13 +152,25 @@ public EmbeddedResource MergeResources() {
157152 if ( encryptedResource . Resource == null )
158153 return null ;
159154 DeobUtils . DecryptAndAddResources ( module , encryptedResource . Resource . Name . String , ( ) => {
155+ byte [ ] decrypted ;
156+ try {
157+ decrypted = encryptedResource . Decrypt ( ) ;
158+ }
159+ catch {
160+ return null ;
161+ }
162+
163+ if ( decrypted . Length < 64 )
164+ throw new Exception ( "Decrypted resource data has length " + decrypted . Length ) ;
165+ if ( decrypted [ 0 ] == 0x4D && decrypted [ 1 ] == 0x5A && decrypted [ 62 ] == 0 && decrypted [ 63 ] == 0 )
166+ return decrypted ;
160167
161168 try {
162- return QuickLZ . Decompress ( encryptedResource . Decrypt ( ) ) ;
169+ return QuickLZ . Decompress ( decrypted ) ;
163170 }
164171 catch {
165172 try {
166- return DeobUtils . Inflate ( encryptedResource . Decrypt ( ) , true ) ;
173+ return DeobUtils . Inflate ( decrypted , true ) ;
167174 }
168175 catch {
169176 return null ;
0 commit comments