-
Notifications
You must be signed in to change notification settings - Fork 2
/
xmlMaker.cs
106 lines (89 loc) · 3.65 KB
/
xmlMaker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using CppAst;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace DLLHeaderParser
{
class XmlMaker
{
/// <summary>
/// generate result for Rohitab Api Monitor
/// </summary>
/// <param name="parserResult">parser result from CppAst</param>
/// <param name="matchingFunctions">matching functions from DLL</param>
public static void genResults(CppCompilation parserResult, List<CppFunction> matchingFunctions) {
XElement x = new XElement("ApiMonitor");
x.Add(
new XElement("Include", new XAttribute("FileName", @"Headers\common.h.xml"))
);
var funcs = XmlMaker.makeFunctions(matchingFunctions);
var variables = XmlMaker.makeVariables(parserResult);
Console.WriteLine(x);
}
public static List<XElement> makeFunctions(List<CppFunction> funcs) {
/**
* each api has this format:
*
* <Api Name="CredFindBestCredential" BothCharset="True">
* <Param Type="LPCTSTR" Name="TargetName" />
* <Param Type="DWORD" Name="Type" />
* <Param Type="DWORD" Name="Flags" />
* <Return Type="BOOL" />
* </Api>
*/
List<XElement> x = new List<XElement>();
/*iterate over each api and make the xml of it*/
foreach (var func in funcs) {
XElement apiElement = new XElement("Api");
apiElement.SetAttributeValue("Name", func.Name); /* set it's name in attribute */
foreach (var param in func.Parameters) { /* add it's parameters */
XElement parameter = new XElement("Param");
parameter.SetAttributeValue("Type",param.Type);
parameter.SetAttributeValue("Name", param.Name);
apiElement.Add(parameter);
}
/* add the return type */
XElement returnType = new XElement("Return",new XAttribute("Type",func.ReturnType));
apiElement.Add(returnType);
/* add it to list */
x.Add(apiElement);
}
//@todo find all attributes of the function
//@todo iterate back to basic types and make them
return x;
}
public static XElement makeModule() {
XElement x = null;
/**
* header is before module
*
* each module has a
*
* 1- variable
* 2- apis
*/
return x;
}
public static List<XElement> makeVariables(CppCompilation comp) {
/**
* we don't need interface , only module. declare variables that are used in each dll and import them
* to other modules if they cross reference
*/
//classes , enums , Fields , typedefs with non-null source file
List<XElement> classes = new List<XElement>();
List<XElement> typedefs = new List<XElement>();
List<XElement> enums = new List<XElement>();
List<XElement> fields = new List<XElement>();
List<XElement> result = new List<XElement>();
/* process classes */
foreach (var clazz in comp.Classes.Where(x=> x.SourceFile != null)) {
/* clazz.ClassKind is either union or struct */
//@Todo continue from here
}
return result;
}
}
}