Skip to content

Commit

Permalink
minimize changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ds5678 committed Dec 29, 2023
1 parent 8f959e1 commit 59240b0
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 12 deletions.
6 changes: 3 additions & 3 deletions LibCpp2IL/BinarySearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ internal ulong FindCodeRegistrationPost2019()

//We have pCodegenModules which *should* be x-reffed in the last pointer of Il2CppCodeRegistration.
//So, subtract the size of one pointer from that...
var bytesToGoBack = (ulong) LibCpp2ILUtils.VersionAwareSizeOf<Il2CppCodeRegistration>() - ptrSize;
var bytesToGoBack = (ulong) LibCpp2ILUtils.VersionAwareSizeOf(typeof(Il2CppCodeRegistration)) - ptrSize;

LibLogger.VerboseNewline($"\t\t\tpCodegenModules is the second-to-last field of the codereg struct. Therefore on this version and architecture, we need to subtract {bytesToGoBack} bytes from its address to get pCodeReg");

Expand Down Expand Up @@ -285,7 +285,7 @@ public static bool ValidateCodeRegistration(Il2CppCodeRegistration codeReg, Dict
public ulong FindMetadataRegistrationPre24_5()
{
//We're looking for TypeDefinitionsSizesCount, which is the 4th-to-last field
var sizeOfMr = (ulong) LibCpp2ILUtils.VersionAwareSizeOf<Il2CppMetadataRegistration>();
var sizeOfMr = (ulong) LibCpp2ILUtils.VersionAwareSizeOf(typeof(Il2CppMetadataRegistration));
var ptrSize = _binary.is32Bit ? 4ul : 8ul;

var bytesToSubtract = sizeOfMr - ptrSize * 4;
Expand Down Expand Up @@ -315,7 +315,7 @@ public ulong FindMetadataRegistrationPre24_5()
public ulong FindMetadataRegistrationPost24_5()
{
var ptrSize = _binary.is32Bit ? 4ul : 8ul;
var sizeOfMr = (uint) LibCpp2ILUtils.VersionAwareSizeOf<Il2CppMetadataRegistration>();
var sizeOfMr = (uint) LibCpp2ILUtils.VersionAwareSizeOf(typeof(Il2CppMetadataRegistration));

LibLogger.VerboseNewline($"\t\t\tLooking for the number of type definitions, 0x{_typeDefinitionsCount:X}");
var ptrsToNumberOfTypes = FindAllMappedWords((ulong) _typeDefinitionsCount).ToList();
Expand Down
2 changes: 1 addition & 1 deletion LibCpp2IL/Elf/ElfFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private void ProcessRelocations()
}
}

var sizeOfRelocationStruct = (ulong) (is32Bit ? LibCpp2ILUtils.VersionAwareSizeOf<ElfDynamicSymbol32>(true, false) : LibCpp2ILUtils.VersionAwareSizeOf<ElfDynamicSymbol64>(true, false));
var sizeOfRelocationStruct = (ulong) (is32Bit ? LibCpp2ILUtils.VersionAwareSizeOf(typeof(ElfDynamicSymbol32), true, false) : LibCpp2ILUtils.VersionAwareSizeOf(typeof(ElfDynamicSymbol64), true, false));

LibLogger.Verbose($"\t-Now Processing {rels.Count} relocations...");

Expand Down
7 changes: 0 additions & 7 deletions LibCpp2IL/LibCpp2IlUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,6 @@ public static Il2CppTypeReflectionData GetTypeReflectionData(Il2CppType forWhat)
throw new ArgumentException($"Unknown type {forWhat.Type}");
}

public static int VersionAwareSizeOf<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(
bool dontCheckVersionAttributes = false,
bool downsize = true)
{
return VersionAwareSizeOf(typeof(T), dontCheckVersionAttributes, downsize);
}

public static int VersionAwareSizeOf(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] Type type,
bool dontCheckVersionAttributes = false,
Expand Down
2 changes: 1 addition & 1 deletion LibCpp2IL/Metadata/Il2CppMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private Il2CppMetadata(MemoryStream stream) : base(stream)

private T[] ReadMetadataClassArray<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(int offset, int length) where T : ReadableClass, new()
{
return ReadReadableArrayAtRawAddr<T>(offset, length / LibCpp2ILUtils.VersionAwareSizeOf<T>(downsize: false));
return ReadReadableArrayAtRawAddr<T>(offset, length / LibCpp2ILUtils.VersionAwareSizeOf(typeof(T), downsize: false));
}

private void DecipherMetadataUsage()
Expand Down

0 comments on commit 59240b0

Please sign in to comment.