2004-04-23 11:58:43 +01:00
|
|
|
/*
|
|
|
|
* output.c
|
|
|
|
*
|
|
|
|
* Outputs an attack.
|
|
|
|
* Currently, every attack is printed.
|
|
|
|
* TODO move attacks to a buffer, and print _only_ the shortest one.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2004-07-24 16:08:35 +01:00
|
|
|
#include "system.h"
|
2004-04-23 11:58:43 +01:00
|
|
|
#include "latex.h"
|
|
|
|
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
void
|
|
|
|
linePrint (int i)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-04-23 12:03:07 +01:00
|
|
|
indent ();
|
|
|
|
while (i > 0)
|
|
|
|
{
|
|
|
|
printf ("--------");
|
|
|
|
i--;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
int
|
2004-07-20 13:41:56 +01:00
|
|
|
correspondingSend (const System sys, int rd)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
int labelMatch = 0;
|
|
|
|
int toMatch = 0;
|
|
|
|
int fromMatch = 0;
|
|
|
|
int tofromMatch = 0;
|
|
|
|
int messageMatch = 0;
|
|
|
|
int nMatches = 0;
|
|
|
|
int maxNMatches = 0;
|
|
|
|
|
|
|
|
int readEvent = rd;
|
|
|
|
int sendEvent = -1;
|
|
|
|
int bestSendEvent = -1;
|
|
|
|
|
|
|
|
for (sendEvent = readEvent; sendEvent >= 0; sendEvent--)
|
|
|
|
{
|
|
|
|
if (sys->traceEvent[sendEvent]->type == SEND)
|
|
|
|
{
|
|
|
|
/* do all the different kind of matchings first */
|
|
|
|
|
|
|
|
labelMatch =
|
|
|
|
isTermEqualFn (sys->traceEvent[sendEvent]->label,
|
|
|
|
sys->traceEvent[readEvent]->label);
|
|
|
|
toMatch =
|
|
|
|
isTermEqualFn (sys->traceEvent[sendEvent]->to,
|
|
|
|
sys->traceEvent[readEvent]->to);
|
|
|
|
fromMatch =
|
|
|
|
isTermEqualFn (sys->traceEvent[sendEvent]->from,
|
|
|
|
sys->traceEvent[readEvent]->from);
|
|
|
|
tofromMatch = toMatch || fromMatch;
|
|
|
|
messageMatch =
|
|
|
|
isTermEqualFn (sys->traceEvent[sendEvent]->message,
|
|
|
|
sys->traceEvent[readEvent]->message);
|
|
|
|
|
|
|
|
/* calculate the score */
|
|
|
|
|
|
|
|
nMatches = labelMatch + tofromMatch + messageMatch;
|
|
|
|
|
|
|
|
if (nMatches == 3)
|
|
|
|
{
|
|
|
|
/* bingo! success on all matches */
|
|
|
|
|
|
|
|
//printf("Found perfect match: %d\n", s);
|
|
|
|
bestSendEvent = sendEvent;
|
|
|
|
break;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
if (nMatches > maxNMatches)
|
|
|
|
{
|
|
|
|
/* if we found a better candidate than we already had, we'll update */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
//printf("Comparing SEND #%d: ",s);
|
|
|
|
//if (labelMatch) printf("label ");
|
|
|
|
//if (toMatch) printf("to ");
|
|
|
|
//if (fromMatch) printf("from ");
|
|
|
|
//if (messageMatch) printf("message ");
|
|
|
|
//printf("\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
/* however, we first want to be sure that at least some matches are successful */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
if (labelMatch && messageMatch)
|
|
|
|
{
|
|
|
|
/* strongest restriction: message and label should match */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
maxNMatches = nMatches;
|
|
|
|
bestSendEvent = sendEvent;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
}
|
|
|
|
else if (messageMatch)
|
|
|
|
{
|
|
|
|
/* if label AND message don't match: */
|
|
|
|
/* at least message should match */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
maxNMatches = nMatches;
|
|
|
|
bestSendEvent = sendEvent;
|
|
|
|
}
|
|
|
|
else if (labelMatch)
|
|
|
|
{
|
|
|
|
/* if message doesn't match */
|
|
|
|
/* the label should matches */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
maxNMatches = nMatches;
|
|
|
|
bestSendEvent = sendEvent;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
//printf("Best match: %d maxNMatches: %d\n", s, maxNMatches);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
//bestSendEvent = NULL;
|
|
|
|
if (bestSendEvent == -1)
|
|
|
|
{
|
|
|
|
/*Termlist tl;
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
//newtl = knowledgeNew(sys->traceKnow[i],sys->traceKnow[i+1]);
|
|
|
|
|
|
|
|
for (tl = sys->traceKnow[rd]->basic; tl != NULL; tl = tl->next)
|
|
|
|
{
|
|
|
|
t = tl->term;
|
|
|
|
termPrint(t);
|
|
|
|
printf(" - ");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
for (tl = sys->traceKnow[rd]->encrypt; tl != NULL; tl = tl->next)
|
|
|
|
{
|
|
|
|
t = tl->term;
|
|
|
|
termPrint(t);
|
|
|
|
printf(" - ");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
for (tl = sys->traceKnow[rd]->inverses; tl != NULL; tl = tl->next)
|
|
|
|
{
|
|
|
|
t = tl->term;
|
|
|
|
termPrint(t);
|
|
|
|
printf(" - ");
|
|
|
|
}
|
|
|
|
printf("\n"); */
|
|
|
|
|
|
|
|
int u;
|
|
|
|
|
|
|
|
for (u = 0; u < rd; u++)
|
|
|
|
{
|
|
|
|
if (sys->traceEvent[u]->type == SEND)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
//termPrint(readEvent->message);
|
|
|
|
//printf("\n");
|
|
|
|
knowledgePrint (sys->traceKnow[u]);
|
|
|
|
//printf("Is received message in knowledge after SEND %d? %d\n", u, inKnowledge(sys->traceKnow[u+1],readEvent->message));
|
|
|
|
if (inKnowledge
|
|
|
|
(sys->traceKnow[u + 1],
|
|
|
|
sys->traceEvent[readEvent]->message))
|
|
|
|
{
|
|
|
|
bestSendEvent = u;
|
|
|
|
break;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
if (bestSendEvent == -1)
|
|
|
|
{
|
|
|
|
printf ("!! Could not find a matching SEND\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//latexMessagePrint(sys, bestSendEvent, readEvent);
|
|
|
|
//printf("Latex: ");
|
|
|
|
//termPrint(bestSendEvent->from);
|
|
|
|
//printf(" -> ");
|
|
|
|
if (!isTermEqualFn
|
|
|
|
(sys->traceEvent[bestSendEvent]->to,
|
|
|
|
sys->traceEvent[readEvent]->to))
|
|
|
|
{
|
|
|
|
//termPrint(bestSendEvent->to);
|
|
|
|
//printf(" -> ");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
if (!isTermEqualFn
|
|
|
|
(sys->traceEvent[bestSendEvent]->from,
|
|
|
|
sys->traceEvent[readEvent]->from))
|
|
|
|
{
|
|
|
|
//termPrint(readEvent->from);
|
|
|
|
//printf(" -> ");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
//termPrint(readEvent->to);
|
|
|
|
//printf("\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
return bestSendEvent;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
void
|
2004-07-20 13:41:56 +01:00
|
|
|
tracePrint (const System sys)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-05-26 13:17:09 +01:00
|
|
|
int i, j;
|
|
|
|
int lastrid;
|
|
|
|
int width;
|
|
|
|
Termlist newtl;
|
|
|
|
|
|
|
|
void sticks (int i)
|
|
|
|
{
|
|
|
|
while (i > 0)
|
|
|
|
{
|
|
|
|
printf ("|\t");
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sticksLine (void)
|
|
|
|
{
|
|
|
|
sticks (width);
|
|
|
|
printf ("\n");
|
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
if (sys->latex)
|
|
|
|
{
|
|
|
|
//latexTracePrint(sys);
|
|
|
|
return;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
/* fix the 'next' knowledge, this is required because sometimes
|
|
|
|
* when calling this function, the next knowledge is not stored
|
|
|
|
* yet, but required for the general form of the output . */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
sys->traceKnow[sys->step + 1] = sys->know;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
/* how wide is the trace? */
|
|
|
|
width = 0;
|
|
|
|
for (i = 0; i <= sys->step; i++)
|
|
|
|
{
|
|
|
|
if (sys->traceRun[i] >= width)
|
|
|
|
width = sys->traceRun[i] + 1;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
linePrint (width);
|
|
|
|
indent ();
|
|
|
|
printf ("Dumping trace:\n");
|
|
|
|
linePrint (width);
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
/* first some parameter issues */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
knowledgePrint (sys->traceKnow[0]);
|
|
|
|
/* also print inverses */
|
|
|
|
indent ();
|
|
|
|
printf ("Inverses: ");
|
|
|
|
knowledgeInversesPrint (sys->traceKnow[0]);
|
|
|
|
printf ("\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
/* Trace columns header. First the run identifier and role. On the
|
|
|
|
* second line we have the perceived agents for each partner role.
|
|
|
|
* These are printed in the same order as the role specification in the
|
|
|
|
* protocol. */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
linePrint (width);
|
|
|
|
indent ();
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
for (i = 0; i < width; i++)
|
|
|
|
{
|
|
|
|
termPrint (sys->runs[i].role->nameterm);
|
|
|
|
printf ("#%i\t", i);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("\n");
|
|
|
|
for (i = 0; i < width; i++)
|
|
|
|
{
|
|
|
|
termPrint (agentOfRun (sys, i));
|
|
|
|
printf ("\t");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
for (i = 0; i < width; i++)
|
|
|
|
{
|
|
|
|
agentsOfRunPrint (sys, i);
|
|
|
|
printf ("\t");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
/* now we print the actual trace */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
linePrint (width);
|
|
|
|
lastrid = -1;
|
|
|
|
for (i = 0; i <= sys->step; i++)
|
|
|
|
{
|
|
|
|
/* yields extra newlines between switching of runs */
|
|
|
|
|
|
|
|
j = sys->traceRun[i];
|
|
|
|
if (j != lastrid)
|
|
|
|
{
|
|
|
|
sticksLine ();
|
|
|
|
lastrid = j;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
/* print the actual event */
|
|
|
|
|
|
|
|
indent ();
|
|
|
|
sticks (j);
|
|
|
|
roledefPrint (sys->traceEvent[i]);
|
|
|
|
|
|
|
|
//if (sys->traceEvent[i]->type == READ && !sys->traceEvent[i]->internal)
|
|
|
|
//{
|
|
|
|
/* calls routine to find the best SEND-candidate */
|
|
|
|
/* the result is not yet being used */
|
|
|
|
|
|
|
|
// printf("\n");
|
|
|
|
// correspondingSend(sys, i);
|
|
|
|
//}
|
|
|
|
|
|
|
|
/* have we learnt anything new? */
|
|
|
|
newtl = knowledgeNew (sys->traceKnow[i], sys->traceKnow[i + 1]);
|
|
|
|
if (newtl != NULL)
|
|
|
|
{
|
|
|
|
printf ("\n");
|
|
|
|
sticksLine ();
|
|
|
|
sticks (width);
|
|
|
|
printf ("/* Intruder learns ");
|
|
|
|
termlistPrint (newtl);
|
|
|
|
termlistDelete (newtl);
|
|
|
|
printf (" */");
|
|
|
|
lastrid = -1;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
/* new line */
|
|
|
|
printf ("\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
switch (sys->clp)
|
|
|
|
{
|
2004-04-23 11:58:43 +01:00
|
|
|
case 1:
|
2004-04-23 12:03:07 +01:00
|
|
|
indent ();
|
|
|
|
printf ("---[ constraints ]-----\n");
|
|
|
|
constraintlistPrint (sys->constraints);
|
|
|
|
break;
|
2004-04-23 11:58:43 +01:00
|
|
|
default:
|
2004-04-23 12:03:07 +01:00
|
|
|
break;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
linePrint (width);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
void
|
2004-07-20 13:41:56 +01:00
|
|
|
attackDisplayAscii (const System sys)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-04-23 12:03:07 +01:00
|
|
|
int i, j;
|
|
|
|
int length;
|
|
|
|
int lastrid;
|
|
|
|
int width;
|
|
|
|
Termlist newtl;
|
|
|
|
struct tracebuf *tb;
|
|
|
|
|
2004-05-26 13:17:09 +01:00
|
|
|
void sticks (int i)
|
|
|
|
{
|
|
|
|
while (i > 0)
|
|
|
|
{
|
|
|
|
printf ("|\t");
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sticksLine (void)
|
|
|
|
{
|
|
|
|
sticks (width);
|
|
|
|
printf ("\n");
|
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
/* attack trace buffer */
|
|
|
|
tb = sys->attack;
|
|
|
|
length = sys->attack->length;
|
|
|
|
|
|
|
|
/* set variables */
|
|
|
|
varbufSet (sys, tb->variables);
|
|
|
|
|
|
|
|
/* how wide is the trace? */
|
|
|
|
width = 0;
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
if (tb->run[i] >= width)
|
|
|
|
width = tb->run[i] + 1;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
linePrint (width);
|
|
|
|
indent ();
|
|
|
|
printf ("Dumping trace:\n");
|
|
|
|
linePrint (width);
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
/* first some parameter issues */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
knowledgePrint (tb->know[0]);
|
|
|
|
printf ("Variables: ");
|
|
|
|
termlistPrint (sys->variables);
|
|
|
|
printf ("\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
/* Trace columns header. First the run identifier and role. On the
|
|
|
|
* second line we have the perceived agents for each partner role.
|
|
|
|
* These are printed in the same order as the role specification in the
|
|
|
|
* protocol. */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
linePrint (width);
|
|
|
|
indent ();
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
for (i = 0; i < width; i++)
|
|
|
|
{
|
|
|
|
termPrint (sys->runs[i].role->nameterm);
|
|
|
|
printf ("#%i\t", i);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("\n");
|
|
|
|
for (i = 0; i < width; i++)
|
|
|
|
{
|
|
|
|
termPrint (agentOfRun (sys, i));
|
|
|
|
printf ("\t");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
for (i = 0; i < width; i++)
|
|
|
|
{
|
|
|
|
agentsOfRunPrint (sys, i);
|
|
|
|
printf ("\t");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
/* now we print the actual trace */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
linePrint (width);
|
|
|
|
lastrid = -1;
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
/* yields extra newlines between switching of runs */
|
|
|
|
|
|
|
|
j = tb->run[i];
|
|
|
|
if (j != lastrid)
|
|
|
|
{
|
|
|
|
sticksLine ();
|
|
|
|
lastrid = j;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
/* print the actual event */
|
|
|
|
|
|
|
|
indent ();
|
|
|
|
sticks (j);
|
|
|
|
roledefPrint (tb->event[i]);
|
|
|
|
|
|
|
|
//if (sys->traceEvent[i]->type == READ && !sys->traceEvent[i]->internal)
|
|
|
|
//{
|
|
|
|
/* calls routine to find the best SEND-candidate */
|
|
|
|
/* the result is not yet being used */
|
|
|
|
|
|
|
|
// printf("\n");
|
|
|
|
// correspondingSend(sys, i);
|
|
|
|
//}
|
|
|
|
|
|
|
|
/* have we learnt anything new? */
|
|
|
|
newtl = knowledgeNew (tb->know[i], tb->know[i + 1]);
|
|
|
|
if (newtl != NULL)
|
|
|
|
{
|
|
|
|
printf ("\n");
|
|
|
|
sticksLine ();
|
|
|
|
sticks (width);
|
|
|
|
printf ("/* Intruder learns ");
|
|
|
|
termlistPrint (newtl);
|
|
|
|
termlistDelete (newtl);
|
|
|
|
printf (" */");
|
|
|
|
lastrid = -1;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
/* new line */
|
|
|
|
printf ("\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
linePrint (width);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
void
|
2004-07-20 13:41:56 +01:00
|
|
|
attackDisplay (const System sys)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-04-23 12:03:07 +01:00
|
|
|
if (sys->latex)
|
|
|
|
{
|
|
|
|
attackDisplayLatex (sys);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
attackDisplayAscii (sys);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
2004-07-12 14:58:41 +01:00
|
|
|
|
2004-07-13 10:14:03 +01:00
|
|
|
/*
|
|
|
|
*-------------------------------------------
|
|
|
|
* state space graph section
|
|
|
|
*-------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
void
|
|
|
|
graphInit (const System sys)
|
2004-07-12 14:58:41 +01:00
|
|
|
{
|
|
|
|
Termlist tl;
|
|
|
|
|
2004-07-12 15:47:43 +01:00
|
|
|
/* drawing state space. */
|
2004-07-12 14:58:41 +01:00
|
|
|
printf ("digraph Statespace {\n");
|
2004-07-12 15:47:43 +01:00
|
|
|
|
2004-07-26 13:43:19 +01:00
|
|
|
/* label */
|
2004-07-29 14:15:29 +01:00
|
|
|
printf ("\tcomment = \"$");
|
2004-07-26 13:43:19 +01:00
|
|
|
commandlinePrint (stdout, sys);
|
|
|
|
printf ("\";\n");
|
|
|
|
|
2004-07-12 15:47:43 +01:00
|
|
|
/* fit stuff onto the page */
|
|
|
|
printf ("\trankdir=LR;\n");
|
2004-07-28 12:39:08 +01:00
|
|
|
printf ("\tsize=\"8.5,11\";\n");
|
|
|
|
//printf ("\tpage=\"8.5,11\";\n");
|
2004-07-26 13:43:19 +01:00
|
|
|
printf ("\tfontsize=\"6\";\n");
|
|
|
|
printf ("\tfontname=\"Helvetica\";\n");
|
|
|
|
printf ("\tmargin=0.5;\n");
|
|
|
|
printf ("\tnodesep=0.06;\n");
|
|
|
|
printf ("\tranksep=0.01;\n");
|
2004-07-12 15:47:43 +01:00
|
|
|
printf ("\torientation=landscape;\n");
|
2004-07-26 13:43:19 +01:00
|
|
|
printf ("\tcenter=true;\n");
|
|
|
|
// printf ("\tlabeljust=\"r\";\n");
|
|
|
|
printf ("\tconcentrate=true;\n");
|
|
|
|
|
|
|
|
/* node/edge defaults */
|
2004-08-09 11:05:58 +01:00
|
|
|
printf
|
|
|
|
("\tnode [shape=\"point\",fontsize=\"4\",fontname=\"Helvetica\"];\n");
|
2004-07-26 13:43:19 +01:00
|
|
|
printf ("\tedge [fontsize=\"4\",fontname=\"Helvetica\"];\n");
|
2004-07-12 15:47:43 +01:00
|
|
|
|
|
|
|
/* start with initial node 0 */
|
2004-07-21 11:35:39 +01:00
|
|
|
printf ("\tn");
|
2004-07-30 13:04:38 +01:00
|
|
|
statesFormat (STATES0);
|
2004-07-26 13:43:19 +01:00
|
|
|
printf (" [shape=box,height=0.2,label=\"M0: ");
|
2004-07-12 14:58:41 +01:00
|
|
|
tl = knowledgeSet (sys->know);
|
|
|
|
termlistPrint (tl);
|
|
|
|
termlistDelete (tl);
|
|
|
|
printf ("\"];\n");
|
|
|
|
}
|
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
void
|
|
|
|
graphDone (const System sys)
|
2004-07-12 14:58:41 +01:00
|
|
|
{
|
|
|
|
/* drawing state space. close up. */
|
|
|
|
printf ("}\n");
|
|
|
|
}
|
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
void
|
|
|
|
graphNode (const System sys)
|
2004-07-12 14:58:41 +01:00
|
|
|
{
|
|
|
|
Termlist newtl;
|
2004-07-21 11:35:39 +01:00
|
|
|
states_t thisNode, parentNode;
|
2004-07-13 12:37:55 +01:00
|
|
|
int index;
|
2004-07-28 12:39:08 +01:00
|
|
|
int run;
|
2004-07-13 12:37:55 +01:00
|
|
|
Roledef rd;
|
2004-07-13 10:14:03 +01:00
|
|
|
|
|
|
|
/* determine node numbers */
|
2004-07-13 12:37:55 +01:00
|
|
|
index = sys->step - 1;
|
|
|
|
parentNode = sys->traceNode[index];
|
2004-07-21 11:35:39 +01:00
|
|
|
thisNode = sys->states;
|
2004-07-13 12:37:55 +01:00
|
|
|
rd = sys->traceEvent[index];
|
2004-07-28 12:39:08 +01:00
|
|
|
run = sys->traceRun[index];
|
2004-07-12 14:58:41 +01:00
|
|
|
|
|
|
|
/* add node */
|
2004-07-21 11:35:39 +01:00
|
|
|
printf ("\tn");
|
2004-07-30 13:04:38 +01:00
|
|
|
statesFormat (thisNode);
|
2004-07-26 13:43:19 +01:00
|
|
|
printf (" [");
|
2004-08-09 11:05:58 +01:00
|
|
|
|
|
|
|
newtl = knowledgeNew (sys->traceKnow[index], sys->traceKnow[index + 1]);
|
2004-07-12 14:58:41 +01:00
|
|
|
if (newtl != NULL)
|
|
|
|
{
|
|
|
|
/* knowledge added */
|
2004-07-26 13:43:19 +01:00
|
|
|
printf ("shape=box,height=0.2,label=\"M + ");
|
2004-07-12 14:58:41 +01:00
|
|
|
termlistPrint (newtl);
|
|
|
|
termlistDelete (newtl);
|
|
|
|
printf ("\"");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* no added knowledge */
|
2004-07-28 12:39:08 +01:00
|
|
|
if (sys->switchScenario != 0 &&
|
|
|
|
rd != NULL &&
|
|
|
|
rd == sys->runs[run].start &&
|
2004-08-09 11:05:58 +01:00
|
|
|
rd->type == READ && run == sys->lastChooseRun)
|
2004-07-28 12:39:08 +01:00
|
|
|
{
|
|
|
|
/* last choose; scenario selected */
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("shape=box,height=0.2,label=\"Scenario %i: ",
|
|
|
|
sys->countScenario);
|
2004-07-28 12:39:08 +01:00
|
|
|
scenarioPrint (sys);
|
|
|
|
printf ("\"");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("label=\"\"");
|
2004-07-28 12:39:08 +01:00
|
|
|
}
|
2004-07-12 14:58:41 +01:00
|
|
|
}
|
|
|
|
printf ("];\n");
|
|
|
|
|
|
|
|
/* add edge */
|
2004-07-21 11:35:39 +01:00
|
|
|
printf ("\tn");
|
2004-07-30 13:04:38 +01:00
|
|
|
statesFormat (parentNode);
|
2004-07-21 11:35:39 +01:00
|
|
|
printf (" -> n");
|
2004-07-30 13:04:38 +01:00
|
|
|
statesFormat (thisNode);
|
2004-07-12 14:58:41 +01:00
|
|
|
/* add label */
|
2004-07-21 11:35:39 +01:00
|
|
|
printf (" [label=\"");
|
2004-07-28 12:39:08 +01:00
|
|
|
|
|
|
|
// Print step
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("%i:", sys->runs[run].step - 1);
|
2004-07-28 12:39:08 +01:00
|
|
|
|
|
|
|
if (rd->type == CLAIM && untrustedAgent (sys, sys->runs[run].agents))
|
2004-07-13 12:37:55 +01:00
|
|
|
{
|
2004-07-28 12:39:08 +01:00
|
|
|
printf ("Skip claim in #%i\"", run);
|
2004-07-13 12:37:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-28 12:39:08 +01:00
|
|
|
// Print event
|
2004-07-13 12:37:55 +01:00
|
|
|
roledefPrint (rd);
|
2004-07-28 12:39:08 +01:00
|
|
|
printf ("#%i\"", run);
|
2004-07-13 12:37:55 +01:00
|
|
|
if (rd->type == CLAIM)
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
printf (",shape=house,color=green");
|
2004-07-13 12:37:55 +01:00
|
|
|
}
|
|
|
|
}
|
2004-07-12 14:58:41 +01:00
|
|
|
/* a choose? */
|
2004-07-13 12:37:55 +01:00
|
|
|
if (rd->type == READ && rd->internal)
|
2004-07-12 14:58:41 +01:00
|
|
|
{
|
|
|
|
printf (",color=blue");
|
|
|
|
//printf (",style=dotted");
|
|
|
|
}
|
|
|
|
printf ("]");
|
|
|
|
printf (";\n");
|
|
|
|
}
|
2004-07-13 10:14:03 +01:00
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
void
|
|
|
|
graphNodePath (const System sys, const int length, const char *nodepar)
|
2004-07-13 10:14:03 +01:00
|
|
|
{
|
|
|
|
int i;
|
2004-07-21 11:35:39 +01:00
|
|
|
states_t thisNode;
|
2004-07-13 10:14:03 +01:00
|
|
|
|
|
|
|
i = 0;
|
2004-07-13 12:10:06 +01:00
|
|
|
while (i < length)
|
2004-07-13 10:14:03 +01:00
|
|
|
{
|
2004-07-13 12:10:06 +01:00
|
|
|
/* determine node number */
|
|
|
|
thisNode = sys->traceNode[i];
|
|
|
|
|
2004-07-13 10:56:19 +01:00
|
|
|
/* color node */
|
2004-07-21 11:35:39 +01:00
|
|
|
printf ("\tn");
|
2004-07-30 13:04:38 +01:00
|
|
|
statesFormat (thisNode);
|
2004-07-21 11:35:39 +01:00
|
|
|
printf (" [%s];\n", nodepar);
|
2004-07-13 12:10:06 +01:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
void
|
|
|
|
graphEdgePath (const System sys, const int length, const char *edgepar)
|
2004-07-13 12:10:06 +01:00
|
|
|
{
|
|
|
|
int i;
|
2004-07-21 11:35:39 +01:00
|
|
|
states_t thisNode, prevNode;
|
2004-07-13 12:10:06 +01:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
prevNode = sys->traceNode[i];
|
|
|
|
while (i < length)
|
|
|
|
{
|
|
|
|
/* determine node number */
|
2004-08-09 11:05:58 +01:00
|
|
|
thisNode = sys->traceNode[i + 1];
|
2004-07-13 12:10:06 +01:00
|
|
|
|
2004-07-13 10:56:19 +01:00
|
|
|
/* color edge */
|
2004-07-21 11:35:39 +01:00
|
|
|
printf ("\tn");
|
2004-07-30 13:04:38 +01:00
|
|
|
statesFormat (prevNode);
|
2004-07-26 13:43:19 +01:00
|
|
|
printf (" -> n");
|
2004-07-30 13:04:38 +01:00
|
|
|
statesFormat (thisNode);
|
2004-07-21 11:35:39 +01:00
|
|
|
printf (" [%s];\n", edgepar);
|
2004-07-13 12:10:06 +01:00
|
|
|
prevNode = thisNode;
|
2004-07-13 10:14:03 +01:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2004-07-13 13:19:03 +01:00
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
void
|
|
|
|
graphPath (const System sys, int length)
|
2004-07-13 13:19:03 +01:00
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
graphNodePath (sys, length, "style=bold,color=red");
|
|
|
|
graphEdgePath (sys, length - 1, "style=bold,color=red");
|
2004-07-13 13:19:03 +01:00
|
|
|
}
|
2004-07-28 12:39:08 +01:00
|
|
|
|
|
|
|
//! Scenario for graph; bit of a hack
|
|
|
|
void
|
|
|
|
graphScenario (const System sys, const int run, const Roledef rd)
|
|
|
|
{
|
|
|
|
/* Add scenario node */
|
|
|
|
printf ("\ts%i [shape=box,height=0.2,label=\"Scenario %i: ",
|
2004-08-09 11:05:58 +01:00
|
|
|
sys->countScenario, sys->countScenario);
|
2004-07-28 12:39:08 +01:00
|
|
|
scenarioPrint (sys);
|
|
|
|
printf ("\"];\n");
|
|
|
|
|
|
|
|
/* draw edge */
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("\tn%i -> s%i", sys->traceNode[sys->step], sys->countScenario);
|
2004-07-28 12:39:08 +01:00
|
|
|
printf (" [color=blue,label=\"");
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("%i:", sys->runs[run].step);
|
2004-07-28 12:39:08 +01:00
|
|
|
roledefPrint (rd);
|
|
|
|
printf ("#%i", run);
|
|
|
|
printf ("\"];\n");
|
|
|
|
}
|