DWORD WINAPI Encrypt(PBYTE pbBuffer, TMyPAZEntry *pEntry) { CHAR szName[MAX_PATH]; BYTE bySeed[400]; DWORD dwSeed, dwSize; LPCSTR lpCrud; LPSTR lpExt, lpFileName; lpFileName = pEntry->szName; lstrcpy(szName, lpFileName); lpExt = findext(szName); if (lpExt && bIsVoice) { *lpExt = 0; } dwSize = pEntry->dwCompSize; lpCrud = GetCrud(findext(lpFileName), &GameInfo[dwInfoIndex]); if (lpCrud) dwSeed = sprintf((char *)bySeed, "%s %08X %s", strlwr(lpFileName), pEntry->dwCompSize, lpCrud ? lpCrud : ""); if (g_bIsMovie == False) { CBlowFish bf; bf.Initialize(GameInfo[dwInfoIndex].key[dwKeyIndex].DataKey, sizeof(GameInfo[dwInfoIndex].key[dwKeyIndex].DataKey)); if (lpCrud) { Decrypt(bySeed, dwSeed, pbBuffer, dwSize); } dwSize = bf.Encode(pbBuffer, pbBuffer, pEntry->dwDecryptSize); } else { if (dwInfoIndex != EF_FIRST) { memset(&bySeed[dwSeed + 10], 0, 0x100); DecryptMovie(&bySeed[dwSeed + 10], bySeed, dwSeed, pbBuffer, pEntry->dwCompSize); } else { } } if (bNeedXor) Xor(pbBuffer, dwSize); return dwSize; }
PAZTYPE WINAPI GetPazTypeFromFileName(LPSTR lpFileName) { DWORD dwLength; CHAR szName[MAX_PATH]; lpFileName = findname(lpFileName); lstrcpyA(szName, lpFileName); lpFileName = findext(szName); if (lpFileName) *lpFileName = 0; dwLength = lstrlenA(szName); if (dwLength > 3 && !lstrcmpiA(szName + dwLength - 3, "_sc")) { dwLength -= 3; szName[dwLength] = 0; /* for (int i = dwLength; i >= 0; --i) szName[i + 2] = szName[i]; *(LPWORD)szName = 'mp'; */ return GetPazTypeFromFileName(szName); } for (int i = 0; i != countof(szType); ++i) { if (!lstrcmpiA(szName, szType[i])) return (PAZTYPE)i; } return NONE; }
Bool WINAPI IsMovie(LPCSTR lpFileName) { CHAR szName[MAX_PATH]; LPSTR lpExt; strcpy(szName, findname((char *)lpFileName)); if (strlen(lpFileName) < 2) return False; lpExt = findext(szName); if (lpExt) *lpExt = 0; strlwr(szName); return strstr(szName, "mov") != NULL; }
char* findext(char* fnbase, char* fnpart) { char* tokenp; char* ext; tokenp = strtok(NULL, "."); if ((tokenp == NULL) && (strlen(fnbase) > 0)) { ext = fnpart; } else { if (strlen(fnbase) != 0) { strcat(fnbase, "."); } strcat(fnbase, fnpart); ext = findext(fnbase, tokenp); } return ext; }
DWORD WINAPI GetKeyIndex(LPSTR lpFileName, TGameInfo *pGameInfo) { CHAR szName[MAX_PATH]; LPSTR lpPrefix; DWORD dwLength, dwLength2; strcpy(szName, findname(lpFileName)); lpPrefix = findext(szName); if (lpPrefix) *lpPrefix = 0; dwLength = strlen(szName); for (DWORD i = 0; pGameInfo->key[i].lpFileName; ++i) { lpPrefix = pGameInfo->key[i].lpFileName; dwLength2 = strlen(lpPrefix); if (!strnicmp(szName, lpPrefix, max(dwLength2, dwLength))) return i; } return -1; }
int main(void) { int n=0; scanf("%d", &n); int m=0; scanf("%d", &m); int *A = NULL; A = (int*)malloc(n*sizeof(int)); for(i = 0;i < n;i++) { scanf("%d", (A+i)); } int *B = NULL; B=(int*)malloc(m*sizeof(int)); for(i = 0;i < m;i++) { scanf("%d", (B+i)); } findext(A,n,B,m); free(A); free(B); return EXIT_SUCCESS; }
static void parse_filename(PATHINFO_STRUCT* pathinfop, char* filename) { char* buff; char* fn; char* ext; int ishiddenfile = 0; size_t fnbufflen; char* fnbuff; if ((filename == NULL) || (strlen(filename) == 0)) { return; } buff = strdup(filename); if (filename[0] == '.') { // Hidden file with leading period ishiddenfile = 1; } fn = strtok(buff, "."); if (fn != NULL) { fnbufflen = strlen(filename); fnbuff = (char*)calloc(fnbufflen, sizeof(char)); ext = findext(fnbuff, fn); if (ext != NULL) { pathinfop->extension = strdup(ext); } if (ishiddenfile) { char* fnbasebuff; fnbasebuff = (char*)calloc(strlen(fn) + 2, sizeof(char)); strcpy(fnbasebuff, "."); strcat(fnbasebuff, fnbuff); pathinfop->basename = fnbasebuff; } else { pathinfop->basename = strdup(fnbuff); } pathinfop->filename = strdup(filename); } free(buff); }
void ProcessFile(char *szName) { FILE *fp; int_32 iSize; uchar *pbBuffer; char *pExtension, szText[MAX_PATH]; TSNHeader *h; fp = fopen(szName, "rb"); if (fp == NULL) { printf("Can't open \"%s\"\n", szName); perror(NULL); return; } iSize = fsize(fp); if (iSize == 0) { printf("Empty file \"%s\"\n", szName); fclose(fp); return; } else if (iSize < sizeof(*h)) { printf("Invalid sn file \"%s\"\n", szName); fclose(fp); return; } pbBuffer = gpbBuffer; if (iSize > iBufferSize) { iBufferSize = iSize; pbBuffer = (uchar *)realloc(pbBuffer, iSize); if (pbBuffer == NULL) { fclose(fp); return; } gpbBuffer = pbBuffer; } fread(pbBuffer, iSize, 1, fp); fclose(fp); h = (TSNHeader *)pbBuffer; if (h->wEndOffset + 9 > iSize || memicmp(pbBuffer + h->wEndOffset, "@FileName", 9)) { printf("Invalid sn file \"%s\"\n", szName); return; } strcpy(szText, szName); pExtension = findext(szText); if (pExtension) { strcpy(pExtension, ".txt"); } else { strcat(szText, ".txt"); } fp = fopen(szText, "wb"); if (fp == NULL) { printf("Can't open \"%s\"\n", szText); perror(NULL); return; } printf("Exporting \"%s\" ... \n", szName); fprintf(fp, ";%s\n", findname(szName)); ExportText(fp, pbBuffer, iSize); fclose(fp); }
Void WINAPI WriteEntry(HANDLE hFile, TMyPAZEntry *pEntry, DWORD dwCount, Bool bEncrypt) { DWORD dwLength, dwEntryPos, dwRemainder; PBYTE pbEntry; BYTE byMovieSeed[256], byMod8[8]; *(LPDWORD)&byMod8[0] = 0; *(LPDWORD)&byMod8[3] = 0; dwEntryPos = 0x24 + (g_bIsMovie ? 0x100 : 0); SetFilePointer(hFile, 0x20, 0, FILE_BEGIN); WriteFile(hFile, &dwCount, 4, &dwLength, NULL); // entry size WriteFile(hFile, &dwCount, 4, &dwLength, NULL); // entry count if (g_bIsMovie) { if (bEncrypt == False) { if (dwInfoIndex != EF_FIRST) { memset(byMovieSeed, 0, sizeof(byMovieSeed)); WriteFile(hFile, byMovieSeed, sizeof(byMovieSeed), &dwLength, NULL); } else { for (int i = 0; i != 256; ++i) { byMovieSeed[i] = i; } for (int i = 0; i != 256; ++i) WriteFile(hFile, byMovieSeed, sizeof(byMovieSeed), &dwLength, NULL); } } else { SetFilePointer(hFile, dwInfoIndex != EF_FIRST ? 0x100 : 0x10000, 0, FILE_CURRENT); } } for (DWORD i = dwCount; i; ) { LPSTR lpExt; --i; lpExt = findext(pEntry[i].szName); if (lpExt) { if (lstrcmpiA(lpExt, ".uca") && bIsVoice) *lpExt = 0; else if (lstrcmpiA(lpExt, ".ogg") && lstrcmpiA(lpExt, ".m4a")) lpExt = NULL; } dwLength = lstrlenA(pEntry[i].szName) + 1; WriteFile(hFile, pEntry[i].szName, dwLength, &dwLength, NULL); if (lpExt && *lpExt == 0) { *lpExt = '.'; } WriteFile(hFile, &pEntry[i].l64Offset, sizeof(*pEntry) - sizeof(pEntry->szName), &dwLength, NULL); } dwCount = SetFilePointer(hFile, 0, 0, FILE_CURRENT) - sizeof(TPAZHeader); dwRemainder = dwCount % 8; if (dwRemainder) { dwRemainder = 8 - dwRemainder; WriteFile(hFile, byMod8, dwRemainder, &dwLength, NULL); dwCount += dwRemainder; } if (bEncrypt) { HANDLE hHeap; CBlowFish bf; hHeap = ghHeap; pbEntry = (PBYTE)HeapAlloc(hHeap, 0, dwCount); SetFilePointer(hFile, 0x24, 0, FILE_BEGIN); ReadFile(hFile, pbEntry, dwCount, &dwLength, NULL); bf.Initialize(GameInfo[dwInfoIndex].key[dwKeyIndex].IndexKey, sizeof(GameInfo[dwInfoIndex].key[dwKeyIndex].IndexKey)); dwLength = bf.Encode(pbEntry, pbEntry, dwLength); if (bNeedXor) { Xor(pbEntry, dwLength); } SetFilePointer(hFile, 0x24, 0, FILE_BEGIN); WriteFile(hFile, pbEntry, dwLength, &dwLength, NULL); dwCount = SetFilePointer(hFile, 0, 0, FILE_CURRENT) - sizeof(TPAZHeader) + 4; } dwCount += 4; SetFilePointer(hFile, 0x20, NULL, FILE_BEGIN); WriteFile(hFile, &dwCount, 4, &dwLength, NULL); // entry size if (bEncrypt && bNeedXor) { CHAR h[0x24]; SetFilePointer(hFile, 0, NULL, FILE_BEGIN); ReadFile(hFile, h, sizeof(h), &dwLength, NULL); Xor((PBYTE)h, sizeof(h)); SetFilePointer(hFile, 0, NULL, FILE_BEGIN); WriteFile(hFile, h, sizeof(h), &dwLength, NULL); } SetFilePointer(hFile, 0, 0, FILE_END); }
/* * Parse into three arguments: Av[0], Av[1], Av[2] */ MNEMONIC *parse(char *buf) { int i, j; MNEMONIC *mne = NULL; i = 0; j = 1; #if OlafFreeFormat /* Skip all initial spaces */ while (buf[i] == ' ') ++i; #endif #if OlafHashFormat /* * If the first non-space is a ^, skip all further spaces too. * This means what follows is a label. * If the first non-space is a #, what follows is a directive/opcode. */ while (buf[i] == ' ') ++i; if (buf[i] == '^') { ++i; while (buf[i] == ' ') ++i; } else if (buf[i] == '#') { buf[i] = ' '; /* label separator */ } else i = 0; #endif Av[0] = Avbuf + j; while (buf[i] && buf[i] != ' ') { if (buf[i] == ':') { i++; break; } if ((unsigned char)buf[i] == 0x80) buf[i] = ' '; Avbuf[j++] = buf[i++]; } Avbuf[j++] = 0; #if OlafFreeFormat /* Try if the first word is an opcode */ findext(Av[0]); mne = findmne(Av[0]); if (mne != NULL) { /* Yes, it is. So there is no label, and the rest * of the line is the argument */ Avbuf[0] = 0; /* Make an empty string */ Av[1] = Av[0]; /* The opcode is the previous first word */ Av[0] = Avbuf; /* Point the label to the empty string */ } else #endif { /* Parse the second word of the line */ while (buf[i] == ' ') ++i; Av[1] = Avbuf + j; while (buf[i] && buf[i] != ' ') { if ((unsigned char)buf[i] == 0x80) buf[i] = ' '; Avbuf[j++] = buf[i++]; } Avbuf[j++] = 0; /* and analyse it as an opcode */ findext(Av[1]); mne = findmne(Av[1]); } /* Parse the rest of the line */ while (buf[i] == ' ') ++i; Av[2] = Avbuf + j; while (buf[i]) { if (buf[i] == ' ') { while(buf[i+1] == ' ') ++i; } if ((unsigned char)buf[i] == 0x80) buf[i] = ' '; Avbuf[j++] = buf[i++]; } Avbuf[j] = 0; return mne; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *data1 = NULL, *data2 = NULL; double *bins = NULL, *cnts = NULL, *ctrs = NULL; int ndata1, ndata2, nbins; double min, max, size = -1; double *t,*y; unsigned int i,m,n; /* Check numbers of arguments */ if (nrhs == 0) { mexErrMsgTxt("HISTDIFF: no data to histogram"); } else if (nrhs > 3) { mexErrMsgTxt("HISTDIFF: too many arguments."); } if (nlhs < 2) { mexErrMsgTxt("HISTDIFF: must be called with two output arguments"); } /* Get data */ m = mxGetM(DATA1_IN); n = mxGetN(DATA1_IN); ndata1 = m*n; if (!mxIsNumeric(DATA1_IN) || mxIsComplex(DATA1_IN) || mxIsSparse(DATA1_IN) || !mxIsDouble(DATA1_IN) || m*n == 0) { mexErrMsgTxt("HISTDIFF: data must be a full real valued matrix."); } data1 = mxGetPr(DATA1_IN); m = mxGetM(DATA2_IN); n = mxGetN(DATA2_IN); ndata2 = m*n; if (!mxIsNumeric(DATA2_IN) || mxIsComplex(DATA2_IN) || mxIsSparse(DATA2_IN) || !mxIsDouble(DATA2_IN) || m*n == 0) { mexErrMsgTxt("HISTDIFF: data must be a full real valued matrix."); } data2 = mxGetPr(DATA2_IN); /* Get bin specification */ m = mxGetM(BINS_IN); n = mxGetN(BINS_IN); if (!mxIsNumeric(BINS_IN) || mxIsComplex(BINS_IN) || mxIsSparse(BINS_IN) || !mxIsDouble(BINS_IN) || (m != 1 && n != 1)) { mexErrMsgTxt("HISTDIFF: bins spec must be a real scalar or vector"); } if (m == 1 && n == 1) { /* number of bins */ nbins = (int)*(double *)mxGetPr(BINS_IN); findext (data1, ndata1, data2, ndata2, &min, &max); size = (max-min)/nbins; } else { /* vector of bin boundaries */ nbins = n*m - 1; bins = mxGetPr (BINS_IN); /* check to see if spacing is regular -- if so use fast algorithm */ size = bins[1] - bins[0]; for (i = 1; i < nbins; i++) if (fabs(bins[i+1] - bins[i] - size) > 1e-3*size) { size = 0; break; } if (size) { min = bins[0]; } } /* Create output matrices */ C_OUT = mxCreateDoubleMatrix(1, nbins, mxREAL); cnts = mxGetPr(C_OUT); B_OUT = mxCreateDoubleMatrix(1, nbins, mxREAL); ctrs = mxGetPr(B_OUT); /* Do the actual computations in a subroutine */ if (size) { if (chckord (data1, ndata1, data2, ndata2)) ordhist(data1, ndata1, data2, ndata2, min, size, nbins, cnts, ctrs); else reghist(data1, ndata1, data2, ndata2, min, size, nbins, cnts, ctrs); } else { binhist(data1, ndata1, data2, ndata2, bins, nbins, cnts, ctrs); } return; }