News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

fda2 from "\masm32\tools"

Started by jdoe, December 07, 2008, 09:08:36 AM

Previous topic - Next topic

jdoe


I've worked on a program like fda2 (which is a bin2obj program). After having read the pecoff_v8 documentation from Microsoft to understand how it worked, I noticed what I'm not sure to call a mistake because the object file created by fda2 work as it should.

From pecoff_v8...




So the struct member LongName should be replaced by ShortName in the code below but it seems to have no incidence on the result. Don't ask me why.


  ; -----------------
  ; COFF SYMBOL TABLE
  ; -----------------
    lea eax, ist.N.LongName
    mov DWORD PTR [eax], 0    ; zero fill 1st 4 bytes
    mov DWORD PTR [eax+4], 4  ; OFFSET is 4th byte into the string table



And just as a side note these two flags are obsolete / not needed.


  ; -----------------
  ; IMAGE_FILE_HEADER
  ; -----------------
    mov ifh.Characteristics, IMAGE_FILE_RELOCS_STRIPPED or \
                             IMAGE_FILE_LINE_NUMS_STRIPPED



Knowing the internals of pe files is not what interest me most but the possibilities it gives are not the least. I should do like Vortex and build few conversion programs to get used to pe structure more seriously.


Vortex

#1
Hi jdoe,

In the MS COFF symbol table, a short symbol can be expressed as a long symbol. The File Data Assembler tool converts all the symbols to long without any problem. To design my bin2coff tool, I decided to follow strictly the MS COFF specification to avoid possible COFF compatibility problems with different versionf of MS COFF  linkers but assuming that all the symbols are long type does not pose a problem.

If a COFF symbol has a size of 8 bytes or less then it's processed as short symbol. Otherwise, it will be written as long symbol.

Doing some experiments, I noticed that the Characteristics field is filled with the ZERO value. This is what I saw while testing Masm and SolAsm.

Personaly, I prefer to follow the MS COFF specification to avoid any minor problems. The best answer would be test different MS COFF object file outputs with different linkers to test various scenarios. Attached is my first attemp to create a simple test bed.

LATER : Added Goasm sample

Characteristics : IMAGE_FILE_32BIT_MACHINE

You can use Wayne J. Radburn's PEview Version 0.9.8 to analyze MS COFF object modules :

Quotemy quick and easy way to view the structure and content of 32-bit Portable Executable (PE) and Component Object File Format (COFF) files which supports the viewing of EXE, DLL, OBJ, LIB, DBG, and other file types.

http://www.magma.ca/~wjr/

[attachment deleted by admin]

Vortex

Additional tests :

#include <stdio.h>

char *TestSym="This is a test file.";



Analyzing the MS COFF object modules :

MS Visual Studio Express Edition 2005 :

Characteristics : 0

Pelles ISO C Compiler, Version 5.00.13 :

Characteristics : IMAGE_FILE_32BIT_MACHINE

jdoe


Hi Vortex,

Few fields in there must be just some kind of informations. For something like fda, getting the key fields at the right place seems to be enough for the ms linker.

PEview look good, I think it's gonna be usefull for me but I have a problem... it crash everytime I try to see the IMAGE_FILE_HEADER.


jdoe


I have a question about alignment. Why the IMAGE_SYMBOL structure, which comes after the data, don't need to be align on a 4 byte boundary ?

My guess would be that it is preferable.

Vortex

Hi Jdoe,

You are right. The structure should be probably aligned.