从二进制文件中确定源语言? [英] Determine source language from a binary?

查看:14
本文介绍了从二进制文件中确定源语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

回复了 另一个关于使用非 Objective-C 语言为 iPhone 开发的问题,我断言使用 C# 为 iPhone 编写会令 Apple 审稿人犯错.我主要是在谈论所讨论的 ObjC 和 C# 库之间的 UI 元素不同,但一位评论者提出了一个有趣的观点,让我想到了这个问题:

I responded to another question about developing for the iPhone in non-Objective-C languages, and I made the assertion that using, say, C# to write for the iPhone would strike an Apple reviewer wrong. I was speaking largely about UI elements differing between the ObjC and C# libraries in question, but a commenter made an interesting point, leading me to this question:

是否有可能仅从其二进制文件中确定程序的编写语言?如果有这样的方法,它们是什么?

Is it possible to determine the language a program is written in, solely from its binary? If there are such methods, what are they?

让我们假设问题的目的:

Let's assume for the purposes of the question:

  • 从交互的角度(控制台行为、任何 GUI 外观等)来看,两者是相同的.
  • 这种性能并不是语言的可靠指标(没有比较,比如 Java 和 C).
  • 您和语言之间没有解释器或其他东西 - 只是原始可执行二进制文件.

如果您与语言无关,则可以加分.

Bonus points if you're language-agnostic as possible.

推荐答案

我不是编译器黑客(我希望有朝一日),但我认为您可能能够在二进制文件中找到可以指示的迹象生成它的编译器以及使用的一些编译器选项,例如指定的优化级别.

I'm not a compiler hacker (someday, I hope), but I figure that you may be able to find telltale signs in a binary file that would indicate what compiler generated it and some of the compiler options used, such as the level of optimization specified.

但是,严格来说,您要问的是不可能的.可能有人拿着笔和纸坐下来,计算出与他们想要编写的程序相对应的二进制代码,然后在十六进制编辑器中输入这些内容.基本上,他们会在没有汇编工具的情况下进行汇编编程.同样,您可能永远无法确定本机二进制文件是用直接汇编程序编写的,还是用 C 语言和内联汇编编写的.

Strictly speaking, however, what you're asking is impossible. It could be that somebody sat down with a pen and paper and worked out the binary codes corresponding to the program that they wanted to write, and then typed that stuff out in a hex editor. Basically, they'd be programming in assembly without the assembler tool. Similarly, you may never be able to tell with certainty whether a native binary was written in straight assembler or in C with inline assembly.

对于 JVM 和 .NET 等虚拟机环境,您应该能够通过二进制可执行文件中的字节码识别 VM,我希望.但是,您可能无法分辨源语言是什么,例如 C# 与 Visual Basic,除非有特定的编译器怪癖提示您.

As for virtual machine environments such as JVM and .NET, you should be able to identify the VM by the byte codes in the binary executable, I would expect. However you may not be able to tell what the source language was, such as C# versus Visual Basic, unless there are particular compiler quirks that tip you off.

这篇关于从二进制文件中确定源语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆