-
-
Save zxc20100123/d67f340829b8ffe0ab36189774fd0eac to your computer and use it in GitHub Desktop.
Extract metadata from ConeShell (Cygames) processed binary
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
#include <cstdio> | |
#include <iostream> | |
#include <cstdint> | |
using namespace std; | |
void writeReverse(FILE* f, uint32_t num) | |
{ | |
char* buf[4]; | |
*(uint32_t*)buf = 0xFFFFFFFF - num; | |
fwrite(buf, 4, 1, f); | |
} | |
int main(int argc, char** argv) | |
{ | |
if (argc < 2) return 1; | |
FILE* prog = fopen(argv[1], "rb"); | |
if (!prog) return 2; | |
FILE* out = fopen("global-metadata.dat", "wb"); | |
cout << "Finding metadata...\n" << endl; | |
uint32_t chk_against = 0x054ee450; | |
fseek(prog, 0, SEEK_END); | |
uint32_t offset = ftell(prog) / 2; | |
fseek(prog, offset, SEEK_SET); | |
//char chk[4]; | |
uint32_t chk; | |
while (1) { | |
fread(&chk, 4, 1, prog); | |
if (chk == chk_against) { | |
break; | |
} | |
offset += 4; | |
if (offset % 8192 == 0) cout << "\r" << offset; | |
} | |
printf("\nFound at %x\nModifing\n", offset - 4); | |
writeReverse(out, *(uint32_t*)&chk); | |
uint32_t len = 4; | |
uint32_t* chk_len = (uint32_t*)&chk; | |
while (1) { | |
fread(&chk, 4, 1, prog); | |
if (*chk_len == len) break; | |
writeReverse(out, *chk_len); | |
len += 4; | |
if (len % 8192 == 0) cout << "\r" << len; | |
} | |
cout << "\r" << len << "\nDone\n"; | |
return 0; | |
} |
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
<?php | |
$f = fopen('zaga', 'r'); | |
$o = fopen('global-metadata.dat', 'w'); | |
echo "Finding metadata...\n"; | |
$chk_against = hex2bin('50e44e05'); | |
$offset = filesize('zaga')/2; | |
$offset -= $offset % 16; | |
fseek($f, $offset); | |
while (1) { | |
$chk = fread($f, 4); | |
if ($chk == $chk_against) break; | |
$offset += 4; | |
if ($offset % 1024 == 0) echo "\r$offset"; | |
} | |
echo "\nfound at ".dechex(ftell($f) - 4)."\nModifing\n"; | |
function writeReverse($f, $num) { | |
fwrite($f, pack('V', 0xffffffff-$num)); | |
} | |
writeReverse($o, unpack('V', $chk)[1]); | |
$len = 4; | |
while (1) { | |
$chk_len = unpack('V', fread($f, 4))[1]; | |
if ($chk_len == $len) break; | |
writeReverse($o, $chk_len); | |
$len += 4; | |
if ($len % 1024 == 0) echo "\r$len"; | |
} | |
echo "\r$len"; | |
echo "\nDone\n"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment