Skip to content

Instantly share code, notes, and snippets.

@ruvolof
Last active September 3, 2020 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruvolof/4cf4786340501b5cf04cb1c3609e7431 to your computer and use it in GitHub Desktop.
Save ruvolof/4cf4786340501b5cf04cb1c3609e7431 to your computer and use it in GitHub Desktop.
Read a file and output it as a string that can be pasted as binar payload
#!/usr/bin/perl
# Reads a file one byte a time and prints it out prepended by "\x".
# Example:
# $ xxd a
# 00000000: ffe4 ..
# $ ./file2hexstring.pl a
# \xff\xe4
use strict;
use warnings;
my $file = $ARGV[0];
print("# Payload:\n\n");
my $payload_length = 0;
open my $fh, '<:raw', $file;
while(my $bytes_read = read $fh, my $bytes, 1) {
printf("\\x%02x", ord($bytes));
$payload_length++;
}
print("\n\n");
print("# Length: $payload_length bytes.\n");
close($file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment