News for hackers. Stuff that matters.
Re:Embedding an EXE inside a .REG file with automatic execution by saagarjha on Thursday July 28, 2022 @05:24PM (#32270305)
> People should learn some windows behaviors are not normal. Your computer shouldn't get slower over time, installing software from untrusted sources is not normal, an extension is part of the name of a file and it should not be hidden, using the computer as administrator should be reserved for administrator tasks only, your desktop area is not /tmp/, drivers belong to the kernel and devices should work as soon as they are plugged in, the command line is not a thing of the past...

Playing devil’s advocate, the Unix/Linux model of things doesn’t have to be “normal” either. Why should file extensions be a thing? Why shouldn’t people use their desktop as they please? Why put drivers in the kernel?

Re:Embedding an EXE inside a .REG file with automatic execution by marcodiego on Thursday July 28, 2022 @05:38PM (#32270409)
> Why should file extensions be a thing?

Because they are part of the name of the file. Note: my file manager even identifies the mime type without extension. That is how it should be, changing the extension should not make the file harder to use. To this day, AFAIK, windows file manager still uses the extension to identify file type, thus allowing the user to easily change it may break expectation. GNOME's nautilus, KDE's Dolphin and even Apple's finder do it right: press f2 and you can rename the file without changing the extension, unless you go out of you way for that.

It is also a security breach: image.jpg and image.exe may look the same.

> Why shouldn’t people use their desktop as they please?

Sure they should! But the fact that the OS lacks a working /tmp incentivizes a form of use that is disorganized and ugly.

> Why put drivers in the kernel?

Read about complaints about wacom tablet driver phoning home or printers drivers doing the same. To use my wacom tablet I simply plugged it. Since it is on the kernel, it will work on any architecture the kernel support. They didn't spent a dime to make it working on my raspi, for example. Also, once it is in the kernel, whoever change any internal api will fix every driver code to keep it working, so things that work once will work for a very long time. I met people who lost a TCE scanner and an ASUS mini projector because it wasn't supported by the most recent windows versions. The ASUS mini projector (disclaimer: I had a little involvement in the development of its driver) works on my rockpi4 just by plugging it; the windows experience with it is far from that simple.

Re:Embedding an EXE inside a .REG file with automatic execution by mike_hock on Thursday July 28, 2022 @07:54PM (#32271493)
> Note: my file manager even identifies the mime type without extension. That is how it should be

No, probing around the file content with a gazillion format-specific heuristics/hacks is not how it should be.

This is a security problem because it makes the probing code a giant attack surface, and there have been CVEs related to precisely that.

The file type should be determined from metadata only (simple, regular and without format-specific idiosyncrasies). Whether that metadata should be a suffix on the filename that's easy to mess up inadvertently is debatable, but Windows has the right idea here.

Re:Embedding an EXE inside a .REG file with automatic execution by 8organicbits on Friday July 29, 2022 @04:24AM (#32274385)
The .zip file and .xlsx/.docx is a good example of the complexity. It's popular to build certain application files (word docs, excel spreadsheets) that are zip files on the outside. Something with the first bytes 0x50 0x4d 0x03 0x04 (iirc) could be a zip file that the user wants to unzip or an application file that the user wants to open with an application. You need to probe deeper to guess which it is, or rely on the file extension.
Re:Embedding an EXE inside a .REG file with automatic execution by marcodiego on Friday July 29, 2022 @11:04AM (#32277863)
> No, probing around the file content with a gazillion format-specific heuristics/hacks is not how it should be.

My favorite file browsers do it wonderfully. I don't even care when using network because performance is good enough and updates are done async.

Re:Embedding an EXE inside a .REG file with automatic execution by elxx on Thursday July 28, 2022 @06:37PM (#32270894)
> GNOME's nautilus, KDE's Dolphin and even Apple's finder do it right: press f2 and you can rename the file without changing the extension, unless you go out of you way for that.

This is exactly how Windows Explorer works by default too.

Re:Embedding an EXE inside a .REG file with automatic execution by ziml77 on Friday July 29, 2022 @03:27PM (#32280847)
They introduced that feature a very long time ago too. I remember when they made the change because it made renaming files while having extensions visible was so much nicer. Hitting Ctrl-A to select everything in those cases where you do actually want to alter the extension is far easier than adjusting the selection to not include the extension for the common case where you don't want to change the extension.
Re:Embedding an EXE inside a .REG file with automatic execution by archi42 on Friday July 29, 2022 @03:36AM (#32274098)
IIRC that wasn't always the case. Maybe GP simply didn't use Windows since a long time.

But you're right, and I wanted to drop the same hint. As much as I dislike the OS, I have to admit they made some improvements.

Re:Embedding an EXE inside a .REG file with automatic execution by marcodiego on Friday July 29, 2022 @11:04AM (#32277870)
So this changed recently. Didn't know that.
Re:Embedding an EXE inside a .REG file with automatic execution by dlainhart on Friday July 29, 2022 @04:19AM (#32274348)
> Note: my file manager even identifies the mime type without extension. That is how it should be, changing the extension should not make the file harder to use. To this day, AFAIK, windows file manager still uses the extension to identify file type, thus allowing the user to easily change it may break expectation. GNOME's nautilus, KDE's Dolphin and even Apple's finder do it right: press f2 and you can rename the file without changing the extension, unless you go out of you way for that.

You've just confounded two different concerns: filetype identification by file managers and the interface to rename files. If you're not just cribbing some bad Intro to UX course, you'd know that Windows Explorer has always gone out of its way to howl bloody murder when you accidentally changed the file extension, and since Windows XP most rename file controls preserve the file extension. Your thinking was very sloppy here.

Identifying files by heuristics is a VERY dangerous game. Different systems have implemented it differently over the years, classic Mac OS in particular offering a fascinating alternative to file extensions.

> Also, once it is in the kernel, whoever change any internal api will fix every driver code to keep it working, so things that work once will work for a very long time.

Sometimes. Not always. Don't blindly worship code you haven't read.

Re:Embedding an EXE inside a .REG file with automatic execution by GekkePrutser on Thursday July 28, 2022 @06:33PM (#32270865)
File extensions aren't really a thing in the UNIX world. Executables and scripts work just fine whatever extension they have, if any. The shell will call the 'file' command to figure out what it is.

Some apps do care about extensions but this is not really an OS thing. And some files have to have specific names but that's really a thing in any OS.

Re:Embedding an EXE inside a .REG file with automatic execution by LtWorf on Thursday July 28, 2022 @07:27PM (#32271298)
The shell will NOT call the file command unless you type "file" and hit enter.

Executables are executed by the kernel. They have the x bit set and a header that the kernel reads to decide what to do with them.

Re:Embedding an EXE inside a .REG file with automatic execution by GekkePrutser on Friday July 29, 2022 @01:02AM (#32273325)
I agree that I've simplified things a bit, 'file' is rather the user facing tool that does the same kind of inspection, and of course the X bit is a prerequisite. I know this but I didn't want to write a whole elaboration on my phone :)

But my main point was that extensions aren't really a thing used at OS level to determine file type like on Windows, like the OP said.

Re:Embedding an EXE inside a .REG file with automatic execution by IX-103 on Thursday July 28, 2022 @08:19PM (#32271639)
Actually the header is read by the shell so it can call the appropriate loader. That may include running the file tool (or an internal equivalent that uses "database" of magic files).
Re:Embedding an EXE inside a .REG file with automatic execution by slabity on Thursday July 28, 2022 @09:06PM (#32271951)
That's completely incorrect. Where did you get that information from?

A regular POSIX shell will simply call the `exec` syscall on the path provided. It may set up some environment variables or parse some arguments, but it will not actually read the file. In fact you can have a file with executable permissions, but not read permissions.

The kernel determines how to execute the file based on its Magic Numbers, which are the first few bytes in certain file formats that will specify what type of file it is. It just so happens that the one for scripts are `#!`.

Re:Embedding an EXE inside a .REG file with automatic execution by matheusmoreira on Thursday July 28, 2022 @10:06PM (#32272374)
> Why should file extensions be a thing?

They're not that important on Linux. Making files without extensions is simple and common.

Honestly, file extensions are an annoying GUI thing. In the command line you pass the file as parameter to a program, the extension doesn't matter. Simply clicking on a file provides no information to the operating system about what program to invoke though, there needs to be additional metadata. So graphical environments created this notion of file associations based on extensions to the file name.

Re:Embedding an EXE inside a .REG file with automatic execution by robertlagrant on Thursday July 28, 2022 @07:15PM (#32271199)
> Why should file extensions be a thing?

The problem is Windows does different things with files based on their extension, and hides their extension by default. Linux does neither.

Re:Embedding an EXE inside a .REG file with automatic execution by 323 on Thursday July 28, 2022 @07:23PM (#32271265)
What happens when you double click a .png file on Linux? It's exactly like Windows, it reads the extension and finds the associated app.

I know you meant +x, but that is limited to only some files.

Re:Embedding an EXE inside a .REG file with automatic execution by robertlagrant on Monday August 01, 2022 @06:29AM (#32304080)
Yes, you're right. Sloppy writing by me. Thanks for the cleanup!