示例#1
0
        public string GenerateHomeProxyCode()
        {
            StringBuilder function_code = new StringBuilder();
            string        return_type   = (_return_type != null) ? _return_type.ParameterTypeCast : "void";

            function_code.AppendLine($@"{return_type} WINAPI Malproxy_{_function_name} (");
            function_code.AppendLine("    MalproxySession* client");
            foreach (var param in _parameters)
            {
                function_code.AppendLine($"    ,{param.ParameterPrototypeTypeAndName}");
            }
            function_code.AppendLine(") {");

            foreach (var null_param in _parameters.Where(arg => arg is NullParameter))
            {
                function_code.AppendLine($"if ({null_param.ParameterName} != nullptr) THROW(\"{null_param.ParameterName} must be nullptr\");");
            }

            string request = "request";

            function_code.AppendLine($"malproxy::CallFuncRequest {request};");
            function_code.AppendLine($"{request}.set_dll_name(\"{_dll_name}\");");
            function_code.AppendLine($"{request}.set_function_name(\"{_function_name}\");");

            function_code.AppendLine();

            foreach (var param in _parameters)
            {
                function_code.AppendLine(param.GetHomeInputCode(request));
            }

            function_code.AppendLine();

            string response = "response";

            function_code.AppendLine($"auto {response} = client->CallFunc({request});");

            int out_arg_index = 0;

            foreach (var param in _parameters)
            {
                if (!(param is PointerParameter))
                {
                    continue;
                }
                var directional_param = param as PointerParameter;
                if (!directional_param.Direction.HasFlag(ParameterDirection.out_param))
                {
                    continue;
                }

                function_code.AppendLine(directional_param.GetHomeOutputCode(response, out_arg_index));

                out_arg_index++;
            }

            if (_return_type != null)
            {
                function_code.AppendLine(_return_type.GetReturnValueCode(response));
            }

            function_code.AppendLine("}");
            return(function_code.ToString());
        }