예제 #1
0
파일: tunnel.cpp 프로젝트: aguinet/ret-sync
HRESULT
ToStringEnc(DWORD dwFlags, const BYTE *pbBinary, DWORD cbBinary, LPSTR *pszString)
{
	BOOL bRes = FALSE;
    HRESULT hRes=S_OK;
    DWORD cchString = 0;

	bRes = CryptBinaryToStringA(pbBinary, cbBinary, dwFlags, NULL, &cchString);
	if (!bRes){
        dprintf("[sync] send failed at CryptBinaryToString: %d\n", GetLastError());
        return E_FAIL;
    }

    *pszString = (LPSTR) malloc(cchString);

    if (*pszString==NULL){
        dprintf("[sync] failed at allocate buffer: %d\n", GetLastError());
        return E_FAIL;
    }

	bRes = CryptBinaryToStringA(pbBinary, cbBinary, dwFlags, *pszString, &cchString);
	if (!bRes){
        dprintf("[sync] failed at CryptBinaryToString: %d\n", GetLastError());
        if (*pszString)
        {
            free(*pszString);
            *pszString = NULL;
        }
        return E_FAIL;
    }

    /*
    CRYPT_STRING_NOCRLF 0x40000000
    Windows Server 2003 and Windows XP: This value is not supported
    */

    #if _NT_TARGET_VERSION_WINXPOR2K3
    trimcrlf(*pszString);
    #endif

    return hRes;
}
예제 #2
0
파일: f.c 프로젝트: noodles-v6/ACM
int main() {
	char s[MAXSTR];
	int i,j,M;
	if(!(from=malloc(sizeof(int)*MAXE))) { puts("out of memory on from"); return 0; }
	if(!(to=malloc(sizeof(int)*MAXE))) { puts("out of memory on to"); return 0; }
	if(!(f=malloc(sizeof(int)*MAXE))) { puts("out of memory on f"); return 0; }
	if(!(cost=malloc(sizeof(int)*MAXE))) { puts("out of memory on cost"); return 0; }
	if(!(inv=malloc(sizeof(int)*MAXE))) { puts("out of memory on inv"); return 0; }
	fgets(s,MAXSTR-1,stdin); sscanf(s,"%d",&nw);
	for(i=0;i<nw;i++) {
		fgets(s,MAXSTR-1,stdin); trimcrlf(s);
		if(strlen(s)>MAXS-1) { printf("increase MAXS to %d and recompile\n",(int)strlen(s)+1); return 0; }
		strcpy(w[i],s);
		wmask[i]=0;
		for(j=0;s[j];j++) wmask[i]|=1LL<<getix(s[j]);
	}
	fgets(s,MAXSTR-1,stdin); sscanf(s,"%d",&M);
	while(M--) solve();
	return 0;
}
예제 #3
0
파일: tunnel.c 프로젝트: idkwim/qb-sync
HRESULT
ToBase64(const BYTE *pbBinary, DWORD cbBinary, LPSTR *pszString)
{
    HRESULT hRes=S_OK;
    DWORD cchString;

    hRes = CryptBinaryToStringA(pbBinary, cbBinary, CRYPT_STRING_BASE64|CRYPT_STRING_NOCRLF, NULL, &cchString);
    if(FAILED(hRes)){
        dbgout("[sync] send failed at CryptBinaryToString: %d\n", GetLastError());
        return E_FAIL;
    }

    *pszString = (LPSTR) malloc(cchString);

    if (pszString==NULL){
        dbgout("[sync] failed at allocate buffer: %d\n", GetLastError());
        return E_FAIL;
    }

    hRes = CryptBinaryToStringA(pbBinary, cbBinary, CRYPT_STRING_BASE64|CRYPT_STRING_NOCRLF, *pszString, &cchString);
    if(FAILED(hRes)){
        dbgout("[sync] send failed at CryptBinaryToString: %d\n", GetLastError());
        return E_FAIL;
    }

    /*
    CRYPT_STRING_NOCRLF 0x40000000
    Windows Server 2003 and Windows XP: This value is not supported
    */

    #if _NT_TARGET_VERSION_WINXPOR2K3
    trimcrlf(*pszString);
    #endif

    return hRes;
}
예제 #4
0
파일: f.c 프로젝트: noodles-v6/ACM
void solve() {
	char s[MAXSTR],t[MAXSTR];
	ll mask1=0,mask2=0,mask3;
	int i,j,tn;
	int source,sink,letters,words;
	int match[MAXSTR];
	fgets(s,MAXSTR-1,stdin); trimcrlf(s);
	for(i=j=0;;) {
		while(s[j]==' ') j++;
		if(!s[j]) break;
		t[i++]=s[j++];
	}
	t[i]=0;
	mask1=(1LL<<getix(t[0]))|(1LL<<getix(t[1]));
	for(i=2;t[i];i++) {
		if(!isalpha(t[i])) printf("illegal char [%c]\n",t[i]),exit(0);
		mask2|=(1LL<<getix(t[i]));
	}
	tn=strlen(t);
	for(ni=i=0;i<nw;i++) if((wmask[i]&mask1)==mask1 && (wmask[i]&mask2)) include[ni++]=i;
	if(ni<tn-2) {
		/* trivial reject - fewer eligible words than letters */
		puts("-1");
		return;
	}
	/* create graph */
	source=0;
	letters=1;
	words=letters+tn-2;
	sink=words+ni;
	n=sink+1;
	ne=0;
	if(n>MAXV) puts("increase MAXV and recompile"),exit(0);
	for(i=0;i<tn-2;i++) addedge(source,letters+i);
	for(i=0;i<tn-2;i++) for(j=0;j<ni;j++) {
		mask3=mask1|(1LL<<getix(t[i+2]));
		if((wmask[include[j]]&mask3)==mask3) addedge(letters+i,words+j);
	}
	for(i=0;i<ni;i++) addedge(words+i,sink);
	radixsort();
	inverseedges();
	memset(f,0,ne*sizeof(int));
	memset(cost,0,ne*sizeof(int));
	/* set capacities and costs */
	for(i=0;i<ne;i++) {
		if(from[i]==source) f[i]=1;
		if(to[i]==sink) f[i]=1,cost[i]=strlen(w[include[from[i]-words]]);
		if(from[i]==sink) f[i]=1,cost[i]=-strlen(w[include[to[i]-words]]);
		if(from[i]>=letters && from[i]<words && to[i]>=words && to[i]<sink) f[i]=1;
	}
	mincost(source,sink);
	for(i=0;i<ne;i++) if(from[i]==source && f[i]) {
		/* unmatched letter, reject */
		puts("-1");
		return;
	}
	printf("%d\n",tn-2);
	for(i=0;i<ne;i++) if(!f[i] && from[i]>=letters && from[i]<words && to[i]>=words && to[i]<sink)
		match[from[i]-letters]=to[i]-words;
	for(i=0;i<tn-2;i++) puts(w[include[match[i]]]);
}