26.09.2018 Views

Antivirus hackers handbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

42 Part I ■ <strong>Antivirus</strong> Basics<br />

pthread_mutex_init((pthread_mutex_t *)(v4 + 144), 0LL);<br />

memset(&v5[12], 0, 0x7EuLL);<br />

g_user_callbacks = (__int64)v5;<br />

result = g_Engine->baseclass_0->CAEEngineDispatch_SetUserCallBack<br />

(g_Engine, v5);<br />

if ( result < 0 )<br />

{<br />

fwrite("SetUserCallBack() failed!\n", 1uLL, 0x1AuLL, stderr);<br />

exit(1);<br />

}<br />

This code is used to set a few callbacks. For example, you could install callbacks<br />

to be notified every time a new file is opened, created, read, written, and so on.<br />

Do you want to write a generic unpacker using the Comodo engine? Install a<br />

notification callback and wait for it to be called, copy the temporary file or buffer,<br />

and you are done! Generic unpackers based on antivirus engines are popular.<br />

This is interesting, but the purpose of this demonstration is to reverse-engineer<br />

the core to get sufficient information about how to write a C/C++ SDK to interact<br />

with the Comodo kernel. Now that the maybe_IFrameWork_CreateInstance<br />

function has been analyzed, go back and look at the main function. The next<br />

code after the call to the previously analyzed function will be similar to the<br />

following pseudo-code:<br />

if ( __lxstat(1, filename, &v7) == -1 )<br />

{<br />

v5 = __errno_location();<br />

v6 = strerror(*v5);<br />

fprintf(stderr, "%s: %s\n", filename, v6);<br />

}<br />

else<br />

{<br />

if ( verbose )<br />

fwrite("-----== Scan Start ==-----\n", 1uLL, 0x1BuLL, stdout);<br />

if ( (v8 & 0xF000) == 0x4000 )<br />

scan_directory(filename, verbose, (__int64)&scanned_files,<br />

(__int64)&virus_found);<br />

else<br />

scan_stream(filename, verbose, &scanned_files,<br />

&virus_found);<br />

if ( verbose )<br />

fwrite("-----== Scan End ==-----\n", 1uLL, 0x19uLL, stdout);<br />

fprintf(stdout, "Number of Scanned Files: %d\n",<br />

(unsigned int)scanned_files);<br />

fprintf(stdout, "Number of Found Viruses: %d\n",<br />

(unsigned int)virus_found);<br />

}<br />

This code checks whether the path pointed out by the global variable src<br />

exists. If it does, the code calls either scan_directory or scan_stream, depending<br />

on the flags returned by the call to __lxstat. The function to scan directories

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!