i put this together:
Code:
private void Form1_Load(object sender, EventArgs e)
{
File.Copy("test - Kopie.exe", "test.exe", true);
IntPtr handle = BeginUpdateResource("test.exe", false);
byte[] file = new byte[3]; file[0] = 65; file[1] = 66; file[2] = 67;
IntPtr fileptr = ToPtr(file);
bool res = UpdateResource(handle, "RT_RCDATA", "test.exe", 0, fileptr, Convert.ToUInt32(file.Length));
EndUpdateResource(handle, false);
}
unsafe private IntPtr ToPtr(byte[] buffer)
{
fixed (byte* ptr = buffer)
{
return (IntPtr)ptr;
}
}
[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 IntPtr BeginUpdateResource(string pFileName, [MarshalAs(UnmanagedType.Bool)]bool bDeleteExistingResources);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool EndUpdateResource(IntPtr hUpdate, bool fDiscard);
which creates a file in the resources of test.exe. resource hacker can even find this file, althoug it never finds any .NET assembly resources???
anyway, it is not beeing recognized by the code of test.exe...
could it be that resources from executables are different/other than the ones i can define in visual studio? if so, all this was for the toilet... ;(