Skip to content
This repository was archived by the owner on Sep 10, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ CC = gcc
CCFLAGS = -O3 -Wextra -Wall -Werror
LDFLAGS =
OUTPUT = data
CFILES = src/*
$(OUTPUT):
$(CC) $(CFILES) $(CCFLAGS) $(LDFLAGS) -o $(OUTPUT)
CMAIN = src/main.c
$(OUTPUT): clean
$(CC) $(CMAIN) $(CCFLAGS) $(LDFLAGS) -o $(OUTPUT)
clean:
rm -rf $(OUTPUT)
install:
cp $(OUTPUT) /bin/
remove:
rm /bin/$(OUTPUT)
rm /bin/$(OUTPUT)
33 changes: 13 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
data [file] #lookup file
data --help #show help
data -h #show help
data --license #show license
data -l #show license
```
### Building from source:
```bash
Expand All @@ -23,23 +25,14 @@ make install #install into /bin/
make remove #remove from /bin/
```
### Format support:
| Status | Format |
|------------|-------|
| ✅ | ELF |
| ✅ | EXE |
| ✅ | PNG |
| ✅ | JPG |
| ✅ | GIF |
| ✅ | ZIP |
| ✅ | RAR |
| ✅ | GZIP |
| ✅ | 7z |
| ❌ | Mach-O |
| ✅ | PDF |
| ✅ | MP3 |
| ✅ | MP4 |
| ❌ | AVI |
| ❌ | MOV |
| ❌ | WAV |
| ❌ | ISO |
| ✅ | SH Script |
> See [./src/magic.h](src/magic.h)

- Images: BMP, PNG, JPEG, QOI, GIF, TIFF, WEBP
- Audio: WAV, MP3, OGG, QOA, AIFF, MIDI, FLAC
- Video: MP4, AVI
- Multimedia: PDF, Blender, glTF, MD2
- Fonts: WOFF, WOFF2, OpenType
- Executables: ELF, EXE, WebAssembly, JAR, Luac
- Archives: Tar, ZIP, GZIP, XZ, LZIP, 7-Zip, RAR, BZip, CPIO, PAK, .deb, .rpm
- Binary Data: qcow, ISO
- Other: XML, Shebang scripts, SSH keys, Shortcuts
12 changes: 0 additions & 12 deletions include/magic.h

This file was deleted.

78 changes: 78 additions & 0 deletions src/license.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
char LICENSE[] = {
0x54,0x68,0x69,0x73,0x20,0x69,0x73,0x20,0x66,0x72,0x65,0x65,0x20,0x61,0x6e,0x64,
0x20,0x75,0x6e,0x65,0x6e,0x63,0x75,0x6d,0x62,0x65,0x72,0x65,0x64,0x20,0x73,0x6f,
0x66,0x74,0x77,0x61,0x72,0x65,0x20,0x72,0x65,0x6c,0x65,0x61,0x73,0x65,0x64,0x20,
0x69,0x6e,0x74,0x6f,0x20,0x74,0x68,0x65,0x20,0x70,0x75,0x62,0x6c,0x69,0x63,0x20,
0x64,0x6f,0x6d,0x61,0x69,0x6e,0x2e,0x0a,0x0a,0x41,0x6e,0x79,0x6f,0x6e,0x65,0x20,
0x69,0x73,0x20,0x66,0x72,0x65,0x65,0x20,0x74,0x6f,0x20,0x63,0x6f,0x70,0x79,0x2c,
0x20,0x6d,0x6f,0x64,0x69,0x66,0x79,0x2c,0x20,0x70,0x75,0x62,0x6c,0x69,0x73,0x68,
0x2c,0x20,0x75,0x73,0x65,0x2c,0x20,0x63,0x6f,0x6d,0x70,0x69,0x6c,0x65,0x2c,0x20,
0x73,0x65,0x6c,0x6c,0x2c,0x20,0x6f,0x72,0x0a,0x64,0x69,0x73,0x74,0x72,0x69,0x62,
0x75,0x74,0x65,0x20,0x74,0x68,0x69,0x73,0x20,0x73,0x6f,0x66,0x74,0x77,0x61,0x72,
0x65,0x2c,0x20,0x65,0x69,0x74,0x68,0x65,0x72,0x20,0x69,0x6e,0x20,0x73,0x6f,0x75,
0x72,0x63,0x65,0x20,0x63,0x6f,0x64,0x65,0x20,0x66,0x6f,0x72,0x6d,0x20,0x6f,0x72,
0x20,0x61,0x73,0x20,0x61,0x20,0x63,0x6f,0x6d,0x70,0x69,0x6c,0x65,0x64,0x0a,0x62,
0x69,0x6e,0x61,0x72,0x79,0x2c,0x20,0x66,0x6f,0x72,0x20,0x61,0x6e,0x79,0x20,0x70,
0x75,0x72,0x70,0x6f,0x73,0x65,0x2c,0x20,0x63,0x6f,0x6d,0x6d,0x65,0x72,0x63,0x69,
0x61,0x6c,0x20,0x6f,0x72,0x20,0x6e,0x6f,0x6e,0x2d,0x63,0x6f,0x6d,0x6d,0x65,0x72,
0x63,0x69,0x61,0x6c,0x2c,0x20,0x61,0x6e,0x64,0x20,0x62,0x79,0x20,0x61,0x6e,0x79,
0x0a,0x6d,0x65,0x61,0x6e,0x73,0x2e,0x0a,0x0a,0x49,0x6e,0x20,0x6a,0x75,0x72,0x69,
0x73,0x64,0x69,0x63,0x74,0x69,0x6f,0x6e,0x73,0x20,0x74,0x68,0x61,0x74,0x20,0x72,
0x65,0x63,0x6f,0x67,0x6e,0x69,0x7a,0x65,0x20,0x63,0x6f,0x70,0x79,0x72,0x69,0x67,
0x68,0x74,0x20,0x6c,0x61,0x77,0x73,0x2c,0x20,0x74,0x68,0x65,0x20,0x61,0x75,0x74,
0x68,0x6f,0x72,0x20,0x6f,0x72,0x20,0x61,0x75,0x74,0x68,0x6f,0x72,0x73,0x0a,0x6f,
0x66,0x20,0x74,0x68,0x69,0x73,0x20,0x73,0x6f,0x66,0x74,0x77,0x61,0x72,0x65,0x20,
0x64,0x65,0x64,0x69,0x63,0x61,0x74,0x65,0x20,0x61,0x6e,0x79,0x20,0x61,0x6e,0x64,
0x20,0x61,0x6c,0x6c,0x20,0x63,0x6f,0x70,0x79,0x72,0x69,0x67,0x68,0x74,0x20,0x69,
0x6e,0x74,0x65,0x72,0x65,0x73,0x74,0x20,0x69,0x6e,0x20,0x74,0x68,0x65,0x0a,0x73,
0x6f,0x66,0x74,0x77,0x61,0x72,0x65,0x20,0x74,0x6f,0x20,0x74,0x68,0x65,0x20,0x70,
0x75,0x62,0x6c,0x69,0x63,0x20,0x64,0x6f,0x6d,0x61,0x69,0x6e,0x2e,0x20,0x57,0x65,
0x20,0x6d,0x61,0x6b,0x65,0x20,0x74,0x68,0x69,0x73,0x20,0x64,0x65,0x64,0x69,0x63,
0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6f,0x72,0x20,0x74,0x68,0x65,0x20,0x62,0x65,
0x6e,0x65,0x66,0x69,0x74,0x0a,0x6f,0x66,0x20,0x74,0x68,0x65,0x20,0x70,0x75,0x62,
0x6c,0x69,0x63,0x20,0x61,0x74,0x20,0x6c,0x61,0x72,0x67,0x65,0x20,0x61,0x6e,0x64,
0x20,0x74,0x6f,0x20,0x74,0x68,0x65,0x20,0x64,0x65,0x74,0x72,0x69,0x6d,0x65,0x6e,
0x74,0x20,0x6f,0x66,0x20,0x6f,0x75,0x72,0x20,0x68,0x65,0x69,0x72,0x73,0x20,0x61,
0x6e,0x64,0x0a,0x73,0x75,0x63,0x63,0x65,0x73,0x73,0x6f,0x72,0x73,0x2e,0x20,0x57,
0x65,0x20,0x69,0x6e,0x74,0x65,0x6e,0x64,0x20,0x74,0x68,0x69,0x73,0x20,0x64,0x65,
0x64,0x69,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x74,0x6f,0x20,0x62,0x65,0x20,0x61,
0x6e,0x20,0x6f,0x76,0x65,0x72,0x74,0x20,0x61,0x63,0x74,0x20,0x6f,0x66,0x0a,0x72,
0x65,0x6c,0x69,0x6e,0x71,0x75,0x69,0x73,0x68,0x6d,0x65,0x6e,0x74,0x20,0x69,0x6e,
0x20,0x70,0x65,0x72,0x70,0x65,0x74,0x75,0x69,0x74,0x79,0x20,0x6f,0x66,0x20,0x61,
0x6c,0x6c,0x20,0x70,0x72,0x65,0x73,0x65,0x6e,0x74,0x20,0x61,0x6e,0x64,0x20,0x66,
0x75,0x74,0x75,0x72,0x65,0x20,0x72,0x69,0x67,0x68,0x74,0x73,0x20,0x74,0x6f,0x20,
0x74,0x68,0x69,0x73,0x0a,0x73,0x6f,0x66,0x74,0x77,0x61,0x72,0x65,0x20,0x75,0x6e,
0x64,0x65,0x72,0x20,0x63,0x6f,0x70,0x79,0x72,0x69,0x67,0x68,0x74,0x20,0x6c,0x61,
0x77,0x2e,0x0a,0x0a,0x54,0x48,0x45,0x20,0x53,0x4f,0x46,0x54,0x57,0x41,0x52,0x45,
0x20,0x49,0x53,0x20,0x50,0x52,0x4f,0x56,0x49,0x44,0x45,0x44,0x20,0x22,0x41,0x53,
0x20,0x49,0x53,0x22,0x2c,0x20,0x57,0x49,0x54,0x48,0x4f,0x55,0x54,0x20,0x57,0x41,
0x52,0x52,0x41,0x4e,0x54,0x59,0x20,0x4f,0x46,0x20,0x41,0x4e,0x59,0x20,0x4b,0x49,
0x4e,0x44,0x2c,0x0a,0x45,0x58,0x50,0x52,0x45,0x53,0x53,0x20,0x4f,0x52,0x20,0x49,
0x4d,0x50,0x4c,0x49,0x45,0x44,0x2c,0x20,0x49,0x4e,0x43,0x4c,0x55,0x44,0x49,0x4e,
0x47,0x20,0x42,0x55,0x54,0x20,0x4e,0x4f,0x54,0x20,0x4c,0x49,0x4d,0x49,0x54,0x45,
0x44,0x20,0x54,0x4f,0x20,0x54,0x48,0x45,0x20,0x57,0x41,0x52,0x52,0x41,0x4e,0x54,
0x49,0x45,0x53,0x20,0x4f,0x46,0x0a,0x4d,0x45,0x52,0x43,0x48,0x41,0x4e,0x54,0x41,
0x42,0x49,0x4c,0x49,0x54,0x59,0x2c,0x20,0x46,0x49,0x54,0x4e,0x45,0x53,0x53,0x20,
0x46,0x4f,0x52,0x20,0x41,0x20,0x50,0x41,0x52,0x54,0x49,0x43,0x55,0x4c,0x41,0x52,
0x20,0x50,0x55,0x52,0x50,0x4f,0x53,0x45,0x20,0x41,0x4e,0x44,0x20,0x4e,0x4f,0x4e,
0x49,0x4e,0x46,0x52,0x49,0x4e,0x47,0x45,0x4d,0x45,0x4e,0x54,0x2e,0x0a,0x49,0x4e,
0x20,0x4e,0x4f,0x20,0x45,0x56,0x45,0x4e,0x54,0x20,0x53,0x48,0x41,0x4c,0x4c,0x20,
0x54,0x48,0x45,0x20,0x41,0x55,0x54,0x48,0x4f,0x52,0x53,0x20,0x42,0x45,0x20,0x4c,
0x49,0x41,0x42,0x4c,0x45,0x20,0x46,0x4f,0x52,0x20,0x41,0x4e,0x59,0x20,0x43,0x4c,
0x41,0x49,0x4d,0x2c,0x20,0x44,0x41,0x4d,0x41,0x47,0x45,0x53,0x20,0x4f,0x52,0x0a,
0x4f,0x54,0x48,0x45,0x52,0x20,0x4c,0x49,0x41,0x42,0x49,0x4c,0x49,0x54,0x59,0x2c,
0x20,0x57,0x48,0x45,0x54,0x48,0x45,0x52,0x20,0x49,0x4e,0x20,0x41,0x4e,0x20,0x41,
0x43,0x54,0x49,0x4f,0x4e,0x20,0x4f,0x46,0x20,0x43,0x4f,0x4e,0x54,0x52,0x41,0x43,
0x54,0x2c,0x20,0x54,0x4f,0x52,0x54,0x20,0x4f,0x52,0x20,0x4f,0x54,0x48,0x45,0x52,
0x57,0x49,0x53,0x45,0x2c,0x0a,0x41,0x52,0x49,0x53,0x49,0x4e,0x47,0x20,0x46,0x52,
0x4f,0x4d,0x2c,0x20,0x4f,0x55,0x54,0x20,0x4f,0x46,0x20,0x4f,0x52,0x20,0x49,0x4e,
0x20,0x43,0x4f,0x4e,0x4e,0x45,0x43,0x54,0x49,0x4f,0x4e,0x20,0x57,0x49,0x54,0x48,
0x20,0x54,0x48,0x45,0x20,0x53,0x4f,0x46,0x54,0x57,0x41,0x52,0x45,0x20,0x4f,0x52,
0x20,0x54,0x48,0x45,0x20,0x55,0x53,0x45,0x20,0x4f,0x52,0x0a,0x4f,0x54,0x48,0x45,
0x52,0x20,0x44,0x45,0x41,0x4c,0x49,0x4e,0x47,0x53,0x20,0x49,0x4e,0x20,0x54,0x48,
0x45,0x20,0x53,0x4f,0x46,0x54,0x57,0x41,0x52,0x45,0x2e,0x0a,0x0a,0x46,0x6f,0x72,
0x20,0x6d,0x6f,0x72,0x65,0x20,0x69,0x6e,0x66,0x6f,0x72,0x6d,0x61,0x74,0x69,0x6f,
0x6e,0x2c,0x20,0x70,0x6c,0x65,0x61,0x73,0x65,0x20,0x72,0x65,0x66,0x65,0x72,0x20,
0x74,0x6f,0x20,0x3c,0x68,0x74,0x74,0x70,0x73,0x3a,0x2f,0x2f,0x75,0x6e,0x6c,0x69,
0x63,0x65,0x6e,0x73,0x65,0x2e,0x6f,0x72,0x67,0x3e,0x0a,0x00
};
87 changes: 29 additions & 58 deletions src/magic.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "../include/magic.h"
extern filetype_t * type;
extern filetype_t magic_table [];

int parse_magic(char *in) {
unsigned char buffer[32];
FILE *target = fopen(in, "rb");
Expand All @@ -11,69 +13,38 @@ int parse_magic(char *in) {
perror("Error");
return 1;
}
// formats
if (buffer[0] == 0x89 && buffer[1] == 0x50 && buffer[2] == 0x4E && buffer[3] == 0x47) {
type = "PNG Image";
}
else if (buffer[0] == 0x23 && buffer[1] == 0x21) {
type = "Script";
}
else if (buffer[0] == 0x49 && buffer[1] == 0x44 && buffer[2] == 0x33) {
type = "MP3 Audio";
}
else if (buffer[4] == 0x66 && buffer[5] == 0x74 && buffer[6] == 0x79) {
type = "MP4 Video";
}
else if (buffer[0] == 0x7F && buffer[1] == 0x45 && buffer[2] == 0x4C && buffer[3] == 0x46) {
type = "ELF UNIX Binary";
}
else if (buffer[0] == 0x4D && buffer[1] == 0x5A) {
type = "EXE Windows Binary";
}
else if (buffer[0] == 0xFF && buffer[1] == 0xD8 && buffer[2] == 0xFF) {
type = "JPEG Image";
}
else if (buffer[0] == 0x47 && buffer[1] == 0x49 && buffer[2] == 0x46) {
type = "GIF Image";
}
else if (buffer[0] == 0x42 && buffer[1] == 0x4D) {
type = "BMP Image";
}
else if (buffer[0] == 0x25 && buffer[1] == 0x50 && buffer[2] == 0x44 && buffer[3] == 0x46) {
type = "PDF Document";
}
else if (buffer[0] == 0x50 && buffer[1] == 0x4B) {
type = "ZIP Archive";
}
else if (buffer[0] == 0x1F && buffer[1] == 0x8B) {
type = "GZIP Archive";
}
else if (buffer[0] == 0x52 && buffer[1] == 0x61 && buffer[2] == 0x72 && buffer[3] == 0x21) {
type = "RAR Archive";
}
else if (buffer[0] == 0x37 && buffer[1] == 0x7A && buffer[2] == 0xBC && buffer[3] == 0xAF && buffer[4] == 0x27 && buffer[5] == 0x1C) {
type = "7z Archive";
} else {
type = "Data";
}

type = NULL;
int i; for (i=0; i<(int)magic_table_size; i++) {
filetype_t * test = &magic_table[i];
int max = test->len;
char * magic = ( test->magic );
char * reference = (char *)( buffer + test->off );
int status = strncmp(reference, magic, max);
if ( status == 0 ) { type = test; break; }
}

fclose(target);
return 0;
}

long parse_size(char *in) {
FILE *target = fopen(in, "rb");
if (target == NULL) { perror("Error"); return 0; }
long yield = get_size(target);
fclose(target);
return yield;
}

long get_size(FILE *f) {
fseek(f, 0, SEEK_END);
long size = ftell(f);
rewind(f);
return size;
}
int parse_size(char *in) {
FILE *target = fopen(in, "rb");
if (target == NULL) {
return 1;
}
b = get_size(target);
kb = b / 1024;
mb = kb / 1024;
gb = mb / 1024;
fclose(target);
return 0;
}

int parse_scale(long in) {
int i=0;
while(in >= 1024) { in >>= 10; i++; }
return i;
}
Loading