Skip to content

Instantly share code, notes, and snippets.

@esterTion
Last active May 25, 2021 12:59
Show Gist options
  • Save esterTion/7fde10f2cb02722079d5fd9335ad5848 to your computer and use it in GitHub Desktop.
Save esterTion/7fde10f2cb02722079d5fd9335ad5848 to your computer and use it in GitHub Desktop.
Extract metadata from ConeShell (Cygames) processed binary
#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;
}
<?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";
Copy link

ghost commented Mar 31, 2020

@esterTion
So it seems like I must run this on android. Can you explain how can I run this to get the global-metadata.dat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment