Map and projects (the most frequently updated page of this blog)

2010/03/19

You can't hide nowhere, with the torchlight on

a emptier TinyPE
TinyPE is an impressive project, that explains step-by-step how to make an incredible 97 bytes functional PE. It also shows that a PE can't be any smaller, otherwise IMAGE_OPTIONAL_HEADER32.Subsystem, which is a critical field, wouldn't be defined - it's even already shortened from a word to a byte.

However, the original TinyPE still defines a section and SizeOfOptionalHeader, which are not necessary.
Removing them makes such a PE not only Tiny, but also very small in amount of information - yet it works, naturally, and there's quite some room for code (relatively).
In the end, here are the only defined fields, across all PE headers fields:
.e_magic
...
NT_SIGNATURE
...
Machine
...
Characteristics
Magic
...
AddressOfEntryPoint
...
ImageBase
SectionAlignment ; also e_lfanew
FileAlignment
...
MajorSubsystemVersion
...
SizeOfImage
SizeOfHeaders
...
Subsystem

source binary


un TinyPE encore plus vide
TinyPE est un projet impressionant, qui explique étape par étape comment faire un PE fonctionnel de 97 octets. Il montre aussi qu'on ne peut pas faire un PE plus petit, sans quoi IMAGE_OPTIONAL_HEADER32.Subsystem, qui est un champ critique, ne serait pas défini - il est d'ailleurs déjà réduit de mot à octet.

Cependant, le TinyPE original défini encore une section et SizeOfOptionalHeader, qui ne sont pas nécessaires.
Les enlever fait un PE non seulement ridicule, mais aussi avec une quantité d'information très faible - pourtant il fonctionne, bien évidemment, et laisse relativement pas mal de place pour y mettre du code.
Au final, voici les seuls champs définis, parmi tous ceux des en-têtes de PE:
.e_magic
...
NT_SIGNATURE
...
Machine
...
Characteristics
Magic
...
AddressOfEntryPoint
...
ImageBase
SectionAlignment ; also e_lfanew
FileAlignment
...
MajorSubsystemVersion
...
SizeOfImage
SizeOfHeaders
...
Subsystem

source binaire

2 comments:

  1. Same thing for ELF format :
    http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html

    ReplyDelete
  2. Thanks for the link.
    Sadly, I'm too busy to play with other OSes :( (maybe that's a good thing actually, it means I have already a lot of projects)

    ReplyDelete