Foros del Web » Programación para mayores de 30 ;) » .NET »

Leer esta dll datos de variables y mostrarlo.

Estas en el tema de Leer esta dll datos de variables y mostrarlo. en el foro de .NET en Foros del Web. Hola: Tengo una variable creada conVisual C++ 2013 en Win32. Su código es de abajo. Tiene variables que se llama Vida, Balas y Mana. Código: ...
  #1 (permalink)  
Antiguo 16/03/2014, 05:01
 
Fecha de Ingreso: mayo-2007
Ubicación: PIC-16F84A
Mensajes: 727
Antigüedad: 16 años, 11 meses
Puntos: 8
Leer esta dll datos de variables y mostrarlo.

Hola:

Tengo una variable creada conVisual C++ 2013 en Win32. Su código es de abajo. Tiene variables que se llama Vida, Balas y Mana.

Código:
#include <stdio.h>
#include <Windows.h>

bool vida = false; // = true;
bool balas = false;
bool mana = false;

bool salir = false;

void Hacks()
{
	DWORD entryPoint = (DWORD)GetModuleHandle(NULL);
	while (!salir) // while ("NO" (salir == true)) => while (salir == false) --> "mientras no salir" --> "mientras no tengamos que salir"
	{
		DWORD estructura = *(DWORD*)(entryPoint + 0x544C);

		// HACK VIDA = 100
		if (vida) // if (vida == true) -> "Si la vida es verdadera"
		{
			// Nivel 1
			*(DWORD*)(entryPoint + 0x5444) = 100;

			// Nivel 2
			// PUNTERO -> DIRECCION (ADDRESS) -> VIDA
			DWORD direccion = *(DWORD*)(entryPoint + 0x5448);
			if (direccion != 0)
			{
				*(DWORD*)(direccion) = 100;
			}

			// Nivel 3
			// PUNTERO (ESTRUCTURA) -> DIRECCION (ADDRESS) + OFFSET -> VIDA
			if (estructura != 0)
			{
				*(DWORD*)(estructura + 0) = 100;
			}
		}

		if (balas)
		{
			// Nivel 1
			*(DWORD*)(entryPoint + 0x5454) = 10;

			// Nivel 2
			// PUNTERO -> DIRECCION (ADDRESS) -> BALAS
			DWORD direccion = *(DWORD*)(entryPoint + 0x5460);
			if (direccion != 0)
			{
				*(DWORD*)(direccion) = 10;
			}

			// Nivel 3
			// PUNTERO (ESTRUCTURA) -> DIRECCION (ADDRESS) + OFFSET -> VIDA
			if (estructura != 0)
			{
				*(DWORD*)(estructura + 4) = 10;
			}
		}

		if (mana)
		{
			// Nivel 1
			*(DWORD*)(entryPoint + 0x545C) = 100;

			// Nivel 2
			// PUNTERO -> DIRECCION (ADDRESS) -> MANA
			DWORD direccion = *(DWORD*)(entryPoint + 0x5450);
			if (direccion != 0)
			{
				*(DWORD*)(direccion) = 100;
			}

			// Nivel 3
			// PUNTERO (ESTRUCTURA) -> DIRECCION (ADDRESS) + OFFSET -> VIDA
			if (estructura != 0)
			{
				*(DWORD*)(estructura + 8) = 100;
			}
		}

		Sleep(200); // 200 milisegundos
		// Sleep(1);
	}
}

void Teclado()
{
	while (!salir)
	{
		// 'a' => vida = activar/desactivar (true/false)
		if (GetAsyncKeyState(VkKeyScan('a')) & 1)
		{
			vida = !vida; // ! "NO"/"LO CONTRARIO"
			/*
			vida es true
			vida = "NO" true => vida = false
			vida = "NO" false => vida = true
			*/
		}

		// 's' => balas = activar/desactivar (true/false)
		if (GetAsyncKeyState(VkKeyScan('s')) & 1)
		{
			balas = !balas;
		}

		// 'd' => mana = activar/desactivar (true/false)
		if (GetAsyncKeyState(VkKeyScan('d')) & 1)
		{
			mana = !mana;
		}

		Sleep(300);
	}
}

// DllMain <--- 
// Cierra --> Dllmain
BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID reserved)
{
	if (reason == DLL_PROCESS_ATTACH)
	{
		// OK! Estamos dentro!
		// Thread
		// Hacks();
		CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Hacks, 0, 0, 0);
		CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Teclado, 0, 0, 0);
	}
	else if (reason == DLL_PROCESS_DETACH)
	{
		// Salimos del juego!
		salir = true;
	}

	// Devolver
	return true;
}
Usando Visual C# 2013, creando otro proyecto a parte con Windows Form, coloco la dll llamada HackDLL.dll en el directorio del proyecto del C#.

Creao en C# una clase que se llama Super_DLL.cs. Dentro de ella tiene este código que en realidad no es nada.

Código:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Runtime.InteropServices; // No olvidar. Para Dllimport.

namespace Prueba_DLL
{
    class Super_DLL
    {
        [DllImport("HackDLL.dll")]
        
    }
}
El formulario principal solo he colocado un using.

Código:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Prueba_DLL; // No olvidar este using. Para llamar a la clase Super_DLL.cs.

namespace Prueba_DLL
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    }
}
En Windows Form de C# solo tiene tres label para mostrar dichas variables. Los label para no condundir se llama su nombre interno.

label_vida

label_balas

label_mana

No se si es posible hacerlo con el código mostrado. Lo que hace simplente ejecutar un juego básico hecho con C++ 2013 (no tengo código fuente y puede ser el ejecutable de cualquier juego).

Se crea una dll a parte con otro proyecto del código de arriba.

Luego creo otro proyecto con Windows Form bajo C# como dije antes arriba. Solo tiene que leer las variables del juego cuando está en ejecución. La dll hace el trabajo principal leyendo y C# solo muestra información optenida gracias a la dll.

Espero que se entienda y me ayuden.

Saludo.
__________________
Meta Shell, VERSIÓN 1.2.2
Descargar
  #2 (permalink)  
Antiguo 16/03/2014, 10:06
 
Fecha de Ingreso: enero-2012
Ubicación: Buenos Aires
Mensajes: 745
Antigüedad: 12 años, 3 meses
Puntos: 35
Respuesta: Leer esta dll datos de variables y mostrarlo.

Tu problema es simple, eso nunca va a funcionar porque hay varias instancias de la DLL ejecutándose. Para ponerlo de otra manera, si vos ejecutas varias veces el mismo programa, esto no quiere decir que todos los programas vayan a tener los mismos valores en las mismas variables, se entiende?

Lo que querrás hacer es comunicar a tu programa de C# con tu DLL de C++, tal vez esto te sirva: http://es.wikipedia.org/wiki/Comunic...entre_procesos.

  #3 (permalink)  
Antiguo 16/03/2014, 11:44
 
Fecha de Ingreso: mayo-2007
Ubicación: PIC-16F84A
Mensajes: 727
Antigüedad: 16 años, 11 meses
Puntos: 8
Respuesta: Leer esta dll datos de variables y mostrarlo.

Hola:

Tienes razón que cambia el nombre de la direcciones, sobre todo los dos primeros bytes en cada ejecución, así que modificar la variable. También he añadido este código desde el principio.

Código:
extern "C" __declspec(dllexport) bool ObtenerVida()
{
	return vida;
}
Código:
#include <stdio.h>
#include <Windows.h>

bool vida = false; // = true;
bool balas = false;
bool mana = false;

bool salir = false;

extern "C" __declspec(dllexport) bool ObtenerVida()
{
	return vida;
}

void Hacks()
{
	DWORD entryPoint = (DWORD)GetModuleHandle(NULL);
	while (!salir) // while ("NO" (salir == true)) => while (salir == false) --> "mientras no salir" --> "mientras no tengamos que salir"
	{
		DWORD estructura = *(DWORD*)(entryPoint + 0x544C);

		// HACK VIDA = 100
		if (vida) // if (vida == true) -> "Si la vida es verdadera"
		{
			// Nivel 1
			*(DWORD*)(entryPoint + 0x5444) = 100;

			// Nivel 2
			// PUNTERO -> DIRECCION (ADDRESS) -> VIDA
			DWORD direccion = *(DWORD*)(entryPoint + 0x5448);
			if (direccion != 0)
			{
				*(DWORD*)(direccion) = 100;
			}

			// Nivel 3
			// PUNTERO (ESTRUCTURA) -> DIRECCION (ADDRESS) + OFFSET -> VIDA
			if (estructura != 0)
			{
				*(DWORD*)(estructura + 0) = 100;
			}
		}

		if (balas)
		{
			// Nivel 1
			*(DWORD*)(entryPoint + 0x5454) = 10;

			// Nivel 2
			// PUNTERO -> DIRECCION (ADDRESS) -> BALAS
			DWORD direccion = *(DWORD*)(entryPoint + 0x5460);
			if (direccion != 0)
			{
				*(DWORD*)(direccion) = 10;
			}

			// Nivel 3
			// PUNTERO (ESTRUCTURA) -> DIRECCION (ADDRESS) + OFFSET -> VIDA
			if (estructura != 0)
			{
				*(DWORD*)(estructura + 4) = 10;
			}
		}

		if (mana)
		{
			// Nivel 1
			*(DWORD*)(entryPoint + 0x545C) = 100;

			// Nivel 2
			// PUNTERO -> DIRECCION (ADDRESS) -> MANA
			DWORD direccion = *(DWORD*)(entryPoint + 0x5450);
			if (direccion != 0)
			{
				*(DWORD*)(direccion) = 100;
			}

			// Nivel 3
			// PUNTERO (ESTRUCTURA) -> DIRECCION (ADDRESS) + OFFSET -> VIDA
			if (estructura != 0)
			{
				*(DWORD*)(estructura + 8) = 100;
			}
		}

		Sleep(200); // 200 milisegundos
		// Sleep(1);
	}
}

void Teclado()
{
	while (!salir)
	{
		// 'a' => vida = activar/desactivar (true/false)
		if (GetAsyncKeyState(VkKeyScan('a')) & 1)
		{
			vida = !vida; // ! "NO"/"LO CONTRARIO"
			/*
			vida es true
			vida = "NO" true => vida = false
			vida = "NO" false => vida = true
			*/
		}

		// 's' => balas = activar/desactivar (true/false)
		if (GetAsyncKeyState(VkKeyScan('s')) & 1)
		{
			balas = !balas;
		}

		// 'd' => mana = activar/desactivar (true/false)
		if (GetAsyncKeyState(VkKeyScan('d')) & 1)
		{
			mana = !mana;
		}

		Sleep(300);
	}
}

// DllMain <--- 
// Cierra --> Dllmain
BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID reserved)
{
	if (reason == DLL_PROCESS_ATTACH)
	{
		// OK! Estamos dentro!
		// Thread
		// Hacks();
		CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Hacks, 0, 0, 0);
		CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Teclado, 0, 0, 0);
	}
	else if (reason == DLL_PROCESS_DETACH)
	{
		// Salimos del juego!
		salir = true;
	}

	// Devolver
	return true;
}
Con Windows Form he hecho esto. Puse un label_vida en el Form1 y este código, compila pero no lee nada de nada.

Código:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Prueba_DLL; // No olvidar este using. Para llamar a la clase Super_DLL.cs.

namespace Prueba_DLL
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           bool vida = Super_DLL.ObtenerVida();
           label_vida.Text = vida.ToString();
        }
    }
}
No me funciona ni así. Leeré tu enlace.

Hay gente que si les funciona y es capaz de leer cualquier variable con su dll hecho por él mismo.

Debo buscar la solución de otra manera.

Saludo.
__________________
Meta Shell, VERSIÓN 1.2.2
Descargar

Última edición por REHome; 16/03/2014 a las 11:58

Etiquetas: dll, variables, visual
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:05.