Advertisement
5_2007-2008 Complete Applications #172534

Let your EXE check itself for VIRUS infection

As far as I know viruses modify the header of your complied EXE to jump to a different location to execute the virus. This means the header will change and your EXE file will (with some viruses) have the virus attached to the end of the EXE file. I've included a module you should use in your EXE file with a function it should call to check itself. The rest of the code as well as the module you have to include in your project will compile as an inoculate program to write the footer to your EXE file so the EXE file can check itself. (THIS SOFTWARE IS NOT FOR PROGRAMMERS THAT WRITE VIRUSES ;) PS: This program will not make your program protect itself but will let the user know when it's infected.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
'Save the files as described above
'and compile your ENOCK.EXE program.
'All you have to do now is to include
'the ENOCK.BAS file in your project
'and add this code to the startup of
'your program .. :)

  Dim lCalc As Long
  'Get the current CheckSum value
  lCalc = CreateLong(CalcCheckSum(""))
  If lCalc > 0 Then
    Select Case CheckENOCK("", lCalc)
      Case 2 'File is ENOCKED and CheckSum was Checked
        MsgBox "File is Authentic ....", 32
      Case 0 'Some Error occured
        'Some error occured and will be displayed by the function
      Case -1 'File is NOT ENOCKED and didn't check Checksum
        MsgBox "File is NOT ENOCKED and didn't check Checksum", 32
      Case -2 'File is ENOCKED and CheckSum doesn't match
        MsgBox "File is NOT Authentic, posible virus infection ", 16
    End Select
  End If

<html>
<head>
<title>Old snake under modern Wind32 SDK</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="keywords" content="alarm, clock, scheduler, planner, timer, time, span, due, notebook, notes, planning, calendar, message, messenger, remind, reminder, game, graphic, sound, puzzle, child, pictures, animation, color, multimedia, program, programming, software design, IT, OOP, OOA, OOD, tutorial, book, article, C++, cpp, sources, project, VC, MFC, Development Studio, student, task, education, exercise, degree work, thesis, research, freeware, shareware, download, good, best, cool, wonderful, nice, colored, alarms, schedulers planners, timers, notebooks, plannings, calendars, messages, messengers, reminders, games, sounds, puzzles, children, animation, colors, programs, tutorials, books, articles, projects, tools, utils, students, tasks, exercises, works, researches, freeware, shareware, download, downloads, good, best, cool, wonderful, nice, colored">
<meta name="description" content="Windows home and office software. Alarm clock, scheduler, timer. Cool design and clean interface.">
<style type="text/css">
<!--
.text { font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #000000; list-style-position: outside; list-style-type: circle}.header { font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #000000; list-style-position: outside; list-style-type: circle ; text-decoration: underline}
-->
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#6699CC" vlink="#666699" alink="#0099FF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<br>
<table width="800" border="0" cellspacing="0" cellpadding="10">
 <tr> 
 <td width="100" valign="top"> </td>
 <td colspan="2" class="text" valign="top" align="left"> 
  <div align="left">
<table width="400" border="0" cellspacing="0" cellpadding="0" align="left">
 <tr> 
 <td class="text" width="600" height="100" align="left" valign="top"> 
	   <div align="left"><img src="http://www.brigsoft.com/images/BrigSoftLogo.gif" width="600" height="61"> 
    </div>
	</td>
 </tr>
</table> </div>
 </td>
 </tr>
 <tr> 
 <td width="100" valign="top"> </td>
 <td width="400" valign="top" align="left" class="text"> 
  <div align="left"><font size="4"><b>Old snake under modern Wind32 SDK</b></font> 
  <p><a href="mailto:support@brigsoft.com?subject=SnakeArticle">O. Reshta</a></p>
  <p>This article would be useful for students that studing IT technology 
   and programming. <br>
   This article for you if you want to know little more about</p>
  </div>
  <ul>
  <li> 
   <div align="left"> Win32 SDK using,</div>
  </li>
  <li> 
   <div align="left"> Graphics and sounds output,</div>
  </li>
  <li> 
   <div align="left"> Dynamic process modeling,</div>
  </li>
  <li> 
   <div align="left"> Visual C++ and C++ using,</div>
  </li>
  <li> 
   <div align="left"> OOA / OOD principles.</div>
  </li>
  </ul>
  <div align="left"> 
  <p>The article is based on BSSnake cpp sources. You can find whole VC++ 
   v6.0 project on the site <a href="http://www.brigsoft.com">http://www.brigsoft.com</a>. 
   The article includes exercises tasks.</p>
  <p>Probably, themes of the article would be difficult for you if don't 
   know C++ language and never wrote programs under Windows using Microsoft 
   VC++.</p>
  <p class="header"> Win SDK or MFC</p>
  </div>
  Usually we use MFC while programming enterprise - level projects. But it 
  is not a rule that we must to use it always. I think that you must prefer 
  SDK if 
  <ol>
  <li> 
   <div align="left"> you don't use document/view architecture, splitting 
   windows, toolbars, serialization process;</div>
  </li>
  <li> 
   <div align="left"> you don't use other libraries that use MFC.</div>
  </li>
  </ol>
  <div align="left"> 
  <p>If you want to create a small utility program or a puzzle game then 
   using SDK would be much wise solution. Time that you spend to program 
   will be same, exe file will be much shorter, and program installation 
   process will be cleaner. While you distribute MFC-Based project you 
   must build it with static MFC libraries ore distribute project with 
   MFC dlls. There is no any warranty that your customer has dlls for your 
   program. Old MFC-Based programs must work with new MFC versions. They 
   must but don't do it always. Your customer will be very glad if after 
   installing your project some his old software products will begin hang 
   up.</p>
  <p>Either you use SDK or don't you must know it good. A big part of MFC 
   is SDK interface only. The most MFC window functions are same as SDK. 
   Difference is very small. CWnd class stores window handle and you must 
   not use it as the first parameter of function. CDC class stores DC handle 
   and most of graphic objects are same as SDK functions. CRect is based 
   on RECT structure, etc. There are good container classes as CArray, 
   CList, CMap, CString in MFC. But you can easy change them by STL classes. 
   STL much shorter and is a part of C++ standard. It is multiplatform 
   library. There are some SDK functions that are absent in MFC and you 
   use them direct from your code. So, good Windows programmer must know 
   SDK. The best way to know something is a project creating. If you use 
   VC++ and never used clean SDK try to write some program and you would 
   see that you begin understand MFC solutions much better. To understand 
   how SDK project works you can look at BSSnake sources. They are short 
   enough. </p>
  <p class="header"> Snake game</p>
  <p> The game rules are very plane. Snake moves in the window with some 
   speed. You can turn it left/right. If the snake eats a mouse it grows. 
   If snake eats hedgehog, its body or window border it dies. The speed 
   of snake is growing. Your task is to live as long as it possible. Score 
   is a function of snake length. </p>
  <p class="header"> BSSnake solutions</p>
  <p>OOP model of this project is very simple. There are no such things 
   as inheritance, polymorphism, abstract classes and RTTI here. I didn't 
   want to write classic OOP program according all rules that I used in 
   the big projects. I was trying to make shot and clean program. If you 
   are beginner in C++ this code is for you! All main games classes are 
   placed in two files Game.h and Game.cpp. They are short enough for easy 
   understanding.<br>
   Imagine yourself a beginner that makes this snake project. He will create 
   Snake class and put in it data that describe a snake. For example, some 
   snake units with (x,y) coordinates. Than he will create method Grow() 
   that will add new unit to snake. Then he will make method Move(), that 
   change all coordinates of all units. Then he will understand that the 
   array is bad solution for snake body storing because every addition 
   will recreate whole array and he will replace the array by list. Then 
   he will find that Snake.Draw() method that redraw all snake units is 
   working too slowly when number of units overload some dozens. At last 
   he will use DirectX to speed up graphic operations.<br>
   I did not so. My snake is not owner of its body! Actually we must not 
   move all Snake. We can move and redraw only the tail and the head. Other 
   body units are not changed. So speed of our solution is not depends 
   from snake length. All information that I need to snake control is storing 
   in the game field cells. Snake object remembers only its head and tail 
   coordinates. While head is moving it writes moving direction to its 
   field cell so we have track to tail moving and tail always gets direction 
   that it needs from cell of game field.<br>
   The game field is a matrix of Cells. A Cell stores direction and its 
   type and nothing more. Its pixel coordinates can be counted easy. Cell 
   also draw itself using bitmap drawing function BitBlt. Bitmap is static 
   member of Cell class and all cells share it. <br>
   PlayBox class controls field objects and cells drawing. All process 
   is execute by CPlayBox::NextTimeStep(). This method is cold every time 
   step. It calls mice generator and snake moving.<br>
   To stop the game I use try/catch/throw mechanism. There are three events 
   that must stop a game and they occur on the second level under situation 
   handle. It would be boring to use BOOL return type to process these 
   events.</p>
  <p class="header"> System solutions</p>
  <p> The project was creating by Visual Studio(V6.0) Win32 Application 
   wizard. My changes are very small. I use global object gEngine to encapsulate 
   all windows message and time tick execution. I always do so because 
   I don't like long switch constructions. <br>
   For time tick generator I did not use WM_TIMER window message because 
   it has low priority. I replaced GetMessage() function, that was waiting 
   thread messages, by PeekMessage() that was not stopping the program. 
   So I created something as OnIdele() method of MFC application class. 
   You would be very surprised if will try testing your system resources. 
   The snake eats 100% of processor! Do not afraid. It is only joke of 
   Microsoft. The program has normal priority and all other process receive 
   their processor ticks. But other process is sleeping if have not any 
   to do. Opposite BSSnake executes its own timer.</p>
  <p>WinMain Message loop looks so :</p>
  <p> <code><font color="#0000FF">while (1) <br>
   {<br>
   if(!PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){<br>
   // OR: there are no any message. OnIdle;-)<br>
   gEngine.TimerProc();<br>
   continue;<br>
   }</font></code></p>
  <p><font color="#0000FF"><code> if (!TranslateAccelerator(msg.hwnd, hAccelTable, 
   &msg)) <br>
   {<br>
   TranslateMessage(&msg);<br>
   DispatchMessage(&msg);<br>
   }</code></font></p>
  <p><font color="#0000FF"><code> if(msg.message == WM_QUIT){<br>
   break;<br>
   };<br>
   }</code></font></p>
  <p> Standard Win32 Application wizard generate a project that cannot use 
   ASSERT macros. I take this macros from MFC and make him working. It 
   stops later then it must stop but you can see and test the program stack 
   as you do it using MFC.</p>
  <p>Insert this strings into stdafx.h and ASSERT macros begins to work 
   (but so-so)</p>
  <p><code><font color="#0000FF">#include <crtdbg.h><br>
   #define ASSERT _ASSERT</font></code></p>
  <p class="header">Appendix - Exersices</p>
  <p>Symbol (*) marks difficult tasks.<br>
   <br>
   <b> A</b>. (OOA/OOD exercise)</p>
  </div>
  <ol>
  <li>Create OOA/OOD documents for this project.</li>
  <li> Create class diagram of BSSnake project using Rational Rose ore other 
   case tools.</li>
  </ol>
  <div align="left"> 
  <p><b> B</b>. (C++ exercises)</p>
  </div>
  <ol>
  <li>Memory allocation. Make dynamic memory allocation of cells array using 
   operator new. Don't forget to destroy it while program is finished.</li>
  <li>(*) Make CellBase abstract class and its children for every kind of 
   cell units. Store base class object pointers or references in the field 
   array. Use virtual function Draw() to draw every unit. Use dynamic_cast 
   operator to test what kind of cell is placed in front of snake.</li>
  <li>(*) Create abstract class CVictim and its child CMouse and CHedgehog. 
   Try to use them instead CMouse class.</li>
  <li> Make field class with static array of cells. Inherit it by all classes 
   that need. It is a good solution to remove global array of cells.</li>
  <li> Every cell store cell type and direction as 32 bit integer. Use bit 
   fields for storing this information. It makes game field array much 
   shorter. How much?</li>
  <li> There are a lot of inline functions in a project. Why we use inline 
   functions? Why many software firms forbid its programmers to use them? 
   Replace all inline functions by normal class member functions. Did it 
   make the snake slowly? Did project become cleaner and easier for modifications? 
  </li>
  </ol>
  <div align="left"> 
  <p><b>C</b>. (Game improving exercises)</p>
  </div>
  <ol>
  <li>Make options dialog. Make game field size and start speed as option.</li>
  <li> Make screen center align of game window.</li>
  <li> Make background as bitmap.</li>
  <li> Make opening background. A background picture opens only in cells 
   where a snake was.</li>
  <li> Include mid files player.</li>
  <li> Store options in the Win register.</li>
  <li> Make pause key.</li>
  <li> Make some new victims.</li>
  <li>(*) Make victims that can walking in the field.</li>
  <li>(*) Make some concurrent snakes. Player controls one snake computer 
   controls other.</li>
  <li> Smooth snake moving. This time snake jumps every step to next cell. 
   Make moving from pixel to pixel. </li>
  </ol>
  <div align="left"> 
  <p><b>D</b>. (System programming exercises)</p>
  </div>
  <ol>
  <li> 
   <div align="left"> Try find solution of timer tick that not use 100% 
   of processor.<br>
   <br>
   <br>
   </div>
  </li>
  </ol>
  <div align="center"><a href="mailto:support@brigsoft.com?subject=SnakeArticle">Contact 
  author </a><br>
  <br>
  </div>
 </td>
 <td width="180" valign="top" align="left">  </td>
 </tr>
</table>
</body>
</html>

Upload
Original Comments (3)
Recovered from Wayback Machine