home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_06 / 3n06024a < prev    next >
Text File  |  1992-04-15  |  3KB  |  99 lines

  1. /* Patch.c  Contains Patch functions for Inter.exe */
  2.  
  3. #define _WINDOWS
  4. #define _WINDLL
  5. #ifndef WIN31
  6.   #define  ChangeSelector PrestoChangoSelector
  7. #endif
  8.  
  9. #include <windows.h>
  10. #include <memory.h>
  11. #include <string.h>
  12. #include <dos.h>
  13.  
  14. VOID FAR PASCAL Patch(HWND hWndList);
  15. VOID FAR PASCAL UnPatch(VOID);
  16. WORD FAR PASCAL MyWinExec  (LPSTR lpPath,int show);
  17. WORD FAR PASCAL WinWinExec (LPSTR lpPath,int show);
  18. int FAR PASCAL    LibMain(HANDLE hInst,WORD wDataSeg,WORD cbHeapSize,
  19.             LPSTR lpszCmdLine);
  20. int FAR PASCAL    WEP (int bSystemExit);
  21.  
  22. #define CPYBYTES 5  /*Number of Bytes to Copy*/
  23.  
  24. BYTE     btWinexec[6];
  25. HWND     hWndList;
  26. LPSTR     lpPatch,lpWinexec;
  27. WORD     selPatchRW,selWinExecRW,selWinExec;
  28.  
  29. /*  Installs a Patch in the Winexec Function.   */
  30.  
  31. VOID FAR PASCAL Patch(HWND hwndlist)
  32. {
  33.   WORD offst;
  34.   hWndList=hwndlist;                /*Save Handle to ListBox*/
  35.   selPatchRW=AllocSelector(HIWORD(Patch));  /*Get Selector of Patch*/
  36.   ChangeSelector(HIWORD(Patch),selPatchRW); /*Change Selector to Read Write*/
  37.   _asm     mov ax,offset patchcode        ;Setup Pointer to Patch Code
  38.   _asm     mov offst,ax
  39.   lpPatch=(LPSTR)MAKELONG(offst,selPatchRW);
  40.   selWinExec=HIWORD(WinWinExec);     /*Get Selector of WinExec Function*/
  41.   GlobalPageLock(selWinExec);            /*Lock Segment*/
  42.   selWinExecRW=AllocSelector(selWinExec);   /*Get New selector*/
  43.   ChangeSelector(selWinExec,selWinExecRW);  /*Change Code Selector to R/W*/
  44.   /*Setup Pointer to WinExec Function*/
  45.   lpWinexec=(LPSTR)MAKELONG(LOWORD(WinWinExec),selWinExecRW);
  46.   _fmemcpy (btWinexec,lpWinexec,CPYBYTES);  /*Save first 5 bytes of Winexec*/
  47.   _fmemcpy (lpWinexec,lpPatch,CPYBYTES);    /* Patch the WinExec Function*/
  48.   return;
  49. patchcode:
  50.  _asm jmp MyWinExec    ;Code Copied to Winexec Function
  51. }
  52.  
  53. /*****************************************************
  54.     MyWinExec Intercept Function
  55.   1) The Windows WinExec Function is Called.
  56.   2) Patch code is Executed in the WinExec function. (Jmp to MyWinExec()).
  57.   3  Debug Output is done to the Listbox.
  58.   3) WinExec is Unpatched.
  59.   4) WinExec is then called.
  60.   5) WinExec is then repatched for next call.
  61. ******************************************************/
  62.  
  63. WORD FAR PASCAL MyWinExec (LPSTR lpPath,int show)
  64. {
  65.  char szbuff[200];
  66.  int result;
  67.  wsprintf (szbuff,"Path %s",(LPSTR)lpPath);
  68.  SendMessage (hWndList,LB_ADDSTRING,0,(LONG)(LPSTR)szbuff);
  69.  _fmemcpy (lpWinexec,btWinexec,CPYBYTES); /*Unpatch and Call*/
  70.  result=WinExec(lpPath,show);
  71.  _fmemcpy (lpWinexec,lpPatch,CPYBYTES);   /*Repatch For Next Call*/
  72.  return result;
  73. }
  74.  
  75. VOID FAR PASCAL UnPatch(VOID)
  76. {
  77.  _fmemcpy (lpWinexec,btWinexec,CPYBYTES);    /* Unpatch for shutdown*/
  78.  GlobalPageUnlock(selWinExec);
  79.  FreeSelector(selPatchRW);
  80.  FreeSelector(selWinExecRW);
  81. }
  82.  
  83.  
  84.  
  85. int FAR PASCAL LibMain(hInst, wDataSeg, cbHeapSize, lpszCmdLine)
  86. HANDLE    hInst;
  87. WORD    wDataSeg;
  88. WORD    cbHeapSize;
  89. LPSTR   lpszCmdLine;
  90. {
  91.  return 1;
  92. }
  93.  
  94. int FAR PASCAL WEP (bSystemExit)
  95. int  bSystemExit;
  96. {
  97.  return(1);
  98. }
  99.