-
Notifications
You must be signed in to change notification settings - Fork 4
Binary Editing
As briefly covered in the README.md, Janus has inbuit binary editing functionality. In this wiki page I wish to further explain how binary editing works in Janus and display the reasoning for implementing this feature in the way I have.
Binary data is data not formatted in a human readable format. Examples include png, mp4, and zip files. Such file formats encode data in a non readable way in order to use the smallest amount of space possible. When loading binary data from a file, Janus takes each byte in a file and individually translates them into Unicode, the universal standard for displaying text. The way it does so is by taking each binary character's ascii hex code and translating that into a unicode counterpart. The ascii table is shown below:
As seen above, the ascii code for the character 'A' is 0x41, which is to say that it is 41 in hexidecimal. In order to convert this to Unicode, simply prepend the signifier U+ to the code and we get U+41, which is indeed the same unicode character for 'A'. However, as you may notice, the ascii table only continues until 0x7f, and computers can store up to 0xff. Here the unicode table, which is much more expansive than ascii and includes characters from hundreds of languages, can help us. The character code U+80 is valid, and U+81, all the way up to U+ff. So when determining how you're binary data will be displayed on screen, janus simply converts the binary number into its unicode equivalent:
| Binary data | Unicode Character Code | Unicode Character |
|---|---|---|
| 0x41 | U+41 | A |
| 0x42 | U+42 | B |
| 0x43 | U+43 | C |
| ... | ||
| 0x7f | U+7f | � |
| 0x80 | U+80 | � |
The one exception to this rule is the null character. Unfortunately, due to a limitation in glib (and not in UTF-8/Unicode), Null characters can not be displayed in GTK. In place of it, Janus uses the NUL stand-in, U+2400, ␀. All of this explanation might go a little over your head, so here is a practical demonstration of binary editing in janus:

Finally, saving files. Saving a binary files works the same way as opening one, just in reverse. When you save a file, it will run through each character and convert them back into binary. U+42 will return to 0x42, and U+2400 will return to 0x00. As long as you haven't added any unicode characters above character code U+ff, in other words representing an impossible binary character code, your file should save and everything should be fine.
One of most important features of windows notepad in my opinion is its ability to open any kind of file, including files not written in human readable format. For this reason I have chosen to build a binary editing mode into Janus. However, unlike other text editors which use escape characters to display binary data or prompt the user to convert the often useless data into Unicode using inapplicable codepages, I have chosen a novel approach. Overall I think this solution has some complicated implementation features, but I think that it's a pretty intuitive mapping for casual users who simply want to view the insides of say a png or zip file. If more advanced users wish to use this feature, it is also convenient to use as to insert characters you simply press Control + Shift + U and then the ascii code you wish to insert. All things considered I really like the way it works and use it for all my personal needs.