Skip to content

Instantly share code, notes, and snippets.

@simontime
Created March 31, 2019 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simontime/440fd110aa05534f4d4f1a42cebe20d9 to your computer and use it in GitHub Desktop.
Save simontime/440fd110aa05534f4d4f1a42cebe20d9 to your computer and use it in GitHub Desktop.
Switch CertStore .bdf extractor
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
typedef struct Header {
uint32_t Magic;
uint32_t NumFiles;
} Header;
typedef struct Entry {
uint32_t Index;
uint32_t Revision;
uint32_t Length;
uint32_t Offset;
} Entry;
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: %s *.bdf\n", argv[0]);
return 1;
}
FILE *in = fopen(argv[1], "rb");
Header hdr;
fread(&hdr, sizeof(hdr), 1, in);
if (hdr.Magic != 'Tlss') {
fputs("Error: Not a valid bdf file.", stderr);
return 1;
}
Entry *ent = malloc(hdr.NumFiles * sizeof(Entry));
fread(ent, sizeof *ent, hdr.NumFiles, in);
char name[0x10];
for (size_t i = 0; i < hdr.NumFiles; i++) {
sprintf(name, "0x%x.bin", ent[i].Index);
printf("Saving %s...\n", name);
char *buf = malloc(ent[i].Length);
FILE *out = fopen(name, "wb");
fseek(in, ent[i].Offset + 8, 0);
fread(buf, 1, ent[i].Length, in);
fwrite(buf, 1, ent[i].Length, out);
fclose(out);
free(buf);
}
puts("\nDone!");
fclose(in);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment