📄 hookcom.cpp
字号:
////////////////////////////////////////////////////////////////////////////////////
//
//HookCom.cpp: common function used both in GUI and Device.
#include "StdAfx.h"
#include "..\HookShr\Comdef.h"
//extract first record containing protected file information from s,
//save the information in pProtFile and char *path.
//
//return value: return 0 if a record is not found, -1 if a record is not complete,
// and 1 if a record is read out successfully.
int StringToFileInfo(const char *buf, PROTECTED_FILE *pProtFile, char *path)
{
//INI file format: each record consist of a '@' followed by length of the path
//(4 char, including a whitespace),a '#' followed by protection type(3 char,
//including a whitespace) and anther '#' followed
//by the path of a file under protection.
//find first '@':
unsigned int pos=0;
while(buf[pos]!='@' && pos<=strlen(buf))
pos++;
if(pos>=strlen(buf))
return -1;
pos++;
unsigned int pathLen=atoi(buf+pos); //read path length.
pos+=4;
if(buf[pos]!=',') //wrong format
return 0;
pos++;
pProtFile->PF_type=atoi(buf+pos); //read protection type.
pos+=3;
if(buf[pos]!=',') //wrong format
return 0;
pos++;
strcpy(path, buf+pos);
if(strlen(path)<pathLen)
return 0;
else pProtFile->PF_pPath=path;
return 1;
}
//Get directory(no file name) form a path by removing last component of a path.
//e.g. E:\*.* ==> E:\
// E:\NEW\A.TXT ==> E:\NEW\
// E:\NEW\ ==> E:\NEW\
//Return Value: Length of the new dir.
int GetDir(char *pPath)
{
int pos=strlen(pPath)-1;
while(pos!=0 && pPath[pos]!='\\' && pPath[pos]!=':')
pos--;
if(pPath[pos]==':')
pPath[++pos]='\\';
pPath[pos+1]=0;
return pos+1;
}
//determine whether uniMatcher matches uniPattern. using Long File Name match.
template <class PCHAR_T> BOOL PatternMatch(PCHAR_T pattern, PCHAR_T matcher, unsigned int patternLen, unsigned int matcherLen)
{
unsigned int pos1=0, pos2=0;
while(pos1<patternLen && pos2<matcherLen)
{
if(pattern[pos1]!=matcher[pos2])
{
if(pattern[pos1]=='*')
{
pos1++;
while(pos1<patternLen && pos2<matcherLen && pattern[pos1]!=matcher[pos2])
pos2++;
}
else if(pattern[pos1]=='?')
{
pos1++;
pos2++;
}
else return FALSE;
}
else
{
pos1++;
pos2++;
}
}
if((pos2==matcherLen && pos1==patternLen) || (pattern[patternLen-1]=='*' && (pos1==patternLen-1|| pos1==patternLen)))
return TRUE;
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -