Skip to content

Commit

Permalink
Fix fixes for /t and node20
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Sep 4, 2024
1 parent ecfee39 commit 2aad3d4
Show file tree
Hide file tree
Showing 4 changed files with 3,917 additions and 2,439 deletions.
56 changes: 30 additions & 26 deletions www/lib/r2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare2 Copyleft 2013-2016 pancake */
/* radare2 Copyleft 2013-2024 pancake */

var r2 = {};

Expand Down Expand Up @@ -437,12 +437,9 @@ function _internal_cmd(c, cb, err) {
if (hascmd) {
// TODO: use setTimeout for async?
if (typeof (r2plugin) != 'undefined') {
// duktape
return cb(r2cmd(c));
} else {
// node
return hascmd(c, cb);
return cb(r2cmd(c)); // duktape
}
return hascmd(c, cb); // node
} else {
Ajax('GET', r2.root + '/cmd/' + encodeURI(c), '', function(x) {
if (cb) {
Expand Down Expand Up @@ -565,30 +562,30 @@ r2.getTextLogger = function(obj) {

r2.filter_asm = function(x, display) {
var curoff = backward ? prev_curoff : next_curoff;
;
var lastoff = backward ? prev_lastoff : next_lastoff;
;
var lines = x.split(/\n/g);
r2.cmd('s', function(x) {
curoff = x;
});
for (var i = lines.length - 1; i > 0; i--) {
for (let i = lines.length - 1; i > 0; i--) {
var a = lines[i].match(/0x([a-fA-F0-9]+)/);
if (a && a.length > 0) {
lastoff = a[0].replace(/:/g, '');
break;
}
}
if (display == 'afl') {
//hasmore (false);
var z = '';
for (var i = 0; i < lines.length; i++) {
var row = lines[i].replace(/\ +/g, ' ').split(/ /g);
// hasmore (false);
let z = '';
for (let i = 0; i < lines.length; i++) {
const row = lines[i].replace(/\ +/g, ' ').split(/ /g);
z += row[0] + ' ' + row[3] + '\n';
}
x = z;
} else if (display[0] == 'f') {
//hasmore (false);
} else if (display === '') {
// nothing
} else if (display[0] === 'f') {
// hasmore (false);
if (display[1] == 's') {
var z = '';
for (var i = 0; i < lines.length; i++) {
Expand All @@ -603,34 +600,41 @@ r2.filter_asm = function(x, display) {
} else {
}
} else if (display[0] == 'i') {
//hasmore (false);
// hasmore (false);
if (display[1]) {
var z = '';
for (var i = 0; i < lines.length; i++) {
var elems = lines[i].split(/ /g);
var name = '';
var addr = '';
for (var j = 0; j < elems.length; j++) {
var kv = elems[j].split(/=/);
if (kv[0] == 'addr') {
addr = kv[1];
const kv = elems[j].split(/=/);
if (kv.length !== 2) {
continue;
}
if (kv[0] == 'name') {
name = kv[1];
}
if (kv[0] == 'string') {
switch (kv[0]) {
case 'addr':
addr = kv[1];
break;
case 'name':
case 'string':
name = kv[1];
break;
}
}
z += addr + ' ' + name + '\n';
}
x = z;
}
} //else hasmore (true);
} // else hasmore (true);

function haveDisasm(x) {
if (x[0] == 'p' && x[1] == 'd') return true;
if (x.indexOf(';pd') != -1) return true;
if (x[0] == 'p' && x[1] == 'd') {
return true;
}
if (x.indexOf(';pd') != -1) {
return true;
}
return false;
}
if (haveDisasm(display)) {
Expand Down
9 changes: 6 additions & 3 deletions www/t/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
VERSION=0.1.1
NPMBIN=node_modules/.bin

GLOBALS=
GLOBALS+=--global _
Expand All @@ -19,22 +20,24 @@ node_modules:
build: node_modules
mkdir -p dist/t
rm -rf dist
$(shell npm bin)/gulp
$(NPMBIN)/gulp

dist:
rm -f $(DISTZIP)
cd ../../dist && zip -r $(DISTZIP) t

run: dist
# r2 -e http.ui=dist -e http.root=$$PWD -qc=H /bin/ls
(sleep 1 && open http://localhost:9090/t) &
r2 -qcq -e http.verbose=true -e http.root=$$PWD/../../dist -e http.ui=t -e http.sandbox=0 -c=H /bin/ls

watch:
$(shell npm bin)/gulp watch
#$(shell npm bin)/gulp watch
$(NPMBIN)/gulp watch

mrproper: clean
rm -rf node_modules


indent:
node_modules/.bin/semistandard $(GLOBALS) --fix js/*.js
$(NPMBIN)/semistandard $(GLOBALS) --fix js/*.js
35 changes: 25 additions & 10 deletions www/t/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ window.onload = function () {
input.onkeyup = function (ev) {
if (ev.keyCode === 13) {
r2.cmd(input.value, function (x) {
_(n + '_output').innerHTML = '<pre>' + x + '</pre>';
_(n + '_output').innerHTML = x; // '<pre>' + x + '</pre>';
input.value = '';
});
}
Expand Down Expand Up @@ -302,9 +302,8 @@ window.onload = function () {
_(n + '_hexdump').innerHTML = seekbar +
'<br /><center><a class=link href=\'#\' id=' + idPrev + '>[PREV]</a>' +
'<a class=link href=\'#\' id=' + id_goto + '>[GOTO]</a>' +
'<a class=link href=\'#\' id=' + idNext + '>[NEXT]</a></center>' +
'<pre>' + x + '</pre>'
;
'<a class=link href=\'#\' id=' + idNext + '>[NEXT]</a></center>' + x;
// '<pre>' + x + '</pre>' ;
// var q = document.getElementById(n+'_hexdump_hex_prev');
var q = document.getElementById(idPrev);
q.onclick = function () {
Expand Down Expand Up @@ -392,8 +391,18 @@ window.onload = function () {
code.style.width = obj.style.width - pos[0];
}
}, position, function (frame, nf) {
if (!frame) {
alert("PUTA");
return;
}
frame = frame.curframe[0];
if (!frame) {
alert("NOFr");
}
var seekbar = '';
if (!nf) {
alert("NONF");
}
frame = nf;
if (!frame.offset) {
r2.cmd('s', function (x) {
Expand All @@ -418,8 +427,8 @@ window.onload = function () {
_(n + '_code').innerHTML = seekbar +
'<br /><center><a class=link href=\'#\' id=' + idPrev + '>[PREV]</a>' +
'<a class=link href=\'#\' id=' + id_goto + '>[GOTO]</a>' +
'<a class=link href=\'#\' id=' + idNext + '>[NEXT]</a></center>' +
'<pre>' + x + '</pre>';
'<a class=link href=\'#\' id=' + idNext + '>[NEXT]</a></center>' + x;
// '<pre>' + x + '</pre>';
var q = document.getElementById(idPrev);
q.onclick = function () {
r2.cmd('s-512;s', function (res) {
Expand Down Expand Up @@ -451,7 +460,12 @@ window.onload = function () {
});
seekAction();
r2.cmd('s', function (res) {
if (typeof frame === 'undefined') {
alert("Noframe");
return;
}
frame.offset = res.trim();
alert("PANTADESAY");
seekAction();
frame.refresh();
});
Expand All @@ -466,12 +480,12 @@ window.onload = function () {
r2.cmd(t.cmd, function (x) {
x = r2.filter_asm(x, 'pd');
_(t.key).innerHTML =
'<div class=\'frame_body\'><a href=\'#\' id=\'cmd_' + ctr + '\'>cmd</a><pre>' + x + '</pre></div>';
'<div class=\'frame_body\'><a href=\'#\' id=\'cmd_' + ctr + '\'>cmd</a>' + x + '</div>';
});
};
_('cmd_' + ctr).onclick = function () {
t.key = 'div_' + ctr;
t.cmd = prompt();
t.cmd = prompt("lala");
t.update();
};
}
Expand All @@ -495,15 +509,16 @@ window.onload = function () {
// t.frames[0].push (t.frames.pop ()[0]);
t.run();
t.update = function () {
alert(t.cmd);
r2.cmd(t.cmd, function (x) {
x = r2.filter_asm(x);
_(t.key).innerHTML =
'<div class=\'frame_body\'><pre>' + x + '</pre></div>';
'<div class=\'frame_body\'>' + x + '</div>';
});
};
_('cmd_' + ctr).onclick = function () {
t.key = 'div_' + ctr;
t.cmd = prompt();
t.cmd = prompt("pene");
t.update();
};
};
Expand Down
Loading

0 comments on commit 2aad3d4

Please sign in to comment.