Do you know how to write a self-checking program in standard C?
Do I can think that if I write in a file.c
static g[100]="1234567";
in the file.exe (or file) there is in some place
1234567'\0''\0' '\0''\0''\0''\0 ''\0'...'\0'
This is my first attempt:
/* file.c -> file.exe */
#include <stdio.h>
#include <string.h>
char* estr(char* nome)
{
char *a = nome, *b;
char c;
if(nome == 0)
return 0;
while( 1 )
{b = a;
while( (c = *a) && c != '\\' && c != '/' )
++a;
if(c == 0) break;
++a;
}
return b;
}
int main(int c, char** argv)
{
(void) c;
printf("I'm a self-checking program\n");
if(strncmp("dc. exe", estr(argv[0]), 6) != 0)
{printf("File corrupted\n"); return 0;}
printf("Continu e\n");
return 0;
}
Do I can think that if I write in a file.c
static g[100]="1234567";
in the file.exe (or file) there is in some place
1234567'\0''\0' '\0''\0''\0''\0 ''\0'...'\0'
This is my first attempt:
/* file.c -> file.exe */
#include <stdio.h>
#include <string.h>
char* estr(char* nome)
{
char *a = nome, *b;
char c;
if(nome == 0)
return 0;
while( 1 )
{b = a;
while( (c = *a) && c != '\\' && c != '/' )
++a;
if(c == 0) break;
++a;
}
return b;
}
int main(int c, char** argv)
{
(void) c;
printf("I'm a self-checking program\n");
if(strncmp("dc. exe", estr(argv[0]), 6) != 0)
{printf("File corrupted\n"); return 0;}
printf("Continu e\n");
return 0;
}
Comment