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

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


  Mostrar Mensajes
Páginas: 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 ... 47
91  Programación / Bases de Datos / Re: Cuando y para que usar bases de datos en un proyecto en: 20 Marzo 2020, 13:38 pm
Por regla general y dependiendo de lo que vayas a presentar en el website

1- Contenido estatico (pocas veces o casi nunca cambiara) -> no necesitas bd
    Ej: Blog, CV, etc.
2- Contenido dinamico (cambia constantemente y siempre necesitas presentar la informacion actualizada) -> necesitas bd
    Ej: Tienda online, catalogo de productos, webs de administracion, etc

Por supuesto que lo anterior es totalmente maleable y facilmente podrias usar una bd en ambos casos, aunque en el primero no seria necesario, pero como dije antes eso dependeria del contenido. Tambien cabe aclarar que lo anterior es recomendable para webs construidas desde cero y sin usar ningun CMS ya que estos ultimos de por si estan basados en el uso de bd
Saludos
92  Programación / Ingeniería Inversa / Re: Licencia xml en: 18 Marzo 2020, 15:34 pm
FileActivation.xml es un XML con el contenido de la peticion y la respuesta de activacion para dicha peticion. Dicho XML usa XML encryption para mantener privado el paso de informacion.
En el caso del segundo FileActivation.xml que muestras, se puede observar una estructura como la siguiente una vez se decodifica

Request
Código
  1. <EncryptedData Id="ActivationRequest" Type="http://www.w3.org/2001/04/xmlenc#Element"
  2.    xmlns="http://www.w3.org/2001/04/xmlenc#">
  3.    <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />
  4.    <KeyInfo
  5.        xmlns="http://www.w3.org/2000/09/xmldsig#">
  6.        <EncryptedKey
  7.            xmlns="http://www.w3.org/2001/04/xmlenc#">
  8.            <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" />
  9.            <KeyInfo
  10.                xmlns="http://www.w3.org/2000/09/xmldsig#">
  11.                <KeyName>SessionKey</KeyName>
  12.            </KeyInfo>
  13.            <CipherData>
  14.                <CipherValue>srYzp3rl3Tf5qwr+XBlUhPr+i5rTIYbDMP8BkHeZfa0jMOVuhCsSDgniKlea7Zjyc7lSifnKzklmx440aXM+EOYwybMnau7OcfVXyc0ko6Syq3zRAMLVF5MQYQ3txRwc1OFz3EkKvjRnXYZ7p2NTK2VvD1JznPI0NJlGTTByjZY=</CipherValue>
  15.            </CipherData>
  16.            <ReferenceList>
  17.                <DataReference URI="#ActivationRequest" />
  18.            </ReferenceList>
  19.        </EncryptedKey>
  20.    </KeyInfo>
  21.    <CipherData>
  22.        <CipherValue>MTybjZciUS/cOwvB4TxaKSBCA18+9OJS4RBUQD2yQQGrwJ8n/ZjH3l8dMjZ7WY9LEAGaVsrUk7OfGUNP3KWfDYvY0JeJC1XhGx+juGs/DB2FH0ZCwsE3OfWgOKfQNV2T10GxRM0TwC5GWGtz3QvzVIj2lGuW8yOB2Nm70tCVzIWYHWkS0mBNqVjkv1jAAk9AwSdDRNfxnLWHn1dJH8I5Ch1mx4P43H5AZxCkMdGdsTPHMiEhBbFV6dPmBD/ejGTSh/+PhboNPThqfIVnW58v6gHj62o39qSOyj4C9FtNESSB02bqd/Jd8N30cgGzFrZZUc06eqfHZ0yJxXAnvtW1uUjKyBkWjev4UhrHUglPAq/We8qFqGXEeNXq44Fu9FcPJqGYgVhkH1FNYUNht4nez4/yEXPXtUzR4Y3GmtW8uVwPzFfPIwR4TTyAOphLsxgFrVt0Psak0KAiHoAwL7qZf9GRmvOGL1p1axKzSTYYAXlPjFbGrkIxQ/NvW3qaINL/cbCEQqE8GM2z6f0bq89rWUI64zG7KpksTeGloqxZsEXRCDV/K1al4D3LzX2sN81aBlRqBUmk7aiXHyUeDcOmkgWxw62MyjncvNYxukwO49uw1MNzz5bUQ/ptODE1Hsq2us/qvu1+m+FgBNvsIoA7zpxPYLJx0GS/BYY41zJk5Bzrtz0BQzHZQ+Ek1GIdnC50/PcOga3o4tnclZv88u++YfqNIz488vmSRldZ9xa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QxWZDkWzKhv6iORgpqqwSwM6H6bh4pAq5IoLfSPYnSgeHiI00FoozCcgekKck+TUKPv8iXJOslyW01/+GPh4JlEXtAVBumvOIwGXxMXpoQ3xTozOXBzV+XLu8LeDcqdp9qt0lo1/UzUbvyq2sTqQo+FkkvEW+wqdYxAIOot5wXwM5jk6C+E0MfSu8yDbDfkr6oql/LDZrVkrfjJe6eUgxWRT4BU5X7EHamM0P2IOcovWH+nL2/pNQp/xWjR8z+jElBP6xkhDC/75nQG8GSP1z5zdmLPUklzjr95g+gJrKFAsiypvP3SOZbSqzuYvL9OnCKrTF1BTQO4nMg6hHZQ=</CipherValue>
  23.    </CipherData>
  24. </EncryptedData>

Response
Código
  1. <EncryptedData Id="ac" Type="http://www.w3.org/2001/04/xmlenc#Element"
  2.    xmlns="http://www.w3.org/2001/04/xmlenc#">
  3.    <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />
  4.    <KeyInfo
  5.        xmlns="http://www.w3.org/2000/09/xmldsig#">
  6.        <EncryptedKey
  7.            xmlns="http://www.w3.org/2001/04/xmlenc#">
  8.            <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" />
  9.            <KeyInfo
  10.                xmlns="http://www.w3.org/2000/09/xmldsig#">
  11.                <KeyName>sessionKey</KeyName>
  12.            </KeyInfo>
  13.            <CipherData>
  14.                <CipherValue>HANAB4Ly8oiAktwrzhE7dZMzi9+/HBiQCkqrzXNkcqITf0ZFMHyFOC+rFXImyEOIAv+kkJ19NcM5aEtZ2V/y7TXYq/sEXIVoUU19640owsQWL6BZsi4AEbcCjIcx/jBL4asVVvgHaJBMMX4VUAOlV0KU8QKSfJOzEAXCLMPcBa7vs80/9mWSk464oRbvjsfXKIRRoFGM6y/IEQKi9ZyqqVRrM+34tOmanFb/OAIw8qkyrWZVCt5luWELx6BoSY1H0clw8FfOLNZvKGHWXU8vtGoMDHusTCmAB9H7nH3hdSn9Evlui9t5TkG0fTClNIoqEWwh8nMNkZE1mmQN9tntTg2TRtETo58aeBi7PgJp2C0qyHHcImNUIXjCLJ5Phy75TOpgGjRtJXxAJ2jROMjTJs70ia55FN+597cIedZXWEiQrWbGDUljSfq7c2zmA10/o11Se+JGhC4LAkwwDIEL24q6wR9zsYj7G8G/CJa6ChDe/gfRz+hhCUbk3+MKj15+hsAffqecKpSLectDIZiUfo3m14xshAebH2x3zi2HBDVcjRuOYEasu/0UsT4sZ+RFsbMD+lEcW2VazxcBc4Iz7TvzABWESYQDgZ7nLjdC0OqSGyNPDVmajov3peZvVb5mL/G3Cv3KvaOBD2dT5ePoIR48YPqAT22FUCV4Ry5cxac=</CipherValue>
  15.            </CipherData>
  16.            <ReferenceList>
  17.                <DataReference URI="#ac" />
  18.            </ReferenceList>
  19.        </EncryptedKey>
  20.    </KeyInfo>
  21.    <CipherData>
  22.        <CipherValue>AjM1SPBWuA7jRkfiMNqsoh8HoZpgGa5aEikspgwKLgZdLc3Q4hsYyguUPjzxAxTZW8VrC+bwDuHjZM+T2fJpIvcEZwAKoMSXFbKYbwuknD4xWIoDFjFmJCoevUZ/ieVpWF9YnCnaZBb6no10bLmyk6+RWxfYAayKttUkHGHLdvxDWhstG2SkEwClabtFtJ5zhVd2ukMKzReKmebm9onRt+Eh+s5Z531iSUlqTo2CVew9tAQTJgzvUO7V9DYodngaWeg7rp/ibvvR4yJSQTfogg4fUs1eqzHeSXZB6R57TUv0If74zvqONz85TxkghKKaYSHTKgeggVygjEYoot9J4V3LujuBORCvNRGea01/GR+JoT5dhU6qEBgAXlQe6lvGcO9hQu1x+jKzKCO7nU3Ew065+3RtmzWtel9RVoix18IyulfxZyDgU3zDsRCHDMWo2Gn3k3kf3dbW7o9q3xQbayYI2AszvvjXv9xcGGxhwV/1KsHklj6SpkxrIVVMYEvjc8EDQjCNxwiXAbonkleLTkY115VvZEZ9q41MGHNzj7ZCC6YJAAPsJMgH7/dHZP7GgUoWdeOjBQgYU7wkOJXjTUuYZsnuoqt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uA63kDfI1W3sFDAPup97Bk8pLoLE9FR17U3pftuSLMEdGAEWh1A/+KOaYs5ftgJirWhlOYcu20eFy3tt1nUf3ilUqZsu0jHHcPgAGJayJ3xhBskz/E8oAR8doSm8WGLhWDMVezrj6uLAjjc6NTY7RhbWz70m+8mTDzo=</CipherValue>
  23.    </CipherData>
  24. </EncryptedData>

Como se puede apreciar se esta usando una combinacion de RSA/AES-256 para cifrar llave/contenido, por lo que habiendo llegado hasta aqui y dicho todo lo anterior, te doy un par de consejos:
1- Realizar ingenieria inversa en un binario no es como seguir un tutorial paso a paso de como lograr un buen efecto en photoshop, va mucho mas alla que eso y exige muchisimos mas conocimientos adicionales que, desde el respeto, no creo que poseas. Mi punto es que no existe "algún tutorial para aprender a generar un keygen para activar este tipo de licencia" (a no ser por supuesto que alguien mas lo haya hecho antes y haya compartido documentacion de como hacerlo paso a paso), para esto no existen caminos rapidos o atajos.
2- Dada la complejidad del tipo de activacion que se esta usando en comparacion con tu nivel en estos temas, te aconsejaria que empezaras buscando tutoriales basicos de como analizar y parchear ejecutables sencillos, solo con tiempo y mucha practica seras capaz entonces de empezar a entender de que va todo y quizas con muchisima suerte puedas lograr un parche exitoso. (repito, esto no es fast food)
3- Una vez mas con suerte y la ayuda de alguien con experiencia y quizas algo mas  :silbar:  quizas seas capaz de obtener algo

Suerte
 
93  Programación / .NET (C#, VB.NET, ASP) / Re: Menús y submenús en consola C# en: 3 Marzo 2020, 01:02 am
Pedazo de código. Eso si, tengo que entenderlo todo paso por paso. Si lo hiciste tu, buen trabajo.

LAs campturas te quedaron de lujo. Voy a investigar.

Si si lo hice yo  :xD de igual manera si no entiendes algo por parte del codigo o el algoritmo en si puedes preguntar, en realidad no es tan complicado. Como dije en un mensaje anterior, una vez que te abstraes lo suficiente puedes ver perfectamente como la relacion de un menu con un Arbol es casi perfecta, haciendo este tipo de estructura de datos las mas apropiada para implementarlo. El codigo se puede simplificar muchisimo si solo se deja el funcionamiento basico. La clase abstracta Menu es nuestra abstraccion del arbol y los atributos principales son:

Código
  1. protected internal Menu Parent;
  2. protected internal List<Menu> Children;
  3. protected internal int ChildIndex;

Parent sera el nodo padre o el menu padre si se quiere ver, Children los nodos hijos de dicho nodo padre, el cual es una lista de nodos pues evidentemente no estamos tratando con arbol binario en este caso pues un menu puede tener mas de dos entradas y finalmente ChildIndex sera nuestro selector.
Luego una de las funciones mas importantes es public void ControlLoop(), la encargada de mostrar el Nodo (menu) y procesar el input del usuario. Finalmente las clases HorizontalMenu/VerticalMenu y Entry son clases especializadas que implementan la clase abstracta Menu de acuerdo a su especificacion para lograr el objetivo de cada una y sus nombres son bien descriptivos del tipo de Nodo que serian.
Saludos

94  Programación / .NET (C#, VB.NET, ASP) / Re: Menús y submenús en consola C# en: 2 Marzo 2020, 08:16 am

No creo que era necesario referenciarme una conferencia de Arboles  :laugh:  se muy bien lo que son. En fin, en mi opinion una implementacion en este caso usando una ED tipo Arbol es la solucion ideal y vuelvo a repetirme, es una implementacion mas eficiente, dinamica y si, muchisimo mas sencilla aunque no lo parezca.
Como me parecio divertida la idea aqui dejo un sencillo framework (poc) que hice para crear menus en consola de forma dinamica usando un Arbol como abstraccion de datos. Aclaro que con esto no quiero decir que esta es la unica forma de hacerlo, simplemente que a mi parecer es la mas natural


Código
  1. /// <summary>
  2. /// Menu.cs
  3. /// Abstract menu class
  4. /// </summary>
  5. public abstract class Menu
  6. {
  7.    /// <summary>
  8.    /// Menu header UI details
  9.    /// </summary>
  10.    public class Position
  11.    {
  12.        public int TopSpacing { get; set; }
  13.        public int TopPadding { get; set; }
  14.        public int LeftPadding { get; set; }
  15.        public int LeftSpacing { get; set; }
  16.        public bool LeftCentered { get; set; }
  17.        public bool TopCentered { get; set; }
  18.    }
  19.  
  20.    public const string MarkerSymbol = "=>";
  21.    public List<string> HeaderText { get; set; }
  22.    public string EntryTitle { get; set; }
  23.    public bool Selected { get; set; }
  24.    public Position HeaderPos { get; set; }
  25.    public Position EntriesPos { get; set; }
  26.  
  27.    protected internal Menu Parent;
  28.    protected internal List<Menu> Children;
  29.    protected internal int ChildIndex;
  30.  
  31.    protected internal Menu()
  32.    {
  33.        Children = new List<Menu>();
  34.        HeaderPos = new Position();
  35.        EntriesPos = new Position();
  36.    }
  37.  
  38.    protected internal void Select()
  39.    {
  40.        Selected = true;
  41.    }
  42.  
  43.    protected internal void Deselect()
  44.    {
  45.        Selected = false;
  46.    }
  47.  
  48.    protected internal string GetMarker()
  49.    {
  50.        return Selected ? MarkerSymbol : new string(' ', MarkerSymbol.Length);
  51.    }
  52.  
  53.    public void AddChild(Menu child)
  54.    {
  55.        child.Parent = this;
  56.        Children.Add(child);
  57.    }
  58.  
  59.    protected internal string GetEntryString()
  60.    {
  61.        return $"{this.GetMarker()} {this.EntryTitle}";
  62.    }
  63.  
  64.    public void ControlLoop()
  65.    {
  66.        Console.CursorVisible = false;
  67.        do
  68.        {
  69.            ShowMenu();
  70.            ProcessKeyPress();
  71.        } while (true);
  72.    }
  73.  
  74.    protected internal abstract void Execute();
  75.    protected internal abstract void ShowMenu();
  76.    protected internal abstract void ProcessKeyPress();
  77. }
  78.  
  79.  
  80. /// <summary>
  81. /// VerticalMenu.cs
  82. /// Vertical menu class
  83. /// </summary>
  84. public class VerticalMenu : Menu
  85. {
  86.    protected internal override void Execute()
  87.    {
  88.        ControlLoop();
  89.    }
  90.  
  91.    protected internal override void ShowMenu()
  92.    {
  93.        Console.Clear();
  94.  
  95.        // calculating left positioning for menu header
  96.        int leftPosition = (HeaderPos.LeftCentered)
  97.                ? (Console.WindowWidth / 2) - (HeaderText.Max(x => x.Length) / 2)
  98.                : HeaderPos.LeftSpacing;
  99.  
  100.        int topPosition = (HeaderPos.TopCentered)
  101.            ? (Console.WindowHeight / 2) -
  102.              (((HeaderPos.TopPadding > 0) ? HeaderText.Count * 2 * HeaderPos.TopPadding : HeaderText.Count +
  103.              ((EntriesPos.TopPadding > 0) ? Children.Count * 2 * EntriesPos.TopPadding : Children.Count)) / 2)
  104.            : Console.CursorTop + HeaderPos.TopSpacing;
  105.  
  106.        Console.SetCursorPosition(leftPosition, topPosition);
  107.        foreach (string line in HeaderText)
  108.        {
  109.            Console.WriteLine(line);
  110.            Console.SetCursorPosition(leftPosition, Console.CursorTop + HeaderPos.TopPadding);
  111.        }
  112.  
  113.        // calculating left positioning for menu entries
  114.        int totalLeft = Children.Select(x => x.GetEntryString().Length).ToList().Max(x => x);
  115.        leftPosition = (EntriesPos.LeftCentered)
  116.            ? (Console.WindowWidth / 2) -
  117.              (totalLeft / 2)
  118.            : EntriesPos.LeftSpacing;
  119.  
  120.        Console.SetCursorPosition(leftPosition, Console.CursorTop + EntriesPos.TopSpacing);
  121.        foreach (var child in Children)
  122.        {
  123.            Console.WriteLine(child.GetEntryString());
  124.            Console.SetCursorPosition(leftPosition, Console.CursorTop + EntriesPos.TopPadding);
  125.        }
  126.    }
  127.  
  128.    protected internal override void ProcessKeyPress()
  129.    {
  130.        var key = Console.ReadKey();
  131.        switch (key.Key)
  132.        {
  133.            case ConsoleKey.UpArrow:
  134.                MoveMarkerUp();
  135.                break;
  136.  
  137.            case ConsoleKey.DownArrow:
  138.                MoveMarkerDown();
  139.                break;
  140.  
  141.            case ConsoleKey.Enter:
  142.                ExecuteEntry();
  143.                break;
  144.  
  145.            case ConsoleKey.Escape:
  146.                TryExitConsole();
  147.                break;
  148.        }
  149.    }
  150.  
  151.    private void MoveMarkerUp()
  152.    {
  153.        ChildIndex = (ChildIndex - 1 >= 0) ? ChildIndex -= 1 : Children.Count - 1;
  154.        Children.ForEach(x => x.Deselect());
  155.        Children[ChildIndex].Select();
  156.    }
  157.  
  158.    private void MoveMarkerDown()
  159.    {
  160.        ChildIndex = (ChildIndex + 1 < Children.Count) ? ChildIndex += 1 : 0;
  161.        Children.ForEach(x => x.Deselect());
  162.        Children[ChildIndex].Select();
  163.    }
  164.  
  165.    private void ExecuteEntry()
  166.    {
  167.        if (ChildIndex >= 0 && ChildIndex < Children.Count)
  168.        {
  169.            Menu menu = Children[ChildIndex];
  170.            if (menu?.GetType() != typeof(Entry) && menu?.Children.Count == 0)
  171.            {
  172.                menu = this.Parent;
  173.            }
  174.  
  175.            menu?.Execute();
  176.        }
  177.    }
  178.  
  179.    private void TryExitConsole()
  180.    {
  181.        if (this.Parent == null)
  182.            Environment.Exit(0);
  183.    }
  184. }
  185.  
  186.  
  187. /// <summary>
  188. /// HorizontalMenu.cs
  189. /// Horizontal menu class
  190. /// </summary>
  191. public class HorizontalMenu : Menu
  192. {
  193.    protected internal override void Execute()
  194.    {
  195.        ControlLoop();
  196.    }
  197.  
  198.    protected internal override void ShowMenu()
  199.    {
  200.        Console.Clear();
  201.  
  202.        // calculating left positioning for menu header
  203.        int leftPosition = (HeaderPos.LeftCentered)
  204.                ? (Console.WindowWidth / 2) - (HeaderText.Max(x => x.Length) / 2)
  205.                : HeaderPos.LeftSpacing;
  206.  
  207.        int topPosition = (HeaderPos.TopCentered)
  208.            ? (Console.WindowHeight / 2) -
  209.              (((HeaderPos.TopPadding > 0) ? HeaderText.Count * 2 * HeaderPos.TopPadding : HeaderText.Count +
  210.              ((EntriesPos.TopSpacing > 0) ? EntriesPos.TopSpacing + 1 : 1)) / 2)
  211.            : Console.CursorTop + HeaderPos.TopSpacing;
  212.  
  213.        Console.SetCursorPosition(leftPosition, topPosition);
  214.        foreach (string line in HeaderText)
  215.        {
  216.            Console.WriteLine(line);
  217.            Console.SetCursorPosition(leftPosition, Console.CursorTop + HeaderPos.TopPadding);
  218.        }
  219.  
  220.        // calculating left positioning for menu entries
  221.        int totalEntriesLeftSpace = Children.Select(x => x.GetEntryString().Length + EntriesPos.LeftPadding)
  222.                                            .ToList().Sum(x => x) - EntriesPos.LeftPadding;
  223.        topPosition = Console.CursorTop + EntriesPos.TopSpacing;
  224.        leftPosition = (EntriesPos.LeftCentered)
  225.            ? (Console.WindowWidth / 2) - (totalEntriesLeftSpace / 2)
  226.            : EntriesPos.LeftSpacing;
  227.        foreach (var entry in Children)
  228.        {
  229.            Console.SetCursorPosition(leftPosition, topPosition);
  230.            Console.WriteLine(entry.GetEntryString());
  231.            leftPosition += MarkerSymbol.Length + entry.EntryTitle.Length + EntriesPos.LeftPadding;
  232.        }
  233.    }
  234.  
  235.    protected internal override void ProcessKeyPress()
  236.    {
  237.        var key = Console.ReadKey();
  238.        switch (key.Key)
  239.        {
  240.            case ConsoleKey.LeftArrow:
  241.                MoveMarkerLeft();
  242.                break;
  243.  
  244.            case ConsoleKey.RightArrow:
  245.                MoveMarkerRight();
  246.                break;
  247.  
  248.            case ConsoleKey.Enter:
  249.                ExecuteEntry();
  250.                break;
  251.  
  252.            case ConsoleKey.Escape:
  253.                TryExitConsole();
  254.                break;
  255.        }
  256.    }
  257.  
  258.    private void MoveMarkerLeft()
  259.    {
  260.        ChildIndex = (ChildIndex - 1 >= 0) ? ChildIndex -= 1 : Children.Count - 1;
  261.        Children.ForEach(x => x.Deselect());
  262.        Children[ChildIndex].Select();
  263.    }
  264.  
  265.    private void MoveMarkerRight()
  266.    {
  267.        ChildIndex = (ChildIndex + 1 < Children.Count) ? ChildIndex += 1 : 0;
  268.        Children.ForEach(x => x.Deselect());
  269.        Children[ChildIndex].Select();
  270.    }
  271.  
  272.    private void ExecuteEntry()
  273.    {
  274.        if (ChildIndex >= 0 && ChildIndex < Children.Count)
  275.        {
  276.            Menu menu = Children[ChildIndex];
  277.            if (menu?.GetType() != typeof(Entry) && menu?.Children.Count == 0)
  278.            {
  279.                menu = this.Parent;
  280.            }
  281.  
  282.            menu?.Execute();
  283.        }
  284.    }
  285.  
  286.    private void TryExitConsole()
  287.    {
  288.        if (this.Parent == null)
  289.            Environment.Exit(0);
  290.    }
  291. }
  292.  
  293.  
  294. /// <summary>
  295. /// Entry.cs
  296. /// Menu entry class
  297. /// </summary>
  298. public class Entry : Menu
  299. {
  300.    public Action Event { get; set; }
  301.  
  302.    protected internal override void Execute()
  303.    {
  304.        Event?.Invoke();
  305.    }
  306.  
  307.    protected internal override void ShowMenu() { }
  308.  
  309.    protected internal override void ProcessKeyPress() { }
  310. }


Su uso para crear menus seria muy basico


Código
  1. static void Main(string[] args)
  2. {
  3.    Menu mainMenu = new VerticalMenu
  4.    {
  5.        HeaderText = new List<string>()
  6.        {
  7.            "============",
  8.            " Main Menu  ",
  9.            "============",
  10.            "Options:"
  11.        }
  12.    };
  13.    Entry blueEntry = new Entry
  14.    {
  15.        Selected = true,
  16.        EntryTitle = "Blue",
  17.        Event = () => { Console.BackgroundColor = ConsoleColor.DarkBlue; }
  18.    };
  19.    Entry redEntry = new Entry
  20.    {
  21.        Selected = false,
  22.        EntryTitle = "Red",
  23.        Event = () => { Console.BackgroundColor = ConsoleColor.DarkRed; }
  24.    };
  25.  
  26.    mainMenu.AddChild(blueEntry);
  27.    mainMenu.AddChild(redEntry);
  28.    mainMenu.ControlLoop();
  29. }


Igual he añadido un par de opciones para jugar con el posicionamiento de los elementos en la ventana de la consola, como el centrado horizontal y vertical, padding, etc



Resumiendo todo lo anterior, como decia antes el codigo base es mucho mas sencillo usando un Arbol para almacenar cada menu y si le quitamos todo el codigo extra para lo ultimo que comente y demas mierdas que puse son mucho menos lineas de codigo y logica de funcionamiento en general, ademas tienes la posibilidad de crear todos los menus, submenus y entradas que quieras de forma dinamica simplemente usando dichas clases en cualquier proyecto.
Pues nada, estuvo divertido  ;-)
Saludos
95  Programación / .NET (C#, VB.NET, ASP) / Re: Menús y submenús en consola C# en: 1 Marzo 2020, 00:19 am
Porque no lo implementas usando algo similar a un arbol?. Creo que seria mucho mas eficiente, dinamico y sobretodo sencillo
Saludos
96  Programación / .NET (C#, VB.NET, ASP) / Re: Corriendo una aplicacion desde .Net !! en: 28 Febrero 2020, 01:10 am
No das mucho detalle de lo que intentas hacer, pero como dijo **Aincrad**, debes tener en cuenta que una vez que un proceso carga una libreria y usa la funcion que necesita, la libera de memoria, por lo que es muy poco probable que en el punto que hagas el listado de modulos obtengas absolutamente todas las librerias que el proceso ha usado o usara en el futuro. Repito, no se lo que intentas hacer, pero puedo decir un par de ideas

1- Lanzar tu aplicacion como debugger del juego y depurarlo a tu gusto (WaitForDebugEvent/ContinueDebugEvent)
2- Inyectarte en el proceso justo antes de que se cargue completamente (ejecute su ep) y hacer hook en LoadLibrary

Saludos

97  Programación / .NET (C#, VB.NET, ASP) / Re: [Duda C#]Suma y Resta en un String en: 28 Febrero 2020, 00:29 am
- He usado una RegEx más corta, me parece que le basta ..., luego voy concatenando una String para los positivos y otra para los negativos, unidas mediante una "coma", al final se usa esa misma coma para hacerle un Split quitando las vacias.

Tienes razon, la expresion se puede simplificar. Algun motivo por el que no usas un List/ArrayList directamente? En mi opinion la concatenacion/split de cadenas estaria de mas.

Código
  1. public int ExtractNumbersFromString(string input, ref ArrayList positives, ref ArrayList negatives)
  2. {
  3.    Regex rx = new Regex(@"(?<positivos>\d+)|(?<negativos>-\d+)");
  4.    MatchCollection matches = rx.Matches(input);
  5.    foreach (Match match in matches)
  6.    {
  7.        if (!string.IsNullOrEmpty(match.Groups["positivos"].Value))
  8.        {
  9.            positives.Add(match.Value);
  10.        }
  11.        else
  12.        {
  13.            negatives.Add(match.Value);
  14.        }
  15.    }
  16.  
  17.    return matches.Count;
  18. }

Saludos

Edit: Supongo que seria mas util devolver la cantidad de matches en lugar de un bool  :silbar:
98  Programación / .NET (C#, VB.NET, ASP) / Re: [Duda C#]Suma y Resta en un String en: 27 Febrero 2020, 14:41 pm
tu idea la entendi pero tu codigo no.

Solo te he pasado la expresion regular que debes usar, todo lo que tienes que hacer es usarla en tu lenguaje

https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex?view=netframework-4.8
99  Programación / .NET (C#, VB.NET, ASP) / Re: Corriendo una aplicacion desde .Net !! en: 27 Febrero 2020, 14:23 pm
Puedes saber en un momento determinado que librerias tiene en memoria un proceso, luego necesitas saber si las que tiene en ese momento son todas las que se supone que deba cargar. Lo primero lo puedes hacer enumerando cada modulo en el proceso (OpenProcess/EnumProcessModules). Para lo segundo te podrias hacer hacer un listado de todas las librerias que carga el proceso en su ejecucion como base de comparacion
Saludos
100  Programación / Programación C/C++ / Re: pantalla de bienvenida en C en: 26 Febrero 2020, 21:58 pm
Para hacerlo en Windows necesitas dos cosas:
1- Obtener las dimensiones de la consola. Lo puedes hacer con GetConsoleScreenBufferInfo
2- Calcular y posicionar el cursor en la posicion correcta. Lo puedes hacer con SetConsoleCursorPosition

Saludos
Páginas: 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 ... 47
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines