Tips

Tips

Video

Showing posts with label Technology. Show all posts
Showing posts with label Technology. Show all posts

Saturday, October 24, 2015

DLL injection and DLL injection example

View here for understand DLL injection and example
- Today I will show you another way using DLL Injection with parameters
- Change NewWndProc function.


DLL injection and DLL injection example (2/2)



NewWndProc









Data Structure

typedef struct tag_locksomeoneuseskill
{ 
 int iIndex;   // skill ID
 int iPos;   // vị trí monster trong mảng NPC
}Locksomeoneuseskill; // struct tham số cho function LockSomeOneUseSkill 


Source code


// dllmain.cpp : Defines the entry point for the DLL application.
/* ****************************************
 * Author: Zidane (huuvi168@gmail.com)
 * Last modified: 2015-06-08
 * ****************************************/

/************************************************************************
VịLH - NewWndProc - 23/05/2013
 Hàm nhận các sự kiện bên chương trình chính gửi qua
params:
 + HWND: HWnd cửa sổ đang chọn
 + UINT: Message của chương trình
 + WPARAM: Tham số wparam
 + LPARAM: Tham số lparam
return: 
 
*************************************************************************/

LRESULT CALLBACK NewWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ 
      switch(uMsg) 
      {
          case WM_COPYDATA: // get data from shared memory area
                        COPYDATASTRUCT* pcds = (COPYDATASTRUCT *)lParam; 
                 if (pcds->dwData == DATA_LOCKSOMEONEUSESKILL)
                 {           
                    iIdSkill = ((Locksomeoneuseskill *)(pcds->lpData))->iIndex;
                    iPosition = ((Locksomeoneuseskill *)(pcds->lpData))->iPos;
                  }
               break; 
      }


     if (!hWnd)
                                                       return CallWindowProc(OldWndProc, hWnd, uMsg, wParam, lParam);
     DWORD pid;
     GetWindowThreadProcessId(hWnd, &pid);  
 

      // Ứng dụng gửi rất nhiều message nhưng chỉ xử lý message 
      // WM_HOOK_WRITE thôi
      if (uMsg == WM_HOOK_WRITE)
      {   
    switch (wParam)
    {     
  case WPARAM_LOCKSOMEONEUSESKILL:
      if (iPosition > 0 && iIdSkill > 0)
   LockSomeOneUseSkill(pid, iPosition, iIdSkill);
      break;   
  }
           } 

           return CallWindowProc(OldWndProc, hWnd, uMsg, wParam, lParam);
      }
}







Main function



COPYDATASTRUCT MyCDS;
Locksomeoneuseskill locksomeoneStruct;
locksomeoneStruct.iIndex = 128;
locksomeoneStruct.iPos = 10488;
  
MyCDS.dwData = DATA_LOCKSOMEONEUSESKILL;
MyCDS.cbData = sizeof(locksomeoneStruct);
MyCDS.lpData = &locksomeoneStruct;

// copy data locksomeoneuseskill
::SendMessage(m_hCurrentWnd, WM_COPYDATA, 0, reinterpret_cast<lparam>(&MyCDS));  

// using function looksomeoneusekill
::SendMessage(m_hCurrentWnd, WM_HOOK_WRITE, WPARAM_LOCKSOMEONEUSESKILL, 1); 

Description

WM_COPYDATA constant will be reference to below source


case WM_COPYDATA: // get data from shared memory area
   COPYDATASTRUCT* pcds = (COPYDATASTRUCT *)lParam; 
   if (pcds->dwData == DATA_LOCKSOMEONEUSESKILL)
   {           
 iIdSkill = ((Locksomeoneuseskill *)(pcds->lpData))->iIndex;
 iPosition = ((Locksomeoneuseskill *)(pcds->lpData))->iPos;
   } 



View more: http://learn-tech-tips.blogspot.com/2015/08/dll-injection-exmaple.html
Have a nice weekend day!
Zidane

Saturday, July 25, 2015

Bài 2: Kiểm tra Ma Trận cuông sắp tăng dần theo đường chéo chính!





Ví dụ:
Ma trận tăng dần theo đường chéo chính như sau
11.00 16.00  20.00  23.00  25.00
47.00 12.00  147.00 21.00 24.00 
1.00  50.00   13.00  15.00  0
1.00  50.00   13.00  14.00  100
1.00  460.00 13.00  15.00   15.00 
Ý tưởng: 
Giống như cách sắp xếp trên mảng 1 chiều, ta xem đường chéo chính như là mảng một chiều sau đó kiểm tra nó có tăng dần không, nếu tăng dần trả về 1, ngược lại bằng 0

Cách làm:
Viết hai hàm: 
- Một hàm dùng để kiểm tra tăng dần (ktTangDan)
- Một hàm xuất kết quả

Ghi Chú:
- Các hàm nhập, xuất tự viết!


Chương trình




/* ------------------------------------------
 * Author: zidane (huuvi168@gmail.com)
 * Last modified: 2015-07-03
 * -----------------------------------------/

// n số phần tử của mảng a
int ktTangDan(float a[], int n) 
{
    bool flag = true;
    for (int i=0; i<=n-1; i++)
       for (int j=i+1; j<=n; i++)
         // chỉ cần một phần tử thỏa là không tăng dần
         if (a[i] > a[j]) 
            // giá trị trả về trong hàm function (pascal)
            flag = false; 
     return flag;
}

// n, m là dòng và cột trong ma trận (ma trận vuông)
void ktTangDanDuongCheoChinh(float a[][100], int n)
{
   float b[100];
   for (int i=0; i<n; i++)
   b[i] = a[i][i];

   if (ktTangDan(b, n) == true)
      printf("Duong cheo chinh tang dan");
   else
      printf("Duong cheo chinh KHONG tang dan");
}