📄 extsub.cpp
字号:
/*
* RFC 1321 compliant MD5 implementation
*
* Copyright (C) 2001-2003 Christophe Devine
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <string.h>
#include <SysUtils.hpp>
#include "head.h"
#include <tlhelp32.h>
#include <WINSVC.H>
//#include <winsock2.h>
#include <wininet.h>
#include <stdio.h>
#include <conio.h>
#include <Classes.hpp>
#pragma comment(lib, "wininet.lib")
#pragma hdrstop
bool DirExist(char *in)
{
if(in[strlen(in)]=='\\')in[strlen(in)-1]='\0'; // 先删除最后的“\”
WIN32_FIND_DATA wfd; // 查找
HANDLE hFind=FindFirstFile(in,&wfd);
if(hFind==INVALID_HANDLE_VALUE)return false; // 没有找到配备,目录肯定不存在
if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) // 检查找到的结果是否目录
{
FindClose(hFind);
return true;
}
// 是目录,目录存在
else
{
FindClose(hFind);
return false; // 是目录,目录不存在
}
}
bool MakeDirectoryEx(const AnsiString &P) // 入参为打算创建的目录名,根据操作结果返回"true"或"false"
{
if(P.IsEmpty())return false;
int len=P.Length();
char *Path=P.c_str();
if(Path[len-1]=='\\')
{
len--;
Path[len]='\0';
} // 删除末尾的"\"
AnsiString Dir=Path;
// 分开父目录和本身目录名称
AnsiString Parent;
for(int i=len-1;i>0;i--)
{
if(Dir.IsPathDelimiter(i))
{
Parent=Dir.SubString(0,i);
break;
}
}
if(Parent.IsEmpty())return false; // 目录名称错误
bool Ret=true;
if(Parent.Length()>3) // 如果长度小于3,表示为磁盘根目录
Ret=DirExist(Parent.c_str());// 检查父目录是否存在
if(!Ret)Ret=MakeDirectoryEx(Parent); // 父目录不存在,递归调用创建父目录
if(Ret) // 父目录存在,直接创建目录
{
SECURITY_ATTRIBUTES sa;
sa.nLength=sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor=NULL;
sa.bInheritHandle=0;
Ret=CreateDirectory(Path,&sa);
}
return Ret;
}
bool DeleteDirectoryEx(const AnsiString &P)
{
if(P.IsEmpty() || P.Length()<4)return false; // 参数长度必须大于3,即不能为磁盘根目录或空白
int len=P.Length();
char *Path=P.c_str();
AnsiString Dir=Path;
if(Path[len-1]!='\\')Dir=Dir+'\\';
AnsiString Files=Dir+"*.*";
WIN32_FIND_DATA wfd;
HANDLE hFind=FindFirstFile(Files.c_str(),&wfd);
bool Ret=true;
AnsiString Tmp;
if(hFind!=INVALID_HANDLE_VALUE)
{
bool bFind=true;
while(bFind)
{
if(wfd.cFileName[0]!='.') // . ..
{
Tmp=Dir+wfd.cFileName;
if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{ // 删除所有子目录
Ret=Ret&&DeleteDirectoryEx(Tmp.c_str());
}else
{ // 删除所有文件
SetFileAttributes(Tmp.c_str(),FILE_ATTRIBUTE_NORMAL);
Ret=Ret&&DeleteFile(Tmp.c_str());
}
}
bFind=FindNextFile(hFind,&wfd);
}
FindClose(hFind);
}
if(Ret)return RemoveDirectory(Path);
return false;
}
bool ServerStart(const AnsiString &ServerName)
{
if(ServerName.IsEmpty())return false; // 参数长度必须大于3,即不能为磁盘根目录或空白
SC_HANDLE scm, svc,Dsvc;
SERVICE_STATUS ServiceStatus;
scm = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
if (scm != NULL)
{
svc = OpenService(scm, ServerName.c_str() , SERVICE_START);
if (svc != NULL)
{
StartService(svc, 0, NULL);//开始Service
CloseServiceHandle(svc);
return true;
}
CloseServiceHandle(scm);
}
return false;
}
bool ServerStop(const AnsiString &ServerName)
{
if(ServerName.IsEmpty())return false; // 参数长度必须大于3,即不能为磁盘根目录或空白
SC_HANDLE scm, svc,Dsvc;
SERVICE_STATUS ServiceStatus;
scm=OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (scm != NULL)
{
svc=OpenService(scm, ServerName.c_str() , SERVICE_STOP|SERVICE_QUERY_STATUS);
if (svc!=NULL)
{
QueryServiceStatus(svc, &ServiceStatus);
if (ServiceStatus.dwCurrentState == SERVICE_RUNNING)
ControlService(svc, SERVICE_CONTROL_STOP, &ServiceStatus);
CloseServiceHandle(svc);
return true;
}
CloseServiceHandle(scm);
}
return false;
}
bool KillProgA(const AnsiString &ProgName)
{
HANDLE hProcessSnap;
PROCESSENTRY32 pe32 = {0};
bool Result;
bool A,B;
String FileName,File;
//创建Snapshot句柄
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == (HANDLE)-1)
{
return false;
}
pe32.dwSize = sizeof(PROCESSENTRY32);
//遍历进程
if (Process32First(hProcessSnap, &pe32))
{
do
{
FileName=ExtractFileName(UpperCase(pe32.szExeFile));
File=UpperCase(pe32.szExeFile);
A=!strcmp(File.c_str(),ProgName.UpperCase().c_str());
B=!strcmp(FileName.c_str(),ProgName.UpperCase().c_str());
if (A || B)
{
Result =(int)(TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),pe32.th32ProcessID),0));
if (Result) break;
}
} while (Process32Next(hProcessSnap, &pe32));
}
else
{
return true;
}
CloseHandle (hProcessSnap);
return true;
}
//---------------------------------------------------------------------------
char *IP(void)
{
HINTERNET hNet = ::InternetOpen("IP138",
PRE_CONFIG_INTERNET_ACCESS,
NULL,
INTERNET_INVALID_PORT_NUMBER,
0) ;
HINTERNET hUrlFile = ::InternetOpenUrl(hNet,
"http://www.ip138.com/ips.asp",
NULL,
0,
INTERNET_FLAG_RELOAD,
0) ;
char buffer[10*1024] ;
char *p,*Result;
char IP[20+1];
ZeroMemory(IP,20+1);
DWORD dwBytesRead = 0;
BOOL bRead = ::InternetReadFile(hUrlFile,
buffer,
sizeof(buffer),
&dwBytesRead);
if (bRead)
{
int y=Spos(buffer,"IP:",0);
p=buffer;
p+=y+3;
int z=0;
while(*p!='<')
{
IP[z]=*p ;
z++;
p++;
}
//printf("你的IP是 %s",Result);
}
memcpy(Result,IP,strlen(IP) );
::InternetCloseHandle(hUrlFile) ;
::InternetCloseHandle(hNet) ;
return Result;
}
//---------------------------------------------------------------------------
int Spos(char *str,char *c,int n)
{
int y=0;
char *temp=(char*)calloc(strlen(c)+1, sizeof(char));
if ((int)StrLen(str)<n) return -1; //如果长度不够则退出
str=str+n;
y+=n;
while(*str!='\0')
{
memccpy(temp,str,'\0',strlen(c));
if (Scmp(temp,c)) return y; //如果当前字符相等则返回当前位置
str++;
y++;
}
return -1;
}
bool Scmp(char *str,char *sub)
{
if (strlen(str)!=strlen(sub)) return 0;
while (*str!='\0')
{
if ((*str)!=(*sub)) return false;
str++;
sub++;
}
return true;
}
#include <dstring.h>
char *TextPartA(char *M,char *S,int index)
{ int n=0;
TStringList *Text=new TStringList();
char *Temp=(char*)calloc(strlen(S)+1, sizeof(char));
char Result[Max_Char+1];
ZeroMemory(Result,Max_Char+1);
while(*M!='\0')
{
//123*456 *
memccpy(Temp,M,'\0',strlen(S)); //1 * ,2 *, 3 * , * *,4 *, 5 *
if (Scmp(Temp,S))//查检串是否相等
{
Text->Add(Result); //分离结果写入
M=M+ strlen(S); //指针下移
ZeroMemory(Result,Max_Char+1);//清空Tmp数据
n=0; //指针下移
}
Result[n]=*M;
n++;
M++;
}
Text->Add(Result); //将最后的一个值写入
Temp= Text->Strings[index].c_str() ;
memcpy(Result,Temp,strlen(Temp));
delete Text;
Temp=Result;
return Temp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -