Created
June 18, 2013 12:28
-
-
Save fovtran/5804956 to your computer and use it in GitHub Desktop.
binary file editing
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 | |
# | |
use strict; | |
use warnings; | |
use bytes; | |
my $filein = 'cm_cert.cer'; | |
my $fileout = 'temp.cer'; | |
my @pos1 = (328..340); | |
my @pos2 = (352..368); | |
local *INPUT; | |
local *OUTPUT; | |
my @NEW_MAC = ('001122334455'); | |
open INPUT, $filein or die "Error opening $filein certificate\n"; | |
open OUTPUT, ">$fileout" or die "Error opening $fileout for writing\n"; | |
binmode INPUT; | |
binmode OUTPUT; | |
my $base_chars = map(chr, 0..255); | |
my ($bytesread, $buffer, $total); | |
my @data; | |
while (($bytesread = sysread(INPUT, $buffer, 1)) == 1) { | |
$total += $bytesread; | |
push (@data, $buffer); | |
} | |
print "Total bytes: $total\n"; | |
print "--Begin MC Certificates--\n"; | |
print "Original MAC:",@data[ @pos1 ]; | |
print "\nOriginal MAC:",@data[ @pos2 ]; | |
my @s = ('112233445566'); | |
foreach my $i (@pos1) { | |
$data[ $i ] = $new_mac[$i]; | |
} | |
print "\nChanged MAC: ",@data[ @pos1 ]; | |
print "\nChanged MAC: ",@data[@pos2]; | |
print "\n--End MC Certificates--\n"; | |
close INPUT; | |
close OUTPUT or die "Error opening $fileout for writing\n" ; | |
print "MC Certificate alteration complete\n"; | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment