Skip to content

Commit

Permalink
fix: correct formatting of loggerFactory creation in Program.cs
Browse files Browse the repository at this point in the history
feat: implement ResolveStringPointerList method in MemoryReader
refactor: update gameInfoAddress resolution logic in Program.cs
chore: update version prefix in Processory.csproj
chore: update assembly file version in AssemblyInfo.cs
  • Loading branch information
myinusa committed Oct 4, 2024
1 parent a301f60 commit 0ecc8d8
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ output-key-value-pairs*
[Bb]uild[Ll]og.*
packages/

release-command.md

*_i.c
*_p.c
*.ilk
Expand Down
24 changes: 20 additions & 4 deletions Processory.Insight/Program.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace Processory.Insight;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;

public class Program {
private const ulong GameExceptionHandlerOffset = 0x04d50e30;
private const ulong BaseAddress = 0x140000000;

public static void Main() {
var GivenName = "fm";
var loggerFactory = LoggerFactory.Create(builder =>
{
var loggerFactory = LoggerFactory.Create(builder => {
builder.AddConsole();
});
var processory = new ProcessoryClient(GivenName, loggerFactory);
Expand All @@ -24,13 +23,30 @@ public static void Main() {
var addr1 = BaseAddress + GameExceptionHandlerOffset;
nuint defrOneAdd = processory.PointerChainFollower.DereferencePointer(addr1);

// var breakpad_exception = processory.PointerChainFollower.ResolvePointerChain(defrOneAdd, new List<int> { 0x10, 0x28, 0x8, 0x4 });
var breakpad_exception = processory.MemoryReader.ResolveStringPointerList(defrOneAdd, new List<int> { 0x10, 0x28, 0x8, 0x4 });

// Console.WriteLine("breakpad_exception: {0:X8}", breakpad_exception);

var screenClient = (ulong)(baseAddress + 0x4C7FF08);
var deferAdd = processory.PointerChainFollower.DereferencePointer(screenClient);
var screenClientValue = processory.MemoryReader.Read<uint>(deferAdd);

var gameInfoAddress = processory.PointerChainFollower.ResolvePointerChain(defrOneAdd, new List<int> { 0x20 });
var gameInfoAddress = processory.PointerChainFollower.ResolvePointerChain(defrOneAdd, new List<int> { 0x20, 0x4 });
// var gameInfoValue = processory.MemoryReader.ResolveStringPointer(defrOneAdd, new List<int> { 0x20, 0x4 });
// var gameInfoValue = processory.MemoryReader.ResolveStringPointerList(defrOneAdd, new List<int> { 0x20, 0x4 });
Console.WriteLine("-------------------------------------------------------------");
// Console.WriteLine($"{breakpad_exception:X8}");
// Console.WriteLine("Total game info count: {0}", gameInfoValue.Count);
Console.WriteLine("Total game info count: {0}", breakpad_exception.Count);
//
for (int i = 0; i < breakpad_exception.Count; i++) {
Console.WriteLine("[{0}] | Game info: {1}", i, breakpad_exception[i]);
}
Console.WriteLine("-------------------------------------------------------------");

Console.WriteLine("Screen client: {0:X}", screenClient);
// Console.WriteLine("gameInfoValue: {0}", gameInfoValue);
Console.WriteLine("Screen client value: {0}", screenClientValue);
Console.WriteLine("Game info address: {0:X}", gameInfoAddress);
}
Expand Down
50 changes: 50 additions & 0 deletions Processory/Internal/MemoryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,56 @@ public string ResolveStringPointerE(UIntPtr initialAddress, List<int> offsets) {
return Encoding.UTF8.GetString(buffer);
}

public List<string> ResolveStringPointerList(nuint initialAddress, List<int> offsets) {
nuint address = processoryClient.PointerChainFollower.FollowPointerChain(initialAddress, offsets);
List<int> list = new List<int>(offsets);
list[list.Count - 1] = 0;
Span<byte> span = stackalloc byte[Read<int>(initialAddress, list)];
ReadR(address, span);

// List to hold the found strings
List<string> strings = new List<string>();
Console.WriteLine(span.Length);

// Iterate through the span to find segments separated by null terminators
int startIndex = 0;
while (startIndex < span.Length) {
try {
// Find the index of the next null terminator (either 0 or 10)
int nullIndex = span.Slice(startIndex).IndexOfAny((byte)0, (byte)10);

// Console.WriteLine($"nullIndex: {nullIndex}");
// If no more null terminator is found, take the rest of the span
if (nullIndex == -1) {
// if (nullIndex < -1) {
nullIndex = span.Length - startIndex;
Span<byte> segment1 = span.Slice(startIndex, nullIndex);
strings.Add(Encoding.UTF8.GetString(segment1));
// Console.WriteLine($"segment: {Encoding.UTF8.GetString(segment1)}");
break;
}
else {
nullIndex += startIndex; // Adjust index to the original span
}

// Console.WriteLine($"startIndex: {startIndex}, span.Length: {span.Length}");
// Create a segment from startIndex to nullIndex
Span<byte> segment = span.Slice(startIndex, nullIndex - startIndex);
// Console.WriteLine($"segment: {Encoding.UTF8.GetString(segment)}");
strings.Add(Encoding.UTF8.GetString(segment));

// Move the startIndex past the null terminator
startIndex = nullIndex + 1; // +1 to skip the null terminator
}
catch (ArgumentOutOfRangeException ex) {
logger.LogError(ex, "An error occurred while resolving string pointer list.");
break; // Exit the loop if an error occurs
}
}

return strings; // Return the list of strings
}

public T ReadUnsignedFileOffset<T>(UIntPtr address, string key)
where T : unmanaged {
Row foundRow = processoryClient.CSVDataOffsetManager.GetRowByStringName(key);
Expand Down
2 changes: 1 addition & 1 deletion Processory/Processory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>1.14.241002.1904</VersionPrefix>
<VersionPrefix>1.15.241004.2022</VersionPrefix>
</PropertyGroup>

<PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions Processory/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#pragma warning disable CS7035 // The specified version string does not conform to the recommended format - major.minor.build.revision

[assembly: AssemblyFileVersion("1.14.241002.1904")]
[assembly: AssemblyInformationalVersion("1.14.0")]
[assembly: AssemblyFileVersion("1.15.241004.2022")]
[assembly: AssemblyInformationalVersion("1.15.0")]

#pragma warning restore CS7035

0 comments on commit 0ecc8d8

Please sign in to comment.