1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
namespace Plug_Load
{
public partial class Form1 : Form
{
#region P/Invoke
[DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("kernel32.dll")]
public static extern bool FreeLibrary(IntPtr hModule);
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hFile, uint dwFlags);
[DllImport("user32.dll")]
public static extern IntPtr LoadBitmap(IntPtr hInstance, int uID);
[DllImport("kernel32.dll")]
static extern IntPtr FindResource(IntPtr hModule, int lpID, string lpType);
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr LoadResource(IntPtr hModule, IntPtr hResInfo);
[DllImport("kernel32.dll", SetLastError = true)]
static extern uint SizeofResource(IntPtr hModule, IntPtr hResInfo);
[DllImport("user32.dll")]
public static extern int MessageBox(int h, string m, string c, int type);
public const uint LOAD_LIBRARY_AS_DATAFILE = 0x00000002;
#endregion
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//windows exit
Close();
}
private void Form1_Load(object sender, EventArgs e)
{
string pathe = "Plugins";
string[] files = Directory.GetFiles(pathe, "*.dll");
foreach (string file in files)
{
FileInfo fr = new FileInfo(file);
string id = Encoding.Default.GetString(BitConverter.GetBytes(2017));
IntPtr hMod = LoadLibraryEx(fr.FullName, IntPtr.Zero, LOAD_LIBRARY_AS_DATAFILE);
IntPtr hRes = FindResource(hMod, 2017, "Bitmap");
uint size = SizeofResource(hMod, hRes);
IntPtr pt = LoadResource(hMod, hRes);
Bitmap bmp;
byte[] bPtr = new byte[size];
Marshal.Copy(pt, bPtr, 0, (int)size);
using (MemoryStream m = new MemoryStream(bPtr))
bmp = (Bitmap)Bitmap.FromStream(m);
pictureBox1.Image = bmp;
menuStrip1.Items.Add(hMod.ToString());
}
} |
Partager