예제 #1
0
void main( int argc, char *argv[] ) {
    Parameters          param;
    ExeFile             exeFile;
    bool                ret;

    ret = true;
    defaultParam( &param );
    exeFile.file = NULL;
    exeFile.tabEnt = NULL;

    printBanner();
    if( argc > 1 ) {
        ret = loadParam( &param, argc, argv );
    } else {
        printHelp();
        ret = false;
    }

    if( ret )   ret = openExeFile( &exeFile, &param );
    if( ret )   ret = readExeHeaders( &exeFile );
    if( ret )   {
                printDosHeader( &exeFile, &param );
                printPeHeader( &exeFile, &param );
                ret = findResourceObject( &exeFile );
    }
    if( ret )   ret = loadAllResources( &exeFile );
    if( ret )   {
                printResObject( &exeFile, &param );
                printTableContents( exeFile.tabEnt, &exeFile,
                                    &param, exeFile.resObj.physical_offset,
                                    0 );
    }
    freeAllResources( &exeFile );
}
예제 #2
0
//-------------------------------------------------------------------
int main(int argc, char *argv[])
{
  xmlDocPtr doc;
  xmlNodePtr cur;

  //Checks for the .xml file name
  if (argc==1)
  {
    fprintf(stderr, "No file name passed.");
    return -1;
  }
  //Opens the .xml file given as an argument
  doc = xmlParseFile(argv[1]);
  //Catches an error in parsing the file
  if (doc == NULL )
  {
    fprintf(stderr,"Document not parsed successfully. \n");
    return -1;
  }

  cur = xmlDocGetRootElement(doc);

  //Catches the error of passing a blank document
  if (cur == NULL)
  {
    fprintf(stderr,"Empty document.\n");
    xmlFreeDoc(doc);
    return -1;
  }

  //Catches the error of passing a document with a different root tag
  if (!tagNameIs("help",cur))
  {
    fprintf(stderr,"Document id of the wrong type, "
            "the root node is not help.\n");
    xmlFreeDoc(doc);
    return -1;
  }

  if (argc==2)
    printf("No output specified.\nOutput will be sent to output.html.\n");
  FILE *outFile;
  outFile=fopen(argc>2?argv[2]:"output.html", "w");

  cur=cur->xmlChildrenNode;

  fprintf(outFile,
          "<html>\n<body>\n<basefont face=\"sans-serif\"></basefont>\n");

  int exampleNum=1;
  //Outputs the file
  while (cur != NULL)
  {
    //Outputs the arugments of the file
    if (tagNameIs("arguments",cur)||tagNameIs("outputs",cur))
    {
      xmlNodePtr argumentType;
      argumentType=(tagNameIs("arguments",cur))?cur->xmlChildrenNode:cur;
      while (argumentType!=NULL)
      {
        if (!tagNameIs("text",argumentType))
        {
          printName(argumentType,outFile);
          if (tagNameIs("arguments",cur))
            fprintf(outFile," ARGUMENTS");
          fprintf(outFile,"</h1>");
          xmlNodePtr argumentElement;
          argumentElement=argumentType->xmlChildrenNode;
          int first=1, justIntro=0, justArg=0;
          // fprintf (outFile,"\n<table border=\"3\">\n");
          while (1)
          {
            if (!tagNameIs("text",argumentElement))
            {
              if ((first||justIntro)&&!tagNameIs("intro",argumentElement))
                fprintf (outFile,
                         "\n<table border=\"3\">\n<tr><th>%s</th><th>"
                         "Explanation</th></tr>\n",
                         (tagNameIs("arguments",cur))?"Argument":"Output");

              if (justArg)
              {
                if (tagNameIs("argument",argumentElement)||
                    tagNameIs("output",argumentElement))
                  fprintf(outFile, "<td>&nbsp;</td>\n");
                justArg=0;
              }
              else if (tagNameIs("explanation",argumentElement))
                fprintf(outFile, "</tr>\n<tr>\n<td>&nbsp;</td>\n");
              if (tagNameIs("argument",argumentElement)||
                  tagNameIs("output",argumentElement))
                justArg=1;
              if (tagNameIs("intro",argumentElement))
              {
                char *c, *intro;
                c= (char *)xmlNodeListGetString
                  (doc,
                   argumentElement->xmlChildrenNode, 1);
                if (first)
                {
                  intro= malloc(strlen("\n<h3>")+strlen(c)+1);
                  strcpy(intro,"\n<h3>");
                  first=0;
                }
                else
                {
                  intro= malloc(strlen("</tr>\n</table>\n<h3>")+strlen(c)+1);
                  strcpy(intro,"</tr>\n</table>\n<h3>");
                }
                intro=strcat(intro,c);
                free(c);
                while (tagNameIs("intro",argumentElement->next)||
                       tagNameIs("text",argumentElement->next))
                {
                  if (!tagNameIs("text",argumentElement->next))
                  {
                    char *content;
                    content= (char *)xmlNodeListGetString
                      (doc, argumentElement->next->xmlChildrenNode, 1);
                    char *secondHalf=
                      malloc(strlen("<br />") +strlen(content)+ 1);
                    strcpy(secondHalf,"<br />");
                    secondHalf=strcat(secondHalf,content);
                    char *temp= malloc(strlen(intro)+strlen(secondHalf)+1);
                    strcpy(temp,intro);
                    temp=strcat(temp,secondHalf);
                    free(intro);
                    intro=temp;
                  }
                  argumentElement=argumentElement->next;
                }
                char *temp= malloc(strlen(intro)+strlen("</h3>\n"+1));
                strcpy(temp,intro);
                temp=strcat(temp,"</h3>");
                free(intro);
                intro=temp;
                fprintf(outFile,"%s\n",intro);
                free(intro);
                justIntro=1;
              }
              else
              {
                if (first)
                  first=0;
                else if ((tagNameIs("argument",argumentElement)||
                          tagNameIs("output",argumentElement))&&!justIntro)
                  fprintf(outFile, "</tr>\n");

                justIntro=0;
                printTableContents(doc,argumentElement,outFile);
              }
            }
            argumentElement= argumentElement->next;
            if (argumentElement==NULL)
            {
              if (!justIntro)
                fprintf (outFile,"</tr>\n</table>\n");
              break;
            }
          }
        }
        if (!tagNameIs("arguments",cur))
          break;
        argumentType=argumentType->next;
      }
    }
    //Outputs all the other tags
    else if (!tagNameIs("text",cur))
    {
      printName(cur,outFile);
      if (tagNameIs("EXAMPLE",cur))
        fprintf(outFile," %d",exampleNum++);
      fprintf(outFile,"</h1>");
      printContents(doc,cur,outFile);
    }
    cur=cur->next;
  }

  fprintf(outFile,"</html>\n</body>\n");

  return EXIT_SUCCESS;
}