Mz, bsjb, and the joys of "magic" constants in managed assemblies.

Source: Internet
Author: User
[Original article link: http://www.moserware.com/2007/11/mz-bsjb-and-joys-of-magic-constants-in.html] When I was 10 or so, I Thought You cocould open up. EXE in a text editor and do meaningful work with it if you only knew some magical secret. I noticed that all exes started with the letters "MZ" as in the cmd. EXE example above, but that's as far as I got.

A few years later, I read this article in the special 20th anniversary edition of Byte magazine that let me know that "MZ" stood for the initials of Mark zbikoski who designed the MS-DOS executable file format. needingSomeMagic number to identify bits as an executable, what better choice than your own initials (in Mark's case 0x4d5a )? This is actually very common knowledge that won't get you points at your next nerd dinner.

However, today I will share a point generating piece of knowledge (well for at least a year or so)... without further ado:


In every piece of managed code, you'll find the four bytes (little-Endian DWORD) of 0x000034a42, (of course, in big-Endian 0x0000a534a ). this corresponds to the start of the "General metadata Header" of an assembly.

The initials correspond BRian Harry, SUsan Radke-sproull, JASON Zander, and BIll Evans who were part of the team in 1998 that worked on the CLR.

I discovered this gem while reading page 76 of expert. NET 2.0 il explorer. After googling for it though it appears that it's been covered elsewhere too.

With this knowledge, you can write a very simple program that checked to see if a file was. net assembly by looking for a start of "MZ" that also contained "bsjb. "It looks like the first" virus "that targeted. net took advantage of this fact.

Now, where can I put "jdm "?

-------------------------------------

"When I was 10 or so, I Thought You cocould open up a. EXE in a text editor and do meaningful work with it if you only knew some magical secret ."

I was thinking exactly the same when I was first introduced to computers. I was opening any file (text or binary) with a text editor and fiddling around.

BTW The compiled. java files,. class files, start with these 4 Bytes: 0xca 0xfe 0xba 0xbe aka cafe babe and ZIP files start with PK.

-------------------------------------

Huseyin: Good point on 0 xcafebabe and PK. similar things can be said for WAV, GIF, and other files. I think that Apache's mimemagic module (and similar modules) looks for these to determine the real file type.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.