Undefined
By: . _ . | Date: Jan 10 2009 16:21 | Format: C++ | Expires: never | Size: 4.24 KB | Hits: 1124
- // gdi_draw.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
- //
- #include "stdafx.h"
- #include "class.h"
- #include <iostream>
- #include <string>
- #include <windows.h>
- #include "process.h"
- #include <cstdlib>
- #include <winbase.h>
- // hat ich auch schonmal versucht..
- void draw(){
- HWND hWnd=FindWindow(NULL,"Counter-Strike");
- HDC hdc=GetDC(hWnd);
- RECT r;
- // Obtain the window's client rectangle
- GetClientRect(hWnd, &r);
- // THE FIX: by setting the background mode
- // to transparent, the region is the text itself
- // SetBkMode(hdc, TRANSPARENT);
- // Bracket begin a path
- BeginPath(hdc);
- // Send some text out into the world
- TCHAR text[ ] = "Defenestration can be hazardous";
- TextOut(hdc,r.left,r.top,text, ARRAYSIZE(text));
- // Bracket end a path
- EndPath(hdc);
- // Derive a region from that path
- SelectClipPath(hdc, RGN_AND);
- // This generates the same result as SelectClipPath()
- // SelectClipRgn(hdc, PathToRegion(hdc));
- // Fill the region with grayness
- }
- using namespace std;
- //using namespace System::Threading;
- BOOL TextOut(int x, int y,
- LPCTSTR lpszString,
- int nCount);
- void InitMenu(void);
- int ReadMem(char *window, int dAddr);
- bool SetDebugPrivilege();
- bool SetPrivilege( HANDLE hToken, LPCTSTR lpszPrivilege, BOOL bEnablePrivilege );
- //void DisplayError( LPTSTR szAPI );
- void runInThread();
- int main(int argc, char *argv[]) {
- unsigned long threadId;
- HWND hWnd=FindWindow(NULL,"Counter-Strike");
- HDC hdc=GetDC(hWnd);
- cout<<"hWnd: "<<hWnd<<endl;
- cout<<"hcd: "<<hdc<<endl;
- /*
- CreateThread(
- __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes,
- __in SIZE_T dwStackSize,
- __in LPTHREAD_START_ROUTINE lpStartAddress,
- __in_opt LPVOID lpParameter,
- __in DWORD dwCreationFlags,
- __out_opt LPDWORD lpThreadId
- );
- */
- HANDLE hThread = CreateThread(
- NULL, 2000, (LPTHREAD_START_ROUTINE)runInThread,"", 0, &threadId
- );
- for(int i=0;i<30;++i) {
- Sleep(10);
- /*
- DrawTextA(
- __in HDC hdc,
- __inout_ecount_opt(cchText) LPCSTR lpchText,
- __in int cchText,
- __inout LPRECT lprc,
- __in UINT format);
- */
- RECT r;
- DrawText(hdc,"text",4,&r,DT_CENTER);
- //InitMenu();
- //printf("main");
- }
- return EXIT_SUCCESS;
- }
- void runInThread() {
- for(int i=0;i<30;++i) {
- }
- }
- bool SetDebugPrivilege()
- {
- HANDLE hToken;
- bool bOK = false;
- if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
- {
- if (!SetPrivilege(hToken, SE_DEBUG_NAME, TRUE))
- {
- cout<<"setprivilege"<<endl;//DisplayError("SetPrivilege");
- }
- else
- bOK = true;
- CloseHandle(hToken);
- }
- else
- //DisplayError("OpenProcessToken");
- cout<<"openprocesstoken"<<endl;
- return bOK;
- }
- bool SetPrivilege( HANDLE hToken, LPCTSTR lpszPrivilege, BOOL bEnablePrivilege )
- {
- TOKEN_PRIVILEGES tp;
- LUID luid;
- TOKEN_PRIVILEGES tpPrevious;
- DWORD cbPrevious = sizeof(TOKEN_PRIVILEGES);
- if(!LookupPrivilegeValue( NULL, lpszPrivilege, &luid ))
- return false;
- // 1) Get current privilege setting
- tp.PrivilegeCount = 1;
- tp.Privileges[0].Luid = luid;
- tp.Privileges[0].Attributes = 0;
- AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), &tpPrevious, &cbPrevious);
- if (GetLastError() != ERROR_SUCCESS)
- return false;
- // 2) Set privilege based on previous setting
- tpPrevious.PrivilegeCount = 1;
- tpPrevious.Privileges[0].Luid = luid;
- if (bEnablePrivilege)
- tpPrevious.Privileges[0].Attributes |= (SE_PRIVILEGE_ENABLED);
- else
- tpPrevious.Privileges[0].Attributes ^= (SE_PRIVILEGE_ENABLED & tpPrevious.Privileges[0].Attributes);
- AdjustTokenPrivileges( hToken, FALSE, &tpPrevious, cbPrevious, NULL, NULL );
- if (GetLastError() != ERROR_SUCCESS)
- return false;
- return true;
- }
- int ReadMem(char *window, int dAddr)
- {
- int buffer;
- //DWORD prevProtection;
- HWND hWnd = FindWindow(0, window);
- if (!hWnd) MessageBox(0, "Error finding window", 0, MB_OK);
- DWORD proc_id;
- GetWindowThreadProcessId(hWnd, &proc_id);
- HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc_id);
- &prevProtection);
- if (!ReadProcessMemory(hProcess, (LPCVOID)dAddr, &buffer, 2, NULL))
- MessageBox(0, "Error doing memory reading", 0, MB_OK);
- return buffer;
- }
Latest pastes
1 hours ago
11 hours ago
1 days ago
2 days ago
2 days ago