Skip to content

Commit f377de9

Browse files
committed
Refactored IsLikelyPrintableData.
1 parent 5ae0961 commit f377de9

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

ReClass.NET/Extensions/StringExtensions.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,23 @@ public static bool IsPrintableData(this IEnumerable<char> source)
4040
{
4141
Contract.Requires(source != null);
4242

43-
return IsLikelyPrintableData(source) >= 1.0f;
43+
return CalculatePrintableDataThreshold(source) >= 1.0f;
4444
}
4545

4646
[DebuggerStepThrough]
47-
public static float IsLikelyPrintableData(this IEnumerable<char> source)
47+
public static bool IsLikelyPrintableData(this IEnumerable<char> source)
4848
{
4949
Contract.Requires(source != null);
5050

51-
bool doCountValid = true;
52-
int countValid = 0;
53-
int countAll = 0;
51+
return CalculatePrintableDataThreshold(source) >= 0.75f;
52+
}
53+
54+
[DebuggerStepThrough]
55+
public static float CalculatePrintableDataThreshold(this IEnumerable<char> source)
56+
{
57+
var doCountValid = true;
58+
var countValid = 0;
59+
var countAll = 0;
5460

5561
foreach (var c in source)
5662
{

ReClass.NET/Memory/NodeDissector.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ public static bool GuessNode(BaseHexNode node, MemoryBuffer memory, out BaseNode
4545
var data32 = memory.ReadObject<UInt32FloatData>(offset);
4646

4747
var raw = memory.ReadBytes(offset, node.MemorySize);
48-
if (raw.InterpretAsUtf8().IsLikelyPrintableData() >= 0.75f)
48+
if (raw.InterpretAsUtf8().IsLikelyPrintableData())
4949
{
5050
guessedNode = new Utf8TextNode();
5151

5252
return true;
5353
}
54-
if (raw.InterpretAsUtf16().IsLikelyPrintableData() >= 0.75f)
54+
if (raw.InterpretAsUtf16().IsLikelyPrintableData())
5555
{
5656
guessedNode = new Utf16TextNode();
5757

@@ -147,13 +147,13 @@ private static bool GuessPointerNode(IntPtr address, IProcessReader process, out
147147

148148
// Check if it is a string.
149149
var data = process.ReadRemoteMemory(address, IntPtr.Size * 2);
150-
if (data.Take(IntPtr.Size).InterpretAsUtf8().IsLikelyPrintableData() >= 07.5f)
150+
if (data.Take(IntPtr.Size).InterpretAsUtf8().IsLikelyPrintableData())
151151
{
152152
node = new Utf8TextPtrNode();
153153

154154
return true;
155155
}
156-
if (data.InterpretAsUtf16().IsLikelyPrintableData() >= 0.75f)
156+
if (data.InterpretAsUtf16().IsLikelyPrintableData())
157157
{
158158
node = new Utf16TextPtrNode();
159159

0 commit comments

Comments
 (0)