Thread: Fixing Errors

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    61

    Fixing Errors

    Code:
    --------------------Configuration: GunzPacketProcess - Win32 Debug--------------------
    Compiling...
    GunzPacketProcess.cpp
    C:\Program Files\Microsoft Visual Studio\MyProjects\GunzPacketProcess\GunzPacketProcess.cpp(58) : error C2664: 'strlen' : cannot convert parameter 1 from 'void *' to 'const char *'
            Conversion from 'void*' to pointer to non-'void' requires an explicit cast
    C:\Program Files\Microsoft Visual Studio\MyProjects\GunzPacketProcess\GunzPacketProcess.cpp(81) : error C2440: '=' : cannot convert from 'void *' to 'unsigned char *'
            Conversion from 'void*' to pointer to non-'void' requires an explicit cast
    C:\Program Files\Microsoft Visual Studio\MyProjects\GunzPacketProcess\GunzPacketProcess.cpp(90) : error C2440: '=' : cannot convert from 'unsigned char *' to 'char *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    C:\Program Files\Microsoft Visual Studio\MyProjects\GunzPacketProcess\GunzPacketProcess.cpp(105) : error C2440: 'initializing' : cannot convert from 'void *' to 'unsigned char *'
            Conversion from 'void*' to pointer to non-'void' requires an explicit cast
    C:\Program Files\Microsoft Visual Studio\MyProjects\GunzPacketProcess\GunzPacketProcess.cpp(127) : error C2440: 'return' : cannot convert from 'unsigned char *' to 'char *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    C:\Program Files\Microsoft Visual Studio\MyProjects\GunzPacketProcess\GunzPacketProcess.cpp(184) : error C2440: 'initializing' : cannot convert from 'void *' to 'struct Command_Packet *'
            Conversion from 'void*' to pointer to non-'void' requires an explicit cast
    C:\Program Files\Microsoft Visual Studio\MyProjects\GunzPacketProcess\GunzPacketProcess.cpp(185) : error C2440: 'initializing' : cannot convert from 'void *' to 'char *'
            Conversion from 'void*' to pointer to non-'void' requires an explicit cast
    C:\Program Files\Microsoft Visual Studio\MyProjects\GunzPacketProcess\GunzPacketProcess.cpp(217) : error C2664: 'packet_checksum' : cannot convert parameter 1 from 'char *' to 'unsigned char *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    C:\Program Files\Microsoft Visual Studio\MyProjects\GunzPacketProcess\GunzPacketProcess.cpp(228) : error C2440: 'initializing' : cannot convert from 'void *' to 'char *'
            Conversion from 'void*' to pointer to non-'void' requires an explicit cast
    Error executing cl.exe.
    
    GunzPacketProcess.dll - 9 error(s), 0 warning(s)
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <windows.h>
    #include <winsock.h>
    #include <winnt.h>
    #include <wtypes.h>
    #pragma comment(lib, "ws2_32")
    #include <stdarg.h>
    #include <time.h>
    
    extern void *x_malloc(size_t siz, const char *alloc_info);
    extern CRITICAL_SECTION plvl_cs,cs_packetID,cs_malloc, unmangle_cs;
    extern CRITICAL_SECTION io_cs, packet_reading;
    extern struct pointers pointers[16000];
    extern struct Command_Packet *MakePacket(char *packet, size_t packet_len, short isUnencrypted, char *key);
    extern unsigned char packet_ID;
    extern char key[32], stageKey[32], NATKey[32];
    extern void x_free(void *ptr);
    extern int fd, peer_fd;
    
    struct pointers {
    	char *ptr;
    	const char *alloc_info;
    };
    
    struct Command_Packet {
    	char *msg;
    	size_t len;
    };
    
    int send_to_server(int fd, char *packet, size_t siz) {
    	size_t ret;
    	EnterCriticalSection(&io_cs);
    	ret = send(fd,packet,siz,0);
    	LeaveCriticalSection(&io_cs);
    	return ret;
    }
    
    void add_identifier(char *packet,short id) {
    	memcpy(packet+sizeof(short),&id,sizeof(id));
    }
    
    void add_packetID(char *packet) {
    	EnterCriticalSection(&cs_packetID);
    	*packet = packet_ID++;
    	if(packet_ID > 0xFF) {
    		packet_ID = 0x01;
    	}
    	LeaveCriticalSection(&cs_packetID);
    }
    
    size_t add_param(char *packet, int type, void *param, size_t siz) {
    	size_t local_size = 0;
    
    	if((type == 4 || type == 10)) {
    		if(!siz) {
    			siz = (short)strlen(param)+1;
    		}
    
    		memcpy(packet+local_size,&siz,sizeof(short));
    		local_size += sizeof(short);
    	}
    
    	memcpy(packet+local_size,param,siz);
    
    	return siz+local_size;
    }
    
    void fix_size(char *packet, short siz) {
    	memcpy(packet,&siz,sizeof(siz));
    }
    
    void *x_malloc(size_t siz, const char *alloc_info) {
    	unsigned char *ptr;
    	int i;
    
    	EnterCriticalSection(&cs_malloc);
    
    	for(i=0;i<10;i++) {
    		ptr = malloc(siz);
    		if(ptr) {
    			break;
    		}
    		Sleep(500);
    	}
    
    	for(i=0;i<=15999;i++) {
    		if(!pointers[i].ptr) {
    			pointers[i].ptr=ptr;
    			pointers[i].alloc_info=alloc_info;
    			break;
    		}
    	}
    
    	LeaveCriticalSection(&cs_malloc);
    	return (void *)ptr;
    }
    
    char *encrypt(char *packet,size_t packet_len, char *key) {
    	unsigned int key_len = 32;
    	unsigned int magic_shl = 0x03;
    	unsigned int temp_num=0,second;
    	unsigned int i,j;
    	unsigned char *new_packet = x_malloc(packet_len,"encrypt(), new_packet");
    
    	memset(new_packet,0,packet_len);
    
    	for(i=0,j=0,temp_num=0,second=0;i<packet_len;i++) {
    		temp_num = *(key+j);
    		temp_num = (temp_num) ^ (*(packet+i));
    		temp_num = temp_num & 0xffff00ff;
    		temp_num <<= magic_shl;
    		second = (temp_num >> 8);
    		second |= (temp_num & 0xff);
    		second ^= 0xf0 & 0xff;
    
    		if(j == key_len-1) {
    			j = 0;
    		} else {
    			j++;
    		}
    
    		*(new_packet+i)=second & 0xff;
    	}
    
    	return new_packet;
    }
    
    void x_free(void *ptr) {
    	int i;
    	EnterCriticalSection(&cs_malloc);
    	for(i=0;i<15999;i++) {
    		if(pointers[i].ptr==ptr) {
    			pointers[i].ptr=NULL;
    			break;
    		}
    	}
    
    	if(i>=15999) {
    		printf("Tried to free() pointer %p that was not localized\n",ptr);
    		LeaveCriticalSection(&cs_malloc);
    		return;
    	}
    
    	free(ptr);
    	LeaveCriticalSection(&cs_malloc);
    }
    
    unsigned short packet_checksum(unsigned char *packet, size_t len) {
    	unsigned int skip_header_len = 6;
    	unsigned int count,i;
    	unsigned int sum = 0;
    
    	if(len > 50000) {
    		return 1;
    	}
    
    	if(len > skip_header_len) {
    		for(count = skip_header_len-1; count < len; count++) {
    			sum += *(packet+count);
    		}
    	}
    
    	i = 0;
    	i += *(packet);
    	i += *(packet+1);
    	i += *(packet+2);
    	i += *(packet+3);
    
    	sum -= i;
    	i = sum;
    	sum >>= 0x10;
    	sum += i;
    
    	return sum;
    }
    
    struct Command_Packet *MakePacket(char *packet, size_t packet_len, short isUnencrypted, char *key) {
    	short version = 0x65; // 0x64 for unencrypted mode.
    	short full_len = packet_len + 6;
    	short ret;
    	char *ptr;
    	struct Command_Packet *cmdpkt = x_malloc(sizeof(struct Command_Packet),"MakePacket(), cmdpkt");
    	char *packetOut = x_malloc(packet_len+6,"MakePacket(), PacketOut");
    
    
    	if(!strncmp(key,NATKey,32)) {
    		isUnencrypted = 1;
    	}
    
    	if(isUnencrypted) {
    		version = 0x64;
    	}
    
    	memset(packetOut,0,packet_len+6);
    
    	memcpy(packetOut,&version,sizeof(short));
    
    	if(!isUnencrypted) {
    		ptr = encrypt((char *)&full_len,sizeof(short),key);
    		memcpy(packetOut+2,ptr,sizeof(short));
    		x_free(ptr);
    	} else {
    		memcpy(packetOut+2,&full_len,sizeof(short));
    	}
    
    	memcpy(packetOut+6,packet,sizeof(short));
    
    	memcpy(packetOut+6,packet,packet_len);
    	if(!isUnencrypted) {
    		ptr = encrypt(packetOut+6,packet_len,key);
    		memcpy(packetOut+6,ptr,packet_len);
    		x_free(ptr);
    	}
    
    	ret = packet_checksum(packetOut,full_len);
    	memcpy(packetOut+4,&ret,sizeof(short));
    
    	cmdpkt->msg = packetOut;
    	cmdpkt->len = full_len;
    
    	return cmdpkt;
    }
    
    int Echo(int fd, char*Text)
    {
    	char *packet = x_malloc(8096,"Echo(), packet");
    	struct Command_Packet *cmdpkt;
    	short siz = 0;
    
    	memset(packet,0,8096);
    	add_identifier(packet,0x1B5A); //Global Announce packet ID
    	siz	+= 4;
    
    	add_packetID(packet+siz);
    	siz += 1;
    	siz += add_param(packet+siz,4,Text,0); //strAnnounce parameter
    
    	fix_size(packet,siz);
    	cmdpkt = MakePacket(packet,siz,0,key);
    
    	siz = send_to_server(fd,cmdpkt->msg,cmdpkt->len);
    
    	x_free(packet);
    	x_free(cmdpkt->msg);
    	x_free(cmdpkt);
    
    	return siz;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Maybe rename your file to be a .c file, so it compiles as a C program?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    61
    Then i get those:
    Code:
    GunzPacketProcess.obj : error LNK2001: unresolved external symbol _io_cs
    GunzPacketProcess.obj : error LNK2001: unresolved external symbol _packet_ID
    GunzPacketProcess.obj : error LNK2001: unresolved external symbol _cs_packetID
    GunzPacketProcess.obj : error LNK2001: unresolved external symbol _pointers
    GunzPacketProcess.obj : error LNK2001: unresolved external symbol _cs_malloc
    GunzPacketProcess.obj : error LNK2001: unresolved external symbol _NATKey
    GunzPacketProcess.obj : error LNK2001: unresolved external symbol _key
    And I don't know how to fix them ^.^

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well you've moved on from compile errors to link errors.

    > extern unsigned char packet_ID;
    > extern char key[32], stageKey[32], NATKey[32];
    So which module is responsible for these variables then?

    Are they meant to be somewhere else, or did you just put 'extern' in there for some other reason?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jul 2007
    Posts
    61
    Quote Originally Posted by Salem View Post
    Well you've moved on from compile errors to link errors.

    > extern unsigned char packet_ID;
    > extern char key[32], stageKey[32], NATKey[32];
    So which module is responsible for these variables then?

    Are they meant to be somewhere else, or did you just put 'extern' in there for some other reason?
    My new code:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <windows.h>
    #include <winsock.h>
    #include <winnt.h>
    #include <wtypes.h>
    #pragma comment(lib, "ws2_32")
    #include <stdarg.h>
    #include <time.h>
    
    #define GetTwoKeys(keyone,keytwo) if(GetAsyncKeyState(keyone) &0x8000 && GetAsyncKeyState(keytwo) &0x8000)
    
    extern void *x_malloc(size_t siz, const char *alloc_info);
    extern CRITICAL_SECTION plvl_cs,cs_packetID,cs_malloc, unmangle_cs;
    extern CRITICAL_SECTION io_cs, packet_reading;
    extern struct pointers pointers[16000];
    extern struct Command_Packet *MakePacket(char *packet, size_t packet_len, short isUnencrypted, char *key);
    extern unsigned char packet_ID;
    extern char key[32], stageKey[32], NATKey[32];
    extern void x_free(void *ptr);
    extern int fd, peer_fd;
    
    unsigned char packet_ID = 0x01;
    CRITICAL_SECTION io_cs, packet_reading;
    CRITICAL_SECTION plvl_cs,cs_packetID,cs_malloc, unmangle_cs;
    char key[32], stageKey[32], NATKey[32];
    
    struct pointers {
    	char *ptr;
    	const char *alloc_info;
    };
    struct pointers pointers[16000];
    
    struct Command_Packet {
    	char *msg;
    	size_t len;
    };
    
    int send_to_server(int fd, char *packet, size_t siz) {
    	size_t ret;
    	EnterCriticalSection(&io_cs);
    	ret = send(fd,packet,siz,0);
    	LeaveCriticalSection(&io_cs);
    	return ret;
    }
    
    void add_identifier(char *packet,short id) {
    	memcpy(packet+sizeof(short),&id,sizeof(id));
    }
    
    void add_packetID(char *packet) {
    	EnterCriticalSection(&cs_packetID);
    	*packet = packet_ID++;
    	if(packet_ID > 0xFF) {
    		packet_ID = 0x01;
    	}
    	LeaveCriticalSection(&cs_packetID);
    }
    
    size_t add_param(char *packet, int type, void *param, size_t siz) {
    	size_t local_size = 0;
    
    	if((type == 4 || type == 10)) {
    		if(!siz) {
    			siz = (short)strlen((char*)param)+1;
    		}
    
    		memcpy(packet+local_size,&siz,sizeof(short));
    		local_size += sizeof(short);
    	}
    
    	memcpy(packet+local_size,param,siz);
    
    	return siz+local_size;
    }
    
    void fix_size(char *packet, short siz) {
    	memcpy(packet,&siz,sizeof(siz));
    }
    
    void *x_malloc(size_t siz, const char *alloc_info) {
    	unsigned char *ptr;
    	int i;
    
    	EnterCriticalSection(&cs_malloc);
    
    	for(i=0;i<10;i++) {
    		ptr = malloc(siz);
    		if(ptr) {
    			break;
    		}
    		Sleep(500);
    	}
    
    	for(i=0;i<=15999;i++) {
    		if(!pointers[i].ptr) {
    			pointers[i].ptr=ptr;
    			pointers[i].alloc_info=alloc_info;
    			break;
    		}
    	}
    
    	LeaveCriticalSection(&cs_malloc);
    	return (void *)ptr;
    }
    
    char *encrypt(char *packet,size_t packet_len, char *key) {
    	unsigned int key_len = 32;
    	unsigned int magic_shl = 0x03;
    	unsigned int temp_num=0,second;
    	unsigned int i,j;
    	unsigned char *new_packet = x_malloc(packet_len,"encrypt(), new_packet");
    
    	memset(new_packet,0,packet_len);
    
    	for(i=0,j=0,temp_num=0,second=0;i<packet_len;i++) {
    		temp_num = *(key+j);
    		temp_num = (temp_num) ^ (*(packet+i));
    		temp_num = temp_num & 0xffff00ff;
    		temp_num <<= magic_shl;
    		second = (temp_num >> 8);
    		second |= (temp_num & 0xff);
    		second ^= 0xf0 & 0xff;
    
    		if(j == key_len-1) {
    			j = 0;
    		} else {
    			j++;
    		}
    
    		*(new_packet+i)=second & 0xff;
    	}
    
    	return new_packet;
    }
    
    void x_free(void *ptr) {
    	int i;
    	EnterCriticalSection(&cs_malloc);
    	for(i=0;i<15999;i++) {
    		if(pointers[i].ptr==ptr) {
    			pointers[i].ptr=NULL;
    			break;
    		}
    	}
    
    	if(i>=15999) {
    		LeaveCriticalSection(&cs_malloc);
    		return;
    	}
    
    	free(ptr);
    	LeaveCriticalSection(&cs_malloc);
    }
    
    unsigned short packet_checksum(unsigned char *packet, size_t len) {
    	unsigned int skip_header_len = 6;
    	unsigned int count,i;
    	unsigned int sum = 0;
    
    	if(len > 50000) {
    		return 1;
    	}
    
    	if(len > skip_header_len) {
    		for(count = skip_header_len-1; count < len; count++) {
    			sum += *(packet+count);
    		}
    	}
    
    	i = 0;
    	i += *(packet);
    	i += *(packet+1);
    	i += *(packet+2);
    	i += *(packet+3);
    
    	sum -= i;
    	i = sum;
    	sum >>= 0x10;
    	sum += i;
    
    	return sum;
    }
    
    struct Command_Packet *MakePacket(char *packet, size_t packet_len, short isUnencrypted, char *key) {
    	short version = 0x65; // 0x64 for unencrypted mode.
    	short full_len = packet_len + 6;
    	short ret;
    	char *ptr;
    	struct Command_Packet *cmdpkt = x_malloc(sizeof(struct Command_Packet),"MakePacket(), cmdpkt");
    	char *packetOut = x_malloc(packet_len+6,"MakePacket(), PacketOut");
    
    
    	if(!strncmp(key,NATKey,32)) {
    		isUnencrypted = 1;
    	}
    
    	if(isUnencrypted) {
    		version = 0x64;
    	}
    
    	memset(packetOut,0,packet_len+6);
    
    	memcpy(packetOut,&version,sizeof(short));
    
    	if(!isUnencrypted) {
    		ptr = encrypt((char *)&full_len,sizeof(short),key);
    		memcpy(packetOut+2,ptr,sizeof(short));
    		x_free(ptr);
    	} else {
    		memcpy(packetOut+2,&full_len,sizeof(short));
    	}
    
    	memcpy(packetOut+6,packet,sizeof(short));
    
    	memcpy(packetOut+6,packet,packet_len);
    	if(!isUnencrypted) {
    		ptr = encrypt(packetOut+6,packet_len,key);
    		memcpy(packetOut+6,ptr,packet_len);
    		x_free(ptr);
    	}
    
    	ret = packet_checksum(packetOut,full_len);
    	memcpy(packetOut+4,&ret,sizeof(short));
    
    	cmdpkt->msg = packetOut;
    	cmdpkt->len = full_len;
    
    	return cmdpkt;
    }
    
    int Echo(int fd, char*Text)
    {
    	char *packet = x_malloc(8096,"Echo(), packet");
    	struct Command_Packet *cmdpkt;
    	short siz = 0;
    
    	memset(packet,0,8096);
    	add_identifier(packet,0x1B5A); //Global Announce packet ID
    	siz	+= 4;
    
    	add_packetID(packet+siz);
    	siz += 1;
    	siz += add_param(packet+siz,4,Text,0); //strAnnounce parameter
    
    	fix_size(packet,siz);
    	cmdpkt = MakePacket(packet,siz,0,key);
    
    	siz = send_to_server(fd,cmdpkt->msg,cmdpkt->len);
    
    	x_free(packet);
    	x_free(cmdpkt->msg);
    	x_free(cmdpkt);
    
    	return siz;
    }
    
    void Main()
    {
    	while(1)
    	{
    		GetTwoKeys(0x12, 'A')
    		{
    			Echo(fd, "Popad Plugin by Popad");
    			Sleep(500);
    		}
    		Sleep(50);
    	}
    }
    
    bool APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpvReserved){
    	if(dwReason == DLL_PROCESS_ATTACH){
    		DisableThreadLibraryCalls(hModule);
    		CreateThread(NULL, 0, (unsigned long(__stdcall*)(void*))Main, NULL, 0, NULL);
    	}
    	return true;
    }
    Errors:
    Code:
    --------------------Configuration: GunzPacketProcess - Win32 Debug--------------------
    Compiling...
    GunzPacketProcess.c
    C:\Program Files\Microsoft Visual Studio\MyProjects\GunzPacketProcess\GunzPacketProcess.c(272) : error C2143: syntax error : missing '{' before '__stdcall'
    C:\Program Files\Microsoft Visual Studio\MyProjects\GunzPacketProcess\GunzPacketProcess.c(277) : error C2065: 'true' : undeclared identifier
    Error executing cl.exe.
    
    GunzPacketProcess.dll - 2 error(s), 0 warning(s)

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    void main is undefined! Use int main.
    Main should be main. Main != main.
    I dunno if bool, true/false exists in C.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You're just guessing now...

    > GetTwoKeys(0x12, 'A')
    What's this line without a ; supposed to do?
    The following braces suggest you may have intended an if statement.

    Also, 'true' is NOT a C keyword.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Jul 2007
    Posts
    61
    Code:
    bool APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpvReserved){
    	if(dwReason == DLL_PROCESS_ATTACH){
    		DisableThreadLibraryCalls(hModule);
    		CreateThread(NULL, 0, (unsigned long(__stdcall*)(void*))main, NULL, 0, NULL);
    	}
    }
    Gives this as error:
    Code:
    error C2143: syntax error : missing '{' before '__stdcall'

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Well I'm not exactly sure what you are trying to accomplish but you obviously do not understand enough about the language or the compiler to undertake such a project. I recommend starting at the basic fundamental level of learning the language and then attempt your project. You really should be able to resolve linker errors and compiler errors without the help of a message board. There are times (such as with templates and pre-compiled headers) where MSVS spits out some extremely cryptic error messages but this is not one of those times.

    I must say that the common thread in your posts is quite disturbing. Advise that we have forum rules prohibiting threads about hacking or other malicious software practices. If you are coding this for educational purposes I understand but it just appears 'suspicious'.

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    'true'/'false' may not be keywords, but they are macros defined in stdbool.h.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Errors i'm having trouble fixing
    By yaniv89 in forum Windows Programming
    Replies: 5
    Last Post: 08-26-2005, 02:35 PM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. Help me with these errors... :-(
    By major_small in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2003, 08:18 PM
  5. Fixing errors!
    By Zophixan in forum C++ Programming
    Replies: 2
    Last Post: 10-31-2002, 06:18 PM