示例#1
0
/* EXPORTED LUA FUNCTIONS */
int keyboardScript::lua_Wait(lua_State* L)
{
	if (!verifyParameters(L, "lua_Wait", 1))
		return 1;

	auto time = keyboardScript::getIntegerParameter(L, 1);
	Sleep(time);
	lua_pushboolean(L, true);
	return 1;
}
bool CEvaluationNodeCall::compile(const CEvaluationTree * pTree)
{
  bool success = true;
  clearParameters(mpCallParameters, mCallNodes);

  switch (mType & 0x00FFFFFF)
    {
      case FUNCTION:
        mpFunction =
          dynamic_cast<CFunction *>(CCopasiRootContainer::getFunctionList()->findFunction(mData));

        if (!mpFunction) return false;

        // We need to check whether the provided arguments match the on needed by the
        // function;
        if (!verifyParameters(mCallNodes, mpFunction->getVariables())) return false;

        mpCallParameters = buildParameters(mCallNodes);
        break;

      case EXPRESSION:
        mpExpression =
          dynamic_cast<CExpression *>(CCopasiRootContainer::getFunctionList()->findFunction(mData));

        if (!mpExpression)
          {
            // We may have a function with no arguments the parser is not able to distinguish
            // between that and an expression.
            mpFunction =
              dynamic_cast<CFunction *>(CCopasiRootContainer::getFunctionList()->findFunction(mData));

            if (!mpFunction) return false;

            mType = (CEvaluationNode::Type)(CEvaluationNode::CALL | FUNCTION);
            success = compile(pTree);
          }
        else
          {
            success = mpExpression->compile(static_cast<const CExpression *>(pTree)->getListOfContainer());
          }

        break;

      default:
        success = false;
        break;
    }

  return success;
}
示例#3
0
// Client-side portion of work for server-relief mode.  Return true if there are no memory
// allocation errors.  The password and data are not cleared if there is an error.
bool TwoCats_ClientHashPassword(TwoCats_HashType hashType, uint8_t *hash, uint8_t *password,
        uint32_t passwordSize, const uint8_t *salt, uint32_t saltSize, uint8_t *data,
        uint32_t dataSize, uint8_t startMemCost, uint8_t stopMemCost, uint8_t timeCost,
        uint8_t multiplies, uint8_t lanes, uint8_t parallelism, uint32_t blockSize,
        uint32_t subBlockSize, uint8_t overwriteCost, bool clearPassword, bool clearData) {

    TwoCats_H H;
    TwoCats_InitHash(&H, hashType);
    if(!verifyParameters(&H, startMemCost, stopMemCost, timeCost, multiplies, lanes,
            parallelism, blockSize, subBlockSize)) {
        return false;
    }

    // Convert overwiteCost from relative to startMemCost to absolute
    if(overwriteCost >= startMemCost) {
        overwriteCost = 0;
    } else if(overwriteCost != 0) {
        overwriteCost = startMemCost - overwriteCost;
    }

    // Add all the inputs, other than stopMemCost
    uint32_t hash32[H.len];
    if(!H.Init(&H) || !H.UpdateUint32(&H, passwordSize) ||
            !H.UpdateUint32(&H, saltSize) || !H.UpdateUint32(&H, dataSize) ||
            !H.UpdateUint32(&H, blockSize) || !H.UpdateUint32(&H, subBlockSize) ||
            !H.Update(&H, &startMemCost, 1) || !H.Update(&H, &timeCost, 1) ||
            !H.Update(&H, &multiplies, 1) || !H.Update(&H, &lanes, 1) ||
            !H.Update(&H, &parallelism, 1) || !H.Update(&H, &overwriteCost, 1) ||
            !H.Update(&H, password, passwordSize) || !H.Update(&H, salt, saltSize) ||
            !H.Update(&H, data, dataSize) || !H.FinalUint32(&H, hash32)) {
        return false;
    }

    // Now clear the password and data if allowed
    if(clearPassword && passwordSize != 0) {
        secureZeroMemory(password, passwordSize);
    }
    if(clearData && dataSize != 0) {
        secureZeroMemory(data, dataSize);
    }

    if(!TwoCats(&H, hash32, startMemCost, stopMemCost, timeCost, multiplies,
            lanes, parallelism, blockSize, subBlockSize, overwriteCost)) {
        return false;
    }
    encodeLittleEndian(hash, hash32, H.size);
    secureZeroMemory(hash32, H.size);
    return true;
}
示例#4
0
int keyboardScript::lua_UpdateKeyboard(lua_State* L)
{
	if (!verifyParameters(L, "lua_UpdateKeyboard", 0))
		return 1;

	if (this->keyboardInstance != nullptr)
	{
		this->keyboardInstance->updateKeyboard();
		lua_pushboolean(L, true);
	}
	else
		lua_pushboolean(L, false);

	return 1;
}
示例#5
0
// Update an existing password hash to a more difficult level of memory cost (garlic).
bool TwoCats_UpdatePassword(TwoCats_HashType hashType, uint8_t *hash, uint8_t oldMemCost,
        uint8_t newMemCost, uint8_t timeCost, uint8_t multiplies, uint8_t lanes,
        uint8_t parallelism, uint32_t blockSize, uint32_t subBlockSize) {

    TwoCats_H H;
    TwoCats_InitHash(&H, hashType);
    if(!verifyParameters(&H, oldMemCost, newMemCost, timeCost, multiplies, lanes,
            parallelism, blockSize, subBlockSize)) {
        return false;
    }
    uint32_t hash32[H.len];
    decodeLittleEndian(hash32, hash, H.size);
    if(!TwoCats(&H, hash32, oldMemCost, newMemCost, timeCost, multiplies, lanes,
            parallelism, blockSize, subBlockSize, 0)) {
        return false;
    }
    encodeLittleEndian(hash, hash32, H.size);
    return TwoCats_ServerHashPassword(hashType, hash);
}
示例#6
0
int keyboardScript::lua_SetKeyColor(lua_State* L)
{
	if (!verifyParameters(L, "lua_SetKeyColor", 4))
		return 1;

	auto key = keyboardScript::getIntegerParameter(L, 1);
	auto r = keyboardScript::getIntegerParameter(L, 2);
	auto g = keyboardScript::getIntegerParameter(L, 3);
	auto b = keyboardScript::getIntegerParameter(L, 4);

	if (this->keyboardInstance != nullptr)
	{
		auto ret = this->keyboardInstance->setKey((uint8_t)key, (uint8_t)r, (uint8_t)g, (uint8_t)b);
		lua_pushboolean(L, ret);
	}
	else
		lua_pushboolean(L, false);

	return 1;
}
示例#7
0
int keyboardScript::lua_InitializeKeyboard(lua_State* L)
{
	if (!verifyParameters(L, "lua_InitializeKeyboard", 1))
		return 1;

	auto type = keyboardScript::getIntegerParameter(L, 1);

	switch (type)
	{
		case KEYBOARD_K70:
			this->keyboardInstance = std::shared_ptr<corsairRGBKeyboard>(new corsairRGBKeyboardK70());
			break;
		case KEYBOARD_K95:
			this->keyboardInstance = std::shared_ptr<corsairRGBKeyboard>(new corsairRGBKeyboardK95());
			break;
		default:
			break;
	}
		
	lua_pushboolean(L, this->keyboardInstance != nullptr && this->keyboardInstance->isValid());
	return 1;
}
void ctkPluginGeneratorAbstractExtension::validate()
{
  Q_D(ctkPluginGeneratorAbstractExtension);
  d->valid = verifyParameters(d->parameters);
}
示例#9
0
bool CEvaluationNodeCall::compile(const CEvaluationTree * pTree)
{
  bool success = true;
  clearParameters(mpCallParameters, mCallNodes);

  CObjectInterface * pObjectInterface = NULL;

  if (mRegisteredFunctionCN != "")
    {
      pObjectInterface = const_cast< CObjectInterface * >(CCopasiRootContainer::getRoot()->getObject(mRegisteredFunctionCN));
    }

  switch (mSubType)
    {
      case S_FUNCTION:

        if (pObjectInterface != NULL)
          {
            mpFunction = dynamic_cast< CFunction * >(pObjectInterface);
          }
        else
          {
            mpFunction =
              dynamic_cast<CFunction *>(CCopasiRootContainer::getFunctionList()->findFunction(mData));
          }

        if (!mpFunction) return false;

        mRegisteredFunctionCN = mpFunction->getCN();

        // We need to check whether the provided arguments match the on needed by the
        // function;
        if (!verifyParameters(mCallNodes, mpFunction->getVariables())) return false;

        mpCallParameters = buildParameters(mCallNodes);
        break;

      case S_EXPRESSION:

        if (pObjectInterface != NULL)
          {
            mpExpression = dynamic_cast<CExpression *>(pObjectInterface);
          }
        else
          {
            mpExpression =
              dynamic_cast<CExpression *>(CCopasiRootContainer::getFunctionList()->findFunction(mData));
          }

        if (!mpExpression)
          {
            // We may have a function with no arguments the parser is not able to distinguish
            // between that and an expression.
            if (pObjectInterface != NULL)
              {
                mpFunction = dynamic_cast< CFunction * >(pObjectInterface);
              }
            else
              {
                mpFunction =
                  dynamic_cast<CFunction *>(CCopasiRootContainer::getFunctionList()->findFunction(mData));
              }

            if (!mpFunction) return false;

            mRegisteredFunctionCN = mpFunction->getCN();

            mMainType = T_CALL;
            mSubType = S_FUNCTION;

            success = compile(pTree);
          }
        else
          {
            mRegisteredFunctionCN = mpExpression->getCN();

            success = mpExpression->compile(static_cast<const CExpression *>(pTree)->getListOfContainer());
          }

        break;

      default:
        success = false;
        break;
    }

  return success;
}