-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFunctionProperties.xaml.cs
163 lines (137 loc) · 4.98 KB
/
FunctionProperties.xaml.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace X360Decompiler
{
/// <summary>
/// Interaction logic for Function.xaml
/// </summary>
public partial class FunctionProperties : Window
{
Function func;
public class ListViewArgument
{
public ListViewArgument(String name, CType t)
{
Name = name;
TypeClass = t;
}
public String Type { get { return TypeClass.ToString(); } }
public String Name { get; set; }
public CType TypeClass;
};
ObservableCollection<ListViewArgument> _ArgCollection = new ObservableCollection<ListViewArgument>();
public ObservableCollection<ListViewArgument> ArgCollection { get { return _ArgCollection; } }
public FunctionProperties(Function f)
{
func = f;
InitializeComponent();
FuncName.Text = f.Name;
Address.Text = "0x" + f.Address.ToString("X8");
if (func.ArgCount != -1)
{
ArgUnknown.IsChecked = false;
ArgKnown.IsChecked = true;
foreach (Variable a in func.Arguments)
{
_ArgCollection.Add(new ListViewArgument(a.Name, a.Type));
}
}
if (func.Returns.Kind == CType.TypeKind.Pointer || func.Returns.Kind == CType.TypeKind.UnknownPointer)
RetPointer.SelectedIndex = 1;
else
RetPointer.SelectedIndex = 0;
for (int i = 0; i < RetType.Items.Count; i++)
{
ComboBoxItem item = RetType.Items[i] as ComboBoxItem;
if (((String) item.Content) == func.Returns.Name)
RetType.SelectedIndex = i;
}
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Close();
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
func.ListViewEntry.FuncName = func.Name = FuncName.Text;
if (ArgUnknown.IsChecked == true)
{
func.ArgCount = -1;
func.Arguments = null;
}
else
{
func.ArgCount = ArgListView.Items.Count;
func.Arguments = new List<Variable>();
foreach (ListViewArgument a in _ArgCollection)
{
func.Arguments.Add(new Variable(a.Name, a.TypeClass));
}
}
ComboBoxItem typeItem = RetType.SelectedItem as ComboBoxItem;
String type = typeItem.Content as String;
CType.TypeKind kind = CType.TypeKind.ValueType;
if (RetPointer.SelectedIndex == 1)
kind = CType.TypeKind.Pointer;
func.Returns = new CType(kind, type);
Close();
}
private void Button_Click_3(object sender, RoutedEventArgs e)
{
}
private void Button_Click_4(object sender, RoutedEventArgs e)
{
if (NewArgName.Text.Length < 1)
{
MessageBox.Show("Choose a name for the parameter!");
return;
}
ComboBoxItem typeItem = NewArgType.SelectedItem as ComboBoxItem;
String type = typeItem.Content as String;
if (type == "void" && NewArgPointer.SelectedIndex != 1)
{
MessageBox.Show("A void argument must be a pointer!");
return;
}
CType.TypeKind kind = CType.TypeKind.ValueType;
if (type == "_unknown_")
{
if (NewArgPointer.SelectedIndex == 1)
kind = CType.TypeKind.UnknownPointer;
else
kind = CType.TypeKind.Unknown;
}
else if (NewArgPointer.SelectedIndex == 1)
kind = CType.TypeKind.Pointer;
String name = NewArgName.Text.Trim();
if (!Regex.IsMatch(name, @"^[a-zA-Z_][a-zA-Z0-9_]*$"))
{
MessageBox.Show("A parameter must be made of only letters, digits and underscores!");
return;
}
foreach (ListViewArgument a in _ArgCollection)
{
if (a.Name == name)
{
MessageBox.Show("Parameter name collision!");
return;
}
}
ListViewArgument arg = new ListViewArgument(NewArgName.Text, new CType(kind, type));
_ArgCollection.Add(arg);
}
}
}