Skip to content

Instantly share code, notes, and snippets.

@ruvolof

ruvolof/file2payload.pl

Last active Sep 3, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.