Add Utils.compareInt32() and use it

This commit is contained in:
de4dot 2011-11-21 10:32:36 +01:00
parent 1b0fbfc681
commit d014835c7c
5 changed files with 12 additions and 29 deletions

View File

@ -304,10 +304,7 @@ namespace de4dot {
if (i1 < i2) return -1;
if (i1 > i2) return 1;
if (a.callStartIndex < b.callStartIndex) return -1;
if (a.callStartIndex > b.callStartIndex) return 1;
return 0;
return Utils.compareInt32(a.callStartIndex, b.callStartIndex);
});
callResults.Reverse();
inlineReturnValues(callResults);

View File

@ -591,11 +591,7 @@ namespace de4dot {
}
var sortedTargets = new List<Instruction>(targets.Keys);
sortedTargets.Sort((a, b) => {
if (a.Offset < b.Offset) return -1;
if (a.Offset > b.Offset) return 1;
return 0;
});
sortedTargets.Sort((a, b) => Utils.compareInt32(a.Offset, b.Offset));
for (int i = 0; i < sortedTargets.Count; i++)
labels[sortedTargets[i]] = string.Format("label_{0}", i);
}

View File

@ -230,5 +230,11 @@ namespace de4dot {
}
return true;
}
public static int compareInt32(int a, int b) {
if (a < b) return -1;
if (a > b) return 1;
return 0;
}
}
}

View File

@ -68,12 +68,7 @@ namespace de4dot.deobfuscators.SmartAssembly {
if (mainMethod == null || methods.Count < MIN_HELPER_METHODS)
return false;
methods.Sort((a, b) => {
if (a.Parameters.Count < b.Parameters.Count) return -1;
if (a.Parameters.Count > b.Parameters.Count) return 1;
return 0;
});
methods.Sort((a, b) => Utils.compareInt32(a.Parameters.Count, b.Parameters.Count));
for (int i = 0; i < methods.Count; i++) {
var method = methods[i];
if (method.Parameters.Count != i + 1)

View File

@ -154,11 +154,7 @@ namespace de4dot.deobfuscators {
var fields = new List<UpdatedField>(updatedFields.Values);
if (fields.Count > 0) {
Log.v("Changing field types from object -> real type");
fields.Sort((a, b) => {
if (a.token < b.token) return -1;
if (a.token > b.token) return 1;
return 0;
});
fields.Sort((a, b) => Utils.compareInt32(a.token, b.token));
Log.indent();
foreach (var updatedField in fields)
Log.v("Field {0:X8}: type {1} ({2:X8})", updatedField.token, updatedField.newFieldType.FullName, updatedField.newFieldType.MetadataToken.ToInt32());
@ -168,11 +164,7 @@ namespace de4dot.deobfuscators {
var methods = new List<UpdatedMethod>(updatedMethods.Values);
if (methods.Count > 0) {
Log.v("Changing method args and return types from object -> real type");
methods.Sort((a, b) => {
if (a.token < b.token) return -1;
if (a.token > b.token) return 1;
return 0;
});
methods.Sort((a, b) => Utils.compareInt32(a.token, b.token));
Log.indent();
foreach (var updatedMethod in methods) {
Log.v("Method {0:X8}", updatedMethod.token);
@ -218,10 +210,7 @@ namespace de4dot.deobfuscators {
if (a.arg.Method.MetadataToken.ToInt32() < b.arg.Method.MetadataToken.ToInt32()) return -1;
if (a.arg.Method.MetadataToken.ToInt32() > b.arg.Method.MetadataToken.ToInt32()) return 1;
if (a.arg.Index < b.arg.Index) return -1;
if (a.arg.Index < b.arg.Index) return 1;
return 0;
return Utils.compareInt32(a.arg.Index, b.arg.Index);
}
class PushedArgs {