프로그래밍
첫 페이지 랜덤 글 회원가입 로그인
비공개 손님 2023-01-12 02:43:00
그림판 뷰어 소스

코드는 개판이니 욕하지 말귀
돌아만 감

using System.Diagnostics;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

namespace mspaintcap
{
    public partial class Form1 : Form
    {
        Process[] p;
        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;

        [DllImport("kernel32.dll")]
        public static extern int OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);

        [DllImport("kernel32.dll")]
        public static extern bool ReadProcessMemory(int hProcess, UInt64 lpBaseAddress, byte[] buffer, int size, int lpNumberOfBytesRead);

        public Form1()
        {
            InitializeComponent();
        }

        int processHandle = 0;

        string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");


        private void Form1_Load(object sender, EventArgs e)
        {
            Directory.CreateDirectory(dtstr);
            Directory.SetCurrentDirectory(dtstr);

            try
            {
                p = Process.GetProcessesByName("mspaint");
            }
            catch { textBoxADDR.Text = "error"; }
            processHandle = OpenProcess((DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER | SYNCHRONIZE | END), false, p[0].Id);
        }

        private void buttonFind_Click(object sender, EventArgs e)
        {
            CAP();

        }

        private void CAP()
        {
            int cpp = 3;
            if (checkBox32bpp.Checked) cpp = 4;
            if (processHandle == 0) return;
            labelHANDLE.Text = processHandle.ToString();
            int w = 300;
            int h = 300;
            UInt64 addr = UInt64.Parse(textBoxADDR.Text, System.Globalization.NumberStyles.HexNumber);
            if (int.TryParse(textBoxW.Text, out w) == false) return;
            if(int.TryParse(textBoxH.Text, out h) == false) return; // int rrrr = w * h;
            byte [] ImageBytes = ReadMemory(addr, w * h * cpp, processHandle);
            if (checkBox32bpp.Checked) for (int ii = 0; ii < w * h * cpp; ii += 4) ImageBytes[ii + 3] = 255;
            Bitmap output = new Bitmap(w, h, cpp == 4 ? PixelFormat.Format32bppArgb : PixelFormat.Format24bppRgb);
            Rectangle rect = new Rectangle(0, 0, output.Width, output.Height);
            BitmapData bmpData = output.LockBits(rect, ImageLockMode.ReadWrite, output.PixelFormat);
            IntPtr ptr = bmpData.Scan0;
            for(int pos = 0; pos < ImageBytes.Length; pos += w * cpp)
            Marshal.Copy(ImageBytes, pos, ptr + ImageBytes.Length - pos - w * cpp, w * cpp);

            output.UnlockBits(bmpData);
            pictureBox1.Image = output;
            pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
            pictureBox1.Refresh();
            output.Save(labelCount.Text, ImageFormat.Png);
        }

        public static byte[] ReadMemory(UInt64 adress, int processSize, int processHandle)
        {
            byte[] buffer = new byte[processSize];
            ReadProcessMemory(processHandle, adress, buffer, processSize, 0);
            return buffer;
        }

        int count = 0;

        private void timer1_Tick(object sender, EventArgs e)
        {
            labelCount.Text = count.ToString("D5") + ".png";
            CAP();
            ++count;
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            textBoxTimer.ReadOnly = true;
            buttonStart.Hide();
            int interval = 30;
            int.TryParse(textBoxTimer.Text, out interval);
            timer1.Interval = interval * 1000;
            timer1.Enabled = true;
        }
    }
}

정보 | 809명이 읽었어요. 44.200.101.84

0
댓글을 작성하실 수 없습니다.
(권한이 없는 회원레벨)
목록으로
△ 이전글: (백엔드) 이럴때 DB 테이블 설계 어떻게 하시나요 ? [4]
▽ 다음글: 그림판 전체보기 기능 성공? [7]
이용약관 | 광고/제휴 | 개인정보취급방침 | 문의/신고 | 모바일 TE31 | 서버 부하 : 13.75%
실시간 Issue 커뮤니티 TE31 [알지롱] ⓒ 2002-2023
TOP arrow_upward