int ProcessInfoListView::compareItem(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
	auto descendingOrder = lParamSort < 0;
	if (descendingOrder)
	{
		lParamSort = abs(lParamSort);
		return compareItem(lParam2, lParam1, lParamSort);
	}

	auto firstItem = reinterpret_cast<ProcessInfo*>(lParam1);
	auto secondItem = reinterpret_cast<ProcessInfo*>(lParam2);
	auto sortColumn = lParamSort - 1;
	auto compare = 0;

	switch (sortColumn)
	{
	case 0:
		compare = firstItem->getProcessPid() - secondItem->getProcessPid();
		if (compare != 0)
		{
			return compare;
		}
		return compareItem(lParam1, lParam2, 1);
	case 1:
		return _tcsicmp(firstItem->getProcessName(), secondItem->getProcessName());
	default:
		_ASSERT(false);
		return 0;
	}
}
Beispiel #2
0
int ServerProcess::cimserver_kill(int id) 
{ 
  FILE *pid_file;
  pid_t pid = 0;
  
  // open the file containing the CIMServer process ID
  pid_file = fopen(getPIDFileName(), "r");
  if (!pid_file) 
  {
      return (-1);
  }

  // get the pid from the file
  fscanf(pid_file, "%d\n", &pid);

  fclose(pid_file);

  if (pid == 0)
  {
     System::removeFile(getPIDFileName());
     return (-1);
  }

  //
  // kill the process if it is still alive
  //
#if defined(PEGASUS_OS_HPUX)
  struct pst_status pstru;

  int ret_code;
  ret_code = pstat_getproc(&pstru, sizeof(struct pst_status), (size_t)0, pid);

  if ( (ret_code != -1 ) && (strcmp(pstru.pst_ucomm, getProcessName())) == 0)
  {
      // cimserver is running, kill the process
      kill(pid, SIGKILL);
  }
#endif
#if defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC)
  if (get_proc(pid) != -1 )
  {
      kill(pid, SIGKILL);
  }
#endif
#if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
  if (isProcRunning(pid)) {
      kill(pid, SIGKILL);
  }
#endif
#if defined(PEGASUS_OS_AIX)
  if (!aixcimsrvrunning(pid, getProcessName()))
        kill(pid,SIGKILL);
#endif
  // remove the file
  System::removeFile(getPIDFileName());
  
  return(0);
}
Beispiel #3
0
bool dumpAlphaTexture(int width, int height, uint8_t *data, const char *prefix, SkBitmap::Config format)
{
    static int count = 0;
    char procName[256];
    char file[512];
    SkBitmap bitmap;
    SkBitmap bitmapCopy;

    if (!getProcessName(procName, sizeof(procName)))
        return false;

    sprintf(file, "/data/data/%s/%s_%04d.png", procName, prefix, count++);
    XLOGI("%s: %dx%d %s\n", __FUNCTION__, width, height, file);

    bitmap.setConfig(format, width, height);
    bitmap.setPixels(data, NULL);

    if (!bitmap.copyTo(&bitmapCopy, SkBitmap::kARGB_8888_Config))
    {
        XLOGD("%s: Failed to copy data", __FUNCTION__);
        return false;
    }

    if (!SkImageEncoder::EncodeFile(file, bitmapCopy, SkImageEncoder::kPNG_Type, 100))
    {
        XLOGE("%s: Failed to encode image %s\n", __FUNCTION__, file);
        return false;
    }

    return true;
}
Beispiel #4
0
bool dumpTexture(int texture, int width, int height, SkBitmap *bitmap)
{
    char procName[256];
    char file[512];

    if (!g_HWUI_debug_dumpTexture)
        return false;

    if (!getProcessName(procName, sizeof(procName)))
        return false;

    char *pch;
    pch = strtok(procName, ":"); // truncate, e.g: com.android.systemui:screenshot
    pch = pch == NULL ? procName : pch;

    sprintf(file, "/data/data/%s/tex_%d_%d_%d_%p.png", pch, texture, width, height, bitmap);
    if (!SkImageEncoder::EncodeFile(file, *bitmap, SkImageEncoder::kPNG_Type, 100))
    {
        XLOGE("%s: Fail to dump texture: %s", __FUNCTION__, file);
        return false;
    }

    XLOGI("%s: %dx%d, %s", __FUNCTION__, width, height, file);
    return true;
}
Beispiel #5
0
bool dumpDraw(int width, int height, bool newFrame)
{
    static int frame = 0;
    static int count = 0;
    char procName[256];
    char file[512];


    if (!getProcessName(procName, sizeof(procName)))
        return false;

    char *pch;
    pch = strtok(procName, ":"); // truncate, e.g: com.android.systemui:screenshot
    pch = pch == NULL ? procName : pch;

    if (newFrame)
    {
        count = 0;
        frame++;
        return false;
    } else {
        sprintf(file, "/data/data/%s/draw_%04d_%04d.png", pch, frame, count++);
        return dumpImage(width, height, file);
    }

}
Beispiel #6
0
// hunt down and kill processes that have files open on the given mount point
void Process::killProcessesWithOpenFiles(const char *path, int action) {
    DIR*    dir;
    struct dirent* de;

    if (!(dir = opendir("/proc"))) {
        SLOGE("opendir failed (%s)", strerror(errno));
        return;
    }
	LOGE("(%s) (%d)", path, action);

    while ((de = readdir(dir))) {
        int killed = 0;
        int pid = getPid(de->d_name);
        char name[PATH_MAX];

        if (pid == -1)
            continue;
        getProcessName(pid, name, sizeof(name));
        char openfile[PATH_MAX];

        if (checkFileDescriptorSymLinks(pid, path, openfile, sizeof(openfile))) {
            LOGE("Process %s (%d) has open file %s", name, pid, openfile);
			killed = 1;
        } else if (checkFileMaps(pid, path, openfile, sizeof(openfile))) {
            LOGE("Process %s (%d) has open filemap for %s", name, pid, openfile);
			killed = 1;
        } else if (checkSymLink(pid, path, "cwd")) {
            LOGE("Process %s (%d) has cwd within %s", name, pid, path);
			killed = 1;
        } else if (checkSymLink(pid, path, "root")) {
            LOGE("Process %s (%d) has chroot within %s", name, pid, path);
			killed = 1;
        } else if (checkSymLink(pid, path, "exe")) {
            LOGE("Process %s (%d) has executable path within %s", name, pid, path);
        } else {
//            continue;
        }
		
#if 1
		if( (!strcmp("android.process.media", name) && (strcmp("/mnt/extsd", path)) ) || killed == 1) {
			if (action == 1) {
				LOGE("Sending SIGHUP to process %d", pid);
				kill(pid, SIGTERM);
			} else if (action == 2) {
				LOGE("Sending SIGKILL to process %d", pid);
				kill(pid, SIGKILL);
			}
		}
#else		
        if (action == 1) {
            SLOGE("Sending SIGHUP to process %d", pid);
            kill(pid, SIGTERM);
        } else if (action == 2) {
            SLOGE("Sending SIGKILL to process %d", pid);
            kill(pid, SIGKILL);
        }
#endif
    }
    closedir(dir);
}
static bool isStartedFromCommandPrompt()
{
	HWND hwnd = GetConsoleWindow();
	
	if (hwnd) {
		DWORD pid = (DWORD)-1;
		DWORD ppid = GetParentProcessID();
		char parent_name[MAX_PATH];
		bool start_from_launcher = false;

		GetWindowThreadProcessId(hwnd, &pid);
		if (getProcessName(ppid, parent_name, sizeof(parent_name))) {
			char *filename = strrchr(parent_name, '\\');
			if (filename != NULL) {
				start_from_launcher = strstr(filename, "blender.exe") != NULL;
			}
		}

		/* When we're starting from a wrapper we need to compare with parent process ID. */
		if (pid == (start_from_launcher ? ppid : GetCurrentProcessId()))
			return true;
	}

	return false;
}
Beispiel #8
0
//=============================================================================
// NAME           : get_proc
// DESCRIPTION    : get_proc() makes a stat() system call on the directory in
//                  /proc with a name that matches the pid of the cimserver.
//                  It returns 0 if it successfully located the process dir
//                  and verified that the process name matches that of the
//                  cimserver.  It returns -1 if it fails to open /proc, or
//                  the cimserver process does not exist.
//=============================================================================
int ServerProcess::get_proc(int pid)
{
  static char path[32];
  static struct stat stat_buff;

  sprintf(path, "/proc/%d", pid);
  if (stat(path, &stat_buff) == -1)          // process stopped running
  {
    return -1;
  }

 // get the process name to make sure it is the cimserver process
// ATTN: skip verify for Solaris
#if !defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC)
  if ((verify_process_name(path, getProcessName())) == -1)
  {
    return -1;
  }
#endif

  //
  // Check to see if this command process has the same pid as the cimserver
  // daemon process pid stored in the cimserver_start.conf file.  Since the
  // command has the same name as the cimserver daemon process, this could
  // happen after a system reboot.  If the pids are the same, cimserver 
  // isn't really running.
  //
  Uint32 mypid = System::getPID();
  if ((mypid == (unsigned)pid) || ((unsigned)parentPid == (unsigned)pid))
  {
      return -1;
  }
  return 0;
}
void LinuxProcessInfoGathererHelper::checkActiveWindow()
{
    //Get the active window info
    WId wid = KWindowSystem::activeWindow();

    NETWinInfo netInfo(QX11Info::display(),
                       wid,
                       QX11Info::appRootWindow(),
                       NET::WMPid | NET::WMName);

    //Get tne name of the process controlling the active window with the pid from netInfo
    QString processName;
    QString windowName;
    QString strPID;

    processName = getProcessName(netInfo.pid());
    if (!processName.isNull()) {
        windowName = netInfo.name();

        //emit any changes to the active window name or its process
        if (m_currentActiveWindowTitle != windowName)
        {
            m_currentActiveWindowTitle = windowName;
            emit activeWindowTitleChanged(windowName);
        }
        if (m_currentActiveWindowProgram != processName)
        {
            m_currentActiveWindowProgram = processName;
            emit activeWindowProcessChanged(processName);
        }
    }
}
Beispiel #10
0
Client::Client(const sp<SurfaceFlinger>& flinger)
    : mFlinger(flinger)
{
#ifdef MTK_AOSP_ENHANCEMENT
    // get client process info
    mClientPid = IPCThreadState::self()->getCallingPid();
    getProcessName(mClientPid, mClientProcName);
    ALOGI("[SF client] NEW(%p) for (%d:%s)", this, mClientPid, mClientProcName.string());
#endif
}
Beispiel #11
0
    std::string getLogPath()
    {
        std::stringstream ss;
        std::string path = getEnv("LOG_PATH");
        if (!path.empty()) {
            ss << path << "/";
        }
        ss << getProcessName() << ".log";

        LOGD << "LOG_PATH:" << ss.str();
        return ss.str();
    }
// hunt down and kill processes that have files open on the given mount point
void killProcessesWithOpenFiles(const char *path, int action)
{
    DIR *dir;
    struct dirent *de;

    if (!(dir = opendir("/proc"))) {
        SLOGE("opendir failed (%s)", strerror(errno));
        return;
    }

    while ((de = readdir(dir))) {
        int pid = getPid(de->d_name);
        char name[PATH_MAX];

        if (pid == -1)
            continue;
        getProcessName(pid, name, sizeof(name));

        char openfile[PATH_MAX];

        if (checkfileDescriptorSymLinks
                (pid, path, openfile, sizeof(openfile))) {
            SLOGE("Process %s (%d) has open file %s", name, pid,
                  openfile);
        } else if (checkfileMaps(pid, path, openfile, sizeof(openfile))) {
            SLOGE("Process %s (%d) has open filemap for %s", name,
                  pid, openfile);
        } else if (checkSymLink(pid, path, "cwd")) {
            SLOGE("Process %s (%d) has cwd within %s", name, pid,
                  path);
        } else if (checkSymLink(pid, path, "root")) {
            SLOGE("Process %s (%d) has chroot within %s", name, pid,
                  path);
        } else if (checkSymLink(pid, path, "exe")) {
            SLOGE("Process %s (%d) has executable path within %s",
                  name, pid, path);
        } else {
            continue;
        }
        if (action == 1) {
            SLOGW("Sending SIGHUP to process %d", pid);
            kill(pid, SIGTERM);
        } else if (action == 2) {
            SLOGE("Sending SIGKILL to process %d", pid);
            kill(pid, SIGKILL);
        }
    }
    closedir(dir);
}
Beispiel #13
0
void BufferQueueDebug::onProducerConnect(
        const sp<IBinder>& token, const int api, bool producerControlledByApp) {
    mProducerPid = (token != NULL && NULL != token->localBinder())
        ? getpid()
        : IPCThreadState::self()->getCallingPid();
    mConnectedApi = api;

    if (NO_ERROR == getProcessName(mProducerPid, mProducerProcName)) {
        BQP_LOGI("connect(P): api=%d producer=(%d:%s) producerControlledByApp=%s", mConnectedApi,
                mProducerPid, mProducerProcName.string(), producerControlledByApp ? "true" : "false");
    } else {
        BQP_LOGI("connect(P): api=%d producer=(%d:\?\?\?) producerControlledByApp=%s", mConnectedApi,
                mProducerPid, producerControlledByApp ? "true" : "false");
    }
}
Beispiel #14
0
MLC_LogCore::MLC_LogCoreNoLock::MLC_LogCoreNoLock()
    : MLC_ILogCore()
    //, mIdGenerator(MLC_SHMID_LOGID)
    , mConfig(NULL)
    , mFactory(NULL)
    , mPlugins()
    , mProcessName(new char[128])
{
    // get process name
    getProcessName();

    mConfig = new(MEM_Base) MLC_Config();

    // enable builtin plugins.
    mFactory = new(MEM_Base) MLC_PluginFactory(this);
}
Beispiel #15
0
void BufferQueueDebug::onConsumerConnect(
        const sp<IConsumerListener>& consumerListener,
        const bool controlledByApp) {
    // check if local or remote connection by the consumer listener
    // (in most cases, consumer side is a local connection)
    mConsumerPid = (NULL != consumerListener->asBinder()->localBinder())
                 ? getpid()
                 : IPCThreadState::self()->getCallingPid();

    String8 name;
    if (NO_ERROR == getProcessName(mConsumerPid, mConsumerProcName)) {
        BQC_LOGI("connect(C): consumer=(%d:%s) controlledByApp=%s",
            mConsumerPid, mConsumerProcName.string(), controlledByApp ? "true" : "false");
    } else {
        BQC_LOGI("connect(C): consumer=(%d:\?\?\?) controlledByApp=%s",
            mConsumerPid, controlledByApp ? "true" : "false");
    }
}
Beispiel #16
0
bool dumpLayer(int width, int height, int fbo)
{
    static int frame = 0;
    char procName[256];
    char file[512];

    if (!getProcessName(procName, sizeof(procName)))
        return false;

    char *pch;
    pch = strtok(procName, ":"); // truncate, e.g: com.android.systemui:screenshot
    pch = pch == NULL ? procName : pch;

    sprintf(file, "/data/data/%s/layer_%d_%d_%d_%04d.png", pch, fbo, width, height, frame);

    frame++;
    return dumpImage(width, height, file);
}
Beispiel #17
0
void ProcessMonitor::timeout() {
    int userId;

    if (QSysInfo::windowsVersion() == QSysInfo::WV_VISTA || QSysInfo::windowsVersion() == QSysInfo::WV_WINDOWS7) {
        QString userName = getCurrentUserName();
        userId = getCurrentUserId(userName);
    } else {
        userId = getCurrentUserId();
    }

    // Check if current user is controlled by Hajeb
    if (userId == -1) {
        return ;
    }

    // Check if Process monitor is enabled for this user.
    if (!isEnabledForUser(userId)) {
        qDebug() << "Process monitor is disabled for this account.";
        return ;
    }

    QStringList pKillNames = getProcessName(userId);

    if (pKillNames.isEmpty())
        return ;

    m_process = new QProcess(this);

    foreach (QString pKillName,pKillNames) {
        QString pName = QString("taskkill /im %1 /f").arg(pKillName);
        m_process->start(pName);
        if (!m_process->waitForStarted())
            qDebug() << "can not start pskill process";
        if (!m_process->waitForFinished())
            qDebug() << "pskill process doesn't finished";
        QString output = m_process->readAll();
        qDebug() << output;
        if (output.contains("SUCCESS")) {
            QString action = "تم غلق البرنامج : " + pKillName + " بنجاح.";
            qDebug() << action ;
            logs(userId,action);
        }
    }
Beispiel #18
0
//////////////////////////////////////////////////////////////////////////
//! LogerManager
//////////////////////////////////////////////////////////////////////////
LogerManager::LogerManager()
{
	_runing = false;
	_lastId = LOG4Z_MAIN_LOGGER_ID;
	_hotUpdateInterval = 0;

	_ullStatusTotalPushLog = 0;
	_ullStatusTotalPopLog = 0;
	_ullStatusTotalWriteFileCount = 0;
	_ullStatusTotalWriteFileBytes = 0;
	
	_pid = getProcessID();
	_proName = getProcessName();
	_loggers[LOG4Z_MAIN_LOGGER_ID]._enable = true;
	_ids[LOG4Z_MAIN_LOGGER_KEY] = LOG4Z_MAIN_LOGGER_ID;
	_loggers[LOG4Z_MAIN_LOGGER_ID]._key = LOG4Z_MAIN_LOGGER_KEY;
	_loggers[LOG4Z_MAIN_LOGGER_ID]._name = _proName;

}
Beispiel #19
0
//======================================================================
BOOL CALLBACK procEnumWindows(HWND hwnd, LPARAM lParam) //find window for PID
{
//	LONG_PTR iLevel = lParam;	//change
	iLevel++;

	TCHAR caption[MAX_PATH];
	TCHAR classname[MAX_PATH];
	TCHAR procname[MAX_PATH];
	TCHAR* szName; szName = (TCHAR*)malloc (MAX_PATH);
	GetClassName(hwnd, classname, MAX_PATH);
	//hack as it hangs for "Button"
	if(wcscmp(classname,L"Button")==0){
		wsprintf(caption, L"");
	}
	else{
		if ( GetWindowTextLength(hwnd)>0 )
			GetWindowText(hwnd, caption, MAX_PATH);
		else
			wsprintf(caption, L"");
	}
	DWORD dwProcID=0;
	GetWindowThreadProcessId(hwnd, &dwProcID);
	
	//dimensions and position
	RECT rect;
	GetWindowRect(hwnd, &rect);
	TCHAR szRect[64];
	wsprintf(szRect, L"%i;%i/%i;%i (%ix%i)", rect.left, rect.top, rect.right, rect.bottom, rect.right-rect.left, rect.bottom-rect.top);

	////visible?, MINIMIZED not supported
	DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE);
	TCHAR szStyle[64];
	wsprintf(szStyle, L"[%s]", dwStyle&WS_VISIBLE ? L"visible":L"hidden" );

	wsprintf(procname, L"%s", getProcessName(dwProcID, szName));
	DEBUGMSG(1, (L"%i\t0x%08x\t0x%08x\t('%s')\t'%s'\t'%s'\t%s\t%s\n", iLevel, hwnd, dwProcID, procname, classname, caption, szRect, szStyle));
	nclog(L"%i\t0x%08x\t0x%08x\t('%s')\t'%s'\t'%s'\t%s\t%s\n", iLevel, hwnd, dwProcID, procname, classname, caption, szRect, szStyle);

	free(szName);
	//return FALSE; // to stop iteration before end of window list
	return true;
}
static bool defaultPollMaximumProcessMemory(size_t &criticalLimit, size_t &nonCriticalLimit)
{
    // Syntax: Case insensitive, process name, wildcard (*), unit multipliers (M=Mb, K=Kb, <empty>=bytes).
    // Example: WPE_POLL_MAX_MEMORY='WPEWebProcess:500M,*Process:150M'

    String processName(getProcessName().convertToLowercaseWithoutLocale());
    String s(getenv("WPE_POLL_MAX_MEMORY"));
    if (!s.isEmpty()) {
        Vector<String> entries;
        s.split(',', false, entries);
        for (const String& entry : entries) {
            Vector<String> keyvalue;
            entry.split(':', false, keyvalue);
            if (keyvalue.size() != 2)
                continue;
            String key = "*"+keyvalue[0].stripWhiteSpace().convertToLowercaseWithoutLocale();
            String value = keyvalue[1].stripWhiteSpace().convertToLowercaseWithoutLocale();
            size_t units = 1;
            if (value.endsWith('k'))
                units = 1024;
            else if (value.endsWith('m'))
                units = 1024 * 1024;
            if (units != 1)
                value = value.substring(0, value.length()-1);
            bool ok = false;
            size_t size = size_t(value.toUInt64(&ok));
            if (!ok)
                continue;

            if (!fnmatch(key.utf8().data(), processName.utf8().data(), 0)) {
                criticalLimit = size * units;
                nonCriticalLimit = criticalLimit * 0.75;
                return true;
            }
        }
    }

    return false;
}
void MemoryPressureHandler::pollMemoryPressure(void*)
{
    ASSERT(!isMainThread());

    bool critical;
    String processName(getProcessName());
    do {
        if (s_pollMaximumProcessMemoryCriticalLimit) {
            size_t vmRSS = readToken(s_processStatus, "VmRSS:", KB);

            if (!vmRSS)
                return;

            if (vmRSS > s_pollMaximumProcessMemoryNonCriticalLimit) {
                critical = vmRSS > s_pollMaximumProcessMemoryCriticalLimit;
                break;
            }
        } else {
            size_t memFree = readToken(s_memInfo, "MemFree:", KB);

            if (!memFree)
                return;

            if (memFree < s_memNonCriticalLimit) {
                critical = memFree < s_memCriticalLimit;
                break;
            }
        }
        sleep(s_pollTimeSec);
    } while (true);

    if (ReliefLogger::loggingEnabled())
        LOG(MemoryPressure, "Polled memory pressure (%s)", critical ? "critical" : "non-critical");

    MemoryPressureHandler::singleton().setUnderMemoryPressure(critical);
    callOnMainThread([critical] {
        MemoryPressureHandler::singleton().respondToMemoryPressure(critical ? Critical::Yes : Critical::No);
    });
}
Beispiel #22
0
// BufferQueueCore part
// -----------------------------------------------------------------------------
void BufferQueueDebug::onConstructor(
        wp<BufferQueueCore> bq, const String8& consumerName) {
    mBq = bq;
    mPid = getpid();
    mConsumerName = consumerName;
    if (sscanf(consumerName.string(), "unnamed-%*d-%d", &mId) != 1) {
        BQ_LOGE("id info cannot be read from '%s'", consumerName.string());
    }

    if (NO_ERROR == getProcessName(mPid, mConsumerProcName)) {
        BQ_LOGI("BufferQueue core=(%d:%s)", mPid, mConsumerProcName.string());
    } else {
        BQ_LOGI("BufferQueue core=(%d:\?\?\?)", mPid);
    }

    mIsInGuiExt = (mConsumerProcName.find("guiext-server") != -1);
    mDump = new BufferQueueDump(mIsInGuiExt ?
            BufferQueueDump::TRACK_PRODUCER : BufferQueueDump::TRACK_CONSUMER, mBq.unsafe_get());

    if (mDump == NULL) {
        BQ_LOGE("new BufferQueueDump() failed in BufferQueue()");
    }
    // update dump name
    mDump->setName(consumerName);

    // check property for drawing debug line
    char value[PROPERTY_VALUE_MAX];
    property_get("debug.bq.line", value, "GOD'S IN HIS HEAVEN, ALL'S RIGHT WITH THE WORLD.");
    mLine = (-1 != consumerName.find(value));
    mLineCnt = 0;

    if (true == mLine) {
        BQ_LOGI("switch on debug line");
    }

    if (!mIsInGuiExt) {
        BufferQueueMonitor::getInstance().monitor(mBq);
    }
}
  virtual void initialize()
    {
      if(isInitialized)
        {
          return;
        }
      ReactionProcess::initialize();
      if(!(getOrder() == 0 || getOrder() == 1 || getOrder() == 2))
        {
          // change code (2011/02/01)
          THROW_EXCEPTION(ValueError, 
                          std::string( getProcessName() ) + 
                          "[" + getFullID().asString() + 
                          "]: Only zeroth, first or second order scheme " + 
                          "is allowed.");
//          THROW_EXCEPTION(ValueError, 
//                          std::string(getPropertyInterface().getClassName()) + 
//                          "[" + getFullID().asString() + 
//                          "]: Only zeroth, first or second order scheme " + 
//                          "is allowed.");
        }
      if(variableA)
        {
          initSizeA = variableA->getValue();
        }
      if(variableB)
        {
          initSizeB = variableB->getValue();
        }
      if(variableC)
        {
          initSizeC = variableC->getValue();
        }
      if(variableD)
        {
          initSizeD = variableD->getValue();
        }
    }
Beispiel #24
0
void ProcessList::init()
{
    HANDLE h;
    PROCESSENTRY32 pe32;

    h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (h == INVALID_HANDLE_VALUE) {
        return;
    }
    pe32.dwSize = sizeof(PROCESSENTRY32);
    if (!Process32First(h, &pe32)) {
        return;
    }

    do {
        HANDLE hProcess = getProcessHandle(pe32.th32ProcessID);
        if (!hProcess) {
            continue;
        }
        QString name = getProcessName(pe32.th32ProcessID);
#ifndef _WIN32_WCE
        PSID sid = getProcessOwner(hProcess);
        if (!sid || m_userId && !EqualSid(m_userId, sid)) {
            freeSid(sid);
            continue;
        }
#else
        PSID sid = 0;
#endif
        m_processes << new ProcessListEntry(hProcess, name, pe32.th32ProcessID, sid);
    } while (Process32Next(h, &pe32));
#ifndef _WIN32_WCE
    CloseHandle(h);
#else
    CloseToolhelp32Snapshot(h);
#endif
}
Beispiel #25
0
void DexHacker::writeDex2Encoded(unsigned char *data, size_t length){




#ifdef CODE_DVM
    ALOGE("--pacthed--  inject  .dex length %d ",length);

    char dexbuffer[64]={0};

    char dexbufferNamed[128]={0};
    char * bufferProcess=(char*)calloc(256,sizeof(char*));

   int  processStatus= getProcessName(bufferProcess);
    sprintf(dexbuffer, "_classes_%d", length);
    strcat(dexbufferNamed,"/sdcard/");
    if (processStatus==1) {
      strcat(dexbufferNamed,bufferProcess);
        strcat(dexbufferNamed,dexbuffer);

    }else{
          ALOGE("--pacthed-- , FAULT pid not  found\n");
        return;
    }
    if(bufferProcess!=NULL)
  {

      free(bufferProcess);
  }
   // strcat(dexbufferNamed,dexbuffer);
    strcat(dexbufferNamed,".dex");

    ALOGE("--pacthed-- , %s\n", dexbufferNamed);

    ALOGE("--pacthed--  debug dalvikParse   find dex try write file  ");

    int status = remove(dexbufferNamed);

    if( status == 0 )
        ALOGE("%s file deleted successfully.\n",dexbufferNamed);
    else
    {
        ALOGE("Unable to delete the file\n");

    }


    u1* buffer_data_dest=(u1*)malloc((length+1)*sizeof(u1));
    memcpy(buffer_data_dest, data, length);
    FILE *fp = fopen(dexbufferNamed,"wb");


    if(NULL==fp){
        ALOGE("--pacthed-- , can't create file ! maybe  you need mount sdcard again!");
        ALOGE( "%s data %s\n", strerror(errno),data);

    }else{
        ALOGE("--pacthed--   create file  %s ",dexbufferNamed);
        int dex_lem_local=length>2048?1024:length;

        unsigned char *dst=(unsigned char*)malloc(length*2.5);
        unsigned long dlen=length*2.5;
        base64_encode(dst, &dlen, data, length);

        fwrite(dst, dlen, 1, fp);
        //fwrite(data, sizeof(u1), length, fp);
        ALOGE("--pacthed--  create file  end ");

        //fflush(fp);
        fclose(fp);
        fp = NULL;
    }
    free(buffer_data_dest);
#else



    char dexbuffer[64]={0};
    char dexbufferNamed[128]={0};
    sprintf(dexbuffer, "classes_%d", length);
    //strcat(dexbufferNamed,");
    strcat(dexbufferNamed,dexbuffer);
    strcat(dexbufferNamed,".dex");



    int status = remove(dexbufferNamed);

    FILE *fp = fopen(dexbufferNamed,"wb");


    if(NULL==fp){

    }else{

        unsigned char *dst=(unsigned char*)malloc(length*2.5);
        unsigned long dlen=length*2.5;
        base64_encode(dst, &dlen, data, length);

        fwrite(dst, dlen, 1, fp);

        //fflush(fp);
        fclose(fp);
        fp = NULL;
    }


#endif


}
Beispiel #26
0
//替换的函数,导出dex文件
DexFile* myDexFileParse(const u1 * addr,size_t len,int dvmdex)
{
	//LOGD("call myDexFileParse! : %d",getpid());

	{
		/*
		 * bufferProcess: processname
		 * dexbuffer: _dump_len
		 * dexbufferNamed: /sdcard -> /sdcard/processname -> /sdcard/processname_dump_len
		 *
		 */
	    char dexbuffer[64]={0};
	    char dexbufferNamed[128]={0};
		char * bufferProcess=(char*)calloc(256,sizeof(char));

		//得到 processname
		int  processStatus= getProcessName(bufferProcess);
		LOGD("call myDexFileParse! pid: %d , pname : %s , size : %d ",getpid(),bufferProcess,len);

		// 对 processname 进行排除

		if(exclude(bufferProcess)){
			LOGI("exclude shoot");
			return oldDexFileParse(addr,len,dvmdex);
		}
		else
			LOGI("continue");

		//创建目录
		if(checkDir())
			LOGD("Dir /sdcard/mydex/ not exit and create it failed, please check it!");

//		对 pre-init 进行 pid 拼接
//		if(!strcmp(bufferProcess,ex0))
//			sprintf(dexbuffer, "_pid_%d", getpid());
//		else
		sprintf(dexbuffer, "_%d", len);

	    strcat(dexbufferNamed,"/sdcard/mydex/");
	    if (processStatus==1) {
	      strcat(dexbufferNamed,bufferProcess);
	      strcat(dexbufferNamed,dexbuffer);

	    }else{
	    	LOGD("FAULT pid not  found\n");
	    }

	    if(bufferProcess!=NULL)
	    {

	      free(bufferProcess);
	    }

	    //正常写文件
	    strcat(dexbufferNamed,".dex");
		FILE * f=fopen(dexbufferNamed,"wb");
		if(!f)
		{
			LOGD("%s : error open sdcard file to write ",dexbufferNamed);
		}
		else{
			fwrite(addr,1,len,f);
			fclose(f);
			LOGD("%s : dump well~ ",dexbufferNamed);
		}

		//base64后写入文件.Anti bangbang hook write function
		//解码: base64 -D -i com.ali.tg.testapp_606716.dex.encode.dex -o my.dex
		// base64 -d com.ali.tg.testapp_606716.dex.encode.dex > my.dex
		strcat(dexbufferNamed,".encode.dex");
		FILE * fp=fopen(dexbufferNamed,"wb");
		if(!fp){
			LOGD("create file failed");
		}else{
			unsigned char *dst=(unsigned char*)malloc(len*2.5);
			unsigned int dlen=len*2.5;
			//int base64_encode( unsigned char *dst, size_t *dlen, const unsigned char *src, size_t )
			//int base64_encode(unsigned char *, unsigned int *, const unsigned char *, unsigned int)
			base64_encode(dst, &dlen, addr, len);
			fwrite(dst, dlen, 1, fp);
			fclose(fp);
			fp = NULL;
		}


	}
	//进行原来的调用,不影响程序运行
	return oldDexFileParse(addr,len,dvmdex);
}
Beispiel #27
0
Boolean ServerProcess::isCIMServerRunning(void)
{
  FILE *pid_file;
  pid_t pid = 0;

  // open the file containing the CIMServer process ID
  pid_file = fopen(getPIDFileName(), "r");
  if (!pid_file)
  {
      return false;
  }

  // get the pid from the file
  fscanf(pid_file, "%d\n", &pid);

  fclose(pid_file);

  if (pid == 0)
  {
     return false;
  }

  //
  // check to see if cimserver process is alive
  //
#if defined(PEGASUS_OS_HPUX)
  struct pst_status pstru;

  int ret_code;
  ret_code = pstat_getproc(&pstru, sizeof(struct pst_status), (size_t)0, pid);

  if ( (ret_code != -1 ) && (strcmp(pstru.pst_ucomm, getProcessName())) == 0)
  {
      //
      // Check to see if this command process has the same pid as the 
      // cimserver daemon process pid stored in the cimserver_start.conf 
      // file.  Since the command has the same name as the cimserver daemon
      // process, this could happen after a system reboot.  If the pids are
      // the same, cimserver isn't really running.
      //
      Uint32 mypid = System::getPID();
      if ((mypid != pid) && (parentPid != pid))
      {
          // cimserver is running
          return true;
      }
  }
#endif
#if defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC)
  if (get_proc(pid) != -1 )
  {
      // cimserver is running
      return true;
  }
#endif
#if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
    return isProcRunning(pid);
#endif
#if defined(PEGASUS_OS_AIX)
    if (aixcimsrvrunning(pid, getProcessName())!=-1)
        return true;
#endif
  return false;
}