[ANN] peettles - low level windows file format parsing

  • From: William Adams <william_a_adams@xxxxxxxxxxx>
  • To: "luajit@xxxxxxxxxxxxx" <luajit@xxxxxxxxxxxxx>
  • Date: Tue, 14 Aug 2018 16:24:47 +0000

This is similar to my previously announced pereader, but goes further in 
multiple directions.

https://github.com/wiladams/peettles

Whereas the pereader (https://github.com/wiladams/LJITPEReader) is focused on 
only PE files, I wanted to start afresh and go after other things.

.lib
.pdb
.exe
.dll
.obj

They're all kinda related, and kinda different.  For example, parsing a .obj 
file standalone, particularly if it has debug info, is different than if it's 
in an 'import library'.  And, there are two flavors of .lib.  One is as an 
"import" library (adjunct to a .dll or .exe), or it's a primary archive of .obj 
files.

Many of the .obj file parsers I've looked at do things at a fairly surface 
level, like finding the name of a module, but not much else.  I try to go as 
deep as I can, like looking at symbols, and auxiliary symbols.  There's a lot 
more that could be done, particularly around debug info, so work in progress.

The .pdb files have been my latest adventure.  These files contain a ton of 
debug information, enough to easily reconstruct an appropriate 'cdef' for 
LuaJIT ffi.  There are two little utilities in the 'testy' directory.

pdb2lua.lua - Turns the meta data of a .pdb file into a lua table.  Of course, 
the 'parse_pdb.lua' does all the parsing, and the utility just does pretty 
printing.

pdb2strm.lua - Turns the individual streams of the .pdb file into individual 
files in a directory.  This is great for those cases when you want to extract a 
single stream to play with in isolation for whatever reason.  Perhaps you want 
to have a much simpler representation of specific information to use for a 
debugging database.

obj2lua.lua - Turn standalone obj into a lua table.  Same deal as the other 
ones.  Parsing is done, then pretty printing.

pecoff2lua.lua - Turn a pecoff file, typically a .dll or .exe into a lua table 
(pretty printing).


I think this is a good set of toys to start playing with if you're interested 
in such things.  For my own part, I'm essentially writing the code I need to 
performs tasks I have, adding in interesting bits as I need them.  Next bits 
for me will be expanding on the .pdb stuff, a discontiguous block stream, so I 
don't have to write streams out to a file first.

In addition to being generally useful utilities, they serve as some clean 
documentation of how these files actually work.  I try, either through the 
code, or comments within the same, to explain things along the way, and give 
all the references I've used to stitch things together.

Enjoy, if it so pleases you.

-- William

Other related posts:

  • » [ANN] peettles - low level windows file format parsing - William Adams