home *** CD-ROM | disk | FTP | other *** search
/ Programming Win32 Under the API / ProgrammingWin32UnderTheApiPatVillani.iso / pedasm.zip / Main.cpp < prev    next >
C/C++ Source or Header  |  1998-10-23  |  5KB  |  169 lines

  1. /*        fichier main.cpp : point d'entree du programme PEDasm
  2.  *    
  3.  *    descr : desassemble un fichier binaire
  4.  *
  5.  *    projet : PEDasm
  6.  *    
  7.  *    rq:
  8.  *    Ce programme est libre de droits. Il peut etre distribue et/ou modifie
  9.  *  selon les termes de la licence 'GNU General Public License version 2'.
  10.  *    
  11.  *    Ce programme est distribue sans aucunes garanties, y compris d'utilite 
  12.  *    ni de risques encouru, quelle que soit son utilisation.
  13.  *
  14.  *    lire le fichier licence.txt fourni ou bien ecrire a :
  15.  *    the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16.  *    pour recevoir une copie de la licence.
  17.  *
  18.  *    Copyright (C) 1997 - 1998 Nicolas Witczak <witczak@geocities.com>
  19.  */
  20.  
  21. #include "Config.h"
  22.  
  23. #include "ExeRep.h"
  24.  
  25.  
  26. ///////////////////////////////////////////////////////
  27. /** message d'aide    
  28.  */
  29.  
  30. static char pszPres[] =
  31.     "PEDasm    : win32 executable file symbolic disassembler freeware ver 0.31\n"
  32.     "\tPEDasm is a free software, you can redistribute it and/or modify\n"
  33.     "\tit under the terms of the GNU General Public License ver 2 as published\n"
  34.     "\tby the Free Software Foundation. It comes with ABSOLUTELY NO WARRANTY\n"
  35.     "\tCopyright (C) 1997 - 1998 Nicolas Witczak <witczak@geocities.com>\n";
  36.  
  37. static char pszHelp[] = 
  38.     "Usage :\n"
  39.     "\tPEDasm inputFile [switches]\n"
  40.     "\t-o outputFile : default ouputFile.asm\n"
  41.     "\t-l add line number : default no\n" 
  42.     "\t-r add raw value : default no\n"
  43.     "\t-p value : specify number of passes must be greater than 1 : default 3\n"
  44.     "\t-s textfile : specify a file containing additionnal synchro point\n" 
  45.     "\t\t line format : 0xAddress data | funct | ptr  [opt_name]\n" 
  46.     "\t-b [+|-]bank_name : force or prevent use of bank_name instruction set\n"
  47.     "\t\tdefault : -b +userX86 -b +fpuX86\n"
  48.     "\t\talvailable banks are : user , system , fpu , mmx\n";
  49.  
  50. ///////////////////////////////////////////////////////
  51. /** point d'entree du programme
  52.  *    
  53.  */
  54.  
  55. int main( int argc , char* argv[] )
  56. {
  57.     const char* pszInput = 0 ;
  58.     const char* pszOutput = 0 ;
  59.     const char* pszTmp = 0 ;
  60.     bool bLineNum = false ;
  61.     bool bRawData = false ;
  62.     int iPassNum = 3 ;
  63.     printf( "%s" , pszPres ) ;
  64.     if( argc <= 1 )
  65.     {
  66.         printf( "Missing file name argument \n" ) ;
  67.         return -1 ;
  68.     }
  69.     for( int iArg = 1 ; iArg < argc ; ++ iArg )
  70.     {
  71.         if( argv[iArg][0] == '-')
  72.         {
  73.             bool bLoad ;
  74.             switch( argv[iArg][1] )
  75.             {
  76.                 case 'h':
  77.                     printf( "%s" , pszHelp );
  78.                     return 0 ;
  79.                 case 'l':
  80.                     bLineNum = true ;
  81.                     break;
  82.                 case 'r':
  83.                     bRawData = true ;
  84.                     break;
  85.                 case 'o':
  86.                     if( ++ iArg < argc )
  87.                     {
  88.                         pszOutput = argv[ iArg ] ;
  89.                         printf( "Output file : %s\n" , pszOutput ) ;
  90.                     }
  91.                     else
  92.                     {
  93.                         printf( "Option -o : Missing output name\n" ) ;
  94.                         return -1 ;
  95.                     }
  96.                     break;
  97.                 case 'p':
  98.                     if( ++ iArg < argc )
  99.                     {
  100.                         pszTmp = argv[ iArg ] ;
  101.                         iPassNum = atoi( pszTmp ) ;
  102.                         if( iPassNum >= 2 )
  103.                             break ;
  104.                     }
  105.                     printf( "Option -p : missing or bad parameter\n" ) ;
  106.                     return -1 ;
  107.                 case 's' :
  108.                     if( ++ iArg < argc )
  109.                     {
  110.                         pszTmp = argv[ iArg ] ;
  111.                         FILE* pAddConf = fopen( pszTmp  , "r" ) ;
  112.                         if( pAddConf != 0 )
  113.                         {
  114.                             bool bSuccess = GetExe()->ScanConfFile( pAddConf ) ;
  115.                             fclose( pAddConf );
  116.                             if( bSuccess )
  117.                             {
  118.                                 printf( "Additionnel config file : %s\n" , pszTmp ) ;
  119.                                 break;
  120.                             }
  121.                         }
  122.                     }
  123.                     printf( "Option -s : missing or bad file name\n" );
  124.                     return -1 ;
  125.                 case 'b' :                     
  126.                     pszTmp = argv[ ++iArg ]  ;                    
  127.                     bLoad = true ;
  128.                     if( pszTmp[0] == '+' )
  129.                         ++ pszTmp ;    
  130.                     else if( pszTmp[0] == '-' )
  131.                     {
  132.                         bLoad = false ;
  133.                         ++ pszTmp ; 
  134.                     }
  135.                     if( !IsBank( pszTmp ) )
  136.                     {
  137.                         printf( "Option -b : unknown bank name : %s\n" , pszTmp );
  138.                         return -1 ;
  139.                     }
  140.                     LoadBank( pszTmp, bLoad );
  141.                     break ;
  142.                 default :
  143.                     printf( "Unknown switch -%c\n" , argv[iArg][1] ) ;
  144.                     printf( "%s" , pszHelp ) ;
  145.                     return -1 ;
  146.             }
  147.         }
  148.         else // inputfile
  149.         {
  150.             if( pszInput == 0 )
  151.             {
  152.                 pszInput = argv[ iArg ] ;
  153.                 printf( "Input file : %s\n" , pszInput ) ;
  154.             }
  155.             else
  156.             {
  157.                 printf( "Unknown arg : %s\n" , argv[iArg] ) ;
  158.                 return -1 ;            
  159.             }
  160.         }            
  161.     }
  162.     InitBanks() ;
  163.     GetExe()->m_iPassNum = iPassNum  ;    
  164.     GetExe()->m_bLineNum = bLineNum  ;
  165.     GetExe()->m_bRawData = bRawData ;
  166.     GetExe()->ProcessExe( pszInput , pszOutput ) ;
  167.     return 0 ;
  168. }
  169.