コード例 #1
0
ファイル: status.c プロジェクト: bitlair/siahsd
STATUS debug(int loglevel, const char *location, const char *function, ...)
{
	va_list ap;
	static char timebuf[100]; /* Static because this should not be reallocated 
	                             in case of out of memory errors */
	time_t rawtime;
	struct tm *timeinfo;
	size_t s;
	FILE *logfile;
	const configuration *conf = get_conf();

	if (loglevel > conf->log_level) {
		return ST_OK;
	}

	logfile = fopen(conf->log_file, "a");
	if (logfile == NULL) {
		if (conf->foreground) {
			fprintf(stderr, "Error opening log file: %s\n", strerror(errno));
		}
		return ST_GENERAL_FAILURE;
	}

	time(&rawtime);
	timeinfo = localtime(&rawtime);
	
	s = strftime(timebuf, sizeof(timebuf), "%c", timeinfo);
	if (s == 0) {
		const char *text = "Failed to get proper strftime formatted date\n";
		if (conf->foreground) {
			fprintf(stderr, "%s", text);
		}
		fprintf(logfile, "%s", text);
		fclose(logfile);
		return ST_GENERAL_FAILURE;
	}

	fprintf(logfile, "%s: %s(%d): Log level %d, at %s in function %s():\n",
	                 timebuf, get_process_name(), getpid(), loglevel, location, function);
	if (conf->foreground)
		fprintf(stderr, "%s: %s(%d): Log level %d, at %s in function %s():\n",
		                timebuf, get_process_name(), getpid(), loglevel, location, function);

	va_start(ap, function);
	vfprintf(logfile, va_arg(ap, char *), ap);
	va_end(ap);
	fputc('\n', logfile);

	if (conf->foreground) {
		va_start(ap, function);
		vfprintf(stderr, va_arg(ap, char *), ap);
		va_end(ap);
		fputc('\n', stderr);
	}

	fclose(logfile);

	return ST_OK;
}
コード例 #2
0
ファイル: logging_old.cpp プロジェクト: JamalAbuDayyeh/ospy
static void
message_element_init(MessageQueueElement *el,
                     const char *function_name,
                     void *bt_address,
                     DWORD resource_id,
                     MessageType msg_type)
{
    /* timestamp */
    GetLocalTime(&el->time);

    /* process name, id and thread id */
    get_process_name(el->process_name, sizeof(el->process_name));
    el->process_id = GetCurrentProcessId();      
    el->thread_id = GetCurrentThreadId();

    /* function name and return address */
    strncpy(el->function_name, function_name, sizeof(el->function_name));
	if (bt_address != NULL)
	{
        OString backtrace = Util::Instance()->CreateBacktrace(bt_address);
		strncpy(el->backtrace, backtrace.c_str(), sizeof(el->backtrace));
		el->backtrace[sizeof(el->backtrace) - 1] = '\0';
	}

    /* underlying resource id */
    if (resource_id == 0)
    {
        resource_id = ospy_rand();
    }

    el->resource_id = resource_id;

    /* message type */
    el->type = msg_type;
}
コード例 #3
0
ファイル: mappath.c プロジェクト: Ps3itaTeam/MAMBA
int map_path_user(char *oldpath, char *newpath, uint32_t flags)
{
	char *oldp, *newp;

	#ifdef DEBUG
	DPRINTF("map_path_user, called by process %s: %s -> %s\n", get_process_name(get_current_process_critical()), oldpath, newpath);
	#endif
	
	if (oldpath == 0) return -1;

	int ret = pathdup_from_user(get_secure_user_ptr(oldpath), &oldp);
	if (ret != 0) return ret;

	if (newpath == 0) newp = NULL;
	else
	{
		ret = pathdup_from_user(get_secure_user_ptr(newpath), &newp);
		if (ret != 0)
		{
			dealloc(oldp, 0x27);
			return ret;
		}
	}

	ret = map_path(oldp, newp, flags | FLAG_COPY);

	dealloc(oldp, 0x27);
	if (newp) dealloc(newp, 0x27);

	return ret;
}
コード例 #4
0
int protect_process ( int pid )
{
  char cmd [ 256 ];
  char *message;
  int ret;

/* Trying to protect the process */
//  printf ( "[x] Scanning PID:%i ... " , pid );
  printf ( "[x] Scanning %s ... " , get_process_name ( pid ) );
  ret = protect_embarcadero ( pid , FALSE );

/* If the pattern was found */
  if ( ret == 1 )
  {
    message = "PROTECTION ACTIVATED !";
  }
/* If the pattern wasn't found */
  else if ( ret == 0 )
  {
    message = "VULNERABLE CODE NOT FOUND";
  }
/* If the process could't be open */
  else
  {
    message = "PROCESS ERROR";
  }

/* The result */
  printf ( "%s\n" , message );

  return ( ret );
}
コード例 #5
0
void final_result_show(FILE * fp)
{
    fprintf(fp, "*******************************************************\n");
    fprintf(fp, "TSP Size:%5d\n",get_tsp_size());
    fprintf(fp, "All Proces Num:%2d\n",get_num_of_all_proc());
    fprintf(fp, "Process Number:%2d\n",get_process_number());
    fprintf(fp, "Process Name:%s\n",get_process_name());
    fprintf(fp, "MPI Group:%2d\n",get_MPI_group_data());
    fprintf(fp, "Running Time:%f\n",get_time());
    fprintf(fp, "%.2f\n",get_best_cost());
    /*if(modep->pole_mode == ON) {
        fprintf(fp, "Search Count:%d\n",turn_loop_times(READONLY));
    }*/
    fprintf(fp, "Search Count Num:%d\n",num_counter(SEARCH_COUNTER, CHECK));
    fprintf(fp, "Tunr Count Num:%2d\n",num_counter(TURN_COUNTER, CHECK));
#ifdef DEBUG
    fprintf(fp, "Local Tabulist Num:%d\n",tabulist_counter(DEFAULT, READONLY));
#ifdef MPIMODE
    if(modep->parallel_mode == ON) {
        fprintf(fp, "Share Tabulist Num:%d\n",tabulist_counter(SHARE, READONLY));
    }
#endif
#endif
    fprintf(fp, "\nActive Modes--->\n");
    show_mode(fp);
    fprintf(fp, "<---Active Modes\n");
    fprintf(fp, "*******************************************************\n");
}
コード例 #6
0
ファイル: dxgi-capture.cpp プロジェクト: reboot/obs-studio
static bool setup_dxgi(IDXGISwapChain *swap)
{
    const char *process_name = get_process_name();
    bool ignore_d3d10 = false;
    IUnknown *device;
    HRESULT hr;

    /* Call of duty ghosts allows the context to be queried as a d3d10
     * context when it's actually a d3d11 context.  Why this is I don't
     * quite know. */
    if (_strcmpi(process_name, "iw6sp64_ship.exe") == 0 ||
            _strcmpi(process_name, "iw6mp64_ship.exe") == 0 ||
            _strcmpi(process_name, "justcause3.exe") == 0) {
        ignore_d3d10 = true;
    }

    if (!ignore_d3d10) {
        hr = swap->GetDevice(__uuidof(ID3D10Device), (void**)&device);
        if (SUCCEEDED(hr)) {
            data.swap = swap;
            data.capture = d3d10_capture;
            data.free = d3d10_free;
            device->Release();
            return true;
        }
    }

    hr = swap->GetDevice(__uuidof(ID3D11Device), (void**)&device);
    if (SUCCEEDED(hr)) {
        data.swap = swap;
        data.capture = d3d11_capture;
        data.free = d3d11_free;
        device->Release();
        return true;
    }

#if COMPILE_D3D12_HOOK
    hr = swap->GetDevice(__uuidof(ID3D12Device), (void**)&device);
    if (SUCCEEDED(hr)) {
        data.swap = swap;
        data.capture = d3d12_capture;
        data.free = d3d12_free;
        device->Release();
        return true;
    }
#endif

    return false;
}
コード例 #7
0
ファイル: egl.cpp プロジェクト: 0omega/platform_development
const char *getProcName()
{
    static const char *procname = NULL;

    if (procname == NULL) {
        const char *str = get_process_name();
        if (strcmp(str, "unknown") != 0) {
            procname = str;
        } else {
            // we need to obtain our process name from the command line;
            FILE *fp = fopen("/proc/self/cmdline", "rt");
            if (fp == NULL) {
                ALOGE("couldn't open /proc/self/cmdline\n");
                return NULL;
            }

            char line[1000];
            if (fgets(line, sizeof(line), fp) == NULL) {
                ALOGE("couldn't read the self cmdline from \n");
                fclose(fp);
                return NULL;
            }
            fclose(fp);

            if (line[0] == '\0') {
                ALOGE("cmdline is empty\n");
                return NULL;
            }

            //obtain the basename;
            line[sizeof(line) - 1] = '\0';
            char *p = line;
            while (*p != '\0' &&
                   *p != '\t' &&
                   *p != ' ' &&
                   *p != '\n') {
                p++;
            }

            *p = '\0'; p--;
            while (p > line && *p != '/') p--;
            if (*p == '/') p++;
            procname = strdup(p);
        }
    }

    return procname;
}
コード例 #8
0
static inline HRESULT get_backbuffer(IDirect3DDevice9 *device,
		IDirect3DSurface9 **surface)
{
	static bool use_backbuffer = false;
	static bool checked_exceptions = false;

	if (!checked_exceptions) {
		if (_strcmpi(get_process_name(), "hotd_ng.exe") == 0)
			use_backbuffer = true;
		checked_exceptions = true;
	}

	if (use_backbuffer) {
		return device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO,
				surface);
	} else {
		return device->GetRenderTarget(0, surface);
	}
}
コード例 #9
0
ファイル: main.cpp プロジェクト: yanjian824/nut
//int hook_entry(char *dex_path, char *optimized_dir, char *library_dir, char *class_name, char *method_name){ 
//int hook_entry(char *dex_path, char *optimized_dir, char *class_name, char *method_name){ 
int hook_entry(char *dex_path, char *library_dir, char *class_name, char *method_name){ 
//int hook_entry(char *dex_path, char *class_name, char *method_name){ 

	LOGD("running: %d, injected: %d, addr: %lx\n", g_is_running, g_is_inject, (unsigned long)&g_is_inject);

	if (g_is_running || g_is_inject) {
		return 0;
	}
	g_is_running = true;

	int ret = 0;
	pid_t pid = getpid();
	char procname[256] = {0};

	ret = get_process_name(pid, procname, sizeof(procname));
	if (ret != 0) {
		LOGD("Hook pid: %d, get process name fail!\n", pid);
		return -1;
	}
	
	char app_cache_dir[512] = {0};
	sprintf( app_cache_dir, "/data/data/%s/cache", procname );

	/*
    LOGD("Hook success, pid = %d, dex_path = %s, optimized_dir = %s, library_dir = %s, class_name = %s, method = %s\n",
		pid, dex_path, optimized_dir, library_dir, class_name, method_name);
		*/

	char *optimized_dir = app_cache_dir;
    LOGD("Hook success, pid = %d, dex_path = %s, optimized_dir = %s, library_dir = %s, class_name = %s, method = %s\n",
		pid, dex_path, optimized_dir, library_dir, class_name, method_name);
    //ret = invoke_dex_method(dex_path,app_cache_dir,class_name,method_name,0,NULL);
    //int ret = invoke_dex_method(dex_path, optimized_dir, library_dir, class_name, method_name);
    ret = invoke_dex_method(dex_path, optimized_dir, library_dir, class_name, method_name);
	if (ret == 0) {
		g_is_inject = true;
	}
	g_is_running = false;
	LOGD("invoke finish!\n");
	return ret;
}
コード例 #10
0
ファイル: log.c プロジェクト: 939347507/ajvm
int log_init(char *log_path, int log_level, int log_size, int log_num)
{
        char buff[1024];
        char proc_name[64];
        char pwd[1024];

	if (log_level > LOG_NOLEVEL ||
		log_size > MAX_LOG_SIZE ||
		log_num > MAX_LOG_NUM) {
		printf("log argument error.\n");
		return -1;
	}

        memset(proc_name, '\0', 64);
        if (get_process_name(proc_name) == -1)
                return -1;

        if (!getcwd(pwd, 1024))
                return -1;

        log_arg = (LOG_ARG *)malloc(sizeof(LOG_ARG));
        if (!log_arg) {
                fprintf(stderr, "Malloc failed.\n");
                return -1;
        }

        log_arg->log_level = log_level;
        log_arg->log_file_num = log_num;
        log_arg->curr_log_num = 0;

        /* the kernel will write data into memory cache first,
         * using fstat to get the file size is not correctly,
         * To solove this case, it can wait the data until kernel
         * write them to the disk from memory cache, but in order to
         * improve the performance, we just raise the log_size:::-).
         */
        log_arg->log_size = log_size * 1024 * 1024;
        snprintf(log_arg->log_path, 1024, "%s/%d", log_path, getpid());
        pthread_mutex_init(&log_arg->log_lock, NULL);

        if (mkdir(log_arg->log_path, 0700) == -1) {
                perror("mkdir");
                free(log_arg);
                return -1;
        }

        snprintf(buff, sizeof(buff), "%s/log.1", log_arg->log_path);
        strcpy(log_arg->curr_log, buff);

        log_lock();
        log_arg->log_fp = fopen(buff, "w+");
        if (!log_arg->log_fp) {
                perror("fopen");
                log_unlock();
                free(log_arg);
                return -1;
        }
        log_unlock();

        return 0;
}
コード例 #11
0
ファイル: appl.c プロジェクト: e8johan/oaesis
/*
** Exported
*/
WORD
Appl_do_init (GLOBAL_ARRAY * global) {
  C_APPL_INIT   par;
  R_APPL_INIT   ret;

  WORD          apid = -1;

  DEBUG3("Appl_do_init: 1");
  CHECK_APID(apid);

  DEBUG3("Appl_do_init: 2");
  if(apid == -1)
  {
#ifdef MINT_TARGET
    Psemaphore(SEM_LOCK, SHEL_WRITE_LOCK, -1);
    Psemaphore(SEM_UNLOCK, SHEL_WRITE_LOCK, 0);
#endif
    
    DEBUG3 ("appl.c: Appl_do_init");
    /* Open connection to server */
    if (Client_open () == -1) {
      return -1;
    }
  DEBUG3("Appl_do_init: 3");
    
#ifdef TUNNEL_VDI_CALLS
    /* Tunnel VDI calls through oaesis' connection with the server */
    vdi_handler = vdi_tunnel;
#endif /* TUNNEL_VDI_CALLS */
    
  DEBUG3("Appl_do_init: 4");
    PUT_C_ALL(APPL_INIT, &par);
    
  DEBUG3("Appl_do_init: 5");
#ifdef MINT_TARGET
    get_process_name (par.common.pid,
                      par.appl_name,
                      sizeof (par.appl_name) - 1);
#else
    DEBUG3 ("appl.c: Appl_do_init: program_invocation_short_name %s",
            program_invocation_short_name);
    strncpy (par.appl_name,
             program_invocation_short_name,
             sizeof (par.appl_name) - 1);
#endif
  DEBUG3("Appl_do_init: 6");
    par.appl_name[sizeof (par.appl_name) - 1] = 0;
    
  DEBUG3("Appl_do_init: 7");
    CLIENT_SEND_RECV(&par,
                     sizeof (C_APPL_INIT),
                     &ret,
                     sizeof (R_APPL_INIT));
    
  DEBUG3("Appl_do_init: 8");
    global->apid = ret.apid;

  DEBUG3("Appl_do_init: 9");
    if(global->apid >= 0)
    {
  DEBUG3("Appl_do_init: 10");
      init_global_appl (global->apid, ret.physical_vdi_id, par.appl_name);
  DEBUG3("Appl_do_init: 11");
#ifndef MINT_TARGET
      {
        GLOBAL_APPL * globals_appl = get_globals (global->apid);
        
  DEBUG3("Appl_do_init: 12");
        init_global (globals_appl->vid);
      }
#endif
    }
  }
  else
  {
    global->apid = apid;
  }

  DEBUG3("Appl_do_init: 13");
  global->version = 0x0410;
  global->numapps = -1;
  global->appglobal = 0L;
  global->rscfile = 0L;
  global->rshdr = 0L;
  global->resvd1 = 0;
  global->resvd2 = 0;
  global->int_info = 0L;
  global->maxchar = 0;
  global->minchar = 0;

  return global->apid;
}
コード例 #12
0
/**	-----------------------------------------------------------------------
	\brief	debug message output routine

	\param	
		IN  Level
				Debug Level (DBG_ERR, DBG_INFO, etc..)
				
		IN  Format
				Debug Message Format

	\return			
		NONE
	\code	
	\endcode		
-------------------------------------------------------------------------*/
VOID DrvDebugPrint(IN DWORD Level, IN const char* Function,IN const char* Format, IN ...)
{
	CHAR ProcName[NT_PROCNAMELEN]={0};
    ULONG i=0;
    va_list vaList;
    va_start(vaList, Format);

    // check mask for debug area and debug level
	//
    if (Level <= g_DebugLevel)
    {
        // find a free buffer
		//
        for (i = 0; i < NUMBER_DEBUG_BUFFERS; ++i)
        {
            if (InterlockedCompareExchange((LONG*)&g_DebugBufferBusy[i], 1, 0) == 0)
            {
                __try
				{
					if (TRUE != NT_SUCCESS( RtlStringCbVPrintfA(
										            g_DebugBuffer[i], 
										            sizeof(g_DebugBuffer[i]),
										            Format,
										            vaList
										            )))
					{
						return;
					}
				}
				__except(EXCEPTION_EXECUTE_HANDLER)
				{
                    return;
				}


				get_process_name(PsGetCurrentProcess(), ProcName);
								
                if (DPFLTR_ERROR_LEVEL == Level)
                {
                    DbgPrintEx(
						DPFLTR_IHVDRIVER_ID, 
						DPFLTR_ERROR_LEVEL, 
						DRIVERNAME"(IRQL %2.2d): %-16s(%04u:%04u) : [ERR ] %s(), %s\n", 
						KeGetCurrentIrql(), 
						ProcName, 
						PsGetCurrentProcessId(), PsGetCurrentThreadId(),
						Function, 
                        g_DebugBuffer[i]
                        ); 
                }
                else if (DPFLTR_WARNING_LEVEL == Level)
                {
                    DbgPrintEx(
						DPFLTR_IHVDRIVER_ID, 
						DPFLTR_WARNING_LEVEL | DPFLTR_MASK,
						DRIVERNAME"(IRQL %2.2d): %-16s(%04u:%04u) : [WARN] %s(), %s\n", 
						KeGetCurrentIrql(), 
						ProcName, 
						PsGetCurrentProcessId(), PsGetCurrentThreadId(),
						Function,                         
                        g_DebugBuffer[i]
                    );
                }
				//else if (DPFLTR_TRACE_LEVEL == Level)
				//{
				//	DbgPrintEx(
				//		DPFLTR_IHVDRIVER_ID, 
				//		DPFLTR_TRACE_LEVEL | DPFLTR_MASK,
				//		DRIVERNAME"(IRQL %2.2d): [TRCE] %s(), %s\n", 
				//		KeGetCurrentIrql(), 
				//		Function,                         
				//		g_DebugBuffer[i]
				//	);					
				//}
                else
                {
                    DbgPrintEx(
						DPFLTR_IHVDRIVER_ID, 
						DPFLTR_INFO_LEVEL |  DPFLTR_MASK, 
						DRIVERNAME"(IRQL %2.2d): %-16s(%04u:%04u) : [INFO] %s(), %s\n", 
                        KeGetCurrentIrql(), 
						ProcName,
						PsGetCurrentProcessId(), PsGetCurrentThreadId(),
						Function,                         
                        g_DebugBuffer[i]
                        );
                }

                InterlockedExchange((LONG*)&g_DebugBufferBusy[i], 0);
                break;
            }
        }
    }
コード例 #13
0
ファイル: region.c プロジェクト: Deversi/HOUYAMAN-master
		{
			fake_region = bd_video_region_map[i].ps3_region;
		}
	}
	
	if (fake_region != 0)
		*region = fake_region;
}

LV2_HOOKED_FUNCTION_PRECALL_SUCCESS_2(int, region_func, (uint64_t func, uint8_t *buf))
{
	if (func == 0x19004)
	{
		//DPRINTF("We are originally in region %02X\n", buf[3]);
		
		char *procname = get_process_name(get_current_process_critical());
		if (procname)
		{
			if (strcmp(procname+8, "_main_bdp_BDVD.self") == 0)
			{
				if (dvd_video_region != 0)
				{
					set_dvd_video_region(&buf[3]);
				}
			}
			else if (strcmp(procname+8, "_main_bdp_BDMV.self") == 0)
			{
				if (bd_video_region != 0)
				{
					set_bd_video_region(&buf[3]);
				}
コード例 #14
0
ファイル: main.cpp プロジェクト: flyfaster/toysrc
int main (int argc, char* argv[])
{ 
  char parent_process_path_buf[128];
  sprintf(parent_process_path_buf, "/proc/%d/cmdline", getppid());
  std::ifstream parent_cmdline;
  parent_cmdline.open(parent_process_path_buf);
  std::string parent_cmdline_str;
  std::getline(parent_cmdline, parent_cmdline_str);  
  
  parent_cmdline.close();
  std::cout <<(char *)getauxval(AT_EXECFN) << " pid " << getpid() << " Parent PID is " << getppid() << " " <<parent_cmdline_str << " " <<currentDateTime() << std::endl;
  usleep(1000000* (rand()%10+1));
  std::cout <<get_process_name(getpid()) << " pid " << getpid() << " Parent PID is " << getppid() << " " <<parent_cmdline_str << " " <<currentDateTime() << std::endl;
  std::cout << "Resource size is " << (size_t)&_binary_main_cpp_size<<std::endl;
  std::string src(&_binary_main_cpp_start,(size_t)( &_binary_main_cpp_end-&_binary_main_cpp_start));
     ACE_Argv_Type_Converter to_tchar (argc, argv);
   ACE_Get_Opt get_opt (argc,
                        to_tchar.get_TCHAR_argv (),
                        ACE_TEXT ("msad:"), 1, 0);
   //ACE_Get_Opt get_opt (argc,argv, ACE_TEXT ("P"), 1, 0);
   for (int c; (c = get_opt ()) != -1; )
     switch (c)
       {
       case 's': // print source code
         std::cout <<src << std::endl;
         break;
       case 'm': // print free memory information
       {
		   std::cout << "Parent process is " << get_process_name(getppid()) << std::endl;
		     std::string ss=runcmd("free -m");
		std::cout << ss <<std::endl; 
		}   
         break;		
       case 'a': // test ACE_Argv_Type_Converter
       {
		  ACE_ARGV_T<char> argslist;
		  argslist.add("abc def ghi");
		  argslist.add("4th");
		  argslist.add("5th");
		  int newargc=argslist.argc();
		  ACE_Argv_Type_Converter cmdline(newargc, argslist.argv());
		  char** newargs=cmdline.get_ASCII_argv();
		  std::cout << "arg count " << argslist.argc()<<std::endl;
		  for(int i=0; i<newargc;i++)
			std::cout<< "argv["<<i<<"] " << newargs[i]<<std::endl;
		}   
         break;	   
       case 'd': // compare performance of itoa and sprintf
       {
		  int cnt = ACE_OS::atoi(get_opt.opt_arg ());
		  uint64_t perf1start= getCurrentMillis();
		  char buf[16];
		  for(int i=0; i<cnt; i++)
			itoa(i, buf, 10);
		  uint64_t perf2start= getCurrentMillis();
		  for(int i=0; i<cnt; i++)
			sprintf(buf, "%d", i);
		  uint64_t perf2stop= getCurrentMillis();
		  std::cout << "convert "<<cnt<<" int to string by itoa in " 
			<< (perf2start-perf1start) << " milliseconds, sprintf in " 
			<< (perf2stop-perf2start) << " milliseconds\n";
		}   
         break;	               
       default:
         break;
       }

  return 0;
}
コード例 #15
0
ファイル: dbggw.c プロジェクト: HarryR/sanos
void handle_command(struct drpc_packet *pkt, char *buf)
{
  unsigned long pid;
  unsigned long tid;
  unsigned long addr;
  unsigned long len;
  unsigned long sel;
  unsigned long flags;
  unsigned long n;
  CONTEXT *ctxt;

  // Validate request
  if (pkt->startmark != startmark) logmsg("WARNING: unexpected startmark %08X\n", pkt->startmark);
  if (pkt->reserved1 != 0) logmsg("WARNING: reserved1 is %08X\n", pkt->reserved1);
  if (pkt->reserved2 != 0) logmsg("WARNING: reserved2 is %08X\n", pkt->reserved2);
  if (pkt->result != 0) logmsg("WARNING: result is %08X\n", pkt->result);

  // Execute command
  switch (pkt->cmd)
  {
    case DRPC_GET_SYSTEM_VERSION:
      logmsg("COMMAND GetSystemVersion: spnamelen=%d, buildnamelen=%d\n", *(unsigned long *) (buf + 0), *(unsigned long *) (buf + 8));
      get_system_version(pkt, buf);
      break;

    case DRPC_DEBUG_BREAK:
      tid = *(unsigned long *) (buf + 0);
      logmsg("COMMAND DebugBreak hthread=%08X\n", tid);
      pkt->result = E_FAIL;
      break;

    case DRPC_GET_HOST_INFO:
      logmsg("COMMAND GetHostInfo: hostlen=%d, transportlen=%d\n", *(unsigned long *) (buf + 0), *(unsigned long *) (buf + 8));
      get_host_info(pkt, buf);
      break;

    case DRPC_GET_CPU_INFO:
      logmsg("COMMAND GetCpuInfo: maxlen=%d\n", *(unsigned long *) buf);
      get_cpu_info(pkt, buf);
      break;

    case DRPC_GET_PROCESS_LIST:
      logmsg("COMMAND GetProcessList: maxpids=%d\n", *(unsigned long *) buf);
      get_process_list(pkt, buf);
      break;

    case DRPC_GET_PROCESS_NAME:
      pid = *(unsigned long *) buf;
      logmsg("COMMAND GetProcessName pid=%d:\n", pid);
      get_process_name(pkt, buf);
      break;

    case DRPC_DEBUG_PROCESS:
      pid = *(unsigned long *) buf;
      logmsg("COMMAND DebugProcess pid=%d (%08X):\n", pid, pid);
      pkt->result = E_FAIL;
      break;

    case DRPC_OPEN_PROCESS:
      pid = *(unsigned long *) buf;
      flags = *(unsigned long *) (buf + 8);
      logmsg("COMMAND OpenProcess pid=%d (%08X) flags=%08X:\n", pid, pid, flags);
      open_process(pkt, buf);
      break;

    case DRPC_CREATE_PROCESS:
      pid = *(unsigned long *) buf;
      logmsg("COMMAND CreateProcess: cmd=%S flags=%08X:\n", buf, *(unsigned long *)(buf + pkt->reqlen - 4));
      pkt->result = E_FAIL;
      break;

    case DRPC_READ_PROCESS_MEMORY:
      pid = *(unsigned long *) (buf + 0);
      addr = *(unsigned long *) (buf + 8);
      len = *(unsigned long *) (buf + 16);
      logmsg("COMMAND ReadProcessMemory hproc=%08X addr=%08x len=%d:\n", pid, addr, len);
      read_memory(pkt, buf);
      break;

    case DRPC_WRITE_PROCESS_MEMORY:
      pid = *(unsigned long *) (buf + 0);
      addr = *(unsigned long *) (buf + 8);
      len = *(unsigned long *) (buf + 16);
      logmsg("COMMAND WriteProcessMemory hproc=%08X addr=%08x len=%d:\n", pid, addr, len);
      write_memory(pkt, buf);
      break;

    case DRPC_SUSPEND_THREAD:
      len = *(unsigned long *) (buf + 0);
      logmsg("COMMAND SuspendThread: hthread=");
      for (n = 0; n < len; n++)
      {
        tid = *(unsigned long *) (buf + 8 + n * 8);
        logmsg(" %08X", tid);
      }
      logmsg("\n");
      suspend_threads(pkt, buf);
      break;

    case DRPC_RESUME_THREAD:
      len = *(unsigned long *) (buf + 0);
      logmsg("COMMAND ResumeThread: hthread=");
      for (n = 0; n < len; n++)
      {
        tid = *(unsigned long *) (buf + 8 + n * 8);
        logmsg(" %08X", tid);
      }
      logmsg("\n");
      resume_threads(pkt, buf);
      break;

    case DRPC_GET_THREAD_CONTEXT:
      tid = *(unsigned long *) (buf + 0);
      flags = *(unsigned long *) (buf + 8);
      len = *(unsigned long *) (buf + 16);
      logmsg("COMMAND GetThreadContext hthread=%08X context=%08x len=%d:\n", tid, flags, len);
      get_context(pkt, buf);
      break;

    case DRPC_SET_THREAD_CONTEXT:
      tid = *(unsigned long *) (buf + 0); 
      len = *(unsigned long *) (buf + 8);
      ctxt = (CONTEXT *) (buf + 12);
      logmsg("COMMAND SetThreadContext hthread=%08X eax=%08x len=%d:\n", tid, ctxt->Eax, len);
      set_context(pkt, buf);
      break;

    case DRPC_GET_PEB_ADDRESS:
      pid = *(unsigned long *) (buf + 0);
      logmsg("COMMAND GetPebAddress hproc=%08X:\n", pid);
      get_peb_address(pkt, buf);
      break;

    case DRPC_GET_THREAD_SELECTOR:
      tid = *(unsigned long *) (buf + 0);
      sel = *(unsigned long *) (buf + 8);
      len = *(unsigned long *) (buf + 12);
      logmsg("COMMAND GetThreadSelector hthread=%08X selector=%08x len=%08x:\n", tid, sel, len);
      get_thread_selector(pkt, buf);
      break;

    case DRPC_GET_DEBUG_EVENT:
      logmsg("COMMAND GetDebugEvent %08X %08X:\n", *(unsigned long *) buf, *(unsigned long *) (buf + 4));
      get_debug_event(pkt, buf);
      break;

    case DRPC_CONTINUE_DEBUG_EVENT:
      flags = *(unsigned long *) buf;
      if (flags == 0x00010001)
        logmsg("COMMAND ContinueDebugEvent: DBG_EXCEPTION_HANDLED\n");
      else if (flags == 0x00010002)
        logmsg("COMMAND ContinueDebugEvent: DBG_CONTINUE\n");
      else
        logmsg("COMMAND ContinueDebugEvent: %08X\n", flags);

      break;

    case 0x0000C001:
      logmsg("COMMAND 0000C001\n");
      pkt->result = dbg_state;
      break;

    case 0x0004C002:
      logmsg("COMMAND 0004C002\n");
      *(unsigned long *) buf = 5;
      break;

    default:
      logmsg("COMMAND %08X ??? (reqlen=%d, rsplen=%d):\n", pkt->cmd, pkt->reqlen, pkt->rsplen);
      if (pkt->reqlen > 0)
      {
        logmsg("reqdata: ");
        dump_data(stdout, buf, pkt->reqlen > 256 ? 256 : pkt->reqlen, 4, NULL);
        if (logfile) dump_data(logfile, buf, pkt->reqlen, 4, NULL);
      }
      pkt->result = E_FAIL;
  }

  pkt->cmd |= 0x00010000;
}
コード例 #16
0
ファイル: kmsg-syslogd.c プロジェクト: terralinux/systemd
static int write_message(Server *s, const char *buf, struct ucred *ucred) {
        ssize_t k;
        char priority[6], pid[16];
        struct iovec iovec[5];
        unsigned i = 0;
        char *process = NULL;
        int r = 0;
        int prio = LOG_USER | LOG_INFO;

        assert(s);
        assert(buf);

        parse_syslog_priority((char**) &buf, &prio);

        if (*buf == 0)
                return 0;

        if ((prio & LOG_FACMASK) == 0)
                prio = LOG_USER | LOG_PRI(prio);

        /* First, set priority field */
        snprintf(priority, sizeof(priority), "<%i>", prio);
        char_array_0(priority);
        IOVEC_SET_STRING(iovec[i++], priority);

        /* Second, skip date */
        skip_date(&buf);

        /* Then, add process if set */
        if (read_process(&buf, &iovec[i]) > 0)
                i++;
        else if (ucred &&
                 ucred->pid > 0 &&
                 get_process_name(ucred->pid, &process) >= 0)
                IOVEC_SET_STRING(iovec[i++], process);

        /* Skip the stored PID if we have a better one */
        if (ucred) {
                snprintf(pid, sizeof(pid), "[%lu]: ", (unsigned long) ucred->pid);
                char_array_0(pid);
                IOVEC_SET_STRING(iovec[i++], pid);

                skip_pid(&buf);

                if (*buf == ':')
                        buf++;

                buf += strspn(buf, WHITESPACE);
        }

        /* Is the remaining message empty? */
        if (*buf) {

                /* And the rest is the message */
                IOVEC_SET_STRING(iovec[i++], buf);
                IOVEC_SET_STRING(iovec[i++], "\n");

                if ((k = writev(s->kmsg_fd, iovec, i)) <= 0) {
                        log_error("Failed to write log message to kmsg: %s", k < 0 ? strerror(errno) : "short write");
                        r = k < 0 ? -errno : -EIO;
                }
        }

        free(process);

        return r;
}