|
1 | | -using System; |
| 1 | +using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Diagnostics.Contracts; |
4 | 4 | using System.Linq; |
|
10 | 10 | using ReClassNET.Core; |
11 | 11 | using ReClassNET.Debugger; |
12 | 12 | using ReClassNET.Extensions; |
| 13 | +using ReClassNET.MemoryScanner; |
13 | 14 | using ReClassNET.Native; |
14 | 15 | using ReClassNET.Symbols; |
15 | 16 | using ReClassNET.Util; |
@@ -366,24 +367,24 @@ public string ReadRemoteString(Encoding encoding, IntPtr address, int length) |
366 | 367 | } |
367 | 368 | } |
368 | 369 |
|
369 | | - /// <summary>Reads a string from the address in the remote process with the given length using UTF8 encoding. The string gets truncated at the first zero character.</summary> |
| 370 | + /// <summary>Reads a string from the address in the remote process with the given length and encoding. The string gets truncated at the first zero character.</summary> |
| 371 | + /// <param name="encoding">The encoding used by the string.</param> |
370 | 372 | /// <param name="address">The address of the string.</param> |
371 | 373 | /// <param name="length">The length of the string.</param> |
372 | 374 | /// <returns>The string.</returns> |
373 | | - public string ReadRemoteUTF8StringUntilFirstNullCharacter(IntPtr address, int length) |
| 375 | + public string ReadRemoteStringUntilFirstNullCharacter(Encoding encoding, IntPtr address, int length) |
374 | 376 | { |
| 377 | + Contract.Requires(encoding != null); |
375 | 378 | Contract.Requires(length >= 0); |
376 | 379 | Contract.Ensures(Contract.Result<string>() != null); |
377 | 380 |
|
378 | | - var data = ReadRemoteMemory(address, length); |
| 381 | + var data = ReadRemoteMemory(address, length * encoding.GetSimpleByteCountPerChar()); |
379 | 382 |
|
380 | | - int index = 0; |
381 | | - for (; index < data.Length; ++index) |
| 383 | + // TODO We should cache the pattern per encoding. |
| 384 | + var index = PatternScanner.FindPattern(BytePattern.From(new byte[encoding.GetSimpleByteCountPerChar()]), data); |
| 385 | + if (index == -1) |
382 | 386 | { |
383 | | - if (data[index] == 0) |
384 | | - { |
385 | | - break; |
386 | | - } |
| 387 | + index = data.Length; |
387 | 388 | } |
388 | 389 |
|
389 | 390 | try |
@@ -444,7 +445,7 @@ private string ReadRemoteRuntimeTypeInformation32(IntPtr address) |
444 | 445 | var typeDescriptorPtr = ReadRemoteIntPtr(baseClassDescriptorPtr); |
445 | 446 | if (typeDescriptorPtr.MayBeValid()) |
446 | 447 | { |
447 | | - var name = ReadRemoteUTF8StringUntilFirstNullCharacter(typeDescriptorPtr + 0x0C, 60); |
| 448 | + var name = ReadRemoteStringUntilFirstNullCharacter(Encoding.UTF8, typeDescriptorPtr + 0x0C, 60); |
448 | 449 | if (name.EndsWith("@@")) |
449 | 450 | { |
450 | 451 | name = NativeMethods.UndecorateSymbolName("?" + name); |
@@ -506,7 +507,7 @@ private string ReadRemoteRuntimeTypeInformation64(IntPtr address) |
506 | 507 | { |
507 | 508 | var typeDescriptorPtr = baseAddress + typeDescriptorOffset; |
508 | 509 |
|
509 | | - var name = ReadRemoteUTF8StringUntilFirstNullCharacter(typeDescriptorPtr + 0x14, 60); |
| 510 | + var name = ReadRemoteStringUntilFirstNullCharacter(Encoding.UTF8, typeDescriptorPtr + 0x14, 60); |
510 | 511 | if (string.IsNullOrEmpty(name)) |
511 | 512 | { |
512 | 513 | break; |
|
0 commit comments