Beispiel #1
0
//-----------------------------------------------------------------------------
// Reads arbitrary binary data from the file fp.
//  fp is positioned at the start of the file.
//
char *sp_load_binary_file(
    const axutil_env_t *env,
    char               *header_blob,
    axutil_stream_t    *st,
    int                *len)
{
    *len                            = 0;
    char                 *bin_data  = NULL;
    TmpStore             *ts        = NULL;
    axutil_linked_list_t *ll        = axutil_linked_list_create(env);

    // pre-pend header-blob (if any) in front of the remaining data
    if (header_blob)
    {
    	int hdr_size = strlen(header_blob);
    	if ( (hdr_size) > SP_IMG_BUF_SIZE)
    	{
    		// failsafe - should never happen.
    	    axutil_linked_list_free(ll, env);
    		return NULL;
    	}

    	ts = (TmpStore *)AXIS2_MALLOC(env->allocator, sizeof(TmpStore));
    	memcpy(ts->buf, header_blob, hdr_size);
    	ts->size = hdr_size;
    	*len    += hdr_size;
    	axutil_linked_list_add (ll, env, (void *)ts);
    }

    int n_read  = 0;
    while ( 1 )
    {
        ts = (TmpStore *)AXIS2_MALLOC(env->allocator, sizeof(TmpStore));
        n_read = axutil_stream_read(st, env, ts->buf, SP_IMG_BUF_SIZE);
        if (0 == n_read) 
        {
            AXIS2_FREE(env->allocator, ts);
            break;
        }

        ts->size = n_read;
        *len    += n_read;
        axutil_linked_list_add (ll, env, (void *)ts);
    }

    bin_data = compose_buffer(env, *len, ll);
    axutil_linked_list_free(ll, env);
    return bin_data;
}
Beispiel #2
0
//-----------------------------------------------------------------------------
// Reads a binary image from the file fp.
// The file should be composed of HTTP mime messages as received in the form of
// an HTTP response. fp is already positioned at the start of the image.
// The boundary is given by boundId.
//
char * rp_read_bin_mime_image(
    const axutil_env_t * env,
    FILE *fp,
    const char *boundId,
    int *len)
{
    char     *image_binary   = NULL;

    int      actual_filled   = 0;

    TmpStore             *ts = NULL;
    axutil_linked_list_t *ll = axutil_linked_list_create(env);

    *len = 0;

    Rp_cb_ctx fill_ctx;
    init_rp_cb_ctx(env, &fill_ctx);
    fill_ctx.fp    = fp;
    fill_ctx.bound = boundId;

    while (!fill_ctx.done)
    {
        ts = (TmpStore *)AXIS2_MALLOC(env->allocator, sizeof(TmpStore));
        actual_filled = rp_fill_buff_CB(ts->buf, SP_IMG_BUF_SIZE, &fill_ctx);
        if (0 == actual_filled)
        {
            AXIS2_FREE(env->allocator, ts);
            break;
        }
        ts->size = actual_filled;
        *len    += actual_filled;
        axutil_linked_list_add (ll, env, (void *)ts);
    }

    image_binary = compose_buffer(env, *len, ll);
    axutil_linked_list_free(ll, env);
    return image_binary;
}
void init(int argc, char** argv)
{
    int c;
    int digit_optind = 0;
    int aopt = 0, bopt = 0;
    char *copt = 0, *dopt = 0;
    struct option long_options[] = {
            {"trace", 0, 0, 0},
            {"help", 0, 0, 0},
            {"brute", 0, 0, 0},
            {"swap", 0, 0, 0},
            {NULL, 0, NULL, 0}
    };

    int option_index = 0;
    char* buffer;

    g_fichier = argv[1];
    recup_extension();

    g_pointeur_fonction_generer_brute_rec = generer_brute_rec;

    while ((c = getopt_long(argc, argv, "a:mMcs:t:l",
                            long_options, &option_index)) != -1)
    {
        int this_option_optind = optind ? optind : 1;
        switch(c)
        {
            case 0:
                if(strcmp("trace", long_options[option_index].name) == 0)
                {
                    g_trace = 1;
                    if (g_brute == 1)
                        g_pointeur_fonction_generer_brute_rec = generer_brute_rec_trace;
                    else
                        g_pointeur_fonction_generer_brute_rec = generer_brute_rec_trace;
                }
                else if(strcmp("help", long_options[option_index].name) == 0)
                    help();
                else if(strcmp("brute", long_options[option_index].name) == 0)
                {
                    g_brute = 1;
                    if (g_trace == 1)
                        g_pointeur_fonction_generer_brute_rec = generer_brute_rec_trace;
                    else
                        g_pointeur_fonction_generer_brute_rec = generer_brute_rec;
                }
                else if(strcmp("swap", long_options[option_index].name) == 0)
                    help();
                else
                {

                }
                printf("\n");
                break;
            case 'r':
                compose_buffer(optarg);
                break;
            case 't':
                g_taille = atoi(optarg);
                break;
            case 'l':
                    g_repertoire = malloc(strlen(optarg) * sizeof(char));
                    strcpy(g_repertoire, optarg);
                break;
            case 'd':
                printf("%s\n", optarg);
                break;
            case 'p':
                    setpriority(PRIO_PROCESS, getpid(), atoi(optarg));
                break;
        }
    }

    recup_extension();
    //debug();

    if(g_brute == 1)
        generer_brute(g_taille);
    else
        generer_swap(g_repertoire, strlen(g_repertoire), g_taille);
}