static void dump_i18n_strings(void) { struct dlist_head * entry; i18nstr_t * istr; size_t i, num; uint32_t offset; sealpac_hdr sphdr; sealpac_str * spstr = NULL; FILE * fh = NULL; MD5_CTX ctx; /* dump the string list. */ if (o_verbose > 2) { entry = NULL; while ((entry = dlist_get_next(entry, &g_i18n_strings))) { istr = dlist_entry(entry, i18nstr_t, list); verbose("["); for (i=0; i<16; i++) verbose("%02x", istr->digest[i]); verbose("] : [%s]\n", istr->string); } } num = count_i18n_strings(); printf("Number of strings : %d\n", num); do { if (num == 0) break; if (o_targetpath == NULL) break; /* Setup sealpac header */ memset(&sphdr, 0, sizeof(sphdr)); sphdr.magic = htonl(SEALPAC_MAGIC); sphdr.num = htonl(num); strncpy(sphdr.langcode, o_langcode, sizeof(sphdr.langcode)); /* Allocate sealpac string head */ spstr = MALLOC(sizeof(sealpac_str) * num); if (!spstr) ERRBREAK("%s: Memory Allocation Failed!\n",__func__); memset(spstr, 0, sizeof(sealpac_str) * num); /* Walk through all the string to prepare sealpac string heads */ i = 0; offset = sizeof(sealpac_hdr) + sizeof(sealpac_str) * num; entry = NULL; while ((entry = dlist_get_next(entry, &g_i18n_strings))) { istr = dlist_entry(entry, i18nstr_t, list); memcpy(spstr[i].hash, istr->digest, 16); spstr[i].offset = htonl(offset); offset += (strlen(istr->string) + 1); i++; } /* Calculate the checksum (MD5 digest) */ MD5Init(&ctx); MD5Update(&ctx, (uint8_t *)spstr, sizeof(sealpac_str) * num); entry = NULL; while ((entry = dlist_get_next(entry, &g_i18n_strings))) { istr = dlist_entry(entry, i18nstr_t, list); MD5Update(&ctx, (uint8_t *)istr->string, strlen(istr->string)+1); } MD5Final(sphdr.checksum, &ctx); /* Open the file to write */ if (o_slpfile == NULL) ERRBREAK("No output file !\n"); fh = fopen(o_slpfile, "w+"); if (fh == NULL) ERRBREAK("ERROR!!! Unable to open output file '%s', %s\n", o_slpfile, strerror(errno)); /* write to the langpack file. */ fwrite(&sphdr, sizeof(sealpac_hdr), 1, fh); fwrite(spstr, sizeof(sealpac_str), num, fh); entry = NULL; while ((entry = dlist_get_next(entry, &g_i18n_strings))) { istr = dlist_entry(entry, i18nstr_t, list); fwrite(istr->string, sizeof(char), strlen(istr->string)+1, fh); } } while (0); if (spstr) FREE(spstr); if (fh) fclose(fh); }
static int read_sealpac(const char * filename) { int ret = 0; size_t i, num; sealpac_hdr sphdr; sealpac_str * spstr = NULL; FILE * fh = NULL; uint8_t digest[16]; uint8_t buf[256]; MD5_CTX ctx; int c; strobj_t sobj = NULL; do { /* open file for reading */ fh = fopen(filename, "r"); if (!fh) ERRBREAK("Unable to open file '%s' for reading. %s. Creating a new one.\n",filename, strerror(errno)); /* Read sealpac head */ if (fread(&sphdr, sizeof(sealpac_hdr), 1, fh) != 1) ERRBREAK("Unable to read sealpac header!\n"); if (sphdr.magic != htonl(SEALPAC_MAGIC)) ERRBREAK("Invalid MAGIC!\n"); /* Read & calculate the MD5 digest */ MD5Init(&ctx); while (!ferror(fh) && !feof(fh)) { i = fread(buf, sizeof(uint8_t), 256, fh); if (i > 0) MD5Update(&ctx, (uint8_t *)buf, i); } MD5Final(digest, &ctx); if (memcmp(digest, sphdr.checksum, 16)) ERRBREAK("Invalid Checksum !\n"); /* dump the header */ if (o_verbose) dump_sealpac_hdr(&sphdr); /* read sealpac_str */ if ((num = ntohl(sphdr.num)) == 0) break; fseek(fh, sizeof(sealpac_hdr), SEEK_SET); spstr = MALLOC(sizeof(sealpac_str) * num); if (!spstr) ERRBREAK("Memory Allocation Failed !\n"); if (fread(spstr, sizeof(sealpac_str), num, fh) != num) ERRBREAK("Unable to read sealpac string head!\n"); /* We need a string oject */ sobj = sobj_new(); if (!sobj) ERRBREAK("Memory Allocation Failed!\n"); for (i=0; i<num; i++) { if (fseek(fh, ntohl(spstr[i].offset), SEEK_SET) < 0) ERRBREAK("Read file error @ %d\n", i); sobj_free(sobj); while ((c = fgetc(fh)) != EOF) { if (c) sobj_add_char(sobj, c); else break; } sealpac_puts(sobj_get_string(sobj)); } } while (0); if (sobj) sobj_del(sobj); if (fh) fclose(fh); if (spstr) FREE(spstr); return ret; }
void Run( HWND hwnd) { ULONG rc; ULONG ctr; ULONG ulID; PRWSHDR pHdr = 0; PRWSBLD pBld; PRWSARG pArg; char * pBuf; char * pErr = 0; do { ctr = sizeof(RWSBLD) + 6*sizeof(RWSARG); memset( (PVOID)argbuf, 0, ctr); pBld = (PRWSBLD)argbuf; pArg = CALCARGPTR( pBld); pBuf = &argbuf[ctr]; pBld->ppHdr = &pHdr; if (GetProc( hwnd, pBld, &pBuf) == FALSE) ERRBREAK( "proc is missing or invalid") if (GetRtn( hwnd, pBld) == FALSE) ERRBREAK( "invalid return type") for (ctr=0, ulID=IDC_ARG1TYPE; ctr < 6; ctr++, ulID += 4) { rc = GetArg( hwnd, &pArg[ctr], ulID, &pBuf); if (rc) break; pBld->argCnt++; } if (rc == 2) { sprintf( rtnbuf, "\r\nArg%d is invalid\r\n", ctr+1); pErr = rtnbuf; break; } rc = RwsCallIndirect( pBld); if (rc) { pErr = rtnbuf + sprintf( rtnbuf, "\r\nRwsCallIndirect rc= %d (", rc); RwsGetRcString( rc, 256, pErr); strcat( pErr, ")\r\n"); pErr = rtnbuf; break; } ShowResults( hwnd, pBld); } while (fFalse); RwsFreeMem( pHdr); if (pErr) { WinSendDlgItemMsg( hwnd, IDC_RESULT, MLM_SETSEL, (MP)0x7fffffff, (MP)0x7fffffff); WinSendDlgItemMsg( hwnd, IDC_RESULT, MLM_SETFIRSTCHAR, (MP)0x7fffffff, 0); WinSendDlgItemMsg( hwnd, IDC_RESULT, MLM_INSERT, (MP)pErr, 0); } return; }