using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
/*
* Open Source Project.
* 지뢰찾기 지뢰 위치 [Win7 32bit minesweeper]
* 분석, 프로그램작성 : sweetchip
* 날자 : 2013.01.22
*
* Blog : http://pgnsc.tistory.com
* Site : http://studyc.co.kr
*
* xp의 지뢰찾기와는 달리 가로 세로 지뢰수를 따로 구하려면 리버싱 작업이 더 필요해서
* 일단은 가로, 세로는 입력을 받는 형식으로 목적을 두고 분석하고 프로그램을 만들었습니다.
* 세로는 쉽게 찾을수 있으나, 가로와 지뢰개수를 찾기가 힘드네요. 그렇다고 리버싱을 더하기엔 시간이 없네요 ㅠㅠ
* 좋은 아이디어 있으신분 덧글로 남겨주심 감사하겠습니다.
*/
namespace Win7_minesweeper
{
public partial class Form1 : Form
{
[DllImport("kernel32.dll")]
public static extern int OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll")]
public static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, byte[] buffer, int size, int lpNumberOfBytesRead);
public uint DELETE = 0x00010000;
public uint READ_CONTROL = 0x00020000;
public uint WRITE_DAC = 0x00040000;
public uint WRITE_OWNER = 0x00080000;
public uint SYNCHRONIZE = 0x00100000;
public uint END = 0xFFF;
public Process[] processes;
public static byte[] ReadMemory(int adress, int processSize, int processHandle)
{
byte[] buffer = new byte[processSize];
ReadProcessMemory(processHandle, adress, buffer, processSize, 0);
return buffer;
}
public int getbaseaddr()
{
int basea = processes[0].MainModule.BaseAddress.ToInt32();
return basea;
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
processes = Process.GetProcessesByName("MineSweeper");
numericUpDown2.Value = gety(getbaseaddr());
}
public void go()
{
processes = Process.GetProcessesByName("MineSweeper");
listBox1.Items.Clear();
try
{
for (int i = 0; i < (int)numericUpDown2.Value; i )
{
for (int j = 0; j < (int)numericUpDown1.Value; j )
{
ismine(i, j);
}
}
}
catch
{
MessageBox.Show("ERROR","ERROR");
}
}
public void ismine(int y, int x)
{
int basea = processes[0].MainModule.BaseAddress.ToInt32();
int ecx1 = getecx(getbaseaddr() 0x868b4) 0x10;
int ecx2 = getmem(ecx1);
int cel = ecx2 0x44;
cel = getmem(cel) 0x0c;
cel = getmem(cel) (x * 4);
cel = getmem(cel) 0x0c;
cel = getmem(cel) y;
cel = getmem1byte(cel);
if (cel == 1)
{
int tempx = x 1;
int tempy = y 1;
listBox1.Items.Add(tempy ", " tempx " 좌표에 지뢰");
}
label1.Text = "우와 @_@ 신기하다\n총 지뢰 개수 : " listBox1.Items.Count;
}
public int getecx(int baseaddr)
{
int processHandle = OpenProcess((DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER | SYNCHRONIZE | END), false, processes[0].Id);
byte[] tmp = ReadMemory(baseaddr, 4, processHandle);
int m = BitConverter.ToInt32(tmp,0);
return m;
}
public int gety(int baseaddr)
{
int processHandle = OpenProcess((DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER | SYNCHRONIZE | END), false, processes[0].Id);
byte[] tmp = ReadMemory(baseaddr 0x7e1dc, 4, processHandle);
int m = BitConverter.ToInt32(tmp, 0);
return m;
}
public int getmem(int addr)
{
int basea = processes[0].MainModule.BaseAddress.ToInt32();
int processHandle = OpenProcess((DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER | SYNCHRONIZE | END), false, processes[0].Id);
byte[] tmp = ReadMemory(addr, 4, processHandle);
int m = BitConverter.ToInt32(tmp, 0);
return m;
}
public int getmem1byte(int addr)
{
int basea = processes[0].MainModule.BaseAddress.ToInt32();
int processHandle = OpenProcess((DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER | SYNCHRONIZE | END), false, processes[0].Id);
byte[] tmp = ReadMemory(addr, 1, processHandle);
int m = (int)tmp[0];
return m;
}
private void button1_Click(object sender, EventArgs e)
{
go();
}
}
}
긴 글 읽어주시느라 수고 하셨습니다.