Add 'asm' utility in webui, fix section auto init

This commit is contained in:
pancake 2012-12-24 00:18:33 +01:00
parent d1c351bcb4
commit 8890b33d21
10 changed files with 386 additions and 270 deletions

View File

@ -8,6 +8,11 @@
<article class="list scroll active" >
<ul>
<!-- Basic Layout -->
<li>
<a href="#assembler" data-router="section" data-title="Assembler" data-async="app/asm.html">
<strong>Assembler</strong>
</a>
</li>
<li>
<a href="#disasm" data-router="section" data-title="Disassembly" data-async="app/disasm.html">
<strong>Disassembly</strong>

37
shlr/www/new/app/asm.html Normal file
View File

@ -0,0 +1,37 @@
<section id="assembler" class="list scroll" style="overflow:hidden">
<header data-title="Assembler">
<nav class="box">
<a href="#features" data-router="aside" data-icon="menu"></a>
</nav>
</header>
<article id="assembler-article" class="active list scroll" style="background-color:white;font-size:12px">
<ul>
<li>
<form action="javascript:r2ui.assembleOpcode()">
<input autocapitalize="off" style="height:32px;width:99%"
type="text" placeholder="" id="assembleOpcode" value="nop"></input>
</form>
</li>
<ul>
<li>
<form action="javascript:r2ui.assembleBytes()">
<input autocapitalize="off" style="height:32px;width:99%"
type="text" placeholder="" id="assembleBytes" value="90"></input>
</form>
</li>
<li>
<div class="two columns right">
<a href="javascript:r2ui.assembleWrite()" class="button big red" data-label="Write" data-icon="pencil"></a>
</div>
<div class="four columns left">
<form action="javascript:r2ui.assembleWrite()">
<input autocapitalize="off" style="height:32px;width:99%"
type="text" placeholder="" id="assembleOffset" value="entry0"></input>
</form>
</div>
<br /><br />&nbsp;
</li>
</ul>
</article>
</section>

View File

@ -1,4 +1,5 @@
<section id="disasm" class="list scroll" style="overflow:hidden" onload="javascript:r2ui.initDisasm()">
<section id="disasm" class="list scroll" style="overflow:hidden">
<img src="icon.png" onload="r2ui.initDisasm()"></img>
<header data-title="Disassembly">
<nav class="box">
<a href="#features" data-router="aside" data-icon="menu"></a>
@ -9,6 +10,9 @@
<nav class="right">
<a href="javascript:r2ui.initDisasm()" class="button" data-icon="right" data-label=""></a>
</nav>
<nav class="right">
<a href="javascript:r2ui.seek('entry0',function(x) {r2ui.initDisasm()});" class="button" data-icon="home" data-label=""></a>
</nav>
<nav class="right">
<a href="javascript:r2ui.initDisasm()" class="button" data-icon="left" data-label=""></a>
</nav>
@ -18,7 +22,7 @@
<center> (previous page) </center>
</div>
<pre style="font-family:monospace" id="disasmBody">
<pre style="margin:10px;font-family:monospace" id="disasmBody">
<br /><br />
<br /><br />
<center>
@ -32,5 +36,4 @@
<center> (next page) </center>
</div>
</article>
</body>
</section>

View File

@ -1,4 +1,5 @@
<section id="hexdump" class="list scroll" style="overflow:hidden">
<img src="icon.png" onload="r2ui.initHexdump()"> </img>
<header data-title="Hexdump">
<nav class="box">
<a href="#features" data-router="aside" data-icon="menu"></a>
@ -8,11 +9,6 @@
</nav>
</header>
<article id="hexdump-normal" class="active list scroll indented" style="background-color: white">
<pre style="margin:10px" id="hexdumpBody">
<br /><br /><center>
<script type="text/javascript">r2ui.initHexdump();</script>
<a href="javascript:r2ui.initHexdump()">init</a>
</center>
</pre>
<pre style="margin-left:15px" id="hexdumpBody"></pre>
</article>
</section>

View File

@ -1,4 +1,5 @@
<section id="sections" class="list scroll" style="overflow:hidden" onload="r2ui.initSections()">
<section id="sections" class="list scroll" style="overflow:hidden">
<img src="icon.png" onload="r2ui.initSections()"></img>
<header data-title="Sections">
<nav class="box">
<a href="#features" data-router="aside" data-icon="menu"></a>

View File

@ -1,4 +1,5 @@
<section id="symbols" class="list scroll" style="overflow:hidden" onload="r2ui.initSymbols()">
<section id="symbols" class="list scroll" style="overflow:hidden">
<img src="icon.png" onload="r2ui.initSymbols()"></img>
<header data-title="Symbols">
<nav class="box">
<a href="#features" data-router="aside" data-icon="menu"></a>

View File

@ -51,5 +51,61 @@ Lungo.init ({
]
});
</script>
<!-- windows -->
<div id="exampleB" style="position:fixed!important;top:200px;right:10;width:250px;height:350px;background-color:#e0e0e0;border: 1px solid black;z-index:99">
<div id="exampleBHandle" style="height:20px;left:0px;top:0px;cursor:move;width:248px;background-color:#20a0e0;font-weight:bold;color:white;border:1px solid black">&nbsp;Registers</div>
<div style="margin:5px">
<br /><br />
<pre>
eax = 0x33441100
ebx = 0x00000000
ecx = 0x00000005
edx = 0x08049204
esp = 0x0bff428a
ebp = 0x0bff428a
eip = 0x08048520
</pre>
<div class="two columns left" style="width:100px">
<a href="#" class="button big theme" data-label="" data-icon="right">Step</a>
</div>
<div class="two columns right" style="width:120px">
<a href="#" class="button big red" data-label="" data-icon="plus">Continue</a>
</div>
</div>
</div>
<script type="text/javascript">
var exampA = null;
var exampB = null;
function initialize()
{
exampA = new dragObject("exampleB", null, new Position(1000,0), new Position(1000,200), null, null, exampleAEnd, false);
exampB = new dragObject("exampleB", "exampleBHandle");
}
function buttonClicked()
{
var button = document.getElementById('dragButton');
if(exampA.IsListening())
{
exampA.StopListening(true);
exampB.StopListening(true);
button.value = "Resume Listening";
}
else
{
exampA.StartListening();
exampB.StartListening();
button.value = "Stop Listening";
}
}
function exampleAEnd()
{
// alert("Drag Ended.");
}
initialize();
</script>
</body>
</html>

View File

@ -9,7 +9,7 @@ function Ajax (method, uri, body, fn) {
x.onreadystatechange = function (y) {
if (x.status == 200) {
if (fn) fn (x.responseText);
} else alert ("ajax "+x.status)
} else console.error ("ajax "+x.status)
}
x.send (body);
}
@ -110,12 +110,14 @@ r2.get_logger = function (obj) {
obj.interval.stop ();
return;
}
obj.interval = setInterval (function () {
function to() {
obj.refresh (function () {
//obj.clear ();
});
setTimeout (to, n*1000);
return true;
}, n*1000);
}
obj.interval = setTimeout (to, n*1000);
}
obj.on = function (ev, cb) {
obj.events[ev] = cb;

View File

@ -229,8 +229,31 @@ function seek(x,back) {
r2ui.seek = seek;
r2ui.initDisasm = function () {
r2.cmd ("pd 512", function (x) {
r2.cmd ("pd 128", function (x) {
x = filter_asm (x);
document.getElementById ("disasmBody").innerHTML = x;
});
}
r2ui.assembleOpcode = function () {
var str = document.getElementById ("assembleOpcode").value;
r2.cmd ("\"pa "+str+"\"", function (x) {
document.getElementById ("assembleBytes").value = x;
});
}
r2ui.assembleBytes = function () {
var hex = document.getElementById ("assembleBytes").value;
r2.cmd ("pi 1@b:"+hex, function (x) {
document.getElementById ("assembleOpcode").value = x;
});
}
r2ui.assembleWrite = function () {
var hex = document.getElementById ("assembleBytes").value;
var off = document.getElementById ("assembleOffset").value;
r2.cmd ("s "+off+";wx "+hex, function (x) {
Lungo.Notification.error('Oops', 'Cannot write bytes', 'file is read-only', 2);
//document.getElementById ("assembleOpcode").value = x;
});
}

View File

@ -1,273 +1,265 @@
/* http://www.switchonthecode.com/tutorials/javascript-draggable-elements */
function hookEvent(element, eventName, callback)
{
if(typeof(element) == "string")
element = document.getElementById(element);
if(element == null)
return;
if(element.addEventListener)
{
element.addEventListener(eventName, callback, false);
}
else if(element.attachEvent)
element.attachEvent("on" + eventName, callback);
function hookEvent(element, eventName, callback) {
if(typeof(element) == "string")
element = document.getElementById(element);
if(element == null)
return;
if(element.addEventListener) {
element.addEventListener(eventName, callback, false);
} else if(element.attachEvent)
element.attachEvent("on" + eventName, callback);
}
function unhookEvent(element, eventName, callback)
{
if(typeof(element) == "string")
element = document.getElementById(element);
if(element == null)
return;
if(element.removeEventListener)
element.removeEventListener(eventName, callback, false);
else if(element.detachEvent)
element.detachEvent("on" + eventName, callback);
function unhookEvent(element, eventName, callback) {
if(typeof(element) == "string")
element = document.getElementById(element);
if(element == null)
return;
if(element.removeEventListener)
element.removeEventListener(eventName, callback, false);
else if(element.detachEvent)
element.detachEvent("on" + eventName, callback);
}
function cancelEvent(e)
{
e = e ? e : window.event;
if(e.stopPropagation)
e.stopPropagation();
if(e.preventDefault)
e.preventDefault();
e.cancelBubble = true;
e.cancel = true;
e.returnValue = false;
return false;
function cancelEvent(e) {
e = e ? e : window.event;
if(e.stopPropagation)
e.stopPropagation();
if(e.preventDefault)
e.preventDefault();
e.cancelBubble = true;
e.cancel = true;
e.returnValue = false;
return false;
}
function Position(x, y)
{
this.X = x;
this.Y = y;
this.Add = function(val)
{
var newPos = new Position(this.X, this.Y);
if(val != null)
{
if(!isNaN(val.X))
newPos.X += val.X;
if(!isNaN(val.Y))
newPos.Y += val.Y
}
return newPos;
}
this.Subtract = function(val)
{
var newPos = new Position(this.X, this.Y);
if(val != null)
{
if(!isNaN(val.X))
newPos.X -= val.X;
if(!isNaN(val.Y))
newPos.Y -= val.Y
}
return newPos;
}
this.Min = function(val)
{
var newPos = new Position(this.X, this.Y)
if(val == null)
return newPos;
if(!isNaN(val.X) && this.X > val.X)
newPos.X = val.X;
if(!isNaN(val.Y) && this.Y > val.Y)
newPos.Y = val.Y;
return newPos;
}
this.Max = function(val)
{
var newPos = new Position(this.X, this.Y)
if(val == null)
return newPos;
if(!isNaN(val.X) && this.X < val.X)
newPos.X = val.X;
if(!isNaN(val.Y) && this.Y < val.Y)
newPos.Y = val.Y;
return newPos;
}
this.Bound = function(lower, upper)
{
var newPos = this.Max(lower);
return newPos.Min(upper);
}
this.Check = function()
{
var newPos = new Position(this.X, this.Y);
if(isNaN(newPos.X))
newPos.X = 0;
if(isNaN(newPos.Y))
newPos.Y = 0;
return newPos;
}
this.Apply = function(element)
{
if(typeof(element) == "string")
element = document.getElementById(element);
if(element == null)
return;
if(!isNaN(this.X))
element.style.left = this.X + 'px';
if(!isNaN(this.Y))
element.style.top = this.Y + 'px';
}
function Position(x, y) {
this.X = x;
this.Y = y;
this.Add = function(val)
{
var newPos = new Position(this.X, this.Y);
if(val != null)
{
if(!isNaN(val.X))
newPos.X += val.X;
if(!isNaN(val.Y))
newPos.Y += val.Y
}
return newPos;
}
this.Subtract = function(val) {
var newPos = new Position(this.X, this.Y);
if(val != null)
{
if(!isNaN(val.X))
newPos.X -= val.X;
if(!isNaN(val.Y))
newPos.Y -= val.Y
}
return newPos;
}
this.Min = function(val)
{
var newPos = new Position(this.X, this.Y)
if(val == null)
return newPos;
if(!isNaN(val.X) && this.X > val.X)
newPos.X = val.X;
if(!isNaN(val.Y) && this.Y > val.Y)
newPos.Y = val.Y;
return newPos;
}
this.Max = function(val)
{
var newPos = new Position(this.X, this.Y)
if(val == null)
return newPos;
if(!isNaN(val.X) && this.X < val.X)
newPos.X = val.X;
if(!isNaN(val.Y) && this.Y < val.Y)
newPos.Y = val.Y;
return newPos;
}
this.Bound = function(lower, upper)
{
var newPos = this.Max(lower);
return newPos.Min(upper);
}
this.Check = function()
{
var newPos = new Position(this.X, this.Y);
if(isNaN(newPos.X))
newPos.X = 0;
if(isNaN(newPos.Y))
newPos.Y = 0;
return newPos;
}
this.Apply = function(element)
{
if(typeof(element) == "string")
element = document.getElementById(element);
if(element == null)
return;
if(!isNaN(this.X))
element.style.left = this.X + 'px';
if(!isNaN(this.Y))
element.style.top = this.Y + 'px';
}
}
function absoluteCursorPostion(eventObj)
{
eventObj = eventObj ? eventObj : window.event;
if(isNaN(window.scrollX))
return new Position(eventObj.clientX + document.documentElement.scrollLeft + document.body.scrollLeft,
eventObj.clientY + document.documentElement.scrollTop + document.body.scrollTop);
else
return new Position(eventObj.clientX + window.scrollX, eventObj.clientY + window.scrollY);
eventObj = eventObj ? eventObj : window.event;
if(isNaN(window.scrollX))
return new Position(eventObj.clientX + document.documentElement.scrollLeft + document.body.scrollLeft,
eventObj.clientY + document.documentElement.scrollTop + document.body.scrollTop);
else
return new Position(eventObj.clientX + window.scrollX, eventObj.clientY + window.scrollY);
}
function dragObject(element, attachElement, lowerBound, upperBound, startCallback, moveCallback, endCallback, attachLater)
{
if(typeof(element) == "string")
element = document.getElementById(element);
if(element == null)
return;
if(lowerBound != null && upperBound != null)
{
var temp = lowerBound.Min(upperBound);
upperBound = lowerBound.Max(upperBound);
lowerBound = temp;
}
if(typeof(element) == "string")
element = document.getElementById(element);
if(element == null)
return;
var cursorStartPos = null;
var elementStartPos = null;
var dragging = false;
var listening = false;
var disposed = false;
if(lowerBound != null && upperBound != null)
{
var temp = lowerBound.Min(upperBound);
upperBound = lowerBound.Max(upperBound);
lowerBound = temp;
}
function touch2move (x) {
var ev = {}
ev.target = x.target;
ev.clientX = x.targetTouches[0].pageX;
ev.clientY = x.targetTouches[0].pageY;
return ev;
}
function dragTouchStart(eventObj) {
if (x.touches.length >1) return;
dragStart(touch2move (x));
}
function dragTouchGo(eventObj) {
if (x.touches.length >1) return;
dragGo(touch2move (x));
}
function dragStart(eventObj)
{
if(dragging || !listening || disposed) return;
dragging = true;
if(startCallback != null)
startCallback(eventObj, element);
cursorStartPos = absoluteCursorPostion(eventObj);
elementStartPos = new Position(parseInt(element.style.left), parseInt(element.style.top));
elementStartPos = elementStartPos.Check();
hookEvent(document, "mousemove", dragGo);
hookEvent(document, "touchmove", dragTouchGo);
hookEvent(document, "mouseup", dragStopHook);
return cancelEvent(eventObj);
}
function dragGo(eventObj)
{
if(!dragging || disposed) return;
var newPos = absoluteCursorPostion(eventObj);
newPos = newPos.Add(elementStartPos).Subtract(cursorStartPos);
newPos = newPos.Bound(lowerBound, upperBound)
newPos.Apply(element);
if(moveCallback != null)
moveCallback(newPos, element);
return cancelEvent(eventObj);
}
function dragStopHook(eventObj)
{
dragStop();
return cancelEvent(eventObj);
}
function dragStop()
{
if(!dragging || disposed) return;
unhookEvent(document, "mousemove", dragGo);
unhookEvent(document, "mouseup", dragStopHook);
cursorStartPos = null;
elementStartPos = null;
if(endCallback != null)
endCallback(element);
dragging = false;
}
this.Dispose = function()
{
if(disposed) return;
this.StopListening(true);
element = null;
attachElement = null
lowerBound = null;
upperBound = null;
startCallback = null;
moveCallback = null
endCallback = null;
disposed = true;
}
this.StartListening = function()
{
if(listening || disposed) return;
listening = true;
hookEvent(attachElement, "mousedown", dragStart);
hookEvent(attachElement, "touchstart", dragTouchStart);
}
this.StopListening = function(stopCurrentDragging)
{
if(!listening || disposed) return;
unhookEvent(attachElement, "mousedown", dragStart);
unhookEvent(attachElement, "touchend", dragStart);
listening = false;
if(stopCurrentDragging && dragging)
dragStop();
}
this.IsDragging = function(){ return dragging; }
this.IsListening = function() { return listening; }
this.IsDisposed = function() { return disposed; }
if(typeof(attachElement) == "string")
attachElement = document.getElementById(attachElement);
if(attachElement == null)
attachElement = element;
if(!attachLater)
this.StartListening();
var cursorStartPos = null;
var elementStartPos = null;
var dragging = false;
var listening = false;
var disposed = false;
function touch2move (x) {
var ev = {}
ev.target = x.target;
ev.clientX = x.targetTouches[0].pageX;
ev.clientY = x.targetTouches[0].pageY;
return ev;
}
function dragTouchStart(eventObj) {
if (x.touches.length >1) return;
dragStart(touch2move (x));
}
function dragTouchGo(eventObj) {
if (x.touches.length >1) return;
dragGo(touch2move (x));
}
function dragStart(eventObj)
{
if(dragging || !listening || disposed) return;
dragging = true;
if(startCallback != null)
startCallback(eventObj, element);
cursorStartPos = absoluteCursorPostion(eventObj);
elementStartPos = new Position(parseInt(element.style.left), parseInt(element.style.top));
elementStartPos = elementStartPos.Check();
hookEvent(document, "mousemove", dragGo);
hookEvent(document, "touchmove", dragTouchGo);
hookEvent(document, "mouseup", dragStopHook);
return cancelEvent(eventObj);
}
function dragGo(eventObj)
{
if(!dragging || disposed) return;
var newPos = absoluteCursorPostion(eventObj);
newPos = newPos.Add(elementStartPos).Subtract(cursorStartPos);
newPos = newPos.Bound(lowerBound, upperBound)
newPos.Apply(element);
if(moveCallback != null)
moveCallback(newPos, element);
return cancelEvent(eventObj);
}
function dragStopHook(eventObj)
{
dragStop();
return cancelEvent(eventObj);
}
function dragStop()
{
if(!dragging || disposed) return;
unhookEvent(document, "mousemove", dragGo);
unhookEvent(document, "mouseup", dragStopHook);
cursorStartPos = null;
elementStartPos = null;
if(endCallback != null)
endCallback(element);
dragging = false;
}
this.Dispose = function()
{
if(disposed) return;
this.StopListening(true);
element = null;
attachElement = null
lowerBound = null;
upperBound = null;
startCallback = null;
moveCallback = null
endCallback = null;
disposed = true;
}
this.StartListening = function()
{
if(listening || disposed) return;
listening = true;
hookEvent(attachElement, "mousedown", dragStart);
hookEvent(attachElement, "touchstart", dragTouchStart);
}
this.StopListening = function(stopCurrentDragging)
{
if(!listening || disposed) return;
unhookEvent(attachElement, "mousedown", dragStart);
unhookEvent(attachElement, "touchend", dragStart);
listening = false;
if(stopCurrentDragging && dragging)
dragStop();
}
this.IsDragging = function(){ return dragging; }
this.IsListening = function() { return listening; }
this.IsDisposed = function() { return disposed; }
if(typeof(attachElement) == "string")
attachElement = document.getElementById(attachElement);
if(attachElement == null)
attachElement = element;
if(!attachLater)
this.StartListening();
}