@@ -17,9 +17,6 @@ public void Discover() {
1717 if ( functionHandler is null || vmTypeDef is null )
1818 throw new ApplicationException ( "Could not locate VmProtectFunctionHandler." ) ;
1919
20- Logger . Debug ( "Found VmTypeDef, MDToken 0x{0:X4}" , vmTypeDef . MDToken ) ;
21- Logger . Debug ( "Found VMPFunctionHandler, MDToken 0x{0:X4}" , functionHandler . MDToken ) ;
22-
2320 Ctx . VmRuntimeStructure = new VmRuntimeStructure {
2421 FunctionHandler = functionHandler ,
2522 VmTypeDef = vmTypeDef
@@ -46,19 +43,41 @@ private static (MethodDef vmpHandler, TypeDef vmTypeDef) LocateVmHandlerAndTypDe
4643 TypeDef vmTypeDef = null ;
4744
4845 foreach ( var type in module . GetTypes ( ) ) {
46+ // search pattern for 3.5.1 and older
4947 vmpHandler = type . Methods . Where ( IsVmpFunctionHandler )
50- . FirstOrDefault ( method => new LocalTypes ( method ) . All ( VmpFunctionHandlerLocals ) ) ;
48+ . FirstOrDefault ( method => new LocalTypes ( method ) . All ( VmpFunctionHandlerLocals ) ) ?? type . Methods
49+ // Search for pattern in 3.6.0
50+ . Where ( IsVmpFunctionHandlerNew )
51+ . FirstOrDefault ( method => new LocalTypes ( method ) . All ( VmpFunctionHandlerLocals ) ) ;
5152
5253 if ( vmpHandler == null )
5354 continue ;
5455
5556 vmTypeDef = type ;
57+
58+ Logger . Info ( "Found VmTypeDef, MDToken 0x{0:X4}" , vmTypeDef . MDToken ) ;
59+ Logger . Info ( "Found VMPFunctionHandler, MDToken 0x{0:X4}" , vmpHandler . MDToken ) ;
5660 break ;
5761 }
5862
63+ if ( vmpHandler is null ) {
64+ Logger . Error ( "Could not find VMP Method handler? Are you using supported version of VMP?" ) ;
65+ Console . ReadKey ( ) ;
66+ }
67+
5968 return ( vmpHandler , vmTypeDef ) ;
6069 }
6170
71+ /// <summary>
72+ /// Checks RetType and Params, etc of MethodDef
73+ /// </summary>
74+ /// <param name="method"></param>
75+ /// <returns>Does method match the requirements</returns>
76+ private static bool IsVmpFunctionHandlerNew ( MethodDef method ) {
77+ return method is { IsStatic : false } && method . MethodSig . GetParamCount ( ) == 0 ;
78+ }
79+
80+
6281 /// <summary>
6382 /// Checks RetType and Params, etc of MethodDef
6483 /// </summary>
@@ -70,7 +89,6 @@ private static bool IsVmpFunctionHandler(MethodDef method) {
7089 method . MethodSig . Params [ 0 ] . GetElementType ( ) == ElementType . Class &&
7190 method . MethodSig . Params [ 1 ] . GetElementType ( ) == ElementType . Boolean ;
7291 }
73-
7492 #endregion
7593 }
7694
0 commit comments