Skip to content

Instantly share code, notes, and snippets.

@getjump
Created November 29, 2014 09:12
Show Gist options
  • Save getjump/bafb71ce0c5f64523ec1 to your computer and use it in GitHub Desktop.
Save getjump/bafb71ce0c5f64523ec1 to your computer and use it in GitHub Desktop.
<?php
$stacks =
[
'edi' => 0x0,
'ecx' => 0x0,
'ebp' => [],
'eax' => 0x0,
'cl' => 0x0
];
function calc($dat)
{
$l = '';
$r = '';
for ($i = 0; $i < strlen($dat); $i++) {
}
}
function validateDigits($dat)
{
foreach ((array)$dat as $s) {
if (!isDigit($s)) {
return false;
}
}
return true;
}
function isDigit($s)
{
$a =
[
'0' => 0,
'1' => 0,
'2' => 0,
'3' => 0,
'4' => 0,
'5' => 0,
'6' => 0,
'7' => 0,
'8' => 0,
'9' => 0
];
return isset($a[$s]);
}
function parseRow($str)
{
$whitespace = ["\r", "\r\n", "\n", " ", " "];
$c = 0;
$parsed = ['', '', ''];
for ($i = 0; $i < strlen($str); $i++) {
if ($str[$i] == ",")
continue;
if (!in_array($str[$i], $whitespace)) {
$parsed[$c] .= $str[$i];
} else {
$c++;
}
}
$a = array_filter($parsed, function ($d) {
return $d != "";
});
$a1 = false;
$a2 = isset($a[2]) ? false : true;
if ($a[1][strlen($a[1]) - 1] == 'h') {
$a[1] = hexdec($a[1]);
$a1 = true;
}
if (!$a1) {
if (validateDigits($a[1])) {
$a[1] = intval($a[1]);
$a1 = true;
}
}
if (!$a2 && $a[2][strlen($a[2]) - 1] == 'h') {
$a[2] = hexdec($a[2]);
$a2 = true;
}
if (!$a2) {
if (validateDigits($a[2])) {
$a[2] = intval($a[2]);
$a2 = true;
}
}
if (!$a1) {
if ($a1[1][0] == '[') {
}
}
return $a;
}
//$data = 'mov [ebp+var_C], edx';
$fileData = file_get_contents('data.asm');
foreach (explode("\n", $fileData) as $line) {
$p = parseRow($line);
switch ($p[0]) {
case 'sub':
$stacks[$p[1]] -= $p[2];
break;
case 'push':
break;
case 'mov':
$stacks[$p[1]] = $stacks[$p[2]];
break;
default:
print('Unprocessed operation ' . $p[0] . PHP_EOL);
exit;
break;
}
}
var_dump($stacks);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment