Esempio n. 1
0
 public function testSetAssembly()
 {
     $instr = new Instruction();
     $asm = new Assembly();
     $asm->addInstruction($instr);
     $this->assertEquals($asm, $instr->getAssembly());
 }
Esempio n. 2
0
 public function testAssembleX8664Jmp2()
 {
     $retInstr1 = new X8664Ret();
     $movInstr1 = new X8664Mov('rax', 'rbx');
     $jmpInstr1 = new X8664Jmp($retInstr1);
     $nopInstrs = array();
     for ($i = 0; $i < 0x2; $i++) {
         $nopInstrs[] = new X8664Nop();
     }
     $asm = new Assembly();
     $asm->addInstruction($movInstr1);
     $asm->addInstruction($jmpInstr1);
     foreach ($nopInstrs as $instrId => $nopInstr1) {
         $asm->addInstruction($nopInstr1);
     }
     $asm->addInstruction($retInstr1);
     $opcode = $asm->assemble();
     $hex = unpack('H*', $opcode);
     $hex = $hex[1];
     $this->assertEquals('4889c3eb029090c3', $hex);
     $this->assertEquals(0, $movInstr1->getOffset());
     $this->assertEquals(3, $jmpInstr1->getOffset());
     $this->assertEquals(5, $nopInstrs[0]->getOffset());
     $this->assertEquals(6, $nopInstrs[1]->getOffset());
     $this->assertEquals(7, $retInstr1->getOffset());
 }
Esempio n. 3
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
use TheFox\Assembly\Assembly;
use TheFox\Assembly\Instruction\X86_64\Mov;
use TheFox\Assembly\Instruction\X86_64\Jmp;
use TheFox\Assembly\Instruction\X86_64\Nop;
use TheFox\Assembly\Instruction\X86_64\Ret;
$retInstr = new Ret();
$asm = new Assembly();
$asm->addInstruction(new Mov('rax', 'rbx'));
$asm->addInstruction(new Jmp($retInstr));
$asm->addInstruction(new Nop());
$asm->addInstruction($retInstr);
$asm->addInstruction(new Nop());
$opcode = $asm->assemble();
$hex = unpack('H*', $opcode);
$hex = $hex[1];
print 'hex opcode: ' . $hex . "\n";