Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use FileHandle;
- use Getopt::Long;
- our ($antiptrace, $noircbacktrace, $ssl, $little_endian, $big_endian, $cc_prefix, $cc_options, $ld_options, $disable_adns, $firedns);
- if(!GetOptions(
- "--with-antiptrace" => \$antiptrace,
- "--no-irc-backtrace" => \$noircbacktrace,
- "--little-endian" => \$little_endian,
- "--big-endian" => \$big_endian,
- "--cc-prefix:s" => \$cc_prefix,
- "--cc-options:s" => \$cc_options,
- "--ld-options:s" => \$ld_options,
- "--disable-adns" => \$disable_adns,
- "--with-ssl" => \$ssl,
- "--with-firedns" => \$firedns))
- {
- exit();
- }
- my %targets;
- $targets{'dynamic'} = '-Wall -Wno-non-virtual-dtor';
- $targets{'static'} = '-Wall -Wno-non-virtual-dtor -static -DHAVE_STATIC';
- $targets{'debug'} = '-DHAVE_DEBUG -g -fno-inline -pedantic -Wall -Wno-long-long -Wformat=2 -Wunused -Wno-non-virtual-dtor';
- my $filelist = "
- class-adns.o
- class-adns-firedns.o
- class-adns-pthread.o
- botcmd.o
- class-blowfish.o
- class-chan-actions.o
- class-chan.o
- class-chan-gotmode.o
- class-comment.o
- class-client.o
- class-clone.o
- class-customdata.o
- class-ent.o
- class-http.o
- class-ignore.o
- class-inet.o
- class-idle.o
- class-listcmd.o
- class-modeq.o
- class-masklist.o
- class-offence.o
- class-pchar.cpp
- class-penal.o
- class-ptime.o
- class-fifo.o
- class-tcl.o
- class-userlist.o
- class-wasop.o
- class-update.o
- class-options.o
- class-server.o
- class-shitlist.o
- class-socks5.o
- config-create.o
- config-load.o
- dlsym_cast.o
- firedns.o
- firestring.o
- functions.o
- hidden-seed-functions.o
- inet_pton.o
- main.o
- match.o
- md5.o
- md5func.o
- parse-bot.o
- parse-botnet.o
- parse-ctcp.o
- parse-hub.o
- parse-irc.o
- parse-owner.o
- random.o
- signals.o";
- my $moduleList = "control
- date
- log
- noautorejoin
- op
- peak
- peak2
- raw
- repeat
- spam
- subop
- uptime
- vctrl
- words";
- require 'tests/test.pm';
- chdir('tests');
- print "[*] Running system check (this may take a while)\n";
- my $os = `uname`;
- $os =~ s/\n//;
- print "[*] Operating system: $os\n";
- my ($cflags, $lflags) = getGccOptions();
- chdir('..');
- if($antiptrace) {
- print "[+] Enabling antiptrace\n";
- $cflags .= "-DHAVE_ANTIPTRACE ";
- }
- else {
- print "[-] Disabling antiptrace (pass --with-antiptrace to enable)\n";
- }
- if($noircbacktrace) {
- print "[-] Disabling irc backtrace\n";
- }
- else {
- print "[+] Enabling irc backtrace (pass --no-irc-backtrace to disable)\n";
- $cflags .= "-DHAVE_IRC_BACKTRACE ";
- }
- if($ssl) {
- print "[+] Enabling SSL support (irc, partyline)\n";
- $cflags .= "-DHAVE_SSL ";
- $lflags .= "-lssl ";
- }
- else {
- print "[-] Disabling SSL support (pass --with-ssl to enable)\n";
- }
- print "[*] Compile options: $cflags\n";
- print "[*] Link options: $lflags\n";
- $filelist =~ tr/\n/ /;
- my $ver = `cat defines.h | egrep S_VERSION | awk '{ print substr(\$3, 2, length(\$3)-2) }'`;
- $ver =~ s/\n//;
- #
- # Generating makefile
- #
- my $f = new FileHandle "> Makefile" or die 'Cannot create Makefile';
- my (@arg, $i, $last, $d, $st, $out);
- print "[+] Generating Makefile\n";
- print $f "#########################################\n";
- print $f "# Code generated by configure\n";
- print $f "#\n";
- print $f "# Copyright (c) 2004-2007 Grzegorz Rusin <grusin\@gmail.com>\n";
- print $f "# WARNING! All changes made in this file will be lost!\n";
- print $f "# \n\n";
- print $f "list:\n";
- print $f "\t\@echo Available targets:\n";
- print $f "\t\@echo '* dynamic (prefered for most systems)'\n";
- print $f "\t\@echo '* static'\n";
- print $f "\t\@echo '* debug'\n";
- print $f "\t\@echo '* apidox'\n\n";
- print $f "create_hidden_seed:\n";
- print $f "\t\@${cc_prefix}g++ -o make-hiddenseed make-hiddenseed.c && ./make-hiddenseed > hidden-seed-functions.c\n\n";
- print $f "debug: create_hidden_seed\n";
- print $f "\t\@echo [*] Making debug\n";
- print $f "\t\@\$(MAKE) -f Makefile.debug\n\n";
- print $f "dynamic: create_hidden_seed\n";
- print $f "\t\@echo [*] Making static\n";
- print $f "\t\@\$(MAKE) -f Makefile.static\n\n";
- print $f "apidox:\n";
- print $f "\t\@echo [*] Generating API documentation\n";
- print $f "\t\@doxygen Doxyfile > docs/doxygen.log 2>&1\n\n";
- print $f "\nclean:\n";
- print $f "\t\@rm -f *.exe *.o core psotnic-* psotnic validator *.log vgcore.* tests/a.out tests/a.exe make-hiddenseed\n\n";
- print $f "\t\@echo [*] Removing temporary files\n";
- print $f "\ndistclean:\n";
- print $f "\t\@\$(MAKE) clean\n";
- print $f "\t\@echo [*] Removing seed.h\n";
- print $f "\t\@rm -f seed.h\n";
- print $f "\t\@rm -rf bin/* pid.* *.ul config.h Makefile Makefile.* modules/Makefile modules/plog/Makefile modules/*.so\n\n";
- print $f "current:\n";
- print $f "\t\@echo [*] Making current source package\n";
- print $f "\t\@\$(MAKE) distclean\n";
- print $f "\t\@tar -cf ../psotnic-current.tar ../psotnic-current/\n";
- print $f "\t\@gzip -f9 ../psotnic-current.tar\n";
- print $f "\t\@echo [+] Done\n";
- print $f "release:\n";
- print $f "\t\@echo [*] Making release source package\n";
- print $f "\t\@\$(MAKE) distclean\n";
- print $f "\t\@tar -cf ../psotnic-current.tar ../psotnic-current/\n";
- print $f "\t\@gzip -f9 ../psotnic-current.tar\n";
- print $f "\t\@echo [+] Done\n";
- $f->close;
- #
- # Generating Makefile.$target
- #
- if($os =~ /cygwin/i) {
- $out = "bin/psotnic.exe";
- if($cflags =~/-DHAVE_IPV6/) {
- $cflags .= "-Dsocklen_t=int -fpermissive ";
- }
- $cflags .= "-DHAVE_CYGWIN ";
- }
- else {
- $out = "bin/psotnic";
- }
- my ($t, @tmp);
- foreach $t (keys %targets)
- {
- {
- $f = new FileHandle "> Makefile.$t" or die "[-] Cannot create Makefile.$t";
- print "[+] Generating Makefile.$t\n";
- print $f "#########################################\n";
- print $f "# Code generated by configure\n";
- print $f "#\n";
- print $f "# Copyright (c) 2003-2005 Grzegorz Rusin <grusin\@gmail.com>\n";
- print $f "# WARNING! All changes made in this file will be lost!\n";
- print $f "# \n\n";
- print $f ".SUFFIXES: .o .c .cpp\n\n";
- print $f ".c.o:\n";
- print $f "\t\@echo [*] Compiling \$<\n";
- print $f "\t\@${cc_prefix}g++ -c \$< $targets{$t} $cflags\n\n";
- print $f ".cpp.o:\n";
- print $f "\t\@echo [*] Compiling \$<\n";
- print $f "\t\@${cc_prefix}g++ -c \$< $targets{$t} $cflags\n\n";
- print $f ".cc.o:\n";
- print $f "\t\@echo [*] Compiling \$<\n";
- print $f "\t\@${cc_prefix}g++ -c \$< $targets{$t} $cflags\n\n";
- print $f "tar: $filelist\n";
- print $f "\t\@echo [*] Linking\n";
- print $f "\t\@test -d bin || mkdir bin\n";
- if($t =~ /debug|dynamic/) {
- print $f "\t\@${cc_prefix}g++ $filelist -o $out $targets{$t} $cflags $lflags -export-dynamic\n";
- }
- else {
- print $f "\t\@${cc_prefix}g++ $filelist -o $out $targets{$t} $cflags $lflags\n";
- }
- if(!($t =~ /debug/)) {
- print $f "\t\@echo [*] Striping debug information\n";
- print $f "\t\@${cc_prefix}strip $out\n";
- }
- print $f "\t\@echo [*] We are done\n";
- $f->close;
- }
- #
- # Modules makefile
- #
- my $f = new FileHandle "> modules/Makefile" or die 'Cannot create modules/Makefile';
- print "[+] Generating modules/Makefile\n";
- print $f "#########################################\n";
- print $f "# Code generated by configure\n";
- print $f "#\n";
- print $f "# Copyright (c) 2004-2007 Grzegorz Rusin <grusin\@gmail.com>\n";
- print $f "# WARNING! All changes made in this file will be lost!\n";
- print $f "# \n\n";
- my @modules = split /\n/, $moduleList;
- print $f "all:";
- foreach (@modules)
- print $f "$_:\n";
- print $f "\t\@echo [*] Compiling module $_\n";
- print $f "\t\@g++ -o $_.so $_.cpp -shared\n\n";
- }
- print $f "clean:\n";
- print $f "\t\@echo [*] Cleaning up\n";
- print $f "\t\@rm -f *.so\n\n";
- $f->close();
- #
- # Plog makefile
- #
- my $f = new FileHandle "> modules/plog/Makefile" or die 'Cannot create plog Makefile';
- print "[+] Generating modules/plog/Makefile\n";
- print $f "###########################################\n";
- print $f "# Code generated by configure\n";
- print $f "#\n";
- print $f "# Copyright (c) 2004-2007 Grzegorz Rusin <grusin\@gmail.com>\n";
- print $f "# WARNING: All changes made to this file will be lost!\n";
- print $f "#\n\n";
- print $f "plog:\n";
- print $f "\t\@echo [*] Compiling module plog\n";
- print $f "\t\@g++ main.cpp plog.cpp misc.cpp -o ../plog.so -shared\n";
- $f->close();
- #
- # Generating random seed
- #
- if(-f "seed.h")
- {
- print "[!] Random seed (seed.h) exists, using existing one.\n";
- }
- else
- {
- $f = new FileHandle "> seed.h";
- if(defined $f)
- {
- print "[+] Generating seed.h\n";
- print $f "/*\n";
- print $f " * This file contains magical seeds that will be used during encryption/decryption process.\n";
- print $f " * So make sure that you store it in safe place, if you loose it you wont be able to decode\n";
- print $f " * crypted files.\n";
- print $f " */\n\n";
- print $f "#ifndef PSOTNIC_SEED_H\n";
- print $f "#define PSOTNIC_SEED_H 1\n\n";
- my $cfg_seed = "";
- my $ul_seed = "";
- for($i=0; $i<16; ++$i) {
- $cfg_seed .= sprintf("\\x%02x", rand(256));
- }
- for($i=0; $i<16; ++$i) {
- $ul_seed .= sprintf("\\x%02x", rand(256));
- }
- print $f "static unsigned char cfg_seed[] = \"$cfg_seed\";\n";
- print $f "static unsigned char ul_seed[] = \"$ul_seed\";\n\n";
- print $f "#endif\n";
- print "[*] Random seeds for all binaries are located in seed.h\n";
- print "[*] Please backup seed.h when you finish compilation\n";
- }
- else
- {
- print "FATAL: Cannot create seed.h\n";
- die;
- }
- }
- #moved to makefiles, to keep compatybility
- #`gcc -o make-hiddenseed make-hiddenseed.c && ./make-hiddenseed > hidden-seed-functions.c`;
- #
- # Creating revision file my $ul_seed = "";
- for($i=0; $i<16; ++$i) {
- $cfg_seed .= sprintf("\\x%02x", rand(256));
- }
- for($i=0; $i<16; ++$i) {
- $ul_seed .= sprintf("\\x%02x", rand(256));
- }
- print $f "static unsigned char cfg_seed[] = \"$cfg_seed\";\n";
- print $f "static unsigned char ul_seed[] = \"$ul_seed\";\n\n";
- print $f "#endif\n";
- print "[*] Random seeds for all binaries are located in seed.h\n";
- print "[*] Please backup seed.h when you finish compilation\n";
- }
- else
- {
- print "FATAL: Cannot create seed.h\n";
- die;
- }
- }
- #moved to makefiles, to keep compatybility
- #`gcc -o make-hiddenseed make-hiddenseed.c && ./make-hiddenseed > hidden-seed-functions.c`;
- #
- # Creating revision file
- print "[*] Retrieving SVN revision\n";
- my $svn_entries = ".svn/entries";
- sub check_svn_revision
- {
- my $f = shift;
- my $x = `head -n 4 $f | tail -n 1 2>/dev/null`;
- $x =~ s/\n//;
- if(!($x =~ /^\d+$/))
- {
- $x = `head -n 4 $f | tail -1 2>/dev/null`;
- $x =~ s/\n//;
- }
- if(!($x =~ /^\d+$/))
- {
- $x = 'UNKNOWN';
- }
- return $x;
- }
- my $svn_rev = check_svn_revision($svn_entries);
- if($svn_rev == 'UNKNOWN')
- {
- my $currDir = `pwd`;
- if($currDir =~ /.*\/\.update-[0-9]*$/)
- {
- $svn_entries = `ls psotnic-*/.svn/entries`;
- $svn_entries =~ s/\n//;
- if($svn_entries =~ /entries/) {
- $svn_rev = check_svn_revision($svn_entries);
- }
- }
- }
- $cflags .= "-DSVN_REVISION=\"$svn_rev\" ";
- print "[+] Done; Source Code Revision = $svn_rev\n";
- #
- # Generating config.h
- #
- $f = new FileHandle "> config.h";
- if(defined $f)
- {
- print "[+] Generating config.h\n";
- print $f "#ifndef PSOTNIC_CONFIG_H\n";
- print $f "#define PSOTNIC_CONFIG_H 1\n\n";
- my @arr = split(/ /, $cflags);
- foreach(@arr)
- {
- if(/(-D)(.*)=(.*)/) {
- print $f "#ifndef $2\n";
- print $f "#\tdefine $2\t$3\n";
- print $f "#endif\n\n";
- }
- elsif(/(-D)(.*)/) {
- print $f "#ifndef $2\n";
- print $f "\t#define $2\t1\n";
- print $f "#endif\n\n";
- }
- }
- print $f "\n#endif\n";
- $f->close
- }
- 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement