0

So I have a UWP app which also opens and runs a console application as a Full Trust Process. The console application runs for a couple of seconds and then exits with the code 0xe0434352, which can mean basically anything.

Debugging in VS is impossible as I can't attach the debugger to my console app quickly enough before it exits, however a quick look in the Windows Event Viewer tells me the following:

Application: Nayax.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.UnauthorizedAccessException at System.IO.__Error.WinIOError(Int32, System.String) at System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean, Boolean) at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, Int32, System.IO.FileOptions, System.String, Boolean, Boolean, Boolean) at System.IO.StreamWriter.CreateFile(System.String, Boolean, Boolean) at System.IO.StreamWriter..ctor(System.String, Boolean, System.Text.Encoding, Int32, Boolean) at System.IO.StreamWriter..ctor(System.String, Boolean) at System.IO.File.AppendText(System.String) at com.bitmick.marshall.protocol.vmc_framework.init() at com.bitmick.marshall.protocol.vmc_framework.getInstance() at Win32.Program+vend_machine..ctor() at Win32.Program.Main(System.String[])

Now, when I run the console app directly, it works fine without any exceptions. Meaning that the errors must be related to my UWP app.

My question is: What does Full Trust actually mean? The errors I am getting look like permission errors which shouldn't be occurring in a Full Trust process, surely?

Full Trust Declaration

<Extensions xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10">
    <desktop:Extension Category="windows.fullTrustProcess" Executable="Nayax\Nayax.exe" />
</Extensions>

Running the Full Trust Process

if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0))
{
      try
      {
         await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
      }

      catch (Exception Ex)
      {
          Debug.WriteLine(Ex.ToString());
      }
}
Adam McMahon
  • 765
  • 3
  • 24
  • maybe some like this can help you attach a debugger: `while (!Debugger.IsAttached) { Thread.Sleep(500); } Debugger.Break();`. I've only used this in wpf. – fstam Jan 30 '20 at 12:35
  • Thanks for the suggestion. This has no effect at all. The Win32 app terminates immediately after firing. I'm at a loss as to why – Adam McMahon Jan 30 '20 at 14:16
  • I'm unfamiliar with both UWP and FullTrustProcess so I'm taking a shot in the dark here. Can you successfully break in the UWP application with a debugger? Is this FullTrustProcess the same thing as a `Process` with a path to an application? If yes, can you run said process in a command line so that you can see it's output or read the output of the process object? Something like this: https://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output – fstam Jan 30 '20 at 14:44
  • No, unfortunately not. UWP is sandboxed and the only thing I can do is give it a single .exe to run in FullTrust (which effectively should be full permissions as you would expect). I can run the .exe from my desktop perfectly, I can compile and debug the .exe seprately and that works perfectly too. However, when it is run from the UWP package, it terminates before it does anything. The only way I could find to debug is via the Windoes Event Viewer, which gave me the output above. However, these are permissions exceptions and I can't understand why – Adam McMahon Jan 30 '20 at 14:52
  • I can find this: ` ` online allong with enabling the extensions. Did you add this capability? See: https://learn.microsoft.com/en-us/uwp/api/windows.applicationmodel.fulltrustprocesslauncher – fstam Jan 30 '20 at 14:56
  • Yes. And I've been able to add other win32 apps successfully in the past (albeit much simpler ones) – Adam McMahon Jan 30 '20 at 14:59
  • 1
    I'm want to dig deeper but I'll need reproduction. Can you provide a repository with repro for me? – fstam Jan 30 '20 at 15:00
  • Yes, but I'm not in the office now so it will be tomorrow. I will share when back in the office. – Adam McMahon Jan 30 '20 at 15:27
  • @fstam - Repro here > https://www.dropbox.com/s/35q5pkuvj6hjxs9/Win32%20Permissions.zip?dl=0 – Adam McMahon Jan 31 '20 at 11:58
  • 1
    Without the code to the library you're using, it's hard to say. Maybe it is trying to write to your install location, etc. Can you use something like SysInternals ProcMon to check all activity and see which file is failing? – Peter Torr - MSFT Feb 01 '20 at 06:06
  • Okay, so after digging a little deeper, the file failing is Windows/System32/log.txt - This file doesn't exist and is never created when I run the Win32 app outside of UWP. However, the library does create a log file for debug purposes and it will likely be placed in the install dir by default so I will look into that – Adam McMahon Feb 03 '20 at 09:12
  • Okay, so you are correct, the log.txt file is being placed at the install dir. However, I don't have access to the code for the library which is creating it. Is there any way I can stop the library from creating the file? Or at least stop the app from crashing when it is trying to do so? The file is just a log and isn't relied upon by the app in any way. – Adam McMahon Feb 03 '20 at 09:44

0 Answers0