tautcony / ISTA-Patcher

An IL patcher
GNU General Public License v3.0
17 stars 8 forks source link

Patches add 8.0.0.0 version references to IstaIcsServiceClient that is a .NETFramework v4.8 app #22

Open brandonros opened 1 month ago

brandonros commented 1 month ago
2024-05-24 11:36:10.539 ERROR [T] ISTA: [1] App.Init() - Failed to start ISTA: System.IO.FileNotFoundException: Could not load file or assembly 'System.Diagnostics.Process, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Diagnostics.Process, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at BMW.ISPI.IstaServices.Client.IstaIcsServiceClient.ValidateHost()
   at BMW.ISPI.IstaServices.Client.IstaIcsServiceClient.GetISPIProcessServicesURL()
   at BMW.Rheingold.ISTAGUI.App.InitServices()
   at BMW.Rheingold.ISTAGUI.App.Init()
   at BMW.Rheingold.ISTAGUI.App..ctor()

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

2024-05-24 11:36:10.543 ERROR [T] ISTA: [1] ServiceLocator.GetService<T>() - No service registered for type 'BMW.Rheingold.CoreFramework.Contracts.IUia'. Using default instead.
2024-05-24 11:36:10.543 WARNING [T] ISTA: [1] DialogBase.Init() - Service IUia is not available using UiaNone instead.
2024-05-24 11:36:10.543 WARNING [T] ISTA: [1] DialogBase.DialogBase() - Dialog owner BMW.Rheingold.PresentationFramework.MessageDialog could not be set, because it is invisible.
2024-05-24 11:36:10.544 INFO [T] ISTA: [1] PresentationFramework.PresentationFramework() - ctor called.
2024-05-24 11:36:10.544 INFO [T] ISTA: [1] 'method_not_set' - ISTA Activatio succeeded
2024-05-24 11:36:10.544 INFO [T] ISTA: [1] 'method_not_set' - ISTA Activation succeeded
2024-05-24 11:36:11.008 INFO [T] ISTA: [1] MainWindow.MainWindow() - Found available Keyboard input language: en-US
2024-05-24 11:36:15.519 ERROR [T] ISTA: [1] InteractionController.DeregisterInteraction - failed with exception: System.ArgumentNullException: Value cannot be null.
Parameter name: model
   at BMW.Rheingold.CoreFramework.Interaction.InteractionController.DeregisterInteraction(InteractionModel model)
2024-05-24 11:36:15.536 ERROR [T] ISTA: [1] InteractionController.DeregisterInteraction - failed with exception: System.ArgumentNullException: Value cannot be null.
Parameter name: model
   at BMW.Rheingold.CoreFramework.Interaction.InteractionController.DeregisterInteraction(InteractionModel model)
brandonros commented 1 month ago

Copied a bunch of DLLs from C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App\8.0.0\ to C:\Program Files (x86)\BMW\ISTA\TesterGUI\bin\Release

2024-05-24 12:02:21.782 ERROR [T] ISTA: [1] App.Init() - Failed to start ISTA: System.TypeLoadException: Could not load type 'System.Object' from assembly 'System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' because the parent does not exist.
   at BMW.ISPI.IstaServices.Client.IstaIcsServiceClient.ValidateHost()
   at BMW.ISPI.IstaServices.Client.IstaIcsServiceClient.GetMarketLanguage()
   at BMW.Rheingold.RheingoldSessionController.Logic.ResetLang()
   at BMW.Rheingold.RheingoldSessionController.Logic.InitProgrammingSessionData()
   at BMW.Rheingold.RheingoldSessionController.Logic..ctor(IDatabaseProvider database, IFasta2Service fasta2)
   at BMW.Rheingold.ISTAGUI.Controller.MultisessionLogic..ctor(Dispatcher dispatcher, String istaOperationProcessDir, INavigationServiceGui navigationService, IDatabaseProvider database, IPrintWatchDog printWatchDog, Dictionary`2 configuration)
   at BMW.Rheingold.ISTAGUI.App.InitMultiSessionLogic()
   at BMW.Rheingold.ISTAGUI.App.Init()
   at BMW.Rheingold.ISTAGUI.App..ctor()
brandonros commented 1 month ago

Are we like mixing and matching netframework48, net8.0, netcoreapp8.0 DLLs? We're introducing System.Diagnostics.Process (and others) dependency/references with the patches but not providing the DLL (or its dependencies) to the directory its loading assemblies from.

https://github.com/tautcony/ISTA-Patcher/blob/bc182502dff54e6f2cbf6b36a9894615485462c6/ISTA-Patcher/Core/PatchUtils.cs#L172

ISTAGUI is a .NETFramework v4.8 app

image

From ILSpy:

// Detected TargetFramework-Id: .NETFramework,Version=v4.8
// Detected RuntimePack: Microsoft.NETCore.App

// Referenced assemblies (in metadata order):
// IstaServicesContract, Version=4.47.18.27933, Culture=neutral, PublicKeyToken=6505efbdc3e5f324
    // Assembly reference loading information:
    // Info: Success - Found in Assembly List

// mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    // Assembly reference loading information:
    // Info: Success - Found in Assembly List

// RheingoldProcessCommunicationBase, Version=4.47.18.27933, Culture=neutral, PublicKeyToken=6505efbdc3e5f324
    // Assembly reference loading information:
    // Info: Success - Found in Assembly List

// System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    // Assembly reference loading information:
    // Info: Success - Found in Assembly List

// System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    // Assembly reference loading information:
    // Info: Success - Found in Assembly List

// System.Diagnostics.Process, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
    // Assembly reference loading information:
    // There were some problems during assembly reference load, see below for more information!
    // Error: Could not find reference: System.Diagnostics.Process, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

// System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
    // Assembly reference loading information:
    // Info: Success - Found in Assembly List with different TFM or version: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.5\System.Private.CoreLib.dll

// System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    // Assembly reference loading information:
    // Info: Success - Found in Assembly List

// Assembly load log including transitive references:
// IstaServicesContract, Version=4.47.18.27933, Culture=neutral, PublicKeyToken=6505efbdc3e5f324
    // Info: Success - Found in Assembly List

// mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    // Info: Success - Found in Assembly List

// System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    // Info: Success - Found in Assembly List

// RheingoldProcessCommunicationBase, Version=4.47.18.27933, Culture=neutral, PublicKeyToken=6505efbdc3e5f324
    // Info: Success - Found in Assembly List

// System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    // Info: Success - Found in Assembly List

// System.Diagnostics.Process, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
    // Error: Could not find reference: System.Diagnostics.Process, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

// System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    // Info: Success - Found in Assembly List

// System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
    // Info: Success - Found in Assembly List with different TFM or version: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.5\System.Private.CoreLib.dll

// System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    // Info: Success - Found in Assembly List

// System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    // Info: Success - Found in Assembly List
brandonros commented 1 month ago

Got around it with this:

using System;
using dnlib.DotNet;

class Program
{
    static void Main(string[] args)
    {
        string assemblyPath = @"IstaServicesClient.dll";

        ModuleDefMD module = ModuleDefMD.Load(assemblyPath);

        AssemblyRef ref1 = null;
        foreach (var assemblyRef in module.GetAssemblyRefs())
        {
            if (assemblyRef.Name == "System.Diagnostics.Process")
            {
                assemblyRef.Version = new Version(4, 0, 0, 0);
                Console.WriteLine("Reference version changed to 4.0.0.0");
            }

            if (assemblyRef.Name == "mscorlib")
            {
                ref1 = assemblyRef;
            }
        }

        foreach (var assemblyRef in module.GetAssemblyRefs())
        {
            if (assemblyRef.Name == "System.Private.CoreLib")
            {
                assemblyRef.Name = ref1.Name;
                assemblyRef.Version = ref1.Version;
                assemblyRef.PublicKeyOrToken = ref1.PublicKeyOrToken;
            }
        }

        // Save the modified assembly
        string outputPath = @"IstaServicesClient-patched.dll";
        module.Write(outputPath);

        Console.WriteLine("Assembly saved to " + outputPath);
    }
}

New error:

2024-05-24 13:44:07.620 ERROR [T] Thread-ID: [9] Caller-PID: [5328] IstaServiceOperationInvoker.Invoke - failed with exception: BMW.iLean.CommonServices.Exceptions.CommonServiceException: 0A_ICS0133: CommonserviceException, see inner exception for more details ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at BMW.iLean.CommonServices.Helper.ObjectToStringHelper.ObjectToByteArray(Object dataToSerialize)
   at BMW.iLean.CommonServices.Helper.ObjectToStringHelper.ObjectToString(Object dataToSerialize)
   at BMW.iLean.CommonServices.Models.LocationBasedParameterList.GetLocationBasedParameter(String countryCode, String environment, String nameSpace, String name)
   at BMW.iLean.CommonServices.Services.BDRCommonServices.GetLocationBasedParameterValue(String nameSpace, String parameterName, InterfaceVersion interfaceVersion)
   at BMW.iLean.CommonServices.Services.BDRCommonServices.GetLocationBasedParameterValue(String nameSpace, String parameterName)
   --- End of inner exception stack trace ---
   at BMW.iLean.CommonServices.Services.BDRCommonServices.GetLocationBasedParameterValue(String nameSpace, String parameterName)
   at BMW.Rheingold.RheingoldISPINext.ICS.CommonServiceWrapper.GetSecureFeatureActivationUrl()
   at BMW.Rheingold.RheingoldISPINext.ICS.CommonServiceWrapper.GetLocationBasedParameters()
   at BMW.ISPI.IstaServices.Impl.ICS.IstaIcsServiceImpl.GetLocationBasedParameters()
   at SyncInvokeGetLocationBasedParameters(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at BMW.ISPI.IstaServices.Impl.IstaServiceOperationInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
tautcony commented 1 month ago

Previously I'd use the BuildCall to build a new function which would introduce 8.0 assemblies and is undesirable, current implementation is to find and reuse the function reference in the ISTA program itself.

So why this happened again need some test and inspection, by the way which version of ista-patcher you had used.