Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.1 KiB

  1. /*++
  2. *
  3. * WOW v1.0
  4. *
  5. * Copyright (c) 2002, Microsoft Corporation
  6. *
  7. * WDPM.C
  8. * WOW32 Dynamic Patch Module support
  9. *
  10. * History:
  11. * Created 22-Jan-2002 by CMJones
  12. *
  13. --*/
  14. #include "precomp.h"
  15. #pragma hdrstop
  16. // The _WDPM_C_ definition allows the global instantiation of gDpmWowFamTbls[]
  17. // and gDpmWowModuleSets[] in WOW32.DLL which are both defined in dpmtbls.h
  18. //
  19. /* For the benefit of folks grepping for gDpmWowFamTbls and gDpmWowModuleSets:
  20. const PFAMILY_TABLE gDpmWowFamTbls[] = // See above for true story.
  21. const PDPMMODULESETS gDpmWowModuleSets[] = // See above for true story.
  22. */
  23. #define _WDPM_C_
  24. #define _DPM_COMMON_
  25. #include "dpmtbls.h"
  26. #undef _WDPM_C_
  27. #undef _DPM_COMMON_
  28. MODNAME(wdpm.c);
  29. // Global DATA
  30. PFAMILY_TABLE *pgDpmWowFamTbls = (PFAMILY_TABLE *)gDpmWowFamTbls;
  31. PDPMMODULESETS *pgDpmWowModuleSets = (PDPMMODULESETS *)gDpmWowModuleSets;
  32. // Checks to see if a given function address is one that we are patching.
  33. // If so, it will return the address of the patch function.
  34. // If not, it will return the passed in address.
  35. PVOID GetDpmAddress(PVOID lpAddress)
  36. {
  37. int i, j;
  38. PFAMILY_TABLE ptFT, pgFT;
  39. PFAMILY_TABLE *ptDpmFamTbls;
  40. ptDpmFamTbls = DPMFAMTBLS(); // get array of WOW task family tables
  41. // if this task is using the global table it means it isn't patched
  42. if(!ptDpmFamTbls || (ptDpmFamTbls == pgDpmWowFamTbls))
  43. return(lpAddress);
  44. for(i = 0; i < NUM_WOW_FAMILIES_HOOKED; i++) {
  45. ptFT = ptDpmFamTbls[i]; // task family list
  46. pgFT = pgDpmWowFamTbls[i]; // global family list
  47. // if this particular family is patched...
  48. if(ptFT && ptFT != pgFT) {
  49. // Go through the family table to see...
  50. for(j = 0; j < ptFT->numHookedAPIs; j++) {
  51. // ...if the address is the same as the one in the global list
  52. if(pgFT->pfn[j] == lpAddress) {
  53. // if so, return the patched address for the task
  54. return(ptFT->pfn[j]);
  55. }
  56. }
  57. }
  58. }
  59. return(lpAddress);
  60. }