Ejemplo n.º 1
0
        internal ImageExports(MappedImage mappedImage)
        {
            _mappedImage = mappedImage;
            _dataDirectory = mappedImage.GetDataEntry(ImageDataEntry.Export);
            _exportDirectory = mappedImage.GetExportDirectory();

            if (_exportDirectory != null)
            {
                _addressTable = (int*)mappedImage.RvaToVa(_exportDirectory->AddressOfFunctions);
                _namePointerTable = (int*)mappedImage.RvaToVa(_exportDirectory->AddressOfNames);
                _ordinalTable = (short*)mappedImage.RvaToVa(_exportDirectory->AddressOfNameOrdinals);
            }
        }
Ejemplo n.º 2
0
        internal ImageExports(MappedImage mappedImage)
        {
            _mappedImage     = mappedImage;
            _dataDirectory   = mappedImage.GetDataEntry(ImageDataEntry.Export);
            _exportDirectory = mappedImage.GetExportDirectory();

            if (_exportDirectory != null)
            {
                _addressTable     = (int *)mappedImage.RvaToVa(_exportDirectory->AddressOfFunctions);
                _namePointerTable = (int *)mappedImage.RvaToVa(_exportDirectory->AddressOfNames);
                _ordinalTable     = (short *)mappedImage.RvaToVa(_exportDirectory->AddressOfNameOrdinals);
            }
        }
Ejemplo n.º 3
0
        private void *GetLoadConfig(short magic)
        {
            if (_magic != magic)
            {
                return(null);
            }

            ImageDataDirectory *dataEntry = this.GetDataEntry(ImageDataEntry.LoadConfig);

            if (dataEntry == null)
            {
                return(null);
            }

            return(this.RvaToVa(dataEntry->VirtualAddress));
        }
Ejemplo n.º 4
0
        public static unsafe IntPtr GetExportedFunctionPointerForModule(long moduleBaseAddress, string importName)
        {
            ImageNtHeaders *    imageNtHeaders            = AnalyseModuleWin((IntPtr)moduleBaseAddress);
            ImageSectionHeader *pSech                     = ImageFirstSection(imageNtHeaders);
            ImageDataDirectory *imageDirectoryEntryExport = MelonUtils.IsGame32Bit() ? &imageNtHeaders->optionalHeader32.exportTable : &imageNtHeaders->optionalHeader64.exportTable;

            ImageExportDirectory *pExportDirectory = (ImageExportDirectory *)((long)moduleBaseAddress + imageDirectoryEntryExport->virtualAddress);

            //MelonLoader.MelonLogger.Msg("pExportDirectory at " + string.Format("{0:X}", (ulong)pExportDirectory - (ulong)moduleBaseAddress));
            for (uint i = 0; i < imageDirectoryEntryExport->size / sizeof(ImageExportDirectory); ++i)
            {
                ImageExportDirectory *pExportDirectoryI = pExportDirectory + i;
                //MelonLoader.MelonLogger.Msg("pExportDirectoryI->name: " + string.Format("{0:X}", pExportDirectoryI->name));
                if (pExportDirectoryI->name != 0)
                {
                    string imagename = Marshal.PtrToStringAnsi((IntPtr)((long)moduleBaseAddress + pExportDirectoryI->name));
                    //string imagename = CppUtils.CharArrayPtrToString((IntPtr)pExportDirectoryI->name);
                    //MelonLoader.MelonLogger.Msg("imagename: " + imagename);

                    /*
                     * if (imagename != "UnityPlayer.dll")
                     *  continue;
                     */


                    long baseNameOrdinalOffset = moduleBaseAddress + (int)pExportDirectoryI->addressOfNameOrdinals;
                    long baseFunctionOffset    = moduleBaseAddress + (int)pExportDirectoryI->addressOfFunctions;
                    long baseNameOffset        = moduleBaseAddress + (int)pExportDirectoryI->addressOfNames;

                    for (int j = 0; j < pExportDirectoryI->numberOfNames; ++j)
                    {
                        ushort ordinal             = *(ushort *)((long)baseNameOrdinalOffset + j * 2);
                        long   functionnameAddress = moduleBaseAddress + *(int *)(baseNameOffset + j * 4);
                        long   functionaddress     = moduleBaseAddress + *(int *)(baseFunctionOffset + ordinal * 4);
                        string importname          = Marshal.PtrToStringAnsi((IntPtr)functionnameAddress);
                        //MelonLoader.MelonLogger.Msg($"{imagename}::{importname} @ 0x{((ulong)functionaddress - (ulong)moduleBaseAddress):X} (0x{functionaddress:X} - 0x{moduleBaseAddress:X})");
                        if (importname == importName)
                        {
                            return((IntPtr)functionaddress);
                        }
                    }
                }
            }

            return(IntPtr.Zero);
        }
Ejemplo n.º 5
0
        public ImageImportDescriptor *GetImportDirectory()
        {
            ImageDataDirectory *dataEntry = this.GetDataEntry(ImageDataEntry.Import);

            return((ImageImportDescriptor *)this.RvaToVa(dataEntry->VirtualAddress));
        }
Ejemplo n.º 6
0
        public ImageExportDirectory *GetExportDirectory()
        {
            ImageDataDirectory *dataEntry = this.GetDataEntry(ImageDataEntry.Export);

            return((ImageExportDirectory *)this.RvaToVa(dataEntry->VirtualAddress));
        }