Created
November 4, 2014 14:02
-
-
Save invisiblek/71b964abeee46aa9cb06 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* To FreeXperia from a friend :) */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <errno.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <unistd.h> | |
#define MISC_FILE "/dev/block/platform/msm_sdcc.1/by-name/misc" | |
#define NV_IN "/system/etc/firmware/wlan/prima/WCNSS_qcom_wlan_nv.bin" | |
#define NV_OUT "/data/misc/wifi/WCNSS_qcom_wlan_nv.bin" | |
#define NV_SIZE 28456 | |
int main(int argc, char **argv) | |
{ | |
char *buf; | |
struct stat statbuf; | |
int ret; | |
size_t actual; | |
FILE *f; | |
char macaddr[18]; | |
memset(macaddr, 0, 18); | |
f = fopen(MISC_FILE, "r"); | |
fseek(f, 0x3000, SEEK_SET); | |
unsigned char macbuf[6]; | |
fread(macbuf, 6, 1, f); | |
sprintf(macaddr,"%02x%02x%02x%02x%02x%02x", | |
macbuf[0], macbuf[1], macbuf[2], | |
macbuf[3], macbuf[4], macbuf[5]); | |
fclose(f); | |
ret = stat(NV_IN, &statbuf); | |
if (ret) { | |
perror("Failed to stat " NV_IN); | |
exit(EINVAL); | |
} | |
f = fopen(NV_IN, "r"); | |
if (!f) { | |
perror("Failed to open " NV_IN); | |
exit(EINVAL); | |
} | |
if (statbuf.st_size < 100) { | |
perror("nv file too small"); | |
exit(EINVAL); | |
} | |
if (statbuf.st_size != NV_SIZE) | |
perror("Warning - size invalid"); | |
buf = malloc(statbuf.st_size); | |
if (!buf) { | |
perror("malloc failed"); | |
exit(ENOMEM); | |
} | |
actual = fread(buf, 1, statbuf.st_size, f); | |
if (actual != statbuf.st_size) { | |
perror("Failed to read from nv"); | |
exit(EINVAL); | |
} | |
fclose(f); | |
f = fopen(NV_OUT, "w+"); | |
if (!f) { | |
perror("Failed to open " NV_OUT); | |
exit(EINVAL); | |
} | |
actual = fwrite(buf, 1, statbuf.st_size, f); | |
if (actual != statbuf.st_size) { | |
perror("Failed to write to nv"); | |
exit(EINVAL); | |
} | |
fseek(f, 0xa, SEEK_SET); | |
fwrite(macaddr, 1, 6, f); | |
fclose(f); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment