Skip to content

Commit 56d4aed

Browse files
committed
Add project files.
1 parent dd5399b commit 56d4aed

26 files changed

+2632
-0
lines changed

App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
5+
</startup>
6+
</configuration>

App.xaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<Application x:Class="Java_Bytecode_Toolkit.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:Java_Bytecode_Toolkit"
5+
xmlns:clr="clr-namespace:System;assembly=mscorlib"
6+
StartupUri="MainWindow.xaml">
7+
<Application.Resources>
8+
<ResourceDictionary>
9+
<ResourceDictionary.MergedDictionaries>
10+
<ResourceDictionary Source="/Themes/LightTheme.xaml"/>
11+
</ResourceDictionary.MergedDictionaries>
12+
13+
<clr:String x:Key="AppName">Java Bytecode Toolkit</clr:String>
14+
15+
<Path x:Key="LightThemeIcon" Stretch="Uniform" Fill="#212121" Data="M11.996 19.01a.75.75 0 0 1 .743.649l.007.102v1.5a.75.75 0 0 1-1.493.101l-.007-.101v-1.5a.75.75 0 0 1 .75-.75Zm6.022-2.072 1.06 1.06a.75.75 0 1 1-1.06 1.061l-1.06-1.06a.75.75 0 0 1 1.06-1.061Zm-10.983 0a.75.75 0 0 1 0 1.06L5.974 19.06a.75.75 0 0 1-1.06-1.06l1.06-1.061a.75.75 0 0 1 1.06 0ZM12 6.475a5.525 5.525 0 1 1 0 11.05 5.525 5.525 0 0 1 0-11.05Zm0 1.5a4.025 4.025 0 1 0 0 8.05 4.025 4.025 0 0 0 0-8.05Zm9.25 3.293a.75.75 0 0 1 .102 1.493l-.102.007h-1.5a.75.75 0 0 1-.102-1.493l.102-.007h1.5Zm-17-.029a.75.75 0 0 1 .102 1.494l-.102.006h-1.5a.75.75 0 0 1-.102-1.493l.102-.007h1.5Zm1.64-6.37.084.072 1.06 1.06a.75.75 0 0 1-.976 1.134l-.084-.073-1.06-1.06a.75.75 0 0 1 .976-1.134Zm13.188.072a.75.75 0 0 1 .073.977l-.073.084-1.06 1.06a.75.75 0 0 1-1.133-.976l.072-.084 1.06-1.061a.75.75 0 0 1 1.061 0ZM12 1.99a.75.75 0 0 1 .743.648l.007.102v1.5a.75.75 0 0 1-1.493.101l-.007-.102v-1.5a.75.75 0 0 1 .75-.75Z"/>
16+
17+
<Path x:Key="DarkThemeIcon" Stretch="Uniform" Fill="#212121" Data="M20.026 17.001c-2.762 4.784-8.879 6.423-13.663 3.661a9.964 9.964 0 0 1-3.234-2.983.75.75 0 0 1 .365-1.131c3.767-1.348 5.785-2.911 6.956-5.146 1.232-2.353 1.551-4.93.689-8.464a.75.75 0 0 1 .769-.926 9.961 9.961 0 0 1 4.457 1.327C21.149 6.1 22.788 12.217 20.025 17Zm-8.248-4.903c-1.25 2.388-3.31 4.099-6.817 5.499a8.492 8.492 0 0 0 2.152 1.766 8.501 8.501 0 1 0 8.502-14.725 8.485 8.485 0 0 0-2.792-1.016c.647 3.384.23 6.044-1.045 8.476Z"/>
18+
19+
<Path x:Key="FileIcon" Stretch="Uniform" Stroke="#212121" StrokeThickness="1" Data="M 14.00,0.00 C 14.00,0.00 14.00,10.00 14.00,10.00 14.00,10.00 24.00,10.00 24.00,10.00M 0.00,0.00 C 0.00,0.00 0.00,32.00 0.00,32.00 0.00,32.00 24.00,32.00 24.00,32.00 24.00,32.00 24.00,10.00 24.00,10.00 24.00,10.00 14.00,0.00 14.00,0.00 14.00,0.00 0.00,0.00 0.00,0.00 Z"/>
20+
21+
<Style x:Key="DefaultSidebarButtonStyle" TargetType="Button">
22+
<Setter Property="DockPanel.Dock" Value="Top"/>
23+
24+
<Setter Property="BorderThickness" Value="0"/>
25+
26+
<Setter Property="HorizontalAlignment" Value="Stretch"/>
27+
28+
<Setter Property="VerticalAlignment" Value="Stretch"/>
29+
30+
<Setter Property="HorizontalContentAlignment" Value="Left"/>
31+
32+
<Setter Property="VerticalContentAlignment" Value="Center"/>
33+
34+
<Setter Property="Padding" Value="10 10 10 10"/>
35+
36+
<Setter Property="Background" Value="{DynamicResource SecondaryBackgroundColor}"/>
37+
</Style>
38+
39+
<Style x:Key="DefaultToolbarButtonStyle" TargetType="Button">
40+
<Setter Property="DockPanel.Dock" Value="Left"/>
41+
42+
<Setter Property="BorderThickness" Value="0"/>
43+
44+
<Setter Property="HorizontalAlignment" Value="Stretch"/>
45+
46+
<Setter Property="VerticalAlignment" Value="Stretch"/>
47+
48+
<Setter Property="HorizontalContentAlignment" Value="Center"/>
49+
50+
<Setter Property="VerticalContentAlignment" Value="Top"/>
51+
52+
<Setter Property="Padding" Value="10 10 10 10"/>
53+
54+
<Setter Property="Background" Value="{DynamicResource SecondaryBackgroundColor}"/>
55+
</Style>
56+
</ResourceDictionary>
57+
</Application.Resources>
58+
</Application>

App.xaml.cs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using Java_Bytecode_Toolkit.ExtensionsNS;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Configuration;
5+
using System.Data;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Threading.Tasks;
9+
using System.Windows;
10+
11+
namespace Java_Bytecode_Toolkit
12+
{
13+
/// <summary>
14+
/// Interaction logic for App.xaml
15+
/// </summary>
16+
public partial class App : Application
17+
{
18+
public readonly ResourceDictionary LIGHT_THEME = null;
19+
20+
public readonly ResourceDictionary DARK_THEME = null;
21+
22+
public readonly string tempDirFilePath = "";
23+
24+
public static new App Current
25+
{
26+
get
27+
{
28+
return (App)Application.Current;
29+
}
30+
}
31+
32+
public ResourceDictionary Theme
33+
{
34+
get
35+
{
36+
return this.Resources.MergedDictionaries.FirstOrDefault();
37+
}
38+
set
39+
{
40+
this.Resources.MergedDictionaries.Clear();
41+
42+
this.Resources.MergedDictionaries.Add(value);
43+
}
44+
}
45+
46+
public string BaseDirectory
47+
{
48+
get
49+
{
50+
return AppDomain.CurrentDomain.BaseDirectory;
51+
}
52+
}
53+
54+
public new MainWindow MainWindow
55+
{
56+
get
57+
{
58+
return (MainWindow)Application.Current.MainWindow;
59+
}
60+
set
61+
{
62+
Application.Current.MainWindow = value;
63+
}
64+
}
65+
66+
private void CreateTempDirIfDoesNotExist()
67+
{
68+
if (Directory.Exists(this.tempDirFilePath) == false)
69+
{
70+
Directory.CreateDirectory(this.tempDirFilePath);
71+
}
72+
}
73+
74+
public App()
75+
{
76+
this.tempDirFilePath = this.BaseDirectory + "/Temp";
77+
78+
this.CreateTempDirIfDoesNotExist();
79+
80+
this.LIGHT_THEME = new ResourceDictionary()
81+
{
82+
Source = new Uri("/Themes/LightTheme.xaml", UriKind.Relative)
83+
};
84+
85+
this.DARK_THEME = new ResourceDictionary()
86+
{
87+
Source = new Uri("/Themes/DarkTheme.xaml", UriKind.Relative)
88+
};
89+
}
90+
}
91+
}

Assets/Icon.ico

3.41 KB
Binary file not shown.

Assets/Icon.svg

Lines changed: 4 additions & 0 deletions
Loading

Assets/file-icon-as-path.svg

Lines changed: 18 additions & 0 deletions
Loading

Assets/file-icon.svg

Lines changed: 5 additions & 0 deletions
Loading

ExtensionsNS/Extensions.cs

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
using Microsoft.Win32;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Runtime.CompilerServices;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using System.Xml;
11+
12+
namespace Java_Bytecode_Toolkit.ExtensionsNS
13+
{
14+
public static class Extensions
15+
{
16+
public static void SetFilter(this FileDialog fileDialog, params FileDialogFilter[] fileDialogFilters)
17+
{
18+
string fileDialogFilterString = "";
19+
20+
for (int currentFilterIndex = 0; currentFilterIndex < fileDialogFilters.Length; currentFilterIndex++)
21+
{
22+
if (currentFilterIndex != 0)
23+
{
24+
fileDialogFilterString += "|";
25+
}
26+
27+
fileDialogFilterString += fileDialogFilters[currentFilterIndex].filterName + "|";
28+
29+
foreach (string fileExtension in fileDialogFilters[currentFilterIndex].fileExtensions)
30+
{
31+
fileDialogFilterString += "*." + fileExtension;
32+
}
33+
}
34+
35+
fileDialog.Filter = fileDialogFilterString;
36+
}
37+
38+
public static T To<T>(this Enum enumInstance)
39+
{
40+
return (T)(object)enumInstance;
41+
}
42+
43+
public static byte[] ReadBytes(this Stream stream, int offset, int numBytesToRead, bool isLittleEndian)
44+
{
45+
byte[] bytes = new byte[numBytesToRead];
46+
47+
stream.Read(bytes, 0, numBytesToRead);
48+
49+
if (isLittleEndian != BitConverter.IsLittleEndian)
50+
{
51+
bytes = bytes.Reverse().ToArray();
52+
}
53+
54+
return bytes;
55+
}
56+
57+
public static T To<T>(this byte[] byteArray)
58+
{
59+
if (typeof(T) == typeof(byte))
60+
{
61+
return (T)(object)byteArray[0];
62+
}
63+
else if (typeof(T) == typeof(bool))
64+
{
65+
return (T)(object)BitConverter.ToBoolean(byteArray, 0);
66+
}
67+
else if (typeof(T) == typeof(char))
68+
{
69+
return (T)(object)BitConverter.ToChar(byteArray, 0);
70+
}
71+
else if (typeof(T) == typeof(double))
72+
{
73+
return (T)(object)BitConverter.ToDouble(byteArray, 0);
74+
}
75+
else if (typeof(T) == typeof(Int16))
76+
{
77+
return (T)(object)BitConverter.ToInt16(byteArray, 0);
78+
}
79+
else if (typeof(T) == typeof(Int32))
80+
{
81+
return (T)(object)BitConverter.ToInt32(byteArray, 0);
82+
}
83+
else if (typeof(T) == typeof(Int64))
84+
{
85+
return (T)(object)BitConverter.ToInt64(byteArray, 0);
86+
}
87+
else if (typeof(T) == typeof(Single))
88+
{
89+
return (T)(object)BitConverter.ToSingle(byteArray, 0);
90+
}
91+
else if (typeof(T) == typeof(UInt16))
92+
{
93+
return (T)(object)BitConverter.ToUInt16(byteArray, 0);
94+
}
95+
else if (typeof(T) == typeof(UInt32))
96+
{
97+
return (T)(object)BitConverter.ToUInt32(byteArray, 0);
98+
}
99+
else if (typeof(T) == typeof(UInt64))
100+
{
101+
return (T)(object)BitConverter.ToUInt64(byteArray, 0);
102+
}
103+
104+
throw new UnsupportedConversionException();
105+
}
106+
107+
public unsafe static T ReadBytesAs<T>(this Stream stream, int offset, bool isLittleEndian)
108+
{
109+
return stream.ReadBytes(offset, sizeof(T), isLittleEndian).To<T>();
110+
}
111+
112+
public unsafe static T ReadBytesFromStreamAs<T>(this Stream stream, bool isLittleEndian)
113+
{
114+
int valueSizeInBytes = sizeof(T);
115+
116+
T obtainedValue = stream.ReadBytes(
117+
(int)stream.Position,
118+
valueSizeInBytes,
119+
isLittleEndian
120+
).To<T>();
121+
122+
return obtainedValue;
123+
}
124+
125+
public static void WriteToXMLWriter(this object obj, XmlWriter xmlWriter, JavaClassFile javaClassFile)
126+
{
127+
Type objType = obj.GetType();
128+
129+
xmlWriter.WriteStartElement(objType.Name);
130+
131+
foreach (FieldInfo fieldInfo in objType.GetFields())
132+
{
133+
string capitalizedFieldName = char.ToUpper(
134+
fieldInfo.Name[0]
135+
) + fieldInfo.Name.Substring(1);
136+
137+
Type fieldType = fieldInfo.FieldType;
138+
139+
if (fieldType.IsArray == true)
140+
{
141+
xmlWriter.WriteStartElement(
142+
capitalizedFieldName
143+
);
144+
145+
Array fieldValueAsObjectArray = fieldInfo.GetValue(obj) as Array;
146+
147+
foreach (object element in fieldValueAsObjectArray)
148+
{
149+
Type elementType = element.GetType();
150+
151+
if (elementType.IsPrimitive == true)
152+
{
153+
xmlWriter.WriteElementString(
154+
elementType.Name,
155+
element.ToString()
156+
);
157+
158+
continue;
159+
}
160+
161+
element.WriteToXMLWriter(xmlWriter, javaClassFile);
162+
}
163+
164+
xmlWriter.WriteEndElement();
165+
166+
continue;
167+
}
168+
169+
MethodInfo writeToXMLWriterMethodInfo = fieldType.GetMethod(
170+
nameof(WriteToXMLWriter)
171+
);
172+
173+
if (writeToXMLWriterMethodInfo == null)
174+
{
175+
xmlWriter.WriteElementString(
176+
capitalizedFieldName,
177+
fieldInfo.GetValue(obj).ToString()
178+
);
179+
180+
continue;
181+
}
182+
183+
writeToXMLWriterMethodInfo.Invoke(
184+
fieldInfo.GetValue(obj),
185+
new object[]
186+
{
187+
xmlWriter,
188+
javaClassFile
189+
}
190+
);
191+
}
192+
193+
xmlWriter.WriteEndElement();
194+
}
195+
196+
public class UnsupportedConversionException : Exception
197+
{
198+
public UnsupportedConversionException() : base("Conversion from byte array to current data type is not supported.")
199+
{
200+
201+
}
202+
}
203+
}
204+
}

0 commit comments

Comments
 (0)