示例#1
0
BOOL CCmdDlg::Cmd_DB()
{
	ULONG_PTR addr;
	if (GetParamCount() >= 2) {

		ULONG_PTR addr = xtol(GetParam(1));
		if (!IsValidPtr(addr)) {

			PrintLine(_T("invalid address: %p"), addr );
			return TRUE;
		}
	} else
		addr = m_dumpAddr;

	BYTE buf[1024];
	size_t len = 0x10;

	if (GetParamCount() > 2) {
		len = atol(GetParam(2));
		if (len == 0)
			len = 1;

		if (len > sizeof(buf))
			len = sizeof(buf);
	}
        
	size_t readlen = g_dbgEng->ReadMemory((PVOID )addr, buf, len);
	len = readlen;

	size_t n = 0;
	while (n < len) {

		Print("%p\t", addr + n);

		for (int i = 0; i < 0x10; i ++) {
			if (n + i < len)
				Print("%02X ", buf[n + i]);
			else
				Print("   ");
		}

		Print("|");

		for (int i = 0; i < 0x10 && n + i < len; i ++) {
			BYTE c = buf[n + i];

#define IsVisableChar(C)		( (C) < 0x20 )

			Print("%c", IsVisableChar(c) ? '.' : c);
		}
        
		Print(CRLF);

		n += 0x10;
	}

	m_dumpAddr = addr + len;

	return TRUE;
}
示例#2
0
BOOL CCmdDlg::Cmd_U()
{
	ULONG_PTR addr;
	if (GetParamCount() >= 2) {

		addr = xtol(GetParam(1));
		if (!IsValidPtr(addr)) {

			PrintLine(_T("invalid address: %p"), addr );
			return TRUE;
		}
	} else
		addr = m_disasmAddr;

	BYTE buf[1024];
	size_t len = 0x10;

	if (GetParamCount() > 2) {
		len = atol(GetParam(2));
		if (len == 0)
			len = 1;

		if (len > sizeof(buf))
			len = sizeof(buf);
	}

	size_t readlen = g_dbgEng->ReadMemory((PVOID )addr, buf, len);
	len = readlen;

	t_disasm da;
	memset(&da, 0, sizeof(da));

	// ulong l = Disasm(code, len, (ulong )addr, &da, DISASM_SIZE);
	ULONG pos = 0;
	ulong l;

	m_disasmAddr = addr;

	while (pos <= len) {

		l = Disasm((char* )&buf[pos], len - pos, (ulong )addr + pos, &da, DISASM_CODE);
		if (l == 0)
			break;

		m_disasmAddr += l;
	    
		PrintLine(" %p | %3i  %-24s  %-24s\n", addr + pos, l, da.dump, da.result);

		pos += l;
	}
	
	return TRUE;
}
示例#3
0
bool CFunctionHandler::GetParam(int nIdx, bool& b)	const
{
    BEHAVIAC_ASSERT(nIdx <= GetParamCount() && "CFunctionHandler::GetParam - (CODE/ERROR) Index out of range");
    int nRealIdx = nIdx + 1;

    if (lua_isnil(m_pLS, nRealIdx))
    {
        b = false;
    }
    else if (lua_isnumber(m_pLS, nRealIdx))
    {
        int nVal = 0;
        nVal = (int)lua_tonumber(m_pLS, nRealIdx);

        if (nVal)
        {
            b = true;
        }
        else
        {
            b = false;
        }
    }
    else
    {
        return false;
    }

    return true;
}
示例#4
0
ScriptVarType CFunctionHandler::GetParamType(int nIdx) const
{
    BEHAVIAC_ASSERT(nIdx <= GetParamCount() && "CFunctionHandler::GetParam - (CODE/ERROR) Index out of range");
    int nRealIdx = nIdx + 1;

    if (lua_isnil(m_pLS, nRealIdx))
    {
        return svtNull;
    }
    else if (lua_iscfunction(m_pLS, nRealIdx) || lua_isfunction(m_pLS, nRealIdx))
    {
        return svtFunction;
    }
    else if (lua_isnumber(m_pLS, nRealIdx))
    {
        return svtNumber;
    }
    else if (lua_isstring(m_pLS, nRealIdx))
    {
        return svtString;
    }
    else if (lua_istable(m_pLS, nRealIdx))
    {
        return svtObject;
    }
    else if (lua_isuserdata(m_pLS, nRealIdx))	// Added by Mrcio
    {
        // was missing the userdata type
        return svtUserData;						//
    }											//

    return svtNull;
}
示例#5
0
BOOL CCmdDlg::Cmd_DD()
{
	ULONG_PTR addr;
	if (GetParamCount() >= 2) {

		ULONG_PTR addr = xtol(GetParam(1));
		if (!IsValidPtr(addr)) {

			PrintLine(_T("invalid address: %p"), addr );
			return TRUE;
		}
	} else
		addr = m_dumpAddr;

	BYTE buf[1024];
	size_t len = 0x10 / sizeof(DWORD);

	if (GetParamCount() > 2) {
		len = atol(GetParam(2));
		if (len == 0)
			len = 1;

		if (len > sizeof(buf) / sizeof(DWORD))
			len = sizeof(buf) / sizeof(DWORD);
	}

	size_t readlen = g_dbgEng->ReadMemory((PVOID )addr, buf, len * sizeof(DWORD));
	len = readlen / sizeof(DWORD);

	size_t n = 0;
	while (n < len) {

		Print("%p\t", addr + n * sizeof(DWORD));

		for (int i = 0; i < 0x10 && n < len; i ++, n ++) {
			Print("%08X ", *(DWORD* )&buf[n * sizeof(DWORD)]);
		}

		Print(CRLF);
	}

	m_dumpAddr = addr + len * sizeof(DWORD);

	return TRUE;
}
示例#6
0
bool CFunctionHandler::GetParam(int nIdx, EntityId& entityId)	const
{
    BEHAVIAC_ASSERT(nIdx <= GetParamCount() && "CFunctionHandler::GetParam - (CODE/ERROR) Index out of range");
    const char* entityIdStr = (const char*)lua_tostring(m_pLS, nIdx + 1);
    EntityId::IdType id;
    sscanf(entityIdStr, "%llu", &id);
    entityId = EntityId(id);
    return entityId.IsValid();
}
示例#7
0
BOOL CCmdDlg::Cmd_E()
{
	if (GetParamCount() != 2) {

		PrintLine(_T("invalid command"));
		return TRUE;
	}

	ULONG_PTR addr = xtol(GetParam(1));
	if (!IsValidPtr(addr)) {

		PrintLine(_T("invalid address: %p"), addr );
		return TRUE;
	}

	CBinModifyDlg dlg;
	if (dlg.DoModal() != IDOK)
		return TRUE;

	DWORD n;
	WCHAR* wstr;
	size_t len;

	bool result = false;

	USES_CONVERSION;

	switch(dlg.m_type) {
		case 0: // BYTE
		case 1: // WORD
		case 2:	// DWORD
			if (dlg.m_hex)
				_stscanf((LPCTSTR )dlg.m_strWhat, "%x", &n);
			else
				_stscanf((LPCTSTR )dlg.m_strWhat, "%d", &n);

			result = ModifyMem(addr, (BYTE* )&n, dlg.m_type == 0 ? 1 : dlg.m_type * 2);
			break;

		case 3: // ASCII
			result = ModifyMem(addr, (BYTE* )(LPCSTR )dlg.m_strWhat, dlg.m_strWhat.GetLength());
			break;

		case 4: // UNICODE
			wstr = T2W((LPCSTR )dlg.m_strWhat);
			len = wcslen(wstr) * 2;

			result = ModifyMem(addr, (BYTE* )wstr, len);
			break;
	}

	if (!result)
		MessageBox(_T("modification failed."), NULL);

	return TRUE;
}
JSBool XPCDispInterface::Member::GetValue(XPCCallContext& ccx,
                                          XPCNativeInterface * iface, 
                                          jsval * retval) const
{
    // This is a method or attribute - we'll be needing a function object

    // We need to use the safe context for this thread because we don't want
    // to parent the new (and cached forever!) function object to the current
    // JSContext's global object. That would be bad!
    if((mType & RESOLVED) == 0)
    {
        JSContext* cx = ccx.GetSafeJSContext();
        if(!cx)
            return JS_FALSE;

        intN argc;
        JSNative callback;
        // Is this a function or a parameterized getter/setter
        if(IsFunction() || IsParameterizedProperty())
        {
            argc = GetParamCount();
            callback = XPC_IDispatch_CallMethod;
        }
        else
        {
            argc = 0;
            callback = XPC_IDispatch_GetterSetter;
        }

        JSFunction *fun = JS_NewFunctionById(cx, callback, argc, 0, nsnull, mName);
        if(!fun)
            return JS_FALSE;

        JSObject* funobj = JS_GetFunctionObject(fun);
        if(!funobj)
            return JS_FALSE;

        // Store ourselves and our native interface within the JSObject
        if(!JS_SetReservedSlot(ccx, funobj, 0, PRIVATE_TO_JSVAL((void *) this)))
            return JS_FALSE;

        if(!JS_SetReservedSlot(ccx, funobj, 1, PRIVATE_TO_JSVAL(iface)))
            return JS_FALSE;

        {   // scoped lock
            XPCAutoLock lock(ccx.GetRuntime()->GetMapLock());
            const_cast<Member*>(this)->mVal = OBJECT_TO_JSVAL(funobj);
            const_cast<Member*>(this)->mType |= RESOLVED;
        }
    }
    *retval = mVal;
    return JS_TRUE;
}
示例#9
0
//-----------------------------------------------------------------------------
// Finds a particular parameter	(works because the lowest parameters match the shader)
//-----------------------------------------------------------------------------
int CBaseShader::FindParamIndex( const char *pName ) const
{
	int numParams = GetParamCount();
	for( int i = 0; i < numParams; i++ )
	{
		if( Q_strnicmp( GetParamInfo( i ).m_pName, pName, 64 ) == 0 )
		{
			return i;
		}
	}
	return -1;
}
示例#10
0
bool CFunctionHandler::GetParam(int nIdx, float& f)	const
{
    int nRealIdx = nIdx + 1;
    BEHAVIAC_ASSERT(nIdx <= GetParamCount() && "CFunctionHandler::GetParam - (CODE/ERROR) Index out of range");

    if (!lua_isnumber(m_pLS, nRealIdx))
    {
        return false;
    }

    f = (float)lua_tonumber(m_pLS, nRealIdx);
    return true;
}
示例#11
0
bool CFunctionHandler::GetParam(int nIdx, CDynamicType*& ud) const
{
    BEHAVIAC_ASSERT(nIdx <= GetParamCount() && "CFunctionHandler::GetParam - (CODE/ERROR) Index out of range");
    USER_DATA_CHUNK* udc = (USER_DATA_CHUNK*)lua_touserdata(m_pLS, nIdx + 1);

    if (!udc)
    {
        return false;
    }

    ud = udc->userData;
    return true;
}
示例#12
0
bool CFunctionHandler::GetParam(int nIdx, IScriptObject* pObj)	const
{
    BEHAVIAC_ASSERT(nIdx <= GetParamCount() && "CFunctionHandler::GetParam - (CODE/ERROR) Index out of range");
    int nRealIdx = nIdx + 1;

    if (!lua_istable(m_pLS, nRealIdx))
    {
        return false;
    }

    lua_pushvalue(m_pLS, nRealIdx);
    pObj->Attach();
    return true;
}
示例#13
0
bool CFunctionHandler::GetParam(int nIdx, char*& s)	const
{
    BEHAVIAC_ASSERT(nIdx <= GetParamCount() && "CFunctionHandler::GetParam - (CODE/ERROR) Index out of range");
    //if(!lua_isstring(m_pLS,nIdx))return false;
    s = (char*)lua_tostring(m_pLS, nIdx + 1);

    if (s)
    {
        return true;
    }
    else
    {
        return false;
    }
}
示例#14
0
BOOL CCmdDlg::Cmd_RTTI()
{
	if (GetParamCount() != 2) {

		PrintLine(_T("invalid command"));
		return TRUE;
	}

	ULONG_PTR addr = xtol(GetParam(1));
	if (!IsValidPtr(addr)) {

		PrintLine(_T("invalid address: %p"), addr );
		return TRUE;
	}

	ULONG_PTR vtablePtr = 0;
	g_dbgEng->ReadMemory((PVOID )addr, (PBYTE )&vtablePtr, sizeof(vtablePtr));	

	ULONG_PTR rttiPtr = vtablePtr - sizeof(ULONG_PTR);
	ULONG_PTR rtti;
	g_dbgEng->ReadMemory((PVOID )rttiPtr, (PBYTE )&rtti, sizeof(rtti));

	ULONG_PTR typeDescPtrPtr = rtti + offsetof(RTTICompleteObjectLocator, pTypeDescriptor);
	ULONG_PTR typeDescPtr;

	g_dbgEng->ReadMemory((PVOID )typeDescPtrPtr, (PBYTE )&typeDescPtr, sizeof(typeDescPtr));

	TypeDescriptor typeDesc;
	memset(&typeDesc, 0 , sizeof(typeDesc));

	g_dbgEng->ReadMemory((PVOID )typeDescPtr, (PBYTE )&typeDesc, sizeof(typeDesc));

	PrintLine("class name: %s", typeDesc.name);

	ULONG_PTR vtable[32];
	memset(vtable, 0 , sizeof(vtable));
	g_dbgEng->ReadMemory((PVOID )vtablePtr, (PBYTE )vtable, sizeof(vtable));

	PrintLine("vtable: %p", vtablePtr);
	for (int i = 0; i < 32; i ++) {
		if (!IsValidPtr(vtable[i]))
			break;
		PrintLine("\t%d\t%p", i, vtable[i]);
	}
	
	return TRUE;
}
/**
Finds the keystring from the source string and replaces it with the
replacement string.
*/
HBufC* CResourceLoader::FormatStringL(const TDesC& aSource, const TDesC& aKey, const TDesC& aSubs, TBidiText::TDirectionality aDirectionality,
    TInt& aParamCount, TInt aSubCount)
    {
    if (aParamCount == KUnknownCount)
        aParamCount = GetParamCount(aSource);

    if (aSubCount == KUnknownCount)
        aSubCount = GetSubStringCount(aSource);

    // determine lenght of needed buffer 
    TInt sourcelength(aSource.Length()); 
    TInt keylength(aKey.Length());
    TInt subslength(aSubs.Length());
    TInt destlength = 0;
    if (subslength >= keylength)
        {
        destlength = sourcelength + ((subslength - keylength) * aParamCount);
        }
    else
        {
        destlength = sourcelength;
        }

    destlength += KExtraSpaceForMainStringDirMarker * aSubCount;
    destlength += KExtraSpaceForSubStringDirMarkers * aParamCount;
    //
    // Allocating heap buffer for return string.
    //

    HBufC* retbuf = HBufC::NewL(destlength);
    TPtr retptr(retbuf->Des());

    // Formating the resource string. Don't bother with format, 
    // if parameter count is not above zero
    if (aParamCount > 0)
        {
        aParamCount -= Formater(retptr, aSource, aKey, aSubs, aDirectionality);
        __ASSERT_DEBUG(aParamCount >= 0, User::Invariant());
        }

    //
    // If the key string wasn't found, retbuf is empty.
    //
    return retbuf; 
    }
ELEMDESC* XPCDispJSPropertyInfo::GetParamInfo()
{
    PRUint32 paramCount = GetParamCount();
    ELEMDESC* elemDesc;
    if(paramCount != 0)
    {
        elemDesc = new ELEMDESC[paramCount];
        if(elemDesc)
        {
            for(PRUint32 index = 0; index < paramCount; ++index)
            {
                FillOutElemDesc(VT_VARIANT, PARAMFLAG_FIN, elemDesc[index]);
            }
        }
    }
    else
        elemDesc = 0;
    // Caller becomes owner
    return elemDesc;
}
示例#17
0
bool CFunctionHandler::GetParam(int nIdx, HSCRIPTFUNCTION& hFunc)	const
{
    BEHAVIAC_ASSERT(nIdx <= GetParamCount() && "CFunctionHandler::GetParam - (CODE/ERROR) Index out of range");
    const	int nRealIdx = nIdx + 1;

    if (!lua_isfunction(m_pLS, nRealIdx))
    {
        return false;
    }

    lua_pushvalue(m_pLS, nRealIdx);
    const	int nRef = lua_ref(m_pLS, 0);

    if	(!nRef)
    {
        return	false;
    }

    hFunc = nRef;
    return true;
}
示例#18
0
BOOL CVNNetMsg::AddParam(
    int id, 
    int type, 
    int length, 
    char* data
    )
    // Current assumption is any 2, 4 byte integers are already
    // in network byte order.
{
    if (m_Data == 0)
        return FALSE;

    // Ensure the parameter doesn't exist
    int tmp;
    if (GetParam(id, &tmp, &tmp, 0) == 0)
    {
        // The parameter already exists, we don't support
        // having two parameters of the same ID. There is
        // currently no method to modify a parameter within
        // a message either.
        return FALSE;
    }

    int requiredLength = ParamDataStart_Offset + length;
    if ((m_Pos + requiredLength) > m_MaxLength)
    {
        // Need to realloc the data
        int oldLength = m_MaxLength;
        m_MaxLength = m_Pos + requiredLength;
		char * hg = new char[m_MaxLength];
        //HGLOBAL hg = GlobalAlloc(GMEM_FIXED, m_MaxLength);
        if (hg)
        {
            char* data = hg;
            memcpy(data, m_Data, oldLength);
			delete[] m_Data;
            //GlobalFree(GlobalHandle((void*)m_Data));
            m_Data = data;          
        } 
        else
        {
            m_Data = 0;
            m_MaxLength = 0;
            return FALSE;
        }
    }

    // Update parmaeter count
    SetParamCount(GetParamCount() + 1);

    u_char* ptr = (u_char*)&m_Data[m_Pos];   
    ptr[ParamID_Offset] = id;
    ptr[ParamType_Offset] = type;

    u_long* lptr = (u_long*)&ptr[ParamLength_Offset];
    *lptr = htonl(length);

    memcpy(&ptr[ParamDataStart_Offset], data, length);

    m_Pos += requiredLength;

    // Update message length
    int addedLength = ParamDataStart_Offset + length;
    SetLength(GetLength() + addedLength);

    return TRUE;
}
示例#19
0
BOOL CCLITerminal::CommandTask(CLISESSION *pSession, BOOL bComplete, BOOL bAddHistory)
{
	CLIHANDLER	*pHandler;
	char		szCommand[256] = "";
	int			nResult, nDepts=0, nCommand;
	int			i, nIndex, argc, nParam, nPos;

	// Make New Line
	WriteStream(pSession, "\n\r");
	pSession->szCommand[pSession->nCmdLength] = '\0';

	if (pSession->nMode == CLIMODE_USER)
	{
		nCommand = atoi(pSession->szCommand);
		pSession->nCmdLength = 0;
		pSession->szCommand[0] = '\0';
		
		switch(nCommand) {
		  case 1 :
			   FirmwareDownload(pSession);
			   WriteStream(pSession, "\n\r");
			   break;
		  case 2 : 
			   pSession->nMode = CLIMODE_COMMAND;
			   DisplayPrompt(pSession);
			   return TRUE; 
		}
		DisplaySplash(pSession);
		return TRUE;
	}

	// Check Login State
	if (!pSession->bLogined)
	{
		if (pSession->bNeedUser)
		{
			if (!CheckUser(pSession))
			{
				// Display Login Error Message
				WriteStream(pSession, "Invalid User.\r\n");
			}

			// Clear Command Buffer
			pSession->nCmdLength 	= 0;
			pSession->szCommand[0]	= '\0';
			DisplayPrompt(pSession);
			return TRUE;

		}
		else if (!CheckLogin(pSession))
		{
			// Clear Command Buffer
			pSession->nCmdLength 	= 0;
			pSession->szCommand[0]	= '\0';
			pSession->bNeedUser		= TRUE;

			// Display Login Error Message
			WriteStream(pSession, "Invalid account or password.\r\n\r\n");
			strcpy(pSession->szPrompt, m_pCLIService->m_szUserPrompt);
			pSession->nLoginRetry++;
			if (pSession->nLoginRetry >= 3)
			{
				if (pSession->nType == CLITYPE_SERIAL)
					sleep(3);
				return FALSE;
			}

			DisplayPrompt(pSession);
			return TRUE;
		}

		// Clear Command Buffer
		pSession->nCmdLength 	= 0;
		pSession->szCommand[0]	= '\0';

		// Callback Login
		if (m_pCLIService->m_pConstruct &&
			m_pCLIService->m_pConstruct->pfnOnLogin)
			m_pCLIService->m_pConstruct->pfnOnLogin(pSession);

		// Login Complete
		pSession->bLogined = TRUE;
		WriteStream(pSession, "\n\r");
		strcpy(pSession->szPrompt, m_pCLIService->m_szDefaultPrompt);
		DisplayPrompt(pSession);
		return TRUE;
	}

	if (pSession->nCmdLength > 0)
	{
		// Find Command
		nResult = CLIERR_OK;
		pSession->szCommand[pSession->nCmdLength] = '\0';

		if (pSession->szCommand[0] == '!')
		{
			if (strcmp(pSession->szCommand, "!!") == 0)
			{
				strcpy(pSession->szCommand, pSession->pszHistory[pSession->nHistoryCount-1]);
				pSession->nCmdLength = strlen(pSession->szCommand);
			}
			else
			{
				nIndex = atoi(&pSession->szCommand[1]);
				if ((nIndex > 0) && (nIndex <= pSession->nHistoryCount))
				{
					strcpy(pSession->szCommand, pSession->pszHistory[nIndex-1]);
					pSession->nCmdLength = strlen(pSession->szCommand);
				}
			}
		}

		pSession->pszArgString = strdup(pSession->szCommand);
		if (bAddHistory)
			AddHistory(pSession, pSession->szCommand);

		SpliteParameter(pSession);
		pHandler = FindCommandHandler(pSession, nDepts, szCommand);
		if (pHandler != NULL)
		{
			// Execute Command
			nParam = GetParamCount(pHandler);
			argc = pSession->argc - (nDepts + 1);
			for(i=0; i<argc; i++)
				pSession->argv[i] = pSession->argv[nDepts+i+1];

			// 파라메터의 갯수가 더 많은 경우를 막을때, add apn 명령 때문에 허용하도록 변경 2007/9/5
			// if ((nParam == argc) || (pHandler->pszParam && (argc >= GetMinParamCount(pHandler)) && (argc <= nParam)))

			if ((nParam == argc) || (pHandler->pszParam && (argc >= GetMinParamCount(pHandler))))
			{
				nPos = ValidateParameter(pSession, pHandler);
				if (nPos == -1)
				{
					pSession->nCmdLength 	= 0;
					pSession->szCommand[0]	= '\0';

					if (m_pCLIService->m_pConstruct &&
						m_pCLIService->m_pConstruct->pfnOnCommand)
						m_pCLIService->m_pConstruct->pfnOnCommand(pSession, argc, pSession->argv, pHandler);

					if (pHandler->nGroup >= pSession->nGroup)
					{
						if (m_pCLIService->m_bEnableLog && pHandler->bLogFlag)
							m_pCLIService->AddLog(pSession->szUser, pSession->szCommand);

						nResult = pHandler->pfnCommand(pSession, argc, pSession->argv, (void *)pHandler);
						WriteStream(pSession, "\xd\xa");
					}
					else
					{
						WriteStream(pSession, "Permission Denied.");					
						WriteStream(pSession, "\xd\xa");
					}
				}
				else
				{
					WriteStream(pSession, "Invalid parameter : '");					
					WriteStream(pSession, pSession->argv[nPos]);					
					WriteStream(pSession, "'\xd\xa");
					WriteStream(pSession, "\xd\xa");
				}
			}
			else
			{
				WriteStream(pSession, "usage: ");
				WriteStream(pSession, szCommand);
				DisplayWideParameter(pSession, pHandler);
				DisplayAllParameter(pSession, pHandler);
				WriteStream(pSession, "\xd\xa");
			}
		}

		if (pSession->pszArgString)
			FREE(pSession->pszArgString);
		pSession->pszArgString = NULL;

		if (nResult == CLIERR_ERROR)
			return FALSE;
	}

	// Clear Command Buffer
	pSession->nCmdLength 	= 0;
	pSession->szCommand[0]	= '\0';

	// Display Prompt
	DisplayPrompt(pSession);
	return TRUE;
}
示例#20
0
wxString wxCmdLineParser::GetParam(size_t n) const
{
    wxCHECK_MSG( n < GetParamCount(), wxEmptyString, wxT("invalid param index") );

    return m_data->m_parameters[n];
}