hier hätte ich noch einen
er scannt exe dateien auf Key strings
Code:
#include <io.h>
#include <fcntl.h>
int LoadConfig()
{
int file;
long size;
long pos;
long cfgpos;
char *buffer;
char cfgheader[20];
CString cfgdata;
file = _open(GetEXEFile(), _O_BINARY | _O_RDONLY);
if (file == -1)
{
DEBUGMSG("CApp::LoadConfig() can't open EXE file");
return 0; // if we can't read config, we also can't enter stealth mode!
}
_lseek(file, 0, SEEK_END);
size = _tell(file);
buffer = (char *) malloc(size + 1);
if (!buffer)
{
DEBUGMSG("CApp::LoadConfig() can't malloc() memory for EXE file");
return 0; // if we can't read config, we also can't enter stealth mode!
}
_lseek(file, 0, SEEK_SET);
_read(file, buffer, size);
_close(file);
strcpy(cfgheader, "#####"); // configure this to match your desired data key
strcat(cfgheader, "MyKey"); // don't put this in one String to prevent finding the "unique" key twice
strcat(cfgheader, "#####");
for (pos = 0; pos < size - 15; pos++)
{
if (!memcmp(buffer + pos, cfgheader, 15)) break;
}
if (pos == size - 15) //if no data attached, do nothing
{
return 1;
}
cfgpos = pos + 15; //calculate where the config data begins
buffer[size] = 0;
cfgdata = buffer + cfgpos;
free(buffer);
m_strConfig = cfgdata;
//DEBUGMSG(STR(cfgdata));
return 1;
}
oder der hier er startet aplikationen und wartetauf ein return
Code:
int RunApplication(CString strPath, CString strArgs)
{
BOOL rc;
STARTUPINFO si;
PROCESS_INFORMATION pi;
CString strCmdLine;
strCmdLine.Format("%s %s", strPath, strArgs); // why don't we use CreateProcess' 1st parameter?
ZeroMemory(&si, sizeof(si));
si.CB = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
rc = CreateProcess(NULL,
strCmdLine.GetBuffer(strCmdLine.GetLength() + 1),
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi);
if (rc)
{
WaitForSingleObject(pi.hProcess, INFINITE); // Wait until child process exits.
CloseHandle(pi.hProcess); // Close process and thread handles.
CloseHandle(pi.hThread);
}
return rc;
}
einen hab ich noch und zwar nen extension zum splitten von strings
Code:
CString StringPart(CString str, char cDelimiter, int nIndex)
{
if (str.Find(cDelimiter) == -1) return str;
int iPos = 0;
int iEnd;
CString str2;
while (nIndex--)
{
iPos = str.Find(cDelimiter, iPos) + 1;
if (!iPos) return str2;
}
iEnd = str.Find(cDelimiter, iPos);
if (iEnd == -1) iEnd = str.GetLength();
str2 = str.Mid(iPos, iEnd - iPos);
return str2;
}
int StringPartCount(CString str, char cDelimiter)
{
if (str.IsEmpty()) return 0;
return str.Remove(cDelimiter) + 1;
}
int StringPartBegin(CString str, char cDelimiter, int nIndex)
{
if (str.Find(cDelimiter) == -1) return 0;
if (str.IsEmpty()) return 0;
if (nIndex == 0) return 0;
int iPos = 0;
while (nIndex--)
{
iPos = str.Find(cDelimiter, iPos) + 1;
if (!iPos) return iPos;
}
return iPos;
}
so das soll es erstmal gewesen sein