oldcode – aimbot genérico

Oct 07, 2011 1 Comment by

Hace un tiempo atrás (2009), conversando con un amigo “gamer de Action Quake 2″, conversamos sobre la idea de crear un aimbot más o menos genérico, que trate de encontrar una cierta combinación de pixeles en la pantalla y realizar un click izquierdo en ellos.

A sí nacio una “desordenada” prueba de concepto, que al menos cumple con la intención de realizar un click cuando encuentra algún pixel correcto. Escrita en .NET C#.

Se compone de un Form principal, que maneja un par de inputs para el ingreso de datos de entradas (colores, timer, etc.) y una clase llamada Aimbot, encargada de procesar la imágen en la busqueda de pixeles de X color.

Es destacable, lo sencillo que es realizar un “screenshot” en .NET C#

// Realizamos una Captura de la Pantalla (Screenshot)
Rectangle region = Screen.AllScreens[0].Bounds;
Bitmap bitmap = new Bitmap(region.Width, region.Height, PixelFormat.Format24bppRgb);

Graphics graphic = Graphics.FromImage(bitmap);
graphic.CopyFromScreen(region.Left, region.Top, 0, 0, region.Size);

Y acceder a los pixeles de la imágen a través de los métodos SetPixel y GetPixel

Color pixel = bitmap.GetPixel(100, 100);
bitmap.SetPixel(200,200,Color.Black);

Finalmente, es una sola prueba de concepto, es funcional, pero un poco lenta, por lo menos es capaz de detectar los pixeles y clickear en ellos, a si que no esperen que sea realmente un aimbot xD.

Código Fuente (Descarga el Proyecto Aimbot para Visual Studio 2005)

Aimbot.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using FastPixel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

/*
 * Es solo una prueba de concepto xD
 * deerme.org
 *
 **/

namespace Aimbot
{
    class Aimbot
    {
        private String[] body_color = new String[3];
        private String[] head_color = new String[3];
        private Int16 error_color;
        private Logger logger;
        private Cursor current_cursor;
        private FastPixel.FastPixel fp;
        private Color current_pixel;
        private int ymin,ymax,xmin,xmax;
        private Boolean current_run = false;
        private Bounty.Mouse mouse;

        internal Logger Logger
        {
            get { return logger; }
            set { logger = value; }
        }

        public Int16 Error_color
        {
            get { return error_color; }
            set { error_color = value; }
        }

        public void setBodyColor( String c , int pos )
        {
            if ( pos < body_color.Length )
            {
                body_color[pos] = c;
            }
        }

        public void setHeadColor(String c, int pos)
        {
            if (pos < head_color.Length)
            {
                head_color[pos] = c;
            }
        }

        public Aimbot()
        {
            error_color = 3;
            this.current_cursor = new Cursor(Cursor.Current.Handle);
            this.mouse = new Bounty.Mouse();

        }

        public void run(object sender, EventArgs e)
        {
            if (this.current_run == false)
            {
                this.current_run = true;
                logger.log("Start Run Aimbot");

                String[] hc1 = head_color[0].Split(',');
                String[] hc2 = head_color[1].Split(',');
                String[] hc3 = head_color[2].Split(',');
                String[] bc1 = body_color[0].Split(',');
                String[] bc2 = body_color[1].Split(',');
                String[] bc3 = body_color[2].Split(',');

                // Realizamos una Captura de la Pantalla (Screenshot)
                Rectangle region = Screen.AllScreens[0].Bounds;
                Bitmap bitmap = new Bitmap(region.Width, region.Height, PixelFormat.Format24bppRgb);

                Graphics graphic = Graphics.FromImage(bitmap);
                graphic.CopyFromScreen(region.Left, region.Top, 0, 0, region.Size);

                // Instanciamos FastPixel
                //fp = new FastPixel.FastPixel(bitmap);
                //fp.Lock();

                // Recorremos toda la pantalla
                int ymin, xmin, ymax, xmax, x, y; ;

                ymin = 0;
                xmin = 0;
                //ymax = 50;
                //xmax = 50;
                ymax = bitmap.Height -1;
                xmax = bitmap.Width -1;

                /*
                // Area acotada según el Cursor del Mouse
                ymin = Cursor.Position.Y - 50;
                if (ymin < 0)
                    ymin = 0;
                ymax = Cursor.Position.Y + 50;
                if (ymin > bitmap.Height - 10)
                    ymin = bitmap.Height - 10;

                xmin = Cursor.Position.X - 50;
                if (xmin < 0)
                    xmin = 0;
                xmax = Cursor.Position.X + 50;
                if (xmin > bitmap.Width -10 )
                    xmin = bitmap.Width -10 ;
                */

                try
                {
                    for (x = xmin; x < xmax; x++)
                    {
                        for (y = ymin; y < ymax; y++)
                        {
                            // Vamos a utilizar el método GetPixel de la Clase Bitmap
                            current_pixel = bitmap.GetPixel(x, y);
                            // Solo si utilizamos FastPixel, pero creo que tiene un problema xD
                            //current_pixel = fp.GetPixel(x, y);

                            if ((colorSimilar(Int16.Parse(hc1[0]), Int16.Parse(hc1[1]), Int16.Parse(hc1[2]), Int16.Parse(current_pixel.R.ToString()), Int16.Parse(current_pixel.G.ToString()), Int16.Parse(current_pixel.B.ToString()), (int)error_color)) || (colorSimilar(Int16.Parse(hc2[0]), Int16.Parse(hc2[1]), Int16.Parse(hc2[2]), Int16.Parse(current_pixel.R.ToString()), Int16.Parse(current_pixel.G.ToString()), Int16.Parse(current_pixel.B.ToString()), (int)error_color)) || (colorSimilar(Int16.Parse(hc3[0]), Int16.Parse(hc3[1]), Int16.Parse(hc3[2]), Int16.Parse(current_pixel.R.ToString()), Int16.Parse(current_pixel.G.ToString()), Int16.Parse(current_pixel.B.ToString()), (int)error_color)))
                            {
                                //this.logger.log("Hemos encontrado el color " + hc1[0]+","+hc1[1]+","+hc1[2] + " en " + x + "," + y  );
                                Cursor.Position = new Point(x, y);
                                this.mouse.SendLeftClick();
                             }
                        }

                    }
                }
                catch( Exception ex)
                {
                    this.logger.log("Hubo una excepción xD" + ex.Message);
                }

                this.current_run = false;
                this.logger.log("Hemos Terminado");                                                

            }
            else
            {
                this.logger.log("There is one instance running");
            }
        }

        private Boolean colorSimilar( int c1r, int c1g , int c1b , int c2r, int c2g, int c2b , int error )
        {
            //this.logger.log(  c1r + "," + c1g + "," + c1b + "," + c2r + "," + c2g + "," + c2b );
            if ( (c1r - error) <= c2r && (c1r + error) >= c2r  && (c1g - error) <= c2g && (c1g + error) >= c2g && (c1b - error) <= c2b && (c1b + error) >= c2b )
                return true;
            else
                return false;
        }
    }
}

AimbotForm.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Timers;

// Namespace of Mouse.cs and FastPixel
using Bounty;
using FastPixel;

namespace Aimbot
{
    public partial class AimbotForm : Form
    {
        private Boolean run = false;
        private Boolean firstRun = true;
        private Aimbot aim = new Aimbot();
        private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
        private Logger logger;

        public AimbotForm()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            if (this.run == false)
            {
                btnRun.Text = "Run";
            }
            logger = new Logger(txtLogger);
        }

        private void btnRun_Click(object sender, EventArgs e)
        {
            /*
            aim.Logger = logger;
            aim.setBodyColor(bColor1.Text, 0);
            aim.setBodyColor(bColor2.Text, 1);
            aim.setBodyColor(bColor3.Text, 2);

            aim.setHeadColor(hColor1.Text, 0);
            aim.setHeadColor(hColor2.Text, 1);
            aim.setHeadColor(hColor3.Text, 2);

            aim.Error_color = (Int16.Parse(cError.Text));
            aim.run(null,null);
            */

            if (this.run == false)
            {
                this.run = true;
                btnRun.Text = "Stop";                

                aim.setBodyColor(bColor1.Text, 0);
                aim.setBodyColor(bColor1.Text, 1);
                aim.setBodyColor(bColor1.Text, 2);

                aim.setHeadColor(hColor1.Text, 0);
                aim.setHeadColor(hColor1.Text, 1);
                aim.setHeadColor(hColor1.Text, 2);

                aim.Error_color = (Int16.Parse(cError.Text)); 

                if (this.firstRun)
                {
                    cTime.ReadOnly = true;
                    aim.Logger = logger;
                    timer.Interval = Int16.Parse(cTime.Text);
                    timer.Tick += new EventHandler( this.aim.run  );
                }

                logger.log("Start Execution");
                timer.Enabled = true;
            }
            else
            {
                btnRun.Text = "Run";
                this.run = false;
                logger.log("Stop Execution");
                timer.Enabled = false;
            }

        }
    }
}

Logger.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Aimbot
{
    class Logger
    {
        private TextBox logger;
        private StreamWriter fp;
        public Logger( TextBox log )
        {
            logger = log;
        }
        public void log(String message)
        {
            message = DateTime.Now.ToString("HH:mm:ss.ff") + "\t" + message + "\r\n";

            logger.AppendText(message);
            // Auto Scroll in Textarea
            logger.SelectionStart = logger.Text.Length;
            logger.ScrollToCaret();
            logger.Refresh();         

        }
    }
}

Clases auxiliares

Mouse.cs (by Robbe D. Morris)

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

/*
 * Class Mouse take from http://www.eggheadcafe.com/articles/transparentform_send_mouse_click_to_desktop.asp by Robbe D. Morris
*/

namespace Bounty
{
    public class Mouse
    {
        [DllImport("user32.dll")]
        private static extern void mouse_event(UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 dwData, IntPtr dwExtraInfo);

        private const UInt32 MouseEventLeftDown = 0x0002;
        private const UInt32 MouseEventLeftUp = 0x0004;

        public void SendDoubleClick()
        {
            mouse_event(MouseEventLeftDown, 0, 0, 0, new System.IntPtr());
            mouse_event(MouseEventLeftUp, 0, 0, 0, new System.IntPtr());
            mouse_event(MouseEventLeftDown, 0, 0, 0, new System.IntPtr());
            mouse_event(MouseEventLeftUp, 0, 0, 0, new System.IntPtr());
        }

        public void SendLeftClick()
        {
            mouse_event(MouseEventLeftDown, 0, 0, 0, new System.IntPtr());
            mouse_event(MouseEventLeftUp, 0, 0, 0, new System.IntPtr());
        }

    }
}

FastPixel.cs (by AndrewVos)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

/*
 * Class take from http://www.codeproject.com/KB/GDI-plus/FastPixel.aspx?msg=1719833 by AndrewVos
 *
*/

namespace FastPixel
{
    class FastPixel
    {
        private byte[] rgbValues;
        private BitmapData bmpData;
        private IntPtr bmpPtr;
        private bool locked = false;

        private bool _isAlpha = false;
        private Bitmap _bitmap;
        private int _width;
        private int _height;

        public int Width
        {
            get
            {
                return this._width;
            }
        }

        public int Height
        {
            get
            {
                return this._height;
            }
        }

        public bool IsAlphaBitmap
        {
            get
            {
                return this._isAlpha;
            }
        }

        public Bitmap Bitmap
        {
            get
            {
                return this._bitmap;
            }
        }

        public FastPixel(Bitmap bitmap)
        {
            if (bitmap.PixelFormat == (bitmap.PixelFormat | PixelFormat.Indexed))
                throw new Exception("Cannot lock an Indexed image.");

            this._bitmap = bitmap;
            this._isAlpha = (this.Bitmap.PixelFormat == (this.Bitmap.PixelFormat | PixelFormat.Alpha));
            this._width = bitmap.Width;
            this._height = bitmap.Height;
        }

        public void Lock()
        {
            if (this.locked)
                throw new Exception("Bitmap already locked.");

            Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
            this.bmpData = this.Bitmap.LockBits(rect, ImageLockMode.ReadWrite, this.Bitmap.PixelFormat);
            this.bmpPtr = this.bmpData.Scan0;

            if (this.IsAlphaBitmap)
            {
                int bytes = (this.Width * this.Height) * 4;
                this.rgbValues = new byte[bytes];
                System.Runtime.InteropServices.Marshal.Copy(this.bmpPtr, rgbValues, 0, this.rgbValues.Length);
            }
            else
            {
                int bytes = (this.Width * this.Height) * 3;
                this.rgbValues = new byte[bytes];
                System.Runtime.InteropServices.Marshal.Copy(this.bmpPtr, rgbValues, 0, this.rgbValues.Length);
            }
            this.locked = true;
        }

        public void Unlock(bool setPixels)
        {
            if (!this.locked)
                throw new Exception("Bitmap not locked.");

            // Copy the RGB values back to the bitmap;
            if (setPixels)
                System.Runtime.InteropServices.Marshal.Copy(this.rgbValues, 0, this.bmpPtr, this.rgbValues.Length);

            // Unlock the bits.;
            this.Bitmap.UnlockBits(bmpData);
            this.locked = false;
        }

        public void Clear(Color colour)
        {
            if (!this.locked)
                throw new Exception("Bitmap not locked.");

            if (this.IsAlphaBitmap)
            {
                for (int index = 0; index < this.rgbValues.Length; index += 4)
                {
                    this.rgbValues[index] = colour.B;
                    this.rgbValues[index + 1] = colour.G;
                    this.rgbValues[index + 2] = colour.R;
                    this.rgbValues[index + 3] = colour.A;
                }
            }
            else
            {
                for (int index = 0; index < this.rgbValues.Length; index += 3)
                {
                    this.rgbValues[index] = colour.B;
                    this.rgbValues[index + 1] = colour.G;
                    this.rgbValues[index + 2] = colour.R;
                }
            }
        }

        public void SetPixel(Point location, Color colour)
        {
            this.SetPixel(location.X, location.Y, colour);
        }

        public void SetPixel(int x, int y, Color colour)
        {
            if (!this.locked)
                throw new Exception("Bitmap not locked.");

            if (this.IsAlphaBitmap)
            {
                int index = ((y * this.Width + x) * 4);
                this.rgbValues[index] = colour.B;
                this.rgbValues[index + 1] = colour.G;
                this.rgbValues[index + 2] = colour.R;
                this.rgbValues[index + 3] = colour.A;
            }
            else
            {
                int index = ((y * this.Width + x) * 3);
                this.rgbValues[index] = colour.B;
                this.rgbValues[index + 1] = colour.G;
                this.rgbValues[index + 2] = colour.R;
            }
        }

        public Color GetPixel(Point location)
        {
            return this.GetPixel(location.X, location.Y);
        }

        public Color GetPixel(int x, int y)
        {
            if (!this.locked)
                throw new Exception("Bitmap not locked.");

            if (this.IsAlphaBitmap)
            {
                int index = ((y * this.Width + x) * 4);
                int b = this.rgbValues[index];
                int g = this.rgbValues[index + 1];
                int r = this.rgbValues[index + 2];
                int a = this.rgbValues[index + 3];
                return Color.FromArgb(a, r, g, b);
            }
            else
            {
                int index = ((y * this.Width + x) * 3);
                int b = this.rgbValues[index];
                int g = this.rgbValues[index + 1];
                int r = this.rgbValues[index + 2];
                return Color.FromArgb(r, g, b);
            }
        }
    }
}
.NET C#, Old Code

About the author

Ingeniero en Informática, Oracle Certified Master Java EE 6 Enterprise Architect, Oracle Certified Professional Java Programmer. Experto en distintas ramas de la computación y otras "yerbas" xD. Si te gusto este post, sígueme en @deerme_org, escríbeme a info AT deerme.org o contactame por linkedin.

One Response to “oldcode – aimbot genérico”

  1. Estudiante says:

    Hola, me parece muy interesante la lógica del programa y me gustaría implementarla en JAVA pero no conozco el código para activar el clic, existe código para mandar click en java? Cuál es?

Leave a Reply to Estudiante

Cancel Reply


nine + 2 =