www.pudn.com > HookAPI > util.cpp


#include "stdafx.h" 
#include  
#include  
#include  
 
#include "resource.h" 
#include "util.h" 
#include "psapi.h" 
 
extern HINSTANCE g_hInstance; 
 
void GetFileName(char *fname) 
{ 
	char temp[200]; 
 
	GetModuleFileName(NULL, temp, sizeof(temp)); 
	int i =strlen(temp); 
	while(i >0 && temp[i-1] !='\\' && temp[i-1] !=':') i--; 
	strcpy(fname, &temp[i]); 
	strupr(fname); 
} 
 
void WriteLog(char *fmt,...) 
{ 
	FILE *fp; 
	va_list args; 
	char modname[200]; 
 
	if((fp =fopen("c:\\hookapi.log", "a")) !=NULL) 
	{		 
		va_start(args,fmt); 
 
		GetModuleFileName(NULL, modname, sizeof(modname)); 
		if(!strstr(modname, "HookAPI")) 
		{ 
			fprintf(fp, "mydll.dll:%s:", modname); 
			vfprintf(fp, fmt, args); 
			fprintf(fp, "\n"); 
		} 
		fclose(fp); 
		 
		va_end(args); 
	} 
} 
 
int ipcmp(char *szip1, char *szip2) 
{ 
	ULONG ip1 =GetIntIP(szip1); 
	ULONG ip2 =GetIntIP(szip2); 
	if(ip1 > ip2) return 1; 
	else if(ip1 app_name); 
		SetWindowPos(hDlg, NULL, 300, 300, 0, 0, SWP_NOSIZE); 
		SendDlgItemMessage(hDlg, IDE_PASSWORD, EM_SETLIMITTEXT, 8, 0L); 
		break; 
	case WM_COMMAND: 
		switch(LOWORD(wParam)) 
		{ 
		case IDOK: 
			if(GetDlgItemText(hDlg, IDE_PASSWORD, password, sizeof(password)) ==0) 
				return TRUE; 
			strcpy(pdata->p_password, password); 
			EndDialog(hDlg, IDOK); 
			break; 
		case IDCANCEL: 
			EndDialog(hDlg, IDCANCEL); 
		} 
		break; 
	} 
	return FALSE; 
} 
 
int GetPassword(char *app, char *password) 
{ 
	PASSWORD_DATA data; 
	strcpy(data.app_name, app); 
	data.p_password =password; 
	if(DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_PASSWORD), NULL, PasswordDlgProc, (LONG)&data) ==IDCANCEL) 
		return -1; 
 
	return 0; 
} 
 
int EncURL(unsigned char *url, int len, char *new_url) 
{ 
	int k =0; 
 
	for(int i =0; i127) 
		{ 
			wsprintf(&new_url[k], "%%%2X", url[i]); 
			k +=3; 
		} 
		else new_url[k++] =url[i]; 
	} 
	new_url[k] =0; 
 
	return k; 
} 
 
int FindData(unsigned char *data1, int len1, unsigned char *data2, int len2, int enc_url) 
{ 
	int i, len_url; 
	char url[1024]; 
	//unsigned char *data =new BYTE[len2]; 
	int count =0; 
	int pos[256], len[256], pos3[256], len3[256]; 
 
	int k =0; 
	pos [0] =0; 
	len [0] =0; 
	char *p =(char *)data2; 
 
	for(i =0; i='z') p[i] =p[i]+'A'-'a'; 
	} 
 
	return p; 
} 
 
int mreplace(char *buf, int len, char *str, char c) 
{ 
	if(len <=0) return NULL; 
	int f_found =false; 
 
	for(int i =0; i