Skip to content

Instantly share code, notes, and snippets.

@Makistos
Created October 25, 2013 12:45
Show Gist options
  • Save Makistos/7154111 to your computer and use it in GitHub Desktop.
Save Makistos/7154111 to your computer and use it in GitHub Desktop.
This small script reads a memory dump that looks like 0x00 0xAB 0xFE 0x10 ... and converts it into 16 -254 171 0 ... I needed this to verify some code as I got two different outputs. Not only was the format different, endianess was as well. Converting from hex to int wasn't the problem, it was making Perl to understand that the values were signe…
#!/usr/bin/perl
my $byte_num = 0;
my @vals;
while(<>)
{
chomp;
$vals[$byte_num] = unpack('c', pack 's', hex($_));
$byte_num++;
if ($byte_num == 4)
{
printf("%d %d\n%d %d\n", $vals[3], $vals[2], $vals[1], $vals[0]);
$byte_num = 0;
@vals = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment