Example #1
0
	//这个函数的特点是可以指定输入数据的长度,注意,input的有效数据长度必须是16的整数倍,input的大小必须大于等于len。
	//但是outbuf仅仅存储,有效的输出长度。
	int Aes::DecryptEcb(Memory<char>& outbuf,const void* input,int len){
		if(len<=0) return 0;
		if(outbuf.Length()<(uint)len){
			if(!outbuf.SetLength(len)) return 0;
		}
		return DecryptEcb(outbuf.Handle(),len,input,len);
	}
Example #2
0
	int Base64::Encode(Memory<char>& output,const void* data,int len){
		int dlen = 0;
		base64_encode(0,&dlen,(uchar*)data,len);
		if(dlen==0) return 0;
		if(!output.SetLength(dlen)) return 0;
		base64_encode((byte*)output.Handle(),&dlen,(uchar*)data,len);
		return dlen;
	}
Example #3
0
	int Base64::Decode(Memory<char>& output,const char* data,int len){
		if(len==-1) len = strlen(data);
		int dlen = 0;
		base64_decode(0,&dlen,(uchar*)data,len);
		if(dlen==0) return 0;
		if(!output.SetLength(dlen)) return 0;
		base64_decode((byte*)output.Handle(),&dlen,(uchar*)data,len);
		return dlen;
	}
Example #4
0
	//返回值是加密数据的长度,outbuf会自动设置大小,但是不一定是数据长度,可能大于它。
	int Aes::EncryptEcb(Memory<char>& outbuf,const void* input,int len){
		if(len<=0) return 0;
		int lastn = len&0xF;
		int outLen;
		if(lastn) outLen = len - lastn + 16;
		else outLen = len;
		if(outbuf.Length()<(uint)outLen){
			if(!outbuf.SetLength(outLen)) return 0;
		}
		return EncryptEcb(outbuf.Handle(),outLen,input,len);
	}
Example #5
0
File: json.cpp Project: Jesna/jucpp
	int _parseBinary(LPCWSTR jstr,int pos,int maxlen,Memory<char>* mbin){
		String bin;
		for(int i=pos;i<maxlen;i++){
			if(jstr[i]=='\''){
				bin.CopyFrom(jstr+pos,i-pos);
				Memory<char> buf;
				int len = bin.ToMultiByte(&buf);
				Base64::Decode(*mbin,buf.Handle(),len);
				return i+1;
			}
		}
		return -1;
	}
Example #6
0
	UINT_PTR FileDialog::OFNHookProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
	{
		if(_Handle==0) _Handle = ::GetParent(hDlg);
		if(uMsg==WM_NOTIFY)
		{
			LPOFNOTIFY pon = (LPOFNOTIFY)lParam;
			switch(pon->hdr.code)
			{
			case CDN_SELCHANGE:
				{
					/*if(OnSelChange.IsNull()) break;
					Memory<wchar_t> path(MAX_PATH),file(MAX_PATH);
					int n = (int)::SendMessage(_Handle,CDM_GETFILEPATH,(WPARAM)MAX_PATH,(LPARAM)path.Handle());
					这个消息返回的值包括目录和文件名,目录们没有引号,文件名用空格分隔并且用引号包围,目录和文件名之间没有空格,目录末尾包含反斜杠。
					但是引号有时没有,有时有,如果文件名包含空格,实际上无法正确获取文件名,所以此方法实际上不可用。
					if(n<0) path[0] = 0;
					n = (int)::SendMessage(_Handle,CDM_GETSPEC,(WPARAM)MAX_PATH,(LPARAM)file.Handle());
					这个消息返回文件名,规则同上。
					if(n<0) path[0] = 0;
					OnSelChange(path,file);*/
					break;
				}
			case CDN_FOLDERCHANGE:
				{
					if(!OnFolderChange.IsNull()){
						Memory<wchar_t> path;
						path.SetLength(MAX_PATH);
						int n = (int)::SendMessage(_Handle,CDM_GETFOLDERPATH,(WPARAM)MAX_PATH,(LPARAM)path.Handle());
						if(n<0){
							path[0] = 0;
						}
						OnFolderChange(path,this);
					}
					break;
				}
			case CDN_FILEOK://this message is ago okid message,if return TRUE then no okid message;
				if((!OnFileOk.IsNull())&&(OnFileOk(pon->lpOFN,this)))
				{
					SetWindowLong(_Handle,DWL_MSGRESULT,1L);
					return 1;
				}
				break;
			case CDN_TYPECHANGE:
				if(!OnTypeChange.IsNull()) OnTypeChange(pon->lpOFN->nFilterIndex,this);
				break;
			}
		}
		return 0;
	};
Example #7
0
	//class ImgEncode
	bool GetImageEncoderClsid(const wchar_t* type,CLSID* pClsid){
		static Memory<char> buffer;
		static UINT number = 0;
		Gdiplus::ImageCodecInfo* imageCodecInfo = (Gdiplus::ImageCodecInfo*)buffer.Handle();
		if(imageCodecInfo==0){
			UINT size = 0;
			Gdiplus::GetImageEncodersSize(&number,&size);
			if(!size) return 0;
			buffer.SetLength(size);
			imageCodecInfo = (Gdiplus::ImageCodecInfo*)buffer.Handle();
			Gdiplus::GetImageEncoders(number,size,imageCodecInfo);
		}
		Registry reg;
		if(!reg.Create(type,HKEY_CLASSES_ROOT)) return 0;
		String str(16);
		if(!reg.GetStrValue(L"Content Type",str)) return 0;
		for(UINT i=0;i<number;i++){
			if(WcsEqual(str,imageCodecInfo[i].MimeType)){
				*pClsid = imageCodecInfo[i].Clsid;
				return 1;
			}
		}
		return 0;
	}
Example #8
0
	int Image::Save(Memory<char>& mem,LPCWSTR type,long quality){
		if(_image==0) return 0;

		CLSID clsid;
		//未知原因,如果不用一个变量转换一下,type是一个常量字串的话,如果把 type 直接传给 GetImageEncoderClsid 会引起程序崩溃。
		//wchar_t tp[256];
		//这样也不行。
		//cs::WcsCopy(tp,type);
		cs::String tp = type;
		if(!GetImageEncoderClsid(tp,&clsid)) return 0;

		if(quality>100) quality = 100;
		if(quality<0) quality = 0;
		Gdiplus::EncoderParameters eps;
		eps.Count = 1;
		eps.Parameter[0].Guid = Gdiplus::EncoderQuality;
		eps.Parameter[0].NumberOfValues = 1;
		eps.Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong;
		eps.Parameter[0].Value = &quality;

		IStream* stream;
		if(FAILED(CreateStreamOnHGlobal(0,1,&stream))) return 0;
		if(((_Image*)_image)->Save(stream,&clsid,&eps)!=0) return 0;

		ULONG ws = 0;
		LARGE_INTEGER li;
		ULARGE_INTEGER npos;
		li.QuadPart = 0;
		stream->Seek(li,STREAM_SEEK_END,&npos);
		if(mem.Length()<npos.LowPart){
			mem.SetUseSysMemory(1);
			if(!mem.SetLength(npos.LowPart)) return 0;
		}
		stream->Seek(li,STREAM_SEEK_SET,0);

		HRESULT ret = stream->Read(mem.Handle(),mem.Length(),&ws);
		stream->Release();
		if(FAILED(ret)) return 0;
		return ws;
	}
Example #9
0
	uint Image::GetPropertyItem(Memory<ImageItem>& tms){
		if(!_image) return 0;
		int nSize = ((_Image*)_image)->GetPropertyItemSize(PropertyTagFrameDelay);   
		tms.SetLength(nSize);
		((_Image*)_image)->GetPropertyItem(PropertyTagFrameDelay, nSize, (Gdiplus::PropertyItem*)tms.Handle());   
		return nSize;
	}
Example #10
0
File: json.cpp Project: Jesna/jucpp
	void _toString(Json* jsn,String& str,String& tab,bool readStyle){
		if(jsn->_type==json_null){
			str = L"null";
		}else if(jsn->_type==json_boolean){
			str = jsn->_boolValue?L"true":L"false";
		}else if(jsn->_type==json_integer){
			str.FromInt64(jsn->_intValue,10);
		}else if(jsn->_type==json_double){
			str.Format(L"%#.16g",jsn->_doubleValue);
		}else if(jsn->_type==json_string){
			addSlash(jsn->_strValue->Handle(),jsn->_strValue->Length(),str,readStyle);
			str.Insert('"',0);
			str.Insert('"');
		}else if(jsn->_type==json_array){
			if(readStyle)
				str = L"[\r\n";
			else
				str = L"[";
			String sub;
			ObjectLink<Json>& a = *jsn->_arrayValue;
			a.First();
			Json* sjsn = a.Element();
			if(sjsn){
				if(readStyle)
					tab += L"\t";
				_toString(sjsn,sub,tab,readStyle);
				str += tab;
				str += sub;
				while(true){
					a.Move(1);
					sjsn = a.Element();
					if(!sjsn) break;
					_toString(sjsn,sub,tab,readStyle);
					if(readStyle)
						str += L",\r\n";
					else
						str += L",";
					str += tab;
					str += sub;
				}
				tab.Head(-1);
				if(readStyle)
					str += L"\r\n";
			}
			str += tab;
			str += L"]";
		}else if(jsn->_type==json_object){
			if(readStyle)
				str = L"{\r\n";
			else
				str = L"{";
			String sub;
			ObjectLink<Json::DICTION>& obj = *jsn->_objectValue;
			obj.First();
			Json::DICTION* dic = obj.Element();
			if(dic){
				if(readStyle){
					tab += L"\t";
					str += tab;
				}
				str += L"\"";
				addSlash(dic->key,dic->key.Length(),sub,readStyle);
				str += sub;
				if(readStyle){
					str += L"\" : ";
				}else{
					str += L"\":";
				}
				_toString(dic->val,sub,tab,readStyle);
				str += sub;
				while(true){
					obj.Move(1);
					dic = obj.Element();
					if(!dic) break;
					if(readStyle){
						str += L",\r\n";
						str += tab;
					}else{
						str += L",";
					}
					str += L"\"";
					addSlash(dic->key,dic->key.Length(),sub,readStyle);
					str += sub;
					if(readStyle){
						str += L"\" : ";
					}else{
						str += L"\":";
					}
					_toString(dic->val,sub,tab,readStyle);
					str += sub;
				}
				tab.Head(-1);
				if(readStyle)
					str += L"\r\n";
			}
			str += tab;
			str += L"}";
		}else if(jsn->_type==json_binary){
			Memory<char> code;
			int len = Base64::Encode(code,jsn->_binaryValue->Handle(),jsn->_binaryValue->Length());
			str.FromMultiByte((LPCSTR)code.Handle(),len);
			str.Insert('\'',0);
			str.Insert('\'');
		}
	}