Beispiel #1
0
            /// <summary>
            /// Create a HarmonyLibrary from a subset of the given byte array, which should contain the bytes of
            /// an unmanaged EXE or an unmanaged DLL.
            /// </summary>
            /// <param name="rawDll">An array of bytes that contains the EXE or DLL to load.</param>
            /// <param name="offset">Where within the raw byte array the actual EXE or DLL starts.</param>
            /// <param name="length">The length of the EXE or DLL bytes starting at the given offset in the array.</param>
            /// <param name="name">(optional) The name of the library we're loading (to be used when resolving other libraries).</param>
            /// <param name="loadFlags">(optional) Flags to control how this loading is performed.</param>
            /// <param name="otherLibraries">(optional) Any other HarmonyLibraries to use when resolving this library's imports.</param>
            /// <returns>A HarmonyLibrary instance.</returns>
            /// <throws cref="LoadFailedException">Thrown when the library cannot be loaded (if, for example, it is corrupt
            /// data, or if one of its imports cannot be resolved).  The exception message will provide details to explain
            /// why the library-load failed.</throws>
            public static HarmonyLibrary CreateFromBytes(byte[] rawDll, uint offset, uint length, string name = null,
                                                         HarmonyLoadFlags loadFlags = 0, IEnumerable <HarmonyLibrary> otherLibraries = null)
            {
                LibraryLoader  libraryLoader = new LibraryLoader(loadFlags, otherLibraries);
                HarmonyLibrary library       = libraryLoader.CreateLibrary(rawDll, offset, length, name);

                return(library);
            }
Beispiel #2
0
            public static T Create <T>(HarmonyLibrary library)
                where T : class, IDisposable
            {
                if (!typeof(T).IsInterface)
                {
                    throw new ArgumentException("The generic T used for a Harmony class must be an interface.");
                }

                return(null);
            }
Beispiel #3
0
        static void Main(string[] args)
        {
            // This assembly has a copy of Crc32.dll stored as an embedded resource, so retrieve that resource.
            Stream crc32Dll = Assembly.GetExecutingAssembly().GetManifestResourceStream("Crc32Example.Crc32.dll");

            // Now make a HarmonyLibrary from that resource stream.
            using (HarmonyLibrary harmonyLibrary = HarmonyLibrary.CreateFromStream(crc32Dll))
            {
                // Get the Crc32 function from the HarmonyLibrary.
                Crc32 method = harmonyLibrary.GetFunction <Crc32>();

                // We're going to perform a CRC32 on this string.
                string sourceString = "This is a test.";                        // Should have a CRC-32 of 0xC6C3C95D.
                Console.WriteLine(sourceString);

                // Do the CRC-32, using the compiled C library.
                uint crc32 = method(Encoding.ASCII.GetBytes(sourceString), 0, sourceString.Length, 0);
                Console.WriteLine("CRC-32: 0x{0:X8}", crc32);
            }
        }
Beispiel #4
0
            private static HarmonyImportLibrary LoadHarmonyImport(byte *basePtr, uint size, IMAGE_IMPORT_DESCRIPTOR *importDescriptor, HarmonyLibrary library)
            {
                HarmonyImportLibrary importLibrary = ApplyImportLibrary(
                    basePtr, size, importDescriptor, library.Name, HarmonyImportLibraryKind.HarmonyLibrary,
                    library.GetProcAddress, library.GetProcAddressByOrdinal
                    );

                return(importLibrary);
            }