Пример #1
0
int cpu_sqrt(cpu_t* _this)
{
    ISNOTNULL(_this);
    int __errnum = 0;

    double a = 0.0;

    __errnum = stack_Pop(_this->stk, &a);

    ERRHANDLER;

    __errnum = stack_Push(_this->stk, sqrt(a));

    ERRHANDLER;

    return 0;

}
Пример #2
0
BOOL CNameEvent::Fire()
{
	assert(ISNOTNULL(m_hEvent));
	if (ISNULL(m_hEvent))
	{
		DOLOG("can't Fire null event handle!");
		return FALSE;
	}
	BOOL bResult = TRUE;
	
	bResult = SetEvent(m_hEvent);
	if (ISNOTTRUE(bResult))
	{
		DOLOG("SetEvent Failed!" + GetLastError());
		bResult = FALSE;
	}
	return bResult;
}
BOOL CDisplayAdapterHelper::InjectSpecificDllAndProcessByNameInner(LPSTR lpAppName, LPSTR lpDllName, BOOL bInjectSafeMode)
{
	assert(ISNOTNULL(lpAppName));
	if (ISNULL(lpAppName))
	{
		DOLOG("AppName should not to be null !");
		return FALSE;
	}

	DWORD procid = GetSpecificProcIDByNameEx(lpAppName);

	if (ISZERO(procid))
	{
		DOLOG("GetSpecificProcIDByNameEx Failed");
		return FALSE;
	}

	return InjectSpecificDllAndProcessByIdInner(procid,  lpDllName,  bInjectSafeMode);
}
Пример #4
0
//================FUNCTIONS============================
int stack_Ctor(stack_t** _this, int length)
{

    stack_t* stk  = (stack_t*) calloc(sizeof(*stk), 1);

    ISNOTNULL(stk);

    if (0 < length && length < MAX_STACK) stk->len = length;
    else return ELENOUTLIM;

    stk->data = (double*) calloc(stk->len, sizeof(double));
    stk->counter = 0;

    if (!stk->data) return ENULLPTR;

    *_this = stk;

    return 0;
}
Пример #5
0
int cpu_out(cpu_t* _this)
{
    ISNOTNULL(_this);
    int __errnum = 0;

    double a = 0.0;

    __errnum = stack_Pop(_this->stk, &a);

    ERRHANDLER;

    __errnum = stack_Push(_this->stk, a);

    ERRHANDLER;

    printf("%lg\n", a);

    return 0;
}
Пример #6
0
int cpu_dump(cpu_t* _this)
{
    ISNOTNULL(_this);

    stack_Dump(_this->stk);

    fprintf(stderr, "\nax %lg\nbx %lg\ncx %lg\ndx %lg\n\n",
            _this->ax, _this->bx, _this->cx, _this->dx);


    if (!_this->addr) fprintf(stderr, "Invalid address to byte code\n");
    else for(char* ptr = _this->addr; *ptr != END; ptr++)
    {
        if ((ptr - _this->addr) > CODE_SIZE) break;
        int byte = *ptr;
        fprintf(stderr, "%02x ", byte);
    }
    fprintf(stderr, "\n\n");


}
Пример #7
0
int cpu_add(cpu_t* _this)
{
    ISNOTNULL(_this);
    int __errnum = 0;

    double a = 0.0;

    __errnum = stack_Pop(_this->stk, &a);

    ERRHANDLER;

    double b = 0.0;

    __errnum = stack_Pop(_this->stk, &b);

    ERRHANDLER;

    __errnum = stack_Push(_this->stk, (a + b));

    ERRHANDLER;

    return 0;
}
Пример #8
0
int stack_Dump(stack_t* _this)
{
    ISNOTNULL(_this);

    int is_OK = stack_Ok(_this);
    fprintf(stderr, "-----------------------\n");
    fprintf(stderr, "STACK[0x%x] %s \n",
             _this, ((!is_OK)? "OK" : "!!!BAD!!!"));
    if(is_OK) fprintf(stderr, "ERROR NUMBER %d", is_OK);

    if(_this) fprintf(stderr, "\tCOUNT = %d\n"
                "\tDATA[0x%x], max %d\n\n",
                _this->counter, _this->data, _this->len);

    if(_this->data)
        for(int i = 0; i < _this->len; i++)
            fprintf(stderr, "\t\t[%d] = %lg %c\n", i, _this->data[i],
                ((i < _this->counter)? '*' : ' '));

    fprintf(stderr, "\n\n");
    if(stderr != stdout) fflush(stderr);

    return 0;
}
BOOL CDisplayAdapterHelper::InjectSpecificDllAndProcessByIdInner(DWORD dwProcessID, LPSTR lpDllName, BOOL bInjectSafeMode)
{
#if defined _M_X64 && _MSC_VER == 1800
	//workaround AVX2 bug in VS2013, http://connect.microsoft.com/VisualStudio/feedback/details/811093
	_set_FMA3_enable(0);
#endif
	
	assert(dwProcessID != 0);
	if (ISZERO(dwProcessID))
	{
		DOLOG("id of target process can't be zero !");
		return FALSE;
	}
	assert(ISNOTNULL(lpDllName));
	if(ISNULL(lpDllName))
	{
		DOLOG("name of dll can't not be null !");
		return FALSE;
	}

	CHAR cbDllPath[MAX_PATH] = { 0 };
	//if (ISZERO(GetCurrentDirectoryA(dirLen, cbDllPath)))
	if(ISZERO(GetModuleFileNameA(GetModuleHandle(NULL), cbDllPath, MAX_PATH)))
	{
		DOLOG("GetCurrentDirectory Failed ! " + GetLastError());
		return FALSE;
	}
	CHAR* lpFullPath = strrchr(cbDllPath, '\\');
	lpFullPath[1] = '\0';
	UINT dirLen = strlen(cbDllPath);
	const size_t fileNameLen = strlen(lpDllName);
	size_t len = dirLen + fileNameLen + 1;
	cbDllPath[dirLen - 1] = '\\';
	strncpy_s(cbDllPath + dirLen, len - dirLen, lpDllName, fileNameLen);

	BOOL result = TRUE;
	LoadSeDebugPrivilege();
	
	CNameEvent nameEvent;
	nameEvent.Init(EVENTNAME, TRUE);
	CNameShareMemory shareMemInst;

	shareMemInst.Init(SHAREMEMNAME, MAX_PATH, TRUE);
	char* lpInfo = shareMemInst.GetBuffer();
	ZeroMemory(lpInfo, MAX_PATH);

	if (!bInjectSafeMode)
	{
		OPPROC pOpenProcess;
		HANDLE hProcess;
		char pOPStr[12];
		int i;

		memcpy(pOPStr, "NpflUvhel{x", 12); //OpenProcess obfuscated
		for (i = 0; i<11; i++) pOPStr[i] ^= i ^ 1;

		pOpenProcess = (OPPROC)GetProcAddress(GetModuleHandle(TEXT("KERNEL32")), pOPStr);

		if (ISNULL(pOpenProcess))
		{
			DOLOG("GetProcAddress failed ! " + GetLastError());
			return FALSE;
		}

		hProcess = (*pOpenProcess)(PROCESS_ALL_ACCESS, FALSE, dwProcessID);

		if (ISNULL(hProcess))
		{
			DOLOG("OpenProcess Failed ! " + GetLastError());
			return FALSE;
		}
		if (ISFALSE(AdjustDllforProcess(hProcess, cbDllPath)))
		{
			DOLOG("AdjustDllforProcess Failed ! " + GetLastError());
			return FALSE;
		}

		if (ISNOTTRUE(InjectLibraryA(hProcess, cbDllPath, (DWORD)(len - 1))))
		{
			result = FALSE;
			DOLOG("Inject Library failed ! " + GetLastError());
		}

		CloseHandle(hProcess);
	}
	else
	{

#ifdef _WIN64
		CHAR cbTempDllPath[MAX_PATH] = { 0 };
		if (ISTRUE(AdjustDllfor64bit(cbTempDllPath, MAX_PATH, cbDllPath)))
		{
			memcpy(cbDllPath, cbTempDllPath, strlen(cbTempDllPath) + 1);
		}
#endif
		if (!InjectLibrarySafeA(dwProcessID, cbDllPath, (DWORD)(len - 1)))
		{
			DOLOG("InjectLibrarySafeA failed ! "+ GetLastError());
			result = FALSE;
		}
	}

	if(ISTRUE(nameEvent.Wait()))
	{
		lpInfo = shareMemInst.GetBuffer();
		if (ISNOTNULL(lpInfo))
		{
			DOLOG(" 得到的信息是>>>>>>" + lpInfo);
			strcpy(m_cbVideoAdapterName, lpInfo);
		}
	}
	nameEvent.Close();
	shareMemInst.Close();

	return result ;
}
Пример #10
0
int cpu_end(cpu_t* _this)
{
    ISNOTNULL(_this);
    end_logging();
    return 0;
}
Пример #11
0
// [2015/12/15 wupeng]
// if failed return 0, success return the Process ID
DWORD GetSpecificProcIDByNameEx(LPSTR lpName)
{
    if (ISNULL(lpName))
    {
        DOLOG("Process Name can't be null");
        return 0;
    }

    if (ISFALSE(EnableDebugPrivilege(TRUE)))
    {
        DOLOG("EnableDebugPrivilege Failed !");
        return 0;
    }

    DWORD allProcessIDs[2048] = { 0 };
    DWORD cbNeed = 0;

    if (ISZERO(EnumProcesses(allProcessIDs, sizeof(allProcessIDs), &cbNeed)))
    {
        DOLOG("EnumProcess Failed ! " + GetLastError());
        return 0;
    }

    HANDLE hProcess = NULL;
    CHAR szProcessName[MAX_PATH] = { 0 };
    for (DWORD i = 0; i < cbNeed; i++)
    {
        if (ISZERO(allProcessIDs[i]))
        {
            continue;
        }

        ZeroMemory(szProcessName, sizeof(szProcessName));
        hProcess = OpenProcess(
                       PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE,
                       allProcessIDs[i]);
        if (ISNOTNULL(hProcess))
        {
            DWORD dwNameSize = sizeof(szProcessName);
            if (QueryFullProcessImageNameA(hProcess, 0, szProcessName, &dwNameSize))
                //if (ISNOZERO(GetModuleBaseNameA(hProcess, NULL, szProcessName,
                //	sizeof(szProcessName))))
            {
                DOLOG(" >>" + szProcessName + " : " + allProcessIDs[i]);

                string strPath = szProcessName;
                TrimFilePathA(strPath);
                if (ISZERO(_stricmp(strPath.c_str(), lpName)))
                {
                    DOLOG("Found the Process " + lpName);
                    CloseHandle(hProcess);
                    return allProcessIDs[i];
                }
            }
            else
            {
                DOLOG("GetmoudleBaseName Failed ! " + GetLastError());
            }
            CloseHandle(hProcess);
        }
        else
        {
            DOLOG("OpenProcess Failed ! " + allProcessIDs[i] + " LastError:" + GetLastError());
        }
    }

    DOLOG("can't found the specify name process Failed ! ");
    return 0;
}