Skip to content

Commit

Permalink
And we got a working hex decoder!
Browse files Browse the repository at this point in the history
  • Loading branch information
luckydonald committed May 13, 2016
1 parent 00c616e commit 415f4d3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions parser.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
<label for="use_single_row" title="with scroll bar."><input type="checkbox" id="use_single_row" onchange="func_use_single_row();"/> Use single row</label>
</div>
<div id="output"></div>
<img id="legend" src="https://cloud.githubusercontent.com/assets/2737108/12401272/a91e8db2-be25-11e5-85f5-533f6e7f4006.png" />
</body>
</html>
23 changes: 17 additions & 6 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,16 @@ ByteStringParser.prototype.new_dict = function() {
obj.addClass("dict");
var count = this.next_int(2);
obj.append(this.new_something("count", 2, count, "add count"));
for (var i = 0; i < count; i++) {
var elem = this.new_id();
var i, elem;
for (i = 0; i < count; i++) {
elem = this.new_id();
obj.append(elem);
var key = this.new_string(true);
obj.append(key);
}
obj.append(this.new_something("count", 2, count, "del. count"));
for (var i = 0; i < count; i++) {
var elem = this.new_id();
for (i = 0; i < count; i++) {
elem = this.new_id();
obj.append(elem);
}
return obj;
Expand Down Expand Up @@ -286,7 +287,6 @@ Application.get_parser = function () {
return parsers[$("#parsers").val() || 0];
};
Application.get_render = function () {
console.log($("#renderers").val(), renders[$("#renderers").val() || 0]);
return renders[$("#renderers").val() || 0] || function (byte) {return ""+byte};
};
Application.parse = function (string) {
Expand All @@ -297,7 +297,18 @@ Application.render = function (byte) {
};

parsers[parsers.length] = new Parser(
"json list", "uses the build in json parser.", JSON.parse
"json list", "uses the build in json parser. Is capable of hex in a format of 0x2E.", JSON.parse
);
parsers[parsers.length] = new Parser(
"hex blob", "all non-hex character are simply ignored.", function (string) {
string = string.replace(/[^0-9a-f]+/gi, '');
if(string.length % 2 === 1) {throw "not an even number of digits..."}
var array = new Uint8Array(string.length/2);
for (var i = 0; i < string.length-1; i += 2) {
array[i/2] = parseInt(string.substring(i, i+2), 16);
}
return array;
}
);
renders[renders.length] = new Renderer(
"decimal", "negative possible.", function (byte) {return byte}
Expand Down
3 changes: 3 additions & 0 deletions parser.less
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,7 @@ body{
border: 1px solid rgb(166, 166, 166);
border-radius: 5px;
}
#legend {
width: 100%;
}
}

0 comments on commit 415f4d3

Please sign in to comment.