Esempio n. 1
0
void Web_catfile(dccrec *d, char *filename)
{
	FILE	*f;
	char	s[BUFSIZ];

	f = fopen(filename,"r");
	if(f == NULL)
	{
		Log_write(LOG_MAIN|LOG_ERROR,"*","No such file \"%s\".",filename);
		DCC_write(d,"Sorry, the owner has not created \"%s\".",filename);
		return;
	}

	if(!isfile(filename))
	{
		fclose(f);
		Log_write(LOG_ERROR,"*","\"%s\" is not a normal file.",filename);
		DCC_write(d,"\"%s\" is not a normal file.",filename);
		return;
	}

	while(readline(f,s))
	{
		Web_fixforhtml(s);
		DCC_write(d,"%s",s);
	}

	fclose(f);
}
Esempio n. 2
0
void Web_loadcommands()
{
	int	i;
	cmdrec_t	*newcmd;

	for(i=0; webcmd_base_tbl[i].name != NULL; i++)
	{
		/* create a new node */
		newcmd = cmdrec_new();

		/* copy data */
		cmdrec_setname(newcmd,webcmd_base_tbl[i].name);
		cmdrec_setfunction(newcmd,webcmd_base_tbl[i].function);

		User_str2flags(webcmd_base_tbl[i].levels,&newcmd->levels);
		if(newcmd->levels & USER_INVALID)
			Log_write(LOG_ERROR,"*","Warning: web command \"%s\" has invalid levels \"%s\".",webcmd_base_tbl[i].name,webcmd_base_tbl[i].levels);

		/* we don't care about dcc requirements here */
		newcmd->needsdcc = FALSE;

		/* Append it to the web commands list */
		Web_appendcmd(newcmd);
	}
}
Esempio n. 3
0
/* Simulate how the CPU works. */
void cpu_exec(volatile uint32_t n) {
	if(nemu_state == END) {
		printf("Program execution has ended. To restart the program, exit NEMU and run again.\n");
		return;
	}
	nemu_state = RUNNING;

#ifdef DEBUG
	volatile uint32_t n_temp = n;
#endif

	setjmp(jbuf);

	for(; n > 0; n --) {
#ifdef DEBUG
		swaddr_t eip_temp = cpu.eip;
		if((n & 0xffff) == 0) {
			/* Output some dots while executing the program. */
			fputc('.', stderr);
		}
#endif

		/* Execute one instruction, including instruction fetch,
		 * instruction decode, and the actual execution. */
		int instr_len = exec(cpu.eip);

		cpu.eip += instr_len;

#ifdef DEBUG
		print_bin_instr(eip_temp, instr_len);
		strcat(asm_buf, assembly);
		Log_write("%s\n", asm_buf);
		if(n_temp < MAX_INSTR_TO_PRINT) {
			printf("%s\n", asm_buf);
		}
#endif

		/* TODO: check watchpoints here. */
		WP *tail=getHead();
		uint32_t result;
		bool f;
		while(tail){
			result=expr(tail->expr,&f);
			if(f==false) return;
			if(result!=tail->result){
				nemu_state=STOP;
				printf("监视点%d:  %s\n",tail->NO,tail->expr);
				printf("原值 result=%d\n",tail->result);
				printf("新值 result=%d\n",result);
				tail->result=result;
			}
			tail=tail->next;
		}


		if(nemu_state != RUNNING) { return; }
	}

	if(nemu_state == RUNNING) { nemu_state = STOP; }
}
Esempio n. 4
0
/* Simulate how the CPU works. */
void cpu_exec(volatile uint32_t n) {
	if(nemu_state == END) {
		printf("Program execution has ended. To restart the program, exit NEMU and run again.\n");
		return;
	}
	nemu_state = RUNNING;

#ifdef DEBUG
	volatile uint32_t n_temp = n;
#endif

	setjmp(jbuf);

	for(; n > 0; n --) {
#ifdef DEBUG
		swaddr_t eip_temp = cpu.eip;
		if((n & 0xffff) == 0) {
			/* Output some dots while executing the program. */
			fputc('.', stderr);
		}
#endif

		/* Execute one instruction, including instruction fetch,
		 * instruction decode, and the actual execution. */
		int instr_len = exec(cpu.eip);
//		if (cpu.eip>=0xc0100740 && cpu.eip <=0xc0100744) printf("%08x %d\n", cpu.eip, instr_len);
		cpu.eip += instr_len;
//		if (cpu.eip>=0xc0100740 && cpu.eip <=0xc0100744) printf("%08x %d\n", cpu.eip, instr_len);

#ifdef DEBUG
		print_bin_instr(eip_temp, instr_len);
		strcat(asm_buf, assembly);
		Log_write("%s\n", asm_buf);
		if(n_temp < MAX_INSTR_TO_PRINT) {
			printf("%s\n", asm_buf);
		}
#endif

		/* TODO: check watchpoints here. */
		if (check()) {
			nemu_state=STOP;
		}
		
		if(nemu_state != RUNNING) { return; }
		if(cpu.INTR & eflags.IF) {
			uint32_t intr_no = i8259_query_intr();
			i8259_ack_intr();
			int len;
			len = get_len();
			cpu.eip--;
			raise_intr(intr_no, len);
		}	
	}

	if(nemu_state == RUNNING) { nemu_state = STOP; }
}
Esempio n. 5
0
void Notify_sendmsgfromqueue()
{
	int	num_entries = 0;
	radirec	*r;

	if(Notify->flags & NOTIFY_WAITING_FOR_302)
	{
		Log_write(LOG_DEBUG,"*","Attempting to send msg from radiate queue before we've received last 302!");
		return;
	}

	/* Build a message */
	Notify->uh_buf[0] = 0;
	for(r=Notify->radiate_queue; r!=NULL && num_entries < 5; r=r->next)
	{
		sprintf(Notify->uh_buf,"%s %s",Notify->uh_buf,r->nick);
		num_entries++;
	}

	if(num_entries == 0)
	{
		Log_write(LOG_DEBUG,"*","Tried to send something from queue and it was empty.");
		return;
	}

	Server_write(PRIORITY_NORM,"USERHOST %s",Notify->uh_buf+1);
	Notify->flags |= NOTIFY_WAITING_FOR_302;
	Notify->last_radiated_msg = time(NULL);

	/* Set last_radiated at the beginning of a radiate session */
	if(!(Notify->flags & NOTIFY_CURRENTLY_RADIATING))
	{
		Notify->last_radiated = time(NULL);
		Notify->flags |= NOTIFY_CURRENTLY_RADIATING;
	}

	/* Now we wait for 302.  We don't delete this entry until we get it. */
}
Esempio n. 6
0
void websay(char *format, ...)
{
	va_list	va;

	Web->websay_buf[0] = 0;
	va_start(va,format);
	vsprintf(Web->websay_buf,format,va);
	va_end(va);

	/* Web say is used only from inside command loop */
	if(!Web->cmdinuse)
	{
		Log_write(LOG_DEBUG,"*","Attempted to 'websay' outside of command loop. \"%s\"",Web->websay_buf);
		return;
	}

	if(Web->d == NULL)
	{
		Log_write(LOG_ERROR,"*","Recipient has no DCC record! \"%s\"",Web->websay_buf);
		return;
	}

	DCC_write(Web->d, "%s", Web->websay_buf);
}
Esempio n. 7
0
/* Simulate how the CPU works. */
void cpu_exec(volatile uint32_t n) {
	if(nemu_state == END) {
		printf("Program execution has ended. To restart the program, exit NEMU and run again.\n");
		return;
	}
	nemu_state = RUNNING;

#ifdef DEBUG
	volatile uint32_t n_temp = n;
#endif

	setjmp(jbuf);

	for(; n > 0; n --) {
#ifdef DEBUG
		swaddr_t eip_temp = cpu.eip;
		if((n & 0xffff) == 0) {
			/* Output some dots while executing the program. */
			fputc('.', stderr);
		}
#endif

		/* Execute one instruction, including instruction fetch,
		 * instruction decode, and the actual execution. */
		int instr_len = exec(cpu.eip);

		cpu.eip += instr_len;

#ifdef DEBUG
		print_bin_instr(eip_temp, instr_len);
		strcat(asm_buf, assembly);
		Log_write("%s\n", asm_buf);
		if(n_temp < MAX_INSTR_TO_PRINT) {
			printf("%s\n", asm_buf);
		}
#endif

        if (check_change()) {
            show_watchpoint();
            break;
        }

		if(nemu_state != RUNNING) { return; }
	}

	if(nemu_state == RUNNING) { nemu_state = STOP; }
}
Esempio n. 8
0
void pcap_callback(u_char *user, const struct pcap_pkthdr *h, const u_char *packet) 
{	
	
	char * pbuf = buf_header;	//헤더 정보	
	register int i = 0;	
	
	//usleep(0.1);
	
	// 시간 체크
	time(&t);
	tm=localtime(&t);
	
	if(tm->tm_sec == 0 && tm->tm_min == 0 && start == 1){
		create_new_file();
		start = 0;
	}
	
	if(tm->tm_sec == 1 && tm->tm_min == 0){		
		start = 1;
	}
	
	
	// 트래픽 계산
	traffic.Byte += h->len;	
	cal_traffic();
	
	//s += h->len;
	
	// 이더넷 헤더
	ep = (struct ether_header *)packet;
	
	// IP헤더 가져오기 위해 이더넷 헤더 만큼 offset
	packet += sizeof(struct ether_header);
	
	// 이더넷 헤더 타입
  ether_type = ntohs(ep->ether_type);
  
	
	// @ IP protocol
	iph = (struct ip *)packet;
	uint32_t d = (iph->ip_dst).s_addr;
	uint32_t s = (iph->ip_src).s_addr;
  if (ether_type == ETHERTYPE_IP && d != pre_ip_dst && s != pre_ip_src){
  	
  	pre_ip_dst = (iph->ip_dst).s_addr;
  	pre_ip_src = (iph->ip_src).s_addr;
  	
  	
  	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // @ TCP protocol
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////  	
    
    tcph = (struct tcphdr *)(packet + iph->ip_hl * 4);
    
    int x = tcph->psh;        
		if (iph->ip_p == IPPROTO_TCP  && (x == 1)){
			
			
    	// @point : http header 
      packet += sizeof(struct tcphdr) + 20; // 20 tcp header
      
    	
    	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    	// @ HTTP protocol
    	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    	if(tcph->dest == htons(80)){
    		
    		
    		if((Host = strstr(packet+300, "Host: ")) != NULL){    			
    			
    			int i = 0;
    			Host += 6;
    			while( *Host != '\r' && *Host != 0 )
    				url_host[i++] = *Host++;    				
    			
    			url_host[i] = 0;
    			puts(url_host);
    			
    			Log_write(pbuf, url_host);
    			
    			
    			write(fd, buf_header, strlen(buf_header));
    			
    			
    		}
    		
    	}    	
    	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    	// @ NOT HTTP protocol
    	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    	else{
    		
    		Log_write(pbuf, "TCP");
    			
    		write(fd, buf_header, strlen(buf_header));
    		
 //   		printf("%s", buf_header);
   	
    	}   	
    }
    
  
  	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// @ UDP protocol
  	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  	else if(iph->ip_p == IPPROTO_UDP){  		
  		
  		Log_write(pbuf, "UDP");
  		
    	write(fd, buf_header, strlen(buf_header));  	
    }
    
    
    
  }  
  
  
  
  printf("%s", buf_header);
 // printf("%d %d %d %d	%d	%d\n",traffic.GByte,traffic.MByte,traffic.KByte,traffic.Byte, h->len, s);
}
Esempio n. 9
0
void Banlist_writebans()
/*
 * Prefix codes are:
 *    'n' - <nick>
 *    'b' - <ban>
 *    't' - <time_set>
 *    'e' - <expires>
 *    'u' - <used>
 */
{
	FILE	*f;
	banlrec	*b;
	int	x;
	char	banlist[256], tmpfile[256];

	/* bail if banlist is inactive (pending read) */
	if(!(Banlist->flags & BANLIST_ACTIVE))
	{
		Log_write(LOG_MAIN,"*","Banlist list is not active.  Ignoring write request.");
		return;
	}

	/* Open for writing */
	sprintf(banlist,"%s/%s",Grufti->botdir,Grufti->banlist);
	sprintf(tmpfile,"%s.tmp",banlist);
	f = fopen(tmpfile,"w");
	if(f == NULL)
	{
		Log_write(LOG_MAIN|LOG_ERROR,"*","Couldn't write banlist.");
		return;
	}

	/* write header */
	writeheader(f,"Banlist->banlist - The shitlist",banlist);

	/* write each record */
	for(b=Banlist->banlist; b!=NULL; b=b->next)
	{
		/* Write nick */
		if(fprintf(f,"n %s\n",b->nick) == EOF)
			return;

		/* Write ban */
		if(fprintf(f,"b %s\n",b->ban) == EOF)
			return;

		/* Write time */
		if(fprintf(f,"t %lu\n",(u_long)b->time_set) == EOF)
			return;

		/* Write expires */
		if(fprintf(f,"e %lu\n",(u_long)b->expires) == EOF)
			return;

		/* Write used */
		if(fprintf(f,"u %d\n",b->used) == EOF)
			return;
	}

	fclose(f);

	/* Move tmpfile over to main response */
	if(Grufti->keep_tmpfiles)
		x = copyfile(tmpfile,banlist);
	else
		x = movefile(tmpfile,banlist);

	verify_write(x,tmpfile,banlist);
	if(x == 0)
	{
		Log_write(LOG_MAIN,"*","Wrote banlist.");
		Banlist->flags &= ~BANLIST_NEEDS_WRITE;
	}
}
Esempio n. 10
0
void Web_docommand(dccrec *d, char *buf)
{
	cmdrec_t	*wc;

	/* fix buf so we don't get empty fields */
	rmspace(buf);

	/* Web command variables must be preset */
	strcpy(Web->from_n,d->nick);
	strcpy(Web->from_uh,d->uh);
	split(Web->cmdname,buf);
	strcpy(Web->cmdparam,buf);

	/* Set DCC connection record */
	Web->d = d;

	/* Set user and account pointers */
	Web->user = d->user;
	Web->account = d->account;

	/* Now we're ready */
	if(Web->cmdname[0] == 0)
	{
		Log_write(LOG_DEBUG,"*","Web_docommand() invoked with empty cmdname.");
		return;
	}

	/* Mark command as active */
	Web->cmdinuse = 1;

	/* Find the command */
	wc = Web_cmd(Web->cmdname);
	if(wc == NULL)
	{
		/* Not found. */
		websay("No such command \"%s\".",Web->cmdname);
		Web->cmdinuse = 0;
		Web_reset();
		return;
	}

	/* Check levels */
	if(wc->levels != 0L)
	{
		if(!(Web->user->flags & wc->levels))
		{
			char	flags[USERFLAGLEN];
	
			User_flags2str(wc->levels,flags);
			websay("That command requires +%s and you don't have it.  Go away.",flags);
			Web->cmdinuse = 0;
			Web_reset();
			return;
		}
	}

	/* Ok here we go */
	str_element(Web->tok1,Web->cmdparam,1);
	str_element(Web->tok2,Web->cmdparam,2);
	str_element(Web->tok3,Web->cmdparam,3);
	Web->istok1 = Web->tok1[0] ? 1 : 0;
	Web->istok2 = Web->tok2[0] ? 1 : 0;
	Web->istok3 = Web->tok3[0] ? 1 : 0;
	Web->num_elements = num_elements(Web->cmdparam);
	Web->paramlen = strlen(Web->cmdparam);
	Web->isparam = Web->cmdparam[0] ? 1 : 0;

	/* Execute command */
	wc->accessed++;
	wc->function();

	/* Reset */
	Web_reset();
	Web->cmdinuse = 0;
}
/* Simulate how the CPU works. */
void cpu_exec(volatile uint32_t n) {
	if(nemu_state == END) {
		printf("Program execution has ended. To restart the program, exit NEMU and run again.\n");
		return;
	}
	nemu_state = RUNNING;

#ifdef DEBUG
	volatile uint32_t n_temp = n;
#endif

	setjmp(jbuf);

	for(; n > 0; n --) {
#ifdef DEBUG
		swaddr_t eip_temp = cpu.eip;
		if((n & 0xffff) == 0) {
			/* Output some dots while executing the program. */
			fputc('.', stderr);
		}
#endif

		/* Execute one instruction, including instruction fetch,
		 * instruction decode, and the actual execution. */
		int instr_len = exec(cpu.eip);

		cpu.eip += instr_len;

#ifdef DEBUG
		print_bin_instr(eip_temp, instr_len);
		strcat(asm_buf, assembly);
		Log_write("%s\n", asm_buf);
		if(n_temp < MAX_INSTR_TO_PRINT) {
			printf("%s\n", asm_buf);
		}
#endif

		/* TODO: check watchpoints here. */
		WP *p;
		uint32_t index;
		bool success=true;
		p=gethead();
		int flag=0;
		while(p!=NULL)
		{
			index=expr(p->expr,&success);
			if(success==false)
				printf("Meet a wrong expression!");
			if(p->ans!=index)
			{
				flag=1;
				printf("watchpoint %d: %s\n",p->NO+1,p->expr);
				printf("Old value = %d\n",p->ans);
				printf("New value = %d\n",index);
				p->ans=index;
			}
			p=p->next;
		}
		if(flag==1)
			nemu_state=STOP;
		if(nemu_state != RUNNING) { return; }
		if(cpu.INTR & cpu.EFLAGS.IF) {
			uint32_t intr_no = i8259_query_intr();
			i8259_ack_intr();
			raise_intr(intr_no);
		}
	}

	if(nemu_state == RUNNING) { nemu_state = STOP; }

}
Esempio n. 12
0
void cpu_exec(volatile uint32_t n) {
	if(nemu_state == END) {
		printf("Program execution has ended. To restart the program, exit NEMU and run again.\n");
		return;
	}
	nemu_state = RUNNING;

#ifdef DEBUG
	volatile uint32_t n_temp = n;
#endif

	setjmp(jbuf);

	for(; n > 0; n --) {
#ifdef DEBUG
		swaddr_t eip_temp = cpu.eip;
		if((n & 0xffff) == 0) {
			/* Output some dots while executing the program. */
			fputc('.', stderr);
		}
#endif
		/* Execute one instruction, including instruction fetch,
		 *  instruction decode, and the actual execution. */
		int instr_len = exec(cpu.eip);
		//printf("instr_len is %x in cpu-exec.c\n",instr_len);
		cpu.eip += instr_len;
		si_count++;

#ifdef DEBUG
		
#endif

		print_bin_instr(eip_temp, instr_len);
		strcat(asm_buf, assembly);
		Log_write("%s\n", asm_buf);
		if(n_temp < MAX_INSTR_TO_PRINT) {
			printf("%s\n", asm_buf);
		} 

		

		/* TODO: check watchpoints here. */
		if(check_watchpoints()){
			n=1;
			nemu_state = STOP; 
		} 

		if(nemu_state != RUNNING) { 
			printf("Cache cost = %llu, L1 miss rate = %f, L2 miss rate = %f\n",(unsigned long long)(L2_get_cache_cost()+L1_get_cache_cost()), (double)L1_cache_miss/(double)L1_cache_access,(double)L2_cache_miss/(double)L2_cache_access);
			printf("Instruction executed: %llu\n",(long long unsigned)si_count);
			return; 
		}
		//printf("cpu.eip is %x in rear cpu-exec.c\n",cpu.eip);
		
		//PA 4.4
		if(cpu.INTR & eflags.eflags.IF) {
			//printf("cpu.INTR triggered\n");
			uint32_t intr_no = i8259_query_intr();
			i8259_ack_intr();
			int len = get_instr_len();
			cpu.eip --;	//TODO: ?!
			raise_intr(intr_no, len);
		}
	}

	if(nemu_state == RUNNING) { nemu_state = STOP; }
}