Skip to content

Instantly share code, notes, and snippets.

@CrazyCoder
Created November 23, 2010 10:44
Show Gist options
  • Save CrazyCoder/711589 to your computer and use it in GitHub Desktop.
Save CrazyCoder/711589 to your computer and use it in GitHub Desktop.
Extracts pl3 and hermes payloads from psgroove hex files (to be used in psfreedom)
#!/usr/bin/perl
use strict;
my $VERSION = '1.0';
my $PL_START = "000000000000FACEB003AABBCCDD";
my $PL3_START ="505347726F6F7665";
my $PL3_END = "1201000200000008AAAABBBB";
my $PL_SIZE = 3822;
my $in;
my $out;
if ($#ARGV < 0) {
die "hex2bin v$VERSION (c) CrazyCoder\nUsage: $0 <payload.hex> <payload.bin>\n";
} else {
$in = $ARGV[0];
$out = $ARGV[1];
}
my $hex = '';
open(IN, "<$in");
while(my $line = <IN>) {
$hex .= substr($line, 9, 32);
}
close(IN);
# check for hermes
my $idx = index($hex, $PL_START);
# check for PL3
if ($idx <= 0) {
$idx = index($hex, $PL3_START);
if ($idx > 0) {
$idx += length($PL3_START);
my $idx_end = index($hex, $PL3_END);
if ($idx_end > $idx) {
$PL_SIZE = ($idx_end - $idx)/2;
} else {
$idx = -1;
}
}
}
if ($idx > 0) {
$hex = substr($hex, $idx, $PL_SIZE*2);
} else {
die "Payload not found in .hex!\n";
}
if ($out) {
open(BIN, ">$out");
binmode BIN;
print BIN pack("H*", $hex);
close(BIN);
print "Payload saved to $out ($PL_SIZE bytes).\n";
} else {
print $hex;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment