| View previous topic :: View next topic |
| Author |
Message |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Fri Jul 11, 2008 11:09 am Post subject: [Help] Last time with GetPixel |
|
|
Haha I know I am posting a lot....but his will be the last one for awhile.
I have this code
| Code: | #include "stdafx.h"
#include <windows.h>
#include <iostream>
HINSTANCE hInstApp = NULL;
COLORREF CColor;
HDC SColor;
POINT Pos;
int redv;
int bluev;
int greenv;
DWORD GPA = (DWORD)GetProcAddress(LoadLibrary("GDI32.DLL"), "GetPixel")+ 5;
_declspec(naked) COLORREF GetPix(HDC hdc, int nXPos, int nYPos) {
_asm
{
mov edi, edi
push ebp
mov ebp, esp
jmp[GPA]
}
}
/////////////////////////////////
int main() {
while (1==1) {
SColor = GetDC(HWND_DESKTOP);
GetCursorPos (&Pos);
CColor = GetPix (SColor,Pos.x,Pos.y);
redv = GetRValue(CColor);
greenv = GetGValue(CColor);
bluev = GetBValue(CColor);
cout << "Red: " << redv << endl;
cout << "Green: " << greenv << endl;
cout << "Blue: " << bluev << endl;
cout << endl;
//Sleep (1000);
}
return 0;
} |
But after showing like 10 color points, it gives the error
| Quote: | | Unhandled exception at 0x00401060 in Test.exe: 0xC0000005: Access violation writing location 0x00130000. |
Any Solutions? |
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Jul 11, 2008 1:31 pm Post subject: |
|
|
Open it in a debugger and figure out where the exception is being generated, then I might be able to help you.
Also, mov edi, edi is not needed in your trampoline. The only reason that instruction is there is to provide a buffer for hot patching. |
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Fri Jul 11, 2008 1:36 pm Post subject: |
|
|
| Flyte wrote: | Open it in a debugger and figure out where the exception is being generated, then I might be able to help you.
Also, mov edi, edi is not needed in your trampoline. The only reason that instruction is there is to provide a buffer for hot patching. |
Why doesn't it use NOPs then? |
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Jul 11, 2008 1:48 pm Post subject: |
|
|
| Symbol wrote: | | Why doesn't it use NOPs then? |
NOPs are used to pad the spaces between functions (INT3 is used in a debug build), so if they did use NOP it would look ugly (and be potentially confusing) in a debugger.
Fun fact: NOP is just an alias mnemonic for xchg eax, eax. |
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Fri Jul 11, 2008 2:02 pm Post subject: |
|
|
| Flyte wrote: | Open it in a debugger and figure out where the exception is being generated, then I might be able to help you.
Also, mov edi, edi is not needed in your trampoline. The only reason that instruction is there is to provide a buffer for hot patching. |
Well im not sure how to load it into a debugger since its like a dos program....but I do know that it is screws up when calling
| Code: | | COLORREF GetPix(HDC hdc, int nXPos, int nYPos) |
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Jul 11, 2008 2:38 pm Post subject: |
|
|
The following code works perfectly for me.
| Code: | #include <windows.h>
#include <iostream>
DWORD GetPixelProc = (DWORD)GetProcAddress( LoadLibrary( "GDI32.DLL" ), "GetPixel" ) + 5;
COLORREF __declspec( naked ) GetPix( HDC hdc, int nXPos, int nYPos )
{
__asm {
mov edi, edi
push ebp
mov ebp, esp
jmp [GetPixelProc]
}
}
void main( void )
{
COLORREF crColor;
POINT pPoint;
//-------
for(;; Sleep( 500 )) {
GetCursorPos( &pPoint );
crColor = GetPix( GetDC( HWND_DESKTOP ), pPoint.x, pPoint.y );
std::cout << "Red:\t" << (int)GetRValue( crColor ) << std::endl;
std::cout << "Green:\t" << (int)GetGValue( crColor ) << std::endl;
std::cout << "Blue:\t" << (int)GetBValue( crColor ) << std::endl << std::endl;
}
} |
Edit: Crashes when you remove Sleep(500), I assume that it is because the console is being flooded with output, and has nothing to do with the trampolined API. |
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Fri Jul 11, 2008 3:32 pm Post subject: |
|
|
| Flyte wrote: | The following code works perfectly for me.
| Code: | #include <windows.h>
#include <iostream>
DWORD GetPixelProc = (DWORD)GetProcAddress( LoadLibrary( "GDI32.DLL" ), "GetPixel" ) + 5;
COLORREF __declspec( naked ) GetPix( HDC hdc, int nXPos, int nYPos )
{
__asm {
mov edi, edi
push ebp
mov ebp, esp
jmp [GetPixelProc]
}
}
void main( void )
{
COLORREF crColor;
POINT pPoint;
//-------
for(;; Sleep( 500 )) {
GetCursorPos( &pPoint );
crColor = GetPix( GetDC( HWND_DESKTOP ), pPoint.x, pPoint.y );
std::cout << "Red:\t" << (int)GetRValue( crColor ) << std::endl;
std::cout << "Green:\t" << (int)GetGValue( crColor ) << std::endl;
std::cout << "Blue:\t" << (int)GetBValue( crColor ) << std::endl << std::endl;
}
} |
Edit: Crashes when you remove Sleep(500), I assume that it is because the console is being flooded with output, and has nothing to do with the trampolined API. |
This works for you? Interesting. Cause it still gives me the Unhandled exception error. |
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Fri Jul 11, 2008 9:06 pm Post subject: |
|
|
| x0r wrote: | | Probably because you're on Windows XP SP1 or earlier. |
Nah im SP2 |
|
| Back to top |
|
 |
|