Skip to content

Instantly share code, notes, and snippets.

@LvMalware
Created November 6, 2021 14:00
Show Gist options
  • Save LvMalware/7f3a9497e4d31d7948f7d47fb2d1dce1 to your computer and use it in GitHub Desktop.
Save LvMalware/7f3a9497e4d31d7948f7d47fb2d1dce1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
sub gen_pattern {
my ($size) = @_;
my @sym1 = "A" .. "Z";
my @sym2 = "a" .. "Z";
my @sym3 = "0" .. "9";
my $pattern = "";
GEN:
while (length($pattern) < $size) {
for my $a (@sym1) {
for my $b (@sym2) {
for my $c (@sym3) {
$pattern .= $a if length($pattern) < $size;
$pattern .= $b if length($pattern) < $size;
$pattern .= $c if length($pattern) < $size;
last GEN if length($pattern) == $size;
}
}
}
}
$pattern;
}
my ($size, $find);
my $input = "-";
my $output = "-";
GetOptions(
"s|size=i" => \$size,
"f|find=s" => \$find,
"i|input=s" => \$input,
"o|output=s" => \$output,
);
open(my $out, ">$output");
open(my $in, "<$input");
if (defined($size) && $size > 0) {
print $out gen_pattern($size), "\n";
}
if (defined($find) && length($find) > 0) {
my $pattern = join '', map { chomp; $_ } <$in>;
my $chunk = join '', reverse map { chr hex } $find =~ /.{2}/g;
my $offset = index($pattern, $chunk);
die "Offset not found" if $offset < 0;
print "Offset: $offset\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment