| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #include "myFile.h"
- #include "md5.h"
- #include "upgrade.h"
- static void print_md5(md5_t* m)
- {
- int i;
- printf("md5:");
- for (i = 0; i < 32; i++) {
- printf("%c", m->data[i]);
- }
- }
- static void print_info(const char* s, upgrade_file_t* hdr, md5_t *m)
- {
- printf("\n");
- printf("__%s__hdr.magic: 0x%08x\n", s, hdr->magic);
- printf("__%s__hdr.obj.num: %d\n", s, hdr->obj.num);
- printf("__%s__hdr.obj.stra: %d\n", s, hdr->obj.stra);
- printf("__%s__hdr.obj.obj1: %s\n", s, hdr->obj.obj1);
- printf("__%s__hdr.obj.obj2: %s\n", s, hdr->obj.obj2);
- print_md5(m);
- }
- int main(int argc, char *argv[])
- {
- int r;
- FILE* fp;
- node_t nd;
- md5_t md5;
- char newPath[1000];
- upgrade_obj_t obj;
- upgrade_file_t hdr;
- char* path = NULL;
- myFile mf;
- //TCHAR curPath[500];
- //GetCurrentDirectory(500, curPath);
- //_tprintf(_T("curPath: %s\n"), curPath);
-
- if(argc<5) {
- printf("usage: pack num stra obj1 obj2 packageFile\n");
- return -1;
- }
- obj.num = (uint8_t)atoi(argv[1]);
- obj.stra = (uint8_t)atoi(argv[2]);
- strcpy(obj.obj1, argv[3]);
- strcpy(obj.obj2, argv[4]);
- path = argv[5];
- strcpy(newPath, path);
- char* dot = strrchr(newPath, '/');
- if (!dot) {
- dot = strrchr(newPath, '\\');
- }
- if (dot) {
- *(dot + 1) = 0;
- strcat(newPath, "pdupkg");
- }
- else {
- strcat(newPath, "./pdupkg");
- }
- fp = fopen(newPath, "wb");
- if (!fp) {
- printf("%s create failed\n", newPath);
- return -1;
- }
- r = mf.read_file(path, &nd);
- if (r) {
- return -1;
- }
- hdr.magic = UPG_FILE_MAGIC;
- hdr.obj = obj;
- md5_calc(&hdr, sizeof(hdr), nd.pbuf, nd.dlen, (char*)md5.data);
- fwrite(&hdr, 1, sizeof(hdr), fp);
- fwrite(nd.pbuf, 1, nd.dlen, fp);
- fwrite(&md5, 1, sizeof(md5), fp);
- print_info("$$$", &hdr, &md5);
- fclose(fp);
- free(nd.pbuf);
- return 0;
- }
|