int chanuser::updateDNSEntry() { adns::host2ip *info = resolver->getIp(host); if(info) { if(ip4) free(ip4); if(ip6) free(ip6); mem_strcpy(ip4, info->ip4); mem_strcpy(ip6, info->ip6); if(*ip4) dnsinfo |= HOST_IPV4; if(*ip6) dnsinfo |= HOST_IPV6; DEBUG(printf(">>> Updating: %s (%s, %s)\n", nick, ip4, ip6)); return 1; } return 0; }
void chanuser::setReason(const char *r) { if(reason) free(reason); mem_strcpy(reason, r); }
const char *str_pool_find( str_Pool pool, const char *s ) { const char *datum; poolInfo p = (poolInfo)pool; if ((datum = hsh_retrieve( p->hash, s ))) return datum; datum = mem_strcpy( p->string, s ); hsh_insert( p->hash, datum, datum ); return datum; }
chanuser::chanuser(const char *m, const chan *ch, const int f, const bool scan) #ifdef HAVE_MODULES : CustomDataStorage() #endif { char *a = strchr(m, '!'); char *b = strchr(m, '@'); reason = NULL; if(!a || !b) { memset(this, 0, sizeof(chanuser)); return; } mem_strncpy(nick, m, (int) abs(m - a) +1); mem_strncpy(ident, a+1, (int) abs(a - b)); mem_strcpy(host, b+1); flags = f; if(scan) flags |= userlist.getFlags(m, ch); hash = ::hash32(nick); handle = NULL; switch(isValidIp(host)) { case 4: dnsinfo = HOST_IPV4; mem_strcpy(ip4, host); mem_strcpy(ip6, ""); break; case 6: dnsinfo = HOST_IPV6; mem_strcpy(ip4, ""); mem_strcpy(ip6, host); break; default: dnsinfo = HOST_DOMAIN; mem_strcpy(ip4, ""); mem_strcpy(ip6, ""); break; } clones_to_check = CLONE_HOST | CLONE_IPV6 | CLONE_IPV4 | CLONE_IDENT | CLONE_PROXY; HOOK( onNewChanuser( this ) ); }
chanuser::chanuser(const char *str) #ifdef HAVE_MODULES : CustomDataStorage() #endif { char *a = strchr(str, '!'); if(a) mem_strncpy(nick, str, (int) abs(str - a) + 1); else mem_strcpy(nick, str); flags = 0; ident = NULL; host = NULL; hash = ::hash32(nick); handle = NULL; reason = NULL; ip4 = NULL; ip6 = NULL; HOOK( onNewChanuser( this ) ); }
/* load program text and initialized data into simulated virtual memory space and initialize program segment range variables */ void ld_load_prog(char *fname, /* program to load */ int argc, char **argv, /* simulated program cmd line args */ char **envp, /* simulated program environment */ struct regs_t *regs, /* registers to initialize for load */ struct mem_t *mem, /* memory space to load prog into */ int zero_bss_segs) /* zero uninit data segment? */ { int i; word_t temp; md_addr_t sp, data_break = 0, null_ptr = 0, argv_addr, envp_addr; FILE *fobj; struct elf_filehdr fhdr; struct elf_scnhdr shdr; byte_t *strtab, *buffer; if (eio_valid(fname)) { if (argc != 1) { fprintf(stderr, "error: EIO file has arguments\n"); exit(1); } fprintf(stderr, "sim: loading EIO file: %s\n", fname); sim_eio_fname = mystrdup(fname); /* open the EIO file stream */ sim_eio_fd = eio_open(fname); /* load initial state checkpoint */ if (eio_read_chkpt(regs, mem, sim_eio_fd) != -1) fatal("bad initial checkpoint in EIO file"); /* load checkpoint? */ if (sim_chkpt_fname != NULL) { counter_t restore_icnt; FILE *chkpt_fd; fprintf(stderr, "sim: loading checkpoint file: %s\n", sim_chkpt_fname); if (!eio_valid(sim_chkpt_fname)) fatal("file `%s' does not appear to be a checkpoint file", sim_chkpt_fname); /* open the checkpoint file */ chkpt_fd = eio_open(sim_chkpt_fname); /* load the state image */ restore_icnt = eio_read_chkpt(regs, mem, chkpt_fd); /* fast forward the baseline EIO trace to checkpoint location */ myfprintf(stderr, "sim: fast forwarding to instruction %n\n", restore_icnt); eio_fast_forward(sim_eio_fd, restore_icnt); } /* computed state... */ ld_environ_base = regs->regs_R[MD_REG_SP]; ld_prog_entry = regs->regs_PC; /* fini... */ return; } #ifdef MD_CROSS_ENDIAN else { warn("endian of `%s' does not match host", fname); warn("running with experimental cross-endian execution support"); warn("****************************************"); warn("**>> please check results carefully <<**"); warn("****************************************"); #if 0 fatal("SimpleScalar/ARM only supports binary execution on\n" " little-endian hosts, use EIO files on big-endian hosts"); #endif } #endif /* MD_CROSS_ENDIAN */ if (sim_chkpt_fname != NULL) fatal("checkpoints only supported while EIO tracing"); /* record profile file name */ ld_prog_fname = argv[0]; /* load the program into memory, try both endians */ #if defined(__CYGWIN32__) || defined(_MSC_VER) fobj = fopen(argv[0], "rb"); #else fobj = fopen(argv[0], "r"); #endif if (!fobj) fatal("cannot open executable `%s'", argv[0]); if (fread(&fhdr, sizeof(struct elf_filehdr), 1, fobj) < 1) fatal("cannot read header from executable `%s'", argv[0]); /* check if it is a valid ELF file */ if (!(fhdr.e_ident[EI_MAG0] == 0x7f && fhdr.e_ident[EI_MAG1] == 'E' && fhdr.e_ident[EI_MAG2] == 'L' && fhdr.e_ident[EI_MAG3] == 'F')) fatal("bad magic number in executable `%s' (not an executable)", argv[0]); /* check if the file is executable */ if (fhdr.e_type != ET_EXEC) fatal("object file `%s' is not executable", argv[0]); /* check if the file is for ARM architecture */ if (fhdr.e_machine != EM_ARM) fatal("executable file `%s' is not for the ARM architecture", argv[0]); ld_prog_entry = fhdr.e_entry; debug("number of sections in executable = %d\n", fhdr.e_shnum); debug("offset to section header table = %d", fhdr.e_shoff); /* seek to the beginning of the first section header, the file header comes first, followed by the optional header (this is the aouthdr), the size of the aouthdr is given in Fdhr.f_opthdr */ fseek(fobj, fhdr.e_shoff + (fhdr.e_shstrndx * fhdr.e_shentsize), SEEK_SET); if (fread(&shdr, sizeof(struct elf_scnhdr), 1, fobj) < 1) fatal("error reading string section header from `%s'", argv[0]); /* allocate space for string table */ strtab = (char *)calloc(shdr.sh_size, sizeof(char)); if (!strtab) fatal("out of virtual memory"); /* read the string table */ if (fseek(fobj, shdr.sh_offset, SEEK_SET) < 0) fatal("cannot seek to string table section"); if (fread(strtab, shdr.sh_size, 1, fobj) < 0) fatal("cannot read string table section"); debug("size of string table = %d", shdr.sh_size); debug("type of section = %d", shdr.sh_type); debug("offset of string table in file = %d", shdr.sh_offset); debug("processing %d sections in `%s'...", fhdr.e_shnum, argv[0]); /* loop through the section headers */ for (i=0; i < fhdr.e_shnum; i++) { buffer = NULL; if (fseek(fobj, fhdr.e_shoff + (i * fhdr.e_shentsize), SEEK_SET) < 0) fatal("could not reset location in executable"); if (fread(&shdr, sizeof(struct elf_scnhdr), 1, fobj) < 1) fatal("could not read section %d from executable", i); /* make sure the file is static */ if (shdr.sh_type == SHT_DYNAMIC || shdr.sh_type == SHT_DYNSYM) fatal("file is dynamically linked, compile with `-static'"); debug("processing section `%s'...", &strtab[shdr.sh_name]); debug(" section flags = 0x%08x", shdr.sh_flags); debug(" section type = %d", shdr.sh_type); debug(" section address = 0x%08x", shdr.sh_addr); debug(" section offset = %d", shdr.sh_offset); debug(" section size = %d", shdr.sh_size); debug(" section link = %d", shdr.sh_link); debug(" section extra info = %d", shdr.sh_info); debug(" section entry size = %d", shdr.sh_entsize); if (shdr.sh_addr != 0 && shdr.sh_size != 0 && (shdr.sh_type == SHT_PROGBITS || shdr.sh_type == SHT_NOBITS)) { /* if the ELF format designates an address for the section then load it into memory */ debug(" processing section `%s'...", &strtab[shdr.sh_name]); if ((shdr.sh_flags & SHF_ALLOC) != 0 && shdr.sh_type != SHT_NOBITS) { debug(" loading section `%s'...", &strtab[shdr.sh_name]); /* go to the offset in file where section is located */ if (fseek(fobj, shdr.sh_offset, SEEK_SET) < 0) fatal("cannot file pointer"); /* allocate memory for the section contents */ buffer = (char *)calloc(shdr.sh_size, sizeof(byte_t)); if (!buffer) fatal("out of virtual memory"); /* read section into buffer */ if (fread(buffer, shdr.sh_size, 1, fobj) < 1) fatal("could not read all the contents of section"); /* copy the section contents into simulator target memory */ mem_bcopy(mem_access, mem, Write, shdr.sh_addr, buffer, shdr.sh_size); } /* update program space limits */ if ((shdr.sh_flags & SHF_EXECINSTR) != 0) { debug("updating text size..."); if (shdr.sh_addr < ld_text_base) ld_text_base = shdr.sh_addr; if ((shdr.sh_addr + shdr.sh_size) > ld_text_bound) ld_text_bound = shdr.sh_addr + shdr.sh_size; } else { debug("updating data size..."); if (shdr.sh_addr < ld_data_base) ld_data_base = shdr.sh_addr; if ((shdr.sh_addr + shdr.sh_size) > ld_data_bound) ld_data_bound = shdr.sh_addr + shdr.sh_size; } ld_text_size = ld_text_bound - ld_text_base; ld_data_size = ld_data_bound - ld_data_base; /* release buffer storage */ if (buffer != NULL) free(buffer); } } /* release string table storage */ free(strtab); /* perform sanity checks on segment ranges */ if (!ld_text_base || !ld_text_size) fatal("executable is missing a `.text' section"); if (!ld_data_base || !ld_data_size) fatal("executable is missing a `.data' section"); if (!ld_prog_entry) fatal("program entry point not specified"); /* determine byte/words swapping required to execute on this host */ sim_swap_bytes = (endian_host_byte_order() != endian_target_byte_order()); if (sim_swap_bytes) { #if 0 /* FIXME: disabled until further notice... */ /* cross-endian is never reliable, why this is so is beyond the scope of this comment, e-mail me for details... */ fprintf(stderr, "sim: *WARNING*: swapping bytes to match host...\n"); fprintf(stderr, "sim: *WARNING*: swapping may break your program!\n"); /* #else */ fatal("binary endian does not match host endian"); #endif } sim_swap_words = (endian_host_word_order() != endian_target_word_order()); if (sim_swap_words) { #if 0 /* FIXME: disabled until further notice... */ /* cross-endian is never reliable, why this is so is beyond the scope of this comment, e-mail me for details... */ fprintf(stderr, "sim: *WARNING*: swapping words to match host...\n"); fprintf(stderr, "sim: *WARNING*: swapping may break your program!\n"); /* #else */ fatal("binary endian does not match host endian"); #endif } /* set up a local stack pointer, this is where the argv and envp data is written into program memory */ /* ld_stack_base = ld_text_base - (409600+4096); */ ld_stack_base = 0xc0000000; #if 0 sp = ROUND_DOWN(ld_stack_base - MD_MAX_ENVIRON, sizeof(MD_DOUBLE_TYPE)); #endif sp = ld_stack_base - MD_MAX_ENVIRON; ld_stack_size = ld_stack_base - sp; /* initial stack pointer value */ ld_environ_base = sp; /* write [argc] to stack */ temp = argc; mem_access(mem, Write, sp, &temp, sizeof(word_t)); regs->regs_R[MD_REG_R1] = temp; sp += sizeof(word_t); /* skip past argv array and NULL */ argv_addr = sp; regs->regs_R[MD_REG_R2] = argv_addr; sp = sp + (argc + 1) * sizeof(md_addr_t); /* save space for envp array and NULL */ envp_addr = sp; for (i=0; envp[i]; i++) sp += sizeof(md_addr_t); sp += sizeof(md_addr_t); /* fill in the argv pointer array and data */ for (i=0; i<argc; i++) { /* write the argv pointer array entry */ temp = sp; mem_access(mem, Write, argv_addr + i*sizeof(md_addr_t), &temp, sizeof(md_addr_t)); /* and the data */ mem_strcpy(mem_access, mem, Write, sp, argv[i]); sp += strlen(argv[i])+1; } /* terminate argv array with a NULL */ mem_access(mem, Write, argv_addr + i*sizeof(md_addr_t), &null_ptr, sizeof(md_addr_t)); /* write envp pointer array and data to stack */ for (i = 0; envp[i]; i++) { /* write the envp pointer array entry */ temp = sp; mem_access(mem, Write, envp_addr + i*sizeof(md_addr_t), &temp, sizeof(md_addr_t)); /* and the data */ mem_strcpy(mem_access, mem, Write, sp, envp[i]); sp += strlen(envp[i]) + 1; } /* terminate the envp array with a NULL */ mem_access(mem, Write, envp_addr + i*sizeof(md_addr_t), &null_ptr, sizeof(md_addr_t)); /* did we tromp off the stop of the stack? */ if (sp > ld_stack_base) { /* we did, indicate to the user that MD_MAX_ENVIRON must be increased, alternatively, you can use a smaller environment, or fewer command line arguments */ fatal("environment overflow, increase MD_MAX_ENVIRON in arm.h"); } /* initialize the bottom of heap to top of data segment */ ld_brk_point = ROUND_UP(ld_data_base + ld_data_size, MD_PAGE_SIZE); /* set initial minimum stack pointer value to initial stack value */ ld_stack_min = regs->regs_R[MD_REG_SP]; regs->regs_R[MD_REG_SP] = ld_environ_base; regs->regs_PC = ld_prog_entry; debug("ld_text_base: 0x%08x ld_text_size: 0x%08x", ld_text_base, ld_text_size); debug("ld_data_base: 0x%08x ld_data_size: 0x%08x", ld_data_base, ld_data_size); debug("ld_stack_base: 0x%08x ld_stack_size: 0x%08x", ld_stack_base, ld_stack_size); debug("ld_prog_entry: 0x%08x", ld_prog_entry); }
/* load program text and initialized data into simulated virtual memory space and initialize program segment range variables */ void ld_load_prog(char *fname, /* program to load */ int argc, char **argv, /* simulated program cmd line args */ char **envp, /* simulated program environment */ struct regs_t *regs, /* registers to initialize for load */ struct mem_t *mem, /* memory space to load prog into */ int zero_bss_segs) /* zero uninit data segment? */ { int i; qword_t temp; md_addr_t sp, data_break = 0, null_ptr = 0, argv_addr, envp_addr; if (eio_valid(fname)) { if (argc != 1) { fprintf(stderr, "error: EIO file has arguments\n"); exit(1); } fprintf(stderr, "sim: loading EIO file: %s\n", fname); sim_eio_fname = mystrdup(fname); /* open the EIO file stream */ sim_eio_fd = eio_open(fname); /* load initial state checkpoint */ if (eio_read_chkpt(regs, mem, sim_eio_fd) != -1) fatal("bad initial checkpoint in EIO file"); /* load checkpoint? */ if (sim_chkpt_fname != NULL) { counter_t restore_icnt; FILE *chkpt_fd; fprintf(stderr, "sim: loading checkpoint file: %s\n", sim_chkpt_fname); if (!eio_valid(sim_chkpt_fname)) fatal("file `%s' does not appear to be a checkpoint file", sim_chkpt_fname); /* open the checkpoint file */ chkpt_fd = eio_open(sim_chkpt_fname); /* load the state image */ restore_icnt = eio_read_chkpt(regs, mem, chkpt_fd); /* fast forward the baseline EIO trace to checkpoint location */ myfprintf(stderr, "sim: fast forwarding to instruction %n\n", restore_icnt); eio_fast_forward(sim_eio_fd, restore_icnt); } /* computed state... */ ld_environ_base = regs->regs_R[MD_REG_SP]; ld_prog_entry = regs->regs_PC; /* fini... */ return; } #ifdef MD_CROSS_ENDIAN else { warn("endian of `%s' does not match host", fname); warn("running with experimental cross-endian execution support"); warn("****************************************"); warn("**>> please check results carefully <<**"); warn("****************************************"); #if 0 fatal("SimpleScalar/Alpha only supports binary execution on\n" " little-endian hosts, use EIO files on big-endian hosts"); #endif } #endif /* MD_CROSS_ENDIAN */ if (sim_chkpt_fname != NULL) fatal("checkpoints only supported while EIO tracing"); #ifdef BFD_LOADER { bfd *abfd; asection *sect; /* set up a local stack pointer, this is where the argv and envp data is written into program memory */ ld_stack_base = MD_STACK_BASE; sp = ROUND_DOWN(MD_STACK_BASE - MD_MAX_ENVIRON, sizeof(MD_DOUBLE_TYPE)); ld_stack_size = ld_stack_base - sp; printf("Thread 0 stack size (3)%d\n", current->ld_stack_size); /* initial stack pointer value */ ld_environ_base = sp; /* load the program into memory, try both endians */ if (!(abfd = bfd_openr(argv[0], "ss-coff-big"))) if (!(abfd = bfd_openr(argv[0], "ss-coff-little"))) fatal("cannot open executable `%s'", argv[0]); /* this call is mainly for its side effect of reading in the sections. we follow the traditional behavior of `strings' in that we don't complain if we don't recognize a file to be an object file. */ if (!bfd_check_format(abfd, bfd_object)) { bfd_close(abfd); fatal("cannot open executable `%s'", argv[0]); } /* record profile file name */ ld_prog_fname = argv[0]; /* record endian of target */ ld_target_big_endian = abfd->xvec->byteorder_big_p; debug("processing %d sections in `%s'...", bfd_count_sections(abfd), argv[0]); /* read all sections in file */ for (sect=abfd->sections; sect; sect=sect->next) { char *p; debug("processing section `%s', %d bytes @ 0x%08x...", bfd_section_name(abfd, sect), bfd_section_size(abfd, sect), bfd_section_vma(abfd, sect)); /* read the section data, if allocated and loadable and non-NULL */ if ((bfd_get_section_flags(abfd, sect) & SEC_ALLOC) && (bfd_get_section_flags(abfd, sect) & SEC_LOAD) && bfd_section_vma(abfd, sect) && bfd_section_size(abfd, sect)) { /* allocate a section buffer */ p = calloc(bfd_section_size(abfd, sect), sizeof(char)); if (!p) fatal("cannot allocate %d bytes for section `%s'", bfd_section_size(abfd, sect), bfd_section_name(abfd, sect)); if (!bfd_get_section_contents(abfd, sect, p, (file_ptr)0, bfd_section_size(abfd, sect))) fatal("could not read entire `%s' section from executable", bfd_section_name(abfd, sect)); /* copy program section it into simulator target memory */ mem_bcopy(mem_fn, Write, bfd_section_vma(abfd, sect), p, bfd_section_size(abfd, sect)); /* release the section buffer */ free(p); } /* zero out the section if it is loadable but not allocated in exec */ else if (zero_bss_segs && (bfd_get_section_flags(abfd, sect) & SEC_LOAD) && bfd_section_vma(abfd, sect) && bfd_section_size(abfd, sect)) { /* zero out the section region */ mem_bzero(mem_fn, bfd_section_vma(abfd, sect), bfd_section_size(abfd, sect)); } else { /* else do nothing with this section, it's probably debug data */ debug("ignoring section `%s' during load...", bfd_section_name(abfd, sect)); } /* expected text section */ if (!strcmp(bfd_section_name(abfd, sect), ".text")) { /* .text section processing */ ld_text_size = ((bfd_section_vma(abfd, sect) + bfd_section_size(abfd, sect)) - MD_TEXT_BASE) + /* for speculative fetches/decodes */TEXT_TAIL_PADDING; /* create tail padding and copy into simulator target memory */ #if 0 mem_bzero(mem_fn, bfd_section_vma(abfd, sect) + bfd_section_size(abfd, sect), TEXT_TAIL_PADDING); #endif } /* expected data sections */ else if (!strcmp(bfd_section_name(abfd, sect), ".rdata") || !strcmp(bfd_section_name(abfd, sect), ".data") || !strcmp(bfd_section_name(abfd, sect), ".sdata") || !strcmp(bfd_section_name(abfd, sect), ".bss") || !strcmp(bfd_section_name(abfd, sect), ".sbss")) { /* data section processing */ if (bfd_section_vma(abfd, sect) + bfd_section_size(abfd, sect) > data_break) data_break = (bfd_section_vma(abfd, sect) + bfd_section_size(abfd, sect)); } else { /* what is this section??? */ fatal("encountered unknown section `%s', %d bytes @ 0x%08x", bfd_section_name(abfd, sect), bfd_section_size(abfd, sect), bfd_section_vma(abfd, sect)); } } /* compute data segment size from data break point */ ld_text_base = MD_TEXT_BASE; ld_data_base = MD_DATA_BASE; ld_prog_entry = bfd_get_start_address(abfd); ld_data_size = data_break - ld_data_base; /* done with the executable, close it */ if (!bfd_close(abfd)) fatal("could not close executable `%s'", argv[0]); } #else /* !BFD_LOADER, i.e., standalone loader */ { FILE *fobj; long floc; struct ecoff_filehdr fhdr; struct ecoff_aouthdr ahdr; struct ecoff_scnhdr shdr; /* record profile file name */ ld_prog_fname = argv[0]; /* load the program into memory, try both endians */ #if defined(__CYGWIN32__) || defined(_MSC_VER) fobj = fopen(argv[0], "rb"); #else fobj = fopen(argv[0], "r"); #endif if (!fobj) fatal("cannot open executable `%s'", argv[0]); if (fread(&fhdr, sizeof(struct ecoff_filehdr), 1, fobj) < 1) fatal("cannot read header from executable `%s'", argv[0]); /* record endian of target */ if (fhdr.f_magic == MD_SWAPH(ECOFF_ALPHAMAGIC)) ld_target_big_endian = FALSE; else if (fhdr.f_magic == MD_SWAPH(ECOFF_EB_MAGIC) || fhdr.f_magic == MD_SWAPH(ECOFF_EL_MAGIC) || fhdr.f_magic == MD_SWAPH(ECOFF_EB_OTHER) || fhdr.f_magic == MD_SWAPH(ECOFF_EL_OTHER)) fatal("Alpha simulator cannot run PISA binary `%s'", argv[0]); else fatal("bad magic number in executable `%s' (not an executable)", argv[0]); if (fread(&ahdr, sizeof(struct ecoff_aouthdr), 1, fobj) < 1) fatal("cannot read AOUT header from executable `%s'", argv[0]); ld_text_base = MD_SWAPQ(ahdr.text_start); ld_text_size = MD_SWAPQ(ahdr.tsize); ld_prog_entry = MD_SWAPQ(ahdr.entry); ld_data_base = MD_SWAPQ(ahdr.data_start); ld_data_size = MD_SWAPQ(ahdr.dsize) + MD_SWAPQ(ahdr.bsize); regs->regs_R[MD_REG_GP] = MD_SWAPQ(ahdr.gp_value); /* compute data segment size from data break point */ data_break = ld_data_base + ld_data_size; /* seek to the beginning of the first section header, the file header comes first, followed by the optional header (this is the aouthdr), the size of the aouthdr is given in Fdhr.f_opthdr */ fseek(fobj, sizeof(struct ecoff_filehdr) + MD_SWAPH(fhdr.f_opthdr), 0); debug("processing %d sections in `%s'...", MD_SWAPH(fhdr.f_nscns), argv[0]); /* loop through the section headers */ floc = ftell(fobj); for (i = 0; i < MD_SWAPH(fhdr.f_nscns); i++) { char *p; if (fseek(fobj, floc, 0) == -1) fatal("could not reset location in executable"); if (fread(&shdr, sizeof(struct ecoff_scnhdr), 1, fobj) < 1) fatal("could not read section %d from executable", i); floc = ftell(fobj); switch (MD_SWAPW(shdr.s_flags)) { case ECOFF_STYP_TEXT: p = calloc(MD_SWAPQ(shdr.s_size), sizeof(char)); if (!p) fatal("out of virtual memory"); if (fseek(fobj, MD_SWAPQ(shdr.s_scnptr), 0) == -1) fatal("could not read `.text' from executable", i); if (fread(p, MD_SWAPQ(shdr.s_size), 1, fobj) < 1) fatal("could not read text section from executable"); /* copy program section into simulator target memory */ mem_bcopy(mem_access, mem, Write, MD_SWAPQ(shdr.s_vaddr), p, MD_SWAPQ(shdr.s_size)); #if 0 /* create tail padding and copy into simulator target memory */ mem_bzero(mem_access, mem, MD_SWAPQ(shdr.s_vaddr) + MD_SWAPQ(shdr.s_size), TEXT_TAIL_PADDING); #endif /* release the section buffer */ free(p); #if 0 Text_seek = MD_SWAPQ(shdr.s_scnptr); Text_start = MD_SWAPQ(shdr.s_vaddr); Text_size = MD_SWAPQ(shdr.s_size) / 4; /* there is a null routine after the supposed end of text */ Text_size += 10; Text_end = Text_start + Text_size * 4; /* create_text_reloc(shdr.s_relptr, shdr.s_nreloc); */ #endif break; case ECOFF_STYP_INIT: case ECOFF_STYP_FINI: if (MD_SWAPQ(shdr.s_size) > 0) { p = calloc(MD_SWAPQ(shdr.s_size), sizeof(char)); if (!p) fatal("out of virtual memory"); if (fseek(fobj, MD_SWAPQ(shdr.s_scnptr), 0) == -1) fatal("could not read `.text' from executable", i); if (fread(p, MD_SWAPQ(shdr.s_size), 1, fobj) < 1) fatal("could not read text section from executable"); /* copy program section into simulator target memory */ mem_bcopy(mem_access, mem, Write, MD_SWAPQ(shdr.s_vaddr), p, MD_SWAPQ(shdr.s_size)); /* release the section buffer */ free(p); } else warn("section `%s' is empty...", shdr.s_name); break; case ECOFF_STYP_LITA: case ECOFF_STYP_LIT8: case ECOFF_STYP_LIT4: case ECOFF_STYP_XDATA: case ECOFF_STYP_PDATA: case ECOFF_STYP_RCONST: /* fall through */ case ECOFF_STYP_RDATA: /* The .rdata section is sometimes placed before the text * section instead of being contiguous with the .data section. */ #if 0 Rdata_start = MD_SWAPQ(shdr.s_vaddr); Rdata_size = MD_SWAPQ(shdr.s_size); Rdata_seek = MD_SWAPQ(shdr.s_scnptr); #endif /* fall through */ case ECOFF_STYP_DATA: #if 0 Data_seek = MD_SWAPQ(shdr.s_scnptr); #endif /* fall through */ case ECOFF_STYP_SDATA: #if 0 Sdata_seek = MD_SWAPQ(shdr.s_scnptr); #endif if (MD_SWAPQ(shdr.s_size) > 0) { p = calloc(MD_SWAPQ(shdr.s_size), sizeof(char)); if (!p) fatal("out of virtual memory"); if (fseek(fobj, MD_SWAPQ(shdr.s_scnptr), 0) == -1) fatal("could not read `.text' from executable", i); if (fread(p, MD_SWAPQ(shdr.s_size), 1, fobj) < 1) fatal("could not read text section from executable"); /* copy program section it into simulator target memory */ mem_bcopy(mem_access, mem, Write, MD_SWAPQ(shdr.s_vaddr), p, MD_SWAPQ(shdr.s_size)); /* release the section buffer */ free(p); } else warn("section `%s' is empty...", shdr.s_name); break; case ECOFF_STYP_BSS: case ECOFF_STYP_SBSS: /* no data to read... */ break; default: warn("section `%s' ignored...", shdr.s_name); } } /* done with the executable, close it */ if (fclose(fobj)) fatal("could not close executable `%s'", argv[0]); } #endif /* BFD_LOADER */ /* perform sanity checks on segment ranges */ if (!ld_text_base || !ld_text_size) fatal("executable is missing a `.text' section"); if (!ld_data_base || !ld_data_size) fatal("executable is missing a `.data' section"); if (!ld_prog_entry) fatal("program entry point not specified"); /* determine byte/words swapping required to execute on this host */ sim_swap_bytes = (endian_host_byte_order() != endian_target_byte_order()); if (sim_swap_bytes) { #if 0 /* FIXME: disabled until further notice... */ /* cross-endian is never reliable, why this is so is beyond the scope of this comment, e-mail me for details... */ fprintf(stderr, "sim: *WARNING*: swapping bytes to match host...\n"); fprintf(stderr, "sim: *WARNING*: swapping may break your program!\n"); /* #else */ fatal("binary endian does not match host endian"); #endif } sim_swap_words = (endian_host_word_order() != endian_target_word_order()); if (sim_swap_words) { #if 0 /* FIXME: disabled until further notice... */ /* cross-endian is never reliable, why this is so is beyond the scope of this comment, e-mail me for details... */ fprintf(stderr, "sim: *WARNING*: swapping words to match host...\n"); fprintf(stderr, "sim: *WARNING*: swapping may break your program!\n"); /* #else */ fatal("binary endian does not match host endian"); #endif } /* set up a local stack pointer, this is where the argv and envp data is written into program memory */ ld_stack_base = ld_text_base - (409600+4096); #if 0 sp = ROUND_DOWN(ld_stack_base - MD_MAX_ENVIRON, sizeof(MD_DOUBLE_TYPE)); #endif sp = ld_stack_base - MD_MAX_ENVIRON; ld_stack_size = ld_stack_base - sp; printf("Thread 0 stack size (4)%d\n", current->ld_stack_size); /* initial stack pointer value */ ld_environ_base = sp; /* write [argc] to stack */ temp = MD_SWAPQ(argc); mem_access(mem, Write, sp, &temp, sizeof(qword_t)); regs->regs_R[MD_REG_A0] = temp; sp += sizeof(qword_t); /* skip past argv array and NULL */ argv_addr = sp; regs->regs_R[MD_REG_A1] = argv_addr; sp = sp + (argc + 1) * sizeof(md_addr_t); /* save space for envp array and NULL */ envp_addr = sp; for (i=0; envp[i]; i++) sp += sizeof(md_addr_t); sp += sizeof(md_addr_t); /* fill in the argv pointer array and data */ for (i=0; i<argc; i++) { /* write the argv pointer array entry */ temp = MD_SWAPQ(sp); mem_access(mem, Write, argv_addr + i*sizeof(md_addr_t), &temp, sizeof(md_addr_t)); /* and the data */ mem_strcpy(mem_access, mem, Write, sp, argv[i]); sp += strlen(argv[i])+1; } /* terminate argv array with a NULL */ mem_access(mem, Write, argv_addr + i*sizeof(md_addr_t), &null_ptr, sizeof(md_addr_t)); /* write envp pointer array and data to stack */ for (i = 0; envp[i]; i++) { /* write the envp pointer array entry */ temp = MD_SWAPQ(sp); mem_access(mem, Write, envp_addr + i*sizeof(md_addr_t), &temp, sizeof(md_addr_t)); /* and the data */ mem_strcpy(mem_access, mem, Write, sp, envp[i]); sp += strlen(envp[i]) + 1; } /* terminate the envp array with a NULL */ mem_access(mem, Write, envp_addr + i*sizeof(md_addr_t), &null_ptr, sizeof(md_addr_t)); /* did we tromp off the stop of the stack? */ if (sp > ld_stack_base) { /* we did, indicate to the user that MD_MAX_ENVIRON must be increased, alternatively, you can use a smaller environment, or fewer command line arguments */ fatal("environment overflow, increase MD_MAX_ENVIRON in alpha.h"); } /* initialize the bottom of heap to top of data segment */ ld_brk_point = ROUND_UP(ld_data_base + ld_data_size, MD_PAGE_SIZE); /* set initial minimum stack pointer value to initial stack value */ ld_stack_min = regs->regs_R[MD_REG_SP]; regs->regs_R[MD_REG_SP] = ld_environ_base; regs->regs_PC = ld_prog_entry; printf("ld_text_base: 0x%08x ld_text_size: 0x%08x", ld_text_base, ld_text_size); printf("ld_data_base: 0x%08x ld_data_size: 0x%08x", ld_data_base, ld_data_size); printf("ld_stack_base: 0x%08x ld_stack_size: 0x%08x", ld_stack_base, ld_stack_size); printf("ld_prog_entry: 0x%08x", ld_prog_entry); debug("ld_text_base: 0x%08x ld_text_size: 0x%08x", ld_text_base, ld_text_size); debug("ld_data_base: 0x%08x ld_data_size: 0x%08x", ld_data_base, ld_data_size); debug("ld_stack_base: 0x%08x ld_stack_size: 0x%08x", ld_stack_base, ld_stack_size); debug("ld_prog_entry: 0x%08x", ld_prog_entry); }
void parse_hub(char *data) { char arg[10][MAX_LEN]; chan *ch; if(!strlen(data)) return; str2words(arg[0], data, 10, MAX_LEN); if(!(net.hub.status & STATUS_REGISTERED)) { switch(net.hub.tmpint) { /* case 0: { //3 bytes for WILL ECHO OFF + 1 byte for NEW LINE ++net.hub.tmpint; //enable encryption net.hub.enableCrypt((unsigned char *) config.botnetword, strlen(config.botnetword)); return; } */ case 1: { if(strlen(arg[0])) { char hash[33]; ++net.hub.tmpint; //unsigned char *dupa = ((entMD5Hash *) &config.currentHub->getPass())->getHash(); MD5HexHash(hash, arg[0], AUTHSTR_LEN, ((entMD5Hash *) &config.hub.getPass())->getHash(), 16); net.hub.send(config.handle, " ", hash, NULL); net.hub.tmpstr = (char *) malloc(AUTHSTR_LEN + 1); MD5CreateAuthString(net.hub.tmpstr, AUTHSTR_LEN); net.hub.send(net.hub.tmpstr, NULL); return; } break; } case 2: { if(strlen(arg[3])) { if(MD5HexValidate(arg[3], net.hub.tmpstr, strlen(net.hub.tmpstr), ((entMD5Hash *) &config.hub.getPass())->getHash(), 16)) { char buf[MAX_LEN]; ++net.hub.tmpint; userlist.addHandle(arg[0], 0, B_FLAGS | HAS_H | HAS_L, arg[1], arg[2], 0); net.hub.handle = userlist.findHandle(arg[0]); DEBUG(printf("[D] hub handle: %s\n", net.hub.handle->name)); free(net.hub.tmpstr); net.hub.tmpstr = NULL; if(config.bottype != BOT_SLAVE) sprintf(buf, "%llu", userlist.SN); else strcpy(buf, "0"); net.hub.send(S_REGISTER, " ", S_VERSION, " ", buf, " ", (const char *) ME.nick, " ", net.irc.origin, NULL); return; } } break; } case 3: { if(!strcmp(arg[0], S_REGISTER)) { mem_strcpy(net.hub.name, arg[1]); net.hub.tmpint = 0; net.hub.status |= STATUS_CONNECTED | STATUS_REGISTERED | STATUS_BOT; net.hub.killTime = NOW + set.CONN_TIMEOUT; net.hub.lastPing = NOW; net.hub.enableCrypt(((entMD5Hash *) &config.hub.getPass())->getHash(), 16); net.sendBotListTo(&net.hub); net.propagate(&net.hub, S_BJOIN, " ", net.hub.name, NULL); config.currentHub->failures = 0; net.propagate(NULL, S_CHNICK, " ", (const char *) ME.nick, " ", net.irc.origin, NULL); return; } } default: break; } /* HUH */ net.hub.close("Access Denied"); } /* REGISTERED HUB */ net.hub.killTime = NOW + set.CONN_TIMEOUT; if(!strcmp(arg[0], S_UL_UPLOAD_START)) { if(userlist.ulbuf) { net.send(HAS_N, "[!] Double UL download, this should not happen", NULL); sleep(5); net.send(HAS_N, "[!] Terminating.", NULL); exit(1337); } userlist.ulbuf = new Pchar(64*1024); return; } if(!strcmp(arg[0], S_UL_UPLOAD_END)) { if(!userlist.ulbuf) { net.send(HAS_N, "[!] Update userlist is empty", NULL); net.send(HAS_N, "[-] Disconnecting", NULL); net.hub.close("Userlist is empty"); return; } userlist.update(); if(userlist.me()->flags[GLOBAL] & HAS_P) hostNotify = 1; else hostNotify = 0; userlist.sendToAll(); return; } if(userlist.ulbuf) { userlist.ulbuf->push(data); userlist.ulbuf->push("\n"); return; } if(!strcmp(arg[0], S_CYCLE) && strlen(arg[1])) { if(ME.findChannel(arg[1])) { net.irc.send("PART ", arg[1], " :", (const char *) config.cyclereason, NULL); ME.rejoin(arg[1], set.CYCLE_DELAY); if(strlen(arg[2])) net.send(HAS_N, "[*] Doing cycle on ", arg[1], NULL); } net.propagate(&net.hub, data, NULL); return; } if(!strcmp(arg[0], S_MKA) && strlen(arg[1])) { ch = ME.findChannel(arg[1]); if(ch) ch->massKick(MK_ALL, !strcmp(arg[3], "close") || !strcmp(arg[3], "lock")); return; } if(!strcmp(arg[0], S_MKO) && strlen(arg[1])) { ch = ME.findChannel(arg[1]); if(ch) ch->massKick(MK_OPS, !strcmp(arg[3], "close") || !strcmp(arg[3], "lock")); return; } if(!strcmp(arg[0], S_MKN) && strlen(arg[1])) { ch = ME.findChannel(arg[1]); if(ch) ch->massKick(MK_NONOPS, !strcmp(arg[3], "close") || !strcmp(arg[3], "lock")); return; } if(!strcmp(arg[0], S_UNLINK) && strlen(arg[1])) { HANDLE *h = userlist.findHandle(arg[1]); if(h && userlist.isBot(h)) { inetconn *bot = net.findConn(h); if(bot) bot->close("Forced unlink"); } return; } if(!strcmp(arg[0], S_NICK) && strlen(arg[1])) { net.irc.send("NICK ", arg[1], NULL); ME.nextNickCheck = NOW + set.KEEP_NICK_CHECK_DELAY; return; } if(!strcmp(arg[0], S_JUMP) && strlen(arg[2])) { ME.jump(arg[2], arg[3], arg[1]); return; } #ifdef HAVE_IPV6 if(!strcmp(arg[0], S_JUMP6) && strlen(arg[2])) { ME.jump(arg[2], arg[3], arg[1], AF_INET6); return; } #endif if(!strcmp(arg[0], S_JUMPS5) && strlen(arg[5])) { ME.jumps5(arg[2], atoi(arg[3]), arg[4], atoi(arg[5]), arg[1]); return; } if(!strcmp(arg[0], S_RDIE) && strlen(arg[1])) { net.send(HAS_N, "[!] ", DIE_REASON, NULL); net.irc.send("QUIT :", arg[1], " ", DIE_REASON2, NULL); safeExit(); } if(!strcmp(arg[0], S_NAMES) && strlen(arg[2])) { ch = ME.findChannel(arg[2]); if(ch) ch->names(arg[1]); else net.sendOwner(arg[1], "Invalid channel", NULL); return; } if(!strcmp(arg[0], S_CWHO) && strlen(arg[2])) { ch = ME.findChannel(arg[2]); if(ch) ch->cwho(arg[1], arg[3]); else net.sendOwner(arg[1], "Invalid channel", NULL); return; } if(!strcmp(arg[0], S_PSOTUPDATE)) { psotget.forkAndGo(arg[1]); return; } if(!strcmp(arg[0], S_STOPUPDATE)) { psotget.end(); return; } if(!strcmp(arg[0], S_RESTART)) { ME.restart(); return; } if(!strcmp(arg[0], S_ULSAVE)) { userlist.save(config.userlist_file); ME.nextRecheck = NOW + 5; net.propagate(&net.hub, data, NULL); return; } if(!strcmp(arg[0], S_RJOIN) && strlen(arg[2])) { userlist.rjoin(arg[1], arg[2]); net.propagate(&net.hub, data, NULL); ++userlist.SN; return; } if(!strcmp(arg[0], S_RPART) && strlen(arg[2])) { userlist.rpart(arg[1], arg[2], arg[3]); net.propagate(&net.hub, data, NULL); ++userlist.SN; return; } if(!strcmp(arg[0], S_STATUS) && strlen(arg[1])) { ME.sendStatus(arg[1]); return; } if(!strcmp(arg[0], S_CHKHOST) && strlen(arg[1])) { ME.checkMyHost(arg[1]); return; } if(parse_botnet(&net.hub, data)) return; if(userlist.parse(data)) { ++userlist.SN; //some things should not be propagated if(config.bottype == BOT_SLAVE) { if(!strcmp(S_ADDBOT, arg[0])) { net.propagate(&net.hub, S_ADDBOT, " ", arg[1], " ", arg[2], " ", arg[3], " ", S_SECRET, NULL); return; } if(!strcmp(S_PASSWD, arg[0]) && userlist.isBot(arg[1])) { net.propagate(&net.hub, S_PASSWD, " ", arg[1], " ", "00000000000000000000000000000000", NULL); return; } if(!strcmp(S_ADDR, arg[0]) && userlist.isBot(arg[1])) { net.propagate(&net.hub, S_ADDR, " ", arg[1], " ", "0.0.0.0", NULL); return; } if(!strcmp(S_ADDOFFENCE, arg[0])) // leaf dont need infos about offence-history return; } net.propagate(&net.hub, data, NULL); return; } }
Comment::entry::entry(const char *k, const char *v) { mem_strcpy(value, v); mem_strcpy(key, k); }
const char *str_pool_copy( str_Pool pool, const char *s ) { poolInfo p = (poolInfo)pool; return mem_strcpy( p->string, s ); }