2004-04-23 11:58:43 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2004-07-24 16:08:35 +01:00
|
|
|
#include "system.h"
|
2004-04-23 11:58:43 +01:00
|
|
|
#include "tracebuf.h"
|
|
|
|
|
2004-05-15 17:43:20 +01:00
|
|
|
//! Help counter for the number of unknowns.
|
2004-04-23 11:58:43 +01:00
|
|
|
int cUnk = 0;
|
2004-05-15 17:43:20 +01:00
|
|
|
//! Help counter for the number of todos.
|
2004-04-23 11:58:43 +01:00
|
|
|
int cTod = 0;
|
|
|
|
|
2004-05-15 17:43:20 +01:00
|
|
|
//! Mark all events of the same run before the event as required.
|
|
|
|
/**
|
|
|
|
*@param sys The system.
|
|
|
|
*@param tb The attack buffer.
|
|
|
|
*@param ev The reference event index.
|
|
|
|
*/
|
2004-08-09 11:05:58 +01:00
|
|
|
void
|
|
|
|
markback (const System sys, struct tracebuf *tb, int ev)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
int run = tb->run[ev];
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
while (ev >= 0)
|
|
|
|
{
|
|
|
|
if (tb->run[ev] == run)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
switch (tb->event[ev]->type)
|
|
|
|
{
|
|
|
|
case READ:
|
|
|
|
switch (tb->status[ev])
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
case S_UNK:
|
|
|
|
cUnk--;
|
|
|
|
case S_RED:
|
|
|
|
tb->status[ev] = S_TOD;
|
|
|
|
cTod++;
|
|
|
|
break;
|
|
|
|
case S_TOD:
|
|
|
|
case S_OKE:
|
|
|
|
break;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-08-09 11:05:58 +01:00
|
|
|
break;
|
|
|
|
case SEND:
|
|
|
|
case CLAIM:
|
|
|
|
if (tb->status[ev] == S_UNK)
|
|
|
|
{
|
|
|
|
cUnk--;
|
|
|
|
}
|
|
|
|
tb->status[ev] = S_OKE;
|
|
|
|
break;
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-08-09 11:05:58 +01:00
|
|
|
ev--;
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-05-15 17:43:20 +01:00
|
|
|
//! Minimize the attack.
|
2004-08-09 11:05:58 +01:00
|
|
|
void
|
|
|
|
attackMinimize (const System sys, struct tracebuf *tb)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
int i;
|
|
|
|
int j;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
cUnk = 0;
|
|
|
|
cTod = 0;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
for (i = 0; i < tb->length; i++)
|
|
|
|
{
|
|
|
|
switch (tb->status[i])
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
case S_UNK:
|
|
|
|
cUnk++;
|
|
|
|
break;
|
|
|
|
case S_TOD:
|
|
|
|
cTod++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-08-09 11:05:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
markback (sys, tb, tb->violatedclaim);
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
while (cUnk + cTod > 0)
|
|
|
|
{
|
|
|
|
while (cTod > 0)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
for (i = 0; i < tb->length; i++)
|
|
|
|
// kies een i; laten we de eerste maar pakken
|
|
|
|
{
|
|
|
|
if (tb->status[i] == S_TOD)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == tb->length)
|
|
|
|
{
|
|
|
|
printf ("Some step error.\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
j = i;
|
|
|
|
while (j >= 0 && inKnowledge (tb->know[j], tb->event[i]->message))
|
|
|
|
{
|
|
|
|
// zoek waar m in de kennis komt
|
|
|
|
j--;
|
|
|
|
}
|
|
|
|
tb->status[i] = S_OKE;
|
|
|
|
cTod--;
|
|
|
|
if (j >= 0)
|
|
|
|
{
|
|
|
|
markback (sys, tb, j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (cTod == 0 && cUnk > 0)
|
|
|
|
{
|
|
|
|
for (i = tb->length - 1; i >= 0; i--)
|
|
|
|
// pak laatste i
|
|
|
|
{
|
|
|
|
if (tb->status[i] == S_UNK)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i < 0)
|
|
|
|
{
|
|
|
|
printf ("Some i<0 error.\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
tb->status[i] = S_RED;
|
|
|
|
cUnk--;
|
|
|
|
tb->reallength--;
|
|
|
|
|
|
|
|
j = tracebufRebuildKnow (tb);
|
|
|
|
if (j > -1)
|
|
|
|
{
|
|
|
|
tb->reallength++;
|
|
|
|
markback (sys, tb, i);
|
|
|
|
if (j < tb->length)
|
|
|
|
{
|
|
|
|
tb->link[j] = (tb->link[j] > i ? tb->link[j] : i);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-08-09 11:05:58 +01:00
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-08-09 11:05:58 +01:00
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|