Skip to content
This repository has been archived by the owner on Oct 5, 2019. It is now read-only.

Commit

Permalink
Added more trash modes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaczero committed Jun 6, 2017
1 parent 9259af5 commit f6411d2
Showing 1 changed file with 59 additions and 6 deletions.
65 changes: 59 additions & 6 deletions SharpLoader/Core/SourceRandomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,40 @@ private void Trash(ref string str)
{
// value trash
var varName = GetRandomName();
var operation = _rnd.Next(0, 2) == 0 ? '+' : '-';
char operation;

switch (_rnd.Next(0, 5))
{
case 0:
{
operation = '+';
break;
}
case 1:
{
operation = '-';
break;
}
case 2:
{
operation = '*';
break;
}
case 3:
{
operation = '/';
break;
}
case 4:
{
operation = '^';
break;
}
default:
{
throw new Exception("invalid switch value");
}
}

string varType;
int varValue;
Expand All @@ -542,7 +575,7 @@ private void Trash(ref string str)
{
varType = "byte";
varChange = _rnd.Next(1, byte.MaxValue);
varValue = operation == '+'
varValue = operation != '-'
? _rnd.Next(byte.MinValue, byte.MaxValue - varChange)
: _rnd.Next(byte.MinValue + varChange, byte.MaxValue);
break;
Expand All @@ -551,7 +584,7 @@ private void Trash(ref string str)
{
varType = "short";
varChange = _rnd.Next(1, short.MaxValue);
varValue = operation == '+'
varValue = operation != '-'
? _rnd.Next(short.MinValue, short.MaxValue - varChange)
: _rnd.Next(short.MinValue + varChange, short.MaxValue);
break;
Expand All @@ -560,7 +593,7 @@ private void Trash(ref string str)
{
varType = "int";
varChange = _rnd.Next(1, int.MaxValue);
varValue = operation == '+'
varValue = operation != '-'
? _rnd.Next(int.MinValue, int.MaxValue - varChange)
: _rnd.Next(int.MinValue + varChange, int.MaxValue);
break;
Expand All @@ -578,8 +611,8 @@ private void Trash(ref string str)
{
// object trash
var operation = _rnd.Next(0, 2) == 0 ? "GetHashCode()" : "GetTypeCode()";

switch (_rnd.Next(0, 6))
switch (_rnd.Next(0, 10))
{
case 0:
{
Expand Down Expand Up @@ -611,6 +644,26 @@ private void Trash(ref string str)
trash += $"new long().{operation};";
break;
}
case 6:
{
trash += $"new sbyte().{operation};";
break;
}
case 7:
{
trash += $"new ushort().{operation};";
break;
}
case 8:
{
trash += $"new uint().{operation};";
break;
}
case 9:
{
trash += $"new ulong().{operation};";
break;
}
default:
{
throw new Exception("invalid switch value");
Expand Down

0 comments on commit f6411d2

Please sign in to comment.