home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 1
/
BUGCD1996_0708.ISO
/
pc
/
util
/
pc64
/
virus895.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-08-19
|
3KB
|
122 lines
// VIRUS895.CPP (Visual C++ 16 bit) -- Scans for virus found in 8'95
// When running an infected program, the virus infects the first
// non-infected EXE file in the current directory.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <dos.h>
#include <fcntl.h>
#include <io.h>
#include <sys\types.h>
#include <sys\stat.h>
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned int uint;
typedef unsigned long dword;
typedef int handle;
typedef int flag;
const FALSE = 0;
const TRUE = 1;
word gwScanned = 0;
word gwInfected = 0;
void ScanFile(char* pcName) {
gwScanned++;
handle hFile = _open(pcName, _O_BINARY | _O_RDONLY);
if (hFile == -1) {
perror(pcName);
return;
}
byte abBuffer[256];
if (_read(hFile, abBuffer, 24) < 24) {
perror(pcName);
_close(hFile);
return;
}
word wHeaderSize = *(word*)(abBuffer + 8);
word wIP = *(word*)(abBuffer + 20);
word wCS = *(word*)(abBuffer + 22);
long lEntryPoint = wHeaderSize * 16L + ((wCS * 16L + wIP) & 0x000FFFFF);
_lseek(hFile, lEntryPoint, SEEK_SET);
if (_read(hFile, abBuffer, 5) < 5) {
perror(pcName);
_close(hFile);
return;
}
if (abBuffer[0] == 0xE8) {
long lPos = lEntryPoint + 3 + *(int*)(abBuffer + 1);
_lseek(hFile, lPos, SEEK_SET);
if (_read(hFile, abBuffer, 12) < 12) {
perror(pcName);
_close(hFile);
return;
}
const byte abVirusEntry[12] = {
0x5D, 0x1E, 0x06, 0x8C, 0xD0, 0x80, 0xC4, 0x10, 0x8B, 0x1E, 0x02, 0x00
};
if (memcmp(abBuffer, abVirusEntry, 12) == 0) {
printf("%s is infected\n", pcName);
gwInfected++;
}
} else if (abBuffer[0] == 0xEA) {
printf("%s is suspicious\n", pcName);
}
if (_close(hFile) == -1) {
perror(pcName);
return;
}
}
void ScanDir(char* pcDir) {
printf("%-79s\r", pcDir);
char acName[80];
strcpy(acName, pcDir);
char* pcName = acName + strlen(acName);
if (pcName[-1] != '\\') {
*pcName++ = '\\';
}
strcpy(pcName, "*.*");
_find_t find;
uint uFind = _dos_findfirst(acName, _A_NORMAL | _A_SUBDIR, &find);
while (!uFind) {
strcpy(pcName, find.name);
if (find.attrib & _A_SUBDIR) {
if (find.name[0] != '.') {
ScanDir(acName);
}
} else {
char* pcExt = strchr(pcName, '.');
if (pcExt != NULL && stricmp(pcExt, ".EXE") == 0) {
ScanFile(acName);
}
}
uFind = _dos_findnext(&find);
}
}
int main(int argc, char** argv) {
_bdos(0x0D, 0, 0);
char acStartDir[80];
if (argc < 2) {
_fullpath(acStartDir, ".", 80);
} else {
_fullpath(acStartDir, argv[1], 80);
_strupr(acStartDir);
}
printf("scanning for virus found in 8'95\n");
printf("start directory is %s\n", acStartDir);
ScanDir(acStartDir);
printf("\r%80c%u files scanned, %u files infected\n", '\r', gwScanned, gwInfected);
#ifdef DEBUG
printf("\nPress any key to continue...");
_bdos(0x0C, 0, 0x07);
printf("\r%80c", '\r');
#endif
return 0;
}