Commit Graph

636 Commits

Author SHA1 Message Date
Katy Coe
1628d1f330 Update README.md 2020-07-02 16:47:00 +02:00
Katy Coe
acc95e00c1 GUI: Add C++ scaffolding output support 2020-07-02 16:04:39 +02:00
Katy Coe
24e4c65c4c Outputs: Add MSVC/GCC option to CppScaffolding and CLI 2020-07-02 15:18:15 +02:00
Katy Coe
0731b380fd C++: Separate compiler option from CppDeclarationGenerator 2020-07-02 15:17:12 +02:00
Katy Coe
01519c4c29 CLI: Add C++ header output support 2020-07-02 14:24:20 +02:00
Katy Coe
25d19457a9 Tests: Make TestRunner output C++ headers 2020-07-02 14:21:56 +02:00
Katy Coe
c59245ec56 Outputs: Add C++ output module 2020-07-02 14:21:40 +02:00
Katy Coe
249873ab02 C++: Add some MSVC symbols to reserved names 2020-07-02 14:21:21 +02:00
Katy Coe
6c45e5867c Tests: Rename TestIDAOutput -> TestUnityVersion 2020-07-01 13:06:33 +02:00
Katy Coe
23db04c369 Minor re-organization 2020-06-30 00:13:18 +02:00
Katy Coe
18b94e08f3 Add CppDeclarationGenerator.Reset() 2020-06-30 00:06:07 +02:00
Katy Coe
a5d15f3daa Fix enum renaming on 2nd use in C++ declarations 2020-06-30 00:05:27 +02:00
Katy Coe
a3a0c17ee1 Dramatically improve startup speed when not using APK/IPA 2020-06-30 00:03:37 +02:00
Robert Xiao
9e455fdabe Renaming for clarity.
Renamed the class CppDeclarations => CppDeclarationGenerator to better reflect
its function and emphasize its statefulness.

Renamed Visit{Type,Method} => Include{Type,Method} to clarify that these methods
include the type or method into the generator state.

Renamed GenerateVisitedTypes => GenerateRemainingTypeDeclarations to clarify
that it outputs *remaining* declarations, i.e. declarations that haven't been
generated yet.
2020-06-29 22:10:45 +02:00
Robert Xiao
393d26b2a3 Move non-output to new CppUtils namespace
We prefer to have the Outputs directory contain just one file or
namespace per output module, so we'll move all C++-related stuff to a
new CppUtils namespace instead.
2020-06-29 22:10:45 +02:00
Robert Xiao
de6d9e2230 Move duplicated sanitizeIdentifier to Extensions
Also ensure that the identifier always starts with an underscore or
letter, which fixes issues with obfuscated identifiers.
2020-06-29 22:10:45 +02:00
Robert Xiao
95ee085374 Comments and minor refactoring into lambdas 2020-06-29 22:10:45 +02:00
Robert Xiao
3ccbab2461 Add/modify copyright notices 2020-06-29 22:10:45 +02:00
Robert Xiao
b7c93ffcc7 Type string literals as System.String 2020-06-29 22:10:45 +02:00
Robert Xiao
67acd18c03 Finish types implementation: vtables and classes.
Also fix a few minor bugs involving arrays and enums. Both should not
have __Class structures generated.
2020-06-29 22:10:45 +02:00
Robert Xiao
930202dfdd Handle idc.SetType return value correctly.
Apparently, idc.SetType returns True if the type is set for the first
time, False if the type is updated, and None if the type couldn't be set
(rather differently from what the documentation says).
2020-06-29 22:10:45 +02:00
Robert Xiao
75744a31dc First whack at type structs for IDA.
This commit only includes instance field structs, not class
structs/vtables/static fields.
2020-06-29 22:10:45 +02:00
Robert Xiao
caa7eaf870 Improve MetadataUsages and add types for globals
- Add string contents to names of StringLiteral objects to improve
decompilation output
- Add string constants for metadata version < 19 via an enum (if you can
identify and type il2cpp_codegen_string_literal_from_index correctly,
all enums resolve nicely to their string contents)
- Add types to metadata usages and globals
- Send method definitions & method references through writeMethods
for consistency
2020-06-29 22:10:45 +02:00
Robert Xiao
4ba48b9c75 Add generics support to TypeInfo.GetVTable
This patch fixes TypeInfo.GetVTable so that it specializes the vtable
for generic type instances. Also fix a minor bug in PropertyInfo that
would pass null pointers to GetMethodByDefinition.
2020-06-29 22:10:45 +02:00
Robert Xiao
359b99fded Automatically infer function ends in IDA.
The problem with using an end param in IDA is that IDA will quite
stupidly treat the function end as gospel even if it makes no sense
(e.g. a single "function" spanning many MB because there are no symbols
in between). Leaving out end, on the other hand, tells IDA there's a
function at a given starting address but lets IDA figure out the end by
itself, which it usually does correctly.
2020-06-29 22:10:45 +02:00
Robert Xiao
34f0d4ceef Add header files for every known Unity version.
We want to get types into the IDA output, and to do that we need
accurate types for the Il2Cpp structures. Unfortunately, some crucial
types like Il2CppClass change between versions without any corresponding
metadata changes, meaning that we have to manually identify the version
outside of the Inspector somehow (e.g. by looking at the version number
embedded in Unity asset files). This patch adds header files for *every*
known Unity version from 5.3.0 to 2019.3.8, merging them into version
ranges where header files don't change.

It also adds front-end support for supplying the version number in both
the CLI and GUI. The GUI is given the ability to guess the version
number approximately to reduce the number of choices presented to the
user.
2020-06-29 22:10:45 +02:00
Katy Coe
b87d82fd11 Tests: Fix missing tests regression 2020-06-27 11:43:21 +02:00
Katy Coe
c7cd6cca43 Update README.md 2020-06-24 10:49:42 +02:00
Katy Coe
955bc2a9ac Tests: Update expected results 2020-06-24 10:38:34 +02:00
Katy Coe
418fb7221c Update .gitignore 2020-06-24 10:38:24 +02:00
Katy Coe
5b62a72897 Tests: Save generated C++ in TestCpp 2020-06-24 10:38:13 +02:00
Katy Coe
ec922ac9ec Tests: Add ARM64 binary generation 2020-06-24 09:17:18 +02:00
Katy Coe
181d3ad600 CS: Don't output redundant interfaces in type declarations 2020-06-22 22:56:26 +02:00
Katy Coe
42310483af CS: Fix "Namespace used like type" (CS0118) (needs additional work) 2020-06-22 22:35:52 +02:00
Katy Coe
ef22c6628b CS: Fix enumeration scoping on default field values (CS0103) 2020-06-22 18:38:16 +02:00
Katy Coe
2791721dd1 Model: Implement MethodBase.GetMethodBody() 2020-06-22 17:35:23 +02:00
Katy Coe
5f0360dc0a Update README.md 2020-06-22 17:18:39 +02:00
Katy Coe
9c51e72cc2 CS: Fix representation of Infinity and NaN 2020-06-20 21:26:29 +02:00
Katy Coe
e0fe7fa1b9 CS: Add unsafe modifier to struct constructors where necessary (CS0214) 2020-06-20 21:11:03 +02:00
Katy Coe
d479431585 Model: Add FieldInfo.RequiresUnsafeContext 2020-06-20 20:43:06 +02:00
Katy Coe
ed1d80aa15 CS: "unsafe" goes after "static" to avoid IntelliSense notice 2020-06-20 20:34:51 +02:00
Katy Coe
ca113fb055 CLI: Handle attempted output to directory that is file gracefully 2020-06-20 19:34:34 +02:00
Robert Xiao
44df54b639 Suppress new on operator methods.
Per the C# language reference
(https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/basic-concepts#hiding-through-inheritance):

> The rules governing operator declarations (Operators) make it
> impossible for a derived class to declare an operator with the same
> signature as an operator in a base class. Thus, operators never hide
> one another.

Therefore, new is not necessary or permitted on operators, even if the
method signatures are identical. This situation can arise if, for
example, an explicit conversion operator from the same target class
exists in both a base class and a derived class.
2020-06-20 10:17:48 +02:00
Robert Xiao
6fff363c29 Fix bugs in testcase #11 and CSharp3.
Bug #1 is that in 32-bit programs, typeDefinitionIndex might be
0xffff_ffff_ffff_ffff instead (32-bit -1 sign-extended to 64 bits), so
we fix that by simply masking to get the low 32 bits.

Bug #2 is that, if the TypeRef points to no generic instance, we return
null, which wasn't being checked for in the IDAPythonScript generator.
Since that's the only time we could get a null type in Types, we simply
remove nulls from the Types collection.
2020-06-20 10:17:48 +02:00
Robert Xiao
5354d39181 Code reformatting 2020-06-20 10:17:48 +02:00
Robert Xiao
4207464208 Add events, fields and properties to concrete generics.
This basically finishes the concrete generics implementation. We can now
enumerate all members of a concrete generic type with full type
substitution implemented.

Also add a simple test to verify that we can obtain the correct type for
a field of a concrete generic type.
2020-06-20 10:17:48 +02:00
Robert Xiao
1a12567227 Fix method signature comparison.
Now that we generate methods in instantiated generic types, we were
getting test failures from methods that were being detected as new
methods. In actuality, they weren't new, but they differed only in
generic type parameters from some base type method, and
GetSignatureString ignores generic parameters completely.

This fix eliminates the hacky GetSignatureString and replaces it with
more-or-less proper signature comparison. This even manages to fix an
incorrect test case from Methods.cs (because GetSignatureString was
incorrectly incorporating the return type - when the return type should
not be examined for signature checking).
2020-06-20 10:17:48 +02:00
Robert Xiao
652d76d6fe Implement constructors & methods on constructed generics.
We adopt roughly the same approach as the C# Reflection API: a
GenericMethodDefinition is a method which has no method parameters
substituted, but lives in a open or closed type with some or all
type parameters substituted. To ensure the uniqueness of the MethodInfo,
we cache by the method type arguments, and also cache generated
DeclaredConstructors/DeclaredMethods in the TypeInfo.

This also enables MakeGenericMethod, albeit in a slightly different form
than the Reflection API: MakeGenericMethod lives in MethodBase, so it's
callable from a constructor (even though in C# constructors cannot be
generic). This slight violation of the spec reduces code duplication, so
it's probably worth it.

Finally, VirtualAddress gets set when populating GenericMethods, and so
it'll work whether or not the methods get cached/generated ahead of
time.
2020-06-20 10:17:48 +02:00
Robert Xiao
867f559f18 Support BaseType and ImplementedInterfaces on generic params
This has been a little TODO for a while, and happily it's easy enough to
implement with TypeRef arrays.

Also implement ImplementedInterfaces for generic type instances via
substitution.
2020-06-20 10:17:48 +02:00
Robert Xiao
a36c93514d Implement NestedTypes for generic instances
In the C# reflection API, DeclaredNestedTypes on concrete generic types
just returns the nested types of the type definition. Notably, type
parameters are not substituted, because nested types are not guaranteed
to use the same containing type's type parameters.
2020-06-20 10:17:48 +02:00