Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cAppCheck.h
Go to the documentation of this file.
1 //
8 //
9 
10 #if 0
11 
12 #define CAPPCHECK_OBFUSCATE0()\
13  if ( m_AlwaysTrue == 0 ) {\
14  _asm mov eax,__COUNTER__\
15  }
16 
17 CAPPCHECK_OBFUSCATE1()
18 CAPPCHECK_OBFUSCATE2()
19 CAPPCHECK_OBFUSCATE3()
20 
21 CAPPCHECK_OBFUSCATE() CAPPCHECK_OBFUSCATE0()
22 
23 namespace GrayLib
24 {
25  template<int _ICOUNT>
26  class cAppCheck
27  {
31  public:
32  cAppCheck()
33  {
34  // establish the CRC ?
35  CAPPCHECK_OBFUSCATE();
36  m_CRC32 = __COUNTER__;
37  CAPPCHECK_OBFUSCATE();
38  m_AllOK = true;
39  m_AlwaysTrue = true;
40  }
41  void TamperingResult()
42  {
43  // call this very infrequently.
44  // Now take some action if tampering was detected.
45  if ( m_AllOK )
46  return;
47 #ifdef _DEBUG
48  ASSERT(0);
49 #endif
50  // do something bad ! like wipe the stack.
51  }
52  void CheckForTampering()
53  {
54  // Only check this periodically.
55  // or send to the server that it has been tampered with ?
56  // crash or terminate the app LATER if this is detected ?
57  // Never act in direct response. (this is detectable)
58  CAPPCHECK_OBFUSCATE();
59  if ( ++m_iLastCheck < 1000+__COUNTER__ )
60  return;
61  CAPPCHECK_OBFUSCATE();
62  }
63  public:
64  FARPROC m_pCallCheckForDebugger; // am i being debugged ?
65  BYTE m_padding1[__COUNTER__&0xf]; // random sized padding
66  int m_iLastCheck;
67  BYTE m_padding2[__COUNTER__&0x7]; // random sized padding
68  UINT32 m_CRC32;
69  bool m_AlwaysTrue;
70  BYTE m_padding3[__COUNTER__&0x3]; // random sized padding
71  bool m_AllOK;
72  };
73 
74  // ON a per file basis. create a check for the applications CRC
75  // #include "cAppCheck.h"
76 #define CAPPCHECK_DECLARE() static cAppCheck<__COUNTER__> g_AppCheck;
77 #define CAPPCHECK_CHECK() g_AppCheck.CheckForTampering();
78 };
79 #else
80 
81 #define CAPPCHECK_DECLARE() __noop
82 #define CAPPCHECK_CHECK() __noop
83 
84 #endif
#define ASSERT(exp)
Definition: cDebugAssert.h:87
Definition: cMesh.h:22