3 ms·
And it's even funnier that the solution the author gives is "hey execute this javascript code that uninstalls a program and deletes itself afterwards" like, re
by xinayder 3y ago
And it's even funnier that the solution the author gives is "hey execute this javascript code that uninstalls a program and deletes itself afterwards"
like, really? can't you write that in C? I don't think most Win32 apps use JavaScript for their installers.
- deleted 3y ago[deleted]
- mananaysiempre 3y ago> can't you write [a self-deleting executable] in C? The point of the exercise is that, on Windows, you can’t, because Windows won’t let anyone delete executables that are currently in use (try it, you won’t be able to delete one either). Upgrading shared DLLs in the face of this fact is why installers for Windows programs often have to have you reboot the system (and in more civilized times asked you to close other programs before installation to reduce the probability of hitting a locked DLL). It’s also why there’s a registry key[1] containing a list of rename and delete actions to be performed on next reboot (usually accessed via the MOVEFILE_DELAY_UNTIL_REBOOT flag to MoveFileEx). You can’t (straightforwardly[2]) make a self-deleting batch script, either, because the command interpreter parses a command at a time and so wants the batch file to exist. The Windows Scripting Host, on the other hand, will parse the whole file at once, close it, and then forget about it, so you can write self-deleting WSH scripts. The workaround used by the uninstaller under discussion is instead for the executable to inject some code into the Windows Explorer (on the assumption that it’s always running and the user has to have access permissions for it) that accomplishes the deletion through return-oriented programming, so that the stack it’s executing from can then disappear into the wind (apparently? I’m not seeing how they plan to clean that up). On a POSIX system you are explicitly allowed to delete any open file—including an executing one—making it languish in a kind of system-managed limbo (and take up disk space, invisibly) until it’s closed. The tradeoff is then that it’s impossible to ensure you’ve opened the same file as somebody else when all you have is its name. (I think you can at least check for success, provided you also have the device and inode numbers for it.) [1] https://superuser.com/questions/58479/is-there-a-registry-key-to-tell-windows-to-delete-a-file-at-next-startup/58481 https://superuser.com/questions/58479/is-there-a-registry-ke... [2] https://stackoverflow.com/questions/20329355/how-to-make-a-batch-file-delete-itself/20333575 https://stackoverflow.com/questions/20329355/how-to-make-a-b...
- dolmen 3y agoI wonder why Raymond Chen suggest a WSH solution. Isn't PowerShell the official scripting language for Windows nowadays?
- mike_hearn 3y agoPowerShell has weird restrictions where it'll refuse to run scripts unless they're signed and stuff.
- rk06 3y agoIf the sysadmin chooses to, otherwise PowerShell can be run arbitrarily
- pie_flavor 3y agoThe key is that unsigned scripts are opt-in, not opt-out. Chen is not going to suggest a solution that requires all users of the software to configure their computer to be less secure.
- ChrisSD 3y agoIt's not really a security measure in that sense. It's a "safety feature" that prevents accidentally running such a script. Anything can trivially disable the protection using a bat script (or anything else) to bootstrap. E.g. `powershell.exe -ExecutionPolicy Unrestricted`