elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


  Mostrar Mensajes
Páginas: 1 2 [3] 4 5 6 7 8 9 10 11 12 13 14 15 16 17
21  Programación / .NET (C#, VB.NET, ASP) / Re: Compilando en tiempo de ejecucion (¿make builder?) C# en: 9 Diciembre 2010, 21:22 pm
Respuesta sublime.

 ;D ;-)
22  Programación / .NET (C#, VB.NET, ASP) / Compilando en tiempo de ejecucion (¿make builder?) C# en: 9 Diciembre 2010, 13:38 pm
Feliz Navidad!!  ;D

Tengo una duda acerca de C# y como podria hacer un builder.

He estado mirando acerca de compilacion en tiempo de ejecucion para poder compilar mi proyecto con las opciones que en ese momento sean oportunas y he encotnrado esto
http://www.digitalcoding.com/Code-Snippets/C-Sharp/C-Code-Snippet-Compile-C-or-VB-source-code-run-time.html  y esto tambien!
http://support.microsoft.com/kb/304655
Que me ha parecido super interesante!
Para el que sea un poco vaguete y no le apetezca mirar las web que he dejado aqui esta lo que hace posible la compilacion en tiempo de ejecucion en un programa:


Código
  1. /// <summary>
  2. /// Function to compile .Net C#/VB source codes at runtime
  3. /// </summary>
  4. /// <param name="_CodeProvider">Base class for compiler provider</param>
  5. /// <param name="_SourceCode">C# or VB source code as a string</param>
  6. /// <param name="_SourceFile">External file containing C# or VB source code</param>
  7. /// <param name="_ExeFile">File path to create external executable file</param>
  8. /// <param name="_AssemblyName">File path to create external assembly file</param>
  9. /// <param name="_ResourceFiles">Required resource files to compile the code</param>
  10. /// <param name="_Errors">String variable to store any errors occurred during the process</param>
  11. /// <returns>Return TRUE if successfully compiled the code, else return FALSE</returns>
  12. private bool CompileCode(System.CodeDom.Compiler.CodeDomProvider _CodeProvider, string _SourceCode, string _SourceFile, string _ExeFile, string _AssemblyName, string[] _ResourceFiles, ref string _Errors)
  13. {
  14.    // set interface for compilation
  15.    System.CodeDom.Compiler.ICodeCompiler _CodeCompiler = _CodeProvider.CreateCompiler();
  16.  
  17.    // Define parameters to invoke a compiler
  18.    System.CodeDom.Compiler.CompilerParameters _CompilerParameters =
  19.        new System.CodeDom.Compiler.CompilerParameters();
  20.  
  21.    if (_ExeFile != null)
  22.    {
  23.        // Set the assembly file name to generate.
  24.        _CompilerParameters.OutputAssembly = _ExeFile;
  25.  
  26.        // Generate an executable instead of a class library.
  27.        _CompilerParameters.GenerateExecutable = true;
  28.        _CompilerParameters.GenerateInMemory = false;
  29.    }
  30.    else if (_AssemblyName != null)
  31.    {
  32.        // Set the assembly file name to generate.
  33.        _CompilerParameters.OutputAssembly = _AssemblyName;
  34.  
  35.        // Generate an executable instead of a class library.
  36.        _CompilerParameters.GenerateExecutable = false;
  37.        _CompilerParameters.GenerateInMemory = false;
  38.    }
  39.    else
  40.    {
  41.        // Generate an executable instead of a class library.
  42.        _CompilerParameters.GenerateExecutable = false;
  43.        _CompilerParameters.GenerateInMemory = true;
  44.    }
  45.  
  46.  
  47.    // Generate debug information.
  48.    //_CompilerParameters.IncludeDebugInformation = true;
  49.  
  50.    // Set the level at which the compiler
  51.    // should start displaying warnings.
  52.    _CompilerParameters.WarningLevel = 3;
  53.  
  54.    // Set whether to treat all warnings as errors.
  55.    _CompilerParameters.TreatWarningsAsErrors = false;
  56.  
  57.    // Set compiler argument to optimize output.
  58.    _CompilerParameters.CompilerOptions = "/optimize";
  59.  
  60.    // Set a temporary files collection.
  61.    // The TempFileCollection stores the temporary files
  62.    // generated during a build in the current directory,
  63.    // and does not delete them after compilation.
  64.    _CompilerParameters.TempFiles = new System.CodeDom.Compiler.TempFileCollection(".", true);
  65.  
  66.    if (_ResourceFiles != null && _ResourceFiles.Length > 0)
  67.        foreach (string _ResourceFile in _ResourceFiles)
  68.        {
  69.            // Set the embedded resource file of the assembly.
  70.            _CompilerParameters.EmbeddedResources.Add(_ResourceFile);
  71.        }
  72.  
  73.  
  74.    try
  75.    {
  76.        // Invoke compilation
  77.        System.CodeDom.Compiler.CompilerResults _CompilerResults = null;
  78.  
  79.        if (_SourceFile != null && System.IO.File.Exists(_SourceFile))
  80.            // soruce code in external file
  81.            _CompilerResults = _CodeCompiler.CompileAssemblyFromFile(_CompilerParameters, _SourceFile);
  82.        else                              
  83.            // source code pass as a string
  84.            _CompilerResults = _CodeCompiler.CompileAssemblyFromSource(_CompilerParameters, _SourceCode);                                                
  85.  
  86.        if (_CompilerResults.Errors.Count > 0)
  87.        {
  88.            // Return compilation errors
  89.            _Errors = "";
  90.            foreach (System.CodeDom.Compiler.CompilerError CompErr in _CompilerResults.Errors)
  91.            {
  92. _Errors += "Line number " + CompErr.Line +
  93.                            ", Error Number: " + CompErr.ErrorNumber +
  94.                            ", '" + CompErr.ErrorText + ";\r\n\r\n";
  95.            }
  96.  
  97.            // Return the results of compilation - Failed
  98.            return false;
  99.        }
  100.        else
  101.        {
  102.            // no compile errors
  103.            _Errors = null;
  104.        }
  105.    }
  106.    catch (Exception _Exception)
  107.    {
  108.        // Error occurred when trying to compile the code
  109.        _Errors = _Exception.Message;
  110.        return false;
  111.    }
  112.  
  113.    // Return the results of compilation - Success
  114.    return true;
  115. }
  116.  


Código
  1. string _Errors = "";
  2.  
  3. // C# source code pass as a string
  4. string _CSharpSourceCode = @"
  5.            using System;
  6.  
  7.            namespace test
  8.            {
  9.                class Program
  10.                {
  11.                    static void Main(string[] args)
  12.                    {
  13.                        Console.WriteLine(""Press ENTER key to start ..."");
  14.                        Console.ReadLine();
  15.                        for (int c=0; c<=100; c++)
  16.                            Console.WriteLine(c.ToString());
  17.                    }
  18.                }
  19.            }";
  20.  
  21.  
  22. // Compile C-Sharp code
  23. if (CompileCode(new Microsoft.CSharp.CSharpCodeProvider(), _CSharpSourceCode, null, "c:\\temp\\C-Sharp-test.exe", null, null, ref _Errors))
  24.    Console.WriteLine("Code compiled successfully");
  25. else
  26.    Console.WriteLine("Error occurred during compilation : \r\n" + _Errors);
  27.  
De modo que veo que con System.CodeDom y algo mas se puede compilar el codigo que tu le introduces a modo de una variable string.

Mi problema es que quiero compilar un proyecto entero de c# con sus librerias y referencias.. porsupuesto en una string es impensable!
Como podria hacer para generar un exe con unas opciones y caracteristicas que yo le ponga a partir de otro exe??
vamos un builder de toda la vida xd
23  Programación / .NET (C#, VB.NET, ASP) / Re: Screenshot a Ram en: 5 Noviembre 2010, 18:08 pm
Ups!!

Esta noche o miro y te digo pero creo que es eso lo que dices :)

joder estoy espeso hoy xd

Gracias, luego te comento !
24  Programación / .NET (C#, VB.NET, ASP) / Screenshot a Ram en: 5 Noviembre 2010, 17:33 pm
Buenas!!!

Estoy intentado hacer una aplicacion cliente/servidor y me he topado con esta barrera!

como podria hacer para que al hacer uan captura de pantalla en vez de que se guarde en una direccion fisica al disco duro, se guarde en la RAM??? (asi nos evitamos el dejar archivos por ahi)
para despues enviar esos bytes guardados en memoria y que en la otra parte del cliente los salve correctamente!

No se si me he explicado correctamente!

De momento tengo esto:
   
Código:
using (MemoryStream memoryStream = new MemoryStream())
      {

        byte[] fileBytes = File.ReadAllBytes(@"C:\imagepath.ext");

        memoryStream.Write(fileBytes, 0, fileBytes.Length)

Para guardar algo en la memoria, pero lo hace apartir de un archivo ya guardado en el disco! yo necesitaria directamente!

Como se haria? iluminarme si sabeis como se hace!


25  Seguridad Informática / Seguridad / Re: Pregunta sobre Nessus en: 9 Septiembre 2010, 21:48 pm
por eso mismo, ya que es un scanner y tener mas flexibilidad seria bueno que fuera portable!
26  Seguridad Informática / Seguridad / Pregunta sobre Nessus en: 9 Septiembre 2010, 20:15 pm
Buenas, me gustaria saber si hay alguna version de nessus portable, o si alguien ha sido capaz de hacer algun paquete para que funcione y no tener que ir haciendo licencias por ahi para que pueda funcionar
27  Sistemas Operativos / Windows / Re: Letras enanas!!!!! en: 14 Agosto 2010, 18:02 pm
en modo a preuba de fallos tampoco me deja borrar la fuente... lo unico que se me ocurre hacer es probar con un cd live ubuntu o alguno asi y probrar a borrar esa fuente.. pero nuse!!
28  Sistemas Operativos / Windows / Re: Letras enanas!!!!! en: 14 Agosto 2010, 17:50 pm
al cambiar el tema todo sigue igual, y la fuente gabriola no me deja borrarla porke dice que es del sistema y nanai... ahora entrare en prueba de fallos!
29  Sistemas Operativos / Windows / Re: Letras enanas!!!!! en: 14 Agosto 2010, 17:44 pm
voy a probar y te cuento!
30  Sistemas Operativos / Windows / Re: Letras enanas!!!!! en: 14 Agosto 2010, 15:18 pm
en el internet explorer de 32 bits y en el de 64 (en win 7 salen las 2 versiones) esta en tamaño del texto: Mediano

puede que sea lo de la resolucion de ese tipo de fuente oke?? aunque si fuera asi, todas se verian enananas!

aggg nose que hacer! me voy a quedar bisojoooo
Páginas: 1 2 [3] 4 5 6 7 8 9 10 11 12 13 14 15 16 17
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines