home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
WDR Computer Club Digital 1995 February
/
CLUB0295.BIN
/
benchmar
/
cheat
/
cheat.c
next >
Wrap
C/C++ Source or Header
|
1995-01-16
|
7KB
|
264 lines
//
// Cheat Demonstration Programm
// (c) 1995, ELSA GmbH, Aachen, Germany
//
// This little tiny program demonstrates how easy some benchmark
// can be cheat.
// After invoking this cheater WinTach (V1.2) and Speedy will calculate
// doubled results.
// To fool other (newer) Benchmarks some more tricky things must be done,
// but it is possible too. For readability such cheats are not handled
// here.
//
// Important:
// This program may not be used without remark, that the currently
// running benchmark is object of cheating!
//
#include <windows.h>
//
// pointer to a void function returning DWORD
//
typedef DWORD (CALLBACK* DWFARPROC)();
//
// some variables
//
#define JMPFAR 0xea // opcode of JMP FAR
DWORD dwStartTickCount = 0L; // start time of cheat
DWFARPROC paGetTickCount = NULL; // pointer to GetTickCount routine
DWFARPROC paGetTickCountJump = NULL; // pointer where GetTickCount will jump
//
// Program identification string
//
static char szAppName[] = "ELSA Cheat Demo 1.00";
//
// window dimesions (to calc string locations)
//
#define COLUMNS 32
#define LINES 4
static short cxChar, cyChar;
static WindowExtX, WindowExtY;
//
// Prototypes
//
long FAR PASCAL _export WndProc (HWND, UINT, UINT, LONG);
static void PaintWindow(HWND, HDC);
DWORD FAR PASCAL _loadds CheatGetTickCount(void);
//
// the new and cheating GetTickCount()
//
// methode : The tick count return value will be divided by 2.
// This causes, that WinTach and Speedy will double the
// speed result.
//
static BOOL CheckBench() // we will check for speedy or WinTach presence
{
static char strWinTach[] = "WinTach";
static char strSpeedy[] = "The quick";
BOOL Result;
_asm {
mov dx,1 ; prepare result value
mov ax,ss
mov es,ax
;
mov si,offset strWinTach
mov di,025h
lop1:
lodsb
or al,al
jz Detect
mov ah,es:[di]
inc di
cmp ah,al
jz lop1
;
mov si,offset strSpeedy
mov di,012h
lop2:
lodsb
or al,al
jz Detect
mov ah,es:[di]
inc di
cmp ah,al
jz lop2
;
xor dx,dx
Detect:
mov Result,dx
}
return(Result);
}
DWORD FAR PASCAL _loadds CheatGetTickCount(void)
{
if (CheckBench())
return ((paGetTickCountJump() + dwStartTickCount) / 2L);
else
return(paGetTickCountJump());
}
//*****************************************************************//
//
// main procedure
//
//*****************************************************************//
int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
TEXTMETRIC tm;
HDC hdc;
UINT uCount;
HANDLE hLib;
DWORD FAR * PatchPointer;
WORD TempSel;
if (hPrevInstance)
return(0);
else
{
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = NULL;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
RegisterClass (&wndclass);
}
hdc = CreateIC ("DISPLAY", NULL, NULL, NULL);
GetTextMetrics (hdc, &tm);
cxChar = tm.tmAveCharWidth;
cyChar = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC (hwnd, hdc);
WindowExtX = cxChar * COLUMNS;
WindowExtY = cyChar * LINES;
hwnd = CreateWindow
(
szAppName, // window class name
szAppName, // title bar string
WS_OVERLAPPEDWINDOW, // windows style
CW_USEDEFAULT, // window position X
CW_USEDEFAULT, // window position Y
WindowExtX, // horizontal size
WindowExtY, // vertical size
NULL, // parent window handle
NULL, // menu handle
hInstance, // program copy handle
NULL // spezial param
);
ShowWindow (hwnd, SW_SHOWNORMAL);
UpdateWindow (hwnd);
//
// build a pointer to the standard timer services
//
if (NULL != (hLib = LoadLibrary("USER.EXE")))
{
if (
NULL !=
(paGetTickCount = (DWFARPROC)GetProcAddress(hLib, "GETTICKCOUNT"))
)
if ((*(BYTE FAR *)paGetTickCount) == JMPFAR)
paGetTickCountJump = (DWFARPROC)
*(DWORD FAR*)((BYTE FAR*)paGetTickCount + 1);
FreeLibrary(hLib);
}
//
// Flex GetTickCount() entry to our cheat
//
if (paGetTickCount) {
dwStartTickCount = GetTickCount();
TempSel = AllocSelector(0);
TempSel = PrestoChangoSelector( SELECTOROF(paGetTickCount), TempSel);
PatchPointer = (DWORD FAR *) (
((DWORD)TempSel << 16) |
((DWORD)paGetTickCount + 1 & 0x0000ffffL)
);
*PatchPointer = (DWORD)CheatGetTickCount;
FreeSelector(TempSel);
}
//
// message loop
//
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
//
// Restore original pointer to GetTickCount()
//
if (paGetTickCount) {
TempSel = AllocSelector(0);
TempSel = PrestoChangoSelector( SELECTOROF(paGetTickCount), TempSel);
PatchPointer = (DWORD FAR *) (
((DWORD)TempSel << 16) |
((DWORD)paGetTickCount + 1 & 0x0000ffffL)
);
*PatchPointer = (DWORD)paGetTickCountJump;
FreeSelector(TempSel);
}
return msg.wParam;
}
//
// window draw routine
//
void PaintWindow(HWND hwnd, HDC hdc)
{
char TextBuffer[128];
wsprintf (TextBuffer, "WinTach/Speedy cheater active");
TextOut (hdc, cxChar, cyChar * (1), TextBuffer, lstrlen(TextBuffer));
}
//
// message loop handler
//
long FAR PASCAL _export WndProc (HWND hwnd, UINT message,
UINT wParam, LONG lParam)
{
HDC hdc;
PAINTSTRUCT ps;
switch (message)
{
case WM_CREATE :
return (0);
case WM_PAINT :
hdc = BeginPaint (hwnd, &ps);
PaintWindow (hwnd, hdc);
EndPaint (hwnd, &ps);
return (0);
case WM_DESTROY :
PostQuitMessage (0);
return (0);
}
return (DefWindowProc (hwnd, message, wParam, lParam));
}