Small improvements in hexpatcher

update
Hamish Coleman 8 years ago
parent 2a65f1bc06
commit 6905163a65

@ -35,7 +35,7 @@ install.radare.projects:
# Generate a working file with any known patches applied
%.img: %.img.orig
cp --reflink=auto $< $@
[ -d $@.d ] && for i in $@.d/*.patch; do ./hexpatch.pl $$i $@; done
[ -d $@.d ] && ./hexpatch.pl $@ $@.d/*.patch
# if you want to work on more patches, you probably want the pre-patched ver
%.img.prepatch: %.img.orig

@ -18,7 +18,7 @@ sub usage() {
print("patching the right file\n");
print("\n");
print("Usage:\n");
print(" hexpatch.pl patchfile binaryfile\n");
print(" hexpatch.pl binaryfile patchfile [patchfile...]\n");
print("\n");
exit(1);
}
@ -60,8 +60,9 @@ sub read_patchfile {
while(<$fh>) {
# anything before we see a starting at symbol line can be ignored
if (!$seen_at_symbols) {
if (m/^\@\@ .* \@\@$/) {
if (m/^\@\@ (.*) \@\@$/) {
$seen_at_symbols = 1;
$db->{name} = $1;
}
next;
}
@ -165,32 +166,37 @@ sub apply_patch {
}
sub main() {
my $patchfile = shift @ARGV;
my $binaryfile = shift @ARGV;
if (!defined($patchfile) or !defined($binaryfile)) {
if (!defined($binaryfile) or !defined($ARGV[0])) {
usage();
}
my $db = read_patchfile($patchfile);
if (!defined($db)) {
warn("Cannot read $patchfile\n");
exit(1);
}
my $fh = IO::File->new($binaryfile, O_RDWR);
if (!defined($fh)) {
warn("Could not open binaryfile\n");
exit(1);
}
if (!verify_context($db,$fh)) {
warn("The binaryfile does not match the context bytes from the patch");
exit(1);
}
print("Attempting to patch $binaryfile\n");
apply_patch($db,$fh);
while ($ARGV[0]) {
my $patchfile = shift @ARGV;
my $db = read_patchfile($patchfile);
if (!defined($db)) {
warn("Cannot read $patchfile\n");
exit(1);
}
if (!verify_context($db,$fh)) {
warn("The binaryfile does not match the context bytes from $patchfile\n");
exit(1);
}
print("Applying ",$patchfile," ",$db->{name},"\n");
apply_patch($db,$fh);
}
}
main();

Loading…
Cancel
Save