Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
JSLinux rewritten to be human readable, deobfuscated and annotated (github.com/levskaya)
160 points by luu on March 19, 2013 | hide | past | favorite | 31 comments


Did the person doing this get his permission? Seems unclear from the readme.

The readable source code of the JS PC emulator itself is not yet available. At this point, any mirroring or redistribution of the code needs my explicit permission

http://bellard.org/jslinux/faq.html


The author here. There is a difference in spirit between publicly accessible and published. I did this in a burst of mania over a few days more than a year ago and only pushed it to github as an afterthought. I never really expected more that one or two people would look at it. I am very surprised to see it here. Given that the hivemind has discovered it, I'll happily contact Mr. Bellard to see if he wants it out in the world or not.

I'm a synthetic biologist, not a professional coder. I did this primarily because I wanted to study how emulation worked, and I pushed it solely in the hopes that one or two other people might find it useful as a study guide of the original codebase.


Agreed that he should have gotten permission before publicly hosting this, but looking through some of what he's done, I'm pretty impressed with what I've seen so far. He's clearly doing this to learn, and some of the comments in the source code I read through reflect this as well. I always loved showing people JSLinux, they'd flip out at how it was a joke or not real or something...

Then I'd do a "Hello, world!" type example in C and their eyes would open wide, knowing that I just compiled and ran an x86 program under a Javascript emulator in my browser.


Definitely the first thing that came to my mind. I don't like that he is not respecting the original author's license. We're all used to opensource and freedom to redistribute here, but when someone licenses something a different way, we should still respect it.

Bellard is a reasonable man. I asked him for permission to release my web terminal (https://github.com/chjj/tty.js), (which was originally based on his jslinux terminal), under the MIT license, and he did give me permission. All it takes is the courtesy to ask and to state your intentions with it. Hopefully thats what the poster did here, but it does seem unclear.


For anybody who wants to study another, freely available, take on this (made by an HN member):

http://www.ubercomp.com/jslm32/src/

https://github.com/ubercomp/jslm32

There's also a nice Quora answer (I don't like linking to them but what the hell) to get the ball rolling on the basics: http://www.quora.com/Emulators-computing/How-does-bellard-or...


You're probably right, but it's been up over a year now that I can see, the code commits are from Dec 2011:

https://github.com/levskaya/jslinux-deobfuscated/commits/mas...

So by now it's likely that Fabrice Bellard is aware of it


When I did a little project using jslinux, just for fun on the Chaos Communication Camp 2011, I contacted Fabrice about it. And he was helpful and gave permission to do with the code what I planned to do (I wrote a network hardware emulation, the corresponding Linux driver and a central server, so I could connect to the remotely running Linux instances in peoples' browsers).

It's allowed to discuss Fabrice's code, it's allowed to post a de-obfuscator software tool, but it's certainly not permitted to publicize a derivate without his consent. It's plain respect for intellectual property.


Fabrice Bellard is smart enough that he can probably work directly with obfuscated code without it having to go through a separate translation process. The "obfuscated" source could in fact be the original :)


While this may seem like a joke when referring to this size of code, some people actually write this way:

http://nsl.com/papers/origins.htm

(Arthur Whitney's initial implementation of "J")


That is not "obfuscated", but rather J-style.

The rationale is: To write a J interpreter/compiler you need to know J. If you know J, then J-style C is easy to work with.


The example I use is: is it easier to read "a + b", or "a plus b"? In many cases, what looks like obfuscation is just shorthand notation.


The appropriate counterexample here is which is easier to read, "a plus b" or "aplusb"? :)


Could that be a byproduct of doing much assembly?


Fabrice is a 2 time winner of the IOCCC http://www.ioccc.org/winners.html#B.


Questioning the wisdom of saying this on the public internet, but the first line of the first file has caught me up.

What is the purpose of this function, from the clock emulator:

  function formatter(a) { return ((a / 10) << 4) | (a % 10);}


Looks like a converter to BCD. It'll take e.g. 42 and turn it into 0x42. No clue why this would be necessary, but that looks like what it does.



Thanks for the links. And, holy crap is PC hardware bizarre.


BCD isn't _that_ bizarre. Many architectures had and have instructions for BCD arithmetic:

x86: http://en.wikipedia.org/wiki/Intel_BCD_opcode

68k: http://meseec.ce.rit.edu/eecc250-winter99/250-1-20-2000.pdf

6502: http://www.6502.org/users/dieter/bcd/bcd_0.htm

6800: http://fundamentals-digital-electronics.blogspot.com/2010/09...

Several others, such as Power6 and Sparc64: http://speleotrove.com/decimal/ (also shows this is is both still useful today)


Why don't you try it for a bunch of input values and find out yourself?

Hint: 0->0, 1->1, ..., 9->9, 10->16, ..., 19->25, 20->32, 29->41, 30->48, ...


I did. But I don't understand the purpose. Something to do with hex?


Pardon my ignorance, but besides being a quite tedious task to write an emulator, what are genius or other similar aspects of it?

I mean, AFAIK you just need to closely follow the SPECS.


I see stuff like this (The original JSLinux, not the de-obfuscated one) and am simply in awe. Guys like Fabrice Bellard are on another level completely.

Someday, I am going to have to produce an emulator, just to see how it is done and to try prove that part of me that thinks maybe I am just not good enough, wrong.


I am working on one now (Apple II, in go). It turns out it is not that difficult. You just have to be persistent, and be willing to do a lot of reading.

Although I don't have a ton of free time at the moment, I would be happy to help people get started.



Bellard has updated his site since this was made. The Newer version has an IDE disk.


Looking at this code really makes me wish I had taken an OS design class in school.


Why not learn now?


Heh, I would love to, but between co-founding a startup and having my first child, I find that I no longer have much free time anymore!


Homeschool your kid and give this to them as homework. No food until they've written their own!


There are mere mortal programmers, there are geniuses and then there's Fabrice Bellard. In french slang: "Tu peux pas test".

Go read the list of Open Source project he's done: it's a humbling experience (even for those who managed to make it big with their startups).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: