Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3.  
  4. extern "C"
  5. {
  6.     int isOnPaintArrived = 0;
  7.  
  8.    _declspec(dllexport) LRESULT CALLBACK GeMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
  9.     {
  10.         if (nCode == HC_ACTION)
  11.         {
  12.            
  13.  
  14.             return CallNextHookEx(0, nCode, wParam, lParam);
  15.         }
  16.  
  17.         return CallNextHookEx(0, nCode, wParam, lParam);
  18.     }
  19.  
  20.     _declspec(dllexport) int GetFlag(void)
  21.     {
  22.         return (isOnPaintArrived);
  23.     }
  24.  
  25.     _declspec(dllexport) void setFlag(void)
  26.     {
  27.         isOnPaintArrived = 0;
  28.     }
  29.  
  30.     _declspec(dllexport) void resetFlag(void)
  31.     {
  32.         isOnPaintArrived = 0;
  33.     }
  34.  
  35. }
  36.  
  37. /* OurDLL.c source code */
  38.  
  39. /*#include <windows.h>
  40. #include <iostream>
  41. #include <fstream>
  42. using namespace std;
  43.  
  44. int main () {
  45.   ofstream myfile;
  46.  
  47.   myfile << "Writing this to a file.\n";
  48.   myfile.close();
  49.   return 0;
  50. }
  51.  
  52. BOOL WINAPI  DllMain(HANDLE    hModule,
  53.             DWORD     dwFunction,
  54.             LPVOID    lpNot)
  55. {
  56.     return TRUE;
  57. }
  58.  
  59. char* LEFT_BUTTON_STRING = "left";
  60. char* RIGHT_BUTTON_STRING = "right";
  61.  
  62. bool isShiftPressed = false;
  63.  
  64. int isOnPaintArrived = 0;
  65.  
  66. extern "C"
  67. {
  68.  
  69.     _declspec (dllexport) LRESULT CALLBACK RecorderMouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
  70.     {
  71.         if (nCode == HC_ACTION)
  72.         {
  73.             if (wParam == WM_LBUTTONDOWN || wParam == WM_RBUTTONDOWN)
  74.             {
  75.                 char* button = RIGHT_BUTTON_STRING;
  76.  
  77.                 if (wParam == WM_LBUTTONDOWN)
  78.                 {
  79.                     button = LEFT_BUTTON_STRING;
  80.                 }
  81.  
  82.                 DWORD result = ScreenToClient(GetActiveWindow(), &(((MSLLHOOKSTRUCT*)lParam)->pt));
  83.  
  84.                 if (result == 0)
  85.                 {
  86.                     int xPos = ((MSLLHOOKSTRUCT*)lParam)->pt.x;
  87.                     int yPos = ((MSLLHOOKSTRUCT*)lParam)->pt.y;
  88.  
  89.                     ofstream file;
  90.                     file.open("C:\\hook-output.au3", ios_base::app);
  91.                     file << "Error:MouseClick (\"" << button << "\", " << xPos << ", " << yPos << ")" << endl;
  92.                     file.close();
  93.                 }
  94.                 else
  95.                 {
  96.                     int xPos = ((MSLLHOOKSTRUCT*)lParam)->pt.x;
  97.                     int yPos = ((MSLLHOOKSTRUCT*)lParam)->pt.y;
  98.  
  99.                     ofstream file;
  100.                     file.open("C:\\hook-output.au3", ios_base::app);
  101.                     file << "MouseClick (\"" << button << "\", " << xPos << ", " << yPos << ")" << endl;
  102.                     file.close();
  103.                 }
  104.             }
  105.  
  106.             return CallNextHookEx(0, nCode, wParam, lParam);
  107.         }
  108.  
  109.         return CallNextHookEx(0, nCode, wParam, lParam);
  110.     }
  111.  
  112.     _declspec (dllexport) LRESULT CALLBACK RecorderKeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
  113.     {
  114.         if (nCode == HC_ACTION)
  115.         {
  116.             if (wParam == VK_SHIFT)
  117.             {
  118.                 isShiftPressed = false;
  119.  
  120.                 if (!(lParam & 0x80000000))
  121.                 {
  122.                     isShiftPressed = true;
  123.                 }
  124.             }
  125.             else
  126.             {
  127.                 if (!(lParam & 0x80000000))
  128.                 {
  129.                     char character = MapVirtualKey(wParam, MAPVK_VK_TO_CHAR);
  130.  
  131.                     if (character >= 'A' && character <= 'Z')
  132.                     {
  133.                         character = character - 'A' + 'a';
  134.  
  135.                         ofstream file;
  136.                         file.open("C:\\hook-output.au3", ios_base::app);
  137.                         file << "Send (\"";
  138.                         if (isShiftPressed)
  139.                         {
  140.                             file << "+";
  141.                         }
  142.                         file << character << "\")" << endl;  
  143.  
  144.                         file.close();
  145.                     }
  146.                 }
  147.             }
  148.  
  149.             return CallNextHookEx(0, nCode, wParam, lParam);
  150.         }
  151.  
  152.         return CallNextHookEx(0, nCode, wParam, lParam);
  153.     }
  154.  
  155.     _declspec (dllexport) LRESULT CALLBACK GeMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
  156.     {
  157.         if (nCode == HC_ACTION)
  158.         {
  159.            
  160.  
  161.             return CallNextHookEx(0, nCode, wParam, lParam);
  162.         }
  163.  
  164.         return CallNextHookEx(0, nCode, wParam, lParam);
  165.     }
  166.  
  167.     _declspec (dllexport) void GetOnPaintFlag()
  168.     {
  169.         //return (isOnPaintArrived);
  170.         isOnPaintArrived = true;
  171.     }
  172.  
  173.     _declspec (dllexport) int CALLBACK getFlag()
  174.     {
  175.         //return (isOnPaintArrived);
  176.         return (0);
  177.     }
  178.  
  179.     _declspec (dllexport) void CALLBACK setFlag()
  180.     {
  181.         //isOnPaintArrived = 0;
  182.     }
  183.  
  184.     _declspec (dllexport) void CALLBACK resetFlag()
  185.     {
  186.         //isOnPaintArrived = 0;
  187.     }
  188. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement