2 * This file is part of the OpenPTS project.
4 * The Initial Developer of the Original Code is International
5 * Business Machines Corporation. Portions created by IBM
6 * Corporation are Copyright (C) 2010 International Business
7 * Machines Corporation. All Rights Reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the Common Public License as published by
11 * IBM Corporation; either version 1 of the License, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * Common Public License for more details.
19 * You should have received a copy of the Common Public License
20 * along with this program; if not, a copy can be viewed at
21 * http://www.opensource.org/licenses/cpl1.0.php.
26 * \brief Utility, generate dot file from Refdrence Manifest (RM)
27 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
29 * cleanup 2011-01-22 SM
31 * RM/UML State Diagram -> DOT --(graphviz)--> Graph(PNG,JPG etc)
37 cd tests/data/ThinkpadX200_Fedora12
39 ../../../src/rm2dot -p 0 -o bios_pcr0.dot platform_rm.xml
40 dot -Tpng bios_pcr0.dot -o bios_pcr0.png
43 ../../../src/rm2dot -p 4 -o grub_pcr4.dot runtime_rm.xml
44 dot -Tpng grub_pcr4.dot -o grub_pcr4.png
54 #include <sys/types.h>
55 #include <sys/socket.h>
56 #include <netinet/in.h>
67 fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_RM2DOT_USAGE, "usage: rm2dot [options] RMfile \n"
68 "\t-o output\tset output file (default is stdout)\n"
69 "\t-p pcrindex\tset PCR index\n"
70 "\t-l level\tset snapshot level (0 or 1)\n"
71 "\t$ dot -Tpng foo.dot -o foo.png; eog foo.png\n"
78 int main(int argc, char *argv[]) {
83 char *input_filename = NULL;
84 char *output_filename = NULL;
91 while ((c = getopt(argc, argv, "do:p:l:h")) != EOF) {
94 setDebugFlags(DEBUG_FLAG);
97 output_filename = optarg;
100 pcr_index = atoi(optarg);
103 level = atoi(optarg);
114 input_filename = argv[0];
116 /* Read RM(XML) file */
118 if (input_filename == NULL) {
119 printf(NLS(MS_OPENPTS, OPENPTS_RM2DOT_MISSING_XML_FILE, "ERROR missing XMLfile\n"));
124 /* new pts context */
125 conf = newPtsConfig();
131 ctx = newPtsContext(conf);
138 rc = readRmFile(ctx, input_filename, 0);
139 if (rc != PTS_SUCCESS) {
140 ERROR("ERROR readRmFile\n");
145 ss = getSnapshotFromTable(ctx->ss_table, pcr_index, 0);
146 } else if (level == 1) {
147 ss = getSnapshotFromTable(ctx->ss_table, pcr_index, 1);
149 fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_RM2DOT_BAD_LEVEL, "ERROR bad level %d\n"), level);
153 rc = writeDotModel(ss->fsm_binary, output_filename);
154 if (rc != PTS_SUCCESS) {
155 ERROR("ERROR writeDotModel\n");