As the title....
How can i include the icons , version information, description, and so in my program when compiling?
(Solved thanks :bg)
All help is appreaciated~
Regards, John
In concept those are the steps:
1)Define them as resources in a resource script named "rsrc.rc"
2)compile the script with rc.exe and convert to curent machine by cvtres
\masm32\bin\rc /v rsrc.rc
\masm32\bin\cvtres /machine:ix86 rsrc.res
3)link your executable including the compiled resources
\masm32\bin\Link /SUBSYSTEM:WINDOWS /OPT:NOREF "my_app.obj" rsrc.obj
The result is a executable "my_app.exe" with icons, version information, dialogs, accelerators, strings, and other resources in a separated section of the PE.
Hello,
+++ here a sample ++++++++ copy it in the .rc
If you are not sure of wich code to put for language see doc or find an extractor of resources,some very good can be found for free,and extract one with the good language code
-------- to be fill as you want.
This one for example
http://www.angusj.com/resourcehacker/
Quote
#define IDR_VERSION1 1
#define VS_FFI_FILEFLAGSMASK 0x0000003FL
#define VS_FF_PRERELEASE 0x00000002L
#define VOS_DOS_WINDOWS32 0x00010004L
#define VOS_NT_WINDOWS32 0x00040004L
#define VFT_APP 0x00000001L
IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
FILEVERSION 00,25,05,2005 --------
PRODUCTVERSION 00,25,05,2005 --------
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEFLAGS VS_FF_PRERELEASE
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE 0 // not used
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040C04E4" //Block: language ID = French, char set = Windows, Multilingual
BEGIN
VALUE "CompanyName", "-----------\0"
VALUE "FileDescription", "-----------\0"
VALUE "FileVersion", "------------\0"
VALUE "InternalName", "--------\0"
VALUE "OriginalFilename", "--------------\0"
VALUE "ProductName", "--------------\0"
VALUE "ProductVersion", "---------\0"
VALUE "Comments", "-----------------------/\0"
VALUE "LegalCopyright", "----------------------\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x040C, 1252
END
END
Many thanks to you helpful guys :bg
One last question...
i followed a example source code by Mob ,which is noimport...its included in masm package..
I tried to call RegCreateKey by
lea eax,[Ebp+offset hkHandle]
push eax
lea eax,[Ebp+szReg]
push eax
push HKEY_LOCAL_MACHINE
Call [Ebp+_RegCreateKey]
the hkHandle and szReg is declared in .data ;the RegCreateKey is declared too..
___Kernel32 db 14,"GetProcAddress"
_Getprocaddress dd 0
db 11,"LoadLibrary"
_Loadlibrary dd 0
db 11,"ExitProcess"
_Exitprocess dd 0
db 12,"RegOpenKeyEx"
_RegOpenKeyEx dd 0
db 12,"RegCreateKey"
_RegCreateKey dd 0
db 10,"RegOpenKey"
_RegOpenKey dd 0
db 13,"RegSetValueEx"
_RegSetValueEx dd 0
The program compiles fine but crashes when it reaches the regcreatekey
I have attached the original noimport .asm with my modifications inside(cut and pasted from my code).. it doesnt compiles coz i did not add the windows header
Could anyone look inside and tell me whats wrong with my code? i usually use invoke but i had to use call here.
Sorry for the messy explaination but im really sleepy now....
[attachment deleted by admin]
you are aware that executables with no imports dont work in xp or higher (maybe 2k too, cant remember) ?
And please explain the reason WHY you want to create an executable with no imports?
0.0 evlncrn8 the original noimport file worked perfectly in vista?
BogdanOntanu
As im learning assembly (started about last week), i would like to learn about it in every aspect...a importless exe seems more compact with one with imports and its more flexible(in a way that it is more portable).
Hello,
The noimport works with XP.
The sample here,show it.
The noimport is not granted to work in any systeme but it is a good exercice for using dll dynamically.
It's a french sample with it's execute.
I don't refind the english one that i have posted.
[attachment deleted by admin]
The program you posted stops working in vista..guess its because of the usage of hex codes(could be?) to identify the function address ... after staring at my programfor like 2 hours i can wager that the problem lies with the calling of the function..surprisingly this works
push MB_ICONSTOP
lea eax,[ebp+szErrCaption]
push eax
lea eax,[ebp+szErrMsg]
push eax
push NULL
Call [Ebp+_MessageBox] ; messagebox
Regards,John
After some extensive searching in this forum, i found one No Import example by thomas interesting I found the "Windows w/o imports post"[url]http://www.masm32.com/board/index.php?topic=1301.msg9627#msg9627 (http://www.masm32.com/board/index.php?topic=1301.msg9627#msg9627) interesting..[/url]. The post seems kinda old so i did not ask there..
:edit
I found another post about noimport by Vortex
http://www.masm32.com/board/index.php?topic=2192.0
His way of loading libs is interesting , but the programs in the samples crashes in vista..
Here is the entire source of the program. The only thing i do not understand is about the macros used. Why does a seemingly random number( :bg sorry but im a noob) is used in it?(in this case the 2)
LoadCursor textequ <2,OFFSET FunctionADDRs+16>
.386 ; 386 32-bit mode
.model flat,stdcall ; Flat memory model, STDCALL convention
option casemap:none ; Case Sensitive
; Import only windows.inc and kernel32.lib to avoid clashes
include windows.inc
includelib kernel32.lib
; Function ProtoTypes
WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
InvokePtr PROTO C :DWORD,:DWORD,:VARARG
GetAPIByName PROTO :DWORD,:DWORD
InitAPI PROTO :DWORD
ExitProcess PROTO :DWORD
.const
; Define macros for easy callig of functions
GetModuleHandle textequ <1,OFFSET FunctionADDRs+00>
LoadLibrary textequ <1,OFFSET FunctionADDRs+04>
;ExitProcess textequ <1,OFFSET FunctionADDRs+08>
LoadIcon textequ <2,OFFSET FunctionADDRs+12>
LoadCursor textequ <2,OFFSET FunctionADDRs+16>
RegisterClassEx textequ <1,OFFSET FunctionADDRs+20>
CreateWindowEx textequ <12,OFFSET FunctionADDRs+24>
ShowWindow textequ <2,OFFSET FunctionADDRs+28>
UpdateWindow textequ <1,OFFSET FunctionADDRs+32>
GetMessage textequ <4,OFFSET FunctionADDRs+36>
TranslateMessage textequ <1,OFFSET FunctionADDRs+40>
DispatchMessage textequ <1,OFFSET FunctionADDRs+44>
BeginPaint textequ <2,OFFSET FunctionADDRs+48>
GetSysColor textequ <1,OFFSET FunctionADDRs+52>
EndPaint textequ <2,OFFSET FunctionADDRs+56>
PostQuitMessage textequ <1,OFFSET FunctionADDRs+60>
DefWindowProc textequ <4,OFFSET FunctionADDRs+64>
SetBkColor textequ <2,OFFSET FunctionADDRs+68>
TextOut textequ <5,OFFSET FunctionADDRs+72>
; Macro for calling functions
$invoke textequ <invoke InvokePtr,>
.data
AppName db "No Import Window",0
ClassName db "NoImportClass",0
Message db "This window program doesn't use an import table!!",0
MsgLen equ $-Message-1
szUser32 db "user32.dll",0
szGdi32 db "gdi32.dll",0
; List of functions
; Functions in Kernel32.dll
Function01 db "GetModuleHandleA",0
Function02 db "LoadLibraryA",0
Function03 db "ExitProcess",0
; Functions in User32.dll
Function04 db "LoadIconA",0
Function05 db "LoadCursorA",0
Function06 db "RegisterClassExA",0
Function07 db "CreateWindowExA",0
Function08 db "ShowWindow",0
Function09 db "UpdateWindow",0
Function10 db "GetMessageA",0
Function11 db "TranslateMessage",0
Function12 db "DispatchMessageA",0
Function13 db "BeginPaint",0
Function14 db "GetSysColor",0
Function15 db "EndPaint",0
Function16 db "PostQuitMessage",0
Function17 db "DefWindowProcA",0
; Functions in Gdi32.dll
Function18 db "SetBkColor",0
Function19 db "TextOutA",0
ALIGN 4 ; Aling above strings to DWORD boundry
; List of addresses of function names
FunctionNames dd OFFSET Function01
dd OFFSET Function02
dd OFFSET Function03
dd OFFSET Function04
dd OFFSET Function05
dd OFFSET Function06
dd OFFSET Function07
dd OFFSET Function08
dd OFFSET Function09
dd OFFSET Function10
dd OFFSET Function11
dd OFFSET Function12
dd OFFSET Function13
dd OFFSET Function14
dd OFFSET Function15
dd OFFSET Function16
dd OFFSET Function17
dd OFFSET Function18
dd OFFSET Function19
dd 0
; Array to hold function addresses
FunctionADDRs dd 20 dup(0)
.data?
hInstance HINSTANCE ?
.code
start:
invoke InitAPI,[esp]
$invoke GetModuleHandle,0
mov hInstance,eax
xor edx,edx
invoke WinMain,eax,edx,edx,SW_SHOW
invoke ExitProcess,0
ret
WinMain proc uses ebx hInst:DWORD,hPrevInst:DWORD,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
lea ebx,wc
mov [ebx.WNDCLASSEX.cbSize],SIZEOF WNDCLASSEX
mov [ebx.WNDCLASSEX.style],CS_VREDRAW+CS_HREDRAW
mov [ebx.WNDCLASSEX.lpfnWndProc],OFFSET WndProc
mov [ebx.WNDCLASSEX.cbClsExtra],0
mov [ebx.WNDCLASSEX.cbWndExtra],0
mov eax,hInst
mov [ebx.WNDCLASSEX.hInstance],eax
$invoke LoadIcon,0,IDI_APPLICATION
mov [ebx.WNDCLASSEX.hIcon],eax
mov [ebx.WNDCLASSEX.hIconSm],eax
$invoke LoadCursor,0,IDC_ARROW
mov [ebx.WNDCLASSEX.hCursor],eax
mov [ebx.WNDCLASSEX.hbrBackground],COLOR_BACKGROUND+10
mov [ebx.WNDCLASSEX.lpszMenuName],0
mov [ebx.WNDCLASSEX.lpszClassName],OFFSET ClassName
$invoke RegisterClassEx,ebx
$invoke CreateWindowEx,0,ADDR ClassName,ADDR AppName,WS_OVERLAPPEDWINDOW+WS_VISIBLE,150,100,500,300,0,0,hInst,0
.if !eax
xor eax,eax
sub eax,1
ret
.endif
$invoke ShowWindow,eax,CmdShow
$invoke UpdateWindow,hwnd
.WHILE TRUE
$invoke GetMessage,ADDR msg,0,0,0
.BREAK .IF(!eax)
$invoke TranslateMessage,ADDR msg
$invoke DispatchMessage,ADDR msg
.ENDW
mov eax,msg.wParam
Ret
WinMain EndP
WndProc proc uses ebx hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL ps:PAINTSTRUCT
.IF uMsg==WM_PAINT
$invoke BeginPaint,hWnd,ADDR ps
mov ebx,eax
$invoke GetSysColor,COLOR_BACKGROUND+10
$invoke SetBkColor,ebx,eax
$invoke TextOut,ebx,100,120,ADDR Message,MsgLen
$invoke EndPaint,hWnd,ADDR ps
.ELSEIF uMsg==WM_DESTROY
$invoke PostQuitMessage,0
.ELSE
$invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
mov eax,TRUE
Ret
WndProc EndP
InitAPI proc pKernel:DWORD
mov eax,pKernel ; get the return address of program
and eax,0FFFFFF00h
add eax,4 ; search for 'PE'
@@: sub eax,4
cmp dword ptr[eax],00004550h ; Check for 'PE'
jnz @B
mov ebx,eax ; Take high 16bits to
and ebx,0FFFF0000h ; Get Imagebase
mov ecx,3 ; no. of functions to import
mov esi,OFFSET FunctionNames ; function names
mov edi,OFFSET FunctionADDRs ; function address array
@@:
invoke GetAPIByName,ebx,[esi] ; get APIS for kernel32.dll
mov [edi],eax ; save API address
add edi,4 ; next element in array
add esi,4 ; next element in array
dec ecx ; decrement counter
jnz @B
$invoke LoadLibrary,ADDR szUser32;load User32.dll
mov ebx,eax ;
mov ecx,14 ; no. of functions to import
mov esi,OFFSET FunctionNames+12
mov edi,OFFSET FunctionADDRs+12
@@:
invoke GetAPIByName,ebx,[esi]
mov [edi],eax
add edi,4
add esi,4
dec ecx
jnz @B
$invoke LoadLibrary,ADDR szGdi32
mov ebx,eax
mov ecx,2
mov esi,OFFSET FunctionNames+68
mov edi,OFFSET FunctionADDRs+68
@@:
invoke GetAPIByName,ebx,[esi]
mov [edi],eax
add edi,4
add esi,4
dec ecx
jnz @B
Ret
InitAPI EndP
GetAPIByName proc uses ebx ecx esi edi pImgBase:DWORD,pName:DWORD
LOCAL exportDir:DWORD
LOCAL count:DWORD
mov eax,pImgBase ; get image base of DLL
mov ecx,eax ; save in ecx and eax
mov ebx,eax
add eax,[eax+3Ch] ; Jump over DOS Header
add eax,78h ; Jump to PE Data Directory
mov eax,[eax]
test eax,eax
je @bad
add eax,ebx ; add ImgBase to RVA
mov edx,[eax.IMAGE_EXPORT_DIRECTORY.AddressOfNames]
mov ebx,eax ; add ImgBase to RVA of list of names
mov eax,[ebx.IMAGE_EXPORT_DIRECTORY.NumberOfNames]
mov count,eax ; get number of functions in DLL
; ebx points to IMAGE_EXPORT_DIRECTORY
mov exportDir,ebx ; save it
@findname:
mov esi,[edx+ecx] ; get RVA of function name
mov edi,pName ; address name to search for in edi
@@:
mov al,[esi+ecx] ; compare each byte
cmp al,[edi] ; goto next name in DLL
jnz @nextname ; if not matching
add esi,1 ; next byte and next....
add edi,1 ;
test al,al ; till we reach end
jne @B ; of string
; Found the name
mov ebx,exportDir ; get export table pointer saved on stack
sub edx,[ebx.IMAGE_EXPORT_DIRECTORY.AddressOfNames] ; get index in edx
mov eax,[ebx.IMAGE_EXPORT_DIRECTORY.AddressOfNameOrdinals]
add eax,ecx ; add imagebase to get address to ordinals
shr edx,1 ; divide by two to get ordinal index
movzx eax,word ptr[edx+eax]; get ordinal to use as index to functions
mov edx,[ebx.IMAGE_EXPORT_DIRECTORY.AddressOfFunctions]
add edx,ecx ; add image base
mov eax,[eax*4+edx]; use ordinal as index to get function address
add eax,ecx ; add imagebase to RVA to get actual address
jmp @done
@nextname:
add edx,4 ; next function in DLL
dec count ; decrment counter
jne @findname ; exit if no more functions in DLL
@bad:
xor eax,eax
@done:
ret
GetAPIByName endp
InvokePtr proc C nParams:DWORD,pFunc:DWORD,params:VARARG
mov ecx,nParams ; get no. of params
test ecx,ecx ; don't push if no param
jz @1 ;
dec ecx ;
@@:
push params[ecx*4] ; push params in the
dec ecx ; right order
test ecx,ecx ; till all params are
jge @B ; over
@1:
mov eax,pFunc ; get function index
mov eax,[eax] ; get address from array
call eax ; call it
Ret
InvokePtr EndP
end start
I get it now -.- ..thats the number of params passed in the function LOL :boohoo:..~thx anyway :toothy