banner

[Rule] Rules  [Home] Main Forum  [Portal] Portal  
[Members] Member Listing  [Statistics] Statistics  [Search] Search  [Reading Room] Reading Room 
[Register] Register  
[Login] Loginhttp  | https  ]
 
Forum Index Thảo luận hệ điều hành Windows Lập trình Hook trong Window  XML
  [Question]   Lập trình Hook trong Window 16/01/2014 13:22:02 (+0700) | #1 | 279469
thanhinterpol
Member

[Minus]    0    [Plus]
Joined: 12/03/2010 19:36:25
Messages: 4
Offline
[Profile] [PM]
Chào mọi người, mình là sinh viên năm cuối DHBK, đang thực tập tại cty LogiGear. Trong thời gian này tụi mình đang được training DEV, hiện tại đang làm một đề tài về Hook gặp một ít khó khăn mong được mọi người giúp đỡ.
Vào nội dung chính, Đề tài của mình là "Create a [Get .Net App Infor] program: This program is show all intormation of .Net application "
Với đề tài này có thể chia ra làm các giai đoạn:
- Lấy danh sách các ứng dụng .NET bằng win API: ở đây mình dùng hàm EnumWindows
- Cài file .dll vào ứng dụng đang chạy : cái này mình dùng remote thread (3)
- Bước tiếp theo là sử dụng SetWindowsHookEx để vài Hook procedure vào Hook chain. :
Code:
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetWindowsHookEx(HookType hookType, HookProc lpfn, IntPtr hMod, uint dwThreadId);

+ tham số thứ nhất là loại Hook: mình dùng WH_CALLWNDPROC
+ tham số thứ 2 là địa chỉ của hàm trong file dll: dùng getProAddress() để lấy,(mình gặp rắc rối ở đây !)
+ tham số thứ 3 là handle của file dll được cài vào ứng dụng: dùng GetModuleHandle()
+ tham sô thứ 4: 0 (hook có phạm vi toàn hệ thống)

Cho mình hỏi là tại sao hàm getProAddress() ko thể lấy được "proceduce address" của "functions" trong file Dll được viết bằng C#, C++ thì lấy bình thường.
Mình đang đọc về cách export function trong dll nhưng vẫn chưa hiểu lắm (4)

Link tham khảo về hook:
(1)/hvaonline/posts/list/765.html
(2)http://msdn.microsoft.com/en-us/library/windows/desktop/ms644959(v=vs.85).aspx
(3)http://www.codeproject.com/Articles/37228/API-Hooking-LoadLibrary
(4) http://msdn.microsoft.com/en-us/library/z4zxe9k8.aspx
[Up] [Print Copy]
  [Question]   Lập trình Hook trong Window 17/01/2014 15:41:16 (+0700) | #2 | 279480
Levis
Member

[Minus]    0    [Plus]
Joined: 14/03/2012 10:31:11
Messages: 27
Location: REPT
Offline
[Profile] [PM] [WWW] [MSN]
Ở đây:
http://social.msdn.microsoft.com/Forums/en-US/cadd6150-de10-47c5-bd5c-a356741c36b3/problem-with-function-pointer?forum=vcmfcatl

có nói
you cannot use GetProcAddress on a managed DLL. GetProcAddress will always return null, because no function is exported by a managed DLL. 


my personal blog:
http://www.ltops9.wordpress.com
(poor english level, but i'm trying to make better)
[Up] [Print Copy]
  [Question]   Lập trình Hook trong Window 17/01/2014 16:02:43 (+0700) | #3 | 279481
thanhinterpol
Member

[Minus]    0    [Plus]
Joined: 12/03/2010 19:36:25
Messages: 4
Offline
[Profile] [PM]
Trong ví dụ trên là "System.Windows.Forms.dll", file này minh ko chỉnh sửa được. Còn trong bài của mình là dll tự tạo. Có thể export functions trong dll này ko?
[Up] [Print Copy]
  [Question]   Lập trình Hook trong Window 18/01/2014 23:03:57 (+0700) | #4 | 279490
Levis
Member

[Minus]    0    [Plus]
Joined: 14/03/2012 10:31:11
Messages: 27
Location: REPT
Offline
[Profile] [PM] [WWW] [MSN]
mình tìm thấy ở đây, không biết có giúp ích cho bạn được không :
http://www.c-sharpcorner.com/UploadFile/JTeeuwen/ExportManagedCodeasUnmanaged11262005051206AM/ExportManagedCodeasUnmanaged.aspx

Mình thấy có 2 cách: thay đổi CLI hoặc là build code thành COM component.
Nếu bạn biết về khái niệm managed dll và unmanaged dll thì sẽ dễ hơn nhiều
my personal blog:
http://www.ltops9.wordpress.com
(poor english level, but i'm trying to make better)
[Up] [Print Copy]
  [Question]   Lập trình Hook trong Window 18/01/2014 23:14:01 (+0700) | #5 | 279491
[Avatar]
quygia128
Member

[Minus]    0    [Plus]
Joined: 15/07/2009 20:50:28
Messages: 119
Location: Somewhere
Offline
[Profile] [PM] [WWW]
DLL bạn code xong hoàn thiện các hàm thì export nó, dùng LoadLibrary load em nó lên, GetProcAddress tên hàm bạn đã export.

Khi code xong cái thư viện export function đầy đủ thì code 1 file exe chỉ đơn giản lấy address của hàm vừa export trong file dll xem ok chưa ?

Khi mọi thứ đã ổn rồi chuyển sang việc hook/ móc thoải mái smilie)

Không được nữa thì cần đến Debugger (ollyDbg chẳn hạn), ta tiến hành đỳ bóc xem coi bị lỗi chổ nào, để có hướng giải quyết, fix code...

Nhiêu đó trước đã, HoooK thì em chịu!!!
.::Mới bắt đầu trên con đường dài::.
.::Super Newbiez::.
[Up] [Print Copy]
  [Question]   Lập trình Hook trong Window 21/01/2014 09:28:45 (+0700) | #6 | 279510
thanhinterpol
Member

[Minus]    0    [Plus]
Joined: 12/03/2010 19:36:25
Messages: 4
Offline
[Profile] [PM]
@quygia128: thank bạn, vấn đề mình gặp là ko export đựoc function trong dll C#, nên ko lấy được ProAddress của nó
@Levis: mình đã thử cách bạn đưa, nhưng vẫn ko được
[Up] [Print Copy]
  [Question]   Lập trình Hook trong Window 23/01/2014 11:49:32 (+0700) | #7 | 279530
thanhinterpol
Member

[Minus]    0    [Plus]
Joined: 12/03/2010 19:36:25
Messages: 4
Offline
[Profile] [PM]
Tình hình là đã giải quyết được vấn đề này.
Tạo một project Dll bằng C#, bulit nó ra file .tlb sau đó tạo 1 file dll bằng C++, gọi lại các hàm trong file dll C#, >> built ra file .dll C++. Như vậy là có thể sử dụng được .dll C# trong việc Hook.
link: http://support.microsoft.com/kb/828736
p/s: cảm ơn mọi người đã giúp đỡ
[Up] [Print Copy]
[digg] [delicious] [google] [yahoo] [technorati] [reddit] [stumbleupon]
Go to: 
 Users currently in here 
1 Anonymous

Powered by JForum - Extended by HVAOnline
 hvaonline.net  |  hvaforum.net  |  hvazone.net  |  hvanews.net  |  vnhacker.org
1999 - 2013 © v2012|0504|218|