You last visited: Today at 02:56
Advertisement
[C++]ws2_32.dll compilation help
Discussion on [C++]ws2_32.dll compilation help within the C/C++ forum part of the Coders Den category.
06/10/2009, 02:35
#1
elite*gold: 0
Join Date: Apr 2008
Posts: 347
Received Thanks: 1,286
[C++]ws2_32.dll compilation help
im trying to compile a .DLL for hacking an online game. currently making something like a pocket sender..
anyways, someone told me to use this code..
i've tried to edit it a little.
and tried to compile it.. but got errors..
i hope you can help me fix it.. thanks..
Code:
#include <Winsock2.h>
#include <Windows.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#pragma comment(lib, "ws2_32.lib")
using namespace std;
FILE* pSendLogFile;
FILE* pRecvLogFile;
typedef int (WINAPI* r_send)(SOCKET sock, char* buf, int len, int flags);
r_send osend;
typedef int (WINAPI* r_recv)(SOCKET sock, char* buf, int len, int flags);
r_recv orecv;
int WINAPI custom_send (SOCKET sock, char* buf, int len, int flags);
int WINAPI custom_recv (SOCKET sock, char* buf, int len, int flags);
void InitDebugConsole();
void *DetourFunc(BYTE *src, const BYTE *dst, const int len);
bool RetourFunc(BYTE *src, BYTE *restore, const int len);
bool bCompare(const BYTE* pData, const BYTE* bMask, const char* szMask);
DWORD dwFindPattern(DWORD dwAddress,DWORD dwLen,BYTE *bMask,char * szMask);
void DumpIt(char v,int size,char* buf);
char score[18];
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved)
{
if (reason == DLL_PROCESS_ATTACH)
{
osend = (r_send) GetProcAddress(GetModuleHandle("ws2_32.dll"), "send"); //gets original address for send
orecv = (r_recv) GetProcAddress(GetModuleHandle("ws2_32.dll"), "recv"); //for recv same as above
//DWORD dwSendOriAddr = GetProcAddress(GetModuleHandle("ws2_32.dll"), "send"); //gets original address for send
//DWORD dwRecvOriAddr = GetProcAddress(GetModuleHandle("ws2_32.dll"), "recv"); //for recv same as above
printf("[In Application] Ori Send Address = %x\n", osend);
printf("[In Application] Ori Recv Address = %x\n", orecv);
osend = (r_send) DetourFunc((BYTE*)osend, (BYTE*)&custom_send, 5);
orecv = (r_recv) DetourFunc((BYTE*)orecv, (BYTE*)&custom_recv, 5);
printf("[This DLL] Ori Send Address = %x\n", osend);
printf("[This DLL] Ori Recv Address = %x\n", orecv);
printf("The score should look like this 73%%2E0440539 (%%2E = dot) accuracy after the dot)\n");
printf("Lowest score is 0%%2E000\n");
printf("Type score you want to get : ");
cin.getline (score,18);
printf("loaded score to be = %s\n", score);
}
else if (reason == DLL_PROCESS_DETACH)
{
}
return true;
}
void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
{
BYTE *jmp = (BYTE*)malloc(len+5);
DWORD dwback;
VirtualProtect(src, len, PAGE_READWRITE, &dwback);
memcpy(jmp, src, len); jmp += len;
jmp[0] = 0xE9;
*(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
src[0] = 0xE9;
*(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
VirtualProtect(src, len, dwback, &dwback);
return (jmp-len);
}
bool RetourFunc(BYTE *src, BYTE *restore, const int len)
{
DWORD dwback;
if(!VirtualProtect(src, len, PAGE_READWRITE, &dwback)) { return false; }
if(!memcpy(src, restore, len)) { return false; }
restore[0] = 0xE9;
*(DWORD*)(restore+1) = (DWORD)(src - restore) - 5;
if(!VirtualProtect(src, len, dwback, &dwback)) { return false; }
return true;
}
bool bCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
for(;*szMask;++szMask,++pData,++bMask)
if(*szMask=='x' && *pData!=*bMask )
return false;
return (*szMask) == NULL;
}
DWORD dwFindPattern(DWORD dwAddress,DWORD dwLen,BYTE *bMask,char * szMask)
{
for(DWORD i=0; i < dwLen; i++)
if( bCompare( (BYTE*)( dwAddress+i ),bMask,szMask) )
return (DWORD)(dwAddress+i);
return 0;
}
int WINAPI custom_send(SOCKET sock, char* buf, int len, int flags)
{
//struct sockaddr_in socketClient = (struct sockaddr_in*)sock;
//printf("ip = %s\n", inet_ntoa(socketClient.sin_addr));
//DumpIt('S',len,buf);
char* pch;
char makeOne[10000];
char endString[5000]; //500 bytes max for now?
pch = strstr(buf,"score=");
if(pch != NULL) { //found match
pch = strstr(buf, "&"); //<-score finish
if(pch != NULL) {
int size = pch-buf;
memcpy(endString,buf+size, len-size);
endString[len-size] = '\0';
sprintf(makeOne, "%s%s%s%s","score=", score,"%2D1195345", endString);
size = strlen(makeOne);
char* sendPacket = new char[size];
memcpy(sendPacket, makeOne, size);
DumpIt('S',size, makeOne);
return osend(sock, sendPacket, size, flags);
}
}
//pSendLogFile = fopen("C:\\sndlog.txt", "a+");
//fprintf(pSendLogFile, "\n", buf);
//fclose(pSendLogFile);
return osend(sock, buf, len, flags);
}
int WINAPI custom_recv(SOCKET sock, char* buf, int len, int flags)
{
//pRecvLogFile = fopen("C:\\rcvlog.txt", "a+");
//fprintf(pRecvLogFile, "\n", buf);
//fclose(pRecvLogFile);
return orecv(sock, buf, len, flags);
}
void DumpIt(char v,int size,char* buf)
{
printf("\n\n");
if (v == 'S')
printf("SEND PACKET");
else
printf("RECV PACKET");
printf(" SIZE: %3d \n ",size);
int col=14;
int pc=0;
int lasti=0;
bool notfull=true;
for (int i=0;i<size;i++)
{
printf("%02x ",BYTE(buf[i]));
if (pc++>col)
{
//PRINT the text to it XD
printf(" ");
for (int x=lasti;x<=i;x++)
{
if (BYTE(buf[x]) >= 33)
printf("%c",char(buf[x]));
else
printf(".");
}
printf("\n ");
pc=0;
lasti=i+1;
notfull=false;
} else
notfull=true;
}
if (notfull)
{
while(1)
{
//FINISH LAST ROW !
printf(" "); //no hex here
if (pc++>col)
{
//PRINT the text to it XD
printf(" ");
for (int x=lasti;x<=i;x++)
{
if (x <size)
if (BYTE(buf[x]) >= 33)
printf("%c",char(buf[x]));
else
printf(".");
else
printf(" ");
}
printf("\n ");
pc=0;
lasti=i+1;
notfull=false;
break;
}
}
}
printf("\n");
}
Errors:
Code:
1>------ Build started: Project: injection, Configuration: Debug Win32 ------
1>Compiling...
1>injection.cpp
1>c:\documents and settings\silencio\my documents\khanhookc++\injection\injection\injection.cpp(41) : error C2664: 'GetModuleHandleW' : cannot convert parameter 1 from 'const char [11]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\silencio\my documents\khanhookc++\injection\injection\injection.cpp(42) : error C2664: 'GetModuleHandleW' : cannot convert parameter 1 from 'const char [11]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\silencio\my documents\khanhookc++\injection\injection\injection.cpp(203) : error C2065: 'i' : undeclared identifier
1>c:\documents and settings\silencio\my documents\khanhookc++\injection\injection\injection.cpp(215) : error C2065: 'i' : undeclared identifier
1>Build log was saved at "file://c:\Documents and Settings\silencio\My Documents\KhanhookC++\injection\injection\Debug\BuildLog.htm"
1>injection - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
06/10/2009, 11:11
#2
elite*gold: 20
Join Date: Sep 2006
Posts: 1,100
Received Thanks: 184
This is what happens when using copy pasta...
Quote:
'GetModuleHandleW' : cannot convert parameter 1 from 'const char [11]' to 'LPCWSTR'
that happens because you can't cast a const string to a const wide string...
Quote:
error C2065: 'i' : undeclared identifier
This happens because you're trying to compile a vs2005 programm with vs2008, i is declared in a header of a for loop but used after the for block, with2005 the scope of a variable decleared in a for header was in the same code block as the header, but in ANSI C it's scope is limited to the for block, you can fix by placing the declaration of "i" out side the for header like this:
PHP Code:
int i ; for(; i < whatever ; i ++){...}
06/10/2009, 13:41
#3
elite*gold: 0
Join Date: May 2008
Posts: 489
Received Thanks: 210
Already using code you don't fully understand is a bad idea, but using code of a language that you don't even know... Gonna fail hard, bro.
06/10/2009, 18:40
#4
elite*gold: 196
Join Date: Nov 2005
Posts: 625
Received Thanks: 192
Quote:
1>c:\documents and settings\silencio\my documents\khanhookc++\injection\injection\injectio n.cpp(41) : error C2664: 'GetModuleHandleW' : cannot convert parameter 1 from 'const char [11]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\silencio\my documents\khanhookc++\injection\injection\injectio n.cpp(42) : error C2664: 'GetModuleHandleW' : cannot convert parameter 1 from 'const char [11]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Wide vs. ANSI. Change your project's settings or use the TEXT macro like so:
Code:
osend = (r_send) GetProcAddress(GetModuleHandle("ws2_32.dll"), "send");
orecv = (r_recv) GetProcAddress(GetModuleHandle("ws2_32.dll"), "recv");
->
Code:
osend = (r_send) GetProcAddress(GetModuleHandle(TEXT("ws2_32.dll")), "send");
orecv = (r_recv) GetProcAddress(GetModuleHandle(TEXT("ws2_32.dll")), "recv");
---
Quote:
1>c:\documents and settings\silencio\my documents\khanhookc++\injection\injection\injectio n.cpp(203) : error C2065: 'i' : undeclared identifier
1>c:\documents and settings\silencio\my documents\khanhookc++\injection\injection\injectio n.cpp(215) : error C2065: 'i' : undeclared identifier
Variable "i" is only declared inside of the loop.
Code:
for (int i=0;i<size;i++)
->
Code:
int i;
for (i=0;i<size;i++)
---
Quote:
Originally Posted by
schlurmann
Already using code you don't fully understand is a bad idea, but using code of a language that you don't even know... Gonna fail hard, bro.
/signed
Similar Threads
NTAttack compilation
09/06/2011 - Diablo 2 Programming - 5 Replies
Ich habe jetzt schon viel gesucht, habe aber noch keine NTAttack gefunden, die alle Charakterklassen, das Goldbarb script und so weiter und so fort alle hübsch beisammen hat. Hab echt vieles zusammen, aber eben nicht alles und einiges davon ist ein wenig buggy .. :D
Compilation of Wallhacks dll
05/08/2010 - Soldier Front Hacks, Bots, Cheats & Exploits - 65 Replies
DOWNLOAD LINK: wallhacks.dll
Virus Scan : Virus scan
Help:Compilation of UCE
01/30/2008 - Kal Online - 0 Replies
Cheat Engine :: View topic - Detailed UCE Tutorial - Rev740 - Covers all the basics.
The above link is the one in which I have followed to make my own UCE. This is such a bitch to do and I found it really difficult. Please could you guys have a look at my dpk and dpkfunction files to see if I have changed them right.
Below are my problems:
-Where do you get Windows 2000 Free Build Environment so you can compile the DPKKernel folder.
-When I pressed Ctrl + F9 in Delphi 7 (I am...
All times are GMT +2. The time now is 02:57 .