mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Move init method analysis
This commit is contained in:
@@ -78,6 +78,16 @@ internal class DecompileContext
|
||||
|
||||
public PropertySchema GetImportedProperty(Operand op) => ImportTables.PropertyImports[(ushort)op.Value];
|
||||
|
||||
public Instruction[] GetMethodBody(uint startOffset)
|
||||
{
|
||||
return Instructions
|
||||
.SkipWhile(i => i.Offset < startOffset)
|
||||
.OrderBy(i => i.Offset)
|
||||
.TakeWhile(i => i.OpCode is not (OpCode.ReturnValue or OpCode.ReturnVoid))
|
||||
.OrderBy(i => i.Offset)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public IEnumerable<KeyValuePair<string, XNamespace>> GetUsedNamespaces()
|
||||
{
|
||||
return _namespaces
|
||||
|
||||
@@ -47,26 +47,52 @@ public class Decompiler
|
||||
new XAttribute("Name", name),
|
||||
new XAttribute("Base", baseTypeName));
|
||||
|
||||
var initPropsOffset = export.InitializePropertiesOffset;
|
||||
var initPropsBody = _context.Instructions
|
||||
.SkipWhile(i => i.Offset < initPropsOffset)
|
||||
.OrderBy(i => i.Offset)
|
||||
.TakeWhile(i => i.OpCode is not (OpCode.ReturnValue or OpCode.ReturnVoid))
|
||||
.OrderBy(i => i.Offset)
|
||||
AnalyzeMethodForInit(export.InitializePropertiesOffset, xExport);
|
||||
|
||||
xRoot.Add(xExport);
|
||||
}
|
||||
|
||||
XDocument xDoc = new(xRoot);
|
||||
|
||||
// Add all namespaces to root element
|
||||
var xNamespaceDeclarations = _context.GetUsedNamespaces()
|
||||
.Select(p => new XAttribute(XNamespace.Xmlns + p.Key, p.Value))
|
||||
.ToArray();
|
||||
|
||||
var propertyElements = new XElement[export.Properties.Length];
|
||||
xDoc.Root.Add(xNamespaceDeclarations);
|
||||
|
||||
Stack<object> stack = new([xExport]);
|
||||
|
||||
for (int i = 0; i < initPropsBody.Length; i++)
|
||||
{
|
||||
var instruction = initPropsBody[i];
|
||||
|
||||
if (instruction.OpCode is OpCode.JumpIfDictionaryContains)
|
||||
{
|
||||
return xDoc;
|
||||
}
|
||||
else if (instruction.OpCode is OpCode.PushConstant)
|
||||
|
||||
public string DecompileToSource()
|
||||
{
|
||||
var xmlDoc = Decompile();
|
||||
|
||||
XmlWriterSettings writerSettings = new()
|
||||
{
|
||||
Indent = true,
|
||||
NamespaceHandling = NamespaceHandling.OmitDuplicates,
|
||||
};
|
||||
|
||||
StringBuilder sb = new();
|
||||
using (XmlWriter writer = XmlWriter.Create(sb, writerSettings))
|
||||
{
|
||||
xmlDoc.WriteTo(writer);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private Stack<object> AnalyzeMethodForInit(uint startOffset, XElement elemToInit)
|
||||
{
|
||||
var methodBody = _context.GetMethodBody(startOffset);
|
||||
|
||||
Stack<object> stack = new([elemToInit]);
|
||||
|
||||
for (int i = 0; i < methodBody.Length; i++)
|
||||
{
|
||||
var instruction = methodBody[i];
|
||||
|
||||
if (instruction.OpCode is OpCode.PushConstant)
|
||||
{
|
||||
var constant = _context.GetConstant(instruction.Operands.First());
|
||||
stack.Push(constant);
|
||||
@@ -121,37 +147,7 @@ public class Decompiler
|
||||
}
|
||||
}
|
||||
|
||||
xRoot.Add(xExport);
|
||||
}
|
||||
|
||||
XDocument xDoc = new(xRoot);
|
||||
|
||||
// Add all namespaces to root element
|
||||
var xNamespaceDeclarations = _context.GetUsedNamespaces()
|
||||
.Select(p => new XAttribute(XNamespace.Xmlns + p.Key, p.Value))
|
||||
.ToArray();
|
||||
|
||||
xDoc.Root.Add(xNamespaceDeclarations);
|
||||
|
||||
return xDoc;
|
||||
}
|
||||
|
||||
public string DecompileToSource()
|
||||
{
|
||||
var xmlDoc = Decompile();
|
||||
|
||||
XmlWriterSettings writerSettings = new()
|
||||
{
|
||||
Indent = true,
|
||||
NamespaceHandling = NamespaceHandling.OmitDuplicates,
|
||||
};
|
||||
|
||||
StringBuilder sb = new();
|
||||
using (XmlWriter writer = XmlWriter.Create(sb, writerSettings))
|
||||
{
|
||||
xmlDoc.WriteTo(writer);
|
||||
}
|
||||
return sb.ToString();
|
||||
return stack;
|
||||
}
|
||||
|
||||
private static XElement GetOrCreateElement(XElement parent, XName name)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-16"?>
|
||||
<UIX xmlns="http://schemas.microsoft.com/2007/uix" xmlns:me="Me" xmlns:dialog="res://UIXControls!Dialog.uix" xmlns:iris="assembly://UIX/Microsoft.Iris" xmlns:zuneUI="assembly://ZuneShell/ZuneUI" xmlns:system="assembly://System.Private.CoreLib/System" xmlns:styles="res://ZuneShellResources!Styles.uix" xmlns:label="res://UIXControls!Label.uix" xmlns:style="res://UIXControls!Style.uix" xmlns:linkButtons="res://ZuneShellResources!LinkButtons.uix" xmlns:button="res://UIXControls!Button.uix">
|
||||
<UIX xmlns="http://schemas.microsoft.com/2007/uix" xmlns:dialog="res://UIXControls!Dialog.uix" xmlns:iris="assembly://UIX/Microsoft.Iris" xmlns:zuneUI="assembly://ZuneShell/ZuneUI" xmlns:system="assembly://System.Private.CoreLib/System">
|
||||
<Class Name="AboutDialog" Base="dialog:Dialog">
|
||||
<Properties>
|
||||
<String String="res://ZuneShellResources!AboutDialog.uix#AboutDialogContentUI" Name="ContentUI" />
|
||||
<iris:Command Description="zuneUI:Shell.LoadString(zuneUI:StringId.IDS_DIALOG_OK)" Name="Cancel" />
|
||||
<zuneUI:WebHelpCommand Description="zuneUI:Shell.LoadString(zuneUI:StringId.IDS_ABOUTDIALOG_TECHNICAL_SUPPORT_INFORMATION)" Url="zuneUI:Shell.LoadString(zuneUI:StringId.IDS_WWW_ZUNE_NET_SUPPORT_URL)" Name="TechSupportLink" />
|
||||
<system:String String="zuneUI:Shell.LoadString(zuneUI:StringId.IDS_ABOUTDIALOG_TITLE)" Name="AccessibleDescription" />
|
||||
<iris:Command Description="{zuneUI:Shell.LoadString(zuneUI:StringId.IDS_DIALOG_OK)}" Name="Cancel" />
|
||||
<zuneUI:WebHelpCommand Description="{zuneUI:Shell.LoadString(zuneUI:StringId.IDS_ABOUTDIALOG_TECHNICAL_SUPPORT_INFORMATION)}" Url="{zuneUI:Shell.LoadString(zuneUI:StringId.IDS_WWW_ZUNE_NET_SUPPORT_URL)}" Name="TechSupportLink" />
|
||||
<system:String String="{zuneUI:Shell.LoadString(zuneUI:StringId.IDS_ABOUTDIALOG_TITLE)}" Name="AccessibleDescription" />
|
||||
</Properties>
|
||||
</Class>
|
||||
<UI Name="AboutDialogContentUI" Base="dialog:DialogContentUI" />
|
||||
|
||||
@@ -220,18 +220,24 @@ AddToCollection_prop:
|
||||
AddToCollection_locl:
|
||||
PSHN
|
||||
PDAD 1, @const7
|
||||
|
||||
COBJ 3
|
||||
PDAD 1, @const8
|
||||
|
||||
COBJ 3
|
||||
PDAD 1, @const9
|
||||
|
||||
COBJ 1
|
||||
PDAD 1, @const10
|
||||
|
||||
COBJ 8
|
||||
PSHC @const11
|
||||
PINI 2
|
||||
INIT 8
|
||||
PDAD 1, @const12
|
||||
|
||||
PSHC @const11
|
||||
PDAD 1, @const13
|
||||
|
||||
CLIS 8
|
||||
RETV
|
||||
|
||||
Reference in New Issue
Block a user