Пример #1
0
 public static bool FindLocation(ref int x, ref int y, ref int z, ref int facet)
 {
     Ultima.LocationPointer locationPointer = Client.LocationPointer;
     System.ProcessStream   processStream   = Client.ProcessStream;
     if (processStream == null || locationPointer == null)
     {
         return(false);
     }
     processStream.BeginAccess();
     if (locationPointer.PointerX > 0)
     {
         processStream.Seek((long)locationPointer.PointerX, SeekOrigin.Begin);
         x = Client.Read(processStream, locationPointer.SizeX);
     }
     if (locationPointer.PointerY > 0)
     {
         processStream.Seek((long)locationPointer.PointerY, SeekOrigin.Begin);
         y = Client.Read(processStream, locationPointer.SizeY);
     }
     if (locationPointer.PointerZ > 0)
     {
         processStream.Seek((long)locationPointer.PointerZ, SeekOrigin.Begin);
         z = Client.Read(processStream, locationPointer.SizeZ);
     }
     if (locationPointer.PointerF > 0)
     {
         processStream.Seek((long)locationPointer.PointerF, SeekOrigin.Begin);
         facet = Client.Read(processStream, locationPointer.SizeF);
     }
     processStream.EndAccess();
     return(true);
 }
Пример #2
0
        public static int Search(System.ProcessStream pc, byte[] buffer)
        {
            int length = 4096 + (int)buffer.Length;

            pc.BeginAccess();
            byte[] numArray = new byte[length];
            int    num      = 0;

            while (true)
            {
                pc.Seek((long)(4194304 + num * 4096), SeekOrigin.Begin);
                if (pc.Read(numArray, 0, length) != length)
                {
                    break;
                }
                for (int i = 0; i < 4096; i++)
                {
                    bool flag = true;
                    for (int j = 0; flag && j < (int)buffer.Length; j++)
                    {
                        flag = buffer[j] == numArray[i + j];
                    }
                    if (flag)
                    {
                        pc.EndAccess();
                        return(4194304 + num * 4096 + i);
                    }
                }
                num++;
            }
            pc.EndAccess();
            return(0);
        }
 public virtual void EndAccess()
 {
     if (!this.m_Open)
     {
         return;
     }
     ProcessStream.CloseHandle(this.m_Process);
     this.m_Open = false;
 }
 public virtual bool BeginAccess()
 {
     if (this.m_Open)
     {
         return(false);
     }
     this.m_Process = ProcessStream.OpenProcess(2035711, 0, this.ProcessID);
     this.m_Open    = true;
     return(true);
 }
Пример #5
0
        public static int Read(System.ProcessStream pc, int bytes)
        {
            int num;
            int num1;
            int i;

            byte[] numArray = new byte[bytes];
            pc.Read(numArray, 0, bytes);
            switch (bytes)
            {
            case 1:
            {
                return((sbyte)numArray[0]);
            }

            case 2:
            {
                return((short)(numArray[0] | numArray[1] << 8));
            }

            case 3:
            {
                num  = 0;
                num1 = 0;
                for (i = 0; i < (int)numArray.Length; i++)
                {
                    num  = num | numArray[i] << (num1 & 31);
                    num1 = num1 + 8;
                }
                return(num);
            }

            case 4:
            {
                return(numArray[0] | numArray[1] << 8 | numArray[2] << 16 | numArray[3] << 24);
            }

            default:
            {
                num  = 0;
                num1 = 0;
                for (i = 0; i < (int)numArray.Length; i++)
                {
                    num  = num | numArray[i] << (num1 & 31);
                    num1 = num1 + 8;
                }
                return(num);
            }
            }
        }
Пример #6
0
        public static void Calibrate(CalibrationInfo[] info)
        {
            Client.m_LocationPointer = null;
            System.ProcessStream processStream = Client.ProcessStream;
            if (processStream == null)
            {
                return;
            }
            int num  = 0;
            int num1 = 0;
            int num2 = 0;
            int num3 = 0;
            int num4 = 0;
            int num5 = 0;
            int num6 = 0;
            int num7 = 0;

            for (int i = 0; i < (int)info.Length; i++)
            {
                CalibrationInfo calibrationInfo = info[i];
                int             num8            = Client.Search(processStream, calibrationInfo.Mask, calibrationInfo.Vals);
                if (num8 != 0)
                {
                    if (num == 0 && (int)calibrationInfo.DetX.Length > 0)
                    {
                        Client.GetCoordDetails(processStream, num8, calibrationInfo.DetX, out num, out num1);
                    }
                    if (num2 == 0 && (int)calibrationInfo.DetY.Length > 0)
                    {
                        Client.GetCoordDetails(processStream, num8, calibrationInfo.DetY, out num2, out num3);
                    }
                    if (num4 == 0 && (int)calibrationInfo.DetZ.Length > 0)
                    {
                        Client.GetCoordDetails(processStream, num8, calibrationInfo.DetZ, out num4, out num5);
                    }
                    if (num6 == 0 && (int)calibrationInfo.DetF.Length > 0)
                    {
                        Client.GetCoordDetails(processStream, num8, calibrationInfo.DetF, out num6, out num7);
                    }
                    if (num != 0 && num2 != 0 && num4 != 0 && num6 != 0)
                    {
                        break;
                    }
                }
            }
            if (num != 0 || num2 != 0 || num4 != 0 || num6 != 0)
            {
                Client.m_LocationPointer = new Ultima.LocationPointer(num, num2, num4, num6, num1, num3, num5, num7);
            }
        }
        public override unsafe void Write(byte[] buffer, int offset, int count)
        {
            bool flag = !this.BeginAccess();

            fixed(byte *numPtr = &buffer[0])
            ProcessStream.WriteProcessMemory(this.m_Process, this.m_Position, (void *)(numPtr + offset), count, 0);

            this.m_Position += count;
            if (!flag)
            {
                return;
            }
            this.EndAccess();
        }
        public override unsafe int Read(byte[] buffer, int offset, int count)
        {
            bool flag = !this.BeginAccess();
            int  op   = 0;

            fixed(byte *numPtr = &buffer[0])
            ProcessStream.ReadProcessMemory(this.m_Process, this.m_Position, (void *)(numPtr + offset), count, ref op);

            this.m_Position += count;
            if (flag)
            {
                this.EndAccess();
            }
            return(op);
        }
Пример #9
0
 private static void GetCoordDetails(System.ProcessStream pc, int ptr, byte[] dets, out int coordPointer, out int coordSize)
 {
     pc.Seek((long)(ptr + dets[0]), SeekOrigin.Begin);
     coordPointer = Client.Read(pc, (int)dets[1]);
     if (dets[2] < 255)
     {
         pc.Seek((long)coordPointer, SeekOrigin.Begin);
         coordPointer = Client.Read(pc, (int)dets[2]);
     }
     if (dets[3] < 255)
     {
         pc.Seek((long)(ptr + dets[3]), SeekOrigin.Begin);
         coordPointer = coordPointer + Client.Read(pc, (int)dets[4]);
     }
     coordSize = dets[5];
 }
Пример #10
0
        public static void Calibrate(int x, int y, int z)
        {
            Client.m_LocationPointer = null;
            System.ProcessStream processStream = Client.ProcessStream;
            if (processStream == null)
            {
                return;
            }
            byte[] numArray = new byte[] { (byte)z, (byte)(z >> 8), (byte)(z >> 16), (byte)(z >> 24), (byte)y, (byte)(y >> 8), (byte)(y >> 16), (byte)(y >> 24), (byte)x, (byte)(x >> 8), (byte)(x >> 16), (byte)(x >> 24) };
            int    num      = Client.Search(processStream, numArray);

            if (num == 0)
            {
                return;
            }
            Client.m_LocationPointer = new Ultima.LocationPointer(num + 8, num + 4, num, 0, 4, 4, 4, 0);
        }
        public override void Write(byte[] buffer, int offset, int count)
        {
            unsafe
            {
                bool flag = !this.BeginAccess();
                fixed(byte *numPointer = &buffer[0])
                {
                    ProcessStream.WriteProcessMemory(this.m_Process, this.m_Position, numPointer + offset, count, 0);
                }

                ProcessStream mPosition = this;
                mPosition.m_Position = mPosition.m_Position + count;
                if (flag)
                {
                    this.EndAccess();
                }
            }
        }
        public override int Read(byte[] buffer, int offset, int count)
        {
            unsafe
            {
                bool flag = !this.BeginAccess();
                int  num  = 0;
                fixed(byte *numPointer = &buffer[0])
                {
                    ProcessStream.ReadProcessMemory(this.m_Process, this.m_Position, numPointer + offset, count, ref num);
                }

                ProcessStream mPosition = this;
                mPosition.m_Position = mPosition.m_Position + count;
                if (flag)
                {
                    this.EndAccess();
                }
                return(num);
            }
        }
Пример #13
0
        public static int Search(System.ProcessStream pc, byte[] mask, byte[] vals)
        {
            if ((int)mask.Length != (int)vals.Length)
            {
                throw new Exception();
            }
            int length = 4096 + (int)mask.Length;

            pc.BeginAccess();
            byte[] numArray = new byte[length];
            int    num      = 0;

            while (true)
            {
                pc.Seek((long)(4194304 + num * 4096), SeekOrigin.Begin);
                if (pc.Read(numArray, 0, length) != length)
                {
                    break;
                }
                for (int i = 0; i < 4096; i++)
                {
                    bool flag = true;
                    for (int j = 0; flag && j < (int)mask.Length; j++)
                    {
                        flag = (numArray[i + j] & mask[j]) == vals[j];
                    }
                    if (flag)
                    {
                        pc.EndAccess();
                        return(4194304 + num * 4096 + i);
                    }
                }
                num++;
            }
            pc.EndAccess();
            return(0);
        }
        public override long Seek(long offset, SeekOrigin origin)
        {
            switch (origin)
            {
            case SeekOrigin.Begin:
            {
                this.m_Position = (int)offset;
                break;
            }

            case SeekOrigin.Current:
            {
                ProcessStream mPosition = this;
                mPosition.m_Position = mPosition.m_Position + (int)offset;
                break;
            }

            case SeekOrigin.End:
            {
                throw new NotSupportedException();
            }
            }
            return((long)this.m_Position);
        }
Пример #15
0
		public HttpStatusCode Post(
			string        requestUri,
			ProcessStream requestStreamProcessor,
			ProcessStream responseStreamProcessor)
		{
			Request(requestUri, "POST", requestStreamProcessor, responseStreamProcessor);

			for (int i = 0; i < 10; i++)
			{
				bool post = false;

				switch (StatusCode)
				{
					case HttpStatusCode.MultipleChoices:   // 300
					case HttpStatusCode.MovedPermanently:  // 301
					case HttpStatusCode.Found:             // 302
					case HttpStatusCode.SeeOther:          // 303
						break;

					case HttpStatusCode.TemporaryRedirect: // 307
						post = true;
						break;

					default:
						return StatusCode;
				}

				if (Location == null)
					break;

				Uri uri = new Uri(new Uri(PreviousUri), Location);

				BaseUri    = uri.Scheme + "://" + uri.Host;
				requestUri = uri.AbsolutePath + uri.Query;

				Request(
					requestUri,
					post? "POST": "GET",
					post? requestStreamProcessor: null,
					responseStreamProcessor);
			}

			return StatusCode;
		}
Пример #16
0
		public HttpStatusCode Post(
			string        requestUri,
			ProcessStream requestStreamProcessor)
		{
			return Post(
				requestUri,
				requestStreamProcessor,
				new DefaultResponseStreamProcessor(this).Process);
		}
Пример #17
0
		public HttpStatusCode Post(
			string        requestUri,
			string        postData,
			ProcessStream responseStreamProcessor)
		{
			return Post(
				requestUri,
				new ProcessStream(new DefaultRequestStreamProcessor(postData).Process),
				responseStreamProcessor);
		}
Пример #18
0
		public IEnumerable<string> Request(
			string        requestUri,
			string        method,
			ProcessStream requestStreamProcessor)
		{
			HttpWebRequest request = PrepareRequest(method, requestUri, requestStreamProcessor);

			using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
			using (Stream          sm   = resp.GetResponseStream())
			using (StreamReader    sr   = new StreamReader(sm, Encoding.Default))
			{
				_statusCode = resp.StatusCode;
				_location   = resp.Headers["Location"];

				if (resp.ResponseUri.AbsoluteUri.StartsWith(BaseUri) == false)
					BaseUri = resp.ResponseUri.Scheme + "://" + resp.ResponseUri.Host;

				CookieCollection cc = request.CookieContainer.GetCookies(request.RequestUri);

				// This code fixes the case when a server sets a cookie without the 'path'.
				// IE takes this as the root ('/') value,
				// the HttpWebRequest class as the RequestUri.AbsolutePath value.
				//
				foreach (Cookie c in cc)
					if (c.Path == request.RequestUri.AbsolutePath)
						CookieContainer.Add(new Cookie(c.Name, c.Value, "/", c.Domain));

				while (true)
				{
					string str = sr.ReadLine();

					if (str == null)
						break;

					yield return str;
				}
			}
		}
Пример #19
0
		public HttpStatusCode Get(string requestUri, ProcessStream responseStreamProcessor)
		{
			return Request(requestUri, "GET", null, responseStreamProcessor);
		}
Пример #20
0
		private HttpWebRequest PrepareRequest(string method, string requestUri, ProcessStream requestStreamProcessor)
		{
			_html = "";

			string uri = BaseUri;
			
			if (method != "SOAP")
				uri += requestUri;

			HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

			if (Proxy       != null) request.Proxy       = Proxy;
			if (Credentials != null) request.Credentials = Credentials;

			request.CookieContainer = CookieContainer;
			request.UserAgent       = UserAgent;
			request.Accept          = Accept;
			request.Method          = method == "SOAP"? "POST" : method;
			request.KeepAlive       = true;

			if (SendReferer)
				request.Referer = PreviousUri ?? uri;

			foreach (string key in Headers.Keys)
				request.Headers.Add(key, Headers[key].ToString());

			if (method == "POST")
			{
				request.ContentType       = "application/x-www-form-urlencoded";
				request.AllowAutoRedirect = false;
			}
			else if (method == "SOAP")
			{
				request.ContentType       = "text/xml; charset=utf-8";
				request.AllowAutoRedirect = false;

				request.Headers.Add("SOAPAction", requestUri);
			}
			else
			{
				request.ContentType       = ContentType;
				request.AllowAutoRedirect = true;
			}

			PreviousUri = uri;
			RequestUri  = request.RequestUri;

			if (Certificate != null)
				request.ClientCertificates.Add(Certificate);

			if (Timeout != 0)
				request.Timeout = Timeout;

			if (requestStreamProcessor != null)
				using (Stream st = request.GetRequestStream())
					requestStreamProcessor(st);

			return request;
		}
Пример #21
0
		public HttpStatusCode Request(
			string        requestUri,
			string        method,
			ProcessStream requestStreamProcessor,
			ProcessStream responseStreamProcessor)
		{
			HttpWebRequest request = PrepareRequest(method, requestUri, requestStreamProcessor);

			using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
			using (Stream          sm   = resp.GetResponseStream())
			{
				_statusCode = resp.StatusCode;
				_location   = resp.Headers["Location"];

				if (resp.ResponseUri.AbsoluteUri.StartsWith(BaseUri) == false)
					BaseUri = resp.ResponseUri.Scheme + "://" + resp.ResponseUri.Host;

				CookieCollection cc = request.CookieContainer.GetCookies(request.RequestUri);

				// This code fixes the situation when a server sets a cookie without the 'path'.
				// IE takes this as the root ('/') value,
				// the HttpWebRequest class as the RequestUri.AbsolutePath value.
				//
				foreach (Cookie c in cc)
					if (c.Path == request.RequestUri.AbsolutePath)
						CookieContainer.Add(new Cookie(c.Name, c.Value, "/", c.Domain));

				if (responseStreamProcessor != null)
					responseStreamProcessor(sm);
			}

			return StatusCode;
		}
Пример #22
0
        public static int Search(ProcessStream pc, byte[] mask, byte[] vals)
        {
            if (mask.Length != vals.Length)
                throw new Exception();

            const int chunkSize = 4096;
            int readSize = chunkSize + mask.Length;

            pc.BeginAccess();

            byte[] read = new byte[readSize];

            for (int i = 0; ; ++i)
            {
                pc.Seek(0x400000 + (i * chunkSize), SeekOrigin.Begin);
                int count = pc.Read(read, 0, readSize);

                if (count != readSize)
                    break;

                for (int j = 0; j < chunkSize; ++j)
                {
                    bool ok = true;

                    for (int k = 0; ok && k < mask.Length; ++k)
                        ok = ((read[j + k] & mask[k]) == vals[k]);

                    if (ok)
                    {
                        pc.EndAccess();
                        return 0x400000 + (i * chunkSize) + j;
                    }
                }
            }

            pc.EndAccess();
            return 0;
        }
Пример #23
0
        public static int Search(ProcessStream pc, byte[] buffer)
        {
            const int chunkSize = 4096;
            int readSize = chunkSize + buffer.Length;

            pc.BeginAccess();

            byte[] read = new byte[readSize];

            for (int i = 0; ; ++i)
            {
                pc.Seek(0x400000 + (i * chunkSize), SeekOrigin.Begin);
                int count = pc.Read(read, 0, readSize);

                if (count != readSize)
                    break;

                for (int j = 0; j < chunkSize; ++j)
                {
                    bool ok = true;

                    for (int k = 0; ok && k < buffer.Length; ++k)
                        ok = (buffer[k] == read[j + k]);

                    if (ok)
                    {
                        pc.EndAccess();
                        return 0x400000 + (i * chunkSize) + j;
                    }
                }
            }

            pc.EndAccess();
            return 0;
        }
Пример #24
0
        private static void GetCoordDetails(ProcessStream pc, int ptr, byte[] dets, out int coordPointer, out int coordSize)
        {
            pc.Seek(ptr + dets[0], SeekOrigin.Begin);
            coordPointer = Read(pc, dets[1]);

            if (dets[2] < 0xFF)
            {
                pc.Seek(coordPointer, SeekOrigin.Begin);
                coordPointer = Read(pc, dets[2]);
            }

            if (dets[3] < 0xFF)
            {
                pc.Seek(ptr + dets[3], SeekOrigin.Begin);
                coordPointer += Read(pc, dets[4]);
            }

            coordSize = dets[5];
        }
Пример #25
0
		private HttpStatusCode Soap(
			string        soapAction,
			ProcessStream inputStreamProcessor,
			ProcessStream outputStreamProcessor)
		{
			return Request("\"" + soapAction + "\"", "SOAP", inputStreamProcessor, outputStreamProcessor);
		}
Пример #26
0
        public static int Read(ProcessStream pc, int bytes)
        {
            byte[] buffer = new byte[bytes];

            pc.Read(buffer, 0, bytes);

            switch (bytes)
            {
                case 1: return (sbyte)buffer[0];
                case 2: return (short)(buffer[0] | (buffer[1] << 8));
                case 4: return (int)(buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24));
            }

            int val = 0;
            int bits = 0;

            for (int i = 0; i < buffer.Length; ++i)
            {
                val |= buffer[i] << bits;
                bits += 8;
            }

            return val;
        }
Пример #27
0
		public HttpStatusCode Soap(string soapAction, string postData, ProcessStream outputStreamProcessor)
		{
			return Soap(
				soapAction,
				new DefaultRequestStreamProcessor(postData).Process,
				outputStreamProcessor);
		}
Пример #28
0
		public HttpStatusCode Request(
			string        requestUri,
			string        method,
			ProcessStream requestStreamProcessor,
			ProcessStream responseStreamProcessor)
		{
			_html = "";

			string uri = BaseUri;
			
			if (method != "SOAP")
				uri += requestUri;

			HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

			if (Proxy       != null) request.Proxy       = Proxy;
			if (Credentials != null) request.Credentials = Credentials;

			request.CookieContainer = CookieContainer;
			request.UserAgent       = UserAgent;
			request.Accept          = Accept;
			request.Method          = method == "SOAP"? "POST" : method;
			request.KeepAlive       = true;

			if (SendReferer)
				request.Referer = PreviousUri ?? uri;

			foreach (string key in Headers.Keys)
				request.Headers.Add(key, Headers[key].ToString());

			if (method == "POST")
			{
				request.ContentType       = "application/x-www-form-urlencoded";
				request.AllowAutoRedirect = false;
			}
			else if (method == "SOAP")
			{
				request.ContentType       = "text/xml; charset=utf-8";
				request.AllowAutoRedirect = false;

				request.Headers.Add("SOAPAction", requestUri);
			}
			else
			{
				request.ContentType       = ContentType;
				request.AllowAutoRedirect = true;
			}

			PreviousUri = uri;
			RequestUri  = request.RequestUri;

			if (Certificate != null)
				request.ClientCertificates.Add(Certificate);

			if (Timeout != 0)
				request.Timeout = Timeout;

			if (requestStreamProcessor != null)
				using (Stream st = request.GetRequestStream())
					requestStreamProcessor(st);

			using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
			using (Stream          sm   = resp.GetResponseStream())
			{
				_statusCode = resp.StatusCode;
				_location   = resp.Headers["Location"];

				if (resp.ResponseUri.AbsoluteUri.StartsWith(BaseUri) == false)
					BaseUri = resp.ResponseUri.Scheme + "://" + resp.ResponseUri.Host;

				CookieCollection cc = request.CookieContainer.GetCookies(request.RequestUri);

				// This code fixes the situation when a server sets a cookie without the 'path'.
				// IE takes this as the root ('/') value,
				// the HttpWebRequest class as the RequestUri.AbsolutePath value.
				//
				foreach (Cookie c in cc)
					if (c.Path == request.RequestUri.AbsolutePath)
						CookieContainer.Add(new Cookie(c.Name, c.Value, "/", c.Domain));

				if (responseStreamProcessor != null)
					responseStreamProcessor(sm);
			}

			return StatusCode;
		}