Skip to content

Instantly share code, notes, and snippets.

@yeti0904
Last active February 27, 2024 17:11
Show Gist options
  • Save yeti0904/eda2b50033d5406ab2bb64bf0d9047b6 to your computer and use it in GitHub Desktop.
Save yeti0904/eda2b50033d5406ab2bb64bf0d9047b6 to your computer and use it in GitHub Desktop.
Rust detector
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