Browsers-software / browsers

Open the right browser at the right time
https://browsers.software
Apache License 2.0
111 stars 11 forks source link

%THIS_DIR% not always set correctly. Uncaught error. #116

Closed Erquint closed 10 months ago

Erquint commented 11 months ago

Renamed the directory to Browsers!. Ran the install script in Windows 10 → Elevated Windows Terminal → PowerShell Core (pwsh)

PS E:\Programs\Utils\Browsers!> .\install.bat
Starting Installation
Because you are running this as an administrator we are going to install it to the whole system

The argument 'E:\Programs\Utils\Browsers\announce_default.ps1' to the -File parameter does not exist. Provide the path to an existing '.ps1' file as an argument to the -File parameter.
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

Browsers has been installed. Enjoy
Please report any issues at https://github.com/Browsers-software/browsers/issues
You can now press Enter to exit this installer.

The script looked for a path without ! and thus failed to execute the PS script. The error was not caught and handled. The script falsely reports success. This isn't good.

install.bat

REM .bat location with trailing \
set THIS_DIR=%~dp0
[…]
powershell -ExecutionPolicy Bypass -File "%THIS_DIR%announce_default.ps1"

Seems like %~dp0 returns the wrong path.

Erquint commented 11 months ago

While the above is an issue of its own to be resolved, I have tried recovering from it… Renamed the directory containing the installer to Browsers. Installed again. Seemed to install fine. Tried associating and launching — the association uses some nonexistent path. I'm investigating further… image An uninstaller would help but none seems to be provided.

Installed over again. image

Ran without elevation.

PS E:\Programs\Utils\Browsers> .\install.bat
Starting Installation
Because you are running this as an administrator we are going to install it to the whole system

Access is denied.
Access is denied.
Access is denied.
Access is denied.
Browsers has been installed. Enjoy
Please report any issues at https://github.com/Browsers-software/browsers/issuesYou can now press Enter to exit this installer.

you are running this as an administrator

This is ridiculous!

No matter how I install it, the executable is in Program Files but the registry entries are set to point at nonexistent AppData path. It can't properly install for the user, it can't properly install for the machine.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Classes\software.Browsers]
@="Browsers HTML Document"
"AppUserModelId"="software.Browsers"

[HKEY_CURRENT_USER\SOFTWARE\Classes\software.Browsers\Application]
"AppUserModelId"="software.Browsers"
"ApplicationIcon"="C:\\Users\\Erquint\\AppData\\Local\\Programs\\software.Browsers\\browsers.exe,0"
"ApplicationName"="Browsers"
"ApplicationDescription"="Open the right browser at the right time"
"ApplicationCompany"="Browsers.software team"

[HKEY_CURRENT_USER\SOFTWARE\Classes\software.Browsers\DefaultIcon]
@="C:\\Users\\Erquint\\AppData\\Local\\Programs\\software.Browsers\\browsers.exe,0"

[HKEY_CURRENT_USER\SOFTWARE\Classes\software.Browsers\shell]

[HKEY_CURRENT_USER\SOFTWARE\Classes\software.Browsers\shell\open]

[HKEY_CURRENT_USER\SOFTWARE\Classes\software.Browsers\shell\open\command]
@="\"C:\\Users\\Erquint\\AppData\\Local\\Programs\\software.Browsers\\browsers.exe\" \"%1\""

Changed registry paths manually. Now it launches, but creates no window and crashes.

PS C:\Program Files\software.Browsers> start "http://google.com"
PS C:\Program Files\software.Browsers>
PS C:\Program Files\software.Browsers> .\browsers.exe "http://google.com"
PS C:\Program Files\software.Browsers>
browsers

Description
Faulting Application Path: C:\Program Files\software.Browsers\browsers.exe
Creation Time: 2023-12-25 00:12:24
Problem: Stopped working
Status: Report sent

Problem signature
Problem Event Name:           APPCRASH
Application Name:             browsers.exe
Application Version:          0.4.3.0
Application Timestamp:        6537e1dc
Fault Module Name:            VCRUNTIME140.dll
Fault Module Version:         14.36.32532.0
Fault Module Timestamp:       c94bf788
Exception Code:               c0000005
Exception Offset:             000000000000148c

Extra information about the problem
Bucket ID: ec94efe0468ee53caa234651238ebc95 (1883426383473851541)

Dependency Walker finds no real issues.

WinDbg log:


************* Preparing the environment for Debugger Extensions Gallery repositories **************
   ExtensionRepository : Implicit
   UseExperimentalFeatureForNugetShare : false
   AllowNugetExeUpdate : false
   AllowNugetMSCredentialProviderInstall : false
   AllowParallelInitializationOfLocalRepositories : true

   -- Configuring repositories
      ----> Repository : LocalInstalled, Enabled: true
      ----> Repository : UserExtensions, Enabled: true

>>>>>>>>>>>>> Preparing the environment for Debugger Extensions Gallery repositories completed, duration 0.000 seconds

************* Waiting for Debugger Extensions Gallery to Initialize **************

>>>>>>>>>>>>> Waiting for Debugger Extensions Gallery to Initialize completed, duration 0.031 seconds
   ----> Repository : UserExtensions, Enabled: true, Packages count: 0
   ----> Repository : LocalInstalled, Enabled: true, Packages count: 36

Microsoft (R) Windows Debugger Version 10.0.25877.1004 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.

CommandLine: C:\Program Files\software.Browsers\browsers.exe

************* Path validation summary **************
Response                         Time (ms)     Location
Deferred                                       srv*
Symbol search path is: srv*
Executable search path is: 
ModLoad: 00007ff7`40c30000 00007ff7`4117c000   browsers.exe
ModLoad: 00007ff8`cd350000 00007ff8`cd548000   ntdll.dll
ModLoad: 00007ff8`cbaa0000 00007ff8`cbb5d000   C:\WINDOWS\System32\KERNEL32.DLL
ModLoad: 00007ff8`cad80000 00007ff8`cb076000   C:\WINDOWS\System32\KERNELBASE.dll
ModLoad: 00007ff8`cd260000 00007ff8`cd30f000   C:\WINDOWS\System32\advapi32.dll
ModLoad: 00007ff8`ccc10000 00007ff8`cccae000   C:\WINDOWS\System32\msvcrt.dll
ModLoad: 00007ff8`cccb0000 00007ff8`ccd4c000   C:\WINDOWS\System32\sechost.dll
ModLoad: 00007ff8`cb5d0000 00007ff8`cb6f6000   C:\WINDOWS\System32\RPCRT4.dll
ModLoad: 00007ff8`cc1e0000 00007ff8`cc925000   C:\WINDOWS\System32\shell32.dll
ModLoad: 00007ff8`cb280000 00007ff8`cb31d000   C:\WINDOWS\System32\msvcp_win.dll
ModLoad: 00007ff8`cac80000 00007ff8`cad80000   C:\WINDOWS\System32\ucrtbase.dll
ModLoad: 00007ff8`cb700000 00007ff8`cb89e000   C:\WINDOWS\System32\USER32.dll
ModLoad: 00007ff8`cb080000 00007ff8`cb0a2000   C:\WINDOWS\System32\win32u.dll
ModLoad: 00007ff8`cb3b0000 00007ff8`cb3dc000   C:\WINDOWS\System32\GDI32.dll
ModLoad: 00007ff8`cb0b0000 00007ff8`cb1ca000   C:\WINDOWS\System32\gdi32full.dll
ModLoad: 00007ff8`cab90000 00007ff8`cabb7000   C:\WINDOWS\System32\bcrypt.dll
ModLoad: 00007ff8`cd130000 00007ff8`cd25b000   C:\WINDOWS\System32\ole32.dll
ModLoad: 00007ff8`ccdd0000 00007ff8`cd124000   C:\WINDOWS\System32\combase.dll
ModLoad: 00007ff8`c7b80000 00007ff8`c8140000   C:\WINDOWS\SYSTEM32\d2d1.dll
ModLoad: 00007ff8`c8140000 00007ff8`c83bf000   C:\WINDOWS\SYSTEM32\dwrite.dll
ModLoad: 00007ff8`c7910000 00007ff8`c793f000   C:\WINDOWS\SYSTEM32\dwmapi.dll
ModLoad: 00007ff8`c92d0000 00007ff8`c93c3000   C:\WINDOWS\SYSTEM32\dxgi.dll
ModLoad: 00007ff8`c8fc0000 00007ff8`c9223000   C:\WINDOWS\SYSTEM32\d3d11.dll
ModLoad: 00007ff8`addf0000 00007ff8`ade0b000   C:\WINDOWS\SYSTEM32\VCRUNTIME140.dll
ModLoad: 00007ff8`ca310000 00007ff8`ca31c000   C:\WINDOWS\SYSTEM32\CRYPTBASE.DLL
(5750.6170): Break instruction exception - code 80000003 (first chance)
ntdll!LdrpDoDebuggerBreak+0x30:
00007ff8`cd420730 cc              int     3
0:000> g
ModLoad: 00007ff8`ccac0000 00007ff8`ccaf0000   C:\WINDOWS\System32\IMM32.DLL
ModLoad: 00007ff8`cb320000 00007ff8`cb3a2000   C:\WINDOWS\System32\bcryptPrimitives.dll
ModLoad: 00007ff8`c8810000 00007ff8`c8fab000   C:\WINDOWS\SYSTEM32\windows.storage.dll
ModLoad: 00007ff8`ca3a0000 00007ff8`ca3cd000   C:\WINDOWS\SYSTEM32\Wldp.dll
ModLoad: 00007ff8`cc9a0000 00007ff8`cca4d000   C:\WINDOWS\System32\SHCORE.dll
ModLoad: 00007ff8`cb3e0000 00007ff8`cb435000   C:\WINDOWS\System32\shlwapi.dll
ModLoad: 00007ff8`c7520000 00007ff8`c75be000   C:\WINDOWS\system32\uxtheme.dll
(5750.6170): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
VCRUNTIME140!memcpy+0x17c:
00007ff8`addf148c c5fe6f02        vmovdqu ymm0,ymmword ptr [rdx] ds:00000000`071c16a9=??
0:000> !analyze -v
*******************************************************************************
*                                                                             *
*                        Exception Analysis                                   *
*                                                                             *
*******************************************************************************

KEY_VALUES_STRING: 1

    Key  : AV.Fault
    Value: Read

    Key  : Analysis.CPU.mSec
    Value: 796

    Key  : Analysis.Elapsed.mSec
    Value: 1195

    Key  : Analysis.IO.Other.Mb
    Value: 0

    Key  : Analysis.IO.Read.Mb
    Value: 0

    Key  : Analysis.IO.Write.Mb
    Value: 0

    Key  : Analysis.Init.CPU.mSec
    Value: 312

    Key  : Analysis.Init.Elapsed.mSec
    Value: 8281

    Key  : Analysis.Memory.CommitPeak.Mb
    Value: 72

    Key  : Failure.Bucket
    Value: INVALID_POINTER_READ_c0000005_VCRUNTIME140.dll!memcpy

    Key  : Failure.Hash
    Value: {6cc7063a-c9e9-809b-b45d-40b8348a9d9b}

    Key  : Timeline.OS.Boot.DeltaSec
    Value: 429574

    Key  : Timeline.Process.Start.DeltaSec
    Value: 8

    Key  : WER.OS.Branch
    Value: vb_release

    Key  : WER.OS.Version
    Value: 10.0.19041.1

    Key  : WER.Process.Version
    Value: 0.4.3.0

NTGLOBALFLAG:  4070

PROCESS_BAM_CURRENT_THROTTLED: 0

PROCESS_BAM_PREVIOUS_THROTTLED: 0

APPLICATION_VERIFIER_FLAGS:  0

EXCEPTION_RECORD:  (.exr -1)
ExceptionAddress: 00007ff8addf148c (VCRUNTIME140!memcpy+0x000000000000017c)
   ExceptionCode: c0000005 (Access violation)
  ExceptionFlags: 00000000
NumberParameters: 2
   Parameter[0]: 0000000000000000
   Parameter[1]: 00000000071c16a9
Attempt to read from address 00000000071c16a9

FAULTING_THREAD:  00006170

PROCESS_NAME:  browsers.exe

READ_ADDRESS:  00000000071c16a9 

ERROR_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%p referenced memory at 0x%p. The memory could not be %s.

EXCEPTION_CODE_STR:  c0000005

EXCEPTION_PARAMETER1:  0000000000000000

EXCEPTION_PARAMETER2:  00000000071c16a9

STACK_TEXT:  
000000f9`5e95c9a8 00007ff7`40caa229     : 00000000`00000000 00000000`071c16a9 00000000`00000001 00000000`00490000 : VCRUNTIME140!memcpy+0x17c
000000f9`5e95c9b0 00007ff7`40d976a7     : 00000000`00000000 00000000`00000018 00000000`00000240 00000000`00000000 : browsers+0x7a229
000000f9`5e95d230 00007ff7`40db01b6     : 00000000`000000d0 00000000`00000000 ffffffff`fffffffe 00007ff7`41104ae9 : browsers+0x1676a7
000000f9`5e95dee0 00007ff7`40dfe0e0     : 000000f9`00000000 000000f9`5e95ed80 000000f9`5e95ed80 000000f9`5e950000 : browsers+0x1801b6
000000f9`5e95ed80 00007ff7`40e07e46     : 00000269`cf1399f0 01ffffff`fffffffe ffffffff`fffffffe 000000f9`5e95f7b0 : browsers+0x1ce0e0
000000f9`5e95f730 00007ff7`40dfa970     : 00000269`cf13f270 00000000`00000000 00000269`cf147450 00007ff8`cad80000 : browsers+0x1d7e46
000000f9`5e95f760 00007ff7`40fcbf58     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : browsers+0x1ca970
000000f9`5e95f860 00007ff8`cbab7344     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : browsers+0x39bf58
000000f9`5e95f8a0 00007ff8`cd3a26b1     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x14
000000f9`5e95f8d0 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x21

STACK_COMMAND:  ~0s ; .cxr ; kb

FAULTING_SOURCE_LINE:  D:\a\_work\1\s\src\vctools\crt\vcruntime\src\string\amd64\memcpy.asm

FAULTING_SOURCE_FILE:  D:\a\_work\1\s\src\vctools\crt\vcruntime\src\string\amd64\memcpy.asm

FAULTING_SOURCE_LINE_NUMBER:  299

FAULTING_SOURCE_CODE:  
No source found for 'D:\a\_work\1\s\src\vctools\crt\vcruntime\src\string\amd64\memcpy.asm'

SYMBOL_NAME:  VCRUNTIME140!memcpy+17c

MODULE_NAME: VCRUNTIME140

IMAGE_NAME:  VCRUNTIME140.dll

FAILURE_BUCKET_ID:  INVALID_POINTER_READ_c0000005_VCRUNTIME140.dll!memcpy

OS_VERSION:  10.0.19041.1

BUILDLAB_STR:  vb_release

OSPLATFORM_TYPE:  x64

OSNAME:  Windows 10

IMAGE_VERSION:  14.36.32532.0

FAILURE_ID_HASH:  {6cc7063a-c9e9-809b-b45d-40b8348a9d9b}

Followup:     MachineOwner
---------

It's not handled.

A complete fiasco, this whole thing..! How do I get rid of it now?

liias commented 11 months ago

Hi, Murad, I hope you are surviving the holiday season! So let's get to it.

First of all, thank you for looking so deeply into this!

Problem 1: Missing ! in path install.bat script has enabled Delayed Expansion, which is a Windows Batch Script feature to "expand" variables to values during execution time. In our case, that allows using local variables scoped to an if-block, and actually reference to that variable in that same if block. Referencing a variable via delayed expansion is done with !var-name! instead of the usual%var-name%`.

But you discovered a bug - having delayed expansion enabled also strips ! characters when expanding %~dp0 value into THIS_DIR. Because we don't actually need delayed expansion at that point, I will toggle it on only in places where it's needed.

Problem 2: Install script continues after failed step Unfortunately Windows Batch has no global flag to exit script whenever any command fails and I forgot to validate that part (as the script doesn't really do anything besides printing after that command).

Problem 3: Missing uninstaller I recently added it for linux and it makes sense to also add it for Windows. Added to backlog.

Problem 4: wrong path in Registry for system-wide install Did the developer even test this??!!?? It's broken for system-wide install and needs to be fixed.

Problem 5: script incorrectly detects that admin is running it I'm using this "hack" to detect if current is admin: https://superuser.com/questions/667607/check-if-current-command-prompt-was-launched-as-the-administrator so there can be some condition met, where it really thinks you are admin, because you can access %windir%\system32\config\systemprofile without any problems.

Problem 6: application crashes at launch Hmm, you are the 3rd person having it crashing, but you are the first one with error trace. Thank you!

I will go through all of them to fix them. But the last (and most important bug) might need more troubleshooting.

But to be honest, Windows release is least tested and lacks the most features. I might pull it off from Download section or mark it with alpha tag.

Erquint commented 10 months ago
  1. Curious.
  2. Manual guarding in control flow required as it often is.
  3. What a lot of projects without ready uninstallers do is list the deployments in the readme so that the user can remove them manually. I ended up intuiting on it but same can't be expected of all users…
  4. Without looking at the code, it might be related to the elevation detection. But there must be more to it than that.
  5. Yeah, well, that's what you get for checking a functionally irrelevant trait — not the one the execution of the script is actually going to depend on. And Linux way doesn't quite apply there. I find the whoami /groups | find "S-1-16-12288" more fitting if you wanna stay in CMD land. However, in Windows PoweShell (powershell) you could use .NET invocations to evaluate a conditional like this: if((New-Object System.Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)){"bark"}else{"meow"}. Unsure if there's any good way in PowerShell Core (pwsh).
  6. Sorry I can't help further than that with the crash. Gone and installed Hurl — turned out to suit my needs nicely.

Wish I could say I'd look into the code, but not really ready to contribute at the moment and it's been a while since I used CMD other than as a PowerShell Core launcher. It's a shame PowerShell Core adoption is so militantly rejected in Linux realm — otherwise you could perhaps realistically target it as a cross-platform shell.

liias commented 10 months ago
  1. Curious.
  2. Manual guarding in control flow required as it often is.
  3. What a lot of projects without ready uninstallers do is list the deployments in the readme so that the user can remove them manually. I ended up intuiting on it but same can't be expected of all users…
  4. Without looking at the code, it might be related to the elevation detection. But there must be more to it than that.
  5. Yeah, well, that's what you get for checking a functionally irrelevant trait — not the one the execution of the script is actually going to depend on. And Linux way doesn't quite apply there. I find the whoami /groups | find "S-1-16-12288" more fitting if you wanna stay in CMD land. However, in Windows PoweShell (powershell) you could use .NET invocations to evaluate a conditional like this: if((New-Object System.Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)){"bark"}else{"meow"}. Unsure if there's any good way in PowerShell Core (pwsh).
  6. Sorry I can't help further than that with the crash. Gone and installed Hurl — turned out to suit my needs nicely.

Wish I could say I'd look into the code, but not really ready to contribute at the moment and it's been a while since I used CMD other than as a PowerShell Core launcher. It's a shame PowerShell Core adoption is so militantly rejected in Linux realm — otherwise you could perhaps realistically target it as a cross-platform shell.

Hey there, Aspects 1-4 should be fixed in latest version. Thanks for the pointer on (5), I will take a look at it again if anyone reports an issue. The main issue (6), I haven't reproduced, but if there are enough interest in Windows, someone will stumble on it again.

And no problem, hope Hurl works out fine for you!

liias commented 10 months ago

As most of the issues should be solved, I'm closing this issue and wait for someone to create a new one if they can reproduce it.