2017-03-29 10:18:37 +00:00
# include <QApplication>
2017-04-01 11:20:13 +00:00
# include <QCommandLineParser>
2017-03-30 21:48:36 +00:00
# include <QTextCodec>
2017-03-31 01:45:59 +00:00
# include <QMessageBox>
2017-03-29 10:18:37 +00:00
2017-10-01 19:09:42 +00:00
# include "MainWindow.h"
2017-10-02 09:41:28 +00:00
# include "dialogs/NewFileDialog.h"
2017-10-01 19:09:42 +00:00
# include "dialogs/OptionsDialog.h"
2017-09-25 12:55:41 +00:00
2017-10-23 09:22:15 +00:00
# ifdef __unix__
2017-10-23 09:37:30 +00:00
# define PREFIX " / tmp / .cutter_usr"
2017-10-23 09:22:15 +00:00
# include <sys/types.h>
# include <sys/stat.h>
# include <unistd.h>
# include <string.h>
2017-10-24 08:18:16 +00:00
void set_appimage_symlink ( )
2017-10-23 09:22:15 +00:00
{
2017-11-03 17:22:54 +00:00
char * path = realpath ( " /proc/self/exe " , NULL ) ;
char * i = strrchr ( path , ' / ' ) ;
* ( i + 1 ) = ' \0 ' ;
char * dest = strcat ( path , " ../ " ) ;
2017-10-23 09:22:15 +00:00
struct stat buf ;
2017-11-03 17:22:54 +00:00
if ( lstat ( PREFIX , & buf ) = = 0 & & S_ISLNK ( buf . st_mode ) )
{
2017-10-23 09:37:30 +00:00
remove ( PREFIX ) ;
2017-10-23 09:22:15 +00:00
}
2017-10-23 09:37:30 +00:00
symlink ( dest , PREFIX ) ;
2017-10-23 21:54:35 +00:00
printf ( " '%s' '%s' '%s' \n " , path , i , dest ) ;
2017-10-23 09:22:15 +00:00
free ( path ) ;
}
# endif
2017-03-29 10:18:37 +00:00
int main ( int argc , char * argv [ ] )
{
QApplication a ( argc , argv ) ;
2017-09-25 12:55:41 +00:00
a . setOrganizationName ( " cutter " ) ;
a . setApplicationName ( " cutter " ) ;
2017-03-29 10:18:37 +00:00
a . setApplicationVersion ( APP_VERSION ) ;
2017-12-04 13:59:41 +00:00
a . setWindowIcon ( QIcon ( " :/img/cutter_white_bg.svg " ) ) ;
2017-03-29 10:18:37 +00:00
2017-03-30 21:48:36 +00:00
// Set QString codec to UTF-8
QTextCodec : : setCodecForLocale ( QTextCodec : : codecForName ( " UTF-8 " ) ) ;
# if QT_VERSION < QT_VERSION_CHECK(5,0,0)
QTextCodec : : setCodecForCStrings ( QTextCodec : : codecForName ( " UTF-8 " ) ) ;
QTextCodec : : setCodecForTr ( QTextCodec : : codecForName ( " UTF-8 " ) ) ;
# endif
2017-05-13 18:09:36 +00:00
QCommandLineParser cmd_parser ;
2017-09-09 09:36:15 +00:00
cmd_parser . setApplicationDescription ( QObject : : tr ( " A Qt and C++ GUI for radare2 reverse engineering framework " ) ) ;
2017-05-13 18:09:36 +00:00
cmd_parser . addHelpOption ( ) ;
cmd_parser . addVersionOption ( ) ;
cmd_parser . addPositionalArgument ( " filename " , QObject : : tr ( " Filename to open. " ) ) ;
2017-04-28 13:09:40 +00:00
2017-05-13 18:09:36 +00:00
QCommandLineOption anal_option ( { " A " , " anal " } ,
2017-11-17 09:41:01 +00:00
QObject : : tr ( " Automatically open file and optionally start analysis. Needs filename to be specified. May be a value between 0 and 2: 0 = no analysis, 1 = aaa, 2 = aaaa (experimental) " ) ,
2017-06-03 12:27:23 +00:00
QObject : : tr ( " level " ) ) ;
2017-05-13 18:09:36 +00:00
cmd_parser . addOption ( anal_option ) ;
2017-04-28 13:09:40 +00:00
2017-05-13 18:09:36 +00:00
cmd_parser . process ( a ) ;
2017-04-01 11:20:13 +00:00
2017-05-13 18:09:36 +00:00
QStringList args = cmd_parser . positionalArguments ( ) ;
2017-04-01 11:20:13 +00:00
2017-03-31 01:45:59 +00:00
// Check r2 version
QString r2version = r_core_version ( ) ;
QString localVersion = " " R2_GITTAP ;
2017-04-09 19:55:06 +00:00
if ( r2version ! = localVersion )
2017-03-31 01:45:59 +00:00
{
QMessageBox msg ;
msg . setIcon ( QMessageBox : : Critical ) ;
msg . setStandardButtons ( QMessageBox : : Yes | QMessageBox : : No ) ;
2017-09-09 09:36:15 +00:00
msg . setWindowTitle ( QObject : : tr ( " Version mismatch! " ) ) ;
2017-09-25 12:55:41 +00:00
msg . setText ( QString ( QObject : : tr ( " The version used to compile cutter (%1) does not match the binary version of radare2 (%2). This could result in unexpected behaviour. Are you sure you want to continue? " ) ) . arg ( localVersion , r2version ) ) ;
2017-04-09 19:55:06 +00:00
if ( msg . exec ( ) = = QMessageBox : : No )
2017-03-31 01:45:59 +00:00
return 1 ;
}
2017-05-13 18:09:36 +00:00
bool anal_level_specified = false ;
int anal_level = 0 ;
2017-04-28 13:09:40 +00:00
2017-05-13 18:09:36 +00:00
if ( cmd_parser . isSet ( anal_option ) )
2017-04-28 13:09:40 +00:00
{
2017-05-13 18:09:36 +00:00
anal_level = cmd_parser . value ( anal_option ) . toInt ( & anal_level_specified ) ;
2017-04-28 13:09:40 +00:00
2017-11-17 09:41:01 +00:00
if ( ! anal_level_specified | | anal_level < 0 | | anal_level > 2 )
2017-04-28 13:09:40 +00:00
{
2017-11-17 09:41:01 +00:00
printf ( " %s \n " , QObject : : tr ( " Invalid Analysis Level. May be a value between 0 and 2. " ) . toLocal8Bit ( ) . constData ( ) ) ;
2017-04-28 13:09:40 +00:00
return 1 ;
}
}
2017-04-09 19:55:06 +00:00
if ( args . empty ( ) )
2017-04-01 11:20:13 +00:00
{
2017-05-13 18:09:36 +00:00
if ( anal_level_specified )
2017-04-28 13:09:40 +00:00
{
printf ( " %s \n " , QObject : : tr ( " Filename must be specified to start analysis automatically. " ) . toLocal8Bit ( ) . constData ( ) ) ;
return 1 ;
}
2017-04-01 11:20:13 +00:00
NewFileDialog * n = new NewFileDialog ( ) ;
n - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
2017-04-01 11:33:16 +00:00
n - > show ( ) ;
2017-04-01 11:20:13 +00:00
}
else // filename specified as positional argument
{
2017-05-13 18:09:36 +00:00
MainWindow * main = new MainWindow ( ) ;
2017-10-21 19:20:10 +00:00
main - > openNewFile ( args [ 0 ] , anal_level_specified ? anal_level : - 1 ) ;
2017-04-01 11:20:13 +00:00
}
2017-10-23 09:22:15 +00:00
// Hack to make it work with AppImage
# ifdef __unix__
2017-10-24 08:18:16 +00:00
set_appimage_symlink ( ) ;
2017-10-23 09:22:15 +00:00
# endif
int ret = a . exec ( ) ;
# ifdef __unix__
2017-10-23 09:37:30 +00:00
remove ( PREFIX ) ;
2017-10-23 09:22:15 +00:00
# endif
return ret ;
2017-03-29 10:18:37 +00:00
}