Пример #1
0
// ---
DATA_PROC HDATA DATA_PARAM DATA_Deserialize( AVP_Serialize_Data* opt, void* buffer, AVP_dword size_in, AVP_dword* size_out ) {

	AVP_word            magic;
	AVP_Data*           data = 0;
	AVP_Serialize_Data  sd;
	AVP_Serialize_Data* psd;
	Serialize           sz;

	if ( !buffer || !size_in ) {
		_RPT0( _CRT_ASSERT, "Bad parameters" );
		return 0;
	}

	if ( opt )
		psd = opt;
	else {
		psd = &sd;
		memset( psd, 0, sizeof(AVP_Serialize_Data) );
	}

	init_get_bytes( &sz, buffer, size_in, psd->proc, psd->user_data );

	if ( get_word (&sz, &magic) != sizeof(magic) || magic != 0xadad ) {
		if ( size_out )
			*size_out = sz.tsize;
		return 0;
	}

	if ( get_dword (&sz, &psd->version) != sizeof(psd->version) || psd->version != 1 ) {
		if ( size_out )
			*size_out = sz.tsize;
		return 0;
	}

	if ( get_dword (&sz, &sz.crc_cluster) != sizeof(sz.crc_cluster) ) {
		if ( size_out )
			*size_out = sz.tsize;
		return 0;
	}

	sz.crc = -1;

	if ( !DATA_Get(&sz,0,&data) || !data || !flush_get_bytes(&sz) ) {
		if ( data ) {
			DATA_Remove( (HDATA)data, 0 );
			data = 0;
		}
		else
			flush_get_bytes( &sz );
	}
	if ( size_out )
		*size_out = sz.tsize;

	return DATA_HANDLE(data);
}
Пример #2
0
/**
 * \brief Command arguments parser.
 *
 * Using the format pointed by the argument fmt
 * parses the input string filling the array argv
 * with input parameters of the correct type.
 *
 * \param fmt   Parameters format string.
 * \param input Input string.
 * \param argv  Array filled with parameters.
 *
 * \return False in case of errors, otherwise true.
 */
static bool parseArgs(const char *fmt, const char *input, parms argv[])
{
	const char *begin = input, *end = input;

	while (*fmt)
	{
		// Extract the argument
		if (!get_word(&begin, &end))
			return false;

		switch (*fmt)
		{
			case 'd':
				(*argv++).l = atol(begin);
				break;

			case 's':
				(*argv).s.p = begin;
				(*argv).s.sz = end - begin;
				/* Remove the quotes from argument */
				if (*begin == '"' && *(end - 1) == '"')
				{
					(*argv).s.p += 1;
					(*argv).s.sz -= 2;
				}
				argv++;
				break;

			default:
				ASSERT2(0, "Unknown format for argument");
				return false;
		}

		++fmt;
	}

	/* check if there are remaining args */
	if (get_word(&begin, &end))
		return false;

	return true;
}
Пример #3
0
void prot_login_verify_reply( struct qqclient* qq, qqpacket* p )
{
    bytebuffer *buf = p->buf;
    get_word( buf );	//length or sth..
    int code = get_byte( buf );
    switch( code ) {
    case 0x00:
        get_token( buf, &qq->data.login_info_token );
        qq->data.login_info_unknown1 = get_int( buf );
        qq->server_time = get_int( buf );
        get_token( buf, &qq->data.login_info_data );
        get_token( buf, &qq->data.login_info_magic );
        get_data( buf, qq->data.login_info_key1, 16 );
        get_word( buf );	//00 00
        get_data( buf, qq->data.login_info_key3, 16 );
        get_word( buf );	//00 00
        //success
        prot_login_get_info( qq );
        return;
    case 0x33:
    case 0x51:	//
        qqclient_set_process( qq, P_DENIED );
        DBG("Denied.");
        break;
    case 0xBF:
        DBG("No this number.");
    case 0x34:
        DBG("Wrong password.");
        qqclient_set_process( qq, P_WRONGPASS );
        break;
    default:
        hex_dump( buf->data, buf->len );
        break;
    }
    buf->pos = 11;
    uchar len = get_word( buf );
    char msg[256];
    get_data( buf, (uchar*)msg, len );
    msg[len] = 0;
    DBG( msg );
    //failed
}
Пример #4
0
int kcinth()
{
   u16    segment, offset;
   int    a,b,c,d, r;

   segment = running->uss; 
   offset = running->usp;

   a = get_word(segment, offset + 2*PA);
   b = get_word(segment, offset + 2*PB);
   c = get_word(segment, offset + 2*PC);
   d = get_word(segment, offset + 2*PD);

   switch(a){
       case 0 : r = running->pid;     break;
       case 1 : r = do_ps();          break;
       case 2 : r = chname(b);        break;
       case 3 : r = kmode();          break;
       case 4 : r = tswitch();        break;
       case 5 : r = do_wait(b);       break;
       case 6 : r = do_exit(b);       break;
        
       case 7 : r = fork();           break;
       case 8 : r = exec(b);          break;

       case 9 : r = vfork();          break;


   case 30 : r = kpipe(b); break;
   case 31 : r = read_pipe(b,c,d);  break;
   case 32 : r = write_pipe(b,c,d); break;
   case 33 : r = close_pipe(b);     break;
   case 34 : r = pfd();             break;

       case 90: r =  getc();          break;
       case 91: color=running->pid+11;
                r =  putc(b);         break;       
       case 99: do_exit(b);           break;
       default: printf("invalid syscall # : %d\n", a); 
   }
   put_word(r, segment, offset + 2*AX);
}
Пример #5
0
int copyImage(int childSeg)
{
    int i, word;
    printf("Copying 0x%x to 0x%x\n", running->uss, childSeg);
    for(i = 0; i < 0xFFFE; i += 2)
    {
        word = get_word(running->uss, i);
        put_word(word, childSeg, i);
    }
    return 0;
}
Пример #6
0
void test_append_word(Segment s, int n)
{
        int length = 0;
        for (int i = 0; i < n; i++) {
                for (int j = 0; j < TO_ADD; j++) {

                        length = get_words_in_seg(s, i);

                        append_word(s, i, j);

                        if (get_word(s, i, (length - 1)) != (unsigned) j) {
                                fprintf(stderr, "get_word: %u\n", get_word(s, i, length));
                                fprintf(stderr, "j: %d\n", j);
                                fprintf(stderr, "did not add...\n");
                        }
                }
        }

        return;
}
Пример #7
0
word_t init_mem(byte_t* ins, char option)
{
	FILE* file;
	if (option == 'i') file = fopen("iimage.bin", "rb");
	else file = fopen("dimage.bin", "rb");

	word_t init_addr = get_word(file);

	int n = get_word(file);

	int i;
	for (i = 0; i < n*4; i++) {
		if (option == 'i') ins[i+init_addr] = get_byte(file);
		else ins[i] = get_byte(file);
	}

	fclose(file);

	return init_addr;
}
Пример #8
0
void prot_login_get_info_reply( struct qqclient* qq, qqpacket* p )
{
    bytebuffer *buf = p->buf;
    get_word( buf );	//01 66 length or sth...
    get_word( buf );	//01 00
    get_data( buf, qq->data.login_info_key2, 16 );
    buf->pos += 8;	//00 00 00 01 00 00 00 64
    qq->data.login_info_unknown2 = get_int( buf );  //00 C8 00 02
    qq->server_time = get_int( buf );
    qq->client_ip = get_int( buf );
    get_int( buf );	//00000000
    get_token( buf, &qq->data.login_info_large );
    get_int( buf );	//????
    uchar len = get_byte( buf );
    get_data( buf, (void*)qq->self->nickname, len );
    qq->self->nickname[len] = 0;
    DBG("Hello, %s", qq->self->nickname );
//	prot_login_a4( qq );
    prot_login_get_list( qq, 0 );
}
Пример #9
0
/*
 * Parse line and create/update a variable.
 */
static void parse_line(char *line)
{
	char *varname;
	char *val;
	pgxc_ctl_var *newv;

	line = get_word(line, &varname);
	if (!varname)
		return;
	if (!(newv = confirm_var(varname)))
		return;
	reset_value(newv);
	while((line = get_word(line, &val)))
	{
		if (val)
		{
			add_val(newv, val);
		}
	}
}
Пример #10
0
static void signalasync (struct s2devstruct *dev, struct asyncreq *ar, int actual, int err)
{
	uaecptr request = ar->request;
	int command = get_word (request + 28);
	if (log_net)
		write_log (_T("%s:%d CMD=%d async request %x completed\n"), getdevname(), dev->unit, command, request);
	put_long (request + 32, actual);
	put_byte (request + 31, err);
	ar->ready = 1;
	write_comm_pipe_u32 (&dev->requests, request, 1);
}
Пример #11
0
void *words( FILE *infile ) {
  d = NULL;
  char wordbuf[MAXWORD];

  pthread_mutex_lock(&lock);
  int have_words = get_word( wordbuf, MAXWORD, infile );
  pthread_mutex_unlock(&lock);


  while( have_words ) {
	 pthread_mutex_lock(&lock);
 	// add word to dictinonary
    	d = insert_word(d, wordbuf); 
  	pthread_mutex_unlock(&lock);
	
	pthread_mutex_lock(&lock);
	have_words = get_word( wordbuf, MAXWORD, infile );
	pthread_mutex_unlock(&lock);
  }
}
Пример #12
0
void get_page(apr_pool_t *pool, const char *arg, apr_size_t page_count,
              apr_size_t *page_no)
{
    *page_no = atosize(get_word(pool, &arg, ARG_SEPARATE_STR[0]));

    if (*page_no == 0) {
        *page_no = 1;
    } else if (*page_no > page_count) {
        *page_no = page_count;
    }
}
Пример #13
0
static uae_u32 scsidev_close (void)
{
#ifdef DEBUGME
    printf("scsidev_close()\n");
#endif

    opencount--;
    put_word (m68k_areg (regs, 6) + 32, get_word (m68k_areg (regs, 6) + 32) - 1);

    return 0;
}
Пример #14
0
Файл: t.c Проект: B-Rich/CptS460
//copys the image of the running proc into child_segment
void copy_image(int child_segment)
{
    int i = 0;
    u16 word;
    while (i<=0x1000)
    {
        word = get_word(running->uss,i);
        put_word(word,child_segment,i);
        i+=2;
    }
}
Пример #15
0
static int
list_files (zip *z)
{
	unsigned char buf[46];
	struct zipfile *zfile;
	ulong pat, fn_size;
	int nr = 0;

	pat = z->cd_offset;
	while (nr < z->nr_files) {
		fseek (z->f, pat + z->head_size, SEEK_SET);

		if (fread (buf, 46, 1, z->f) != 1) return ZIP_EREAD;
		if (get_long (buf) != 0x02014b50) return ZIP_BADZIP;

		zfile = malloc (sizeof (struct zipfile));
		if (!zfile) return ZIP_NOMEM;
		memset (zfile, 0, sizeof (struct zipfile));

		zfile->crc = get_long (buf + 16);
		zfile->zip_size = get_long (buf + 20);
		zfile->real_size = get_long (buf + 24);
		fn_size = get_word (buf + 28);
		zfile->pos = get_long (buf + 42);

		zfile->name = malloc (fn_size + 1);
		if (!zfile->name) {
			free (zfile);
			return ZIP_NOMEM;
		}
		fread (zfile->name, fn_size, 1, z->f);
		zfile->name[fn_size] = '\0';

		zfile->next = z->files;
		z->files = zfile;

		pat += 0x2e + fn_size + get_word (buf + 30) + get_word (buf + 32);
		nr++;
	}
	return ZIP_OK;
}
Пример #16
0
void cScenarioAmiga::load_Teams( byte keyID, byte **pBuffer ) {
	word house = get_word( pBuffer );
	word findMode = get_word( pBuffer );

	word foundMode = 0;

	bool found = false;
	
	for( int i = 0; i < 5; ++i ) {
		string mode = g_DuneEngine->resourcesGet()->aiModeGet( i );

		if( mode[0] == (char) findMode ) {
			found = true;
			foundMode = i;
			break;
		}
	}
	if(!found)
		return;

	found = false;
	word findMovement = get_word( pBuffer );
	word foundMove = 0;

	for( int i = 0; i < 6; ++i ) {
		string move = g_DuneEngine->resourcesGet()->movementNameGet(i);

		if( move[0] == (char) findMovement ) {
			foundMove = i;
			found = true;
			break;
		}
	}
	if(!found)
		return;

	word min = get_word( pBuffer );
	word max = get_word( pBuffer );
	
	mTeams.push_back( new cTeam( g_DuneEngine->houseGet( (eHouse) house ), foundMode, foundMove, min, max ));
}
Пример #17
0
int main() {
	struct tnode *root;
	char word[MAXWORD];

	root = NULL;
	//'\t' is just for indicate the end 
	while (get_word(word, MAXWORD) != -1)
		if (isalpha(word[0]))
			root = add_tree(root, word);
	tree_print(root);
	return 0;
}
Пример #18
0
/**
 * A utility function to avoid duplication when testing pop() implementations.
 *
 * @param push_value TODO
 * @param pop_mode TODO
 * @param storage_location TODO
 * @param source_location TODO
 */
void
pop_test_util(uint32_t push_value, uint8_t pop_mode, uint32_t storage_location,
              int source_location)
{
    allocate();
    push(push_value);

    if (source_location == SOURCE_IMMEDIATE)
    {
        store_dword(ram, NEXT_INSTR, NEXT2_INSTR);

        if (storage_location == NEXT3_INSTR)
            store_dword(ram, NEXT2_INSTR, NEXT3_INSTR);

        exec(create_instruction(INSTR_POP, pop_mode, EMPTY_BYTE,
                                EMPTY_BYTE));
    }
    else
    {
        //  We can point the register to next instruction by default
        r[TEST_REGISTER] = NEXT_INSTR;

        if (storage_location == NEXT2_INSTR)
            store_dword(ram, NEXT_INSTR, NEXT2_INSTR);

        exec(create_instruction(INSTR_POP, pop_mode, EMPTY_BYTE,
                                TEST_REGISTER));
    }

    if (storage_location == REGISTER_LOCATION)
    {
        CU_ASSERT(push_value == r[TEST_REGISTER]);
    }
    else
    {
        switch (push_value)
        {
            case DUMMY_VALUE_32:
            CU_ASSERT(push_value == get_dword(ram, storage_location));
                break;
            case DUMMY_VALUE_16:
            CU_ASSERT(push_value == get_word(ram, storage_location));
                break;
            case DUMMY_VALUE_8:
            CU_ASSERT(push_value == get_byte(ram, storage_location));
                break;
            default:
            CU_FAIL("Invalid push_value");
        }
    }

    deallocate();
}
Пример #19
0
void * dic_words(void * args){

  FILE * infile = (FILE *) args;
  
  char w_buf[MAXWORD];
  
  while(get_word( w_buf, MAXWORD, infile ) ) {

    d = insert_word(d, w_buf); 
  }
 
}
Пример #20
0
int copyImage(int child_segment) {
    int i, word;
    
    // Copy word for word... (word==2 bytes)
    printf("Copying 0x%x to 0x%x\n", running->uss, child_segment);
    for (i=0; i<0xFFFE; i+=2) {
	word = get_word(running->uss, i);
	put_word(word, child_segment, i);
    }
    
    return(0);
}
Пример #21
0
/* convert a resource name */
static void convert_name( LPVOID *dst, LPVOID *src )
{
    int len;
    switch (*((WORD *)*src))
    {
    case 0x0000:
        get_word( src );
        put_byte( dst, 0 );
        break;
    case 0xffff:
        get_word( src );
        put_byte( dst, 0xff );
        put_word( dst, get_word(src) );
        break;
    default:
        len = WideCharToMultiByte( CP_ACP, 0, *src, -1, *dst, 0x7fffffff, NULL,NULL );
        *dst = (char *)*dst + len;
        *src = (WCHAR *)*src + strlenW( (WCHAR *)*src ) + 1;
        break;
    }
}
Пример #22
0
void prot_login_request_reply( struct qqclient* qq, qqpacket* p )
{
    bytebuffer *buf = p->buf;
    token answer_token;
    token png_token;
    uchar next = 0;
    uchar result = get_byte( buf );	//03: ok   04: need verifying
    get_byte( buf ); //00
    get_byte( buf ); //05
    uchar png_data = get_byte( buf );
    get_int( buf );	//需要验证码时为00 00 01 23,不需要时为全0
    get_token( buf, &answer_token );
    if( png_data == 1 ) {	//there's data for the png picture
        int len;
        len = get_word( buf );
        uchar* data;
        NEW( data, len );
        if( !data )
            return;
        get_data( buf, data, len );
        get_byte( buf ); //00
        next = get_byte( buf );
        char path[PATH_LEN];
        sprintf( path, "%s/%u.png", qq->verify_dir, qq->number );
        FILE *fp;
        if( next ) {
            fp = fopen( path, "wb" );
        } else {
            fp = fopen( path, "ab" );
            DBG("got png at %s", path );
        }
        if( fp ) {
            fwrite( data, len, 1, fp );
            fclose( fp );
        }
        DEL( data );
        get_token( buf, &png_token );
    }
    //parse the data we got
    if( png_data ) {
        if( next ) {
            prot_login_request( qq, &png_token, 0, 1 );
        } else {
            qq->data.verify_token = answer_token;
            qqclient_set_process( qq, P_VERIFYING );
        }
    } else {
        DBG("process verify password");
        qq->data.token_c = answer_token;
        prot_login_verify( qq );
    }
    result = 0;
}
Пример #23
0
static void
cmd_alias(void)
{
   /* Currently only two forms are supported:
    * *alias station - ..
    * *alias station -
    */
   get_token();
   if (strcmp(ucbuffer, "STATION") != 0)
      goto bad;
   get_word();
   if (strcmp(buffer, "-") != 0)
      goto bad;
   get_word();
   if (*buffer && strcmp(buffer, "..") != 0)
      goto bad;
   pcs->dash_for_anon_wall_station = (*buffer != '\0');
   return;
bad:
   compile_error_skip(/*Bad *alias command*/397);
}
Пример #24
0
static void debug_print_memory(int address) {
    int i;
    
    if (address < 0 || address > zFilesize) {
        glk_printf("ERROR: address out of range (0 - %08x)\n", zFilesize);
        return;
    }
    glk_printf("%#08x : ", address);
    for (i = 0; i < 16 ; i+=2)
        glk_printf("  %04x", get_word(address + i));
    glk_put_string("\n");
}
Пример #25
0
void prot_user_keep_alive_reply( struct qqclient* qq, qqpacket* p )
{
	bytebuffer *buf = p->buf;
	get_byte( buf );	//00
	int onlines;
	onlines = get_int( buf );
	int ip;
	ip = get_int( buf ); //client ip
	ushort port = get_word( buf ); //client port
	get_word( buf );	//unknown 00 3c
	uint server_time;
	server_time = get_int( buf );
	//...5 zeros 
	time_t t;
	t = CN_TIME( server_time );
	char event[64];
	sprintf( event, "keepalive^$%u", qq->number );
	qqclient_put_event( qq, event );
//	DBG("keepalive: %u ", qq->number );
	port = ip= 0;
}
int main (void)
{
  int i;

  for (i = 0; i < 10; i++)
    {
      word_t word = get_word (stdin);
      fprintf (stderr, "%012llo\n", word);
    }

  return 0;
}
Пример #27
0
static void dump_ne_names( const IMAGE_OS2_HEADER *ne )
{
    const unsigned char *pstr = (const unsigned char *)ne + ne->ne_restab;

    printf( "\nResident name table:\n" );
    while (*pstr)
    {
        printf( " %4d: %*.*s\n", get_word(pstr + *pstr + 1), *pstr, *pstr, pstr + 1 );
        pstr += *pstr + 1 + sizeof(WORD);
    }
    if (ne->ne_cbnrestab)
    {
        unsigned int pos = ne->ne_nrestab;
        printf( "\nNon-resident name table:\n" );
        while ((pstr = PRD(pos, 0)) && *pstr)
        {
            printf( " %4d: %*.*s\n", get_word(pstr + *pstr + 1), *pstr, *pstr, pstr + 1 );
            pos += *pstr + 1 + sizeof(WORD);
        }
    }
}
Пример #28
0
void * words(void * args){

  FILE * infile = (FILE *) args;
  //dict_t *wd = NULL;
  char wordbuf[MAXWORD];
 
  while(get_word( wordbuf, MAXWORD, infile ) ) {
//pthread_mutex_lock(&mtex);
    d = insert_word(d, wordbuf); // add to dict
//pthread_mutex_unlock(&mtex);
  }
}
Пример #29
0
PPMdata* LoadASCIIPPMImage(const char* filename, PPMdata* ppm)
{
	int i, j, isize, jsize;
	GLubyte* data;
	FILE* texturefile;

	if( NULL == (texturefile = fopen(filename, "r"))){
		fprintf(stderr, "Cannot open texure file %s\n", filename);
		return NULL;
	}

	if(strcmp("P3", get_word(texturefile)) != 0 ){
		fprintf(stderr, "Texure file %s is not an ASCII PPM format\n", filename);
		return NULL;
	}

	isize = atoi(get_word(texturefile));

	if ( 2<<(MAX_LOD-1) != isize ){
		fprintf(stderr, "Width of texture filef %s is not %d.\n", filename, 2<<(MAX_LOD-1));
		return NULL;
	}

	jsize = atoi(get_word(texturefile));
	if ( 2<<(MAX_LOD-1) != jsize ){
		fprintf(stderr, "Height of texture filef %s is not %d.\n", filename, 2<<(MAX_LOD-1));
		return NULL;
	}

	if(255 != atoi(get_word(texturefile))){
		fprintf(stderr, "Color component in %s does not fit in a byte.\n",
            filename);
		return NULL;
	}

	if(NULL == (data = (GLubyte*)malloc(3*isize*jsize*sizeof(GLubyte)))){
		fprintf(stderr, "Cannot allocate memory for texture data\n");
		return NULL;
	}

	ppm->imagewidth = jsize;
	ppm->imageheight = isize;
	ppm->data = data;

	for (i = 0; i < isize; i++) {
		for (j = 0; j < jsize; j++) {
			*(data + 3*(jsize*i + j)) = (GLubyte) atoi(get_word(texturefile));
			*(data + 3*(jsize*i + j)+1) = (GLubyte) atoi(get_word(texturefile));
			*(data + 3*(jsize*i + j)+2) = (GLubyte) atoi(get_word(texturefile));
		}
	}

	fclose(texturefile);
	return ppm;
}
Пример #30
0
char get_token()
{
   // char token_string[MAX_TOKEN_STRING_LENGTH]; //Store your token here as you build it.
    get_source_line(token_string);


    while(token_string[0] != '\0')
    {
    	//printf("I went through the while loop: %d times\n", debugCount); //debug line
    	transfer(skipArray,token_string);
        skip_blanks(skipArray);  //1.  Skip past all of the blanks
        transfer(token_string,skipArray);
        //printf("This is token_string after skip_blanks :2%s2\n", token_string); //debug
        //printf("ldksaf");
        if(token_string[0] == '\n')
        {
            return 'a';
        }
        if(token_string[0] == '.')
        {
            printf("\t>> .\t.\n");
            return '.';
        }
        if(isalpha(token_string[0]))
        {
        	get_word();
        }
        else if(isdigit(token_string[0]))
        {
            //token_string = get_number(token_string);
            get_number();
        }
        else if(token_string[0] == '\'')
        {
            //token_string = get_string(token_string);
            get_string();
        }
        else if(token_string[0] == '{'){
        	skip_comment(token_string);
        }
        else
        {
            if(token_string[0] == '.')
            {
                return '.';
            }
            get_special();
        }

    }
    return 'a'; //What should be returned here?
}