Friday, July 01, 2005

outpatch.pl for PSP in Perl

#!/usr/bin/perl -w

use strict;
use IO::File;

if($#ARGV <1){
die "Usage: $0 ";
}

my $section_header=`readelf -a $ARGV[0]|grep .xodata.sceModule |grep PROGBITS|awk '{print \$5}'`;
chomp $section_header;
die "Error: failed to locate section header.\n" unless($section_header);
$section_header=hex $section_header;
print "Found section header at $section_header.\n";

my $section_title_offset=`grep -a -b -z -Z .rel.xodata.sceModuleInfo $ARGV[0]|awk -F':' '{print \$1}'`;
chomp $section_title_offset;
die "Error: failed to locate section title.\n" unless($section_title_offset);
print "Found sestion title at $section_title_offset.\n";

my $s='';
for(my $n=0;$n<32;$n+=8){
$s=$s.chr(($section_header>>$n)&0xFF);
}
#$s=chr(0).chr(0).chr(0xa0).chr(0x6b);

`cp -af $ARGV[0] $ARGV[1]`;
sysopen(HANDLE,$ARGV[1],O_RDWR|O_EXCL);
seek(HANDLE,0x40,SEEK_SET);
syswrite HANDLE,$s,4;
seek(HANDLE,$section_title_offset,SEEK_SET);
syswrite HANDLE,".rel.rodata";
close(HANDLE);

No comments: