Skip to content

Instantly share code, notes, and snippets.

@mouseos
Last active October 23, 2022 18:06
Show Gist options
  • Save mouseos/740cdb866b6bb74e0c7efcd8c3800dfb to your computer and use it in GitHub Desktop.
Save mouseos/740cdb866b6bb74e0c7efcd8c3800dfb to your computer and use it in GitHub Desktop.
Mediatek端末のアンロックコードを計算しようとしているところ。(動作しないと思う。)
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#define SERIALNO_LEN 32
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
static char udc_chr[32] = {"ABCDEFGHIJKLMNOPQRSTUVWSYZ456789"};
int get_serial(uint64_t hwkey, uint32_t chipid, char ser[SERIALNO_LEN])
{
uint16_t hashkey[4];
int idx, ser_idx;
uint32_t digit, id;
uint64_t tmp = hwkey;
memset(ser, 0x00, SERIALNO_LEN);
/* split to 4 key with 16-bit width each */
tmp = hwkey;
for (idx = 0; idx < ARRAY_SIZE(hashkey); idx++) {
hashkey[idx] = (uint16_t)(tmp & 0xffff);
//printf("%d\n",hashkey[idx]);
tmp >>= 16;
}
/* hash the key with chip id */
id = chipid;
for (idx = 0; idx < ARRAY_SIZE(hashkey); idx++) {
digit = (id % 10);
hashkey[idx] = (hashkey[idx] >> digit) | (hashkey[idx] << (16-digit));
//printf("%d\n",hashkey[idx]);
id = (id / 10);
}
/* generate serail using hashkey */
ser_idx = 0;
for (idx = 0; idx < ARRAY_SIZE(hashkey); idx++) {
ser[ser_idx++] = (hashkey[idx] & 0x001f);
ser[ser_idx++] = (hashkey[idx] & 0x00f8) >> 3;
ser[ser_idx++] = (hashkey[idx] & 0x1f00) >> 8;
ser[ser_idx++] = (hashkey[idx] & 0xf800) >> 11;
}
for (idx = 0; idx < ser_idx; idx++){
//printf("before %d\n",ser[idx]);
ser[idx] = udc_chr[(int)ser[idx]];
printf("%c",ser[idx]);
//printf("text %c\n",(char)udc_chr[3]);
}
ser[ser_idx] = 0x00;
return ser;
}
int main(int argc, char *argv[]) {
char serial_number[SERIALNO_LEN] = {0};
//printf("Unlock code = %c\n",get_serial(1, 0x1, serial_number));
get_serial(0x490a3ddf51e74f47801ccd62b7cf808b, 0x8168, serial_number);
// get_serial(Paste here serial number., Paste here chipid, serial_number);
//oem unlock "key"
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment