/*
Fixcrc.c - small program to fix the crc of the VPx500 swinfo files
Copyright (C) 2010 Sprite_tm
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
/*
Checksum updater for swinfo file for VPx500 updates.
Contents of swinfo file:
- full update field (37 bytes)
- 6 x partial update fields (37 bytes each)
- checksum (4 bytes)
Every update field contains the following:
- Filename (16 bytes, zero-padded)
- Md5-sum of update package file (16 bytes)
- Version (5 bytes, zero-padded)
The VPx500-updater will download swinfo from the server, then check its
checksum. If this is OK, it'll check the version of the partial update
fields against the versions of these packages installed on the phone itself.
If the version on the server is newer, it will start downloading the file
from the same directory as the swinfo file resides in. As soon as that's
done, it'll wait till a few minutes past 02.00AM, run some patch-scripts,
ttar -zxf the updates to the root of the filesystem and then run some more
patchscripts.
How the full update works is unknown at this time. The workings of the
patch-scripts are also unknown as of yet. It is, however, known that the patch-
scripts running for the 5th partial update won't do anything damaging. This
is the one replaced by hack.tgz in my version, and I suggest you use this one
too if you don't need any patch scripts to be run.
If you hack a swinfo file, you'll need its checksum updated before the
phone accepts it. Just compile this file (gcc -o fixcrc fixcrc.c) and
run it with the swinfo file as the first argument.
*/
#include
#include
#include
#include
#include
unsigned long getUL(unsigned char* bytes) {
unsigned long p;
p=bytes[3]+(bytes[2]<<8)+(bytes[1]<<16)+(bytes[0]<<24);
return p;
}
void fixcs(char *file) {
char data[1024];
int f;
int len;
f=open(file, O_RDONLY);
if (f<1) perror("opening");
len=read(f, data, 1024);
close(f);
long cs=0;
int x;
for (x=0; x>24);
data[len-3]=(cs>>16)&0xff;
data[len-2]=(cs>>8)&0xff;
data[len-1]=(cs)&0xff;
f=open(file, O_WRONLY|O_TRUNC);
write(f, data, len);
close(f);
}
int main(int argc, char **argv) {
if (argc<2) {
printf("Use: fixcrc file\n");
exit(1);
}
//Fix checksum
fixcs(argv[1]);
}