[ale] hex

Dan Newcombe Newcombe at mordor.clayton.edu
Fri May 11 17:19:22 EDT 2001


On Fri, 11 May 2001, Stephen Turner wrote:
> well then, how do people program in machine language?

They usually don't.  They usually program in assembly language and then
run the code through an assembler to produce the machine language.

That way, instead of putting in 83 FB 00 75 0B CD 21, I can put in
cmp bx,0
jne :label
int 21
:label
rest of code - much easier...plus I can use things like :label instead of
putting hard addresses in there and let the assembler figure it out.

> i want to make REALLY tiny programs and if i use c c++
> or similar there will allways be unneeded code there
> from where it has to be compatible with many different
> instances... my understanding is when its compiled it

Usually when you compile C/C++ code, there are a bunch of libraries and
stuff it links to.  One thing it links to is the crt0??? code.  I can't
remember exaclty where it is, but it is the code that helps to load your
program in memory and then transfers execution to the main() function.

All of this code is useless for bios and booting, since most of it is
related to a specific OS.  For booting, the first sector of a disk is
loaded and then it jumps to a specific address within that sector.  That
is where your code starts.  Any thing else it needs to do, it better be
programmed to do.  At one point I had gone through and heavily commented
the boot.S of the kernel, right up until a little bit after it went into
protected mode - simple, elegant, and ugly :)


> faster not to mention its good practice :) your
> telling me i cant edit notepad? why do programs cease
> to work if you change the overall size of them in a
> hex editor? im here to learn! feed my hunger! hehhee 

You can edit notepad, you just have to be VERY careful.  If you go in and
find a string that says "Cannot Find" you can replace it with "Didn't
Find" with no problems - same number of characters.  But if you inserted
extra characters, you are gonna be throwing of locations of part of the
code and data.

Think of it like this.  Someone places you in a circular room and points
you towards the door.  You (blindfolded) walk in a perfectly straight
line. You will get to the door.  Now, imagine that once you started
walking to the door, someone spun the room a little bit.  Now, you will
not find the door.  You may be where you were told it was, but it just
isn't there.  So you panic, just like the machine :)

Another gotcha is that on the i386 architecture, not all opcodes are the
same size.  That means one instruction may be 8 bits long and another 6
and another 10.  This really makes editing the code sections of a program
by hand a nightmare.  Editing the data may or may not be as bad, depending
on if what you want to replace is compatiable.

Say you wanted to replace a default value of a program from 54600 to
80,000.  Not that big of an increase.  Well, if the data you were trying
to replace was a short int, which is normally just 2 bytes, you're in
trouble, because it can only a max of 65,355.  However, you need at least
one more byte to store 80,000.  So, if you replaced D5 48 (54600) with 
1 38 80 (80,000) you are now overwriting other areas of the data.  So now
instead of the File menu you may have the Bile menu :)

So yeah...you can do it, but it isn't that safe.

--
To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.





More information about the Ale mailing list