Пример #1
0
static void
process_pu (PU_Info *pu_tree)
{
    PU_Info *pu;

    for (pu = pu_tree; pu != NULL; pu = PU_Info_next(pu)) {
	Current_PU_Info = pu;
	MEM_POOL_Push (MEM_pu_nz_pool_ptr);
	Read_Local_Info (MEM_pu_nz_pool_ptr, pu);

	if (vflag)
	  printf ("%*sProcessing PU: %s\n", indent, "",
	          ST_name(PU_Info_proc_sym(pu)));
	indent += indent_inc;
	Process_PU (pu);

	process_stab (PU_Info_symtab_ptr(pu));

	process_func (PU_Info_tree_ptr(pu));

	if (PU_Info_child(pu)) {
	    process_pu (PU_Info_child(pu));
	}

#ifdef WRITE_IRB
	Write_PU_Info (pu);
#endif

	indent -= indent_inc;
	Free_Local_Info (pu);
	MEM_POOL_Pop (MEM_pu_nz_pool_ptr);

    }
}
Пример #2
0
// function that generalizes the matching and processing of a regular expression, it takes
// the request rec, a pointer to data, the number of regexp groups, the size of an ovector
// group (normally 3), a pointer to the regular expression, and a callback function that 
// can use the request rec, the data passed in and the ovector to process the expression
// it then returns a string of processed data
static char * match_and_process_expression(
				request_rec *r, char *data, int num_groups, int group_size,
				char *reg_exp, char*(process_func)(request_rec *r, char *data, int ovector[])) {
	//initialize values
	pcre *re;
	const char *error;
	int erroffset;
	int ovector[num_groups * group_size];
	int rc;	
	char *regex=reg_exp;
	char *output = NULL;
	apr_status_t rv;

	//compile
	re = pcre_compile(regex, PCRE_DOTALL, &error, &erroffset, NULL);
	rv = check_compile_error(re, erroffset, error);
	if (rv != OK) {
		return NULL;
	}

	//evaluate exp against data
	rc = pcre_exec(re, NULL, data, strlen(data), 0, 0, ovector, num_groups * group_size);
	rv = check_match_error(rc);
	if (rv != OK) {
		return NULL;
	}

	//output latitude and longitude
	output= process_func(r, data, ovector);
	return output;
}
Пример #3
0
void
ann_traverse(char *directory, int (*process_func)(char *))
{
	char dotdir[PATH_MAX], sdir[PATH_MAX], filename[PATH_MAX];
	struct annheader header;
	FILE *fpdir;

	snprintf(dotdir, sizeof(dotdir), "%s/.DIR", directory);
	if ((fpdir = fopen(dotdir, "r")) == NULL)      /* no .DIR found */
		return;

	while (fread(&header, 1, sizeof(header), fpdir) == sizeof(header)) {
		// 目录/#或留言本#/, 递归 
		if ((header.flag & ANN_DIR) /* || (header.flag & ANN_GUESTBOOK) */) {
			/* TODO: save title to stack */
			snprintf(sdir, sizeof(sdir), "%s/%s", directory, header.filename);
			ann_traverse(sdir, process_func);
		} else {
			snprintf(filename, sizeof(filename), "%s/%s", directory, header.filename);
			//fprintf(stderr, "indexing %u %s %s\n ", g_docid, filename, header.title);
			process_func(filename);
		}
	}
	fclose(fpdir);
}
Пример #4
0
/* LOCKING: requires that the GC lock is held */
static void
process_stage_entries (int num_entries, volatile gint32 *next_entry, StageEntry *entries, void (*process_func) (MonoObject*, void*))
{
	int i;
	int num_registered = 0;
	int num_busy = 0;

	for (i = 0; i < num_entries; ++i) {
		gint32 state = entries [i].state;

		if (state == STAGE_ENTRY_BUSY)
			++num_busy;

		if (state != STAGE_ENTRY_USED ||
				InterlockedCompareExchange (&entries [i].state, STAGE_ENTRY_BUSY, STAGE_ENTRY_USED) != STAGE_ENTRY_USED) {
			continue;
		}

		process_func (entries [i].obj, entries [i].user_data);

		entries [i].obj = NULL;
		entries [i].user_data = NULL;

		mono_memory_write_barrier ();

		entries [i].state = STAGE_ENTRY_FREE;

		++num_registered;
	}

	*next_entry = 0;

	/* g_print ("stage busy %d reg %d\n", num_busy, num_registered); */
}
Пример #5
0
void interpreter::process_call()
{
    function *old_func = func_; 
    const function_id_t id = read<function_id_t>();
    
    func_ = code_->get_function(id);

    process_func();

    func_ = old_func;
}
Пример #6
0
bool Aura::Process()
{
	// Aura::Depop clears buffs
	if (p_depop)
		return false;

	auto owner = entity_list.GetMob(m_owner);
	if (owner == nullptr) {
		Depop();
		return true;
	}

	if (remove_timer.Check()) {
		owner->RemoveAura(GetID(), false, true);
		return true;
	}

	if (movement_type == AuraMovement::Follow && GetPosition() != owner->GetPosition() && movement_timer.Check()) {
		m_Position = owner->GetPosition();
		auto app = new EQApplicationPacket(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct));
		auto spu = (PlayerPositionUpdateServer_Struct*)app->pBuffer;
		MakeSpawnUpdate(spu);
		auto it = spawned_for.begin();
		while (it != spawned_for.end()) {
			auto client = entity_list.GetClientByID(*it);
			if (client) {
				client->QueuePacket(app);
				++it;
			} else {
				it = spawned_for.erase(it);
			}
		}
		safe_delete(app);
	}
	// TODO: waypoints?

	if (!process_timer.Check())
		return true;

	if (spawn_type != AuraSpawns::Noone)
		ProcessSpawns(); // bit of a hack

	if (process_func)
		process_func(*this, owner);

	// TODO: quest calls
	return true;
}
Пример #7
0
void interpreter::interpret(interpreted *code)
{
    /*
    for (size_t i = 0; i < code->num_functions(); ++i)
    {
        cout << "Function " << i << endl << endl;

        code->get_function(i)->bytecode()->dump(cout);
        
        cout << endl;
    }
    */

    code_ = code;
    func_ = code_->get_function(code_->get_top_function());
    process_func();
}
Пример #8
0
static int network_be_read ( se_ptr_t *ptr )
{
    epdata_t *epd = ptr->data;

    if ( !epd ) {
        return 0;
    }

    int n = 0;

    update_timeout ( epd->timeout_ptr, STEP_READ_TIMEOUT );

    if ( epd->headers == NULL ) {
        epd->headers = &epd->iov;
        epd->buf_size = sizeof ( epd->iov );

    } else if ( epd->data_len == epd->buf_size ) {
        if ( epd->headers == &epd->iov ) {
            epd->headers = malloc ( 4096 * 2 );
            memcpy ( epd->headers, &epd->iov, sizeof ( epd->iov ) );
            epd->buf_size = 4096 * 2;

        } else {
            char *_t = ( char * ) realloc ( epd->headers, epd->buf_size + 4096 );

            if ( _t != NULL ) {
                epd->headers = _t;

            } else {
                epd->iov[0].iov_base = NULL;
                epd->iov[0].iov_len = 0;
                epd->iov[1].iov_base = NULL;
                epd->iov[1].iov_len = 0;
                network_send_error ( epd, 503, "memory error!" );
                close_client ( epd );
                serv_status.reading_counts--;
                return 0;
            }

            epd->buf_size += 4096;
        }
    }

    while ( ( n = recv ( epd->fd, epd->headers + epd->data_len,
                         epd->buf_size - epd->data_len, 0 ) ) >= 0 ) {
        if ( n == 0 ) {
            close_client ( epd );
            epd = NULL;
            break;
        }

        if ( epd->data_len + n >= epd->buf_size ) {
            if ( epd->headers == &epd->iov ) {
                epd->headers = malloc ( 4096 * 2 );
                memcpy ( epd->headers, &epd->iov, sizeof ( epd->iov ) );
                epd->buf_size = 4096 * 2;

            } else {
                char *_t = ( char * ) realloc ( epd->headers, epd->buf_size + 4096 );

                if ( _t != NULL ) {
                    epd->headers = _t;

                } else {
                    epd->iov[0].iov_base = NULL;
                    epd->iov[0].iov_len = 0;
                    epd->iov[1].iov_base = NULL;
                    epd->iov[1].iov_len = 0;
                    network_send_error ( epd, 503, "memory error!" );
                    close_client ( epd );
                    serv_status.reading_counts--;
                    return 0;
                }

                epd->buf_size += 4096;
            }
        }

        if ( epd->status != STEP_READ ) {
            serv_status.reading_counts++;
            epd->status = STEP_READ;
            epd->data_len = n;
            epd->start_time = longtime();

        } else {
            epd->data_len += n;
        }

        if ( epd->_header_length < 1 && epd->data_len >= 4 && epd->headers ) {
            int _get_content_length = 0;

            if ( epd->headers[epd->data_len - 1] == '\n' &&
                 ( epd->headers[epd->data_len - 2] == '\n' ||
                   ( epd->headers[epd->data_len - 4] == '\r' &&
                     epd->headers[epd->data_len - 2] == '\r' ) ) ) {
                epd->_header_length = epd->data_len;

            } else {
                _get_content_length = 1;
                unsigned char *fp2 = stristr ( epd->headers, "\r\n\r\n", epd->data_len );

                if ( fp2 ) {
                    epd->_header_length = ( fp2 - epd->headers ) + 4;

                } else {
                    fp2 = stristr ( epd->headers, "\n\n", epd->data_len );

                    if ( fp2 ) {
                        epd->_header_length = ( fp2 - epd->headers ) + 2;
                    }
                }
            }

            if ( epd->_header_length > 0 && epd->content_length < 0 ) {
                /// not POST or PUT request
                if ( _get_content_length == 0 && epd->headers[0] != 'P' && epd->headers[0] != 'p' ) {
                    epd->content_length = 0;

                } else {
                    int flag = 0;

                    unsigned char *fp = stristr ( epd->headers, "\ncontent-length:", epd->data_len );

                    if ( fp ) {
                        int fp_at = fp - epd->headers + 16;
                        int i = 0, _oc;

                        for ( i = fp_at; i < epd->data_len; i++ ) {
                            if ( epd->headers[i] == '\r' || epd->headers[i] == '\n' ) {
                                flag = 1;
                                fp = epd->headers + fp_at;
                                _oc = epd->headers[i];
                                epd->headers[i] = '\0';
                                break;
                            }
                        }

                        if ( flag ) {
                            epd->content_length = atoi ( fp );
                            epd->headers[i] = _oc;
                        }

                        if ( stristr ( epd->headers + ( epd->_header_length - 60 ), "100-continue",
                                       epd->_header_length ) ) {
                            network_raw_send ( epd->fd, "HTTP/1.1 100 Continue\r\n\r\n", 25 );
                        }
                    }
                }
            }

            if ( epd->_header_length > 0
                 && epd->_header_length < epd->data_len
                 && epd->content_length < 1 ) {
                epd->iov[0].iov_base = NULL;
                epd->iov[0].iov_len = 0;
                epd->iov[1].iov_base = NULL;
                epd->iov[1].iov_len = 0;
                network_send_error ( epd, 411, "" );
                close_client ( epd );
                epd = NULL;
                serv_status.reading_counts--;

                break;
            }
        }

        //printf("data_len = %d header_length = %d content_length = %d\n", epd->data_len, epd->_header_length, epd->content_length);

        if ( epd->_header_length > 0 && ( ( epd->content_length < 1
                                            && epd->_header_length > 0 ) ||
                                          epd->content_length <= epd->data_len - epd->_header_length ) ) {


            /// start job
            epd->header_len = epd->_header_length;
            epd->headers[epd->data_len] = '\0';
            epd->header_len -= 1;
            epd->headers[epd->header_len] = '\0';

            if ( epd->header_len + 1 < epd->data_len ) {
                epd->contents = epd->headers + epd->header_len + 1;

            } else {
                epd->content_length = 0;
            }


            if ( USE_KEEPALIVE == 1 && ( epd->keepalive == 1 ||
                                         ( stristr ( epd->headers, "keep-alive", epd->header_len ) ) )
               ) {
                epd->keepalive = 1;
            }

            epd->response_header_length = 0;
            epd->iov_buf_count = 0;
            epd->response_content_length = 0;

            epd->response_sendfile_fd = -1;

            /// output server status !!!!!!!!!!
            {
                int i, len;
                char *uri = NULL;
                uri = epd->headers;

                for ( i = 0; i < epd->header_len; i++ )
                    if ( uri[i] == ' ' ) {
                        break;
                    }

                for ( ; i < epd->header_len; i++ )
                    if ( uri[i] != ' ' ) {
                        break;
                    }

                uri = epd->headers + i;
                len = strlen ( uri );

                for ( i = 0; i < len; i++ ) {
                    if ( uri[i] == '\r' || uri[i] == '\n' || uri[i] == ' ' ) {
                        break;
                    }
                }

                if ( i > 11 && strncmp ( "/serv-status", uri, i ) == 0 ) {
                    epd->process_timeout = 0;

                    epd->iov[0].iov_base = NULL;
                    epd->iov[0].iov_len = 0;
                    epd->iov[1].iov_base = NULL;
                    epd->iov[1].iov_len = 0;

                    network_send_status ( epd );
                    serv_status.reading_counts--;
                    break;
                }
            }
            /// end.

            se_be_pri ( epd->se_ptr, NULL ); // be wait

            if ( epd->status == STEP_READ ) {
                serv_status.reading_counts--;
                epd->status = STEP_PROCESS;

                serv_status.sec_process_counts[ ( now ) % 5]++;
                serv_status.process_counts++;
                epd->method = NULL;
                epd->uri = NULL;
                epd->host = NULL;
                epd->query = NULL;
                epd->http_ver = NULL;
                epd->referer = NULL;
                epd->user_agent = NULL;

                if ( process_func ( epd, 0 ) != 0 ) {
                    close_client ( epd );
                    epd = NULL;
                }
            }

            break;
        }
    }

    if ( epd && n < 0 && errno != EAGAIN && errno != EWOULDBLOCK ) {
        //printf("error fd %d (%d) %s\n", epd->fd, errno, strerror(errno));
        close_client ( epd );
        epd = NULL;
        return 0;
    }

    return 1;
}
Пример #9
0
void menu_func (int value)
{
	// variables used in the switch statement
	char filename[MAX_LINE];

	switch (value)
	{
	case M_QUIT:  // enum #0
		exit(0);
		break;



	case M_HELP:  // enum #1
		menu_help();
		break;



	case M_FILE_OPEN:   // enum #2
		if (!quietMode)
			cerr << "Open file (string - no spaces) : ";
		cin  >> filename;
		checkStream(cin);
		image_load(filename);
		break;


	case M_FILE_SAVE:   // enum #3
		if (!quietMode)
			cerr << "Save as (string - no spaces) : ";
		cin  >> filename;
		checkStream(cin);
		image_save(filename);
		break;


	case M_FILE_INFO:  // enum #4
		image_print_info();
		break;


	case M_FILE_REVERT:  // enum #5
		image_revert();
		break;

	case M_VIEW_PIXEL_VALUE: // enum #31
		{
			if (!currentImage) 
			{
				cerr << "Sorry, no image is loaded." << endl;
				break;
			}
			if (!quietMode)
			{
				cerr << "Current image width and height: " << currentImage->getWidth()-1 << " " 
					<< currentImage->getHeight()-1 << endl;
			}
			int x=getInt("x value of pixel to view");
			int y=getInt("y value of pixel to view");
			if (x<0 || x>=currentImage->getWidth() || y<0 || y>=currentImage->getHeight())
			{
				cerr << "Invalid pixel location." << endl;
				break;
			}
			cerr << "R: " << currentImage->getPixel(x,y,RED);
			cerr << ", G: " << currentImage->getPixel(x,y,GREEN);
			cerr << ", B: " << currentImage->getPixel(x,y,BLUE) << endl;
			break;
		}

	default:
		process_func(value);
	}
	return;
}
Пример #10
0
/* takes ownership of the input buffer */
static GstFlowReturn
gst_rtp_base_depayload_handle_buffer (GstRTPBaseDepayload * filter,
    GstRTPBaseDepayloadClass * bclass, GstBuffer * in)
{
  GstBuffer *(*process_rtp_packet_func) (GstRTPBaseDepayload * base,
      GstRTPBuffer * rtp_buffer);
  GstBuffer *(*process_func) (GstRTPBaseDepayload * base, GstBuffer * in);
  GstRTPBaseDepayloadPrivate *priv;
  GstFlowReturn ret = GST_FLOW_OK;
  GstBuffer *out_buf;
  guint32 ssrc;
  guint16 seqnum;
  guint32 rtptime;
  gboolean discont, buf_discont;
  gint gap;
  GstRTPBuffer rtp = { NULL };

  priv = filter->priv;

  process_func = bclass->process;
  process_rtp_packet_func = bclass->process_rtp_packet;

  /* we must have a setcaps first */
  if (G_UNLIKELY (!priv->negotiated))
    goto not_negotiated;

  if (G_UNLIKELY (!gst_rtp_buffer_map (in, GST_MAP_READ, &rtp)))
    goto invalid_buffer;

  buf_discont = GST_BUFFER_IS_DISCONT (in);

  priv->pts = GST_BUFFER_PTS (in);
  priv->dts = GST_BUFFER_DTS (in);
  priv->duration = GST_BUFFER_DURATION (in);

  ssrc = gst_rtp_buffer_get_ssrc (&rtp);
  seqnum = gst_rtp_buffer_get_seq (&rtp);
  rtptime = gst_rtp_buffer_get_timestamp (&rtp);

  priv->last_seqnum = seqnum;
  priv->last_rtptime = rtptime;

  discont = buf_discont;

  GST_LOG_OBJECT (filter, "discont %d, seqnum %u, rtptime %u, pts %"
      GST_TIME_FORMAT ", dts %" GST_TIME_FORMAT, buf_discont, seqnum, rtptime,
      GST_TIME_ARGS (priv->pts), GST_TIME_ARGS (priv->dts));

  /* Check seqnum. This is a very simple check that makes sure that the seqnums
   * are strictly increasing, dropping anything that is out of the ordinary. We
   * can only do this when the next_seqnum is known. */
  if (G_LIKELY (priv->next_seqnum != -1)) {
    if (ssrc != priv->last_ssrc) {
      GST_LOG_OBJECT (filter,
          "New ssrc %u (current ssrc %u), sender restarted",
          ssrc, priv->last_ssrc);
      discont = TRUE;
    } else {
      gap = gst_rtp_buffer_compare_seqnum (seqnum, priv->next_seqnum);

      /* if we have no gap, all is fine */
      if (G_UNLIKELY (gap != 0)) {
        GST_LOG_OBJECT (filter, "got packet %u, expected %u, gap %d", seqnum,
            priv->next_seqnum, gap);
        if (gap < 0) {
          /* seqnum > next_seqnum, we are missing some packets, this is always a
           * DISCONT. */
          GST_LOG_OBJECT (filter, "%d missing packets", gap);
          discont = TRUE;
        } else {
          /* seqnum < next_seqnum, we have seen this packet before, have a
           * reordered packet or the sender could be restarted. If the packet
           * is not too old, we throw it away as a duplicate. Otherwise we
           * mark discont and continue assuming the sender has restarted. See
           * also RFC 4737. */
          GST_WARNING ("gap %d <= priv->max_reorder %d -> dropping %d",
              gap, priv->max_reorder, gap <= priv->max_reorder);
          if (gap <= priv->max_reorder)
            goto dropping;

          GST_LOG_OBJECT (filter,
              "%d > %d, packet too old, sender likely restarted", gap,
              priv->max_reorder);
          discont = TRUE;
        }
      }
    }
  }
  priv->next_seqnum = (seqnum + 1) & 0xffff;
  priv->last_ssrc = ssrc;

  if (G_UNLIKELY (discont)) {
    priv->discont = TRUE;
    if (!buf_discont) {
      gpointer old_inbuf = in;

      /* we detected a seqnum discont but the buffer was not flagged with a discont,
       * set the discont flag so that the subclass can throw away old data. */
      GST_LOG_OBJECT (filter, "mark DISCONT on input buffer");
      in = gst_buffer_make_writable (in);
      GST_BUFFER_FLAG_SET (in, GST_BUFFER_FLAG_DISCONT);
      /* depayloaders will check flag on rtpbuffer->buffer, so if the input
       * buffer was not writable already we need to remap to make our
       * newly-flagged buffer current on the rtpbuffer */
      if (in != old_inbuf) {
        gst_rtp_buffer_unmap (&rtp);
        if (G_UNLIKELY (!gst_rtp_buffer_map (in, GST_MAP_READ, &rtp)))
          goto invalid_buffer;
      }
    }
  }

  /* prepare segment event if needed */
  if (filter->need_newsegment) {
    priv->segment_event = create_segment_event (filter, rtptime,
        GST_BUFFER_PTS (in));
    filter->need_newsegment = FALSE;
  }

  priv->input_buffer = in;

  if (process_rtp_packet_func != NULL) {
    out_buf = process_rtp_packet_func (filter, &rtp);
    gst_rtp_buffer_unmap (&rtp);
  } else if (process_func != NULL) {
    gst_rtp_buffer_unmap (&rtp);
    out_buf = process_func (filter, in);
  } else {
    goto no_process;
  }

  /* let's send it out to processing */
  if (out_buf) {
    ret = gst_rtp_base_depayload_push (filter, out_buf);
  }

  gst_buffer_unref (in);
  priv->input_buffer = NULL;

  return ret;

  /* ERRORS */
not_negotiated:
  {
    /* this is not fatal but should be filtered earlier */
    GST_ELEMENT_ERROR (filter, CORE, NEGOTIATION,
        ("No RTP format was negotiated."),
        ("Input buffers need to have RTP caps set on them. This is usually "
            "achieved by setting the 'caps' property of the upstream source "
            "element (often udpsrc or appsrc), or by putting a capsfilter "
            "element before the depayloader and setting the 'caps' property "
            "on that. Also see http://cgit.freedesktop.org/gstreamer/"
            "gst-plugins-good/tree/gst/rtp/README"));
    gst_buffer_unref (in);
    return GST_FLOW_NOT_NEGOTIATED;
  }
invalid_buffer:
  {
    /* this is not fatal but should be filtered earlier */
    GST_ELEMENT_WARNING (filter, STREAM, DECODE, (NULL),
        ("Received invalid RTP payload, dropping"));
    gst_buffer_unref (in);
    return GST_FLOW_OK;
  }
dropping:
  {
    gst_rtp_buffer_unmap (&rtp);
    GST_WARNING_OBJECT (filter, "%d <= 100, dropping old packet", gap);
    gst_buffer_unref (in);
    return GST_FLOW_OK;
  }
no_process:
  {
    gst_rtp_buffer_unmap (&rtp);
    /* this is not fatal but should be filtered earlier */
    GST_ELEMENT_ERROR (filter, STREAM, NOT_IMPLEMENTED, (NULL),
        ("The subclass does not have a process or process_rtp_packet method"));
    gst_buffer_unref (in);
    return GST_FLOW_ERROR;
  }
}
Пример #11
0
int main(int ac, char** av)
{
	/* Preset to no match */
	unsigned long func = -1;
	const char* funcstr = NULL;
	unsigned char* opcode_buf = NULL;
	unsigned char* intrinsic_buf = NULL;
	long sz;
	int i = 0;
	int found = 0;
	int mode = 0;
	unsigned long opcode = -1;
	unsigned long intrinsic = -1;
	FILE* f;
	printf("Ultima 7 usecode disassembler v0.7\n\n");
	/* Parse command line */
	if( ac == 3 )
	{
		if( !strcmp(av[1], "-o") )
		{
			char* stopstr;
			/* Opcode search */
			opcode = strtoul(av[2], &stopstr, 16);
			if( stopstr - av[2] < strlen(av[2]) )
				opcode = -1;
			else
				/* Hex opcode OK */
				mode = 4;
		}
		else if( !strcmp(av[1], "-i") )
		{
			char* stopstr;
			/* Intrinsic function search */
			intrinsic = strtoul(av[2], &stopstr, 16);
			if( stopstr - av[2] < strlen(av[2]) )
				intrinsic = -1;
			else
				/* Hex opcode OK */
				mode = 5;
		}
	}
	else if( ac == 2 )
	{
		if( !strcmp(av[1], "-l") )
			/* List mode */
			mode = 2;
		else if( !strcmp(av[1], "-c") )
			/* Opcode scan mode */
			mode = 3;
		else
		{
			char* stopstr;
			/* Disassembly mode */
			funcstr = av[1];
			func = strtoul(funcstr, &stopstr, 16);
			if( stopstr - funcstr < strlen(funcstr) )
				/* Invalid number */
				func = -1;
			else
				mode = 1;
		}
	}
	if( mode == 0 )
	{
		printf("Usage:\n");
		printf("\tucdump -l - prints list of all present functions\n");
		printf("\tucdump -c - scans the whole usecode file for unknown opcodes\n");
		printf("\tucdump -o <hex number> - prints list of functions which use ");
		printf("the given opcode\n");
		printf("\tucdump -i <hex number> - prints list of functions which use ");
		printf("the given intrinsic function\n");
		printf("\tucdump <hex number> - disassembles single function to stdout\n");
		return -1;
	}
	/* Allocate opcode & intrinsic function buffers */
	if( mode != 2 )
	{
		opcode_buf = (unsigned char*)malloc(256);
		intrinsic_buf = (unsigned char*)malloc(256);
		if( ( opcode_buf == NULL ) || ( intrinsic_buf == NULL ) )
		{
			/* No memory */
			if( opcode_buf )
				free(opcode_buf);
			if( intrinsic_buf )
				free(intrinsic_buf);
			printf("Out of memory\n");
			return -2;
		}
		/* Zero them */
		memset(opcode_buf, 0, 256);
		memset(intrinsic_buf, 0, 256);
	}
	/* Open a usecode file */
#ifdef _WIN32
	/* Microsoftism */
	f = fopen("usecode", "rb");
#else
	f = fopen("usecode", "r");
#endif
	if( f == NULL )
	{
		/* Free the buffers */
		if( opcode_buf )
			free(opcode_buf);
		if( intrinsic_buf )
			free(intrinsic_buf);
		printf("Failed to open usecode file\n\n");
		return -2;
	}
	fseek(f, 0, SEEK_END);
	sz = ftell(f);
	fseek(f, 0, SEEK_SET);
	if( mode == 1 )
		printf("Looking for function number %08lx\n\n", func);
	while( ftell(f) < sz )
	{		
		process_func(f, func, i, &found, opcode_buf, intrinsic_buf, ( mode == 3 ),
									opcode, intrinsic);
		if( ( ( mode != 4 ) && ( mode !=5 ) ) || found )
			i++;
		if( ( mode == 4 ) || ( mode == 5 ) )
			found = 0;
	}
	if( func == -1 )
	{
		if( ftell(f) != sz )
			printf("Problem, tell = %ld!\n", ftell(f));
		printf("Functions: %d\n", i);
	}
	if( ( ( mode == 1 ) || ( mode == 4 ) ) && !found )
		printf("Function not found.\n");
	fclose(f);
	/* Dump unknowns */
	if( ( mode == 1 ) || ( mode == 3 ) )
	{
		if( opcode_buf )
		{
			int found = 0;
			for( i = 0; i < 255; i++ )
				if( opcode_buf[i] )
				{
					if( !found )
					{
						printf("Undefined opcodes found\n");
						found = 1;
					}
					printf("0x%02lx (%d times)\n", i, opcode_buf[i]);
				}
		}
		if( intrinsic_buf )
		{
			int found = 0;
			for( i = 0; i < 255; i++ )
				if( intrinsic_buf[i] )
				{
					if( !found )
					{
						printf("Undefined intrinsic functions found\n");
						found = 1;
					}
					printf("0x%02lx (%d times)\n", i, intrinsic_buf[i]);
				}
		}
	}
	/* Free the buffers */
	if( opcode_buf )
		free(opcode_buf);
	if( intrinsic_buf )
		free(intrinsic_buf);
	return 0;
}
Пример #12
0
int main()
{
	int listen_sock = -1, trans_sock = -1, event_fd = -1, cur_fds = 0, nfds = 0, index = 0;
	struct sockaddr_in client_addr;
	size_t sock_len = sizeof(struct sockaddr_in);
	struct epoll_event ev = { 0 };
	struct epoll_event wait_process_fds[MAX_EPOLL_SIZE];

	if (access(STORE_SERVER_DATA_PATH, F_OK) < 0)
	{
		if (mkdir(STORE_SERVER_DATA_PATH, 0) < 0)
		{
			lerror("mkdir failed, path: %s, err: %s", STORE_SERVER_DATA_PATH, strerror(errno));
			return -1;
		}
	}

	listen_sock = create_server_socket();
	if (-1 == listen_sock)
	{
		lerror("call create_server_socket() failed");
		goto ERR;
	}

	event_fd = epoll_create(MAX_EPOLL_SIZE);
	if (-1 == event_fd)
	{
		lerror("call epoll_create() failed, MAX_EPOLL_SIZE: %d, err: %s", MAX_EPOLL_SIZE, strerror(errno));
		goto ERR;
	}
	ev.events = EPOLLIN | EPOLLET; //在LT模式下工作
	ev.data.fd = listen_sock;

	if (epoll_ctl(event_fd, EPOLL_CTL_ADD, listen_sock, &ev) < 0)
	{
		lerror("call epoll_ctl() failed, err: %s", strerror(errno));
		goto ERR;
	}

	ldebug("listen_sock: %d, event_fd: %d", listen_sock, event_fd);
	ldebug("enter event loop...");

	cur_fds = 1;
	while (1)
	{
		nfds = epoll_wait(event_fd, wait_process_fds, cur_fds, -1);
		if (-1 == nfds)
		{
			lerror("call epoll_wait() failed, err: %s", strerror(errno));
			goto ERR;
		}
		for (index = 0; index < nfds; index++)
		{
			if (wait_process_fds[index].data.fd == listen_sock)
			{
				trans_sock = accept(listen_sock, (struct sockaddr *)(&client_addr), (socklen_t *)&sock_len);
				if (-1 == trans_sock)
				{
					lerror("call accept() failed, listen_sock: %d, err: %s", listen_sock, strerror(errno));
					goto ERR;
				}
				(void)process_func(trans_sock);
			}
		}
	}

	if (event_fd > 0)
	{
		close(event_fd);
	}
	if (listen_sock > 0)
	{
		close(listen_sock);
	}
	return 0;
ERR:
	if (event_fd > 0)
	{
		close(event_fd);
	}
	if (listen_sock > 0)
	{
		close(listen_sock);
	}
	return -1;
}