Exemplo n.º 1
0
/*
* @arg in_array: array to search in
* @arg out_array: array to write to
* @arg out_file_name: file to write to
* @arg cur_pos: pointer to current position in in_array
* @arg cur_pos_out: pointer to current position in out_array
* @arg print: boolean to check if we have to print or not
* @arg file_size: size of in_array
* @return: none
*/
void sync_word_search(unsigned char *in_array, unsigned char *out_array, char *out_file_name, int *cur_pos, int *cur_pos_out, char *print, int file_size){
	unsigned char first, second, third;
	char first_time = 1;

	//First check for sync word
	first = in_array[*cur_pos];
	second = in_array[(*cur_pos) + 1];
	third = in_array[(*cur_pos) + 2];
	(*cur_pos) += 3;
	while(!((first + second == 0) && (second + third == 1))){
		if(*cur_pos > file_size){
			write_out_file(out_array, in_array, out_file_name, *cur_pos_out);
		}
		if (first_time){
			if (*print){
				out_array[*cur_pos_out] = first;
				out_array[(*cur_pos_out) + 1] = second;
				(*cur_pos_out) += 2;
			}
			first_time = 0;
		}
		if(*print){
			//Write RBSP to the output
			out_array[*cur_pos_out] = third;
			++(*cur_pos_out);
		}
		//Roll the list over
		first = second;
		second = third;
		//Try to find sync word
		third = in_array[*cur_pos];
		++(*cur_pos);
	}
}
Exemplo n.º 2
0
int
main(int argc, char **argv)
{
    GError *error = NULL;
    int retval = EXIT_SUCCESS;
    EVP_PKEY *pubkey;

    if (!process_arguments(&argc, &argv, &error)) {
        retval = handle_error(error);
        g_clear_error(&error);
    } else if ((pubkey = read_public_key(option_key_file, &error)) == NULL) {
        retval = handle_error(error);
        g_clear_error(&error);
    } else {
        FILE *infile = fopen(option_data_file, "rb");

        if (infile == NULL) {
            fprintf(stderr, "%s: %s\n", option_data_file, strerror(errno));
            retval = EXIT_IO_ERROR;
        } else {
            uint8_t hash[SHA256_DIGEST_LENGTH];
            uint8_t signature[SIGNATURE_SIZE];

            if (fread(signature, 1, sizeof(signature), infile) !=
                sizeof(signature)) {
                if (ferror(infile)) {
                    fprintf(
                        stderr, "%s: %s\n", option_data_file, strerror(errno));
                    retval = EXIT_IO_ERROR;
                } else {
                    fprintf(stderr,
                            "%s: File too short for signature\n",
                            option_data_file);
                    retval = EXIT_FORMAT_ERROR;
                }
            } else if (!hash_stream(infile, hash, &error) ||
                       !verify_signature(hash, signature, pubkey, &error)) {
                retval = handle_error(error);
                g_clear_error(&error);
            } else if (option_out_file &&
                       !write_out_file(infile, option_out_file, &error)) {
                retval = handle_error(error);
                g_clear_error(&error);
            }

            fclose(infile);
        }

        EVP_PKEY_free(pubkey);
    }

    return retval;
}