elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  [C#] Problema override WndProc
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [C#] Problema override WndProc  (Leído 1,869 veces)
.:UND3R:.
Moderador Global
***
Desconectado Desconectado

Mensajes: 3.118


Ingeniería inversa / MASM


Ver Perfil WWW
[C#] Problema override WndProc
« en: 19 Noviembre 2015, 03:25 am »

Hola a todos, estoy teniendo problemas al intentar hacer un override en WndProc, el problema consiste en que no se generan los mensajes de Windows que quiero capturar. Cabe mencionar que la aplicación es "Console Application" y para ocultar la consola, modifiqué la opción del proyecto de output: "Windows Application". Adicionar que www.asd.com lo uso como ejemplo, pues de acorde a cada evento, se realiza una notificación distinta a una Web, si me pudieran ayudar quedaría completamente agradecido, saludos y gracias por su tiempo, aquí el código:

Código
  1. using System;
  2. using System.Net;
  3. using System.Runtime.InteropServices;
  4. using System.Security.Permissions;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Windows.Forms;
  8.  
  9. namespace iWatch
  10. {
  11.    class Program : System.Windows.Forms.Form
  12.    {
  13.        private const int WM_QUERYENDSESSION = 0x0011;
  14.        private const int WM_POWERBROADCAST = 0x0218;
  15.        private const int PBT_APMSUSPEND = 0x04;
  16.        private const int PBT_APMRESUMESUSPEND = 0x07;
  17.        WebRequest request;
  18.  
  19.        [DllImport("user32.dll")]
  20.        private static extern IntPtr GetForegroundWindow();
  21.  
  22.        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  23.        private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
  24.  
  25.        [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.InheritanceDemand, Name = "FullTrust")]
  26.        protected override void WndProc(ref Message m)
  27.        {
  28.            // Listen for operating system messages.
  29.            switch (m.Msg)
  30.            {
  31.                // The WM_ACTIVATEAPP message occurs when the application
  32.                // becomes the active application or becomes inactive.
  33.                case WM_QUERYENDSESSION:
  34.  
  35.                    request = WebRequest.Create("http://www.asd.com");
  36.                    request.GetResponse();
  37.                    break;
  38.  
  39.                case WM_POWERBROADCAST:
  40.  
  41.                    if((int)m.WParam == PBT_APMSUSPEND)
  42.                    {
  43.                        request = WebRequest.Create("http://www.asd.com");
  44.                        request.GetResponse();
  45.  
  46.                    }else if((int)m.WParam == PBT_APMRESUMESUSPEND)
  47.                    {
  48.                        request = WebRequest.Create("http://www.asd.com");
  49.                        request.GetResponse();
  50.  
  51.                    }
  52.                    break;
  53.            }
  54.            base.WndProc(ref m);
  55.        }
  56.  
  57.        static void Main(string[] args)
  58.        {
  59.            Thread.Sleep(20000);
  60.  
  61.            WebRequest request = WebRequest.Create("http://www.asd.com");
  62.            request.GetResponse();
  63.  
  64.            while (true)
  65.            {
  66.                String[] phraselist = new String[] { "hola", "adios" };
  67.  
  68.                // get handle
  69.                IntPtr handle = GetForegroundWindow();
  70.  
  71.                // get title
  72.                const int count = 512;
  73.                var text = new StringBuilder(count);
  74.  
  75.                if (GetWindowText(handle, text, count) > 0)
  76.                {
  77.                    foreach(String phrase in phraselist){
  78.                        if(text.ToString().ToUpper().IndexOf(phrase.ToUpper()) != -1)
  79.                        {
  80.                            System.Console.WriteLine(text.ToString());
  81.                            request = WebRequest.Create("http://www.asd.com");
  82.                            request.GetResponse();
  83.                            Thread.Sleep(1200000);
  84.                        }
  85.                    }
  86.                }
  87.            }
  88.        }
  89.    }
  90. }


En línea


Solicitudes de crack, keygen, serial solo a través de mensajes privados (PM)
.:UND3R:.
Moderador Global
***
Desconectado Desconectado

Mensajes: 3.118


Ingeniería inversa / MASM


Ver Perfil WWW
Re: [C#] Problema override WndProc
« Respuesta #1 en: 19 Noviembre 2015, 22:26 pm »

Solucionado:
Copié este código completamente y luego lo adapté a mis necesidades:

Código
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4.  
  5. namespace csTempWindowsApplication1
  6. {
  7.    public class Form1 : System.Windows.Forms.Form
  8.    {
  9.        // Constant value was found in the "windows.h" header file.
  10.        private const int WM_ACTIVATEAPP = 0x001C;
  11.        private bool appActive = true;
  12.  
  13.        [STAThread]
  14.        static void Main()
  15.        {
  16.            Application.Run(new Form1());
  17.        }
  18.  
  19.        public Form1()
  20.        {
  21.            this.Size = new System.Drawing.Size(300,300);
  22.            this.Text = "Form1";
  23.            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  24.        }
  25.  
  26.        protected override void OnPaint(PaintEventArgs e)
  27.        {
  28.            // Paint a string in different styles depending on whether the
  29.            // application is active.
  30.            if (appActive)
  31.            {
  32.                e.Graphics.FillRectangle(SystemBrushes.ActiveCaption,20,20,260,50);
  33.                e.Graphics.DrawString("Application is active", this.Font, SystemBrushes.ActiveCaptionText, 20,20);
  34.            }
  35.            else
  36.            {
  37.                e.Graphics.FillRectangle(SystemBrushes.InactiveCaption,20,20,260,50);
  38.                e.Graphics.DrawString("Application is Inactive", this.Font, SystemBrushes.ActiveCaptionText, 20,20);
  39.            }
  40.        }
  41.  
  42. [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
  43.        protected override void WndProc(ref Message m)
  44.        {
  45.            // Listen for operating system messages.
  46.            switch (m.Msg)
  47.            {
  48.                // The WM_ACTIVATEAPP message occurs when the application
  49.                // becomes the active application or becomes inactive.
  50.                case WM_ACTIVATEAPP:
  51.  
  52.                    // The WParam value identifies what is occurring.
  53.                    appActive = (((int)m.WParam != 0));
  54.  
  55.                    // Invalidate to get new text painted.
  56.                    this.Invalidate();
  57.  
  58.                    break;                
  59.            }
  60.            base.WndProc(ref m);
  61.        }
  62.    }
  63. }

Supongo que se debe a la forma en que se crea el Form, saludos.


En línea


Solicitudes de crack, keygen, serial solo a través de mensajes privados (PM)
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Problema BlueZScanner y problema de conexión
Hacking Mobile
Kasswed 3 6,280 Último mensaje 6 Mayo 2006, 22:04 pm
por Gospel
Diferencias entre overload y override??
Java
Carlosjava 3 10,380 Último mensaje 28 Julio 2015, 22:23 pm
por Carlosjava
@Override
Java
neveldine 3 1,974 Último mensaje 10 Diciembre 2015, 07:15 am
por edr89
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines