Skip to content

Instantly share code, notes, and snippets.

@uobikiemukot
Created October 26, 2012 13:38
Show Gist options
  • Save uobikiemukot/3958877 to your computer and use it in GitHub Desktop.
Save uobikiemukot/3958877 to your computer and use it in GitHub Desktop.
descramble kindle firmware
#include <stdio.h>
#include <stdlib.h>
enum {
BITS_PER_BYTE = 8,
TYPE_AUTO = 1,
TYPE_MANUAL = 2,
};
int swap_byte(int byte)
{
int low, high;
low = (0x0F & byte) << 4;
high = (0xF0 & byte) >> 4;
return (high | low);
}
int main()
{
char sig[5];
int byte, type;
long offset;
/* check signature (first 4 bytes) */
fread(sig, 4, 1, stdin);
sig[4] = '\0';
if (strncmp("FB01", sig, 4) == 0)
type = TYPE_MANUAL;
else if (strncmp("FC02", sig, 4) == 0
|| strncmp("FD03", sig, 4) == 0)
type = TYPE_AUTO;
else {
fprintf(stderr, "unknown signature: %s\n", sig);
exit(EXIT_FAILURE);
}
/* seek */
offset = (type == TYPE_MANUAL) ? 0x20000: 0x40;
fseek(stdin, offset, SEEK_SET);
/* read gzipped tar */
while ((byte = fgetc(stdin)) != EOF) {
byte = swap_byte(byte ^ 0x7A);
fwrite(&byte, 1, 1, stdout);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment