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

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Ayuda win32.beginupdateresource(), win32.updateresource(), no funciona.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda win32.beginupdateresource(), win32.updateresource(), no funciona.  (Leído 3,559 veces)
krosty123

Desconectado Desconectado

Mensajes: 8


Ver Perfil
Ayuda win32.beginupdateresource(), win32.updateresource(), no funciona.
« en: 2 Noviembre 2010, 02:03 am »

estuve probando varias maneras de cambiar los rescursos de un exe, al final lo que ando usando es:

Código
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using Microsoft.Win32;
  11.  
  12. namespace WindowsFormsApplication1
  13. {
  14.    static class Program
  15.    {
  16.        /// <summary>
  17.        /// The main entry point for the application.
  18.        /// </summary>
  19.        [STAThread]
  20.        [DllImport("kernel32.dll", SetLastError = true)]
  21.        static extern IntPtr BeginUpdateResource(string pFileName, bool bDeleteExistingResources);
  22.        [DllImport("kernel32.dll", SetLastError = true)]
  23.        static extern bool UpdateResource(IntPtr hUpdate, string lpType, string lpName, ushort wLanguage, IntPtr lpData, uint cbData);
  24.        [DllImport("kernel32.dll", SetLastError = true)]
  25.        static extern bool EndUpdateResource(IntPtr hUpdate, bool fDiscard);
  26.        static unsafe void Main()
  27.        {
  28.            string path = "c:\\users\\sean\\desktop\\resourcer.exe";
  29.  
  30.            IntPtr hResource = BeginUpdateResource(path, false);
  31.            if (hResource.ToInt32() == 0)
  32.                throw new Exception("File Not Found");
  33.  
  34.            string newMessage = File.ReadAllText("c:\\users\\sean\\desktop\\newMessage.txt");
  35.            Byte[] bytes = new ASCIIEncoding().GetBytes(newMessage);
  36.            GCHandle bHandle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
  37.            IntPtr ptr = bHandle.AddrOfPinnedObject();
  38.  
  39.            ushort id = (ushort)Language.MakeLanguageID();
  40.  
  41.            if (UpdateResource(hResource, "FILE", "eva.txt", id, ptr, (uint)bytes.Length))
  42.                EndUpdateResource(hResource, false);
  43.            else
  44.                MessageBox.Show("Did not update", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  45.        }
  46.    }
  47.    public static class Language
  48.    {
  49.  
  50.        public static int MakeLanguageID()
  51.        {
  52.            CultureInfo currentCulture = CultureInfo.CurrentCulture;
  53.            int pid = GetPid(currentCulture.LCID);
  54.            int sid = GetSid(currentCulture.LCID);
  55.            return (((ushort)pid) << 10) | ((ushort)sid);
  56.        }
  57.  
  58.  
  59.        public static int GetPid(int lcid)
  60.        { return ((ushort)lcid) & 0x3ff; }
  61.  
  62.  
  63.        public static int GetSid(int lcid)
  64.        { return ((ushort)lcid) >> 10; }
  65.  
  66.    }
  67. }
  68.  


Para ver si funciona lo que hago es "descomprimir" el recurso del exe modificado.
Supuestamente deberia mostrar el nuevo .txt, pero no... cuando lo abro contiene el texto viejo.

Lo que hago para descomprimir los recursos del exe modificado es:
Código
  1.  
  2.      string strNewPathToSave = "new.txt";
  3.  
  4.      Assembly assembly = Assembly.GetExecutingAssembly();
  5.  
  6.      Stream resourceStream = assembly.GetManifestResourceStream("WindowsFormsApplication2.Resources.eva.txt");
  7.  
  8.      System.IO.FileStream fs = System.IO.File.OpenWrite(strNewPathToSave);
  9.  
  10.      try
  11.  
  12.      {
  13.  
  14.      // Save the File...
  15.  
  16.      byte[] buffer = new byte[resourceStream.Length];
  17.  
  18.      resourceStream.Read(buffer, 0, (int)resourceStream.Length);
  19.  
  20.      fs.Write(buffer, 0, buffer.Length);
  21.  
  22.      }
  23.  
  24.      finally
  25.  
  26.      {
  27.  
  28.      fs.Close();
  29.  
  30.      }

Redondeando....
Con exe1 cambio un recurso de exe2 (un .txt). Despues abro el exe2 y descomprimo el recurso .txt . Este en lugar de mostrar el nuevo texto, muestra el texto del recurso original.
Alguna idea?

Saludos


« Última modificación: 2 Noviembre 2010, 18:14 pm por krosty123 » En línea

MANULOMM


Desconectado Desconectado

Mensajes: 559


Erepublik.com


Ver Perfil
Re: Ayuda win32.beginupdateresource(), win32.updateresource(), no funciona.
« Respuesta #1 en: 2 Noviembre 2010, 20:31 pm »

NO entiendo que intentas hacer y por que usas las llamadas a la API de Windows. los exe's que contienen los recursos en que estan hechos?...

Atentamente,

Juan Manuel Lombana
Medellín - Colombia


En línea


krosty123

Desconectado Desconectado

Mensajes: 8


Ver Perfil
Re: Ayuda win32.beginupdateresource(), win32.updateresource(), no funciona.
« Respuesta #2 en: 6 Noviembre 2010, 04:10 am »

Llamo a la api, para poder modificar el recurso de una aplicacion desde otra, es la unica manera que encontre.
Los exes estan hechos en c# ambos.
Saludos
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
JDK para win32? [ayuda]
Java
akibara 3 7,108 Último mensaje 27 Mayo 2011, 01:31 am
por Mr.Blue
Ayuda con firma Win32:VBCrypt-VW !!
Análisis y Diseño de Malware
VanHelsing810 9 5,948 Último mensaje 7 Diciembre 2014, 03:12 am
por x64core
Ayuda para remover virus Win32/Small.CA
Seguridad
Kaxperday 1 3,069 Último mensaje 12 Diciembre 2014, 03:20 am
por r32
Leer dll en consola win32 « 1 2 3 »
Programación C/C++
Meta 21 9,540 Último mensaje 3 Julio 2020, 23:29 pm
por Meta
Libros de Win32 API en C/C++
Programación C/C++
Locura_23 2 2,556 Último mensaje 26 Agosto 2021, 21:36 pm
por Locura_23
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines