Last active
February 27, 2024 17:11
-
-
Save yeti0904/eda2b50033d5406ab2bb64bf0d9047b6 to your computer and use it in GitHub Desktop.
Rust detector
This file contains 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
module rustdetector.app; | |
import std.file; | |
import std.path; | |
import std.stdio; | |
import std.algorithm; | |
string[] rustyThingsSource = [ | |
"svtu0svtud", | |
"joefy/dsbuft/jp" | |
]; | |
string[] rustyThings = []; | |
bool IsRusty(string path) { | |
auto contents = cast(ubyte[]) std.file.read(path); | |
if (contents.length < 4) { | |
return false; | |
} | |
if (cast(string) contents[0 .. 4] != "\x7fELF") { | |
return false; | |
} | |
foreach (ref thing ; rustyThings) { | |
if (contents.canFind(cast(ubyte[]) thing)) { | |
return true; | |
} | |
} | |
return false; | |
} | |
void main(string[] args) { | |
foreach (ref thing ; rustyThingsSource) { | |
rustyThings ~= string.init; | |
foreach (ref ch ; thing) { | |
rustyThings[$ - 1] ~= ch - 1; | |
} | |
} | |
string path = args.length == 1? getcwd() : args[1]; | |
if (isFile(path)) { | |
if (IsRusty(path)) { | |
writeln(path); | |
} | |
return; | |
} | |
foreach (DirEntry file ; dirEntries(path, SpanMode.depth)) { | |
if (!file.isFile()) continue; | |
if (IsRusty(file.name)) { | |
writeln(file.name); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment