/* HackDemo example 2

   Name   : demo2
   Version: v0.01
   Date   : Tuesday, 20th January 2004

   Purpose: Hacking "protection" systems, example 2

   Creator: Rick Murray
            for Frobnicate issue #20

            http://www.heyrick.co.uk/frobnicate/

            NEEDS NEWER C COMPILER UNLESS YOU'D
            CARE TO JIGGLE THE CODE SLIGHTLY...
*/




// Included files
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "kernel.h"
#include "setjmp.h"

#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
#define MAD_COW 123



jmp_buf viaggio;
jmp_buf andare;



void validate_year(void);
void bomb_out(void);
void svuotare(void);
extern void call_for_error(void);



int  main(void)
{
   int  result = 0;

   result = setjmp(viaggio);
   if (result != 0)
      bomb_out();

   // ...program start-up code would go here...

   svuotare();
   validate_year();

   // ...rest of program would come here...
   printf("Program loaded okay.\n");

   return 0;
}



void validate_year(void)
{
   time_t timeblock;
   struct tm *timeblk;

   time(&timeblock);
   timeblk = localtime(&timeblock);

   if ( (timeblk->tm_year + 1900) > 2003 )
      longjmp(viaggio, MAD_COW);

   return;
}



void bomb_out(void)
{
   longjmp(andare, MAD_COW);
   return; // unreachable code
}



void svuotare(void)
{
   int  result = 0;

   result = setjmp(andare);
   if (result == 0)
      return;

   call_for_error(); // it exits for us...
}
