问题描述
我见过类似的问题(或者看起来如此),例如
How do I compile C++ to JavaScript in a browser?
Executing Javascript Code From Objective C
Library to write javascript code
What language is JavaScript written in?
Is there any way to compile code ( C/ C++ ) with in browser?
Is there a way to use C++ in JavaScript?
Possible to write a Compiler with Javascript?
[最相关] Is there such a thing as a javascript compiler?
How can I write a JavaScript compiler for Arduino or similar microcontroller?
但是其中一些谈论相反的情况。
基本上,我的意思是获取C ++代码,将其转换为程序集(NTO WebAssembly)[或像Microsoft一样跳过此步骤],生成机器代码,然后将该机器代码的字节放入某些可执行文件中。种类(unix可执行文件或Windows可执行文件),就像实际的编译器一样。
我意识到这意味着不同的处理器和架构会有差异,因为它将直接编写机器代码,但是JavaScript能够使用mimeType application/octet-stream
编写纯字节和应用程序并将其下载到像
var a =document.createElement("a");
a.href = URL.createObjectURL(
new Blob([
(bytes => {
var headers = "some header bytes";
for(var i = headers.length; i < bytes.length; i++) {
bytes[i] = Math.floor(
Math.random() * 256 //represents machine code
//and other file headers etc
)
}
headers.split("").forEach((h,i) => {
bytes[i] = h.charCodeAt(h)
})
return bytes
})(new Uint8Array(500))
],{
type: "application/octet-stream" //not really
//necessary for HTML but for executables it might be
})
)
a.download = "BoruchHashem.html"//or.exe,but this is just testing
a.click()
[就像在https://stackoverflow.com/questions/23451726/saving-binary-data-as-file-using-javascript-from-a-browser中一样]
如果仅知道他们要编译的处理器的体系结构,[和必要的操作码] [1],以及他们要运行的特定类型的可执行文件的文件格式规范( [例如Windows的exe] [2]),它们应该能够使用JavaScript(https://stackoverflow.com/questions/13171616/c-parser-in- javascript),然后生成必要的操作码和机器语言字节,并将其放在.exe文件的必要部分中,然后将所有字节放入blob并将其下载给用户(显然,如果公共网站,任何人都可以在其中插入恶意软件等,但这是另一个问题)
问题是是否有任何相关文档,或者有任何现成的C ++ JavaScript编译器可供使用?谷歌搜索无法在github上找到任何东西 [1]:http://ref.x86asm.net/coder32.html [2]:https://blog.kowalczyk.info/articles/pefileformat.html [3]:https://github.com/ajaxorg/treehugger
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)