Bleadof’s world of tinkering

November 11, 2008

AT&T x86 assembly instruction reference

Filed under: Assembly,C,Programming,Studies,Thesis,Tinkering — Bleadof @ 19:11

The juice of this blog post is here: AT&T x86 assembly instruction reference can be found in the Appendix B. with the the title “Common x86 Instructions” from Programming from the Ground Up by Bartlett, J.

The actual process how I came about finding this bit of info was when I was reading Building Secure Software by Viega, J and McGraw, G in towards efforts of finishing my bachelor and master thesis on “Common faults in software which lead to a vulnerability”. The book is a brilliant as an entry level book for everyone working on software development and trying to think more securely when programming. Although hopefully my master’s thesis will serve this entry level of thinking secure while programming as well. Anyway, I was reading the BSS book and on the Stack Overflows chapter there’s this part where you’re told to use the gcc with -S flag to compile the C code to Assembly language and tweak it. So to be able to tweak it I wanted to understand what were the instructions in the Assembly language. I googled a bit to find AT&T instructions and that didn’t give me much until I finally found a question on comp.lang.asm.x86 news group which said that one would be in the Programming from the Ground Up book and there it was.

March 14, 2008

Great Assembler programming book

Filed under: Assembly,Programming,Thesis,Tinkering — Tags: , , — Bleadof @ 14:03

I found this brilliantly written Assembler, which I’m reading for my thesis, book online a while back already but I thought it might worth mentioning now. It’s called “PC Assembly Language” and its author is Paul A. Carter. It can be downloaded in PDF and PostScript so I suppose most of the people can read it. I don’t about the accessibility of a PDF or PS so I won’t say everyone can read it, but the text itself is very clear and easy to understand. It also offers good examples. I think it’s a bit sad that it’s written in Intel syntax, but I suppose that’s unavoidable. I’ve been reading mostly AT&T syntax which is a bit different, but you get used to Intel syntax fairly fast.

Now I’m off to a meeting…

July 3, 2006

Work and ajax

Filed under: PHP,Programming,Tinkering — Bleadof @ 11:07

Well, I was asked to do a suggesting text-box for one field in the UI so that it would be easier to type in the info which apparently is the one they make most of the errors. I did it with some script.aculo.us love. It’s nice that they have pretty good docs.

So basically what you have to do is include


<head>
...
<script src="scriptaculous/lib/prototype.js" type="text/javascript"></script>
<script src="scriptaculous/src/scriptaculous.js" type="text/javascript"></script>
...
</head>

Then add


<label for="signum">Signum</label>
<input id="signum" name="item[signum]" type="text" />
<div id="signumhint" class="signumhint"></div>
<script type="text/javascript">
// <![CDATA[
new Ajax.Autocompleter("signum","signumhint","AjaxController.php?get=signum", {})
// ]]>
</script>

Then add process the request, this is from my AjaxController.class.php draft


function handleRequest($post, $get) {
if(count($post) <= 0 && count($get) <= 0) {
return null;
}
if($post['item']['signum'] != null) {
$signums = $this->getSignums($post['item']['signum']);
}
$this->makeUnorderedList($signums);
$this->printList($signums);
}
function makeUnorderedList($results) {
$unorderedList = Array();
$unorderedList[] = '<ul>';
foreach($results as $result) {
$unorderedList[] = '<li>'.$result.'</li>';
}
$unorderedList[] = '</ul>';
return $unorderedList;
}
function printList($unorderedListArray) {
foreach($unorderedListArray as $item) {
print $item;
}
}

You also need to edit your css so that the hints div will look nice. It’ll be populated data. In here the hints field css looks like this:


.signumhint {
position: absolute;
font-size: 0.8em;
background-color: white;
left: 8em;
z-index: 100;
}
.signumhint ul {
list-style-type:none;
margin:0px;
padding:0px;
}
.signumhint ul li.selected { background-color: #ffb;}
.signumhint ul li {
list-style-type:none;
display:block;
margin:0;
padding:0;
height:32px;
cursor:pointer;
}

And voila, you’re good to go.

Ajax screenshot

June 12, 2006

PHP4 OOP and references

Filed under: PHP,Programming,Tinkering — Bleadof @ 13:06

So today I decided check PHP4 OOP quirks. So now I know for sure how my code is going to behave. I wasn’t really sure how the PHP4 behaves with references so I did a test.

class ReferenceTest {

  var $reference;

  function ReferenceTest() {
    $this->reference = new Reference();
  }

  function getReference() {
    return $this->reference;
  }

  function &getReferenceReference() {
    return $this->reference;
  }
}

class Reference {

  var $var;

  function Reference() {
    $this->var = "";
  }

  function setVar($var) {
    $this->var = $var;
  }

  function getVar() {
    return $this->var;
  }

  function &getVarReference() {
    return $this->var;
  }

}

$rt =  new ReferenceTest();
$ref = $rt->getReference();
$ref->setVar("bar");
$ref2 =& $rt->getReferenceReference();
$ref2->setVar("baz");
$ref3 =& $rt->getReferenceReference();
$varRef =& $ref3->getVarReference();
$varRef = "baf";
$ref3->setVar("foo");

print "ref:".$ref->getVar()."<br/>";
print "ref2:".$ref2->getVar()."<br/>";
print "ref3:".$ref3->getVar()."<br/>";

Do you know what is the output? Here’s the anwser.

April 27, 2006

PHP4 and error handling…

Filed under: PHP,Programming,Tinkering — Bleadof @ 00:04

I’m working on a project at the moment. Doing stuff for company called Boogie Beat Oy. I’m doing a whole rewrite for their system-of-a-thingie… I decided to start using proper OOP-style. Pretty interesting thing to do with a language which I’ve used only for procedural programming. So I stumbled upon some of the problems which PHP4 has with objects and error handling.

set_error_handler(“yourErrorHandlerFunction”)

I’m used to do objects with Java andJava’s way of handling errors which is quite nice and flexible.

In PHP4 the built in way of raising errors is:

trigger_error("Error message", E_USER_ERROR)

This is not the actual problem but the:


function my_errror_handler($errno, $errstr, $errfile, $errline, $errcontext) {
switch($errno) {
case E_USER_ERROR:
...
}
}
$old_error_handler = set_error_handler("my_error_handler");

Which would be just brilliant if you could say…


$old_error_handler = set_error_handler("$object->errorHandler");

…and when you can’t. You’re basically bound to do like this:


require('Object.class.php');
$object = new Object();
function __errorHandler($errno, $errstr, $errfile, $errline, $errcontext) {
global $object;
$object->errorHandler($errno, $errstr, $errfile, $errline, $errcontext);
}
$oldErrorHandler = set_error_handler("__errorHandler");

Which is kind of sucky way of doing things… Basically what I’ve done is that my errorHandler will store all of the errors in an Array and I can just ask for the errors when I need to get them and it’ll return an Array of the errors. So I can easily foreach the errors in a Smarty template and not have to worry about the errors been print out anywhere or anytime they are triggered.

Took me some time to figure out a way to point to the function of this errorHandler class I wrote. This implementation is a hack but it works! It makes it easy to localize the errors if wanted because you can modify the errorHandling as you wish…

Here’s few documents where you can find more information about the error handling in PHP4

Oh well, that’s about it… Probably more about this later…

Powered by WordPress