PE Malware Detector
A byte-level neural network that reads a whole Windows program file (.exe / .dll) and estimates
whether it is malware. It is trained on files from 2021β2024 and tested on files from 2026, to measure
how well it detects malware that did not exist when it was trained.
β οΈ Safety. This repository contains no malware and no binaries: only code, model weights, hashes and numeric features. The dataset can be rebuilt with a script, on Linux only. Never run or open the files it downloads.
Results
Trained on 60,786 files (2021β2024). The decision threshold was chosen on the 2025 validation set to allow about 1% false alarms, then fixed; the 2026 test set was scored once.
| Validation (2025) | Test (2026) | |
|---|---|---|
| Files (benign / malware) | 2,874 / 2,599 | 4,281 / 2,129 |
| AUC | 0.984 | 0.952 |
| Malware detected (recall) | 82.2% | 60.0% |
| Benign files flagged (false-positive rate) | 0.97% | 1.19% |
| Precision | 98.7% | 96.2% |
| F1 | 0.897 | 0.739 |
| Balanced accuracy | 90.6% | 79.4% |
Test confusion matrix: 4,230 benign correct, 51 benign flagged, 1,278 malware caught, 851 malware missed.
Compared with two baselines
Both baselines were trained on the same files and scored on the same test set, each with its own threshold chosen on validation for 1% false alarms.
- MalConv (Raff et al., 2017): a byte-level convolutional network that reads the first 1 MB.
- LightGBM on a byte histogram, byte entropy and file size.
| Test set (2026) | MalConv | LightGBM | This model |
|---|---|---|---|
| Parameters | 1,042,953 | β | 534,098 |
| AUC | 0.860 | 0.923 | 0.952 |
| Malware detected (recall) | 34.3% | 44.4% | 60.0% |
| Precision | 95.3% | 95.3% | 96.2% |
| F1 | 0.504 | 0.606 | 0.739 |
| Balanced accuracy | 66.7% | 71.6% | 79.4% |
| False-positive rate | 0.84% | 1.10% | 1.19% |
On validation (2025) the three score an AUC of 0.957, 0.980 and 0.984. The gap widens on 2026 files: this model detects nearly twice as much new malware as MalConv with half the parameters.
Why the test score is lower than validation
The test set is one year further from the training data, and almost half of its malware (1,003 of 2,129 files) belongs to a family that is new or unnamed. A random split of the same data would have reported an AUC of 0.99 for the baseline; the time split shows the harder, more realistic number.
How the model works
- Chunk. The file is cut into 4,096-byte chunks, as many as it needs (up to 16 MB).
- Encode. A small shared convolutional network turns each chunk into a vector. Each chunk also gets its position in the file, three statistics (byte entropy, share of zero bytes, share of printable text) and a tag for the PE region it lies in (header, code, data, resources, overlay).
- Pool. Neighbouring chunks are merged into 256 segments, keeping the maximum and the average of their vectors, so a file of any size becomes 256 vectors.
- Attend. Two transformer layers let the segments exchange information. Each segment has a learned position.
- Classify. An attention-weighted average of the segments goes to a small classifier that outputs the malware probability.
The model has 534,098 parameters. It can be fed a file piece by piece (begin β feed β finalize),
so memory use does not grow with file size. During training, half of each file's chunks are dropped
at random on every pass, which was the single most effective measure against overfitting.
Using the model
pip install -r requirements.txt
python src/predict.py /path/to/file.exe
import sys; sys.path.insert(0, "src")
from predict import load_model, predict
model, threshold = load_model() # model/model.pt + model/model_config.json
predict("/path/to/file.exe", model, threshold=threshold)
# "Malware" or "Benign" (or a message if the file is not a PE file)
The file is opened read-only and read as bytes, 1 MB at a time. It is never executed.
Demo app
A small browser app: drop a .exe or .dll on the page and it shows the verdict and the model's confidence.
pip install -r requirements.txt
python app/app.py
Then open http://127.0.0.1:7860 in a browser on the same machine. In Colab, use
python app/app.py --share for a temporary public link.
- The model is loaded once when the app starts.
- Empty files and files that are not Windows PE files get a clear message instead of a verdict.
- The uploaded file is only read as bytes, never run. Its temporary copy is made read-only and deleted
right after the check. For extra safety, point
GRADIO_TEMP_DIRat a folder mountednoexec. - Only test with malware from inside an isolated Linux environment. Do not download malware to a Windows machine to try the app.
AI assistance. An AI assistant (Claude) helped build the app: it wrote the first version of the
Gradio page, the input checks (empty file, missing MZ / PE signature) and the clean-up of the
temporary upload. I reviewed and tested the code and am responsible for it.
Dataset
72,669 Windows PE files (.exe and .dll), about 155 GB in total, collected for this project and
split by the date each file first appeared.
Size and split
| Split | Period | Benign | Malware | Total | Malware share | Size |
|---|---|---|---|---|---|---|
| Train | 2021β2024 | 23,947 | 36,839 | 60,786 | 60.6% | 120 GB |
| Validation | 2025 | 2,874 | 2,599 | 5,473 | 47.5% | 16 GB |
| Test | 2026 (JanβNov) | 4,281 | 2,129 | 6,410 | 33.2% | 20 GB |
| All | 31,102 | 41,567 | 72,669 | 57.2% | 155 GB |
Files range from a few kilobytes to 16 MB (median 715 KB); 41% are larger than 1 MB.
Sources
| Source | Class | Files | What it is | How files were chosen |
|---|---|---|---|---|
| MalwareBazaar | Malware | 41,567 | Public malware-sharing site run by abuse.ch; 941 daily archives were used | PE files with a family name, at most 300 per family per split; 1,195 families |
| Scoop | Benign | 21,750 | Package catalogue for Windows software (buckets Main, Extras, Versions) | Programs and libraries unpacked from dated releases of 2,233 apps |
| winget | Benign | 9,352 | Microsoft's community package catalogue | Programs and libraries unpacked from dated releases of 2,666 apps |
Every file was checked to be a real PE file by its MZ and PE signatures. Exact duplicates, files
over 16 MB, files with an unreadable header, and files that appeared as both benign and malware were removed.
Structure
The repository holds no program files. The dataset is published as a list of files plus a script that downloads them again from the sources above and checks each one against its SHA-256 hash.
| File | Contents |
|---|---|
dataset/manifest.csv |
One row per file: sha256, label (0 benign, 1 malware), source, split, size_bytes, plus date, malware family, app name, processor type, program-or-library flag, and the download location for benign files |
dataset/build_dataset.py |
Rebuilds the files into data/<split>/<benign or malware>/<sha256> |
dataset/features.parquet |
Numbers only, one row per file: size, byte entropy, a 256-value byte histogram and a few header facts |
dataset/collection_summary.csv |
How many files were collected, dropped and kept at each step |
data/
βββ train/ benign/ malware/
βββ val/ benign/ malware/
βββ test/ benign/ malware/ each file is named by its SHA-256, with no extension
Why it is split by time
A model trained on older files and tested on newer ones is measured the way it would be used. On this data, a random split makes a simple baseline look about twice as good at detecting malware as it is on the following year's files. Nearly half of the test malware belongs to a family that is new or unnamed.
More detail: dataset/README.md covers the decisions and limitations, and
notebooks/data_exploration.ipynb has the analysis behind each decision.
Intended use and limitations
This is a research and learning project, not a replacement for antivirus software.
- It misses 40% of next-year malware at the chosen threshold. A file it calls benign is not proven safe.
- Windows PE files only, up to 16 MB.
- The probability is not calibrated. The model is overconfident, so use the label at the stored threshold (0.9856), not the raw number.
- Benign training data comes from two package catalogues. Commercial software, games and drivers are under-represented, so false alarms may be more frequent on those.
- It reads static bytes only. It never runs the file, and heavily packed or encrypted malware hides most of what it could learn from.
Repository contents
| Path | Contents |
|---|---|
dataset/ |
Manifest, build script, numeric features and the dataset README |
notebooks/data_exploration.ipynb |
Data exploration and justification |
notebooks/model_training.ipynb |
MalConv baseline, model design, training, threshold choice and test evaluation |
model/model.pt, model/model_config.json |
Trained weights (plain state_dict), network settings and decision threshold |
model/malconv_baseline.pt |
Weights of the MalConv baseline |
model/test_results.json, model/malconv_test_results.json, model/roc_final.png |
Validation and test figures, ROC curves |
src/ |
Model definition (whole_model.py), MalConv (malconv.py), predict.py, training and evaluation scripts |
requirements.txt |
Python packages needed |
app/app.py |
Drag-and-drop demo (Gradio) |