Esempio n. 1
0
int send_file(char *path, long IPaddr, uuid_t *uuids, uint64_t num_uuids, int PN)
{
	FILE *fp = fopen(path,"r");
	char block[DEFAULT_BLOCK_SIZE];
	int i=0;
	fseek(fp,0,SEEK_SET);
	while(!feof(fp))
	{
		char *msg = 0, *err_msg_string = 0;
		uint64_t msg_len;
		int num;
		uuid_t uuid;
		char *resp_msg = 0;
		ErrorCode error;
		struct Node* resp;
		if(i>=num_uuids)
		{
			printf("Not enough uuids\n");
			fclose(fp);
			return 0;
		}
		else
		{
			memset(block,0,sizeof(block));
			num = fread(block, 1, DEFAULT_BLOCK_SIZE, fp);
			create_msg_post_block_request(uuids[i], num, block, &msg, &msg_len);
			error = mysend(msg, IPaddr, PN, msg_len);
			if(error == FAILURE || error == RETRY)
			{
				printf("error in send");
				free(msg);
				fclose(fp);
				return 0;
			}
			else
			{
				resp = myrecv(CLIENT_PORT);
				resp_msg = resp->message;
				if(get_header_type(resp_msg) == BACS_ERROR)
				{
      					parse_msg_error(resp_msg, &err_msg_string);
					printf("%s\n",err_msg_string);
					fclose(fp);
					return 0;
				}
    				else
					parse_msg_post_block_response(resp_msg, &uuid);
			}
			free(err_msg_string);
			free(resp->message);
			free(resp);
			free(msg);
		}
		i++;
	}
	printf("\nFile uploaded successfully\n");
	fclose(fp);
	return 1;
}
Esempio n. 2
0
void make_dir(char* dir, bool l, char* path, unsigned long IPaddr, int PN)
{
  if(l==0)
  {
    char dirpath[1024];
    int result;

    strcpy(dirpath,path);
    strcat(dirpath,"/");
    strcat(dirpath,dir);
   /* printf("dirpath:%s\n",dirpath);*/
    result = mkdir(dirpath, 0777);
    if(result==0)
      printf("Local directory '%s' created at path: %s\n", dir, path);
    else
      perror("mkdir() error");
  }
  else
  {
	char* msg = 0, * resp_msg = 0, *err_msg_string = 0;
	uint64_t msg_len;
	ErrorCode error;
	struct Node* resp;
	char dirpath[1024];
    	strcpy(dirpath,path);
	if(strcmp(path,"/")!=0)
    		strcat(dirpath,"/");
    	strcat(dirpath,dir);
	create_msg_post_folder_request(dirpath, &msg, &msg_len);
	error = mysend(msg, IPaddr, PN, msg_len);
	free(msg);
	if(error == FAILURE || error == RETRY)
	{
		printf("error in send\n");
		return;
	}
	resp = myrecv(CLIENT_PORT);
	resp_msg = resp->message;
	if(get_header_type(resp_msg) == BACS_ERROR)
	{
      		parse_msg_error(resp_msg, &err_msg_string);
		printf("%s\n",err_msg_string);
		free(err_msg_string);
		free(resp->message);
		free(resp);
		return;
	}
	parse_msg_post_folder_response(resp_msg);
	printf("Remote directory '%s' created at path: %s\n", dir, path);
	free(err_msg_string);
	free(resp->message);
	free(resp);
  }
}
Esempio n. 3
0
void download_folder(char* file_name, char* local_path, char* remote_path, unsigned long IPaddr, int PN)
{
	char local_temp[1024], remote_temp[1024];
	char* msg = 0, * resp_msg = 0, *err_msg_string = 0;
	uint64_t msg_len;
	uint32_t num_metas;
	int i;
	basic_meta_t *basic_metas = 0;
	ErrorCode error;
	struct Node* resp;
    	strcpy(local_temp, local_path);
    	strcpy(remote_temp, remote_path);
    	make_dir(file_name, 0, local_path, IPaddr, PN);
    	change_dir(file_name, local_temp, 0, IPaddr, PN);
    	change_dir(file_name, remote_temp, 1, IPaddr, PN);

	create_msg_get_folder_meta_request(remote_temp, &msg, &msg_len);
	error = mysend(msg, IPaddr, PN, msg_len);
	free(msg);
	if(error == FAILURE || error == RETRY)
	{	printf("error in send\n");
		return;
	}
	resp = myrecv(CLIENT_PORT);
	resp_msg = resp->message;
	if(get_header_type(resp_msg) == BACS_ERROR)
	{
      		parse_msg_error(resp_msg, &err_msg_string);
		printf("%s",err_msg_string);
		free(resp->message);
		free(resp);
		free(err_msg_string);
		return;
	}
	parse_msg_get_folder_meta_response(resp_msg, &basic_metas, &num_metas);
	free(resp->message);
	free(resp);
	free(err_msg_string);
	for(i=0; i < num_metas; i++)
	{
		if(strcmp(basic_metas[i].name,".")!=0 && strcmp(basic_metas[i].name,"..")!=0)
			download_file(basic_metas[i].name, local_temp, remote_temp, IPaddr, PN);
		//free(basic_metas[i].name);
	}
	free(basic_metas);
 	/*download file complete*/
    	printf("Directory downloaded to path: %s\n",local_path);
}
Esempio n. 4
0
void download_file(char* file_name, char* local_path, char* remote_path, unsigned long IPaddr, int PN)
{
	FILE *fp;   	
	char local_file[1024];
	char remote_file[1024];
	char *msg = 0;
	uint64_t msg_len;
	basic_block_t *blocks = 0;
	uint64_t num_blocks;
	int i;
	ErrorCode error;
	struct Node* resp;
	char * resp_msg = 0, *err_msg_string = 0;
	strcpy(local_file,local_path);
    	strcat(local_file,"/");
    	strcat(local_file,file_name);
	strcpy(remote_file,remote_path);
	if(strcmp(remote_path,"/")!=0)
    		strcat(remote_file,"/");
    	strcat(remote_file,file_name);
    	printf("Downloading file '%s'..\n", file_name);
	create_msg_get_file_request(remote_file, &msg, &msg_len);
	error = mysend(msg, IPaddr, PN, msg_len);
	free(msg);
	if(error == FAILURE || error == RETRY)
	{
		printf("error in send\n");
		return;
	}
	resp = myrecv(CLIENT_PORT);
	resp_msg = resp->message;
	if(get_header_type(resp_msg) == BACS_ERROR)
	{
      		parse_msg_error(resp_msg, &err_msg_string);
		printf("%s\n",err_msg_string);
		free(resp->message);
		free(resp);
		free(err_msg_string);
		return;
	}
	parse_msg_get_file_response(resp_msg, &blocks, &num_blocks);
	/*printf("UUIDS received: ");*/
	for(i=0; i<num_blocks; i++)
	{
		char *str = uuid_str(blocks[i].uuid);
    		/*printf(" - %s\n", str);*/
    		free(str);
	}
	fp = fopen(local_file, "w"); 
	free(resp->message);
	free(resp);
	free(err_msg_string);
	for(i=0; i<num_blocks; i++)
	{
		char *msg = 0, *resp_msg = 0, *err_msg_string = 0;
		uuid_t uuid;
		uint32_t size;
		char *content = 0;
		ErrorCode error;
		struct  Node* resp;
		create_msg_get_block_request(blocks[i].uuid, &msg, &msg_len);
		/*printf("in client\n");
		print_msg(msg);*/
		error = mysend(msg, IPaddr, PN, msg_len);
		free(msg);
		if(error == FAILURE || error == RETRY)
		{
			printf("error in send\n");
			free(blocks);
			close(fp);
			return;
		}
		resp = myrecv(CLIENT_PORT);
		resp_msg = resp->message;
		if(get_header_type(resp_msg) == BACS_ERROR)
		{
	      		parse_msg_error(resp_msg, &err_msg_string);
			printf("%s\n",err_msg_string);
			/*char *str = uuid_str(blocks[i].uuid);
    			printf(" - %s\n", str);
    			free(str);*/
			free(resp->message);
			free(resp);
			free(err_msg_string);
			free(blocks);
			close(fp);
			return;
		}
		parse_msg_get_block_response(resp_msg, &uuid, &size, &content);
		fwrite (content, sizeof(char), size, fp);
		free(content);
		free(resp->message);
		free(resp);
		free(err_msg_string);
	}	
	printf("File downloaded to path: %s\n",local_path);
	fclose(fp);
	free(blocks);
}
Esempio n. 5
0
bool upload_file(char* file_name, char* local_path, char* remote_path, unsigned long IPaddr, int PN)
{
    	char filepath[1024];
 	struct stat st;
	uint64_t size;
	char *msg = 0, *resp_msg = 0, *err_msg_string = 0;
	uint64_t msg_len;
	uuid_t *uuids = 0;
	uint64_t num_uuids;
	ErrorCode error;
	struct Node* resp;
    	printf("...Uploading file '%s'...\n", file_name);
   	strcpy(filepath,local_path);
	strcat(filepath,"/");
    	strcat(filepath,file_name);
	if(stat(filepath, &st)==0)
	{
		size = st.st_size;
	/*	printf("*********************************size= %d\n", size);*/
		if(size == 0)
		{
			printf("File empty. Cannot be uploaded\n");
			return 0;
		}
	}
	else
	{	
		perror("size error: ");
		return 0;
	}
	memset(filepath, 0, 1024);
	strcpy(filepath,remote_path);
	if(strcmp(remote_path,"/")!=0)
		strcat(filepath,"/");
    	strcat(filepath,file_name);
    	create_msg_post_file_request(filepath, size, &msg, &msg_len);
	/*mysend(msg, ...) */
	error = mysend(msg, IPaddr, PN, msg_len);
	free(msg);
	if(error == FAILURE || error == RETRY)
	{
		printf("error in send\n");
		return 0;
	}	
	resp = myrecv(CLIENT_PORT);
	resp_msg = resp->message;
	if(get_header_type(resp_msg) == BACS_ERROR)
	{
      		parse_msg_error(resp_msg, &err_msg_string);
		printf("%s\n",err_msg_string);
		free(err_msg_string);
		free(resp->message);
		free(resp);
		return 0;
	}
	parse_msg_post_file_response(resp_msg, &uuids, &num_uuids);
	int i;
	
	for(i=0; i<num_uuids; i++)
	{
		char *str = uuid_str(uuids[i]);
    		/*printf(" - %s\n", str);*/
    		free(str);
	}
	free(err_msg_string);
	free(resp->message);
	free(resp);
	if(num_uuids==0)
	{
		printf("***************error num_uuids\n");
		free(uuids);
		return 0;
	}
	bool success;				
	memset(filepath, 0, 1024);
	strcpy(filepath,local_path);
	strcat(filepath,"/");
    	strcat(filepath,file_name);
	success = send_file(filepath, IPaddr, uuids, num_uuids, PN);
	if(success == 0)
	{
		free(uuids);
		return 0;
	}	
	free(uuids);
	return 1;
}	
Esempio n. 6
0
bool change_dir(char* dir, char* path, bool l, unsigned long IPaddr, int PN)
{
	if(l==0)
	{
  		char dirpath[1024];
  		int result;
		memset(dirpath, 0, 1024);
		if(strcmp(path,"/")==0 && strcmp(dir,"..")==0)
			strcpy(dirpath,path);
		else if(strcmp(dir,"..")!=0 && strcmp(path,"/")!=0)
		{
			strcpy(dirpath,path);
  			strcat(dirpath,"/");
  			strcat(dirpath,dir);
		}
		else if(strcmp(dir,"..")!=0 && strcmp(path,"/")==0)
		{
			strcpy(dirpath,path);
  			strcat(dirpath,dir);
		}
		else if(strcmp(path,"/")!=0)
		{
    			char** tokens;
    			tokens = str_split(path, '/');
			if (tokens)
    			{
        			int i;
        			for (i = 0; *(tokens + i); i++);
				if(i!=1)
				{
					int j;
					for (j = 0; j<i-1; j++)
        				{
						strcat(dirpath,"/");
						strcat(dirpath,*(tokens + j));
            					free(*(tokens + j));
        				}
				}
				else
					strcpy(dirpath,"/");
        			free(tokens);
			}
		}
		else
			strcpy(dirpath,"/");
  		result = chdir(dirpath);
  		if(result==0)
  		{
    			memset(path, 0, 1024);
			strcpy(path, dirpath);
    			printf("New local path: '%s'\n", path);
  		}
  		else 
  		{
			perror("cd() error");
			return 1;
  		}
	}
	else
	{
		char dirpath[1024];
		char* msg = 0;
		uint64_t msg_len;
		uint32_t num_metas;
		int i;
		basic_meta_t *basic_metas = 0;
		ErrorCode error;
		char* resp_msg =0, *err_msg_string = 0;
		struct Node* resp;
  		memset(dirpath, 0, 1024);
		if(strcmp(path,"/")==0 && strcmp(dir,"..")==0)
			strcpy(dirpath, path);
		else if(strcmp(dir,"..")!=0 && strcmp(path,"/")!=0)
		{
			strcpy(dirpath,path);
  			strcat(dirpath,"/");
  			strcat(dirpath,dir);
		}
		else if(strcmp(dir,"..")!=0 && strcmp(path,"/")==0)
		{
			strcpy(dirpath,path);
  			strcat(dirpath,dir);
		}
		else if(strcmp(path,"/")!=0)
		{
    			char** tokens;
    			tokens = str_split(path, '/');
			if (tokens)
    			{
        			int i;
        			for (i = 0; *(tokens + i); i++);
				if(i!=1)
				{
					int j;
					for (j = 0; j<i-1; j++)
        				{
						strcat(dirpath,"/");
						strcat(dirpath,*(tokens + j));
            					free(*(tokens + j));
        				}
				}
				else
					strcpy(dirpath,"/");
        			free(tokens);
			}
		}
		else
			strcpy(dirpath,"/");
  	/*	printf("dirpath:%s\n",dirpath);		*/
		create_msg_get_folder_meta_request(dirpath, &msg, &msg_len);
		error = mysend(msg, IPaddr, PN, msg_len);
		free(msg);
		if(error == FAILURE || error == RETRY)
		{
			printf("error in send\n");
			return 1;
		}
		resp = myrecv(CLIENT_PORT);
		resp_msg = resp->message;
		if(get_header_type(resp_msg) == BACS_ERROR)
		{
      			parse_msg_error(resp_msg, &err_msg_string);
			printf("%s\n",err_msg_string);
			free(err_msg_string);
			free(resp->message);
			free(resp);
			return 1;
		}
		parse_msg_get_folder_meta_response(resp_msg, &basic_metas, &num_metas);
		free(err_msg_string);
		free(resp->message);
		free(resp);
	/*	printf("remote directory contains: \n");*/
		for(i=0; i < num_metas; i++)
		{
			/*printf("%s\n",basic_metas[i].name);*/
			free(basic_metas[i].name);
		}
		memset(path, 0, 1024);
		strcpy(path, dirpath);
		free(basic_metas);
		printf("New remote path: '%s'\n", path);
	}
  	return 0;
}
Esempio n. 7
0
void list_dir(char* path, bool l, unsigned long IPaddr, int PN)
{
	if(l==0)
	{
  		DIR *dp;
  		struct dirent *ep;
		dp = opendir (path);
  		if (dp != NULL)
  		{
    			while ((ep = readdir (dp)))
      			{
				if(strcmp(ep->d_name,".")!=0 && strcmp(ep->d_name,"..")!=0)			
				{
					if(ep->d_type == DT_REG)
					{
						int size = -1;
						char filepath[1024];
						struct stat st;
						strcpy(filepath,path);
						strcat(filepath,"/");
						strcat(filepath,ep->d_name);
						if(stat(filepath, &st)==0)
							size = st.st_size;
						else
							perror("Unable to calculate file size: ");
						printf("%s	File	Size: %d\n",ep->d_name, size);
					}
					if(ep->d_type == DT_DIR)
						printf("%s	Folder\n",ep->d_name);	
				}	
			}
    			closedir (dp);
  		}
  		else
    			perror ("ls() error");
	}
	else
	{
		char* msg = 0, * resp_msg = 0, *err_msg_string = 0;
		uint64_t msg_len;
		uint32_t num_metas;
		int i;
		basic_meta_t *basic_metas = 0;
		ErrorCode error;
		struct Node* resp;
		create_msg_get_folder_meta_request(path, &msg, &msg_len);
		error = mysend(msg, IPaddr, PN, msg_len);
		free(msg);
		if(error == FAILURE || error == RETRY)
		{
			printf("error in send\n");
			return;
		}
		resp = myrecv(CLIENT_PORT);
		resp_msg = resp->message;
		if(get_header_type(resp_msg) == BACS_ERROR)
		{
      			parse_msg_error(resp_msg, &err_msg_string);
			printf("%s\n",err_msg_string);
			free(err_msg_string);
			free(resp->message);
			free(resp);
			return;
		}
    		parse_msg_get_folder_meta_response(resp_msg, &basic_metas, &num_metas);	
		free(err_msg_string);
		free(resp->message);
		free(resp);	
		if(num_metas>0)
		{
			/*printf("remote directory contains: \n");*/
			for(i=0; i < num_metas; i++)
			{
				if(basic_metas[i].type==BACS_FILE_TYPE)
					printf("%s	FILE	Size: %d\n",basic_metas[i].name,basic_metas[i].size);
				else
					printf("%s	FOLDER\n",basic_metas[i].name);
				free(basic_metas[i].name);
			}
		}
		else
			printf("Empty folder.\n");
		free(basic_metas);
	}
}
Esempio n. 8
0
void mainLoop(int sock)
{
	uint16_t width, height;
	uint8_t devcount = POINTER_COUNT;
	UInputAbsPointer *uinputs[POINTER_COUNT];
	Display *display = 0;
	UInputAbsPointer *pointer = 0;
	
	unsigned char buffer[7];
	int bytes;
	
	// Warte auf HELO
	bytes = myrecv(sock, buffer, sizeof(buffer) - 1, 0);
	if (bytes == -1)
	{
		perror("recv() fehlgeschlagen");
 		return;
	}
	else if (bytes == 0)
		return;
	else if ((bytes >= 6) and (buffer[0] == '#') and (buffer[1] == '#'))
	{
		// Got HELO
		width = ntohs(*(reinterpret_cast<uint16_t*>(&buffer[2])));
		height = ntohs(*(reinterpret_cast<uint16_t*>(&buffer[4])));
	}
	else
	{
		std::cerr << "Received invalid HELO" << std::endl;
		return;
	}
	
	uint i;
	for (i=0;i<POINTER_COUNT;i++)
	{
		std::string name = "MTC Touchpoint ";
		name += i2str(i);
		// Erzeuge UInput-Gerät
		uinputs[i] = new UInputAbsPointer(name, width, height);
	}
	
	// Verbinde zu X-Display
	#ifdef MPX
	if (Mpx)
	{
		display = XOpenDisplay(NULL);
		if (display == NULL) {
			std::cout << "Could not connect to X-Server!" << std::endl;
			exit(1);
		}
		XSync(display, False);
	}
	if (Mpx) for (i=0;i<POINTER_COUNT;i++)
	{
		std::string mname;
		std::string name = "MTC Touchpoint ";
		name += i2str(i);
		if (i>0)
		{
			mname = "MTC Touchpoint Master ";
			mname += i2str(i);
			// Erzeuge einen neuen XInput2-Master
			if (xi2_create_master(display, mname, 0, 1) != 0) {
				std::cout << "Could not create XInput2 master device " << i2str(i) << "!" << std::endl;
				exit(1);
			}
		}
		else
			mname = "Virtual core pointer";
		// Warte bis das vorhin erzeugte UInput-Gerät vom X-Server eingebunden wurde
		// aber maximal 1s.
		xi2_wait_for_device(display, name, 1000);
		// Wechsle die UInput-Geräte in die neuen Master.
		xi2_change_attachment(display, name, mname);
	}
	#endif
	
	// Befehlsschleife
	while (!killed)
	{
		bytes = myrecv(sock, buffer, sizeof(buffer) - 1, 0);
		buffer[bytes] = 0;
		if (bytes == -1)
		{
			perror("recv() fehlgeschlagen");
			break;
		}
		if (bytes == 0)
			break;

		/*while (bytes < 6)
		{
			int i = recv(sock, buffer+bytes, sizeof(buffer-bytes) - 1, 0);
			if (i <= 0) break;
			bytes += i;
			buffer[bytes] = 0;
		}*/
		
		if (bytes >= 6)
		{
			unsigned char opcode = buffer[0], pointernum = buffer[1];
			uint16_t xcoord = ntohs(*(reinterpret_cast<uint16_t*>(&buffer[2]))),
						ycoord = ntohs(*(reinterpret_cast<uint16_t*>(&buffer[4])));
			if (Debug) printf("ACTION %c POINTER %hhu [ %hu, %hu ]\n", opcode, pointernum, xcoord, ycoord);
			if (pointernum < POINTER_COUNT)
			{
				pointer = uinputs[pointernum];
			}
			else continue;
			
			if (opcode == '.')
				pointer->moveTo(xcoord, ycoord);
			else if (opcode == '!')
			{
				pointer->moveTo(xcoord, ycoord);
				usleep(20000);
				pointer->click();
			}
			else if (opcode == 'd')
			{
				pointer->press();
				usleep(20000);
			}
			else if (opcode == 'D')
			{
				pointer->moveTo(xcoord, ycoord);
				pointer->press();
				usleep(20000);
			}
			else if (opcode == 'u')
			{
				pointer->release();
				usleep(20000);
			}
			else if (opcode == 'U')
			{
				pointer->moveTo(xcoord, ycoord);
				pointer->release();
				usleep(20000);
			}
			else { printf("Unknown opcode '%c' received.\n", opcode); }
		}
		else
			std::cerr << "Received invalid data: " << buffer << std::endl;
	}
	
	
	for (i=POINTER_COUNT-1;i>0;i--)
	{
		std::string name = "MTC Touchpoint ";
		name += i2str(i);
		// Lösche das UInput-Gerät
		if (uinputs[i])
		{
			if (Debug) std::cerr << "deleting " << name << std::endl;
			delete uinputs[i];
			uinputs[i] = NULL;
		}
	}
	#ifdef MPX
	if (Mpx) for (i=POINTER_COUNT-1;i>0;i--)
	{
		usleep(50000);
		std::string name = "MTC Touchpoint ";
		name += i2str(i);
		std::string mname = "MTC Touchpoint Master ";
		mname += i2str(i);
		// Lösche den Master
		if (display)
		{
			if (Debug) std::cerr << "deleting master " << mname << std::endl;
			xi2_remove_master(display, mname);
		}
	}
	#endif
	std::cerr << "done" << std::endl;
}
Esempio n. 9
0
int CALLBACK WinMain(HINSTANCE,HINSTANCE,LPSTR,int){
	quiet = strstr(GetCommandLineA(), "quiet") != NULL;

	//Change directory to binary directory
	char filename[MAX_PATH];
	DWORD size = GetModuleFileNameA(NULL, filename, sizeof(filename));
	for(size -= 1; filename[size] != '\\' && size != 0; size--)
		filename[size] = 0;
	SetCurrentDirectoryA(filename);

	if(ask("Update signatures?"))
		system("config.exe update");

	if(ask("Manually load library?"))
#ifdef _M_X64
		if(LoadLibraryA("apihook64.dll") == NULL)
#else
		if(LoadLibraryA("apihook.dll") == NULL)
#endif
			MessageBoxA(NULL,"Load failed!","Hook Tester",0);

	//ALLOW TEST
	clock_t one=clock();
	if(ask("Test starting. SleepEx 1000..."))
		SleepEx(1000, FALSE);
	if(quiet && clock() - one < CLOCKS_PER_SEC / 2)
		error("SleepEx(1000, 0) exited early");

	//BLOCK AND AGGREGATION TEST
	one=clock();
	if(ask("SleepEx 1001 quad"))
		for(int i = 0; i < 4; i++)
			SleepEx(1001, FALSE);
	if(ask("SleepEx 1001 quad"))
		for(int i = 0; i < 4; i++)
			SleepEx(1001, FALSE);
	if(quiet && clock() - one > CLOCKS_PER_SEC * 5)
		error("SleepEx(1001, 0) was not blocked");

	//URLDOWNLOADTOFILEW TEST
	//Test LoadLibrary, GetProcAddress, WC string regex
	DeleteFileA("deleteme.txt");
	URLDownloadToFileWFunc URLDownloadToFileW = (URLDownloadToFileWFunc)
		GetProcAddress(LoadLibraryA("urlmon"), "URLDownloadToFileW");
	if(ask("URLDownloadToFileW http://www.yahoo.com/"))
		if(URLDownloadToFileW(NULL, L"http://www.yahoo.com/", L"deleteme.txt", 0, NULL) != (HANDLE)73)
			error("URLDOWNLOADTOFILEW wrong return value");

	//RECV TEST
	//Test LoadLibrary, GetProcAddress, Pointer, and Integer range
	recvfunc myrecv = (recvfunc)GetProcAddress(LoadLibraryA("ws2_32.dll"), "recv");
	PVOID rwx = VirtualAlloc(NULL, 1021, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
	if(ask("winsock recv"))
		if(myrecv(0, (char*)rwx, 1021, 0) != 0)
			error("Ws2_32 recv did not return the correct value");

	//INJECT TEST - ensures library is loaded into all new processes
	STARTUPINFOA start;
	PROCESS_INFORMATION proc;
	memset(&start,0,sizeof(start));
	memset(&proc,0,sizeof(proc));
	start.cb = sizeof(start);
	char cmdline[100];
	lstrcpyA(cmdline,"cmd.exe");
	if(ask("Start cmd")){
		CreateProcessA(NULL,cmdline,NULL,NULL,0,0,NULL,NULL,&start,&proc);
		HMODULE hmods[100];
		DWORD bytes = sizeof(hmods);
		CHAR modname[MAX_PATH];
		bool found = false;
		if(EnumProcessModules(proc.hProcess, hmods, sizeof(hmods), &bytes))
			for(int i = 0; i < (bytes / sizeof(HMODULE)); i++)
				if(GetModuleFileNameExA(proc.hProcess, hmods[i], modname, MAX_PATH))
					if(strstr(modname, "apihook") != NULL)
						found = true;
		if(found == false)
			error("Process injection failed!");
		TerminateProcess(proc.hProcess, 0);
	}

	//TEST NOT
	if(ask("Non-remote CreateRemoteThread")){
		WaitForSingleObject(CreateRemoteThread(GetCurrentProcess(),NULL,0,&ThreadProc,NULL,0,NULL), 500);
		if(thread != true)
			error("Thread did not run!");
	}

	//Test killproc with sleepEx 1002
	if(ask("Read PE")){
		GetModuleFileNameA(NULL, filename, sizeof(filename));
		HANDLE h = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 
			NULL, OPEN_EXISTING, NULL, NULL);
		char readbuf[1000];
		DWORD dontcare;
		ReadFile(h,readbuf,sizeof(readbuf),&dontcare,NULL);
		CloseHandle(h);
	}
	error("Read PE Kill process failed!");
}