Repository navigation
Conversation
epSection is stored as the text "name|index", so split('|')[1] yields a
string. Comparing it to 6 is silently False on Python 2, leaving the
highest-weighted packer rule (+60) unreachable and every score 60 low.
Cast the index to int, bound it against len(secEntropies) instead of the
off-by-one "<= 6", and skip rows whose entropy cell is empty, which
happens when the entry point falls outside every section of a sample
with fewer than six sections.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BLUF
epSecIndexwas a string, so the packer rule that compares it to6and indexessecEntropieswith it never ran.intand bound the index against the actual list length, plus skip rows whose entropy value is empty.standalone/Kinginyourcastle.py. No behaviour change anywhere outside--packerdatascoring.What was wrong
check_ep_section()returns the entry-point section as the textname|index(e.g.
.text|0), andDatabase.pystores it in theepSectiontext column.In the packer-scoring loop:
str.split()returns strings, and the value is never cast. Under Python 2 —the only interpreter this file runs on —
'0' <= 6is alwaysFalse, becausestrings sort above ints in CPython 2's default cross-type ordering. The branch
therefore never executed and the failure was completely silent: no exception,
no log line.
Two further problems were hidden behind that dead branch:
secEntropiesalways holds exactly six items (Database.pyselectssecEntropy1..secEntropy6), so valid indices are0..5. The bound<= 6is off by one: index
6would raiseIndexErrorthe moment the comparisonstarted working.
check_ep_section()returnspos == len(pe.sections). For a sample with fewer than six sections thecorresponding
secEntropycolumn holds the empty string (absent sections arestored as
"", not NULL), sofloat('')would raiseValueError— which,being unhandled, would abort the whole
update_packedpass for everyremaining row. That combination — entry point outside any section, few
sections — is a classic packed/malformed-PE signature, i.e. exactly the
population this script exists to score.
Impact
Entry-point section entropy is the single strongest packer signal in this
heuristic, weighted
+60against the next-highest+90/+50. Because therule never fired, every score written by
--packerdatahas been low by 60 forthe samples it was designed to flag, compressing the packed/not-packed
separation the score is supposed to provide.
Note for consumers: after this fix, scores for affected samples rise by
60.
update_packed()only stores the value, and nothing in this repositorythresholds on the
packedcolumn, but anything downstream that does will see ashifted distribution.
What this changes
standalone/Kinginyourcastle.py, one hunk:int(...)makes the value usable both as a comparison operand and as a list index.< len(secEntropies)replaces<= 6, fixing the off-by-one without hardcodingthe width a second time. The existing comment stays accurate.
and secEntropies[epSecIndex]mirrors theif item[5]:idiom used a few linesabove and keeps the now-reachable branch from crashing on an empty entropy cell.
Nothing else is touched: no reformatting, no modernisation, no dependency changes.
How it was verified
This repository has no test suite, no build system and no CI, so the rule was
reproduced standalone and exercised directly (the module itself is Python 2
only —
printstatements,file(),pefile— so it cannot be imported underpython3):
, all entropies7.1`+0(rule dead), 1-section sample (['7.1','','','','','']`)The pre-fix comparison
'0' <= 6was confirmed to be a silent no-op rather thanan error on Python 2 (it raises
TypeErroron Python 3, which is how the deadbranch is demonstrable today).
Syntax was checked with
bash -n hashes-extract.shand by AST-parsing thepatched module; the file's pre-existing Python 2 syntax (line 389) is unchanged
by this patch and fails to parse under python3 at HEAD as well.