浏览器查看源代码:文件可以“下载”吗?这边走?

发布于 2025-01-11 14:06:58 字数 574 浏览 0 评论 0原文

您可能知道,可以通过在浏览器中添加 view-source: 前缀来查看任何网站 URL 的原始响应 HTML 代码(例如 view-source:https://www. google.de/)。

有趣的是,这也适用于指向 HTML 以外类型的文件的 URL。例如,view-source:https://d3.7-zip.org/a/7z2107.exe 会将 .exe 文件(此处为 7zip)显示为字节流(可能解释为 latin1或其他编码)。如果您正常下载 .exe 文件,然后在记事本中打开它,您会得到类似结果。

我的问题是这样的:当我手动复制代码 view-source: 给我一个 .exe 文件,将其粘贴到记事本中,然后将其另存为 .exe 时,该文件是大小大致正确但已损坏。有什么办法可以解决这个问题吗?

(如果你想知道为什么有人会想要这样做,公认的奇特情况是使用 Selenium 进行浏览器自动化,对于一个资源来说,它实际上无法正常下载文件以这样的方式受到保护,实际上只能由真正的浏览器下载。)

As you probably know, one can view the original response HTML code for any website URL by prefixing it with view-source: in the browser (e.g. view-source:https://www.google.de/).

Now interestingly, this also works for URLs that lead to files with types other than HTML. For instance, view-source:https://d3.7-zip.org/a/7z2107.exe will show the .exe file (here of 7zip) as byte stream (probably interpreted as latin1 or another encoding). You would get a similar result if you downloaded the .exe file normally and then open it in Notepad.

My question is this: When I just manually copy the code view-source: gives me for a .exe file, paste it in Notepad and then save it as .exe, the file is of roughly correct size but corrupted. Can there anything be done to fix this?

(If you wonder why anyone would want to do this, the admittedly exotic case is browser automatization with Selenium, which is not really able to download files normally, for a resource that is protected in such a way that it practically can only be downloaded by real browsers.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分分钟 2025-01-18 14:06:58

编译应用程序时,会对可执行文件的各个部分进行静态引用,以字节为单位计算偏移量。这些可以像可执行文件的 .text 和 .data 部分一样广泛,也可以像函数调用地址和跳转一样更底层。

如果你在真正的反汇编器中打开一个exe,你会看到有以字节为单位的硬编码跳转、以字节为单位的函数地址等。当你在文本编辑器中打开exe时,这些跳转使处理器开始运行随机代码,这会导致一个例外。这会导致 Windows 认为它​​不再是有效的可执行文件。

When an application is compiled, there are static references to parts of the executable, calculated as offset in bytes. These can be as broad as the .text and .data sections of the executable, or more low-level like function call addresses and jumps.

If you open an exe in a real disassembler, you'll see that there are hard coded jumps in bytes, function addresses in bytes, etc. When you open exe in text editor, these jumps make the processor start running random code, which causes an exception. That causes Windows to believe its not a valid executable anymore.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文