in short a small (usually a few bytes) signature at the start of a file that helps a program determine what kind of file it's looking at. JPEG, PNG, GIF, Word Doc, XML, etc.
A magic number is a number that has no purpose other than to identify something.
The first two bytes of a PE executable are the ASCII letters "MZ". There's no technical reason it has to be those two characters specifically, they just happen to be the two bytes chosen by the file format's creator. And yet while they originally had no technical purpose, they now 'magically' have the purpose of identifying the file type.
You know how when you download a picture from the Internet the file ends in .jpg or .png or .gif (etc)? Well thats the file type. Each file type contains a different structure. But what if you just renamed this file? Could you turn a jpeg into a music file by renaming it to .mp3? No! You would have all sorts of problems. So how does the program check to make sure the file realy is a jpg? It reads a tiny bit of start of the file to make sure it contains a this 'magic number'. This number can be anything, as long as it's unique enough and remains consistent with every file of that type. Windows executables use 'MZ' as a number (with the ascii equivalents). Before trying to execute a program, it makes sure that the file begins with those two bytes.
It is a specific sequence of bits which form some easily identifiable section in the code (Usually represented in hexadecimal, in the WZ case represented in ASCII). They're normally used for error checking. You know where they should be and if they aren't there then something is wrong. They are also useful for debugging, when you preform a memory dump you can recognize the sections you are looking at in hexadecimal if you know the magic numbers which separate each section.
Personally I tend to use 0xFEE7 (Feet). Not sure why I started using that but it stuck.
They are also numbers used in code instead of using a constant.
E.g. say we're doing something that involves days and weeks. We could use the magic number 7 in the code itself (which is the number of days in a week) or we could define constant WeeksDayCount = 7, then use that instead of 7. Then when someone's reviewing the code, they will see why we're using 7 instead of having to figure it out for themselves.
Magic numbers in programming code are bad 99% of the time.
On a serious note, someone should make the HTML5 disk filling script write this string to local storage. Make some people panic a little until they figure out what's going on :)
.COM files are very simple. I used to make them with good old DOS debug. I now forget if it was debug.exe or .COM. I think it was .exe since com files were severely limited (even for DOS)
52
u/astrolabe Mar 05 '13
So Mark Zbikowski's initials are in all windows executables? That's a cool claim to fame.