Util.cpp
资源名称:HookAPI [点击查看]
上传用户:nbcables
上传日期:2007-01-11
资源大小:1243k
文件大小:4k
源码类别:
钩子与API截获
开发平台:
Visual C++
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h>
- //#include <windows.h>
- #include <winsock.h>
- //#include "Resource.h"
- //#include "Util.h"
- //#include "Psapi.h"
- //#include <shlwapi.h>
- extern HINSTANCE g_hInstance;
- char *strnstr_nbuf ( char *buf, char *text, int bufsz )
- {
- char *t = (char *)malloc (bufsz+1);
- char *result;
- strncpy (t, buf, bufsz);
- *(t+bufsz)=0;
- result = strstr (t, text);
- free(t);
- return result;
- }
- char *strnstr_ntext ( char *buf, char *text, int textsz )
- {
- char *t = (char *)malloc (textsz+1);
- char *result;
- strncpy (t, text, textsz);
- *(t+textsz)=0;
- result = strstr (buf, t);
- free(t);
- return result;
- }
- void StrChrSubst ( char *s, char c1, char c2)
- {
- while (*s!=0)
- {
- if (*s==c1) *s = c2;
- s++;
- }
- }
- 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:\APIHook.log", "a")) !=NULL)
- {
- va_start(args,fmt);
- GetModuleFileName(NULL, modname, sizeof(modname));
- fprintf(fp, "HookFunc.dll:%s:", modname);
- vfprintf(fp, fmt, args);
- fprintf(fp, "n");
- fclose(fp);
- va_end(args);
- }
- }
- void WriteLog2( char *buf, int bufsz )
- {
- FILE *fp;
- if((fp =fopen("c:\APIHook2.log", "a")) !=NULL)
- {
- for (int n=0; n<bufsz; n++)
- {
- fputc ( *(buf+n), fp );
- }
- fprintf(fp, "