elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
28 Mayo 2012, 04:32  


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (Moderador: [D4N93R])
| | | |-+  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 941 veces)
krosty123

Desconectado Desconectado

Mensajes: 8


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

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

Código
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
 
namespace WindowsFormsApplication1
{
   static class Program
   {
       /// <summary>
       /// The main entry point for the application.
       /// </summary>
       [STAThread]
       [DllImport("kernel32.dll", SetLastError = true)]
       static extern IntPtr BeginUpdateResource(string pFileName, bool bDeleteExistingResources);
       [DllImport("kernel32.dll", SetLastError = true)]
       static extern bool UpdateResource(IntPtr hUpdate, string lpType, string lpName, ushort wLanguage, IntPtr lpData, uint cbData);
       [DllImport("kernel32.dll", SetLastError = true)]
       static extern bool EndUpdateResource(IntPtr hUpdate, bool fDiscard);
       static unsafe void Main()
       {
           string path = "c:\\users\\sean\\desktop\\resourcer.exe";
 
           IntPtr hResource = BeginUpdateResource(path, false);
           if (hResource.ToInt32() == 0)
               throw new Exception("File Not Found");
 
           string newMessage = File.ReadAllText("c:\\users\\sean\\desktop\\newMessage.txt");
           Byte[] bytes = new ASCIIEncoding().GetBytes(newMessage);
           GCHandle bHandle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
           IntPtr ptr = bHandle.AddrOfPinnedObject();
 
           ushort id = (ushort)Language.MakeLanguageID();
 
           if (UpdateResource(hResource, "FILE", "eva.txt", id, ptr, (uint)bytes.Length))
               EndUpdateResource(hResource, false);
           else
               MessageBox.Show("Did not update", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
       }
   }
   public static class Language
   {
 
       public static int MakeLanguageID()
       {
           CultureInfo currentCulture = CultureInfo.CurrentCulture;
           int pid = GetPid(currentCulture.LCID);
           int sid = GetSid(currentCulture.LCID);
           return (((ushort)pid) << 10) | ((ushort)sid);
       }
 
 
       public static int GetPid(int lcid)
       { return ((ushort)lcid) & 0x3ff; }
 
 
       public static int GetSid(int lcid)
       { return ((ushort)lcid) >> 10; }
 
   }
}
 


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
 
     string strNewPathToSave = "new.txt";
 
     Assembly assembly = Assembly.GetExecutingAssembly();
 
     Stream resourceStream = assembly.GetManifestResourceStream("WindowsFormsApplication2.Resources.eva.txt");
 
     System.IO.FileStream fs = System.IO.File.OpenWrite(strNewPathToSave);
 
     try
 
     {
 
     // Save the File...
 
     byte[] buffer = new byte[resourceStream.Length];
 
     resourceStream.Read(buffer, 0, (int)resourceStream.Length);
 
     fs.Write(buffer, 0, buffer.Length);
 
     }
 
     finally
 
     {
 
     fs.Close();
 
     }

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 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 »

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 »

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 2,496 Último mensaje 27 Mayo 2011, 01:31
por Mr.Blue
Demonio RAT 3.0 - [OpenSource - GPLv3] - Añadidos ejecutables win32 « 1 2 3 »
Análisis y Diseño de Malware
paju1986 37 11,597 Último mensaje 21 Abril 2012, 19:26
por ernilos
Problema con UpdateResource
Programación C/C++
carlosjw 0 220 Último mensaje 18 Agosto 2011, 15:25
por carlosjw
Problema listando proceso en win32
Programación C/C++
Uknow 3 306 Último mensaje 20 Noviembre 2011, 06:06
por naderST
Win32 API Hooking
Hacking Avanzado
nts94 0 341 Último mensaje 9 Febrero 2012, 23:54
por nts94
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines