por el khuong
/**
* VC Rom Injector
* v.1
* - khuong
*/
$appfile = "sins.app"; // original 00000005.APP
$tmdfile = "data/TITLE.TMD"; // original TMD file
$newrom = "data/Harvest Moon 64 (U) [!].z64"; // new rom
$romstart = 0x14BF00; // where roms starts in memory
$romsize = 32; // in mb
// do not edit.
$romsize = ((pow(2,20))/1) * $romsize;
$fp = fopen($appfile, "rb");
$header = fread($fp, $romstart);
fseek($fp, $romstart + $romsize, SEEK_SET);
$footer = fread($fp, filesize($appfile) - ($romstart + $romsize));
fclose($fp);
$fp = fopen("00000005.APP", "w");
print "writing header...\n";
flush();
fwrite($fp, $header);
print "injecting rom....\n";
flush();
$handle = fopen($newrom, "rb");
$contents = '';
while (!feof($handle)) {
fwrite($fp, fread($handle, 8192));
}
fclose($handle);
if(filesize($newrom) != $romsize) {
print "writing padding....\n";
flush();
fwrite($fp, str_repeat(pack("c", 0xff), ((33554432 - filesize($newrom)))));
}
fwrite($fp, $footer);
fclose($fp);
print "finished....\n";
flush();
$fp = fopen($tmdfile, "rb");
$header = fread($fp, 0x2A8);
fseek($fp, (0x2A8 + 20), SEEK_SET);
$footer = fread($fp, filesize($tmdfile) - (0x2A8 + 20));
fclose($fp);
file_put_contents("TITLE.TMD", $header . sha1_file("00000005.app", true) . $footer);
print "edited tmd file....\n";
flush();
?>