示例#1
0
void* mm_realloc(void* ptr, size_t size)
{
#ifdef MM_USE_STUBS
    return realloc(ptr, size);
#else
    if(size==0){
        free(ptr);
        return ptr;
    }
    if(!ptr)
        return malloc(size);
    t_block last;
    t_block b = valid_addr(ptr,&last);
    if(!b)
        return ptr;
    size_t s = align4(size);
    if(b->size >= s){
        if(b->size > s+BLOCK_SIZE+4)
            split_block(b,s);
        return ptr;
    }
    void *new = malloc(s);
    if(!new)
        return NULL;
    size_t i,s4,*sp,*newp;
    s4=s/(sizeof(size_t));
    sp=(size_t*)(p);
    newp=(size_t*)(new);
    for(i=0;i<s4;i++)
        newp[i]=sp[i];
    free(ptr);
    return new;
    //#error Not implemented.
#endif
}
示例#2
0
void			free(void *ptr)
{
  t_block		*currentElem;
  /* size_t		page_size; */
  /* size_t		size_to_reduce; */

  pthread_mutex_lock(&g_mutex);
  if (valid_addr(ptr))
    {
      currentElem = get_elem_by_ptr(ptr);
      currentElem->free = STATUS_FREE;
      currentElem = fusion_prev_block(currentElem);
      if (currentElem && currentElem->next && currentElem->next->free)
	currentElem = fusion_prev_block(currentElem->next);
      /* if (currentElem && !currentElem->next) */
      /* 	{ */
      /* 	  page_size = getpagesize(); */
      /* 	  if (currentElem->size > 2 * page_size) */
      /* 	    { */
      /* 	      if (currentElem->prev) */
      /* 		{ */
      /* 		  g_last = currentElem->prev; */
      /* 		  currentElem->prev->next = NULL; */
      /* 		} */
      /* 	      else */
      /* 		g_data = NULL; */
      /* 	      size_to_reduce = (currentElem->size / page_size - 1)  * page_size; */
      /* 	      sbrk(size_to_reduce); */
      /* 	      currentElem->size = currentElem->size - size_to_reduce; */
      /* 	    } */
      /* 	} */
    }
  pthread_mutex_unlock(&g_mutex);
}
示例#3
0
int task_create(task_t* tasks, size_t num_tasks)
{
  size_t i;

  if (num_tasks > OS_MAX_TASKS - 2)
  	return -EINVAL;

  if (!valid_addr(tasks, sizeof(task_t) * num_tasks, USR_START_ADDR, USR_END_ADDR))
  	return -EFAULT;

  task_t *(task_array[OS_MAX_TASKS]);
  for (i = 0; i < num_tasks; i++)
  {
    task_array[i] = &(tasks[i]);
  }

  if (!assign_schedule(task_array, num_tasks))
  {
    return -ESCHED;
  }

  disable_interrupts();
  tasks_created = 1;
  allocate_tasks(task_array, num_tasks);
  dispatch_nosave();

  // This should never return
  return -1;
}
//frees dynamic allocated memory
void free(void *p){
    t_block block;
    if(valid_addr(p)){
        block = get_block(p);
        block->block_free = 1;
        //merge with previous if possible
        if(block->prev && block->prev->block_free){
            block = merge(block->prev);
        }
        //merge with next if possible
        if(block->next){
            if(block->next->block_free){
                merge(block);
            }
        } else {
            //free the end of the heap
            if(block->prev){
                //block->prev->next = 0x0;
            } else {
                // brk(block);
                // base = 0x0;
            }

        }

        //no more blocks
        if(!block->next && !block->prev){
            brk(block);
            base = 0x0;
        }
    }
}
示例#5
0
文件: observer.c 项目: xsoameix/rock
void
get_addr_port(char ** addr, char ** port) {
  char * value;
  value = getenv("OBSERVER_ADDR");
  if (value != NULL && !valid_addr(value)) * addr = value;
  value = getenv("OBSERVER_PORT");
  if (value != NULL && !valid_port(value)) * port = value;
}
示例#6
0
void check_reg_extra() {
	struct schoolmate_info schmate;
	struct userec *urec = &currentuser;
	char buf[192], bufe[192];
	sethomefile(buf, currentuser.userid, ".regextra");

	if (!dashf(buf)) {
		do {
			memset(&schmate, 0, sizeof(schmate));
			strlcpy(schmate.userid, currentuser.userid, sizeof(schmate.userid));
			screen_move(1, 0);
			//% prints("请输入个人信息. 如果输入错误,可以重新输入.\n");
			prints("\xc7\xeb\xca\xe4\xc8\xeb\xb8\xf6\xc8\xcb\xd0\xc5\xcf\xa2. \xc8\xe7\xb9\xfb\xca\xe4\xc8\xeb\xb4\xed\xce\xf3,\xbf\xc9\xd2\xd4\xd6\xd8\xd0\xc2\xca\xe4\xc8\xeb.\n");
			/*default value is 0*/
			do {
				//% getdata(2, 0, "输入以前的学号: ", schmate.school_num,
				getdata(2, 0, "\xca\xe4\xc8\xeb\xd2\xd4\xc7\xb0\xb5\xc4\xd1\xa7\xba\xc5: ", schmate.school_num,
						sizeof(schmate.school_num), DOECHO, YEA);
			} while (!isNumStr(schmate.school_num)); //如果有输入非数字,重新输入!下同
			do {
				//% getdata(4, 0, "输入邮箱(外部邮箱亦可): ", schmate.email, STRLEN,
				getdata(4, 0, "\xca\xe4\xc8\xeb\xd3\xca\xcf\xe4(\xcd\xe2\xb2\xbf\xd3\xca\xcf\xe4\xd2\xe0\xbf\xc9): ", schmate.email,
						sizeof(schmate.email), DOECHO, YEA);
			} while (!valid_addr(schmate.email));
			do {
				//% getdata(6, 0, "输入身份证号码: ", schmate.identity_card_num,
				getdata(6, 0, "\xca\xe4\xc8\xeb\xc9\xed\xb7\xdd\xd6\xa4\xba\xc5\xc2\xeb: ", schmate.identity_card_num,
						sizeof(schmate.identity_card_num), DOECHO, YEA);
			} while (!isNumStrPlusX(schmate.identity_card_num)
					|| strlen(schmate.identity_card_num) !=IDCARDLEN);

			do {
				//% getdata(8, 0, "输入毕业证书编号: ", schmate.diploma_num,
				getdata(8, 0, "\xca\xe4\xc8\xeb\xb1\xcf\xd2\xb5\xd6\xa4\xca\xe9\xb1\xe0\xba\xc5: ", schmate.diploma_num,
						sizeof(schmate.diploma_num), DOECHO, YEA);
			} while (!isNumStr(schmate.diploma_num));

			do {
				//% getdata(10, 0, "输入手机或固定电话号码: ", schmate.mobile_num,
				getdata(10, 0, "\xca\xe4\xc8\xeb\xca\xd6\xbb\xfa\xbb\xf2\xb9\xcc\xb6\xa8\xb5\xe7\xbb\xb0\xba\xc5\xc2\xeb: ", schmate.mobile_num,
						sizeof(schmate.mobile_num), DOECHO, YEA);
			} while (!isNumStr(schmate.mobile_num));

			strcpy(buf, "");
			//% getdata(11, 0, "以上信息输入正确并进行邮箱绑定认证[Y/n]", buf, 2, DOECHO, YEA);
			getdata(11, 0, "\xd2\xd4\xc9\xcf\xd0\xc5\xcf\xa2\xca\xe4\xc8\xeb\xd5\xfd\xc8\xb7\xb2\xa2\xbd\xf8\xd0\xd0\xd3\xca\xcf\xe4\xb0\xf3\xb6\xa8\xc8\xcf\xd6\xa4[Y/n]", buf, 2, DOECHO, YEA);
		} while (buf[0] =='n' || buf[0] == 'N');
		sprintf(buf, "%s, %s, %s, %s, %s\n", schmate.school_num,
				schmate.email, schmate.identity_card_num,
				schmate.diploma_num, schmate.mobile_num);
		sethomefile(bufe, currentuser.userid, ".regextra");
		file_append(bufe, buf);
		do_report(".SCHOOLMATE", buf);
		register_send_email(urec, schmate.email);
	}
	screen_clear();
	tui_check_reg_mail();
}
示例#7
0
文件: bsdname.c 项目: basecq/q2dos
/*
 * BSD-style: \n
 * Make a FQDN from `hostname' & `def_domain'.
 * Set errno on failure and return -1.
 */
int W32_CALL gethostname (char *buffer, int buflen)
{
  /* the FQDN when no hostname has been set is "localhost.localdomain".
   * the FQDN when a hostname has been set, but no domname is set, is 'my_hostname'
   * the FQDN when both are set is 'my_hostname.my_domname'
   */
  const char *my_hostname = "localhost";
  const char *my_domname  = "localdomain";
  int   pos;

  if (!buffer || buflen < 0)
  {
    SOCK_ERRNO (EINVAL);
    return (-1);
  }
  if (buflen == 0)
     return (0);

#if (DOSX)
  if (!valid_addr((DWORD)buffer, buflen))
  {
    SOCK_ERRNO (EFAULT);
    return (-1);
  }
#endif

  if (*hostname) /* otherwise use localhost.localdomain */
  {
    my_hostname = hostname;
    my_domname  = NULL;         /* have hostname but no domain name */
    if (def_domain && *def_domain)
       my_domname = def_domain;
  }
  pos = 0;
  while (pos < buflen && *my_hostname)
      buffer[pos++] = *my_hostname++;

  if (pos < buflen && my_domname)
  {
    buffer[pos++] = '.';
    /*@-nullderef@*/
    while (pos < buflen && *my_domname)
        buffer[pos++] = *my_domname++;
  }
  if (pos < buflen)
     buffer[pos] = '\0';
  return (0);
}
示例#8
0
文件: syscall.c 项目: henryxlau/OS
/* Return true if vaddr points to a valid user buffer of at most lim characters
 * in cur's page directory.  If zeroed is false, all lim characters are
 * checked.  If it is true, the checking stops at the first NUL ('\0')
 * character.  If zeroed is true and the buffer is otherwise valid but contains
 * no NUL ('\0') false is returned.
 */
static bool
valid_buffer (struct thread *cur, char *vaddr, int lim, bool zeroed)
{
    int i = 0;
    bool found_zero = false;

    for (i = 0; i < lim; i++) {
        if ( !valid_addr (cur, vaddr+i))
            return false;
        if ( zeroed && vaddr[i] == '\0' ) {
            found_zero = true;
            break;
        }
    }
    return (zeroed) ? found_zero : true;
}
示例#9
0
文件: addr.c 项目: troglobit/mcjoin
/* Find IPv4 address of default outbound LAN interface */
int getaddr(char *iface, struct in_addr *ina)
{
	struct ifaddrs *ifaddr, *ifa;
	char ifname[17] = { 0 };
	char buf[20] = { 0 };
	int rc = -1;

	if (!iface)
		iface = getifname(ifname, sizeof(ifname));

	rc = getifaddrs(&ifaddr);
	if (rc)
		return -1;

	for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
		if (!ifa->ifa_addr)
			continue;

		if (ifa->ifa_flags & IFF_LOOPBACK)
			continue;

		if (!(ifa->ifa_flags & IFF_MULTICAST))
			continue;

		if (ifa->ifa_addr->sa_family != AF_INET)
			continue;

		if (iface && strcmp(iface, ifa->ifa_name))
			continue;

		rc = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in),
				 buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
		if (!rc) {
			if (!inet_aton(buf, ina))
				continue;
			if (!valid_addr(ina))
				continue;
			break;
		}
	}
	freeifaddrs(ifaddr);

	if (rc || IN_ZERONET(ntohl(ina->s_addr)))
		return -1;

	return 0;
}
示例#10
0
文件: bsdname.c 项目: basecq/q2dos
/**
 * BSD-style: \n
 * Expects a "Fully Qualified Domain Name" in `fqdn'.
 * Split at first `.' and extract `hostname' and `def_domain'.
 * Set errno on failure and return -1.
 */
int W32_CALL sethostname (const char *fqdn, int len)
{
  int pos;

  if (!fqdn || !*fqdn || len < 0 || len > MAX_HOSTLEN)
  {
    SOCK_ERRNO (EINVAL);
    return (-1);
  }

#if (DOSX)
  if (!valid_addr((DWORD)fqdn, len))
  {
    SOCK_ERRNO (EFAULT);
    return (-1);
  }
#endif

  pos = 0;
  while (pos < len && fqdn[pos] != '.')
  {
    if (!fqdn[pos]) /* should do complete alpha/digit/underscore check here */
    {
      pos = 0;
      break;
    }
    pos++;
  }
  if (pos == 0) /* leading '.' or invalid char in name */
  {
    SOCK_ERRNO (EINVAL);
    return (-1);
  }
  if (pos >= SIZEOF(hostname))
  {
    SOCK_ERRNO (ERANGE);
    return (-1);
  }
  if (fqdn[pos] == '.') /* a trailing '.' is ok too */
  {
    if (setdomainname(&fqdn[pos+1], len-pos) != 0)
       return (-1);
  }
  memcpy (&hostname[0], fqdn, pos);
  hostname[pos] = '\0';
  return (0);
}
示例#11
0
文件: bsdname.c 项目: basecq/q2dos
/**
 * BSD-style: \n
 * Set the host's domain name.
 * Set errno on failure and return -1.
 */
int W32_CALL setdomainname (const char *name, int len)
{
  if (!name || len < 0 || len > SIZEOF(defaultdomain)-1)
  {
    SOCK_ERRNO (EINVAL);
    return (-1);
  }

#if (DOSX)
  if (!valid_addr((DWORD)name, len))
  {
    SOCK_ERRNO (EFAULT);
    return (-1);
  }
#endif

  def_domain = StrLcpy (defaultdomain, name, len);
  return (0);
}
示例#12
0
文件: level2.c 项目: yuxinvalo/malloc
int main(void)
{
    void *test = malloc(sizeof(int) * 20);
    int i =  valid_addr(test);
    printf("now free time, i is %i: ----------\n",i);
    free(test);
    printf("\n\n");
    void *test1 = malloc(564);
    printf("\n\n");
    void *test3 = malloc(8);
    printf("\n\n");
    printf("now free time test3: ----------\n");
    free(test3);
    void *test5 = malloc(1200);
    printf("\n\n");
    printf("now free time test3 and test 5: ----------\n");
    free(test1);
    free(test5);

    return 0;
}
示例#13
0
文件: bsdname.c 项目: basecq/q2dos
/**
 * BSD-style: \n
 * Return domain name of this host.
 * As per BSD spec, the resultant buffer ...
 * ... "will be null-terminated _unless_there_is_insufficient_space_";
 *
 * Set errno on failure and return -1.
 */
int W32_CALL getdomainname (char *buffer, int buflen)
{
  const char *my_domainname = def_domain ? def_domain : "";

  if (!buffer || buflen < 0 || buflen < (int)strlen(my_domainname))
  {
    SOCK_ERRNO (EINVAL);
    return (-1);
  }
#if (DOSX)
  if (!valid_addr((DWORD)buffer, buflen))
  {
    SOCK_ERRNO (EFAULT);
    return (-1);
  }
#endif

  strncpy (buffer, my_domainname, buflen);
  /* no terminating '\0' needs to be forced here per bsd spec */
  return (0);
}
示例#14
0
void bf_free (void * ptr ){
  t_block b;
  if (valid_addr(ptr)){
    //we get the block address		      
    b = get_block(ptr);
    b->free = 1;
    //fusion with previous if possible	       
    if (b->prev && b->prev->free)
      b = fusion(b->prev);
    //then try to fusion with next	       
    if(b->next)
      fusion(b);
    else
      //if we're the last block, we release memory                                      
      if(b->prev)
	b->prev->next = NULL;
      else
	//no more block                                                                                                                                                            
	base = NULL;
    brk(b);//put break at chunk position                                                                                                                                         
  }
}
示例#15
0
void mm_free(void* ptr)
{
#ifdef MM_USE_STUBS
    free(ptr);
#else
    s_block_ptr b;
    if (valid_addr(ptr)){
        b = get_block(ptr);
        b->free = 1;
        if(b->prev && b->prev->free) b = fusion(b->prev);
        if(b->next){
            fusion(b);
        }
        else{
            if(b->prev) b->prev->next = NULL;
            else base = NULL;
            brk(b);
        }
    }
    //#error Not implemented.
#endif
}
示例#16
0
/*Realise Realloc is a little like free function, 
 *just collect all the block allocated, and copy it to a new memory
 *by "mumcyp", then split, fusion.
 */
void *realloc(void *ptr, size_t size)
{
	t_block b, newb;
	size_t temp_s = size;
	void *newptr;
	if (!ptr)
		return (malloc(size));

	if (valid_addr(ptr))
	{
		b = get_block(ptr);
		if (b->size >= temp_s)
			{
				if (b->size - temp_s >= (BLOCK_SIZE + 8))
				{
					split_block(b, temp_s);
				}
			}
			else
			{
				
			}
	}
}
示例#17
0
文件: syscall.c 项目: henryxlau/OS
/*
 * Parse the signature from cur's address space starting from stack pointer
 * esp.  Each parameter must be valid.  Value entries in the signature are
 * overwritten.  Return true if the whole signature was parsed.
 */
static bool
get_args (struct syscall_signature *sig, void *esp, struct thread *cur)
{
    int nvar = sig->nparams;
    int i =0;

    for (i = 0; i < nvar; i++) {
        if (!valid_addr (cur, esp) ) return false;
        switch (sig->param[i].type) {
        case SYSCALL_PTR:
        {
            /* Interpret esp as a pointer to a void *, get the void * into the
             * current parameter value and advnace esp */
            void **pesp = (void **) esp;
            sig->param[i].value.pval = *pesp;
            pesp++;
            esp = (void *) pesp;
            break;
        }
        case SYSCALL_INT:
        {
            /* Interpret esp as a pointer to an int get the int into the
             * current parameter value and advnace esp */
            int *iesp = (int *) esp;
            sig->param[i].value.ival = *iesp;
            iesp++;
            esp = (void *) iesp;
            break;
        }
        default:
            /* Unknown parameter type */
            return false;
        }
    }
    return true;
}
示例#18
0
int main(int argc, char *argv[]) {
	if (argc < 2) {
		usage(argv[0]);
	}

	if ((fin = fopen(argv[1], "rb")) == 0) {
		fprintf(stderr, "Error: could not open file\n");
		exit(1);
	}

	BYTE *fbuf = (BYTE *) malloc(16 * sizeof(BYTE));
	pe = (PESTRUCT *) malloc(sizeof(PESTRUCT));

	parse_pe_header();

	printf("EP RVA: %.8X\n", pe->rvaep);
	printf("Code section RVA: %.8X\n", pe->rvacode);
	printf("Data section RVA: %.8X\n", pe->rvadata);
	printf("Image base: %.8X\n", pe->imagebase);
	printf("Size of code section: %.8X\n", pe->codesize);

	/* Get size of headers to know where code section starts */
	fseek(fin, pe->offset + 84, SEEK_SET);
	fgets(fbuf, 4, fin);
	pe->codeoffset = lendian(fbuf, 4);
	printf("Code section offset: %.8X\n", pe->codeoffset);

	/* Get OEP address */
	pe->oep = pe->imagebase + pe->rvacode;
	printf("OEP address: %.8X\n", pe->oep);

	printf("\n");	// Formatting

	/* Get max offset from total file size */
	fseek(fin, 0L, SEEK_END);
	pe->maxoffset = ftell(fin);

	fseek(fin, pe->codeoffset, SEEK_SET);	// Go to start of code section

	DWORD len;
	DWORD cur_addr = pe->oep;	// First instruction at OEP
	DWORD addr;
	int i;
	int quit = 0;

	/* Start parsing and outputting 50 instructions at a time, waiting for user input after each block */
	while (!feof(fin) && !quit) {
		printf(":");

		/* Wait for user input */
		int ch = _getch();
		printf("\b");	// Erase character
		switch (ch) {
		case KEY_ESC:	// Quit
		case 'q':
			quit = 1;
			break;
		case 'n':	// Next instruction
			print_instr(&cur_addr);
			break;
		case ' ':	// Next 32 instructions
			print_ninstr(&cur_addr, 50);
			break;
		case 'o':	// Go back to OEP
			printf("\r \n");	// Clear line
			printf("EP RVA: %.8X\n", pe->rvaep);
			printf("Code section RVA: %.8X\n", pe->rvacode);
			printf("Data section RVA: %.8X\n", pe->rvadata);
			printf("Image base: %.8X\n", pe->imagebase);
			printf("Size of code section: %.8X\n", pe->codesize);
			printf("Code section offset: %.8X\n", pe->codeoffset);
			printf("OEP address: %.8X\n", pe->oep);
			printf("\n");
			fseek(fin, pe->codeoffset, SEEK_SET);
			cur_addr = pe->oep;
			break;
		case 'g': {	// Go to specific address
			printf("\r \n");	// Clear line
			printf("Go to address: ");
			char getaddr[32];
			fgets(getaddr, sizeof(getaddr), stdin);	// Get input
			if (getaddr[0] == '\n' || getaddr[0] == '\r') { printf("\n"); break; }	// Blank input (cancel instruction)
			addr = strtol(getaddr, NULL, 16);	// Parse input address
			if (!print_instr(&addr)) break;	// Print the first instruction
			cur_addr = addr;
			break;
		}
		case 'f': {	// Follow instruction at specific address
			printf("\r \n");	// Clear line
			printf("Address of instruction to follow: ");
			char addrstr[32];
			fgets(addrstr, sizeof(addrstr), stdin);	// Get input
			if (addrstr[0] == '\n' || addrstr[0] == '\r') { printf("\n"); break; }	// Blank input (cancel instruction)
			addr = strtol(addrstr, NULL, 16);
			char *instr = get_instr(addr);
			if (!instr) break;	// Error
			printf("%.8X\t%s\n", addr, instr);	// Print instruction to follow
			printf("\t\tv\n");
			addr = parse_addr(instr);
			if (!print_instr(&addr)) break;
			cur_addr = addr;
			free(instr);
			break;
		}
		case 'd': {	// Dump data at specific address
			printf("\r \n");	// Clear line
			printf("Address to dump: ");
			char addrstr[32];
			fgets(addrstr, sizeof(addrstr), stdin);	// Get input
			if (addrstr[0] == '\n' || addrstr[0] == '\r') { printf("\n"); break; }	// Blank input (cancel instruction)
			addr = strtol(addrstr, NULL, 16);
			if (!valid_addr(addr)) {
				printf("Address out of bounds\n");
				break;
			}
			printf("Number of bytes to dump (default 16): ");
			char bytesstr[3];
			fgets(bytesstr, sizeof(bytesstr), stdin);
			int bytes = strtol(bytesstr, NULL, 10);
			if (bytes == 0) bytes = 16;
			if (bytes > DUMP_MAX) {
				printf("Too high\n");
				break;
			}
			print_dump(addr, bytes);
			printf("\n");	// Formatting
			break;
		}
		case 's': {	// Search for a string in .data, .rdata, and .rsrc sections (no unicode support)
			printf("\r \n");	// Clear line
			printf("Search for string: ");
			char searchstr[STRLEN_MAX];
			fgets(searchstr, sizeof(searchstr), stdin);	// Get input
			if (searchstr[0] == '\n' || searchstr[0] == '\r') { printf("\n"); break; }	// Blank input (cancel instruction)
			addr = find_string_addr(searchstr);	// Find address of string
			if (addr == 0) {
				printf("String not found\n");
			} else {
				print_dump_str(addr);	// Print dump of matched string
			}
			printf("\n");	// Formatting
			break;
		}
		case 'e': {	// Edit binary
			printf("\r \n");	// Clear line
			printf("Starting address for editing: ");
			char addrstr[32];
			fgets(addrstr, sizeof(addrstr), stdin);	// Get input
			if (addrstr[0] == '\n' || addrstr[0] == '\r') { printf("\n"); break; }	// Blank input (cancel instruction)
			addr = strtol(addrstr, NULL, 16);
			if (!valid_addr(addr)) {
				printf("Address out of bounds\n");
				break;
			}
			printf("Input hex bytes: ");
			char bytestr[STRLEN_MAX];
			fgets(bytestr, sizeof(bytestr), stdin);	// Get input
			char *edit_file = (char *) calloc(strlen(argv[1]) + 6, sizeof(char));
			strncpy(edit_file, argv[1], strlen(argv[1]) - 4);
			strcat(edit_file, "_edit.exe");	// Edited file name: inputfilename_edit.exe
			save_edits_to_file(fin, edit_file, addr, bytestr);
			printf("Edited file %s saved\n\n", edit_file);
			free(edit_file);
			break;
		}
		case 'h':	// Show help
		case '?':
			print_help();
			break;

		// Special keys
		case SPECIAL_KEY:
			ch = _getch();
			switch (ch) {
			case KEY_DOWN:	// Next instruction
				print_instr(&cur_addr);
				break;
			case KEY_PGDN:	// Next 32 instructions
				print_ninstr(&cur_addr, 50);
				break;
			case KEY_HOME:	// Go back to OEP
				printf("\r \n");	// Clear line
				printf("EP RVA: %.8X\n", pe->rvaep);
				printf("Code section RVA: %.8X\n", pe->rvacode);
				printf("Data section RVA: %.8X\n", pe->rvadata);
				printf("Image base: %.8X\n", pe->imagebase);
				printf("Size of code section: %.8X\n", pe->codesize);
				printf("Code section offset: %.8X\n", pe->codeoffset);
				printf("OEP address: %.8X\n", pe->oep);
				printf("\n");
				fseek(fin, pe->codeoffset, SEEK_SET);
				cur_addr = pe->oep;
				break;
			default:
				//printf("0x%X\n", ch);	// DEBUGGING
				break;
			}
			break;

		default:
			//printf("0x%X\n", ch);	// DEBUGGING
			break;
		}

		fflush(stdin);
	}

	free(fbuf);
	free(pe);

	fclose(fin);

	return 0;
}
示例#19
0
void tui_check_reg_mail(void)
{
	//% char email[EMAIL_LEN] = "您的邮箱", file[HOMELEN], buf[RNDPASSLEN + 1];
	char email[EMAIL_LEN] = "\xc4\xfa\xb5\xc4\xd3\xca\xcf\xe4", file[HOMELEN], buf[RNDPASSLEN + 1];
	int i = 0;

	sethomefile(file, currentuser.userid, REG_CODE_FILE);
	if (!dashf(file)) {
		screen_move(1, 0);
		//% outs("    请输入您的复旦邮箱([email protected]/alu.fudan.edu.cn)\n"
		outs("    \xc7\xeb\xca\xe4\xc8\xeb\xc4\xfa\xb5\xc4\xb8\xb4\xb5\xa9\xd3\xca\xcf\xe4([email protected]/alu.fudan.edu.cn)\n"
				//% "    \033[1;32m本站采用复旦邮箱绑定认证,将发送认证码至您的复旦邮箱\033[m");
				"    \033[1;32m\xb1\xbe\xd5\xbe\xb2\xc9\xd3\xc3\xb8\xb4\xb5\xa9\xd3\xca\xcf\xe4\xb0\xf3\xb6\xa8\xc8\xcf\xd6\xa4\xa3\xac\xbd\xab\xb7\xa2\xcb\xcd\xc8\xcf\xd6\xa4\xc2\xeb\xd6\xc1\xc4\xfa\xb5\xc4\xb8\xb4\xb5\xa9\xd3\xca\xcf\xe4\033[m");
		do {
			getdata(3, 0, "    E-Mail:> ", email, sizeof(email), DOECHO, YEA);
			if (!valid_addr(email) || !register_domain_allowed(email)
					|| !register_email_allowed(email)) {
				//% prints("    对不起, 该email地址无效, 请重新输入 \n");
				prints("    \xb6\xd4\xb2\xbb\xc6\xf0, \xb8\xc3""email\xb5\xd8\xd6\xb7\xce\xde\xd0\xa7, \xc7\xeb\xd6\xd8\xd0\xc2\xca\xe4\xc8\xeb \n");
				continue;
			} else
				break;
		} while (1);

		register_send_email(&currentuser, email);
	}

	screen_move_clear(4);
	screen_move(5, 0);
	//% prints(" \033[1;33m   认证码已发送到 %s ,请查收\033[m\n", email);
	prints(" \033[1;33m   \xc8\xcf\xd6\xa4\xc2\xeb\xd2\xd1\xb7\xa2\xcb\xcd\xb5\xbd %s \xa3\xac\xc7\xeb\xb2\xe9\xca\xd5\033[m\n", email);

	screen_move(7, 0);
	//% if (askyn("    现在输入认证码么?", true, false)) {
	if (askyn("    \xcf\xd6\xd4\xda\xca\xe4\xc8\xeb\xc8\xcf\xd6\xa4\xc2\xeb\xc3\xb4\xa3\xbf", true, false)) {
		screen_move(9, 0);
		//% outs("请输入注册确认信里, \"认证码\"来做为身份确认\n");
		outs("\xc7\xeb\xca\xe4\xc8\xeb\xd7\xa2\xb2\xe1\xc8\xb7\xc8\xcf\xd0\xc5\xc0\xef, \"\xc8\xcf\xd6\xa4\xc2\xeb\"\xc0\xb4\xd7\xf6\xce\xaa\xc9\xed\xb7\xdd\xc8\xb7\xc8\xcf\n");
		//% prints("一共是 %d 个字符, 大小写是有差别的, 请注意.\n", RNDPASSLEN);
		prints("\xd2\xbb\xb9\xb2\xca\xc7 %d \xb8\xf6\xd7\xd6\xb7\xfb, \xb4\xf3\xd0\xa1\xd0\xb4\xca\xc7\xd3\xd0\xb2\xee\xb1\xf0\xb5\xc4, \xc7\xeb\xd7\xa2\xd2\xe2.\n", RNDPASSLEN);
		//% outs("请注意, 请输入最新一封认证信中所包含的乱数密码!\n\n"
		outs("\xc7\xeb\xd7\xa2\xd2\xe2, \xc7\xeb\xca\xe4\xc8\xeb\xd7\xee\xd0\xc2\xd2\xbb\xb7\xe2\xc8\xcf\xd6\xa4\xd0\xc5\xd6\xd0\xcb\xf9\xb0\xfc\xba\xac\xb5\xc4\xc2\xd2\xca\xfd\xc3\xdc\xc2\xeb\xa3\xa1\n\n"
				//% "\033[1;31m提示:注册码输错 3次后系统将要求您重填需绑定的邮箱。\033[m\n");
				"\033[1;31m\xcc\xe1\xca\xbe\xa3\xba\xd7\xa2\xb2\xe1\xc2\xeb\xca\xe4\xb4\xed 3\xb4\xce\xba\xf3\xcf\xb5\xcd\xb3\xbd\xab\xd2\xaa\xc7\xf3\xc4\xfa\xd6\xd8\xcc\xee\xd0\xe8\xb0\xf3\xb6\xa8\xb5\xc4\xd3\xca\xcf\xe4\xa1\xa3\033[m\n");

		for (i = 0; i < 3; i++) {
			screen_move(15, 0);
			//% prints("您还有 %d 次机会\n", 3 - i);
			prints("\xc4\xfa\xbb\xb9\xd3\xd0 %d \xb4\xce\xbb\xfa\xbb\xe1\n", 3 - i);
			//% getdata(16, 0, "请输入认证码: ", buf, sizeof(buf), DOECHO, YEA);
			getdata(16, 0, "\xc7\xeb\xca\xe4\xc8\xeb\xc8\xcf\xd6\xa4\xc2\xeb: ", buf, sizeof(buf), DOECHO, YEA);
			if (register_activate_email(currentuser.userid, buf))
				break;
		}
	}

	if (i == 3) {
		unlink(file);
		//% prints("认证失败! 请重填邮箱。\n");
		prints("\xc8\xcf\xd6\xa4\xca\xa7\xb0\xdc! \xc7\xeb\xd6\xd8\xcc\xee\xd3\xca\xcf\xe4\xa1\xa3\n");
		sethomefile(file, currentuser.userid, ".regextra");
		if (dashf(file))
			unlink(file);
		pressanykey();
	} else {
		//% prints("认证成功!\n");
		prints("\xc8\xcf\xd6\xa4\xb3\xc9\xb9\xa6!\n");
		sethomefile(file, currentuser.userid, ".regextra");
		if (dashf(file)) {
			//% prints("我们将暂时保留您的正常使用权限,如果核对您输入的个人信息有误将停止您的发文权限,\n");
			prints("\xce\xd2\xc3\xc7\xbd\xab\xd4\xdd\xca\xb1\xb1\xa3\xc1\xf4\xc4\xfa\xb5\xc4\xd5\xfd\xb3\xa3\xca\xb9\xd3\xc3\xc8\xa8\xcf\xde,\xc8\xe7\xb9\xfb\xba\xcb\xb6\xd4\xc4\xfa\xca\xe4\xc8\xeb\xb5\xc4\xb8\xf6\xc8\xcb\xd0\xc5\xcf\xa2\xd3\xd0\xce\xf3\xbd\xab\xcd\xa3\xd6\xb9\xc4\xfa\xb5\xc4\xb7\xa2\xce\xc4\xc8\xa8\xcf\xde,\n");
			//% prints("因此请确保您输入的是个人真实信息.\n");
			prints("\xd2\xf2\xb4\xcb\xc7\xeb\xc8\xb7\xb1\xa3\xc4\xfa\xca\xe4\xc8\xeb\xb5\xc4\xca\xc7\xb8\xf6\xc8\xcb\xd5\xe6\xca\xb5\xd0\xc5\xcf\xa2.\n");
		}
		if (!HAS_PERM(PERM_REGISTER)) {
			//% prints("请继续填写注册单。\n");
			prints("\xc7\xeb\xbc\xcc\xd0\xf8\xcc\xee\xd0\xb4\xd7\xa2\xb2\xe1\xb5\xa5\xa1\xa3\n");
		}
		pressanykey();
	}
}