X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f X-Authentication-Warning: mcomail01.maxtor.com: iscan owned process doing -bs X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Subject: RE: Generating a CRC over a DJGPP programs binary code in memory? Date: Mon, 25 Jul 2005 11:54:15 -0600 Message-ID: <71078E41DDE3E541B024832F34BC3D0D4BC2E4@cowexc03.corp.mxtr.net> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: djgpp weekly digest for 23 Jul 2005 Thread-Index: AcWQBQRgxBvvgGvQSQy5IVkrUolzfgBPC69Q From: "Schumacher, Gordon" To: "DJGPP List \(E-mail\)" X-OriginalArrivalTime: 25 Jul 2005 17:54:15.0302 (UTC) FILETIME=[DF2BD260:01C59141] Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id j6PHsONj002044 # From: List Admin at delorie.com [mailto:dj-admin AT delorie DOT com] # Sent: Saturday, July 23, 2005 10:05 PM # To: djgpp weekly digest # Subject: djgpp weekly digest for 23 Jul 2005 # # From: "Gundolf" # Subject: Generating a CRC over a DJGPP programs binary code in memory? # Date: 21 Jul 2005 10:44:03 -0700 # To: djgpp AT delorie DOT com # # Hello all, # # Maybe someone can help me, I need to get an application to self-check # that certain portions of its binary code haven't been altered once it # has been started. # To do that, I'd like to generate a CRC over the code between certain # markers inserted into the binary code via something like "asm DB ..." # (assuming there is an equivalent for that in DJGPP) You might look at using a tip that I got from DJ Delorie a while back. You can get the program's location in memory like this: extern char* _text asm(".text"); extern char* _etext asm("etext"); static char* __dbg_progstart = (char*) &_text; static size_t __dbg_progsize = (&_etext - &_text) - sizeof(uint32); Now, __dbg_progstart is a pointer to the start of your program, and __dbg_progsize contains its size in bytes. So you could walk over this space in memory to do your checking. I'm using this code to do something very close to what you're after - I have some functions to take CRC "snapshots" of a block of memory to ensure they haven't changed (i.e., by someone writing with a wild pointer) and the first thing I do in my code is take a snapshot of the codespace.