void script_command_parser::add_script_command(std::string& input) {
    std::transform(input.begin(), input.end(), input.begin(), ::tolower);

    std::regex check_binary(".*b:.+?\\s(.+?)\\s.+");
    std::smatch matches;
    if (std::regex_match(input, matches, check_binary)) {
        if (isscript_command((std::string)matches[1], script_command::Type::LEFT_RIGHT)) { return; }
        script_command command = script_command(matches[1], script_command::Type::LEFT_RIGHT);
        commands.push_back(command);
    }
    else {
        std::regex check_unary(".*u:(.+)?\\s.+");
        if (std::regex_match(input, matches, check_unary)) {
            if (isscript_command((std::string)matches[1], script_command::Type::RIGHT)) { return; }
            script_command command = script_command(matches[1], script_command::Type::RIGHT);
            commands.push_back(command);
        } 
        else {
            std::regex check_null(".*n:(.+)");
            if (std::regex_match(input, matches, check_null)) {
                if (isscript_command((std::string)matches[1], script_command::Type::NONE)) { return; }
                script_command command = script_command(matches[1], script_command::Type::NONE);
                commands.push_back(command);
            }
        }
    }
}
Beispiel #2
0
/*
 * Extra a token from input.
 * If TOKEN_ERROR, something bad has happened in the attempt to do so.
 * Otherwise, this returns a valid token (possibly end of input).
 */
static enum token
tokenise(const char **v, char *buf, enum token lasttok)
{
	size_t		i, sz;

	/* Short-circuit this case. */
	if ('\0' == **v)
		return(TOKEN_END);

	/* Look for token in our predefined inputs. */
	for (i = 0; i < TOK__MAX; i++)
		if ('\0' != toks[i].key && **v == toks[i].key) {
			switch (toks[i].arity) {
			case (ARITY_NONE):
				(*v)++;
				return((enum token)i);
			case (ARITY_ONE):
				if ( ! check_unary(lasttok))
					continue;
				break;
			case (ARITY_TWO):
				if ( ! check_binary(lasttok))
					continue;
				break;
			}
			(*v)++;
			return((enum token)i);
		}

	/* See if we're a real number or identifier. */
	if (isdigit((int)**v) || '.' == **v) {
		sz = 0;
		for ( ; isdigit((int)**v) || '.' == **v; (*v)++) {
			assert(sz < BUFSZ);
			buf[sz++] = **v;
		}
		buf[sz] = '\0';
		return(TOKEN_NUMBER);
	} else if (isalpha((int)**v)) {
		sz = 0;
		for ( ; isalpha((int)**v); (*v)++) {
			assert(sz < BUFSZ);
			buf[sz++] = **v;
		}
		buf[sz] = '\0';
		if (0 == strcmp(buf, "sqrt"))
			return(TOKEN_SQRT);
		else if (0 == strcmp(buf, "exp"))
			return(TOKEN_EXPF);
	} 

	/* Eh... */
	return(TOKEN_ERROR);
}
Beispiel #3
0
expression make_binary(location loc, int binop, expression e1, expression e2)
{
  expression result = CAST(expression, newkind_binary(parse_region, binop, loc, e1, e2));

  result->type = check_binary(binop, e1, e2);
  if (result->type != error_type)
    {
      result->cst = fold_binary(result->type, result);
    }

  /* XXX: The warn_parentheses stuff (and a <= b <= c) */
#if 0
  unsigned_conversion_warning (result, arg1);
  unsigned_conversion_warning (result, arg2);
  overflow_warning (result);
#endif

  return result;
}
Beispiel #4
0
		void add_reserved_word(std::string input_) {
			std::regex check_binary(".*b:.+?\\s(.+?)\\s.+");
			std::smatch matches;
			if (std::regex_match(input_, matches, check_binary)) {
				reserved_words.insert(matches[1]);
			}
			else {
				std::regex check_unary(".*u:(.+)?\\s.+");
				if (std::regex_match(input_, matches, check_unary)) {
					reserved_words.insert(matches[1]);
				}
				else {
					std::regex check_null(".*n:(.+)");
					if (std::regex_match(input_, matches, check_null)) {
						reserved_words.insert(matches[1]);
					}
				}
			}
            script_command_parser::add_script_command(input_);
		}
Beispiel #5
0
int
pocl_binary_check_binary(cl_device_id device, const unsigned char *binary)
{
  return (check_binary(device, binary) != NULL);
}
Beispiel #6
0
int main(int argc, char **argv)
{
	uid_t uid, euid;
	pid_t pid, parent_pid;
	gid_t gid;
	int pipe_fds[2];
	int err;

	parent_pid = getpid ();

	/* get real user and group ids, effective user id */
	uid = getuid ();
	gid = getgid ();
	euid = geteuid ();

	/* are we running suid root? */
	if (uid != 0) {
		if (euid != 0) {
			fprintf (stderr, "jackstart: not running suid root, can't use capabilities\n");
			fprintf (stderr, "    (currently running with uid=%d and euid=%d),\n", uid, euid);
			fprintf (stderr, "    make jackstart suid root or start jackd directly\n\n");
		}
	}
	/* see if we can get the required capabilities */
	if (check_capabilities () == 0) {
		size_t size;
		cap_t cap = cap_init();
		capgetp(0, cap);
		fprintf (stderr, "jackstart: cannot get realtime capabilities, current capabilities are:\n");
		fprintf (stderr, "           %s\n", cap_to_text(cap, &size));
		fprintf (stderr, "    probably running under a kernel with capabilities disabled,\n");
		fprintf (stderr, "    a suitable kernel would have printed something like \"=eip\"\n\n");
	}

	/* check the executable, owner, permissions, md5 checksum */
	if (check_binary(jackd_bin_path)) {
		exit(1);
	}

	/* set process group to current pid */
	if (setpgid (0, getpid())) {
		fprintf (stderr, "jackstart: failed to set process group: %s\n", 
			 strerror(errno));
		exit (1);
	}

	/* create pipe to synchronize with jackd */
	if (pipe (pipe_fds)) {
		fprintf (stderr, "jackstart: could not create pipe: %s\n",
			 strerror(errno));
		exit (1);
	}

	/* make sure the file descriptors are the right ones,
	   otherwise dup them, this is to make sure that both
	   jackstart and jackd use the same fds
	*/
	if (pipe_fds[0] != PIPE_READ_FD) {
		if (dup2 (pipe_fds[0], PIPE_READ_FD) != PIPE_READ_FD) {
			fprintf (stderr, "jackstart: could not dup pipe read file descriptor: %s\n",
				 strerror(errno));
			exit (1);
		}
	}
	if (pipe_fds[1] != PIPE_WRITE_FD) {
		if (dup2(pipe_fds[1], PIPE_WRITE_FD)!=PIPE_WRITE_FD) {
			fprintf (stderr, "jackstart: could not dup pipe write file descriptor: %s\n",
				 strerror(errno));
			exit (1);
		}
	}
	/* fork off a child to wait for jackd to start */
	fflush(NULL);
	pid = fork();
	if (pid == -1) {
		fprintf (stderr, "jackstart: fork failed\n");
		exit (1);
	}
	if (pid) {
		/* mother process: drops privileges, execs jackd */
		close(PIPE_READ_FD);

		/* get rid of any supplemental groups */
		if (!getuid () && setgroups (0, 0)) {
			fprintf (stderr, "jackstart: setgroups failed: %s\n", strerror(errno));
			exit (1);
		}

		/* set gid and uid */
		setregid(gid, gid);
		setreuid(uid, uid);
		execvp(jackd_bin_path, argv);
	
		/* we could not start jackd, clean up and exit */
		fprintf(stderr, "jackstart: unable to execute %s: %s\n", jackd_bin_path, strerror(errno));
		close (PIPE_WRITE_FD);
		wait (&err);
		exit (1);
	} else {
		/* child process: grants privileges to jackd */
		close(PIPE_WRITE_FD);

		/* wait for jackd to start */
		while (1) {
		  	int ret;
			char c;

			/* picking up pipe closure is a tricky business. 
			   this seems to work as well as anything else.
			*/

			ret = read(PIPE_READ_FD, &c, 1);
			fprintf (stderr, "back from read, ret = %d errno == %s\n", ret, strerror (errno));
			if (ret == 1) {
			  break;
			} else if (errno != EINTR) {
			  break;
			}
		}

		/* set privileges on jackd process */
		give_capabilities (parent_pid);
	}
	exit (0);
}
Beispiel #7
0
int check_types_in_expr(ast_node root) {
  symhashtable_t *hash = NULL;
  symnode_t *node = NULL;
  ast_node anode = NULL;

  switch (root->node_type) {
    case OP_ASSIGN_N:
    //check_binary(root);
    check_assignment(root);
    break;

    case OP_PLUS_N:
    check_binary(root);
    break;

    case OP_MINUS_N:
    check_binary(root);
    break;

    case OP_NEG_N:
    check_unary(root);
    break;

    case OP_TIMES_N:
        check_binary(root);
    break;

    case OP_DIVIDE_N:
        check_binary(root);
    break;

    case OP_EQUALS_N:
        check_binary(root);
    break;

    case OP_INCREMENT_N:
        check_unary(root);
    break;

    case OP_DECREMENT_N:
        check_unary(root);
    break;

    case OP_MODULUS_N:
        check_binary(root);
    break;

    case OP_LESS_THAN_N:
        check_binary(root);
    break;

    case OP_LESS_EQUAL_N:
        check_binary(root);
    break;

    case OP_GREATER_THAN_N:
        check_binary(root);
    break;

    case OP_GREATER_EQUAL_N:
        check_binary(root);
    break;

    case OP_NOT_EQUAL_N:
        check_binary(root);
    break;

    case OP_AND_N:
        check_binary(root);
    break;

    case OP_OR_N:
        check_binary(root);
    break;

    case OP_NOT_N:
        check_unary(root);
    break;

    case RETURN_N:
        check_unary(root);
    break;

    default:
      // printf("at default of switch\n");
      break;


  }

  /* Recurse on each child of the subtree root, with a depth one
     greater than the root's depth. */
  ast_node child;
  for (child = root->left_child; child != NULL; child = child->right_sibling)
    check_types_in_expr(child);
  return 0;
}
Beispiel #8
0
int main (int argc, char *argv[], char *arge[]) {
	if (argc < 2) {
		print_usage();
		return 0;
	}
	
	// check if argv[1] is a binary string
	if (!check_binary(argv[1])) {
		fprintf(stderr, "%s is not a binary string\n", argv[1]);
		return -1;
	}
	
	// init rand()
	srand(time(NULL));
	
	// copy the argv[1] message
	// calculate final message length
	// so we don't need to realloc it everytime
	int len = strlen(argv[1]);
    int parity_len = 2;
    for (int i = 0; i<=len; i++) {
        //printf("t:%d - %s\n",t,power_of_2(t+1) ? "YES" : "NO");
        parity_len++;
        if (power_of_2(parity_len)) {
            parity_len++;
        }
    }
    printf("F2^%d -> F2^%d\n",len, parity_len-1);
	char *message = (char*)malloc(parity_len*sizeof(char));
	strncpy(message, argv[1], len+1);
	
	// print the raw binary message
	printf("[•] encoding   '%s' (len:%d)\n",message,len);
	
	// then add spaces for parity bits
	// and calculate them
	add_parity_space(message);
	calculate_parity(message);
	printf("[•] sent       '%s' (len:%d)\n",message,(int)strlen(message));
	
	// copy the message and alter one bit
	char *bad = (char*)malloc(strlen(message)*sizeof(char));
	strncpy(bad, message, strlen(message));
	alter_a_bit(bad);
	
	// print altered message
	printf("[•] recieve    '%s' (len:%d)\n",bad,(int)strlen(bad));
	
	// check parity to correct the altered message
	int *bad_bits = bad_parity(bad);
	int i = 0, sum=0;
	printf("[?] corrupted parity bits :");
	while (bad_bits[i] != -1) {
		sum+=bad_bits[i]+1;
		printf(" %d",bad_bits[i]+1);
		i++;
	}
	printf("\n");
	printf("[?] fixed data bit at index %d\n",sum);
	free(bad_bits);
	
	// correct if necessary
	if (sum>0) {
		bad[sum-1] = (bad[sum-1] == '0') ? '1' : '0';
		printf("[•] corrected  '%s' (len:%d)\n",bad,(int)strlen(bad));
	}else {
		printf("[•] already_ok '%s' (len:%d)\n",bad,(int)strlen(bad));
	}
	
	// remove the parity bits
	remove_parity_space(bad);
	printf("[•] decoding   '%s' (len:%d)\n",bad,(int)strlen(bad));
	
	// compare with original message
	printf("[•] %s\n",strncmp(argv[1],bad,len) == 0 ? "message successfully decoded" : "failed to decode message");
    
    //printf(" in: '%s'\n",argv[1]);
    //printf("out: '%s'\n",bad);
	
	// free memory space
	free(message);
	free(bad);
	
	return 0;
}