int Boomerang::ParseInputCmds(int argc,const char**argv)
{
char CmdIntuit[256];
int kmd = 0;
/*keeping this for later :]
case 'g':
if(argv[I][2]=='d')
dotFile = argv[++i];
else if(argv[I][2]=='c')
generateCallGraph=true;
else if(argv[I][2]=='s') {
generateSymbols=true;
stopBeforeDecompile=true;
}
break;
*/
if(strlen(argv) < 256)
{
strcpy(&CmdIntuit,argv[0]);
}
else
{
return 0;
}
switch(CmdIntuit[0])
{
//alphabetical lower or upper(must be one or other..for now ;P)
//case handler for commands.
case 'a':
{
if(CmdIntuit[1] == 'd')
{
if(argc <= 1)
{
usage();
return 0;
}
else if(argc <=2)
{
usage();
return 0;
}
else
{
if(strcpy(CmdIntuit,argv[1]) == 'e')
{
if(Cmdintuit[1][0] == 'n')
{
noDecodeChildren = true;
ADDRESS addr;
int n;
decodeMain = false;
if(argv[2][0] == '0' && argv[2][1] == 'x')
{
n = sscanf(argv[2], "0x%x", &addr);
} else {
n = sscanf(argv[2], "%i", &addr);
}
if (n != 1)
{
std::cerr << "bad address: " << argv[I] << std::endl;
return 0;
}
entrypoints.push_back(addr);
return 1;
}
}
}
}
usage();
return 0;
}
case 'A':
{
if(CmdIntuit[1] == 'D')
{
if(argc <= 1)
{
usage();
return 0;
}
else if(argc <=2)
{
usage();
return 0;
}
else
{
if(strcpy(CmdIntuit,argv[1]) == 'E')
{
if(Cmdintuit[1][0] == 'N')
{
noDecodeChildren = true;
ADDRESS addr;
int n;
decodeMain = false;
if(argv[2][0] == '0' && argv[2][1] == 'X')
{
n = sscanf(argv[2], "0x%x", &addr);
} else {
n = sscanf(argv[2], "%i", &addr);
}
if (n != 1)
{
std::cerr << "bad address: " << argv[I] << std::endl;
return 0;
}
entrypoints.push_back(addr);
return 1;
}
}
}
}
usage();
return 0;
}
case 'b':
case 'B':
case 'c':
case 'C':
case 'd':
{
if(CmdIntuit[1] == 'f')
{
dfaTypeAnalysis = true;
return 1;
}
}
case 'D':
{
if(CmdIntuit[1] == 'F')
{
dfaTypeAnalysis = true;
return 1;
}
}
case 'e':
case 'E':
case 'f':
case 'F':
case 'g':
case 'G':
case 'h':
{
switch(CmdIntuit[1])
{
case 'e':
{
if(argc !> 1)
{
help();
return 1;
}
else
{
helpcmd();
return 1;
}
}
default:
return 0;
}
}
case 'H':
{
switch(CmdIntuit[1])
{
case 'E':
{
if(argc !> 1)
{
help();
return 1;
}
else
{
helpcmd();
return 1;
}
}
default:
return 0;
}
}
case 'i':
case 'I':
case 'j':
case 'J':
case 'k':
case 'K':
case 'l':
case 'L':
case 'm':
case 'M':
case 'n':
case 'N':
case 'o':
case 'O':
case 'p':
case 'P':
case 'q':
case 'Q':
case 'r':
case 'R':
case 's':
case 'S':
case 't':
{
switch(CmdIntuit[1])
{
case 'c':
{
conTypeAnalysis = true; // -Tc: use old constraint-based type analysis
dfaTypeAnalysis = false;
return 1;
}
default:
return 0;
}
}
case 'T':
{
switch(CmdIntuit[1])
{
case 'C':
{
conTypeAnalysis = true; // -Tc: use old constraint-based type analysis
dfaTypeAnalysis = false;
return 1;
}
default:
return 0;
}
}
case 'u':
case 'U':
case 'v':
{
switch(CmdIntuit[1])
{
case 'e':
{
vFlag = true;
return 1;
}
default:
return 0;
}
}
case 'V':
{
switch(CmdIntuit[1])
{
case 'E':
{
vFlag = true;
return 1;
}
default:
return 0;
}
}
case 'w':
case 'W':
case 'x':
case 'X':
case 'y':
case 'Y':
case 'z':
case 'Z':
default:
return 0;
}
/*
case 'o': {
outputPath = argv[++i];
char lastCh = outputPath[outputPath.size()-1];
if (lastCh != '/' && lastCh != '\\')
outputPath += '/'; // Maintain the convention of a trailing slash
break;
}
case 'n':
switch(argv[I][2]) {
case 'b':
noBranchSimplify = true;
break;
case 'c':
noDecodeChildren = true;
break;
case 'd':
noDataflow = true;
break;
case 'D':
noDecompile = true;
break;
case 'l':
noLocals = true;
break;
case 'n':
noRemoveNull = true;
break;
case 'P':
noPromote = true;
break;
case 'p':
noParameterNames = true;
break;
case 'r':
noRemoveLabels = true;
break;
case 'R':
noRemoveReturns = true;
break;
case 'g':
noGlobals = true;
break;
case 'G':
break;
default:
help();
}
break;
case 'E':
noDecodeChildren = true;
// Fall through
case 'e':
{
ADDRESS addr;
int n;
decodeMain = false;
if (++i == argc) {
usage();
return 1;
}
if (argv[I][0] == '0' && argv[i+1][1] == 'x') {
n = sscanf(argv[I], "0x%x", &addr);
} else {
n = sscanf(argv[I], "%i", &addr);
}
if (n != 1) {
std::cerr << "bad address: " << argv[I] << std::endl;
}
entrypoints.push_back(addr);
}
break;
case 's':
{
if (argv[I][2] == 'f') {
symbolFiles.push_back(argv[i+1]);
i++;
break;
}
ADDRESS addr;
int n;
if (++i == argc) {
usage();
return 1;
}
if (argv[I][0] == '0' && argv[i+1][1] == 'x') {
n = sscanf(argv[I], "0x%x", &addr);
} else {
n = sscanf(argv[I], "%i", &addr);
}
if (n != 1) {
std::cerr << "bad address: " << argv[i+1] << std::endl;
exit(1);
}
const char *nam = argv[++i];
symbols[addr] = nam;
}
break;
case 'd':
switch(argv[I][2]) {
case 'a':
printAST = true;
break;
case 'c':
debugSwitch = true;
break;
case 'd':
debugDecoder = true;
break;
case 'g':
debugGen = true;
break;
case 'l':
debugLiveness = true;
break;
case 'p':
debugProof = true;
break;
case 's':
stopAtDebugPoints = true;
break;
case 't': // debug type analysis
debugTA = true;
break;
case 'u': // debug unused locations (including returns and parameters now)
debugUnused = true;
break;
default:
help();
}
break;
case 'm':
if (++i == argc) {
usage();
return 1;
}
sscanf(argv[I], "%i", &maxMemDepth);
break;
case 'i':
if (argv[I][2] == 'c')
decodeThruIndCall = true; // -ic;
if (argv[I][2] == 'w') // -iw
if (ofsIndCallReport) {
std::string fname = getOutputPath() + "indirect.txt";
ofsIndCallReport = new std:

fstream(fname.c_str());
}
break;
case 'L':
if (argv[I][2] == 'D')
#if USE_XML
loadBeforeDecompile = true;
#else
std::cerr << "LD command not enabled since compiled without USE_XML\n";
#endif
break;
case 'S':
if (argv[I][2] == 'D')
#if USE_XML
saveBeforeDecompile = true;
#else
std::cerr << "SD command not enabled since compiled without USE_XML\n";
#endif
else {
sscanf(argv[++i], "%i", &minsToStopAfter);
}
break;
case 'k':
kmd = 1;
break;
case 'P':
progPath = argv[++i];
if (progPath[progPath.length()-1] != '\\')
progPath += "\\";
break;
case 'a':
assumeABI = true;
break;
case 'l':
if (++i == argc) {
usage();
return 1;
}
sscanf(argv[I], "%i", &propMaxDepth);
break;
default:
help();
}
}
setOutputDirectory(outputPath.c_str());
if (kmd)
return cmdLine();
*/
return decompile(argv[argc-1]);
}