Advertisement
BaSs_HaXoR

DNGUARD - Jit Hook Unpack Method

Oct 31st, 2014
1,685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. //SOURCE: http://www.reteam.org/board/archive/index.php?t-2562.html
  2.  
  3. //DNGuard uses some tricks to stop naive generic JIT-hook-based unpackers from working. Example code from lgcoree.cpp by Daniel Pistelli:
  4.  
  5. int __stdcall my_compileMethod(ULONG_PTR classthis, ICorJitInfo *comp, CORINFO_METHOD_INFO *info, unsigned flags, BYTE **nativeEntry, ULONG *nativeSizeOfCode)
  6. ...
  7. // call original method
  8. int nRet = compileMethod(classthis, comp, info, flags, nativeEntry, nativeSizeOfCode); //Bug1: errorcode is not checked
  9. DisplayMethodAndCalls(comp, info);
  10. ...
  11. return nRet;
  12. }
  13.  
  14. VOID DisplayMethodAndCalls(ICorJitInfo *comp, CORINFO_METHOD_INFO *info)
  15. {
  16. ...
  17. szMethodName = comp->getMethodName(info->ftn, &szClassName); //Bug2: CRASH!
  18. ...
  19. }
  20. /*
  21. Bug 1: on first pass, DNGuard sends invalid IL to JIT. Unpacker should check the return value and handle error appropriately. Lgcoree dumps the invalid IL instead.
  22. Bug 2: DNGuard passes evil CORINFO_METHOD_HANDLE to JIT compiler. Specifically, ICorMethodInfo->getMethodName() is invalid. Lgcoree does not check that and crashes with access violation. Proper unpacker should always call ICorMethodInfo->getMethodName() from .NET framework or use method tokens instead of names.
  23.  
  24. Have fun!*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement