Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 06-08-2020, 18:24
jonwil jonwil is offline
VIP
 
Join Date: Feb 2004
Posts: 315
Rept. Given: 2
Rept. Rcvd 19 Times in 7 Posts
Thanks Given: 1
Thanks Rcvd at 40 Times in 26 Posts
jonwil Reputation: 19
Tips for fixing up decompiled .NET code?

I have decompiled a .NET binary with dnSpy and the resulting output has some strange things in it like this
Code:
		public HouseType(sbyte id, string name, string unitTeamColor, string buildingTeamColor, [TupleElementNames(new string[]
		{
			"type",
			"teamColor"
		})] params ValueTuple<string, string>[] overrideTeamColors)
		{
			this.ID = id;
			this.Name = name;
			this.UnitTeamColor = unitTeamColor;
			this.BuildingTeamColor = buildingTeamColor;
			this.OverrideTeamColors = overrideTeamColors.ToDictionary(([TupleElementNames(new string[]
			{
				"type",
				"teamColor"
			})] ValueTuple<string, string> x) => x.Item1, ([TupleElementNames(new string[]
			{
				"type",
				"teamColor"
			})] ValueTuple<string, string> x) => x.Item2);
		}
and this
Code:
				for (int i = 0; i < array2.Length; i++)
				{
					var <>f__AnonymousType = array2[i];
					this.plugin.Map.Triggers.Add(<>f__AnonymousType.NewTrigger.Clone());
					this.plugin.Map.Triggers.Remove(<>f__AnonymousType.OldTrigger);
				}
and this
Code:
		[CompilerGenerated]
		internal static string <LoadINI>g__indexToType|20_1(IList<string> list, string index)
		{
			int num;
			if (!int.TryParse(index, out num) || num < 0 || num >= list.Count)
			{
				return list.First<string>();
			}
			return list[num];
		}
Are there any good tutorials on how to fix up such things?
Reply With Quote
  #2  
Old 06-08-2020, 20:05
Kurapica's Avatar
Kurapica Kurapica is offline
VIP
 
Join Date: Jun 2009
Location: Archives
Posts: 135
Rept. Given: 13
Rept. Rcvd 129 Times in 37 Posts
Thanks Given: 27
Thanks Rcvd at 231 Times in 50 Posts
Kurapica Reputation: 100-199 Kurapica Reputation: 100-199
This is normal code, what do you need to fix ?

Try to familiarize yourself with .NET framework classes, maybe this can help.
Reply With Quote
  #3  
Old 06-09-2020, 16:53
jonwil jonwil is offline
VIP
 
Join Date: Feb 2004
Posts: 315
Rept. Given: 2
Rept. Rcvd 19 Times in 7 Posts
Thanks Given: 1
Thanks Rcvd at 40 Times in 26 Posts
jonwil Reputation: 19
Turns out that ILSpy is the best decompiler and produced output that had few problems.
Reply With Quote
  #4  
Old 06-09-2020, 17:22
chants chants is offline
Family
 
Join Date: Jul 2016
Posts: 559
Rept. Given: 6
Rept. Rcvd 35 Times in 21 Posts
Thanks Given: 472
Thanks Rcvd at 835 Times in 392 Posts
chants Reputation: 35
The ValueTuple and AnonymousType are just in a really ugly long form syntax. They can be reduced easily. Incidentally it's one reason to avoid them in code designed to be high performance as they can introduce extra generated code. The naming on the compiler generated function can be cleaned up that's the only annoying thing there. As for getting rid of all the compiler generated functions, this is the job of a good decompiler that can manage such refactorings
Reply With Quote
  #5  
Old 06-09-2020, 23:16
niculaita's Avatar
niculaita niculaita is offline
Family
 
Join Date: Jun 2011
Location: here
Posts: 1,169
Rept. Given: 873
Rept. Rcvd 85 Times in 57 Posts
Thanks Given: 2,854
Thanks Rcvd at 436 Times in 313 Posts
niculaita Reputation: 85
how to avoid start activation during 30 trial days and after that using an unic code changing next ?

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim num As Integer
Dim num2 As UInt32
Dim num3 As UInt32
Try
If (MySettingsProperty.Settings.Culture.Length > 0) Then
Thread.CurrentThread.CurrentUICulture = New CultureInfo(MySettingsProperty.Settings.Culture)
End If
Catch exception1 As Exception
Dim ex As Exception = exception1
ProjectData.SetProjectError(ex)
Dim exception As Exception = ex
ProjectData.ClearProjectError
End Try
Me.Localize
Me.KSVE = New KSVE4Class
Me.KSVE.Initialize(-1281006)
Me.KSVE.FindActivation(num, num2, num3)
If ((num <> 0) And (num <> &H100)) Then
Me.RunActivationApplication
MyBase.Close
Else
Me.voice = New SpeechSynthesizer
Me.ComboBox1.Items.Clear
Dim voice As InstalledVoice
For Each voice In Me.voice.GetInstalledVoices
Me.ComboBox1.Items.Add(voice.VoiceInfo.Name)
Next
If (Me.ComboBox1.Items.Count > 0) Then
Me.ComboBox1.SelectedIndex = 0
End If
End If
End Sub
__________________
Decode and Conquer
Reply With Quote
  #6  
Old 06-10-2020, 03:41
sendersu sendersu is offline
VIP
 
Join Date: Oct 2010
Posts: 847
Rept. Given: 324
Rept. Rcvd 216 Times in 110 Posts
Thanks Given: 168
Thanks Rcvd at 353 Times in 200 Posts
sendersu Reputation: 200-299 sendersu Reputation: 200-299 sendersu Reputation: 200-299
Quote:
Originally Posted by jonwil View Post
Turns out that ILSpy is the best decompiler and produced output that had few problems.
just wondering how does the ILSpy decompile your code?
Reply With Quote
The Following User Says Thank You to sendersu For This Useful Post:
niculaita (06-11-2020)
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT +8. The time now is 07:15.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX
( 1998 - 2020 )