Facebook
From awd, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 263
  1. // lab2Dlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "lab2.h"
  6. #include "lab2Dlg.h"
  7. #include "lab2lib.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #endif
  12.  
  13.  
  14. // Clab2Dlg dialog
  15.  
  16.  
  17.  
  18. Clab2Dlg::Clab2Dlg(CWnd* pParent /*=NULL*/)
  19.         : CDialog(Clab2Dlg::IDD, pParent)
  20. {
  21.         m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  22. }
  23.  
  24. void Clab2Dlg::DoDataExchange(CDataExchange* pDX)
  25. {
  26.         CDialog::DoDataExchange(pDX);
  27.         DDX_Control(pDX, IDC_BUTTON1, m_przycisk1);
  28.         DDX_Control(pDX, IDC_BUTTON2, m_przycisk2);
  29.         DDX_Control(pDX, IDC_BUTTON3, m_przycisk3);
  30.         DDX_Control(pDX, IDC_EDIT1, m_ekran);
  31.         DDX_Control(pDX, IDC_EDIT2, m_proces);
  32.         DDX_Control(pDX, IDC_EDIT3, m_strona);
  33. }
  34.  
  35. BEGIN_MESSAGE_MAP(Clab2Dlg, CDialog)
  36.         ON_WM_PAINT()
  37.         ON_WM_QUERYDRAGICON()
  38.         //}}AFX_MSG_MAP
  39.         ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton3)
  40.         ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
  41.         ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
  42. END_MESSAGE_MAP()
  43.  
  44.  
  45. // Clab2Dlg message handlers
  46.  
  47. BOOL Clab2Dlg::OnInitDialog()
  48. {
  49.         CDialog::OnInitDialog();
  50.  
  51.         // Set the icon for this dialog.  The framework does this automatically
  52.         //  when the application's main window is not a dialog
  53.         SetIcon(m_hIcon, TRUE);                 // Set big icon
  54.         SetIcon(m_hIcon, FALSE);                // Set small icon
  55.  
  56.         // TODO: Add extra initialization here
  57.        
  58.         return TRUE;  // return TRUE  unless you set the focus to a control
  59. }
  60.  
  61. // If you add a minimize button to your dialog, you will need the code below
  62. //  to draw the icon.  For MFC applications using the document/view model,
  63. //  this is automatically done for you by the framework.
  64.  
  65. void Clab2Dlg::OnPaint()
  66. {
  67.         if (IsIconic())
  68.         {
  69.                 CPaintDC dc(this); // device context for painting
  70.  
  71.                 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  72.  
  73.                 // Center icon in client rectangle
  74.                 int cxIcon = GetSystemMetrics(SM_CXICON);
  75.                 int cyIcon = GetSystemMetrics(SM_CYICON);
  76.                 CRect rect;
  77.                 GetClientRect(&rect);
  78.                 int x = (rect.Width() - cxIcon + 1) / 2;
  79.                 int y = (rect.Height() - cyIcon + 1) / 2;
  80.  
  81.                 // Draw the icon
  82.                 dc.DrawIcon(x, y, m_hIcon);
  83.         }
  84.         else
  85.         {
  86.                 CDialog::OnPaint();
  87.         }
  88. }
  89.  
  90. // The system calls this function to obtain the cursor to display while the user drags
  91. //  the minimized window.
  92. HCURSOR Clab2Dlg::OnQueryDragIcon()
  93. {
  94.         return static_cast<HCURSOR>(m_hIcon);
  95. }
  96.  
  97.  
  98. void Clab2Dlg::OnBnClickedButton1()
  99. {
  100.         // TODO: Add your control notification handler code here
  101.         // TODO: Obsługa przycisku "Do odczytu"
  102.         HANDLE hProces;
  103.         DWORD n;
  104.         char *s;
  105.         DWORD id;
  106.         CString str,str2;
  107.  
  108.         DWORD adres;
  109.  
  110.         m_proces.GetWindowText(str);
  111.         sscanf((const char *)str,"%i", &id);
  112.         m_strona.GetWindowText(str2);
  113.         sscanf((const char *)str2,"%i", &adres);
  114.  
  115.         hProces = OpenProcess(PROCESS_ALL_ACCESS,0,id);
  116.  
  117.         VirtualProtectEx(hProces,(void *)adres,4095,PAGE_READONLY,&n);
  118.         CloseHandle(hProces);
  119. }
  120.  
  121. void Clab2Dlg::OnBnClickedButton2()
  122. {
  123.         // TODO: Add your control notification handler code here
  124.         // TODO: Obsługa przycisku "Brak dostępu"
  125.         HANDLE hProces;
  126.         DWORD n;
  127.         char *s;
  128.         DWORD id;
  129.         CString str,str2;
  130.  
  131.         DWORD adres;
  132.  
  133.         m_proces.GetWindowText(str);
  134.         sscanf((const char *)str,"%i", &id);
  135.         m_strona.GetWindowText(str2);
  136.         sscanf((const char *)str2,"%i", &adres);
  137.  
  138.         hProces = OpenProcess(PROCESS_ALL_ACCESS,0,id);
  139.  
  140.         VirtualProtectEx(hProces,(void *)adres,4095,PAGE_NOACCESS,&n);
  141.         CloseHandle(hProces);
  142.  
  143. }
  144.  
  145. void Clab2Dlg::OnBnClickedButton3()
  146. {
  147.         // TODO: Add your control notification handler code here
  148.         // TODO: Obsługa przycisku "Wyświetl"
  149.         HANDLE hProces;
  150.         unsigned int n;
  151.         DWORD id;
  152.         char *s;
  153.         n = 0;
  154.         CString str;
  155.  
  156.         m_proces.GetWindowText(str);
  157.         sscanf((const char *)str,"%i", &id);
  158.  
  159.         hProces = OpenProcess(PROCESS_ALL_ACCESS,0,id);
  160.        
  161.         ShowVMem(hProces,0,&n);
  162.         s = (char *)malloc(n);
  163.         ShowVMem(hProces,s,&n);
  164.         m_ekran.SetWindowText(s);
  165.         free(s);
  166.  
  167.         CloseHandle(hProces);
  168.  
  169. }