|
-
May 12th, 2020, 11:33 AM
#1
[RESOLVED] How to change resource file data of an executable?
Problem:
I have an executable VB6 file.
I want to change the bytes of an encapsulated file as a resource that is loaded with LoadResData (101, "CUSTOM")
What I want to know is:
1) Where are these data inside the exe (at what offset)
2) How long is the "packet" of data and where does it end?
3) Optional: Which program to use to edit the binary exe file?
Thanks
Edit PS
Why do I want to do this?
For example because I have distributed in exe that I want to modify but I don't have an "exact" copy of the source code that I used to create it.
Last edited by reexre; May 12th, 2020 at 11:37 AM.
-
May 12th, 2020, 12:13 PM
#2
Re: How to change resource file data of an executable?
You could use something like ResHacker to look at the resource in question, that will list the offset, then something like WinHex to edit.
Or just extract the resource, edit traditionally, and replace the old one.
-
May 12th, 2020, 12:20 PM
#3
Re: How to change resource file data of an executable?
 Originally Posted by reexre
but I don't have an "exact" copy of the source code that I used to create it.
Basically, to my eyes reexre, you're admitting to "hacking", even if you did write the original code. Personally, I don't think there's ever a good reason to modify a compiled executable. And there are just too many other paths/ways to store persistent data. Also, I would actually hope that altering executables would flag warnings in virus scanners. But, that's just all my opinion.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
May 12th, 2020, 12:29 PM
#4
Re: How to change resource file data of an executable?
You can use BeginUpdateResource, UpdateResource, EndUpdateResource.
-
May 12th, 2020, 01:27 PM
#5
Re: How to change resource file data of an executable?
 Originally Posted by fafalone
You could use something like ResHacker to look at the resource in question, that will list the offset, then something like WinHex to edit.
Or just extract the resource, edit traditionally, and replace the old one.
THANK YOU !
Elroy
To clarify again: I'm "hacking" a program made by me because I don't have the source "perfectly" equal to the released executable, of which a user asks me for a modification.
The resource in question is simply an image! who knows what a dangerous hack!
Last edited by reexre; May 12th, 2020 at 01:32 PM.
-
May 12th, 2020, 02:22 PM
#6
Re: How to change resource file data of an executable?
 Originally Posted by Elroy
Basically, to my eyes reexre, you're admitting to "hacking", even if you did write the original code. Personally, I don't think there's ever a good reason to modify a compiled executable. And there are just too many other paths/ways to store persistent data. Also, I would actually hope that altering executables would flag warnings in virus scanners. But, that's just all my opinion.
Anything that's not piracy, multiplayer cheating, or to help a crime is a fine reason to modify an executable. Hack it up!
-
May 12th, 2020, 03:02 PM
#7
Re: How to change resource file data of an executable?
I'd go with what the trick has suggested - these APIs are pretty simple to use...(only about 15-20 lines of VB-Code) -
am using this quite often, to change Manifests or Icons in a post-compile-step.
Olaf
-
May 13th, 2020, 02:41 PM
#8
Re: How to change resource file data of an executable?
 Originally Posted by Schmidt
I'd go with what the trick has suggested - these APIs are pretty simple to use...(only about 15-20 lines of VB-Code) -
am using this quite often, to change Manifests or Icons in a post-compile-step.
Olaf
Hi
could you post an example or a link about how to change a PNG image in resources enbedded in an EXE ?
It would be of great help.
EDIT
I tried this but it add ... do not replace:
Code:
Public Declare Function BeginUpdateResource Lib "KERNEL32" Alias "BeginUpdateResourceA" _
(ByVal pFileName As String, ByVal bDeleteExistingResources As Long) As Long
Public Declare Function UpdateResource Lib "KERNEL32" Alias "UpdateResourceA" _
(ByVal hUpdate As Long, ByVal lpType As String, ByVal lpName As String, ByVal wLanguage As Long, lpData As Byte, ByVal cbData As Long) As Long
Public Declare Function EndUpdateResource Lib "KERNEL32" Alias "EndUpdateResourceA" _
(ByVal hUpdate As Long, ByVal fDiscard As Long) As Long
Code:
Dim FileHandle As Long
Dim ResData As String
Dim ResByte() As Byte
ResData = "Test Data"
ResByte() = StrConv(ResData, vbFromUnicode)
FileHandle = BeginUpdateResource(App.Path & "\......exe", False)
UpdateResource FileHandle, "CUSTOM", "101 : 1040", 0, ResByte(0), Len(ResData)
EndUpdateResource FileHandle, 0
Last edited by reexre; May 13th, 2020 at 03:27 PM.
-
May 13th, 2020, 03:05 PM
#9
Re: [RESOLVED] How to change resource file data of an executable?
i put a dll file into vb6 abc.res file,and a 123.xls in abc.res.
make for project1.exe.
how to change the "dll file",and "xls file" on project1.exe?
i used for memory load dll ,and run dll,call dllmain,and api list in dll.
Other people should have no way to remove this DLL file from the EXE resources?
-
May 14th, 2020, 02:59 PM
#10
Re: How to change resource file data of an executable?
 Originally Posted by reexre
Hi
could you post an example or a link about how to change a PNG image in resources enbedded in an EXE ?
EDIT
I tried this but it add ... do not replace:
For replacements to work, you'll have to put the "SubIDs" in as a Long-Value.
It's easier to do with the W-versions of that API, since the String-Params *are* already defined as Long...
Here is an example:
Code:
Option Explicit
Private Declare Function BeginUpdateResourceW Lib "kernel32" (ByVal pFileName As Long, ByVal bDeleteExistingResources As Long) As Long
Private Declare Function UpdateResourceW Lib "kernel32" (ByVal ResHdl As Long, ByVal pTypeOrID As Long, ByVal pNameOrID As Long, ByVal wLanguage As Long, ByVal lpData As Long, ByVal cbData As Long) As Long
Private Declare Function EndUpdateResourceW Lib "kernel32" (ByVal ResHdl As Long, ByVal fDiscard As Long) As Long
Private Sub Form_Load() 'please compile this Project first, before running it in the IDE
If App.LogMode = 0 Then 'we run in the IDE... let's write the resource to the Executable-File
Const PathToExecutable As String = "c:\temp\MyResTest.exe" 'as said, please make sure you've compiled it to this name and place
Caption = WriteResData(101, "CUSTOM", "Some Test-Data abc-123", PathToExecutable) 'data can alternatively passed also as ByteArray
' UpdateManifestData "<xml>...</xml>", PathToExecutable
' RemoveManifestData PathToExecutable
Else 'we run compiled, let's try to read out what we've written above
On Error GoTo 1
Dim B() As Byte
B = LoadResData(101, "CUSTOM")
Caption = StrConv(B, vbUnicode)
1 If Err Then Caption = Err.Description
End If
End Sub
Function WriteResData(ByVal ResSubID As Long, ResTypeOrID, BytesOrString, FileNameToExeOrDll As String, Optional ByVal LCID As Long) As Boolean
Dim ResTyp As Long: ResTyp = IIf(VarType(ResTypeOrID) = vbString, StrPtr(ResTypeOrID), ResTypeOrID)
Dim Data() As Byte: Data = IIf(IsArray(BytesOrString), BytesOrString, StrConv(BytesOrString, vbFromUnicode))
Dim LenDat As Long: LenDat = UBound(Data) - LBound(Data) + 1
Dim lpData As Long: If LenDat Then lpData = VarPtr(Data(LBound(Data)))
Dim ResHdl As Long: ResHdl = BeginUpdateResourceW(StrPtr(FileNameToExeOrDll), 0)
If ResHdl Then
On Error GoTo 1
Call UpdateResourceW(ResHdl, ResTyp, ResSubID, LCID, lpData, LenDat)
1 WriteResData = EndUpdateResourceW(ResHdl, IIf(Err, 1, 0))
End If
End Function
Function UpdateManifestData(sManifestContent As String, FileNameToExeOrDll As String) As Boolean
Dim IsExe As Boolean: IsExe = LCase$(Right$(FileNameToExeOrDll, 4)) = ".exe"
Const RT_MANIFEST As Long = 24
UpdateManifestData = WriteResData(IIf(IsExe, 1, 2), RT_MANIFEST, sManifestContent, FileNameToExeOrDll, 1033)
End Function
Function RemoveManifestData(FileNameToExeOrDll As String) As Boolean
RemoveManifestData = UpdateManifestData("", FileNameToExeOrDll)
End Function
The above "workhorse-function" (WriteResData) is not that long - and most of it is "Parameter-Preparation".
It is generic - meaning you can use it as a convenience-function, to write any resource-type
(as shown in the two "derived functions" UpdateManifestData() and RemoveManifestData()).
HTH
Olaf
-
May 21st, 2020, 05:04 PM
#11
Re: [RESOLVED] How to change resource file data of an executable?
Olaf
It do not work for replacing PNG resource.
At then Beginnig I have a PNG in CUSTOM -> 101 -> 1040
and calling "WriteResData" using some Bytes I have both
CUSTOM -> 101 -> 1040
CUSTOM -> 101 -> 0 ( the new one)
-
May 21st, 2020, 08:06 PM
#12
Re: [RESOLVED] How to change resource file data of an executable?
 Originally Posted by reexre
Olaf
It do not work for replacing PNG resource.
At then Beginnig I have a PNG in CUSTOM -> 101 -> 1040
and calling "WriteResData" using some Bytes I have both
CUSTOM -> 101 -> 1040
CUSTOM -> 101 -> 0 ( the new one)
Then just do not place that custom-resource (via VB6-res-file, I assume) in the new compiled executable.
That way (when you leave the new compiled exe virginal), the adding of the resource via WriteResData will happen (by default, when the optional Paral was left empty) with LCID=0 ... ensuring the first entry under that LCID...
And later, when you want to overwrite (the existing entry at LCID=0) you will change the PNG-resource (at the same LCID-position) to something else (again using only the WriteResData-routine, with the default LCID=0).
That's working for me without problems, since I never place resources in the compiled Exe via the builtin VB6-mechanism.
-----------------------------------------
Alternatively, you could determine your current LCID on the machine you're running your IDE
(there's APIs for that, which should give you the 1040 for your current italian locale) -
and then pass this pre-determined LCID as the last (Optional) param into the WriteResData-routine.
That way, you'd overwrite the existing VB6-resource (which apparently used the same LCID of the current locale in any fresh compiler-run beforehand).
HTH
Olaf
Last edited by Schmidt; May 21st, 2020 at 08:12 PM.
-
May 26th, 2020, 02:59 PM
#13
Re: [RESOLVED] How to change resource file data of an executable?
 Originally Posted by Schmidt
-----------------------------------------
Alternatively, you could determine your current LCID on the machine you're running your IDE
(there's APIs for that, which should give you the 1040 for your current italian locale) -
and then pass this pre-determined LCID as the last (Optional) param into the WriteResData-routine.
That way, you'd overwrite the existing VB6-resource (which apparently used the same LCID of the current locale in any fresh compiler-run beforehand).
HTH
Olaf
Thank you!!! it works: overwrite the existing VB6-resource (which apparently used the same LCID of the current locale in any fresh compiler-run beforehand).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|