Exemplo n.º 1
0
static void log_all(void)
{
   /* a check on the input */
   if (strlen(logfile) == 0) {
      ui_error("Please specify a filename");
      return;
   }

   set_loglevel(LOG_PACKET, logfile);
   SAFE_FREE(logfile);
}
Exemplo n.º 2
0
Arquivo: pwm_py.c Projeto: sert00/RPIO
// python function (void) set_loglevel(level);
static PyObject*
py_set_loglevel(PyObject *self, PyObject *args)
{
    int level;

    if (!PyArg_ParseTuple(args, "i", &level))
        return NULL;

    set_loglevel(level);

    Py_INCREF(Py_None);
    return Py_None;
}
Exemplo n.º 3
0
int main(int argc, char **argv) {

    enable_shell_log();
    disable_file_log();
    set_loglevel(LOG_NOTICE);

    progname = malloc((10*sizeof(char))+1);
    progname = strdup("433-debug");

#ifdef USE_LIRC
    lirc_t data;
    char *socket = strdup("/dev/lirc0");
    int have_device = 0;
#else
    int newDuration;
#endif

    int duration = 0;
    int i = 0;
    int y = 0;

    int recording = 1;
    int bit = 0;
    int raw[255];
    int pRaw[255];
    int code[255];
    int binary[255];
    int footer = 0;
    int header = 0;
    int pulse = 0;
    int rawLength = 0;
    int binaryLength = 0;

    int loop = 1;

#ifdef USE_LIRC
    hw_choose_driver(NULL);
#endif

    addOption(&options, 'H', "help", no_value, 0, NULL);
    addOption(&options, 'V', "version", no_value, 0, NULL);
#ifdef USE_LIRC
    addOption(&options, 'S', "socket", has_value, 0, "^/dev/([A-Za-z]+)([0-9]+)");
#endif

    while (1) {
        int c;
        c = getOptions(&options, argc, argv, 1);
        if(c == -1)
            break;
        switch (c) {
        case 'h':
            printf("Usage: %s [options]\n", progname);
            printf("\t -H --help\t\tdisplay usage summary\n");
            printf("\t -V --version\t\tdisplay version\n");
#ifdef USE_LIRC
            printf("\t -S --socket=socket\tread from given socket\n");
#endif
            return (EXIT_SUCCESS);
            break;
        case 'v':
            printf("%s %s\n", progname, "1.0");
            return (EXIT_SUCCESS);
            break;
#ifdef USE_LIRC
        case 'S':
            socket = optarg;
            have_device = 1;
            break;
#endif
        default:
            printf("Usage: %s [options]\n", progname);
            return (EXIT_FAILURE);
            break;
        }
    }

#ifdef USE_LIRC
    if(strcmp(socket, "/var/lirc/lircd") == 0) {
        logprintf(LOG_ERR, "refusing to connect to lircd socket");
        return EXIT_FAILURE;
    }

    if(have_device)
        hw.device = socket;

    if(!hw.init_func()) {
        return EXIT_FAILURE;
    }
#endif

    /*
    End of the original (but stripped) code of mode2
    */

#ifndef USE_LIRC
    if(gpio_request(GPIO_IN_PIN) == 0) {
        /* Attach an interrupt to the requested pin */
        irq_attach(GPIO_IN_PIN, CHANGE);
    } else {
        return EXIT_FAILURE;
    }
#endif

    while(loop) {
#ifdef USE_LIRC
        data = hw.readdata(0);
        duration = (data & PULSE_MASK);
#else

        unsigned short a = 0;

        if((newDuration = irq_read()) == 1) {
            continue;
        }

        for(a=0; a<2; a++) {
            if(a==0) {
                duration = PULSE_LENGTH;
            } else {
                duration = newDuration;
                if(duration < 750) {
                    duration = PULSE_LENGTH;
                }
            }
#endif

        /* If we are recording, keep recording until the next footer has been matched */
        if(recording == 1) {
            if(bit < 255) {
                raw[bit++] = duration;
            } else {
                bit = 0;
                recording = 0;
            }
        }

        /* First try to catch code that seems to be a footer.
           If a real footer has been recognized, start using that as the new footer */
        if((duration > 5000
                && duration < 100000 && footer == 0) || ((footer-(footer*0.1)<duration) && (footer+(footer*0.1)>duration))) {
            recording = 1;

            /* Check if we are recording similar codes */
            for(i=0; i<(bit-1); i++) {
                if(!(((pRaw[i]-(pRaw[i]*0.3)) < raw[i]) && ((pRaw[i]+(pRaw[i]*0.3)) > raw[i]))) {
                    y=0;
                    recording=0;
                }
                pRaw[i]=raw[i];
            }
            y++;

            /* Continue if we have 2 matches */
            if(y>2) {
                /* If we are certain we are recording similar codes.
                   Save the header values and the raw code length */
                if(footer>0) {
                    if(header == 0) {
                        header=raw[1];
                    }
                    if(rawLength == 0)
                        rawLength=bit;
                }
                /* Try to catch the footer, and the low and high values */
                for(i=0; i<bit; i++) {
                    if((i+1)<bit && i > 2 && footer > 0) {
                        if((raw[i]/PULSE_LENGTH) >= 2) {
                            pulse=raw[i];
                        }
                    }
                    if(duration > 5000 && duration < 100000) {
                        footer=raw[i];
                    }
                }

                /* If we have gathered all data, stop with the loop */
                if(header > 0 && footer > 0 && pulse > 0 && rawLength > 0) {
                    loop = 0;
                }
            }
            bit=0;
        }

        fflush(stdout);
#ifndef USE_LIRC
    }
#endif
};

/* Convert the raw code into binary code */
for(i=0; i<rawLength; i++) {
    if((unsigned int)raw[i] > (pulse-PULSE_LENGTH)) {
        code[i]=1;
    } else {
        code[i]=0;
    }
}
for(i=2; i<rawLength; i+=4) {
    if(code[i+1] == 1) {
        binary[i/4]=1;
    } else {
        binary[i/4]=0;
    }
}

binaryLength = (int)((float)i/4);

/* Print everything */
printf("--[RESULTS]--\n");
printf("\n");
printf("header:\t\t%d\n",normalize(header));
printf("pulse:\t\t%d\n",normalize(pulse));
printf("footer:\t\t%d\n",normalize(footer));
printf("rawLength:\t%d\n",rawLength);
printf("binaryLength:\t%d\n",binaryLength);
printf("\n");
printf("Raw code:\n");
for(i=0; i<rawLength; i++) {
    printf("%d ",normalize(raw[i])*PULSE_LENGTH);
}
printf("\n");
printf("Binary code:\n");
for(i=0; i<binaryLength; i++) {
    printf("%d",binary[i]);
}
printf("\n");
return (EXIT_SUCCESS);
}
Exemplo n.º 4
0
int main(int argc, char **argv) {

	disable_file_log();
	enable_shell_log();
	set_loglevel(LOG_NOTICE);

	progname = malloc((10*sizeof(char))+1);
	progname = strdup("433-send");

	options = malloc(255*sizeof(struct options_t));

	int sockfd = 0;
    char *recvBuff = NULL;
    char *message;
	steps_t steps = WELCOME;

	/* Hold the name of the protocol */
	char protobuffer[25] = "\0";
	int i;
	/* Does this protocol exists */
	int match = 0;

	/* Do we need to print the help */
	int help = 0;
	/* Do we need to print the version */
	int version = 0;
	/* Do we need to print the protocol help */
	int protohelp = 0;

	char server[16] = "127.0.0.1";
	unsigned short port = PORT;
	
	/* Hold the final protocol struct */
	protocol_t *protocol = NULL;

	JsonNode *json = json_mkobject();
	JsonNode *code = json_mkobject();

	/* Define all CLI arguments of this program */
	addOption(&options, 'H', "help", no_value, 0, NULL);
	addOption(&options, 'V', "version", no_value, 0, NULL);
	addOption(&options, 'p', "protocol", has_value, 0, NULL);
	addOption(&options, 'S', "server", has_value, 0, "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$");
	addOption(&options, 'P', "port", has_value, 0, "[0-9]{1,4}");

	/* Initialize peripheral modules */
	hw_init();

	/* Get the protocol to be used */
	while (1) {
		int c;
		c = getOptions(&options, argc, argv, 0);
		if (c == -1)
			break;
		switch(c) {
			case 'p':
				if(strlen(optarg) == 0) {
					logprintf(LOG_ERR, "options '-p' and '--protocol' require an argument");
					exit(EXIT_FAILURE);
				} else {
					strcpy(protobuffer, optarg);
				}
			break;
			case 'V':
				version = 1;
			break;
			case 'H':
				help = 1;
			break;
			case 'S':
				strcpy(server, optarg);
			break;
			case 'P':
				port = (unsigned short)atoi(optarg);
			break;
			default:;
		}
	}

	/* Check if a protocol was given */
	if(strlen(protobuffer) > 0 && strcmp(protobuffer,"-v") != 0) {
		if(strlen(protobuffer) > 0 && version) {
			printf("-p and -V cannot be combined\n");
		} else {
			for(i=0; i<protocols.nr; ++i) {
				protocol = protocols.listeners[i];
				/* Check if the protocol exists */
				if(protocol_has_device(&protocol, protobuffer) == 0 && match == 0 && protocol->createCode != NULL) {
					match=1;
					/* Check if the protocol requires specific CLI arguments
					   and merge them with the main CLI arguments */
					if(protocol->options != NULL && help == 0) {
						mergeOptions(&options, &protocol->options);
					} else if(help == 1) {
						protohelp=1;
					}
					break;
				}
			}
			/* If no protocols matches the requested protocol */
			if(!match) {
				logprintf(LOG_ERR, "this protocol is not supported");
			}
		}
	}

	/* Display help or version information */
	if(version == 1) {
		printf("%s %s\n", progname, "1.0");
		return (EXIT_SUCCESS);
	} else if(help == 1 || protohelp == 1 || match == 0) {
		if(protohelp == 1 && match == 1 && protocol->printHelp != NULL)
			printf("Usage: %s -p %s [options]\n", progname, protobuffer);
		else
			printf("Usage: %s -p protocol [options]\n", progname);
		if(help == 1) {
			printf("\t -H --help\t\t\tdisplay this message\n");
			printf("\t -V --version\t\t\tdisplay version\n");
			printf("\t -S --server=%s\t\tconnect to server address\n", server);
			printf("\t -P --port=%d\t\t\tconnect to server port\n", port);
			printf("\t -p --protocol=protocol\t\tthe protocol that you want to control\n");
		}
		if(protohelp == 1 && match == 1 && protocol->printHelp != NULL) {
			printf("\n\t[%s]\n", protobuffer);
			protocol->printHelp();
		} else {
			printf("\nThe supported protocols are:\n");
			for(i=0; i<protocols.nr; ++i) {
				protocol = protocols.listeners[i];
				if(protocol->createCode != NULL) {
					while(protocol->devices != NULL) {
						printf("\t %s\t\t\t",protocol->devices->id);
						if(strlen(protocol->devices->id)<6)
							printf("\t");
						printf("%s\n", protocol->devices->desc);
						protocol->devices = protocol->devices->next;
					}
				}
			}
		}
		return (EXIT_SUCCESS);
	}

	/* Store all CLI arguments for later usage
	   and also check if the CLI arguments where
	   used correctly by the user. This will also
	   fill all necessary values in the options struct */
	while(1) {
		int c;
		c = getOptions(&options, argc, argv, 1);

		if(c == -1)
			break;
	}

	int itmp;
	/* Check if we got sufficient arguments from this protocol */
	while(options != NULL && strlen(options->name) > 0) {
		/* Only send the CLI arguments that belong to this protocol, the protocol name
		   and those that are called by the user */
		if((getOptionIdByName(&protocol->options, options->name, &itmp) == 0 || strcmp(options->name, "protocol") == 0)
		   && strlen(options->value) > 0) {
			json_append_member(code, options->name, json_mkstring(options->value));
		}
		options = options->next;
	}

	if(protocol->createCode(code) == 0) {
		if((sockfd = connect_to_server(strdup(server), port)) == -1) {
			logprintf(LOG_ERR, "could not connect to 433-daemon");
			goto close;
		}

		while(1) {
			/* Clear the receive buffer again and read the welcome message */
			if((recvBuff = socket_read(sockfd)) != NULL) {
				json = json_decode(recvBuff);
				json_find_string(json, "message", &message);
			} else {
				goto close;
			}
			usleep(100);
			switch(steps) {
				case WELCOME:
					if(strcmp(message, "accept connection") == 0) {
						socket_write(sockfd, "{\"message\":\"client sender\"}");
						steps=IDENTIFY;
					}
				case IDENTIFY:
					if(strcmp(message, "accept client") == 0) {
						steps=SEND;
					}
					if(strcmp(message, "reject client") == 0) {
						steps=REJECT;
					}
				case SEND:
					json_delete(json);
					json = json_mkobject();
					json_append_member(json, "message", json_mkstring("send"));
					json_append_member(json, "code", code);
					socket_write(sockfd, json_stringify(json, NULL));
					goto close;
				break;
				case REJECT:
				default:
					goto close;
				break;
			}
		}
	}
close:
	json_delete(json);
	socket_close(sockfd);
return EXIT_SUCCESS;
}
Exemplo n.º 5
0
void parse_options(int argc, char **argv)
{
   int c;

   static struct option long_options[] = {
      { "help", no_argument, NULL, 'h' },
      { "version", no_argument, NULL, 'v' },
      
      { "iface", required_argument, NULL, 'i' },
      { "iflist", no_argument, NULL, 'I' },
      { "netmask", required_argument, NULL, 'n' },
      { "write", required_argument, NULL, 'w' },
      { "read", required_argument, NULL, 'r' },
      { "pcapfilter", required_argument, NULL, 'f' },
      
      { "reversed", no_argument, NULL, 'R' },
      { "proto", required_argument, NULL, 't' },
      
      { "plugin", required_argument, NULL, 'P' },
      
      { "filter", required_argument, NULL, 'F' },
      
      { "superquiet", no_argument, NULL, 'Q' },
      { "quiet", no_argument, NULL, 'q' },
      { "script", required_argument, NULL, 's' },
      { "silent", no_argument, NULL, 'z' },
      { "unoffensive", no_argument, NULL, 'u' },
      { "load-hosts", required_argument, NULL, 'j' },
      { "save-hosts", required_argument, NULL, 'k' },
      { "wep-key", required_argument, NULL, 'W' },
      { "config", required_argument, NULL, 'a' },
      
      { "dns", no_argument, NULL, 'd' },
      { "regex", required_argument, NULL, 'e' },
      { "visual", required_argument, NULL, 'V' },
      { "ext-headers", no_argument, NULL, 'E' },
      
      { "log", required_argument, NULL, 'L' },
      { "log-info", required_argument, NULL, 'l' },
      { "log-msg", required_argument, NULL, 'm' },
      { "compress", no_argument, NULL, 'c' },
      
      { "text", no_argument, NULL, 'T' },
      { "curses", no_argument, NULL, 'C' },
      { "gtk", no_argument, NULL, 'G' },
      { "daemon", no_argument, NULL, 'D' },
      
      { "mitm", required_argument, NULL, 'M' },
      { "only-mitm", no_argument, NULL, 'o' },
      { "bridge", required_argument, NULL, 'B' },
      { "promisc", no_argument, NULL, 'p' },
      
      { 0 , 0 , 0 , 0}
   };


#ifdef HAVE_GTK 
      if (strcmp(argv[0], "ettercap-gtk") == 0)
          select_gtk_interface();
#endif
#ifdef HAVE_NCURSES 
      if (strcmp(argv[0], "ettercap-curses") == 0)
          select_curses_interface();
#endif
      if (strcmp(argv[0], "ettercap-text") == 0)
          select_text_interface();

   for (c = 0; c < argc; c++)
      DEBUG_MSG("parse_options -- [%d] [%s]", c, argv[c]);

   
/* OPTIONS INITIALIZATION */
   
   GBL_PCAP->promisc = 1;
   GBL_FORMAT = &ascii_format;

/* OPTIONS INITIALIZED */
   
   optind = 0;

   while ((c = getopt_long (argc, argv, "a:B:CchDdEe:F:f:GhIi:j:k:L:l:M:m:n:oP:pQqiRr:s:Tt:UuV:vW:w:z", long_options, (int *)0)) != EOF) {

      switch (c) {

         case 'M':
                  GBL_OPTIONS->mitm = 1;
                  if (mitm_set(optarg) != ESUCCESS)
                     FATAL_ERROR("MITM method '%s' not supported...\n", optarg);
                  break;
                  
         case 'o':
                  GBL_OPTIONS->only_mitm = 1;
                  //select_text_interface();
                  break;
                  
         case 'B':
                  GBL_OPTIONS->iface_bridge = strdup(optarg);
                  set_bridge_sniff();
                  break;
                  
         case 'p':
                  GBL_PCAP->promisc = 0;
                  break;
                 
         case 'T':
                  select_text_interface();
                  break;
                  
         case 'C':
#ifdef HAVE_NCURSES 
                  select_curses_interface();
#else
            fprintf(stdout, "\nncurses-interface not supported.\n\n");
            clean_exit(-1);
#endif
                  break;
         case 'G':
#ifdef HAVE_GTK
                  select_gtk_interface();
#else
            fprintf(stdout, "\nGTK-Interface not supported.\n\n");
            clean_exit(-1);
#endif
                  break;
         
         case 'D':
                  select_daemon_interface();
                  break;
                  
         case 'R':
                  GBL_OPTIONS->reversed = 1;
                  break;
                  
         case 't':
                  GBL_OPTIONS->proto = strdup(optarg);
                  break;
                  
         case 'P':
                  /* user has requested the list */
                  if (!strcasecmp(optarg, "list")) {
                     plugin_list();
                     clean_exit(0);
                  }
                  /* else set the plugin */
                  GBL_OPTIONS->plugin = strdup(optarg);
                  break;
                  
         case 'i':
                  GBL_OPTIONS->iface = strdup(optarg);
                  break;
                  
         case 'I':
                  /* this option is only useful in the text interface */
                  select_text_interface();
                  GBL_OPTIONS->iflist = 1;
                  break;
         
         case 'n':
                  GBL_OPTIONS->netmask = strdup(optarg);
                  break;
                  
         case 'r':
                  /* we don't want to scan the lan while reading from file */
                  GBL_OPTIONS->silent = 1;
                  GBL_OPTIONS->read = 1;
                  GBL_OPTIONS->pcapfile_in = strdup(optarg);
                  break;
                 
         case 'w':
                  GBL_OPTIONS->write = 1;
                  GBL_OPTIONS->pcapfile_out = strdup(optarg);
                  break;
                  
         case 'f':
                  GBL_PCAP->filter = strdup(optarg);
                  break;
                  
         case 'F':
                  if (filter_load_file(optarg, GBL_FILTERS) != ESUCCESS)
                     FATAL_ERROR("Cannot load filter file \"%s\"", optarg);
                  break;
                  
         case 'L':
                  if (set_loglevel(LOG_PACKET, optarg) == -EFATAL)
                     clean_exit(-EFATAL);
                  break;

         case 'l':
                  if (set_loglevel(LOG_INFO, optarg) == -EFATAL)
                     clean_exit(-EFATAL);
                  break;

         case 'm':
                  if (set_msg_loglevel(LOG_TRUE, optarg) == -EFATAL)
                     clean_exit(-EFATAL);
                  break;
                  
         case 'c':
                  GBL_OPTIONS->compress = 1;
                  break;

         case 'e':
                  if (set_regex(optarg) == -EFATAL)
                     clean_exit(-EFATAL);
                  break;
         
         case 'Q':
                  GBL_OPTIONS->superquiet = 1;
                  /* no break, quiet must be enabled */
         case 'q':
                  GBL_OPTIONS->quiet = 1;
                  break;
                  
         case 's':
                  GBL_OPTIONS->script = strdup(optarg);
                  break;
                  
         case 'z':
                  GBL_OPTIONS->silent = 1;
                  break;
                  
         case 'u':
                  GBL_OPTIONS->unoffensive = 1;
                  break;
                  
         case 'd':
                  GBL_OPTIONS->resolve = 1;
                  break;
                  
         case 'j':
                  GBL_OPTIONS->silent = 1;
                  GBL_OPTIONS->load_hosts = 1;
                  GBL_OPTIONS->hostsfile = strdup(optarg);
                  break;
                  
         case 'k':
                  GBL_OPTIONS->save_hosts = 1;
                  GBL_OPTIONS->hostsfile = strdup(optarg);
                  break;
                  
         case 'V':
                  if (set_format(optarg) != ESUCCESS)
                     clean_exit(-EFATAL);
                  break;
                  
         case 'E':
                  GBL_OPTIONS->ext_headers = 1;
                  break;
                  
         case 'W':
                  set_wep_key(optarg);
                  break;
                  
         case 'a':
                  GBL_CONF->file = strdup(optarg);
                  break;
                  
         case 'h':
                  ec_usage();
                  break;

         case 'v':
                  printf("%s %s\n", GBL_PROGRAM, GBL_VERSION);
                  clean_exit(0);
                  break;

         case ':': // missing parameter
            fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM);
            clean_exit(-1);
         break;

         case '?': // unknown option
            fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM);
            clean_exit(-1);
         break;
      }
   }

   DEBUG_MSG("parse_options: options parsed");
   
   /* TARGET1 and TARGET2 parsing */
   if (argv[optind]) {
      GBL_OPTIONS->target1 = strdup(argv[optind]);
      DEBUG_MSG("TARGET1: %s", GBL_OPTIONS->target1);
      
      if (argv[optind+1]) {
         GBL_OPTIONS->target2 = strdup(argv[optind+1]);
         DEBUG_MSG("TARGET2: %s", GBL_OPTIONS->target2);
      }
   }

   /* create the list form the TARGET format (MAC/IPrange/PORTrange) */
   compile_display_filter();
   
   DEBUG_MSG("parse_options: targets parsed");
   
   /* check for other options */
   
   if (GBL_SNIFF->start == NULL)
      set_unified_sniff();
   
   if (GBL_OPTIONS->read && GBL_PCAP->filter)
      FATAL_ERROR("Cannot read from file and set a filter on interface");
   
   if (GBL_OPTIONS->read && GBL_SNIFF->type != SM_UNIFIED )
      FATAL_ERROR("You can read from a file ONLY in unified sniffing mode !");
   
   if (GBL_OPTIONS->mitm && GBL_SNIFF->type != SM_UNIFIED )
      FATAL_ERROR("You can't do mitm attacks in bridged sniffing mode !");

   if (GBL_SNIFF->type == SM_BRIDGED && GBL_PCAP->promisc == 0)
      FATAL_ERROR("During bridged sniffing the iface must be in promisc mode !");
   
   if (GBL_OPTIONS->quiet && GBL_UI->type != UI_TEXT)
      FATAL_ERROR("The quiet option is useful only with text only UI");
  
   if (GBL_OPTIONS->load_hosts && GBL_OPTIONS->save_hosts)
      FATAL_ERROR("Cannot load and save at the same time the hosts list...");
  
   if (GBL_OPTIONS->unoffensive && GBL_OPTIONS->mitm)
      FATAL_ERROR("Cannot use mitm attacks in unoffensive mode");
   
   if (GBL_OPTIONS->read && GBL_OPTIONS->mitm)
      FATAL_ERROR("Cannot use mitm attacks while reading from file");
   
   if (GBL_UI->init == NULL) {
      FATAL_ERROR("Please select an User Interface");
    }
     
   /* force text interface for only mitm attack */
   //if (GBL_OPTIONS->only_mitm) {
   //   if (GBL_OPTIONS->mitm)
   //      select_text_interface();
   //   else
   //      FATAL_ERROR("Only mitm requires at least one mitm method");
   //}

   DEBUG_MSG("parse_options: options combination looks good");
   
   return;
}
Exemplo n.º 6
0
/*
 * Entry point. Process command line options, start up pcap and enter capture loop.
 */
int main(int argc, char *argv[])
{
    pthread_t packetth;
    options_t *options;

    options = parse_options(argc, argv);

    if (options->verbose)
        set_loglevel(LOG_INFO);

    if (options->adjunct)
        create_pidfile();

    /*
     * In adjunct mode, it's important that the attached program gets
     * notification of images in a timely manner. Make stdout line-buffered
     * for this reason.
     */
    if (options->adjunct)
        setvbuf(stdout, NULL, _IOLBF, 0);

    /*
     * If a directory name has not been specified, then we need to create one.
     * Otherwise, check that it's a directory into which we may write files.
     */
    if (options->tmpdir) {
        check_dir_is_rw(options->tmpdir);
        set_tmpdir(options->tmpdir, TMPDIR_USER_OWNED, options->max_tmpfiles, options->adjunct);

    } else {
        /* need to make a temporary directory. */
        set_tmpdir(make_tmpdir(), TMPDIR_APP_OWNED, options->max_tmpfiles, options->adjunct);
    }

    setup_signals();

    /* Start up the audio player, if required. */
    if (!options->adjunct && (options->extract_type & m_audio))
        do_mpeg_player();

#ifndef NO_DISPLAY_WINDOW
    /* Possibly fork to start the display child process */
    if (!options->adjunct && (options->extract_type & m_image))
        do_image_display(options->savedimgpfx, options->beep);
    else
        log_msg(LOG_INFO, "operating in adjunct mode");
#endif /* !NO_DISPLAY_WINDOW */

    init_mediadrv(options->extract_type, !options->adjunct);

    /* Start up pcap. */
    if (options->dumpfile)
        packetcapture_open_offline(options->dumpfile);
    else
        packetcapture_open_live(options->interface, options->filterexpr, options->promisc);

    connection_alloc_slots();

    /*
     * Actually start the capture stuff up. Unfortunately, on many platforms,
     * libpcap doesn't have read timeouts, so we start the thing up in a
     * separate thread. Yay!
     */
    pthread_create(&packetth, NULL, capture_thread, NULL);

    while (!foad)
        sleep(1);

    if (options->verbose)
        print_exit_reason();

    pthread_cancel(packetth); /* make sure thread quits even if it's stuck in pcap_dispatch */
    pthread_join(packetth, NULL);

    /* Clean up. */
    /*    pcap_freecode(pc, &filter);*/ /* not on some systems... */
    packetcapture_close();

    /* Easier for memory-leak debugging if we deallocate all this here.... */
    connection_free_slots();

    clean_tmpdir();

    if (options->adjunct)
        close_pidfile();

    return 0;
}
Exemplo n.º 7
0
int main(int argc, char *argv[])
{
	int c;
	struct option long_options[] = {
		/* Options/Commands */
		{"clear",             0, 0, 'c'},
		{"disable",           0, 0, 'd'},
		{"enable",            0, 0, 'e'},
		{"force-reset",       0, 0, 'f'},
		{"loglevel",          1, 0, 'l'},
		{"help",              0, 0, 'h'},
		{"reboot",            1, 0, 'r'},
		{"status",            0, 0, 's'},
		{"verbose",           0, 0, 'V'},
		{"version",           0, 0, 'v'},
		/* Tests */
		{"complete-cycle",    0, 0, 200},
		{"disable-enable",    0, 0, 201},
		{"false-ack",         0, 0, 202},
		{"false-unsubscribe", 0, 0, 203},
		{"failed-kick",       0, 0, 204},
		{"no-kick",           0, 0, 205},
		{"premature-trigger", 0, 0, 206},
		{NULL, 0, 0, 0}
	};

	while ((c = getopt_long(argc, argv, "cdefl:hr:sVv?", long_options, NULL)) != EOF) {
		switch (c) {
		case 'c':
			return do_clear();

		case 'd':
			return do_enable(0);

		case 'e':
			return do_enable(1);

		case 'f':
			return do_reset(0);

		case 'l':
			return set_loglevel(optarg);

		case 'h':
			return usage(0);

		case 'r':
			return do_reset(atoi(optarg));

		case 's':
			return show_status();

		case 'V':
			verbose = 1;
			break;

		case 'v':
			return show_version();

		case 200:
			return testit();

		case 201:
			disable_enable = 1;
			return testit();

		case 202:
			false_ack = 1;
			return testit();

		case 203:
			false_unsubscribe = 1;
			return testit();

		case 204:
			failed_kick = 1;
			return testit();

		case 205:
			no_kick = 1;
			return testit();

		case 206:
			premature = 1;
			return testit();

		default:
			warn("Unknown or currently unsupported.");
			return usage(1);
		}
	}

	return 0;
}
Exemplo n.º 8
0
void parse_options(int argc, char **argv)
{
   int c;

   static struct option long_options[] = {
      { "help", no_argument, NULL, 'h' },
      { "version", no_argument, NULL, 'v' },
      { "update", no_argument, NULL, 'U' },
      
      { "iface", required_argument, NULL, 'i' },
      { "lifaces", no_argument, NULL, 'I' },
      { "netmask", required_argument, NULL, 'n' },
      { "address", required_argument, NULL, 'A' },
      { "write", required_argument, NULL, 'w' },
      { "read", required_argument, NULL, 'r' },
      { "pcapfilter", required_argument, NULL, 'f' },
      
      { "reversed", no_argument, NULL, 'R' },
      { "proto", required_argument, NULL, 't' },
      
      { "plugin", required_argument, NULL, 'P' },
      
      { "filter", required_argument, NULL, 'F' },
      
      { "superquiet", no_argument, NULL, 'Q' },
      { "quiet", no_argument, NULL, 'q' },
      { "script", required_argument, NULL, 's' },
      { "silent", no_argument, NULL, 'z' },
      { "unoffensive", no_argument, NULL, 'u' },
      { "nosslmitm", no_argument, NULL, 'S' },
      { "load-hosts", required_argument, NULL, 'j' },
      { "save-hosts", required_argument, NULL, 'k' },
      { "wep-key", required_argument, NULL, 'W' },
      { "config", required_argument, NULL, 'a' },
      
      { "dns", no_argument, NULL, 'd' },
      { "regex", required_argument, NULL, 'e' },
      { "visual", required_argument, NULL, 'V' },
      { "ext-headers", no_argument, NULL, 'E' },
      
      { "log", required_argument, NULL, 'L' },
      { "log-info", required_argument, NULL, 'l' },
      { "log-msg", required_argument, NULL, 'm' },
      { "compress", no_argument, NULL, 'c' },
      
      { "text", no_argument, NULL, 'T' },
      { "curses", no_argument, NULL, 'C' },
      { "daemon", no_argument, NULL, 'D' },
      { "gtk", no_argument, NULL, 'G' },

      
      { "mitm", required_argument, NULL, 'M' },
      { "only-mitm", no_argument, NULL, 'o' },
      { "bridge", required_argument, NULL, 'B' },
      { "broadcast", required_argument, NULL, 'b' },
      { "promisc", no_argument, NULL, 'p' },
      { "gateway", required_argument, NULL, 'Y' },
      { "certificate", required_argument, NULL, 0 },
      { "private-key", required_argument, NULL, 0 },

      
      { 0 , 0 , 0 , 0}
   };

   for (c = 0; c < argc; c++)
      DEBUG_MSG("parse_options -- [%d] [%s]", c, argv[c]);

   
/* OPTIONS INITIALIZATION */
   
   GBL_PCAP->promisc = 1;
   GBL_FORMAT = &ascii_format;
   GBL_OPTIONS->ssl_mitm = 1;
   GBL_OPTIONS->broadcast = 0;
   GBL_OPTIONS->ssl_cert = NULL;
   GBL_OPTIONS->ssl_pkey = NULL;

/* OPTIONS INITIALIZED */
   
   optind = 0;
   int option_index = 0;

   while ((c = getopt_long (argc, argv, "A:a:bB:CchDdEe:F:f:GhIi:j:k:L:l:M:m:n:oP:pQqiRr:s:STt:UuV:vW:w:Y:z", long_options, &option_index)) != EOF) {
      /* used for parsing arguments */
      char *opt_end = optarg;
      while (opt_end && *opt_end) opt_end++;
      /* enable a loaded filter script? */
      uint8_t f_enabled = 1;

      switch (c) {

         case 'M':
                  GBL_OPTIONS->mitm = 1;
                  if (mitm_set(optarg) != ESUCCESS)
                     FATAL_ERROR("MITM method '%s' not supported...\n", optarg);
                  break;
                  
         case 'o':
                  GBL_OPTIONS->only_mitm = 1;
                  //select_text_interface();
                  break;

         case 'b':
                  GBL_OPTIONS->broadcast = 1;
		  break;
                  
         case 'B':
                  GBL_OPTIONS->iface_bridge = strdup(optarg);
                  set_bridge_sniff();
                  break;
                  
         case 'p':
                  GBL_PCAP->promisc = 0;
                  break;
                 
         case 'T':
                  select_text_interface();
                  break;
                  
         case 'C':
                  select_curses_interface();
                  break;

         case 'G':
                  select_gtk_interface();
                  break;

                  
         case 'D':
                  select_daemon_interface();
                  break;
                  
         case 'R':
                  GBL_OPTIONS->reversed = 1;
                  break;
                  
         case 't':
                  GBL_OPTIONS->proto = strdup(optarg);
                  break;
                  
         case 'P':
                  /* user has requested the list */
                  if (!strcasecmp(optarg, "list")) {
                     plugin_list();
                     clean_exit(0);
                  }
                  /* else set the plugin */
                  GBL_OPTIONS->plugin = strdup(optarg);
                  break;
                  
         case 'i':
                  GBL_OPTIONS->iface = strdup(optarg);
                  break;
                  
         case 'I':
                  /* this option is only useful in the text interface */
                  select_text_interface();
                  GBL_OPTIONS->lifaces = 1;
                  break;

         case 'Y':
                  GBL_OPTIONS->secondary = parse_iflist(optarg);
                  break;
         
         case 'n':
                  GBL_OPTIONS->netmask = strdup(optarg);
                  break;

         case 'A':
                  GBL_OPTIONS->address = strdup(optarg);
                  break;
                  
         case 'r':
                  /* we don't want to scan the lan while reading from file */
                  GBL_OPTIONS->silent = 1;
                  GBL_OPTIONS->read = 1;
                  GBL_OPTIONS->pcapfile_in = strdup(optarg);
                  break;
                 
         case 'w':
                  GBL_OPTIONS->write = 1;
                  GBL_OPTIONS->pcapfile_out = strdup(optarg);
                  break;
                  
         case 'f':
                  GBL_PCAP->filter = strdup(optarg);
                  break;
                  
         case 'F':
                  /* is there a :0 or :1 appended to the filename? */
                  if ( (opt_end-optarg >=2) && *(opt_end-2) == ':' ) {
                     *(opt_end-2) = '\0';
                     f_enabled = !( *(opt_end-1) == '0' );
		  }
                  if (filter_load_file(optarg, GBL_FILTERS, f_enabled) != ESUCCESS)
                     FATAL_ERROR("Cannot load filter file \"%s\"", optarg);
                  break;
                  
         case 'L':
                  if (set_loglevel(LOG_PACKET, optarg) == -EFATAL)
                     clean_exit(-EFATAL);
                  break;

         case 'l':
                  if (set_loglevel(LOG_INFO, optarg) == -EFATAL)
                     clean_exit(-EFATAL);
                  break;

         case 'm':
                  if (set_msg_loglevel(LOG_TRUE, optarg) == -EFATAL)
                     clean_exit(-EFATAL);
                  break;
                  
         case 'c':
                  GBL_OPTIONS->compress = 1;
                  break;

         case 'e':
                  if (set_regex(optarg) == -EFATAL)
                     clean_exit(-EFATAL);
                  break;
         
         case 'Q':
                  GBL_OPTIONS->superquiet = 1;
                  /* no break, quiet must be enabled */
         case 'q':
                  GBL_OPTIONS->quiet = 1;
                  break;
                  
         case 's':
                  GBL_OPTIONS->script = strdup(optarg);
                  break;
                  
         case 'z':
                  GBL_OPTIONS->silent = 1;
                  break;
                  
         case 'u':
                  GBL_OPTIONS->unoffensive = 1;
                  break;

         case 'S':
                  GBL_OPTIONS->ssl_mitm = 0;
                  break;
 
         case 'd':
                  GBL_OPTIONS->resolve = 1;
                  break;
                  
         case 'j':
                  GBL_OPTIONS->silent = 1;
                  GBL_OPTIONS->load_hosts = 1;
                  GBL_OPTIONS->hostsfile = strdup(optarg);
                  break;
                  
         case 'k':
                  GBL_OPTIONS->save_hosts = 1;
                  GBL_OPTIONS->hostsfile = strdup(optarg);
                  break;
                  
         case 'V':
                  if (set_format(optarg) != ESUCCESS)
                     clean_exit(-EFATAL);
                  break;
                  
         case 'E':
                  GBL_OPTIONS->ext_headers = 1;
                  break;
                  
         case 'W':
                  set_wep_key(optarg);
                  break;
                  
         case 'a':
                  GBL_CONF->file = strdup(optarg);
                  break;
         
         case 'U':
                  /* load the conf for the connect timeout value */
                  load_conf();
                  global_update();
                  /* NOT REACHED */
                  break;
                  
         case 'h':
                  ec_usage();
                  break;

         case 'v':
                  printf("%s %s\n", GBL_PROGRAM, GBL_VERSION);
                  clean_exit(0);
                  break;

        /* Certificate and private key options */
         case 0:
		if (!strcmp(long_options[option_index].name, "certificate")) {
			GBL_OPTIONS->ssl_cert = strdup(optarg);	
		} else if (!strcmp(long_options[option_index].name, "private-key")) {
			GBL_OPTIONS->ssl_pkey = strdup(optarg);
		} else {
			fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM);
			clean_exit(-1);
		}

		break;

         case ':': // missing parameter
            fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM);
            clean_exit(-1);
         break;

         case '?': // unknown option
            fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM);
            clean_exit(-1);
         break;
      }
   }

   DEBUG_MSG("parse_options: options parsed");
   
   /* TARGET1 and TARGET2 parsing */
   if (argv[optind]) {
      GBL_OPTIONS->target1 = strdup(argv[optind]);
      DEBUG_MSG("TARGET1: %s", GBL_OPTIONS->target1);
      
      if (argv[optind+1]) {
         GBL_OPTIONS->target2 = strdup(argv[optind+1]);
         DEBUG_MSG("TARGET2: %s", GBL_OPTIONS->target2);
      }
   }

   /* create the list form the TARGET format (MAC/IPrange/PORTrange) */
   compile_display_filter();
   
   DEBUG_MSG("parse_options: targets parsed");
   
   /* check for other options */
   
   if (GBL_SNIFF->start == NULL)
      set_unified_sniff();
   
   if (GBL_OPTIONS->read && GBL_PCAP->filter)
      FATAL_ERROR("Cannot read from file and set a filter on interface");
   
   if (GBL_OPTIONS->read && GBL_SNIFF->type != SM_UNIFIED )
      FATAL_ERROR("You can read from a file ONLY in unified sniffing mode !");
   
   if (GBL_OPTIONS->mitm && GBL_SNIFF->type != SM_UNIFIED )
      FATAL_ERROR("You can't do mitm attacks in bridged sniffing mode !");

   if (GBL_SNIFF->type == SM_BRIDGED && GBL_PCAP->promisc == 0)
      FATAL_ERROR("During bridged sniffing the iface must be in promisc mode !");
   
   if (GBL_OPTIONS->quiet && GBL_UI->type != UI_TEXT)
      FATAL_ERROR("The quiet option is useful only with text only UI");
  
   if (GBL_OPTIONS->load_hosts && GBL_OPTIONS->save_hosts)
      FATAL_ERROR("Cannot load and save at the same time the hosts list...");
  
   if (GBL_OPTIONS->unoffensive && GBL_OPTIONS->mitm)
      FATAL_ERROR("Cannot use mitm attacks in unoffensive mode");
   
   if (GBL_OPTIONS->read && GBL_OPTIONS->mitm)
      FATAL_ERROR("Cannot use mitm attacks while reading from file");
   
   if (GBL_UI->init == NULL)
      FATAL_ERROR("Please select an User Interface");
     
   /* force text interface for only mitm attack */
  /* Do not select text interface for only MiTM mode 

   if (GBL_OPTIONS->only_mitm) {
      if (GBL_OPTIONS->mitm)
         select_text_interface();
      else
         FATAL_ERROR("Only mitm requires at least one mitm method");
   } */

   DEBUG_MSG("parse_options: options combination looks good");
   
   return;
}
Exemplo n.º 9
0
static void curses_stop_log(void)
{
   set_loglevel(LOG_STOP, "");
   curses_message("Logging was stopped.");
}
Exemplo n.º 10
0
/*
 * Main program
 */
int main(int argc, char *argv[])
{
	int i = 0;
	int ret = 0;
	struct sockaddr_in client_address;
	int client_sockfd = 0;
	pthread_t threads[MAX_THREADS];
			
	/* Parse commandline args */
	params = malloc(sizeof(cmd_params));
	ret = parse_cmd_args(&argc, argv);
	if (params->help)
	{
		display_help_page();
		exit(0);
	}
	if (params->version)
	{
		display_version_info();
		exit(0);
	}
	if (ret < 0)
	{
		if (ret == -2)
			logline(LOG_ERROR, "Error: Invalid port range specified (-p)");
		if (ret == -6)
			logline(LOG_ERROR, "Error: Invalid log level option specified (-l).");
		logline(LOG_ERROR, "Use the -h option if you need help.");
		exit(ret);
	}
	
	/* Set log level */
	switch (params->loglevel)
	{
		case 1: set_loglevel(LOG_ERROR); break;
		case 2: set_loglevel(LOG_INFO); break;
		case 3: set_loglevel(LOG_DEBUG); break;
		default: set_loglevel(LOG_ERROR);
	}

	/* Setup signal handler */
	signal(SIGINT, shutdown_server);
	signal(SIGTERM, shutdown_server);
	
	/* Show banner and stuff */
	show_gnu_banner();	

	/* Startup the server listener */
	if (startup_server() < 0)
	{
		logline(LOG_ERROR, "Error during server startup. Please consult debug log for details.");
		exit(-1);
	}
	
	/* Post ready message */
	logline(LOG_INFO, "Server listening on %s, port %d", params->ip, params->port);
	switch (params->loglevel)
	{
		case LOG_ERROR: logline(LOG_INFO, "Log level set to ERROR"); break;
		case LOG_INFO: logline(LOG_INFO, "Log level set to INFO"); break;
		case LOG_DEBUG: logline(LOG_INFO, "Log level set to DEBUG"); break;
		default: logline(LOG_INFO, "Unknown log level specified"); break;
	}
	
	/* Handle connections */
	while (1)
	{
		logline(LOG_INFO, "Waiting for incoming connection...");
		
		/* Accept a client connection */
		client_len = sizeof(client_address);
		client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address, (socklen_t *)&client_len);

		if (client_sockfd > 0)
		{
			logline(LOG_INFO, "Server accepted new connection on socket id %d", client_sockfd);
			
			/* A connection between a client and the server has been established.
			 * Now create a new thread and handover the client_sockfd
			 */
			pthread_mutex_lock(&curr_thread_count_mutex);
			if (curr_thread_count < MAX_THREADS)
			{
				/* Prepare client infos in handy structure */
				client_info *ci = (client_info *)malloc(sizeof(client_info));
				ci->sockfd = client_sockfd;
				ci->address = client_address;
				sprintf(ci->nickname, "anonymous_%d", client_sockfd);
				
				/* Add client info to linked list */
				llist_insert(&list_start, ci);
				llist_show(&list_start);
				
				/* Pass client info and invoke new thread */	
				ret = pthread_create(&threads[curr_thread_count],
					NULL,
					(void *)&proc_client, 
					(void *)&client_sockfd); /* only pass socket id ? */
			
				if (ret == 0)
				{
					pthread_detach(threads[curr_thread_count]);
					curr_thread_count++;
										
					/* Notify server and clients */
					logline(LOG_INFO, "User %s joined the chat.", ci->nickname);	
					logline(LOG_DEBUG, "main(): Connections used: %d of %d", curr_thread_count, MAX_THREADS);
				}
				else
				{
					free(ci);
					close(client_sockfd);
				}
			}
			else
			{
				logline(LOG_ERROR, "Max. connections reached. Connection limit is %d. Connection dropped.", MAX_THREADS);
				close(client_sockfd);
			}
			pthread_mutex_unlock(&curr_thread_count_mutex);
		}
		else
		{
			/* Connection could not be established. Post error and exit. */
			perror(strerror(errno));
			exit(-3);
		}
	}
	
	free(params);

	return 0;
}
Exemplo n.º 11
0
/*
 * App entry point. The place where everything starts...
 */
int main(int argc, char *argv[])
{
    int ret = 0;

    /* Initialize pseudo-random number generator */
    srand((unsigned)time(NULL));

    /* Allocate structures on heap */
    params = malloc(sizeof(cmd_params));

    /* Parse commandline args */
    ret = parse_cmd_args(&argc, argv);
    if (params->help)
    {
        display_help_page();
        return 0;
    }
    if (params->version)
    {
        display_version_info();
        return 0;
    }
    if (ret < 0)
    {
        switch (ret)
        {
        case -1:
            logline(LOG_ERROR, "Error: No server specified (use option -s)");
            break;
        case -2:
            logline(LOG_ERROR, "Error: Input file must be specified (use option -i)");
            break;
        case -3:
            logline(LOG_ERROR, "Error: Servers could not be interpreted (use option -s)");
            break;
        case -4:
            logline(LOG_ERROR, "Error: Invalid log level option specified (use option -l).");
            break;
        case -5:
            logline(LOG_ERROR, "Error: No domain specified (use -d option).");
            break;
        default:
            logline(LOG_ERROR, "Error: An unknown error occurred during parsing of command line args.");
        }

        logline(LOG_ERROR, "Use the -h option if you need help.");
        return ret;
    }

    /* Set log level */
    switch (params->loglevel)
    {
    case 1:
        set_loglevel(LOG_ERROR);
        break;
    case 2:
        set_loglevel(LOG_INFO);
        break;
    case 3:
        set_loglevel(LOG_DEBUG);
        break;
    default:
        set_loglevel(LOG_ERROR);
    }

    show_gnu_banner();
    printf("Executing %s Version %s\n", APP_NAME, APP_VERSION);
    printf("\n");

    /* Display help page if desired. Otherwise, do DNS lookups */
    ret = do_dns_lookups();
    if (ret < 0)
    {
        logline(LOG_ERROR, "Error: Could not perform DNS lookups. Errorcode: %d", ret);
    }

    /* Free memory on heap */
    free(params);

    return ret;
}
Exemplo n.º 12
0
void set_loglevel_info(char *arg)
{
	if (set_loglevel(LOG_INFO, arg) == -EFATAL)
		clean_exit(-EFATAL);
}
Exemplo n.º 13
0
void set_loglevel_packet(char *arg)
{
	if (set_loglevel(LOG_PACKET, arg) == -EFATAL)
		clean_exit(-EFATAL);
}
Exemplo n.º 14
0
Arquivo: jass.c Projeto: jait/jass
int main(int argc, char **argv)
{
    extern char *optarg;
    extern int optind, optopt;
    char *fname = NULL;
    char step = 0;
    int c;
    init();

    /* check args
     * -f: read sudokus from file (- for stdin)
     */
    while ((c = getopt(argc, argv, "f:vsh")) != EOF)
    {
        switch (c)
        {
        case 'f':
            fname = (char *) malloc(strlen(optarg)+1);
            if (fname == NULL)
                eprintf("malloc() failed:");

            strncpy(fname, optarg, strlen(optarg));
            fname[strlen(optarg)] = '\0';
            break;
        case 'v':
            set_loglevel(get_loglevel() + 1);
            break;
        case 'h':
            usage();
            exit(EXIT_SUCCESS);
        case 's':
            step = 1;
            break;
        default:
            break;
        }
    }

    /*
    if (step && verbose == 0)
        ++verbose;
    */

    if (fname != NULL)
    {
        FILE *file;
        char *line;
        int bufsize = X*Y + 2;
        if (strcmp(fname, "-") == 0)
            file = stdin;
        else
        {
            file = fopen(fname, "r");
            if (file == NULL)
                eprintf("Couldn't open file '%s':", fname);

        }
        line = (char *) malloc(bufsize);
        if (NULL == line)
            eprintf("malloc() failed:");

        while (fgets(line, bufsize, file) != NULL)
        {
            if (line[0] == '#')
                continue;

            init();
            parse_board(line);
            mode = MODE_NORMAL;
            if (step)
                mode = MODE_STEP;

            printf(line);
            solve();
        }
        if (fileno(file) != STDIN_FILENO)
            fclose(file);

        free(line);
        free(fname);
    }
    else
    {
        /* try if there was a puzzle as argument */
        if (argc > optind)
        {
            printf("Initializing the board ...\n");
            if (parse_board(argv[optind]) != X*Y)
            {
                eprintf("Error parsing the puzzle");
            }
            print_board();
            mode = MODE_NORMAL;
            if (step)
                mode = MODE_STEP;

            solve();
        }
        else
        {
            wprintf("Error: no puzzle(s) given");
            usage();
            exit(EXIT_FAILURE);
        }
    }

    exit(EXIT_SUCCESS);
}
Exemplo n.º 15
0
void gtkui_stop_log(void)
{
   set_loglevel(LOG_STOP, "");
   gtkui_message("Logging was stopped.");
}
Exemplo n.º 16
0
__attribute__((section(".text.start"), noreturn)) void _start()
{
	static const TCHAR fontPath[] = _T("") SYS_PATH "/" FONT_NAME;
	void *fontBuf;
	UINT btr, br;
	int r;
	FIL f;

	// Enable TMIO IRQ
	*(volatile uint32_t *)0x10001000 = 0x00010000;

	preloadStringsA();

	
	if (!FSInit()) {
		DrawString(BOT_SCREEN, strings[STR_FAILED],
			BOT_SCREEN_WIDTH / 2, SCREEN_HEIGHT - FONT_HEIGHT, RED, BLACK);
		while (1);
	}

	
	set_loglevel(ll_info);
	log(ll_info, "Initializing rxTools...");
	

	setConsole();

	fontIsLoaded = 0;
	r = f_open(&f, fontPath, FA_READ);
	if (r == FR_OK) {
		btr = f_size(&f);
		fontBuf = __builtin_alloca(btr);
		r = f_read(&f, fontBuf, btr, &br);
		if (r == FR_OK)
			fontIsLoaded = 1;

		f_close(&f);
		fontaddr = fontBuf;
	}

	if (fontIsLoaded)
		preloadStringsU();
	else
		warn(L"Failed to load " FONT_NAME ": %d\n", r);

	if (getMpInfo() == MPINFO_KTR)
    {
        r = initN3DSKeys();
        if (r != FR_OK) {
            warn(L"Failed to load keys for N3DS\n"
            "  Code: %d\n"
            "  RxMode will not boot. Please\n"
            "  include key_0x16.bin and\n"
            "  key_0x1B.bin at the root of your\n"
            "  SD card.\n", r);
            InputWait();
            goto postinstall;
        }
    }


	install();
	postinstall:
	readCfg();

	log(ll_info, "Done...");

	r = loadStrings();
	if (r)
		warn(L"Failed to load strings: %d\n", r);

	drawTop();

	//Default boot check
	if (cfgs[CFG_DEFAULT].val.i && HID_STATE & BUTTON_L1)
		{
			if(cfgs[CFG_DEFAULT].val.i == 3) PastaMode();
			else rxMode(cfgs[CFG_DEFAULT].val.i - 1);
		}

	if (sysver < 7) {
		r = initKeyX();
		if (r != FR_OK)
			warn(L"Failed to load key X for slot 0x25\n"
				"  Code: %d\n"
				"  If your firmware version is less\n"
				"  than 7.X, some titles decryption\n"
				"  will fail, and some EmuNANDs\n"
				"  will not boot.\n", r);
	}

	if (warned) {
		warn(strings[STR_PRESS_BUTTON_ACTION],
			strings[STR_BUTTON_A], strings[STR_CONTINUE]);
		WaitForButton(BUTTON_A);
	}

	OpenAnimation();
	mainLoop();
}
Exemplo n.º 17
0
int main(int argc, char **argv) {

	disable_file_log();
	enable_shell_log();
	set_loglevel(LOG_NOTICE);

	progname = malloc((10*sizeof(char))+1);
	progname = strdup("433-control");

	options = malloc(255*sizeof(struct options_t));

	int sockfd = 0;
    char *recvBuff = NULL;
	char *message;
	steps_t steps = WELCOME;

	char device[50];
	char location[50];
	char state[10] = {'\0'};
	struct conf_locations_t *slocation = NULL;
	struct conf_devices_t *sdevice = NULL;
	
	char server[16] = "127.0.0.1";
	unsigned short port = PORT;
	
	JsonNode *json = json_mkobject();
	JsonNode *config = json_mkobject();
	JsonNode *code = json_mkobject();

	/* Define all CLI arguments of this program */
	addOption(&options, 'h', "help", no_value, 0, NULL);
	addOption(&options, 'v', "version", no_value, 0, NULL);
	addOption(&options, 'l', "location", has_value, 0, NULL);
	addOption(&options, 'd', "device", has_value, 0,  NULL);
	addOption(&options, 's', "state", has_value, 0,  NULL);
	addOption(&options, 'S', "server", has_value, 0, "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$");
	addOption(&options, 'P', "port", has_value, 0, "[0-9]{1,4}");

	/* Store all CLI arguments for later usage
	   and also check if the CLI arguments where
	   used correctly by the user. This will also
	   fill all necessary values in the options struct */
	while(1) {
		int c;
		c = getOptions(&options, argc, argv, 1);
		if(c == -1)
			break;
		switch(c) {
			case 'h':
				printf("\t -h --help\t\t\tdisplay this message\n");
				printf("\t -v --version\t\t\tdisplay version\n");
				printf("\t -S --server=%s\t\tconnect to server address\n", server);
				printf("\t -P --port=%d\t\t\tconnect to server port\n", port);
				printf("\t -l --location=location\t\tthe location in which the device resides\n");
				printf("\t -d --device=device\t\tthe device that you want to control\n");
				printf("\t -s --state=state\t\tthe new state of the device\n");
				exit(EXIT_SUCCESS);
			break;
			case 'v':
				printf("%s %s\n", progname, "1.0");
				exit(EXIT_SUCCESS);
			break;
			case 'l':
				strcpy(location, optarg);
			break;
			case 'd':
				strcpy(device, optarg);
			break;
			case 's':
				strcpy(state, optarg);
			break;
			case 'S':
				strcpy(server, optarg);
			break;
			case 'P':
				port = (unsigned short)atoi(optarg);
			break;			
			default:
				printf("Usage: %s -l location -d device\n", progname);
				exit(EXIT_SUCCESS);
			break;
		}
	}

	if(strlen(location) == 0 || strlen(device) == 0) {
		printf("Usage: %s -l location -d device\n", progname);
		exit(EXIT_SUCCESS);
	}

	if((sockfd = connect_to_server(strdup(server), port)) == -1) {
		logprintf(LOG_ERR, "could not connect to 433-daemon");
		exit(EXIT_FAILURE);
	}

	/* Initialize peripheral modules */
	hw_init();

	while(1) {
		if(steps > WELCOME) {
			/* Clear the receive buffer again and read the welcome message */
			if(steps == REQUEST) {
				if((recvBuff = socket_read_big(sockfd)) != NULL) {
					json = json_decode(recvBuff);
					json_find_string(json, "message", &message);
				} else {
					goto close;
				}
			} else {
				if((recvBuff = socket_read(sockfd)) != NULL) {
					json = json_decode(recvBuff);
					json_find_string(json, "message", &message);
				} else {
					goto close;
				}
			}
			usleep(250);
		}
		switch(steps) {
			case WELCOME:
				socket_write(sockfd, "{\"message\":\"client controller\"}");
				steps=IDENTIFY;
			break;
			case IDENTIFY:
				if(strcmp(message, "accept client") == 0) {
					steps=REQUEST;
				}
				if(strcmp(message, "reject client") == 0) {
					steps=REJECT;
				}
			case REQUEST:
				socket_write(sockfd, "{\"message\":\"request config\"}");
				steps=CONFIG;
			break;
			case CONFIG:
				if((config = json_find_member(json, "config")) != NULL) {
					config_parse(config);
					if(config_get_location(location, &slocation) == 0) {
						if(config_get_device(location, device, &sdevice) == 0) {
							json_delete(json);

							json = json_mkobject();
							code = json_mkobject();

							json_append_member(code, "location", json_mkstring(location));
							json_append_member(code, "device", json_mkstring(device));

							if(strlen(state) > 0) {
								if(config_valid_state(location, device, state) == 0) {
									json_append_member(code, "state", json_mkstring(state));
								} else {
									logprintf(LOG_ERR, "\"%s\" is an invalid state for device \"%s\"", state, device);
									goto close;
								}
							}

							json_append_member(json, "message", json_mkstring("send"));
							json_append_member(json, "code", code);

							socket_write(sockfd, json_stringify(json, NULL));

						} else {
							logprintf(LOG_ERR, "the device \"%s\" does not exist", device);
							goto close;
						}
					} else {
						logprintf(LOG_ERR, "the location \"%s\" does not exist", location);
						goto close;
					}
				}
				goto close;
			break;
			case REJECT:
			default:
				goto close;
			break;
		}
	}
close:
	json_delete(json);
	socket_close(sockfd);
return EXIT_SUCCESS;
}