int main(int argc, char *argv[]) { char *progname = argv[0]; int allowUnsafe = 0; int sawStdin; int state, opt; char *param; int errors; ILContext *context; /* Parse the command-line arguments */ state = 0; while((opt = ILCmdLineNextOption(&argc, &argv, &state, options, ¶m)) != 0) { switch(opt) { case 'u': { allowUnsafe = 1; } break; case 'v': { version(); return 0; } /* Not reached */ default: { usage(progname); return 1; } /* Not reached */ } } /* We need at least one input file argument */ if(argc <= 1) { usage(progname); return 1; } /* Initialize the engine, to ensure that the garbage collector is OK */ #ifdef IL_CONFIG_APPDOMAINS ILExecInit(0, 0); #else ILExecInit(0); #endif /* Create a context to use for image loading */ context = ILContextCreate(); if(!context) { fprintf(stderr, "%s: out of memory\n", progname); return 1; } /* Load and verify the input files */ sawStdin = 0; errors = 0; while(argc > 1) { if(!strcmp(argv[1], "-")) { /* Verify the contents of stdin, but only once */ if(!sawStdin) { errors |= verify("-", context, allowUnsafe); sawStdin = 1; } } else { /* Verify the contents of a regular file */ errors |= verify(argv[1], context, allowUnsafe); } ++argv; --argc; } /* Destroy the context */ ILContextDestroy(context); /* Done */ return errors; }
int main(int argc, char *argv[]) { char *progname = argv[0]; char *outputFile = 0; int dumpSections = 0; int wholeFile = 0; int flags = 0; int sawStdin; int state, opt; char *param; FILE *infile; int errors; ILContext *context; /* Parse the command-line arguments */ state = 0; while((opt = ILCmdLineNextOption(&argc, &argv, &state, options, ¶m)) != 0) { switch(opt) { case 'o': { outputFile = param; } break; case 'd': { dumpSections = 1; } break; case 'r': { flags |= ILDASM_REAL_OFFSETS; } break; case 't': { flags |= IL_DUMP_SHOW_TOKENS; } break; case 'q': { flags |= IL_DUMP_QUOTE_NAMES; } break; case 'w': { wholeFile = 1; } break; case 'b': { flags |= ILDASM_INSTRUCTION_BYTES; } break; case 'n': { flags |= ILDASM_NO_IL; } break; case 'R': { flags |= ILDASM_RESOLVE_ALL; } break; case '?': { /* Ignore this compatilibity option that we don't support */ } break; case 'v': { version(); return 0; } /* Not reached */ default: { usage(progname); return 1; } /* Not reached */ } } /* We need at least one input file argument */ if(argc <= 1) { usage(progname); return 1; } /* Open the output stream */ if(outputFile && strcmp(outputFile, "-") != 0) { if((outstream = fopen(outputFile, "w")) == NULL) { perror(outputFile); return 1; } } else { outstream = stdout; } /* Create a context to use for image loading */ context = ILContextCreate(); if(!context) { fprintf(stderr, "%s: out of memory\n", progname); return 1; } /* Load and dump the input files */ sawStdin = 0; errors = 0; while(argc > 1) { if(!strcmp(argv[1], "-")) { /* Dump the contents of stdin, but only once */ if(!sawStdin) { if(!wholeFile) { errors |= dumpFile("stdin", stdin, 0, context, dumpSections, flags); } else { dumpWholeFile("stdin", stdin); } sawStdin = 1; } } else { /* Dump the contents of a regular file */ if((infile = fopen(argv[1], "rb")) == NULL) { /* Try again in case libc did not understand the 'b' */ if((infile = fopen(argv[1], "r")) == NULL) { perror(argv[1]); errors = 1; ++argv; --argc; continue; } } if(!wholeFile) { errors |= dumpFile(argv[1], infile, 1, context, dumpSections, flags); } else { dumpWholeFile(argv[1], infile); fclose(infile); } } ++argv; --argc; } /* Destroy the context */ ILContextDestroy(context); /* Close the output stream */ if(outstream != stdout) { fclose(outstream); } /* Done */ return errors; }