Hi all...
Is there a way add file,string or data to exsisting standalone exe?
I find one example on net but looks strange for me.
Example is very old but is interesting.
-----------------------------------------------------
QB CULT MAGAZINE
Issue #9 - February 2001
Appending Data To Your .EXEs
By Chris Charabaruk
He say this:
The executable header type, in QuickBasic, would look as so:
TYPE EXEHEADER
exSignature AS INTEGER
exExtraBytes AS INTEGER ' Number of bytes in last page.
exPages AS INTEGER ' Number of whole and part pages.
exRelocItems AS INTEGER
exHeaderSize AS INTEGER
exMinAlloc AS INTEGER
exMaxAlloc AS INTEGER
exInitSS AS INTEGER
exInitSP AS INTEGER
exCheckSum AS INTEGER
exInitIP AS INTEGER
exInitCS AS INTEGER
exRelocTable AS INTEGER
exOverlay AS INTEGER
END TYPE
The two entries exExtraBytes and exPages let you find where the end of executable code is, and where dataspace begins, using this formula:
IF exeheadblock.exPages MOD 512 <> 0 THEN
size = exeheadblock.exPages * 512& - (512& - exeheadblock.exExtraBytes)
ELSE ' If no partial pages then execute the ELSE statement.
size = exeheadblock.exPages * 512&
END IF
Note that exeheadblock is of type EXEHEADER. We extract the header from the program with this juicy tidbit of code:
DIM exeheadblock AS EXEHEADER
OPEN "test.exe" FOR BINARY AS #1
GET #1, , exeheadblock ' This puts the executable header in
' to the structure exeheadblock.
I know that exe file hes MZ header wich is for DOS and PE header wich is for window app.
Maby i'm wrong?
Is there a way to do something similiar in Creative Basic?
What i wannt?
I wannt add for example string or Istring to existing EXE wich can be executed with this exe or
with this program not compile or recompile existing exe.
My knowlege about this is small.
I think that this file or string must be first converted to binary or maby not, i dont know.
If is posibile ,that would be great stuff.
What you mean?
regards
zlatko
http://www.codingmonkeys.com/index.php?topic=558.0
Larry
Wrong Larry! I say about adding to exe and you give link to
Joske example How extract resource from exe.
But however thanks for link.
Any other ideas?
Resource could be an exe file.
And to extract it you have to be able to add it.
Larry
Zlatko, I don't think it is possible in Creative without additional helpers, because
* there are api's to update resources (like UpdateResource). But first, you'll need to extract all resources with same type. To do it, you should provide a callback function for EnumResourceNames api.
The api UpdateResource does not just add, it removes any existing resource with given type.
So, you can:
1. use a helper dll to extract resources, then use the api's to update your exe (example) (http://msdn.microsoft.com/en-us/library/ms648008(VS.85).aspx#_win32_Updating_Resources).
2. stay with Creative, and parse all the exe headers to extract and update resources. You'll need to learn the PE format.
3. download ResHacker freeware to do it.
Yes Sapero you right.Complicated stuff.Learn PE format uff...
I find this example written by Copex in Ibpro archive look:
'Add resource to EXE
'code by Copex
'Ibasic professional
/*
This is unfinshed !! API requires the nt5 kernal so
'you must be running win xp or 2k for the code to work...
Ok what the code dose is add a resource to a executable file,
not all of the code is required to add a resource but i was going to
add the ability to change resources as well....
how to test, get a smal zip file and copy it to C then rename an executable
file to test.exe and copy it to C:\, compile and run the code below,
now if you use a Resource editor "Reshacker http://www.devhood.com/Tools/tool_details.aspx?tool_id=420
or http://www.angusj.com/resourcehacker/ " you will see the zip file has been
added to the exe file RT_RCDATA/store_data...
for more infomation on resource see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/WindowsUserInterface/Resources/IntroductiontoResources.asp
*/
DECLARE IMPORT, _FindResource ALIAS FindResourceA(hInstance AS INT,lpName AS POINTER,lpType AS POINTER),INT
DECLARE IMPORT, _FindResourceEx ALIAS FindResourceExA(hModule AS INT,lpType AS POINTER,lpName AS POINTER,wLanguage AS INT),INT
DECLARE IMPORT, _BeginUpdateResource ALIAS BeginUpdateResourceA(pFileName AS STRING,bDeleteExistingResources AS INT),INT
DECLARE IMPORT, _UpdateResource ALIAS UpdateResourceA(hUpdate AS INT,lpType AS POINTER,lpName AS POINTER,wLanguage AS INT,lpData AS POINTER,cbData AS INT),INT
DECLARE IMPORT, _EndUpdateResource ALIAS EndUpdateResourceA(hUpdate AS INT,fDiscard AS INT),INT
DECLARE IMPORT, _LoadResource ALIAS LoadResource(hInstance AS INT,hResInfo AS INT),INT
DECLARE IMPORT, _LockResource ALIAS LockResource(hResData AS INT),INT
DECLARE IMPORT, _SizeofResource ALIAS SizeofResource(hInstance AS INT,hResInfo AS INT),INT
DECLARE MAKEINTRESOURCE(n as WORD),POINTER
declare "kernel32",GetLastError(),INT
DECLARE "kernel32",FormatMessage Alias FormatMessageA(dwFlags:INT, lpSource:INT, dwMessageId:INT, dwLanguageId:INT, lpBuffer:STRING, nSize:INT, Arguments:INT),INT
CONST FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x100
CONST FORMAT_MESSAGE_IGNORE_INSERTS = 0x200
CONST FORMAT_MESSAGE_FROM_STRING = 0x400
CONST FORMAT_MESSAGE_FROM_HMODULE = 0x800
CONST FORMAT_MESSAGE_FROM_SYSTEM = 0x1000
CONST FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x2000
CONST FORMAT_MESSAGE_MAX_WIDTH_MASK = 0xFF
const SUBLANG_DEFAULT =0x01
const LANG_NEUTRAL =0x00
openconsole
def bf:bfile
def m:memory
def tmp:pointer
def hResource,ret:int
t = "store_data"
tmp = t
openfile(bf,getstartpath+"test.txt", "R") /* File to add as a resource */
allocmem(m,len(bf),1)
read(bf,m)
'openfile(bf,"C:\\bug1tmp.exe", "w")
' write bf,m
'closefile bf
hResource = _BeginUpdateResource(getstartpath+"test.exe", FALSE)/* EXE file rosource to be added to....*/
print hResource
ret = _UpdateResource(hResource,"RT_RCDATA",tmp,4,m,len(bf))
' UpdateResource(hExe, RT_RCDATA, PChar('MYDATA'), 4, ms, ms.Size)
print ret
if ret = 0 then error()
ret = _EndUpdateResource(hResource, FALSE)
print ret
'_waitkey
do: until inkey$<>""
closefile bf
freemem m
closeconsole
end
SUB MAKEINTRESOURCE(n as WORD),POINTER
DEF pReturn as POINTER
_asm
lea eax,[ebp-4]
mov ebx,[ebp+8]
mov [eax],ebx
_endasm
RETURN pReturn
ENDSUB
SUB error()
CONST MB_ICONINFORMATION = &H40
DEF CodeErrorId:INT
DEF nBufferSize:INT
DEF flag:INT
DEF sBuffer:STRING
nBufferSize = 1024
sBuffer = String$(nBufferSize, Chr$(0))
flag=FORMAT_MESSAGE_FROM_SYSTEM
CodeErrorId=GetLastError()
FormatMessage(flag, NULL,CodeErrorId,LANG_NEUTRAL, sBuffer, nBufferSize ,NULL )
print "Error := ",sBuffer,"Error Code := ",MB_ICONINFORMATION
RETURN
endsub
What you mean about this?
Is this something?