Commit Graph

778 Commits

Author SHA1 Message Date
Robert Xiao
a9f6e7b4e0 Generify reference indices to prepare for generic instances
We use indices into the TypesByReferenceIndex table to defer type lookup
during model construction. However, this won't support fully generic
instances (which might not be in the type table at all). This patch
introduces a new TypeRef abstraction which can either represent a fixed
index or an instantiated generic type.
2020-06-20 10:17:48 +02:00
Robert Xiao
3cd5af09fc Have TestRunner output IDA scripts too
This is done as a sanity check to make sure we aren't breaking IDA output.
2020-06-20 10:17:48 +02:00
Robert Xiao
ab5fc836a1 Introduce a cache for generic type instantiations.
Also add MakeGenericType, which creates type instances from a generic
type definition and arguments. We will use this later to build properly
fleshed out concrete generic types.
2020-06-20 10:17:48 +02:00
Robert Xiao
648840c714 Add generic type definition to list of type references 2020-06-20 10:17:48 +02:00
Robert Xiao
2c164aec02 Change generic params/args to arrays
The C# functions for GetGenericParameters/GetGenericArguments use
Type[], not lists, so we should conform to that.

Also fix the definition of IsGenericTypeDefinition - because it's
possible for a class to be instantiated with all generic parameters.
2020-06-20 10:17:48 +02:00
Robert Xiao
996fb1ff36 Avoid recreating ref'd types that already exist
Because TypesByReferenceIndex can be populated in two places
(Il2CppModel constructor and GetTypeFromVirtualAddress), we need to
avoid generating the same type multiple times.
2020-06-20 10:17:48 +02:00
Robert Xiao
71bf353ae0 Remove ResolveGenericArguments(int) entirely
It's not really needed anymore, and it is clearer without that method.
2020-06-20 10:17:48 +02:00
Robert Xiao
f0124d9290 Remove index from BaseType, DeclaringType
All types will need to eventually be fully generic. Therefore, we need
to eliminate indices when referring to types, and also be very lazy when
accessing TypeInfo properties so that we don't access uninitialized
types during model creation.
2020-06-20 10:17:48 +02:00
Robert Xiao
6ddb502e96 Refactor TypeInfo names and fix out/in
Replace the deeply nested ternaries in TypeInfo with if-statements for
clarity.
Remove in/out from CSharpName, keeping it only on immediate type params
in CSharpTypeDeclarationName (refactored to a method).
Rearrange name-related properties and methods to group them all together
into a region for easier navigation.
2020-06-20 10:17:48 +02:00
Robert Xiao
7797ac2506 Refactor TypeInfo constructors
This patch replaces Il2CppModel.resolveTypeReference by a static
TypeInfo constructor, and simultaneously refactors the TypeInfo
constructors to eliminate duplication between resolveTypeReference and
the original constructors. This will make future refactoring much
easier.
2020-06-20 10:17:48 +02:00
Robert Xiao
dfabe9235d Use CollectionAssert for better test feedback.
For minor problems with the test output (e.g. one-line changes),
CollectionAssert.AreEqual will show the exact line which is changed, for
much better test feedback.
2020-06-20 10:17:48 +02:00
Robert Xiao
d2b5f9d48b Enable test parallelization for a nice speedup 2020-06-20 10:17:48 +02:00
Katy Coe
e2f42bd137 Tests: Update expected results 2020-06-19 14:57:37 +02:00
Robert Xiao
1c1f542107 Tests: Add new test assemblies for C# features (#36)
* Add new test assemblies for C# features

Three of these test assemblies go over several important features of C#,
organized by C# language version. PartialGenericTypes stresses closed
and partially closed generics. Finally, VTablesAndLayout tests the
layout of classes when translated to C++, and also contains code which
calls vtable and interface functions to test reverse engineering.

* Tests: Update .csproj

* Tests: Update .csproj

Co-authored-by: Katy Coe <djkaty@users.noreply.github.com>
2020-06-19 14:52:09 +02:00
Katy Coe
ce4d2792b8 Update README.md 2020-06-18 17:12:12 +02:00
Katy Coe
f79d4b7aad Update README.md 2020-06-18 16:52:01 +02:00
Katy Coe
d38620a7d7 GUI: Add support for opening APK and IPA package files 2020-06-18 16:45:32 +02:00
Katy Coe
5bcce0ca0a CLI: Allow -i to accept APK or IPA package files 2020-06-18 16:44:31 +02:00
Katy Coe
5baf8cdc2d IL2CPP: Add APK and IPA package extraction API
Add LoadFromStream, LoadFromPackage, GetStreamsFromPackage
2020-06-18 16:43:48 +02:00
Katy Coe
08937ead3a MachO: Throw an exception if file is encrypted with FairPlay DRM 2020-06-18 16:41:57 +02:00
Katy Coe
d668cd3685 Update .gitignore 2020-06-18 16:40:43 +02:00
Robert Xiao
5d57b76735 Move index decoding to MetadataUsage
This reduces code duplication between metadata usage index decoding and
vtable method index decoding.
2020-06-17 08:18:15 +02:00
Robert Xiao
d426dad820 Add support for parsing and interpreting VTables
This prepares for a future PR where we add types to the IDA script
output.
2020-06-17 08:18:15 +02:00
Robert Xiao
5224429b0a Fix {{ typo in CSharpCodeStubs 2020-06-17 08:18:15 +02:00
Robert Xiao
c9d65e5f2d Get 2019.3.7f1+ working by adding new '24.3' version
In 2019.3.7f1, the following fields were added to
Il2CppCodeRegistration:

     uint32_t interopDataCount;
     Il2CppInteropData* interopData;
+    uint32_t windowsRuntimeFactoryCount;
+    Il2CppWindowsRuntimeFactoryTableEntry* windowsRuntimeFactoryTable;
     uint32_t codeGenModulesCount;
     const Il2CppCodeGenModule** codeGenModules;

These two fields overlap the old codeGenModules fields, causing failures.
The current fix is simply to bump the version to 24.3 if these fields are
detected in order to get the correct codeGenModules pointer. Long term, a
better detection mechanism (probably based on examining the name string
pointer in codeGenModules[0]) will be necessary. However, this is pending
more samples of 2019.3.7+ for testing.
2020-06-16 23:30:53 +02:00
Robert Xiao
4f074837b7 Fix fieldOffsetsArePointers logic on 64-bit builds
The logic for fieldOffsetsArePointers was always reading 32-bit units
even on 64-bits. When fieldOffsetsArePointers is true, fieldOffsets is
declared as int32_t**, so each element *must* be a pointer and therefore
word-sized (64 bits on 64-bit machines). So it doesn't make sense to
only read 32-bit words for this test.

This fixes metadata extraction for 64-bit builds from Il2Cpp versions
5.3.7f1, 5.3.8f2, 5.4.1f1, 5.4.2f2, 5.4.3f1, 5.4.4f1, 5.4.5f1 and
5.4.6f3. Notably, 5.4.0f3 is an unusual outlier which uses int32_t * for
fieldOffsets.
2020-06-16 23:30:53 +02:00
Robert Xiao
02fab932ae referencedAssemblies was added in v5.3.3 (metadata 20)
According to the headers I have available, Unity v5.3.2f1 (metadata 19)
lacks the referencedAssemblies{Offset,Count} fields in
Il2CppGlobalMetadataHeader. These appear to have been added some time
between that version and 5.3.3f1 (metadata 20).

Changing these fields makes the Inspector work properly on the output from
Il2Cpp from Unity v5.3.2f1.
2020-06-16 23:30:53 +02:00
Robert Xiao
7fce43aba0 Fix IDA writeUsages for metadata <19
This fixes a NullReferenceException that was being thrown for IDA script
generation for metadata 16 files (e.g. as generated by Il2Cpp v5.3.0f4).
2020-06-16 23:30:53 +02:00
Robert Xiao
5b78fc3f3c Fix pointer extraction for MSVC in metadata <21.
This change causes the Inspector to properly parse DLLs generated with
Il2Cpp versions 5.3.0f4 through 5.3.4f1 (excluding 5.3.2f1, which is a
separate problem).
2020-06-16 23:30:53 +02:00
Katy Coe
b9dffd3500 Allow divergent metadata/binary versions
Il2CppInspector reports the highest version of the two
2020-06-16 23:27:51 +02:00
Katy Coe
0f2fff6e70 Tidy up error handling slightly 2020-06-16 23:08:15 +02:00
Katy Coe
d16db6f1f5 X64: Fix R8 unused compile warning 2020-06-16 23:07:42 +02:00
Katy Coe
89b3c2b3aa ELF: Detect a specific type of packing that isn't handled 2020-06-16 23:07:01 +02:00
Katy Coe
0b9b5022ab CLI: Fix regression causing Windows path search to fail 2020-06-16 23:06:08 +02:00
Katy Coe
370eebfffc ELF: Slightly more careful XOR decryption (#27) 2020-06-16 21:53:57 +02:00
Katy Coe
5e435465f1 ELF: Don't crash on duplicate section names (#26) 2020-06-16 15:35:17 +02:00
Callie LeFave
dee6c45056 Fix CSharp output paths on POSIX filesystems 2020-06-16 12:25:10 +02:00
Katy Coe
3e1228495f Tests: Update expected results 2020-02-28 11:29:35 +01:00
Katy Coe
40ab603c56 C#: Don't output field offsets for open generic types 2020-02-28 11:01:38 +01:00
Katy Coe
c0e90f2e9c IL2CPP: Fix field offsets for value types (#25) 2020-02-28 11:01:26 +01:00
Katy Coe
a5a5d66182 Update README.md 2020-02-26 15:38:51 +01:00
Katy Coe
c540318363 Update version to 2.1 2020-02-26 15:38:45 +01:00
Katy Coe
b961db78f2 SELF: Initial support for PRX/SPRX files (issue #21) 2020-02-26 02:59:02 +01:00
Katy Coe
e4034e6a39 SELF: More boilerplate code 2020-02-25 16:15:37 +01:00
Katy Coe
b509b4d227 SELF: Boilerplate code 2020-02-25 16:15:17 +01:00
Katy Coe
250c3a2fc9 Loader: Unwrap FileFormatReader.Load exceptions 2020-02-24 13:37:06 +01:00
Katy Coe
58771cf308 Tests: Update test results 2020-02-24 12:32:23 +01:00
Katy Coe
027dde8358 C#: Replace "in, out" with "[In, Out]" (CS8328) 2020-02-24 12:28:38 +01:00
Katy Coe
168c955558 C#: Set static and instance constructor defaults correctly (CS0120) 2020-02-24 12:24:04 +01:00
Katy Coe
6046f2493d C#: Reduce scope redundancies in type declarations 2020-02-24 12:05:33 +01:00