예제 #1
0
파일: Clang.cs 프로젝트: thfabian/Bifrost
            /// <summary>
            /// Visit a function declaration
            /// </summary>
            private void VisitFunctionDecl(FunctionDecl funDecl, TraversalData traversalData)
            {
                var desc = MatchHook(traversalData.GetQualifiedType(funDecl));

                if (desc != null)
                {
                    m_bir.Hooks.Add(CreateHook(funDecl, desc, traversalData));
                }
            }
예제 #2
0
파일: Clang.cs 프로젝트: thfabian/Bifrost
            /// <summary>
            /// Register a hook
            /// </summary>
            private BIR.BIR.Hook CreateHook(FunctionDecl decl, HookDesc hookDesc, TraversalData traversalData)
            {
                BIR.BIR.Hook hook = new BIR.BIR.Hook();

                var desc = hookDesc.Desc;

                hook.Identifier = IO.MakeValidIdentifier(string.IsNullOrEmpty(desc.Identifier) ? traversalData.GetQualifiedType(decl).Replace("::", "_") : desc.Identifier);
                hook.ReturnType = decl.ReturnType.ToString();
                hook.Module     = desc.Module;
                hook.Inputs     = desc.Input;

                if (decl.Handle.Kind == CXCursorKind.CXCursor_CXXMethod)
                {
                    var cxxMethodDecl = (CXXMethodDecl)decl;
                    hook.VTableThisType = traversalData.GetClasses();
                    hook.HookType       = cxxMethodDecl.IsVirtual ? BIR.BIR.HookTypeEnum.VTable : BIR.BIR.HookTypeEnum.CFunction;
                }
                else
                {
                    hook.HookType      = BIR.BIR.HookTypeEnum.CFunction;
                    hook.CFunctionName = traversalData.GetQualifiedType(decl);
                    if (string.IsNullOrEmpty(hook.Module))
                    {
                        throw new Exception($"'hook.descriptions.[{hookDesc.Key}].module' is required to load function \"{desc.Name}\"");
                    }
                }

                // Extract parameter
                foreach (var param in decl.Parameters)
                {
                    hook.Parameters.Add(new BIR.BIR.Hook.Parameter()
                    {
                        Name = param.Name,
                        Type = param.Type.ToString(),
                    });
                }

                return(hook);
            }