Skip to content

Commit

Permalink
Merge branch 'topic/bbannier/spicy-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Aug 28, 2023
2 parents e9e5ff7 + ce46e8e commit eef3312
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
54 changes: 35 additions & 19 deletions analyzer/analyzer.spicy
Original file line number Diff line number Diff line change
Expand Up @@ -467,36 +467,52 @@ type ImportLookupTable = unit(f: ImageFile) {
};

type ImportLookupTableEntry = unit(f: ImageFile) {
var full: uint64;
var importByName: bool;
var ordinal: uint16;
var hintNameRVA: uint32;

switch ( f.peFileFormat ) {
PE32 -> entry: bitfield(32) {
full: 0..31 &convert=cast<uint64>($$);
importByName: 31 &convert=cast<bool>(! $$);
ordinal: 0..15 &convert=cast<uint16>($$);
hintNameRVA: 0..30 &convert=cast<uint32>($$);
};
PE32_Plus -> entry: bitfield(64) {
full: 0..63 &convert=cast<uint64>($$);
importByName: 63 &convert=cast<bool>(! $$);
ordinal: 0..15 &convert=cast<uint16>($$);
hintNameRVA: 0..30 &convert=cast<uint32>($$);
};
PE32 -> : bitfield(32) {
full: 0..31;
importByName: 31;
ordinal: 0..15;
hintNameRVA: 0..30;
} {
self.full = cast<uint64>($$.full);
self.importByName = cast<bool>(! $$.importByName);
self.ordinal = cast<uint16>($$.ordinal);
self.hintNameRVA = cast<uint32>($$.hintNameRVA);
}

PE32_Plus -> : bitfield(64) {
full: 0..63;
importByName: 63;
ordinal: 0..15;
hintNameRVA: 0..30;
} {
self.full = cast<uint64>($$.full);
self.importByName = cast<bool>(! $$.importByName);
self.ordinal = cast<uint16>($$.ordinal);
self.hintNameRVA = cast<uint32>($$.hintNameRVA);
}
};

: void
{
if ( self.importByName )
self.hintNameOffset = rvaToOffset(f, self.hintNameRVA);
}

hintName: HintName
&parse-at=checkpointOffset(f.peStart + *self.hintNameOffset, f.consumedOffsets)
if ( self.hintNameOffset );

on entry
{
if ( self.entry.importByName )
self.hintNameOffset = rvaToOffset(f, self.entry.hintNameRVA);
}

var hintNameOffset: Offset;
};

function isNull(e: ImportLookupTableEntry): bool
{ return e.entry.full == 0; }
{ return e.full == 0; }

type HintName = unit {
hint: uint16;
Expand Down
8 changes: 4 additions & 4 deletions analyzer/zeek_analyzer.spicy
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,16 @@ public function makeImportTable(idt: PE::ImportDirectoryTable): ImportTable
{
local imp: Import;

if ( i.entry.importByName )
if ( i.importByName )
{
if ( i.hintNameOffset )
imp = (i.entry.hintNameRVA,
imp = (i.hintNameRVA,
i.hintName.hint, i.hintName.name, Null);
else
imp = (i.entry.hintNameRVA, Null, Null, Null);
imp = (i.hintNameRVA, Null, Null, Null);
}
else
imp = (Null, Null, Null, i.entry.ordinal);
imp = (Null, Null, Null, i.ordinal);

imports.push_back(imp);
}
Expand Down

0 comments on commit eef3312

Please sign in to comment.