Ejemplo n.º 1
0
        //public static string ReadSectionAllKey(string section)
        //{
        //    StringBuilder temp = new StringBuilder(512);
        //    GetPrivateProfileSection(section, temp, 512, __path);
        //    return temp.ToString();
        //    //string filePath = __path;

        //    //UInt32 MAX_BUFFER = 32767;

        //    //string[] items = new string[0];

        //    //IntPtr pReturnedString = Marshal.AllocCoTaskMem((int)MAX_BUFFER * sizeof(char));

        //    //UInt32 bytesReturned = GetPrivateProfileSection(section, pReturnedString, MAX_BUFFER, filePath);

        //    //if (!(bytesReturned == MAX_BUFFER - 2) || (bytesReturned == 0))
        //    //{
        //    //    string returnedString = Marshal.PtrToStringAuto(pReturnedString, (int)bytesReturned);

        //    //    items = returnedString.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
        //    //}

        //    //Marshal.FreeCoTaskMem(pReturnedString);

        //    //return items;
        //}

        /// <summary>  
        /// 获取INI文件中指定节点(Section)中的所有条目的Key列表  
        /// </summary>  
        /// <param name="iniFile">Ini文件</param>  
        /// <param name="section">节点名称</param>  
        /// <returns>如果没有内容,反回string[0]</returns>  
        public static string[] ReadSectionAllKey(string section)
        {
            int SIZE = 1024 * 10;

            if (string.IsNullOrEmpty(section))
            {
                throw new ArgumentException("必须指定节点名称", "section");
            }

            Byte[] Buffer = new Byte[16384];

            int bytesReturned = GetPrivateProfileString(section, null, null, Buffer, Buffer.GetUpperBound(0),__path);
            List<string> lt = new List<string>();

            if (bytesReturned != 0)
            {                                
                int start = 0;
                for (int i = 0; i < bytesReturned; i++)
                {
                    if ((Buffer[i] == 0) && ((i - start) > 0))
                    {
                        String s = Encoding.GetEncoding(0).GetString(Buffer, start, i - start);
                        lt.Add(s);
                        start = i + 1;
                    }
                }
            }


            return lt.ToArray();
        }  
Ejemplo n.º 2
0
 /// <summary>
 /// 读取指定节的所有键
 /// </summary>
 /// <param name="path"></param>
 /// <param name="section"></param>
 /// <param name="list"></param>
 public static void ReadSections(string path, string section, System.Collections.Specialized.StringCollection keys)
 {
     Byte[] buffer = new Byte[16384];
     long bufLen = GetPrivateProfileString(section, null, null, buffer, buffer.GetUpperBound(0), path);
     //对Section进行解析 
     GetStringsFromBuffer(buffer, bufLen, keys);
 }
Ejemplo n.º 3
0
        public string get(string Ident)
        {
            Byte[] Buffer = new Byte[65535];
            int bufLen = GetPrivateProfileString(this.section, Ident, "", Buffer, Buffer.GetUpperBound(0), this.iniFile);
            string s = Encoding.GetEncoding(0).GetString(Buffer);

            return s.Substring(0, bufLen).Trim();
        }
Ejemplo n.º 4
0
 /*read string from ini file*/
 public string ReadString(string Section, string Ident, string Default)
 {
     Byte[] Buffer = new Byte[65535];
     int bufLen = GetPrivateProfileString(Section, Ident, Default, Buffer, Buffer.GetUpperBound(0), FileName);
     //set 0 to support chinese
     string s = Encoding.GetEncoding(0).GetString(Buffer);
     s = s.Substring(0, bufLen);
     return s.Trim();
 }
Ejemplo n.º 5
0
 public void ReadSection(String Section, StringCollection Idents)
 {
     Byte[] Buffer = new Byte[16384];
     Idents.Clear();
     int bufLen = getPrivateProfileString(Section, null, null,
         Buffer, Buffer.GetUpperBound(0), filename);
     //��Section�����
     getStringsFromBuffer(Buffer, bufLen, Idents);
 }
Ejemplo n.º 6
0
	//读取INI文件指定
	public string readString(string Section, string Ident, string Default)
	{
		Byte[] Buffer = new Byte[65535];
		int bufLen = GetPrivateProfileString(Section, Ident, Default, Buffer, Buffer.GetUpperBound(0), FileName);
		//必须设定0(系统默认的代码页)的编码方式,否则无法支持中文
		string s = Encoding.GetEncoding(0).GetString(Buffer);
		s = s.Substring(0, bufLen);
		return s.Trim();
	}
Ejemplo n.º 7
0
        ////读INI文件 
        ///// <summary>
        ///// 读取Ini文件方法
        ///// </summary>
        ///// <param name="Section">区域名称</param>
        ///// <param name="Key">项目名称</param>
        ///// <returns></returns>
        //public string ReadTextFile(string Section, string Key)
        //{
        //    StringBuilder strTemp = new StringBuilder(9000);
        //    int i = GetPrivateProfileString(Section, Key, "", strTemp, 9000, this._Path);
        //    return (strTemp.ToString().Trim().Equals("") ? Key : strTemp.ToString());
        //}

        //读INI文件 
        /// <summary>
        /// 读取Ini文件方法
        /// </summary>
        /// <param name="Section">区域名称</param>
        /// <param name="Key">项目名称</param>
        /// <returns>返回读取结果</returns>
        public string ReadTextFile(string Section, string Key)
        {
            Byte[] Buffer = new Byte[400];
            int bufLen = GetPrivateProfileString(Section, Key, "", Buffer, Buffer.GetUpperBound(0), this._Path);

            //以Utf-8的编码来显示的编码方式,否则无法支持日文操作系统
            System.Text.Encoding enc=System.Text.Encoding.UTF8;
            string s = enc.GetString(Buffer);
            return s.Replace("\0","").Trim();
  

        }
Ejemplo n.º 8
0
        // ------------------------------------------------------------------------
        // Read values from textboxes
        // ------------------------------------------------------------------------
        private byte[] GetData(int num)
        {
            bool[] bits	= new bool[num];
            byte[] data	= new Byte[num];
            int[]  word	= new int[num];

            // ------------------------------------------------------------------------
            // Convert data from text boxes
            foreach(Control ctrl in grpData.Controls)
            {
                if (ctrl is TextBox)
                {
                    int x = Convert.ToInt16(ctrl.Tag);
                    if(radBits.Checked)
                    {
                        if((x <= bits.GetUpperBound(0)) && (ctrl.Text != "")) bits[x] = Convert.ToBoolean(Convert.ToByte(ctrl.Text));
                        else break;
                    }
                    if(radBytes.Checked)
                    {
                        if((x <= data.GetUpperBound(0)) && (ctrl.Text != "")) data[x] = Convert.ToByte(ctrl.Text);
                        else break;
                    }
                    if(radWord.Checked)
                    {
                        if ((x <= data.GetUpperBound(0)) && (ctrl.Text != ""))
                        {
                            try { word[x] = Convert.ToInt16(ctrl.Text); }
                            catch(SystemException) { word[x] = Convert.ToUInt16(ctrl.Text);};
                        }
                        else break;
                    }
                }
            }
            if(radBits.Checked)
            {
                int numBytes		= (byte)(num / 8 + (num % 8 > 0 ? 1 : 0));
                data				= new Byte[numBytes];
                BitArray bitArray	= new BitArray(bits);
                bitArray.CopyTo(data, 0);
            }
            if(radWord.Checked)
            {
                data = new Byte[num*2];
                for(int x=0;x<num;x++)
                {
                    byte[] dat = BitConverter.GetBytes((short) IPAddress.HostToNetworkOrder((short) word[x]));
                    data[x*2]	= dat[0];
                    data[x*2+1] = dat[1];
                }
            }
            return data;
        }
Ejemplo n.º 9
0
        public void ReadSection(string Section, StringCollection Idents)
        {
            Byte[] Buffer = new Byte[16384];

            int bufLen = GetPrivateProfileString(Section, null, null, Buffer, Buffer.GetUpperBound(0),
             FileName);
            GetStringsFromBuffer(Buffer, bufLen, Idents);
        }
Ejemplo n.º 10
0
 //��ȡINI�ļ�ָ��
 public string ReadString(string Section, string Ident, string Default)
 {
     Byte[] Buffer = new Byte[65535];
     int bufLen = GetPrivateProfileString(Section, Ident, Default, Buffer, Buffer.GetUpperBound(0), FileName);
     //�����趨0��ϵͳĬ�ϵĴ���ҳ���ı��뷽ʽ�������޷�֧������
     string s = Encoding.GetEncoding(0).GetString(Buffer);
     s = s.Substring(0, bufLen);
     return s.Trim();
 }
Ejemplo n.º 11
0
		///  <summary>
		///  Sends an Output report.
		///  Assumes report ID = 0.
		///  </summary>

		private async void RequestToSendOutputReport()
		{
			const Int32 writeTimeout = 5000;
			String byteValue = null;

			try
			{
				//  If the device hasn't been detected, was removed, or timed out on a previous attempt
				//  to access it, look for the device.

				if (!_deviceHandleObtained)
				{
					_deviceHandleObtained = FindTheHid();
				}

				if (_deviceHandleObtained)
				{
					GetBytesToSend();
				}
				//  Don't attempt to exchange reports if valid handles aren't available
				//  (as for a mouse or keyboard.)

				if (!_hidHandle.IsInvalid)
				{
					//  Don't attempt to send an Output report if the HID has no Output report.

					if (_myHid.Capabilities.OutputReportByteLength > 0)
					{
						//  Set the size of the Output report buffer.   

						var outputReportBuffer = new Byte[_myHid.Capabilities.OutputReportByteLength];

						//  Store the report ID in the first byte of the buffer:

						outputReportBuffer[0] = 0;

						//  Store the report data following the report ID.
						//  Use the data in the combo boxes on the form.

						outputReportBuffer[1] = Convert.ToByte(CboByte0.SelectedIndex);

						if (outputReportBuffer.GetUpperBound(0) > 1)
						{
							outputReportBuffer[2] = Convert.ToByte(CboByte1.SelectedIndex);
						}

						//  Write a report.

						Boolean success;

						if (_transferType.Equals(TransferTypes.Control))
						{
							{
								_transferInProgress = true;

								//  Use a control transfer to send the report,
								//  even if the HID has an interrupt OUT endpoint.

								success = _myHid.SendOutputReportViaControlTransfer(_hidHandle, outputReportBuffer);

								_transferInProgress = false;
								cmdSendOutputReportControl.Enabled = true;
							}
						}
						else
						{
							Debug.Print("interrupt");
							_transferInProgress = true;

							// The CancellationTokenSource specifies the timeout value and the action to take on a timeout.

							var cts = new CancellationTokenSource();

							// Create a delegate to execute on a timeout.

							Action onWriteTimeoutAction = OnWriteTimeout;

							// Cancel the read if it hasn't completed after a timeout.

							cts.CancelAfter(writeTimeout);

							// Specify the function to call on a timeout.

							cts.Token.Register(onWriteTimeoutAction);

							// Send an Output report and wait for completion or timeout.

							success = await _myHid.SendOutputReportViaInterruptTransfer(_deviceData, _hidHandle, outputReportBuffer, cts);

							// Get here only if the operation completes without a timeout.

							_transferInProgress = false;
							cmdSendOutputReportInterrupt.Enabled = true;

							// Dispose to stop the timeout timer.

							cts.Dispose();
						}
						if (success)
						{
							DisplayReportData(outputReportBuffer, ReportTypes.Output, ReportReadOrWritten.Written);
						}
						else
						{
							CloseCommunications();
							AccessForm(FormActions.AddItemToListBox, "The attempt to write an Output report failed.");
							ScrollToBottomOfListBox();
						}
					}
				}
				else
				{
					AccessForm(FormActions.AddItemToListBox, "The HID doesn't have an Output report.");
				}
			}

			catch (Exception ex)
			{
				DisplayException(Name, ex);
				throw;
			}
		}
Ejemplo n.º 12
0
		///  <summary>
		///  Sends a Feature report.
		///  Assumes report ID = 0.
		///  </summary>

		private void RequestToSendFeatureReport()
		{
			String byteValue = null;

			try
			{
				_transferInProgress = true;

				//  If the device hasn't been detected, was removed, or timed out on a previous attempt
				//  to access it, look for the device.

				if (!_deviceHandleObtained)
				{
					_deviceHandleObtained = FindTheHid();
				}

				if (_deviceHandleObtained)
				{
					GetBytesToSend();

					if ((_myHid.Capabilities.FeatureReportByteLength > 0))
					{
						//  The HID has a Feature report.
						//  Set the size of the Feature report buffer. 

						var outFeatureReportBuffer = new Byte[_myHid.Capabilities.FeatureReportByteLength];

						//  Store the report ID in the buffer.

						outFeatureReportBuffer[0] = 0;

						//  Store the report data following the report ID.
						//  Use the data in the combo boxes on the form.

						outFeatureReportBuffer[1] = Convert.ToByte(CboByte0.SelectedIndex);

						if (outFeatureReportBuffer.GetUpperBound(0) > 1)
						{
							outFeatureReportBuffer[2] = Convert.ToByte(CboByte1.SelectedIndex);
						}

						//  Write a report to the device

						Boolean success = _myHid.SendFeatureReport(_hidHandle, outFeatureReportBuffer);

						if (success)
						{
							DisplayReportData(outFeatureReportBuffer, ReportTypes.Feature, ReportReadOrWritten.Written);
						}
						else
						{
							CloseCommunications();
							AccessForm(FormActions.AddItemToListBox, "The attempt to send a Feature report failed.");
							ScrollToBottomOfListBox();
						}
					}

					else
					{
						AccessForm(FormActions.AddItemToListBox, "The HID doesn't have a Feature report.");
						ScrollToBottomOfListBox();
					}

				}
				_transferInProgress = false;
				cmdSendFeatureReport.Enabled = true;
				ScrollToBottomOfListBox();

			}
			catch (Exception ex)
			{
				DisplayException(Name, ex);
				throw;
			}
		}
Ejemplo n.º 13
0
 //读操作
 public string GetSectionKey_StringValue(string section, string key, string value)
 {
     StringBuilder sb = new StringBuilder(500);
     Byte[] Buffer = new Byte[65535];
     int bufLen = GetPrivateProfileString(section, key, value, Buffer, Buffer.GetUpperBound(0), filePath);
     string s = Encoding.GetEncoding(0).GetString(Buffer);
     s = s.Substring(0, bufLen);
     return s.Trim();
 }
Ejemplo n.º 14
0
        //从Ini文件中,将指定的Section名称中的所有Ident添加到列表中
        public void ReadSection(string Section, StringCollection Idents)
        {
            Byte[] Buffer = new Byte[32768];
            //Idents.Clear();

            int bufLen = GetPrivateProfileString(Section, null, null, Buffer, Buffer.GetUpperBound(0),
            FileName);
            //对Section进行解析
            GetStringsFromBuffer(Buffer, bufLen, Idents);
        }
Ejemplo n.º 15
0
 internal static void clean(ref Byte[] Data)
 {
     for (int count = 0; count <= Data.GetUpperBound(0); count++)
     {
         Data[count] = (byte)new Random().Next((int)Byte.MinValue, (int)byte.MaxValue);
     }
 }
Ejemplo n.º 16
0
 //读取INI文件指定
 public string ReadString(string Section, string Ident, string Default)
 {
     Byte[] Buffer = new Byte[65535];
     char[] sCdest = new char[65535];
     string sDest = "";
     int bufLen = GetPrivateProfileString(Section, Ident, Default, Buffer, Buffer.GetUpperBound(0), FileName);
     //必须设定0(系统默认的代码页)的编码方式,否则无法支持中文
     //string s = Encoding.GetEncoding(0).GetString(Buffer);
      string s = Encoding.GetEncoding(0).GetString(Buffer);
     s = s.Replace("\0","");
     s = s.Substring(0, s.Length);
     //s = s.Replace("\n", string.Empty).Replace("\r", string.Empty);
     return s.Trim();
 }
Ejemplo n.º 17
0
        //GeDirディレクトリを見つかる。
        private static string getLogConfigFilePath()
        {
            string gedir = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            if (gedir.EndsWith(@"\"))
            {
                gedir = gedir.Substring(0, gedir.Length - 1);
            }
            int index = 0;
            index = gedir.LastIndexOf(@"\");
            if (index > 0)
            {
                gedir = gedir.Substring(0, index + 1) + "Ini";
            }

            //APPサーバの配置ファイルを見つかる。
            Byte[] Buffer = new Byte[1024];
            string appSvrConfig = "";
            int bufLen = GetPrivateProfileString("PATH", "AppSvrConfig", "", Buffer, Buffer.GetUpperBound(0), gedir + @"\Gedir.ini");
            if (bufLen > 0)
            {
                appSvrConfig = System.Text.Encoding.GetEncoding(0).GetString(Buffer);
                appSvrConfig = appSvrConfig.Substring(0, bufLen);
            }

            return appSvrConfig;
        }
Ejemplo n.º 18
0
	/// <summary>
	/// Read BLOB field to stream property
	/// </summary>
	/// <param name="objID">Stream owner object ID</param>
	/// <param name="propName">Name of stream property</param>
	/// <returns>
	/// Persistent stream that contains BLOB data.
	/// </returns>
	private PersistentStream read_blob( int objID, string propName )
	{
		#region debug info
#if (DEBUG)
		Debug.Print( "<- ODB.imageRead( {0}, '{1}' )", objID, propName );
#endif
		#endregion

		// create stream to return as result
		PersistentStream stream = new PersistentStream();

		// get pointer to BLOB field using TEXTPTR.
		DbCommand cmd = new SqlCommand( string.Format(
			"SELECT @Pointer = TEXTPTR([Value]), @Length = DataLength([Value])\n" +
			"FROM [dbo].[_images]\n" +
			"WHERE [ObjectID] = {0} AND [Name] ='{1}'",
			objID, propName) );
		cmd.Connection = m_con;
		cmd.Transaction = m_trans;
		// setup parameters
		DbParameter pointerParam = new SqlParameter("@Pointer", SqlDbType.VarBinary, 16);
		pointerParam.Direction = ParameterDirection.Output;
		cmd.Parameters.Add( pointerParam );
		DbParameter lengthParam = new SqlParameter("@Length", SqlDbType.Int);
		lengthParam.Direction = ParameterDirection.Output;
		cmd.Parameters.Add( lengthParam );
		// open connection and start new transaction if required
		TransactionBegin();
		try {
			// get pointer and length of BLOB field
			cmd.ExecuteNonQuery();

			//check that BLOB field exists
			if( pointerParam.Value == null ) {
				throw new KeyNotFoundException( ERROR_IMAGE_IS_ABSENT );
			}

			// run the query.
			// set up the READTEXT command to read the BLOB by passing the following
			// parameters: @Pointer – pointer to blob, @Offset – number of bytes to
			// skip before starting the read, @Size – number of bytes to read.
			cmd = new SqlCommand(
				"READTEXT [dbo].[_images].[Value] @Pointer @Offset @Size HOLDLOCK");
			cmd.Connection = m_con;
			cmd.Transaction = m_trans;
			// temp buffer for read/write purposes
			Byte[] buffer = new Byte[BUFFER_LENGTH];

			// set up the parameters for the command.
			cmd.Parameters.Add( new SqlParameter("@Pointer", pointerParam.Value) );
			// current offset position
			DbParameter offset = new SqlParameter("@Offset", SqlDbType.Int);
			offset.Value = 0;
			cmd.Parameters.Add( offset );
			DbParameter size =  new SqlParameter("@Size", SqlDbType.Int);
			size.Value = 0;
			cmd.Parameters.Add( size );

			while( Convert.ToInt32(offset.Value) < Convert.ToInt32( lengthParam.Value ) ) {
				// calculate buffer size - may be less than BUFFER_LENGTH for last block.
				if( (Convert.ToInt32( offset.Value ) + buffer.GetUpperBound( 0 ))
					>=
					Convert.ToInt32( lengthParam.Value ) )
					// setting size parameter
					size.Value =
						Convert.ToInt32( lengthParam.Value ) -
						Convert.ToInt32( offset.Value );
				else
					size.Value = buffer.GetUpperBound( 0 );

				// execute reader
				DbDataReader dr =
					cmd.ExecuteReader( CommandBehavior.SingleRow );

				try {
					// read data from SqlDataReader
					dr.Read();
					// put data to buffer
					// and return size of read data
					int count = Convert.ToInt32(
						dr.GetBytes( 0, 0, buffer, 0, Convert.ToInt32( size.Value ) ) );
					// append buffer data to stream
					stream.Write( buffer, 0, count );
					// increment offset
					offset.Value = Convert.ToInt32( offset.Value ) + count;
				} finally { dr.Dispose(); /*dispose DataReader*/}
			}
			// seek to begin of the stream after writing data
			stream.Seek( 0, SeekOrigin.Begin );
		} catch( Exception ex ) {
			#region dubug info
#if (DEBUG)
			Debug.Print( "[ERROR] @ ODB.imageRead: {0}", ex.Message );
#endif
			#endregion
			// rollback failed transaction
			TransactionRollback();
			throw;
		}
		// close connection and commit transaction if required
		TransactionCommit();

		#region debug info
#if (DEBUG)
		Debug.Print( "<- ODB.imageRead( {0}, '{1}' )", objID, propName );
#endif
		#endregion

		// return filled with SQL BLOB stream
		return stream;
	}
Ejemplo n.º 19
0
        public void PacketSender2(Byte[] pPacket)
        {
            IntPtr BytesAddr;
            long pSize;
            Byte[] pCode;

            pSize = pPacket.GetUpperBound(0) - pPacket.GetLowerBound(0) + 1;
            BytesAddr = VirtualAllocEx(GameProcessHandle, IntPtr.Zero, pPacket.Length, MEM_COMMIT, PAGE_READWRITE);
            if (DEBUG_MODE)
                log("VAM Address: " + AlignDWORD(BytesAddr));

            if (BytesAddr == IntPtr.Zero || BytesAddr == null)
            {
                if (DEBUG_MODE)
                    log(">>> Error commiting memory: " + AlignDWORD(BytesAddr));
                VirtualFreeEx(GameProcessHandle, BytesAddr, 0, MEM_RELEASE);
                return;
            }

            WriteProcessMemory(GameProcessHandle, BytesAddr, pPacket, pSize, 0);

            String cCode = "608B0D" + AlignDWORD(new IntPtr(PTR_PKT)) + "68" + AlignDWORD(new IntPtr(pSize)) + "68" + AlignDWORD(BytesAddr) + "BF" + AlignDWORD(new IntPtr(SND_FNC)) + "FFD7C605" + AlignDWORD(new IntPtr(PTR_PKT + 0xC5)) + "0061C3";
            pCode = ToByteArray(cCode);
            ExecuteRemoteCode(pCode);

            WriteMemory(new IntPtr(PTR_PKT + 0xC5), 0);
            VirtualFreeEx(GameProcessHandle, BytesAddr, 0, MEM_RELEASE);
        }
Ejemplo n.º 20
0
 public String ReadString(String Section, String Ident, String Default)
 {
     //StringBuilder Buffer = new StringBuilder(255);
     Byte[] Buffer = new Byte[65535];
     int bufLen = getPrivateProfileString(Section, Ident, Default, Buffer, Buffer.GetUpperBound(0), filename);
     //�����趨0��ϵͳĬ�ϵĴ���ҳ���ı��뷽ʽ�������޷�֧������
     string s = Encoding.GetEncoding(0).GetString(Buffer);
     s = s.Substring(0, bufLen);
     return s.Trim();
 }