Skip to content

Commit

Permalink
Demos: Added SPARC code
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAltea committed Feb 4, 2017
1 parent 55f494c commit fd7ef47
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 22 deletions.
28 changes: 16 additions & 12 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,22 @@
<a role="button" href="demo.html?arch=sparc">SPARC</a>,
<a role="button" href="demo.html?arch=x86">X86</a>.
</p>
<h2>Pending</h2>
<ul>
<li>Support for JavaScript callback on hooks, i.e. <code>uc_hook_add</code> and <code>uc_hook_del</code>.</li>
<li>Support for breakpoints</li>
<li>Fixing the memory panel and editing memory from there.</li>
<li>Saving editor sessions</li>
<li></li>
</ul>
Finally, boost my ego by clicking here:
<hr style="border-color:#777">
<iframe src="https://ghbtns.com/github-btn.html?user=AlexAltea&type=follow&count=false" frameborder="0" scrolling="0" width="132px" height="20px"></iframe>
<iframe src="https://ghbtns.com/github-btn.html?user=AlexAltea&repo=unicorn.js&type=star&count=true" frameborder="0" scrolling="0" width="80px" height="20px"></iframe>
<p>
<b>Pending features</b>:
<ul>
<li>Support for JavaScript callbacks on hooks via <code>uc_hook_add</code> and <code>uc_hook_del</code>.</li>
<li>Support for breakpoints and stepping.</li>
<li>Implement demos for 64-bit archs.</li>
<li>Fixing the memory panel, editing memory and viewing updated bytes.</li>
<li>Improve editor: Support for comments, labels, realtime assembling and more.</li>
<li>Saving sessions in local storage</li>
</ul>
</p>
Finally, feel free to boost my ego:
<p>
<iframe src="https://ghbtns.com/github-btn.html?user=AlexAltea&type=follow&count=false" frameborder="0" scrolling="0" width="132px" height="20px"></iframe>
<iframe src="https://ghbtns.com/github-btn.html?user=AlexAltea&repo=unicorn.js&type=star&count=true" frameborder="0" scrolling="0" width="80px" height="20px"></iframe>
</p>
</div>
</div>
<div id="pane-l" class="split split-horizontal">
Expand Down
2 changes: 1 addition & 1 deletion demos/demo-mips.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var e = new uc.Unicorn(uc.ARCH_MIPS, uc.MODE_MIPS32 | uc.MODE_BIG_ENDIAN);
var a = new ks.Keystone(ks.ARCH_MIPS, ks.MODE_MIPS32 | ks.MODE_BIG_ENDIAN);
var a = new ks.Keystone(ks.ARCH_MIPS, ks.MODE_MIPS32 | uc.MODE_BIG_ENDIAN); // TODO
var d = new cs.Capstone(cs.ARCH_MIPS, cs.MODE_MIPS32 | cs.MODE_BIG_ENDIAN);

// Instruction Pointer
Expand Down
58 changes: 58 additions & 0 deletions demos/demo-sparc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var e = new uc.Unicorn(uc.ARCH_SPARC, uc.MODE_SPARC32 | uc.MODE_BIG_ENDIAN);
var a = new ks.Keystone(ks.ARCH_SPARC, ks.MODE_SPARC32 | uc.MODE_BIG_ENDIAN); // TODO
var d = new cs.Capstone(cs.ARCH_SPARC, cs.MODE_SPARC32 | cs.MODE_BIG_ENDIAN);

// Instruction Pointer
function pcRead() {
return e.reg_read_i32(uc.SPARC_REG_PC);
}
function pcWrite(value) {
return e.reg_write_i32(uc.SPARC_REG_PC, value);
}

// Customization
$('title').html('Unicorn.js: SPARC');
$('.navbar-demo').html('SPARC');

// Registers
paneRegisters.add(new Register('G0', 'i32', uc.SPARC_REG_G0));
paneRegisters.add(new Register('G1', 'i32', uc.SPARC_REG_G1));
paneRegisters.add(new Register('G2', 'i32', uc.SPARC_REG_G2));
paneRegisters.add(new Register('G3', 'i32', uc.SPARC_REG_G3));
paneRegisters.add(new Register('G4', 'i32', uc.SPARC_REG_G4));
paneRegisters.add(new Register('G5', 'i32', uc.SPARC_REG_G5));
paneRegisters.add(new Register('G6', 'i32', uc.SPARC_REG_G6));
paneRegisters.add(new Register('G7', 'i32', uc.SPARC_REG_G7));
paneRegisters.add(new Register('L0', 'i32', uc.SPARC_REG_L0));
paneRegisters.add(new Register('L1', 'i32', uc.SPARC_REG_L1));
paneRegisters.add(new Register('L2', 'i32', uc.SPARC_REG_L2));
paneRegisters.add(new Register('L3', 'i32', uc.SPARC_REG_L3));
paneRegisters.add(new Register('L4', 'i32', uc.SPARC_REG_L4));
paneRegisters.add(new Register('L5', 'i32', uc.SPARC_REG_L5));
paneRegisters.add(new Register('L6', 'i32', uc.SPARC_REG_L6));
paneRegisters.add(new Register('L7', 'i32', uc.SPARC_REG_L7));
paneRegisters.add(new Register('I0', 'i32', uc.SPARC_REG_I0));
paneRegisters.add(new Register('I1', 'i32', uc.SPARC_REG_I1));
paneRegisters.add(new Register('I2', 'i32', uc.SPARC_REG_I2));
paneRegisters.add(new Register('I3', 'i32', uc.SPARC_REG_I3));
paneRegisters.add(new Register('I4', 'i32', uc.SPARC_REG_I4));
paneRegisters.add(new Register('I5', 'i32', uc.SPARC_REG_I5));
paneRegisters.add(new Register('I6', 'i32', uc.SPARC_REG_I6));
paneRegisters.add(new Register('I7', 'i32', uc.SPARC_REG_I7));
paneRegisters.add(new Register('O0', 'i32', uc.SPARC_REG_O0));
paneRegisters.add(new Register('O1', 'i32', uc.SPARC_REG_O1));
paneRegisters.add(new Register('O2', 'i32', uc.SPARC_REG_O2));
paneRegisters.add(new Register('O3', 'i32', uc.SPARC_REG_O3));
paneRegisters.add(new Register('O4', 'i32', uc.SPARC_REG_O4));
paneRegisters.add(new Register('O5', 'i32', uc.SPARC_REG_O5));
paneRegisters.add(new Register('O6', 'i32', uc.SPARC_REG_O6));
paneRegisters.add(new Register('O7', 'i32', uc.SPARC_REG_O7));
paneRegisters.add(new Register('PC', 'i32', uc.SPARC_REG_PC));
paneRegisters.update();

// Initialization
paneAssembler.setAddr(0x10000);
paneAssembler.appendAsm(/*`
add %g1, %g2, %g3;
`*/);
paneMemory.update();
2 changes: 1 addition & 1 deletion demos/demo-x86.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ paneAssembler.setAddr(0x10000);
paneAssembler.appendAsm(`
mov eax, 0
mov edx, 1
mov edx, 30
mov ecx, 30
xadd eax, edx
loop -3
`);
Expand Down
21 changes: 13 additions & 8 deletions demos/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function Register(name, type, id) {
reg.nodeHex.appendChild(input);
$(input).on('keyup', function (e) {
if (e.keyCode == 13) {
reg.set(this.value);
reg.set(parseInt(this.value, 16));
reg.update();
}
});
Expand All @@ -83,9 +83,9 @@ function Register(name, type, id) {
// Set value
this.dataValue = value.toString();
switch (this.type) {
case 'i8': this.dataHex = utilIntToHex(value, 2);
case 'i16': this.dataHex = utilIntToHex(value, 4);
case 'i32': this.dataHex = utilIntToHex(value, 8);
case 'i8': this.dataHex = utilIntToHex(value, 2); break;
case 'i16': this.dataHex = utilIntToHex(value, 4); break;
case 'i32': this.dataHex = utilIntToHex(value, 8); break;
}
}
this._update_float = function () {
Expand All @@ -102,10 +102,13 @@ function Register(name, type, id) {
case 'i16':
case 'i32':
this._update_int();
break;
case 'f32':
this._update_float();
break;
case 'v128':
this._update_vector();
break;
}
this.restore();
}
Expand All @@ -116,7 +119,7 @@ function Register(name, type, id) {
this.set = function (value) {
switch (this.type) {
default:
e.reg_write_type(this.id, this.type, 16);
e.reg_write_type(this.id, this.type, value);
}
}

Expand Down Expand Up @@ -218,9 +221,11 @@ var paneAssembler = {
// Emulation
emuStart: function () {
var bytes = this.bytes();
e.mem_write(this.address, bytes);
e.emu_start(this.address, this.address+bytes.length, 0, 0);
paneRegisters.update();
if (bytes.length > 0) {
e.mem_write(this.address, bytes);
e.emu_start(this.address, this.address+bytes.length, 0, 0);
paneRegisters.update();
}
},
emuPause: function () {
console.warn("Pause unimplemented");
Expand Down

0 comments on commit fd7ef47

Please sign in to comment.