Skip to content

Instantly share code, notes, and snippets.

@CrazyCoder
Created November 23, 2010 11:24
Show Gist options
  • Save CrazyCoder/711623 to your computer and use it in GitHub Desktop.
Save CrazyCoder/711623 to your computer and use it in GitHub Desktop.
Extracts pl3 and hermes payloads from psgroove hex files (to be used in psfreedom)
static const char *PL_START = "000000000000FACEB003AABBCCDD";
static const char *PL3_START = "505347726F6F7665";
static const char *PL3_END = "1201000200000008AAAABBBB";
unsigned int PL_SIZE = 3822;
int hex2bin(char *hex_file, char *bin_file) {
FILE *infile, *outfile;
char line[100];
char buffer[50*1024];
char outc = 0;
if ((infile = fopen(hex_file, "r")) == NULL) {
return -1;
}
if ((outfile = fopen(bin_file, "wb")) == NULL) {
fclose(infile);
return -2;
}
unsigned int len = 0;
while (fgets(line, sizeof(line), infile) != NULL) {
if (len + 32 >= sizeof(buffer)) break; // prevent overflow
strncat(buffer, line+9, 32);
len += 32;
}
char *start = strstr(buffer, PL_START);
// check for PL3
if (start == NULL) {
start = strstr(buffer, PL3_START);
if (start != NULL) {
char *end = strstr(buffer, PL3_END);
if (end != NULL) {
start += strlen(PL3_START);
PL_SIZE = (end-start) / 2;
} else {
start = NULL;
}
}
}
// Can't find payload inside hex =(
if (start == NULL) {
fclose(infile);
fclose(outfile);
unlink(bin_file);
return -3;
}
unsigned int pos;
for (pos = 0; pos < PL_SIZE*2; pos += 2) {
sscanf(start+pos, "%2hhx", &outc);
fputc(outc, outfile);
}
fclose(infile);
fclose(outfile);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment