Пример #1
0
/*
 * An AllJoyn dictionary entry maps cleanly to a JavaScript object property
 */
static AJ_Status PushDictionaryArg(duk_context* ctx, AJ_Message* msg)
{
    AJ_Arg arg;
    AJ_Status status = AJ_UnmarshalContainer(msg, &arg, AJ_ARG_ARRAY);
    if (status == AJ_OK) {
        int objIndex = duk_push_object(ctx);
        while (status == AJ_OK) {
            AJ_Arg entry;
            status = AJ_UnmarshalContainer(msg, &entry, AJ_ARG_DICT_ENTRY);
            if (status == AJ_OK) {
                status = PushArg(ctx, msg); // key
                if (status == AJ_OK) {
                    status = PushArg(ctx, msg); // value
                }
                if (status == AJ_OK) {
                    duk_put_prop(ctx, objIndex);
                }
                AJ_UnmarshalCloseContainer(msg, &entry);
            }
        }
        if (status == AJ_ERR_NO_MORE) {
            status = AJ_OK;
        }
        AJ_UnmarshalCloseContainer(msg, &arg);
    }
    return status;
}
Пример #2
0
/// <summary>
/// Generate function call
/// </summary>
/// <param name="pFN">Function pointer</param>
/// <param name="args">Function arguments</param>
/// <param name="cc">Calling convention</param>
void AsmHelper32::GenCall( const AsmFunctionPtr& pFN, const std::vector<AsmVariant>& args, eCalligConvention cc /*= CC_stdcall*/ )
{
    std::set<int> passedIdx;

    // Pass arguments in registers
    // 64bit arguments are never passed in registers
    if ((cc == cc_thiscall || cc == cc_fastcall) && !args.empty())
        for (int i = 0, j = 0; i < static_cast<int>(args.size()) && (j < ((cc == cc_fastcall) ? 2 : 1)); i++)
            if (args[i].reg86Compatible())
            {
                PushArg( args[i], (eArgType)j );
                passedIdx.emplace( i );
                j++;
            }      

    // Push args on stack
    for (int i = (int)args.size() - 1; i >= 0; i--)
    {
        // Skip arguments passed in registers
        if (passedIdx.count( i ) == 0)
            PushArg( args[i] );
    }
 
    // Direct pointer
    if(pFN.type == AsmVariant::imm)
    {
        assert( pFN.imm_val64 <= std::numeric_limits<uint32_t>::max() );
        _assembler.mov( asmjit::host::eax, pFN.imm_val );
        _assembler.call( asmjit::host::eax );
    }
    // Already in register
    else if (pFN.type == AsmVariant::reg)
    {
        _assembler.call( pFN.reg_val );
    }
    else
    {
        assert( "Invalid function pointer type" && false );
    }

    // Adjust stack ptr
    if (cc == cc_cdecl)
    {
        size_t argsize = 0;

        for (auto& arg : args)
        {
            if (arg.type != AsmVariant::dataPtr)
                argsize += arg.size;
            else
                argsize += sizeof( uint32_t );
        }

        _assembler.add( asmjit::host::esp, argsize );
    }
      
}
Пример #3
0
AJ_Status AJS_UnmarshalPropArgs(duk_context* ctx, AJ_Message* msg, uint8_t accessor, duk_idx_t msgIdx)
{
    AJ_Status status;
    const char* iface;
    const char* prop;
    const char* signature;
    uint32_t propId;
    uint8_t secure = FALSE;

    AJ_InfoPrintf(("PushPropArgs\n"));

    if (accessor == AJ_PROP_GET_ALL) {
        status = AJ_UnmarshalArgs(msg, "s", &iface);
        if (status == AJ_OK) {
            duk_push_string(ctx, iface);
            /*
             * Save interface (read-only) so we know how to marshal the reply values
             */
            duk_push_string(ctx, AJS_HIDDEN_PROP("propIface"));
            duk_dup(ctx, -2);
            duk_def_prop(ctx, msgIdx, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE);
        }
        /*
         * This call always returns an error status because the interface name we are passing in is
         * invalid but it will indicate if security is required so we can perform the check below
         */
        AJ_IdentifyProperty(msg, iface, "", &propId, &signature, &secure);
    } else {
        status = AJ_UnmarshalArgs(msg, "ss", &iface, &prop);
        if (status == AJ_OK) {
            status = AJ_IdentifyProperty(msg, iface, prop, &propId, &signature, &secure);
            if (status == AJ_OK) {
                duk_push_string(ctx, iface);
                duk_push_string(ctx, prop);
                if (accessor == AJ_PROP_GET) {
                    /*
                     * If we are getting a property save the signature so we know how to marshal the
                     * value in the reply.
                     */
                    duk_push_string(ctx, AJS_HIDDEN_PROP("propSig"));
                    duk_push_string(ctx, signature);
                    duk_def_prop(ctx, msgIdx, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE);
                } else {
                    /*
                     * Push the value to set
                     */
                    status = PushArg(ctx, msg);
                }
            }
        }
    }
    /*
     * If the interface is secure check the message is encrypted
     */
    if ((status == AJ_OK) && secure && !(msg->hdr->flags & AJ_FLAG_ENCRYPTED)) {
        status = AJ_ERR_SECURITY;
        AJ_WarnPrintf(("Security violation accessing property\n"));
    }
    return status;
}
Пример #4
0
/// <summary>
/// Generate function call
/// </summary>
/// <param name="pFN">Function pointer</param>
/// <param name="args">Function arguments</param>
/// <param name="cc">Ignored</param>
void AsmHelper64::GenCall( const AsmVariant& pFN, const std::vector<AsmVariant>& args, eCalligConvention /*cc = CC_stdcall*/ )
{
    //
    // reserve stack size (0x28 - minimal size for 4 registers and return address)
    // after call, stack must be aligned on 16 bytes boundary
    //
    size_t rsp_dif = (args.size() > 4) ? args.size() * WordSize : 0x28;

    // align on (16 bytes - sizeof(return address))
    rsp_dif = Align( rsp_dif, 0x10 );

    if (_stackEnabled)
        _assembler.sub( asmjit::host::rsp, rsp_dif + 8 );

    // Set args
    for (size_t i = 0; i < args.size(); i++)
        PushArg( args[i], i );

    if (pFN.type == AsmVariant::imm)
    {
        _assembler.mov( asmjit::host::rax, pFN.imm_val );
        _assembler.call( asmjit::host::rax );
    }
    else if (pFN.type == AsmVariant::reg)
    {
        _assembler.call( pFN.reg_val );
    }
    else
        assert("Invalid function pointer type" && false );

    if (_stackEnabled)
        _assembler.add( asmjit::host::rsp, rsp_dif + 8 );
}
Пример #5
0
bool Disasm::PushData(uint8 byte) {
	struct ATTRIBUTE* attr = ReadData(byte);
	if (attr) {
		PushArg(attr); return true;
	} else {
		Error("Reading data");
		return false;
	}
}
Пример #6
0
AJ_Status AJS_UnmarshalMsgArgs(duk_context* ctx, AJ_Message* msg)
{
    AJ_Status status = AJ_OK;

    while (status == AJ_OK) {
        status = PushArg(ctx, msg);
    }
    if (status == AJ_ERR_NO_MORE) {
        status = AJ_OK;
    }
    return status;
}
Пример #7
0
/*
 * Structs and arrays have the same representation in JavaScript. Ideally an AllJoyn struct would be
 * represented as a JavaScript object but struct elements are not named in the wire protocol so
 * there is no way to map them into object properties.
 */
static AJ_Status PushContainerArg(duk_context* ctx, uint8_t typeId, AJ_Message* msg)
{
    AJ_Arg arg;
    AJ_Status status = AJ_UnmarshalContainer(msg, &arg, typeId);
    if (status == AJ_OK) {
        int elem = 0;
        int arrayIndex = duk_push_array(ctx);
        while (status == AJ_OK) {
            status = PushArg(ctx, msg);
            if (status == AJ_OK) {
                duk_put_prop_index(ctx, arrayIndex, elem++);
            }
        }
        if (status == AJ_ERR_NO_MORE) {
            status = AJ_OK;
        }
        AJ_UnmarshalCloseContainer(msg, &arg);
    }
    return status;
}
Пример #8
0
CCliArg& CCliReq::operator[] (std::string &a_strArgName)
{
	return *PushArg(a_strArgName);
}
Пример #9
0
int CCliReq::DecodeMessage(std::string &a_strData)
{
	int nRet = 0;
	unsigned int i = 0;
	std::string strTableName;
	std::string strTableType;
	std::string strRscId;

	try {
		rabbit::document doc;
		rabbit::object cBody;
		rabbit::array cArgArray;
		doc.parse(a_strData);

		cBody = doc["BODY"];

		m_nSessionId = cBody["session_id"].as_uint();

		if(cBody.has("cmd_line")  != 0){
			m_strCmdLine = cBody["cmd_line"].as_string();
		}

		if(cBody.has("package") != 0){
			m_strPkgName = cBody["package"].as_string();
		}
		m_nCmdCode = cBody["command_code"].as_uint();
		m_strCmdName = cBody["command"].as_string();

		if(cBody.has("argument_array")){
			cArgArray = cBody["argument_array"];

			for(i=0;i<cArgArray.size();i++){
				rabbit::object cObject;
				std::string argName;
				CCliArg *cArg = NULL;

				cObject = cArgArray[i];

				argName = cObject["name"].as_string();

				cArg = PushArg(argName);

				nRet = cArg->GetDecodeMessage(cObject);
				if(nRet != RESULT_OK){
					return nRet;
				}
			}
		}
	} catch(rabbit::type_mismatch   e) {
		m_strErrString.append(e.what());
		return CCliApi::RESULT_PARSING_ERROR;
	} catch(rabbit::parse_error e) {
		m_strErrString.append(e.what());
		return CCliApi::RESULT_PARSING_ERROR;
	} catch(std::string e) {
		m_strErrString.append(e);
		return CCliApi::RESULT_PARSING_ERROR;
	} catch(...) {
		m_strErrString.append("Unknown Error");
		return CCliApi::RESULT_PARSING_ERROR;
	}

	return CCliApi::RESULT_OK;
}