Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions dspatch/Nitro/ARM9.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,30 @@ private static uint FindModuleParams(byte[] Data)
return (uint)IndexOf(Data, new byte[] { 0x21, 0x06, 0xC0, 0xDE, 0xDE, 0xC0, 0x06, 0x21 }) - 0x1C;
}

private static unsafe long IndexOf(byte[] Data, byte[] Search)
private static long IndexOf(byte[] Data, byte[] Search)
{
fixed (byte* H = Data) fixed (byte* N = Search)
long MaxOffset = Data.LongLength - Search.LongLength + 1;
if (MaxOffset <= 0)
{
long i = 0;
for (byte* hNext = H, hEnd = H + Data.LongLength; hNext < hEnd; i++, hNext++)
throw new ArgumentOutOfRangeException(nameof(Search));
}

for (long Offset = 0; Offset < MaxOffset; Offset++)
{
bool Found = true;
for (long patternOffset = 0; patternOffset < Search.LongLength; patternOffset++)
{
bool Found = true;
for (byte* hInc = hNext, nInc = N, nEnd = N + Search.LongLength; Found && nInc < nEnd; Found = *nInc == *hInc, nInc++, hInc++) ;
if (Found) return i;
if (Data[Offset + patternOffset] != Search[patternOffset])
{
Found = false;
break;
}
}
return -1;

if (Found) return Offset;
}

throw new Exception("No target module params offset found!");
}
}
}
12 changes: 12 additions & 0 deletions dspatch/dspatch-core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>dspatch</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Properties\**" />
</ItemGroup>

</Project>