AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Compile_AHK II - for those who compile!
Goto page Previous  1, 2, 3 ... 18, 19, 20
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Yook



Joined: 20 Nov 2008
Posts: 56
Location: Thionville, France

PostPosted: Fri Dec 18, 2009 6:04 am    Post subject: Reply with quote

ladiko, i extracted some code from SKAN's IconEx to create an icon extraction function that will work with named resources as well. I don't exactly know how the extraction part works, but it works Razz It doesn't use ResHacker and it seems it performs faster.
Code:
IconExtract(Res, Nb = 0, Out = "") ;Resource file, resource number [0..N], Output file
{
   Global _IconGroups_, _IconGroupsCount_
   Static CallB
   If !CallB
      CallB := RegisterCallback( "EnumResNameProc" )
   Nb:=Nb+1
   If (Out = "")
      Out := A_WorkingDir "\Icon_1.ico"
   Loop, %Res%
   {
      If (A_LoopFileExt = "ICO")
      {
         FileCopy, %Res%, %Out%, 1
         If !ErrorLevel
            Return 1
         Else
            Return
      }
      If A_LoopFileExt Not in EXE,DLL,CPL,SCR
         Return
      hModule := DllCall( "LoadLibraryEx", Str,A_LoopFileLongPath, UInt,0, UInt,0x2 )
      IfEqual,hModule,0,Return
      _IconGroupsCount_:=0, _IconGroups_ := ""
      DllCall("EnumResourceNamesA", UInt,hModule, UInt,14, UInt,CallB, UInt,0 )
      DllCall( "FreeLibrary", UInt,hModule )
      IfEqual,_IconGroupsCount_,0, Continue
      SplitPath, Res,, Res
      hModule := DllCall( "LoadLibraryEx", Str,Res "\" DllCall( "CharUpperA", Str,A_LoopFileName, Str ), UInt,0, UInt,0x2 )
   }
   Loop, Parse, _IconGroups_, |
   {
      If (A_Index > Nb)
         Break
      If (A_Index != Nb)
         Continue
      IconGroup := A_LoopField
      hFile := DllCall( "_lcreat", Str,Out, UInt,0 )
      sBuff := GetResource( hModule, IconGroup, (RT_GROUP_ICON:=14), nSize, hResData )
      Icons := NumGet( sBuff+0, 4, "UShort" )
      tSize := nSize+( Icons*2 ), VarSetCapacity( tmpBuff,tSize, 0 ), tBuff := &tmpBuff
      CopyData( sBuff, tBuff, 6  ),   sBuff:=sBuff+06,  tBuff:=tBuff+06
      Loop %Icons%
         CopyData( sBuff, tBuff, 14  ),  sBuff:=sBuff+14,  tBuff:=tBuff+16
      DllCall( "FreeResource", UInt,hResData )
      DllCall( "_lwrite", UInt,hFile, Str,tmpBuff, UInt,tSize )
      EOF := DllCall( "_llseek", UInt,hFile, UInt,-0, UInt,2 )
      VarSetCapacity( tmpBuff, 0 )
      DataOffset := DllCall( "_llseek", UInt,hFile, UInt,18, UInt,0 )
      Loop %Icons%
      {
         VarSetCapacity( Data,4,0 )
         DllCall( "_lread", UInt,hFile, Str,Data, UInt,2 )
         nID := NumGet( Data, 0, "UShort" )
         DllCall( "_llseek", UInt,hFile, UInt,-2, UInt,1 )
         NumPut( EOF, Data ),  DllCall( "_lwrite", UInt,hFile, Str,Data, UInt,4 )
         DataOffset := DllCall( "_llseek", UInt,hFile, UInt,0, UInt,1 )
         sBuff := GetResource( hModule, nID, (RT_ICON:=3), nSize, hResData )   
         DllCall( "_llseek", UInt,hFile, UInt,0, UInt,2 )         
         DllCall( "_lwrite", UInt,hFile, UInt,sBuff, UInt,nSize )
         DllCall( "FreeResource", UInt,hResData )
         EOF := DllCall( "_llseek", UInt,hFile, UInt,-0, UInt,2 )
         DataOffset := DllCall( "_llseek", UInt,hFile, UInt,DataOffset+12, UInt,0 )
      } 
      DllCall( "_lclose", UInt,hFile )
   }
   DllCall( "FreeLibrary", UInt,hModule )
   If IconGroup
      Return 1
}

EnumResNameProc( hModule, lpszType, lpszName, lParam )
{
   Global _IconGroups_, _IconGroupsCount_
   _IconGroups_ .= ( ( _IconGroups_!="" ) ? "|" : "" ) . lpszName , _IconGroupsCount_:=_IconGroupsCount_+1 
   Return True
}

GetResource( hModule, rName, rType, ByRef nSize, ByRef hResData )
{
   hResource := DllCall( "FindResource", UInt,hModule, UInt,rName, UInt,rType )
   nSize     := DllCall( "SizeofResource", UInt,hModule, UInt,hResource )
   hResData  := DllCall( "LoadResource", UInt,hModule, UInt,hResource )
Return DllCall( "LockResource", UInt, hResData )
}

CopyData( SPtr, TPtr, nSize )
{
   Return DllCall( "RtlMoveMemory", UInt,TPtr, UInt,SPtr, UInt,nSize )
}


EDIT: I noticed it didn't work anymore for named icons on Win7 x64...


Last edited by Yook on Wed Dec 30, 2009 2:03 pm; edited 1 time in total
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 4459
Location: Qld, Australia

PostPosted: Fri Dec 18, 2009 8:00 am    Post subject: Reply with quote

Anonymous wrote:
Kinda limits the cosmetic options when it comes to compiled scripts then huh. Guess I'll need to find a way to work around having images in the gui. ):
I take it this means you were using file paths, not actually referencing the resources? I suggest you take a look at one or both of the following posts by SKAN: Embed images in compiled AutoHotkey scripts and How to convert Image data (JPEG/PNG/GIF) to hBITMAP.
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Fri Dec 18, 2009 7:10 pm    Post subject: Reply with quote

Lexikos wrote:
Anonymous wrote:
Kinda limits the cosmetic options when it comes to compiled scripts then huh. Guess I'll need to find a way to work around having images in the gui. ):
I take it this means you were using file paths, not actually referencing the resources? I suggest you take a look at one or both of the following posts by SKAN: Embed images in compiled AutoHotkey scripts and How to convert Image data (JPEG/PNG/GIF) to hBITMAP.


A lot of hassle for a branding watermark, is all. Thanks anyway.
Back to top
Guest2
Guest





PostPosted: Fri Dec 18, 2009 8:29 pm    Post subject: Reply with quote

pekkle wrote:
poetbox wrote:
Guest2 wrote:
Quick Question.

What are the benefits using this complier over the standard supplied compiler ?

Is the source more secure ? Faster / Smaller etc ?

Thx

you can make it smaller,add icon,add version info ,or other which you maybe like

To add to the above, you can modify Manifest for Vista Administrator Exection Level (User Account Control) easily, instead of using the "standard" compiler, which you need to change the Manifest by using Reshacker manually. Cool


Thanks for taking the time to reply !

How about encrypting the source code ? to make it harder to decode ?

Thanks again.
Back to top
pekkle



Joined: 20 Jan 2009
Posts: 9

PostPosted: Sat Dec 19, 2009 2:53 am    Post subject: Reply with quote

Guest2 wrote:
pekkle wrote:
poetbox wrote:
Guest2 wrote:
Quick Question.

What are the benefits using this complier over the standard supplied compiler ?

Is the source more secure ? Faster / Smaller etc ?

Thx

you can make it smaller,add icon,add version info ,or other which you maybe like

To add to the above, you can modify Manifest for Vista Administrator Exection Level (User Account Control) easily, instead of using the "standard" compiler, which you need to change the Manifest by using Reshacker manually. Cool


Thanks for taking the time to reply !

How about encrypting the source code ? to make it harder to decode ?

Thanks again.

For encrypting the source, I find no great benefit for using this compiler. The standard one already have that field allowing you to input the password ("N/A" to disable decompiling). However, with this compiler, you could specify the password (and version no.) to use for compiling in the source code and no need to input again everytime.
Back to top
View user's profile Send private message
mouser



Joined: 03 Oct 2008
Posts: 9

PostPosted: Mon Jan 11, 2010 3:25 am    Post subject: Reply with quote

very cool. thank you for sharing!
Back to top
View user's profile Send private message
Zaelia



Joined: 31 Oct 2008
Posts: 159
Location: France

PostPosted: Sun Jan 24, 2010 12:44 pm    Post subject: Reply with quote

It's possible to include .wav file into WAVE group, and not RCData ?

For use PlaySound easly ?
http://msdn.microsoft.com/en-us/library/aa910369.aspx

And to rename resource before compile ? not 1, 2, 3, ...
Back to top
View user's profile Send private message
Zaelia



Joined: 31 Oct 2008
Posts: 159
Location: France

PostPosted: Tue Jan 26, 2010 9:37 am    Post subject: Reply with quote

at line 2402
Code:

      } Else If s_Resources_Ext = WAV
      {
         WAVE_I++
         WAVE_I += 0.0
         
         s_Target := "WaveX , Wav" . WAVE_I . "X ,"  ;X for debug


To use:
Code:

flags := (SND_ASYNC := 0x1) | (SND_RESOURCE := 0x40004) | (SND_NODEFAULT := 0x2)
hMod := DllCall("LoadLibrary", "str", "MyApp.exe")
DllCall( "winmm.dll\PlaySoundA", Str, "WAV01", UInt, hMod, UInt, flags ) ; don't use UPX
return

escape::
DllCall("FreeLibrary", "UInt", hMod)
exitapp
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 4459
Location: Qld, Australia

PostPosted: Fri Feb 19, 2010 12:46 pm    Post subject: Reply with quote

I have a request for an option: "Compile as console application."

I think the uses are fairly obvious, but can elaborate if you need me to.

The following (somewhat rudimentary) script can be used (via Run if desired) to change the subsystem of the AutoHotkeySC.bin file before the script is compiled. Ideally it would be used to modify Compile_AHK's temporary copy of the bin file rather than the original. Using it directly on a compiled script exe invalidates its checksum and prevents the script from working.
Code:
; Args:
;   1   filename of bin/exe file to switch
;   2   subsystem, i.e. "C" (console) or "G" (gui).  if omitted, switches between the two.
ifNotExist %1%
    ExitApp -1
file = %1%
if 2 not in ,C,G
    ExitApp -1

; Define Win32 constants.
GENERIC_READ  := 0x80000000
GENERIC_WRITE := 0x40000000
OPEN_EXISTING := 0x3
IMAGE_DOS_SIGNATURE := 0x5A4D
IMAGE_NT_SIGNATURE := 0x4550
IMAGE_SIZEOF_FILE_HEADER := 20
IMAGE_SUBSYSTEM_WINDOWS_GUI := 2
IMAGE_SUBSYSTEM_WINDOWS_CUI := 3

; Open file for read/write.
hfile := DllCall("CreateFile", "str", file, "uint", GENERIC_READ|GENERIC_WRITE, "uint", 0, "uint", 0, "uint", OPEN_EXISTING, "uint", 0, "uint", 0)
if hfile = -1
    ErrorExit("CreateFile failed")

; Verify EXE signature.
e_magic := SeekNumRead(hfile, 0, "ushort")
if (e_magic != IMAGE_DOS_SIGNATURE)
    ErrorExit("Bad exe file: no DOS sig")

; Get offset of IMAGE_NT_HEADERS.
e_lfanew := SeekNumRead(hfile, 60, "int")

; Verify NT signature.
ntSignature := SeekNumRead(hfile, e_lfanew, "uint")
if (ntSignature != IMAGE_NT_SIGNATURE)
    ErrorExit("Bad exe file: no NT sig")

; Calculate offset of IMAGE_OPTIONAL_HEADER and its Subsystem field.
offset_optional_header := e_lfanew + 4 + IMAGE_SIZEOF_FILE_HEADER
offset_Subsystem := offset_optional_header + 68

; Read current subsystem.
Subsystem := SeekNumRead(hfile, offset_Subsystem, "UShort")
; Toggle subsystem (do this even if it will be overridden, to validate):
if (Subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI)
    Subsystem := IMAGE_SUBSYSTEM_WINDOWS_CUI
else if (Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI)
    Subsystem := IMAGE_SUBSYSTEM_WINDOWS_GUI
else
    ErrorExit("Bad subsystem: " Subsystem)

; Allow override on command-line:
if 2 !=  ; i.e. it is C or G
    Subsystem := IMAGE_SUBSYSTEM_WINDOWS_%2%UI

; Write new subsystem.
SeekNumWrite(Subsystem, hfile, offset_Subsystem, "UShort")

DllCall("CloseHandle", "uint", hfile)

MsgBox Changed subsystem to %Subsystem%.


; SeekNumRead: Seek to absolute offset and read a number of the specified type.
SeekNumRead(hfile, offset, type) {
    Seek(hfile, offset)
    VarSetCapacity(v,8), bytesToRead := NumPut(0,v,0,type)-&v
    if !(DllCall("ReadFile", "uint", hfile, "uint", &v, "uint", bytesToRead, "uint*", bytesRead, "uint", 0) && bytesRead == bytesToRead)
        ErrorExit("Read failed")
    return NumGet(v,0,type)
}

; SeekNumWrite: Seek to absolute offset and write a number of the specified type.
SeekNumWrite(num, hfile, offset, type) {
    Seek(hfile, offset)
    VarSetCapacity(v,8), bytesToWrite := NumPut(num,v,0,type)-&v
    if !(DllCall("WriteFile", "uint", hfile, "uint", &v, "uint", bytesToWrite, "uint*", bytesWritten, "uint", 0) && bytesWritten == bytesToWrite)
        ErrorExit("Write failed")
}

Seek(hfile, offset) {
    static FILE_BEGIN := 0
    if DllCall("SetFilePointer", "uint", hfile, "int", offset, "uint", 0, "uint", FILE_BEGIN) = -1
        ErrorExit("Seek failed")
}

ErrorExit(msg) {
    MsgBox %msg%`n  ErrorLevel=%ErrorLevel% A_LastError=%A_LastError%
    global hfile
    if (hfile != "" && hfile != -1)
        DllCall("CloseHandle", "uint", hfile)
    ExitApp
}
Back to top
View user's profile Send private message Visit poster's website
a_h_k



Joined: 02 Feb 2008
Posts: 405

PostPosted: Sat Feb 20, 2010 8:49 am    Post subject: Reply with quote

3 minor things...

1) Icons tab .. Select
Maybe should disable gui momentaritly (or at least the "Compile" button) until icon's image appears (else can get an error)

2) Have script loaded into Notepad++ (haven't edited) --> Compile with Options --> Get below message
---------------------------
Reload
---------------------------
C:\<path><filename>.ahk

This file has been modified by another program.
Do you want to reload it?
---------------------------
Yes No
---------------------------

3) The en-us tab should be "Resources" not "Ressources"
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3 ... 18, 19, 20
Page 20 of 20

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group