Last active
September 3, 2020 19:44
-
-
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
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
#!/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