// ---------------------------------------------------------------------------
//
// ------------
void bXMapTopoCheck::open(int* flags){
    bStdXMap::open(flags);
bGenericType*	tp;
    for(long i=1;i<=_gapp->typesMgr()->count();i++){
        tp=_gapp->typesMgr()->get(i);
        _types.add(&tp);
    }
    _prm.activated=false;
    read_p();
}
// ---------------------------------------------------------------------------
//
// ------------
void bXMapNetClean::init_data(){
    _cfg_prm.nodes=&_nodes;
    _cfg_prm.edges=&_edges;
    _cfg_prm.tnod=NULL;
    _cfg_prm.stnod=1;
    _cfg_prm.name[0]=0;
    _cfg_prm.tbdg=NULL;
    _cfg_prm.stbdg=2;
    _cfg_prm.dnod=0;
    _cfg_prm.dbdg=0;
    _cfg_prm.autoclean=false;
    
    _act_prm.create_nodes=true;
    _act_prm.cut_edges=true;
    _act_prm.join_on_nodes=true;
    _act_prm.join_on_edges=false;
    _act_prm.check_nodes=true;
    _act_prm.check_edges=true;
    
bGenericType*	tp;
    for(long i=1;i<=_gapp->typesMgr()->count();i++){
        tp=_gapp->typesMgr()->get(i);
        if(tp->kind()!=kBaseKindPoint){
            tp=NULL;
        }
        _nodes.add(&tp);
        if(_cfg_prm.tnod==NULL){
            _cfg_prm.tnod=tp;
            _cfg_prm.tbdg=tp;
        }
    }
    for(long i=1;i<=_gapp->typesMgr()->count();i++){
        tp=_gapp->typesMgr()->get(i);
        if(tp->kind()!=kBaseKindPolyline){
            tp=NULL;
        }
        _edges.add(&tp);
    }
    read_p();
}
main()
{
    int             i;

    read_p();               /* Read m */
    generate_gf();          /* Construct the Galois Field GF(2**m) */
    gen_poly();             /* Compute the generator polynomial of BCH code */

    /* Randomly generate DATA */
    seed = 131073;
    srandom(seed);
    for (i = 0; i < k; i++)
        data[i] = ( random() & 65536 ) >> 16;

    encode_bch();           /* encode data */

    /*
     * recd[] are the coefficients of c(x) = x**(length-k)*data(x) + b(x)
     */
    for (i = 0; i < length - k; i++)
        recd[i] = bb[i];
    for (i = 0; i < k; i++)
        recd[i + length - k] = data[i];
    printf("Code polynomial:\nc(x) = ");
    for (i = 0; i < length; i++) {
        printf("%1d", recd[i]);
        if (i && ((i % 50) == 0))
            printf("\n");
    }
    printf("\n");

    printf("Enter the number of errors:\n");
    scanf("%d", &numerr);	/* CHANNEL errors */
    printf("Enter error locations (integers between");
    printf(" 0 and %d): ", length-1);
    /*
     * recd[] are the coefficients of r(x) = c(x) + e(x)
     */
    for (i = 0; i < numerr; i++)
        scanf("%d", &errpos[i]);
    if (numerr)
        for (i = 0; i < numerr; i++)
            recd[errpos[i]] ^= 1;
    printf("r(x) = ");
    for (i = 0; i < length; i++) {
        printf("%1d", recd[i]);
        if (i && ((i % 50) == 0))
            printf("\n");
    }
    printf("\n");

    decode_bch();             /* DECODE received codeword recv[] */

    /*
     * print out original and decoded data
     */
    printf("Results:\n");
    printf("original data  = ");
    for (i = 0; i < k; i++) {
        printf("%1d", data[i]);
        if (i && ((i % 50) == 0))
            printf("\n");
    }
    printf("\nrecovered data = ");
    for (i = length - k; i < length; i++) {
        printf("%1d", recd[i]);
        if ((i-length+k) && (((i-length+k) % 50) == 0))
            printf("\n");
    }
    printf("\n");

    /*
     * DECODING ERRORS? we compare only the data portion
     */
    for (i = length - k; i < length; i++)
        if (data[i - length + k] != recd[i])
            decerror++;
    if (decerror)
        printf("There were %d decoding errors in message positions\n", decerror);
    else
        printf("Succesful decoding\n");
}
Esempio n. 4
0
/** \brief Initialize a ZipFile object from an input file.
 *
 * This constructor opens the named zip file. If the zip "file" is
 * embedded in a file that contains other data, e.g. a binary
 * program, the offset of the zip file start and end must be
 * specified.
 *
 * If the file cannot be opened or the Zip directory cannot
 * be read, then the constructor throws an exception.
 *
 * \param[in] filename  The filename of the zip file to open.
 * \param[in] s_off  Offset relative to the start of the file, that
 *                   indicates the beginning of the zip data in the file.
 * \param[in] e_off  Offset relative to the end of the file, that
 *                   indicates the end of the zip data in the file.
 *                   The offset is a positive number, even though the
 *                   offset is towards the beginning of the file.
 */
ZipFile::ZipFile(std::string const& filename, offset_t s_off, offset_t e_off)
    : FileCollection(filename)
    , m_vs(s_off, e_off)
{
    std::ifstream zipfile(m_filename, std::ios::in | std::ios::binary);
    if(!zipfile)
    {
        throw IOException("Error opening Zip archive file for reading in binary mode.");
    }

    // Find and read the End of Central Directory.
    ZipEndOfCentralDirectory eocd;
    {
        BackBuffer bb(zipfile, m_vs);
        ssize_t read_p(-1);
        for(;;)
        {
            if(read_p < 0)
            {
                if(!bb.readChunk(read_p))
                {
                    throw FileCollectionException("Unable to find zip structure: End-of-central-directory");
                }
            }
            // Note: this is pretty fast since it reads from 'bb' which
            //       caches the buffer the readChunk() function just read.
            //
            if(eocd.read(bb, read_p))
            {
                // found it!
                break;
            }
            --read_p;
        }
    }

    // Position read pointer to start of first entry in central dir.
    m_vs.vseekg(zipfile, eocd.getOffset(), std::ios::beg);

    // TBD -- is that ", 0" still necessary? (With VC2012 and better)
    // Give the second argument in the next line to keep Visual C++ quiet
    //m_entries.resize(eocd.totalCount(), 0);
    m_entries.resize(eocd.getCount());

    size_t const max_entry(eocd.getCount());
    for(size_t entry_num(0); entry_num < max_entry; ++entry_num)
    {
        m_entries[entry_num] = FileEntry::pointer_t(new ZipCentralDirectoryEntry);
        m_entries[entry_num].get()->read(zipfile);
    }

    // Consistency check #1:
    // The virtual seeker position is exactly the start offset of the
    // Central Directory plus the Central Directory size
    //
    offset_t const pos(m_vs.vtellg(zipfile));
    if(static_cast<offset_t>(eocd.getOffset() + eocd.getCentralDirectorySize()) != pos)
    {
        throw FileCollectionException("Zip file consistency problem. Zip file data fields are inconsistent with zip file layout.");
    }

    // Consistency check #2:
    // Are local headers consistent with CD headers?
    //
    for(auto it = m_entries.begin(); it != m_entries.end(); ++it)
    {
        /** \TODO
         * Make sure the entry offset is properly defined by ZipCentralDirectoryEntry.
         * Also the isEqual() is a quite advance test here!
         */
        m_vs.vseekg(zipfile, (*it)->getEntryOffset(), std::ios::beg);
        ZipLocalEntry zlh;
        zlh.read(zipfile);
        if(!zipfile || !zlh.isEqual(**it))
        {
            throw FileCollectionException("Zip file consistency problem. Zip file data fields are inconsistent with zip file layout.");
        }
    }

    // we are all good!
    m_valid = true;
}
Esempio n. 5
0
int main(int argc, char* argv[])
{
	if (argc != 2) {
		fprintf(stderr, "[-] Error: usage: %s config_file\n", argv[0]);
		return EXIT_FAILURE;
	}

	char* filename = argv[1];

	FILE* fp = fopen(filename, "r");
	if (!fp) {
		fprintf(stderr, "[-] Error: failed to open file %s\n", filename);
		return EXIT_FAILURE;
	}

	/* File buffer */
	char* buffer;
	int nbytes = 128;

	buffer = (char*)malloc(2048*sizeof(char));

	/* Parsing vars */
	int m_size;
	int p_id;
	int p_size;
	int r_page;
	int r_id;
	int w_page;
	int w_id;
	int e_id;

	init_process_table();

	/* Main loop */
	while ((getline(&buffer, (size_t*)&nbytes, fp) != -1)) {

		/* Todas as operações começam com letras diferentes */
		switch(buffer[0]) {
			case 'M': /* MEMSIZE SIZE */
			case 'm':
				parse_memsize(buffer, &m_size);
				printf("[+] MEMSIZE %d\n", m_size);
				memsize(m_size);
				break;

			case 'P': /* PROCSIZE ID SIZE */
			case 'p':
				parse_procsize(buffer, &p_id, &p_size);
				printf("[+] PROCSIZE %d %d\n", p_id, p_size);
				procsize(p_id, p_size);
				break;

			case 'R': /* READ PAGE ID */
			case 'r':
				parse_read(buffer, &r_page, &r_id);
				printf("[+] READ %d %d\n", r_page, r_id);
				read_p(r_page, r_id);
				break;

			case 'W': /* WRITE PAGE ID */
			case 'w':
				parse_write(buffer, &w_page, &w_id);
				printf("[+] WRITE %d %d\n", w_page, w_id);
				write_p(w_page, w_id);
				break;

			case 'E': /* ENDPROC ID */
			case 'e':
				parse_endproc(buffer, &e_id);
				printf("[+] ENDPROC %d\n", e_id);
				endproc(e_id);
				break;

			default:
				printf("[-] Invalid Operation!\n");
		}
	}

	/* Write stats here */
	write_stats();

	fclose(fp);
	return EXIT_SUCCESS;
}