Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Include virtually any file in a script (exe/zip/dll/etc....)


  • Please log in to reply
49 replies to this topic
Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010

I have no issues when I extract a file twice in the same script (or any number of times) - can you paste your full script?

 

This works perfectly for me: http://pastebin.com/BrGezDag



AHK_Lee
  • Members
  • 31 posts
  • Last active: Aug 17 2014 02:16 PM
  • Joined: 13 Apr 2010

Hi Rseding91,

 

I used your new example script for testing and it will not go corrupt.

 

But If I use my file {Static 1} a not ascii? it will be corrupt.

Extract_test(A_ScriptDir "\out file 1.ahk")
Extract_Test(A_ScriptDir "\out file 2.ahk")


test_Get(_What)
{
	Static Size = 6339, Name = "Include file.ahk", Extension = "ahk", Directory = "C:\Users\reding\Dropbox\Autohotkey Projects\Store file in script"
	, Options = "Size,Name,Extension,Directory"
	;This function returns the size(in bytes), name, filename, extension or directory of the file stored depending on what you ask for.
	If (InStr("," Options ",", "," _What ","))
		Return %_What%
}

Extract_test(_Filename, _DumpData = 0)
{
	;This function "extracts" the file to the location+name you pass to it.
	Static HasData = 1, Out_Data, Ptr
	Static 1 = "AAAAAAAAAAAAAPA/AAAAAAEAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJAAAACQAAAAkAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAABAAAAAAAAAAAAgD8CAAAAAQAAAAEAAAABAAAAAQAAABdERV9NUBpJX0gXFkkFT1MgVAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAQAAAAEAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAyEIAAMhCAADIQgAAyEIHR3JhcGggOAAAAAAAAAAAAQAAAAAAAAAAAIA/AgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMhCAADIQgAAyEIAAMhC"
	
	If (!HasData)
		Return -1
	
	If (!Out_Data){
		Ptr := A_IsUnicode ? "Ptr" : "UInt"
		, VarSetCapacity(TD, 8685 * (A_IsUnicode ? 2 : 1))
		
		Loop, 1
			TD .= %A_Index%, %A_Index% := ""
		
		VarSetCapacity(Out_Data, Bytes := 6339, 0)
		, DllCall("Crypt32.dll\CryptStringToBinary" (A_IsUnicode ? "W" : "A"), Ptr, &TD, "UInt", 0, "UInt", 1, Ptr, &Out_Data, A_IsUnicode ? "UIntP" : "UInt*", Bytes, "Int", 0, "Int", 0, "CDECL Int")
		, TD := ""
	}
	
	IfExist, %_Filename%
		FileDelete, %_Filename%
	
	h := DllCall("CreateFile", Ptr, &_Filename, "Uint", 0x40000000, "Uint", 0, "UInt", 0, "UInt", 4, "Uint", 0, "UInt", 0)
	, DllCall("WriteFile", Ptr, h, Ptr, &Out_Data, "UInt", 6339, "UInt", 0, "UInt", 0)
	, DllCall("CloseHandle", Ptr, h)
	
	If (_DumpData)
		VarSetCapacity(Out_Data, 6339, 0)
		, VarSetCapacity(Out_Data, 0)
		, HasData := 0
}

I am trying various options the only thing I can find is that somehow once the static variable has been filed with my "static data" i will not assign anymore.

 

example test

#persistent
#singleinstance force

f5::
IfNotExist, dummyfile_org.dat
Extract_dummyfile("dummyfile_org.dat")

Extract_dummyfile("dummyfile_corrupt.dat")
return

f6::
reload
return

Extract_dummyfile(_Filename, _DumpData = 0)
{
	;This function "extracts" the file to the location+name you pass to it.
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AAAAAAAAAAAgD8CAAAAAQAAAAEAAAAAAAAAAAAAABxJX0MAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMhCAADIQgAAyEIAAMhCB0dyYXBoIDYAAAAAAAAAAAEAAAAAAAAAAACAPwIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADIQgAAyEIAAMhCAADIQgdHcmFwaCA3AAAAAAAAAAABAAAAAAAAAAAAgD8CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAyEIAAMhCAADIQgAAyEIHR3JhcGggOAAAAAAAAAAAAQAAAAAAAAAAAIA/AgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMhCAADIQgAAyEIAAMhC"

FileAppend,
(
1.`t%_Filename%`n`r
2.`t%_DumpData%`n`r
3.`t%HasData%`n`r
4.`t%Out_Data%`n`r
5.`t%Ptr%`n`r
6.`t%1%`n`r
7.`t%h%`n`r
8.`t%TD%`n`r
9.`t%Bytes%`n`r
`n`r
), data.txt

 


	If (!HasData)
		Return -1
	
	If (!Out_Data){
		Ptr := A_IsUnicode ? "Ptr" : "UInt"
		, VarSetCapacity(TD, 1768 * (A_IsUnicode ? 2 : 1))
		
		Loop, 1
			TD .= %A_Index%, %A_Index% := ""
		
		VarSetCapacity(Out_Data, Bytes := 1290, 0)
		, DllCall("Crypt32.dll\CryptStringToBinary" (A_IsUnicode ? "W" : "A"), Ptr, &TD, "UInt", 0, "UInt", 1, Ptr, &Out_Data, A_IsUnicode ? "UIntP" : "UInt*", Bytes, "Int", 0, "Int", 0, "CDECL Int")
		, TD := ""
	}
	
	IfExist, %_Filename%
		FileDelete, %_Filename%
	
	h := DllCall("CreateFile", Ptr, &_Filename, "Uint", 0x40000000, "Uint", 0, "UInt", 0, "UInt", 4, "Uint", 0, "UInt", 0)
	, DllCall("WriteFile", Ptr, h, Ptr, &Out_Data, "UInt", 1290, "UInt", 0, "UInt", 0)
	, DllCall("CloseHandle", Ptr, h)
	
	If (_DumpData)
		VarSetCapacity(Out_Data, 1290, 0)
		, VarSetCapacity(Out_Data, 0)
		, HasData := 0
}

I am using Beyond Compare from http://www.scootersoftware.com/ to compare.

 

In the above script the static will not be assigned anymore with data for the second time the function is called.


[quote name="Confucius ]And remember, no matter where you go, there you are.[/quote]

AHK_Lee
  • Members
  • 31 posts
  • Last active: Aug 17 2014 02:16 PM
  • Joined: 13 Apr 2010

It has something todo with the static variable.

 

It's written in the manual but can't seem to figure out for my benefit

GetFromStaticArray(WhichItemNumber)
{
    static
    static FirstCallToUs := true  ; A static declaration's initializer still runs only once (upon startup).
    if FirstCallToUs  ; Create a static array during the first call, but not on subsequent calls.
    {
        FirstCallToUs := false
        Loop 10
            StaticArray%A_Index% := "Value #" . A_Index
    }
    return StaticArray%WhichItemNumber%
}

http://www.autohotke...s/Functions.htm


[quote name="Confucius ]And remember, no matter where you go, there you are.[/quote]

AHK_Lee
  • Members
  • 31 posts
  • Last active: Aug 17 2014 02:16 PM
  • Joined: 13 Apr 2010
I think I found how to solve it.
 
I now only need to go backwards to adapt your awesome orginal include script to prevent changing every outcome file hand by hand.
 
Static 1 
1 := "..."
instead of
Static 1 = "..."
 
	
Extract_test(A_ScriptDir "\out file 1.ahk")
Extract_Test(A_ScriptDir "\out file 2.ahk")


test_Get(_What)
{
	Static Size = 6339, Name = "Include file.ahk", Extension = "ahk", Directory = "C:\Users\reding\Dropbox\Autohotkey Projects\Store file in script"
	, Options = "Size,Name,Extension,Directory"
	;This function returns the size(in bytes), name, filename, extension or directory of the file stored depending on what you ask for.
	If (InStr("," Options ",", "," _What ","))
		Return %_What%
}

Extract_test(_Filename, _DumpData = 0)
{
	;This function "extracts" the file to the location+name you pass to it.
	Static HasData = 1, Out_Data, Ptr
	Static 1 
	1 := "AAAAAAAAAAAAAPA/AAAAAAEAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJAAAACQAAAAkAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAABAAAAAAAAAAAAgD8CAAAAAQAAAAEAAAABAAAAAQAAABdERV9NUBpJX0gXFkkFT1MgVAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAADIQgAAyEIAAMhCAADIQgVUYQAAAAAAAAAAAQAAAAAAAAAAAIA/AgAAAAEAAAABAAAAAQAAAAEAAAAZSU8USR1IAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAyEIAAMhCAADIQgAAyEIHSGUAAAAAAAAAAAEAAAAAAAAAAACAPwIAAAABAAAAAQAAAAEAAAABAAAAHR5JBFAxIEgEQzIgSARDMSBIA1cgSAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAEAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAMhCAADIQgAAyEIAAMhCBXMAAAAAAAAAAAEAAAAAAAAAAACAPwIAAAABAAAAAQAAAAEAAAABAAAAHGZ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all("Crypt32.dll\CryptStringToBinary" (A_IsUnicode ? "W" : "A"), Ptr, &TD, "UInt", 0, "UInt", 1, Ptr, &Out_Data, A_IsUnicode ? "UIntP" : "UInt*", Bytes, "Int", 0, "Int", 0, "CDECL Int")
		, TD := ""
	}
	
	IfExist, %_Filename%
		FileDelete, %_Filename%
	
	h := DllCall("CreateFile", Ptr, &_Filename, "Uint", 0x40000000, "Uint", 0, "UInt", 0, "UInt", 4, "Uint", 0, "UInt", 0)
	, DllCall("WriteFile", Ptr, h, Ptr, &Out_Data, "UInt", 6339, "UInt", 0, "UInt", 0)
	, DllCall("CloseHandle", Ptr, h)
	
	If (_DumpData)
		VarSetCapacity(Out_Data, 6339, 0)
		, VarSetCapacity(Out_Data, 0)
		, HasData := 0
}

[quote name="Confucius ]And remember, no matter where you go, there you are.[/quote]

Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

can you post the result of "the adapted original include"?



AHK_Lee
  • Members
  • 31 posts
  • Last active: Aug 17 2014 02:16 PM
  • Joined: 13 Apr 2010

Herewith the adapted version;

 

;Created by Robert Eding: Rseding91[@]yahoo_c0m
;Current version 2.5+
 
;+Modified by AHK_Lee
 
All credits goes to: Robert Eding: Rseding91[@]yahoo_c0m
 
Amazing work ! Thank you !
 
SetBatchLines -1
#NoEnv
;Created by Robert Eding: [email protected]
;Current version 2.5+
;+Modified by AHK_Lee

Loop
{
	FileSelectFile, From_File,,, Select file to convert.
	
	IfNotExist, %From_File%
	{
		MsgBox, 1,, Error! invalid file.
		IfMsgBox Ok
		{
			From_File := "" 
			Continue
		}
		IfMsgBox Cancel
			ExitApp
	} else
		Break
}

InputBox, T_Function_Name, Please enter a name for the recreate function.
If (T_Function_Name = "")
	ExitApp
Extract_%T_Function_Name% = If you see this you entered a invalid function name.

E := Convert_File(From_File, T_Function_Name)

If (E)
	MsgBox Error converting file: %E%


Convert_File(_From_File, _Function_Name, _SplitLength = 16000)
{
	ST1 := A_TickCount
	, Ptr := A_IsUnicode ? "Ptr" : "UInt"
	, H := DllCall("CreateFile", Ptr, &_From_File, "UInt", 0x80000000, "UInt", 3, "UInt", 0, "UInt", 3, "UInt", 0, "UInt", 0)
	, VarSetCapacity(FileSize, 8, 0)
	, DllCall("GetFileSizeEx", Ptr, H, "Int64*", FileSize)
	, DllCall("CloseHandle", Ptr, H)
	, FileSize := FileSize = -1 ? 0 : FileSize
	
	If (!FileSize)
		Return -1
	If (_SplitLength < 65)
		_SplitLength := 65
	
	SplitPath, _From_File, F_Name, F_Directory, F_Extension
	
	Needed_Capacity := Ceil((FileSize * 1.38) + (((FileSize * 1.38) / _SplitLength) * 15) + (5 * 1024))
	, VarSetCapacity(Bin_D, A_IsUnicode ? Needed_Capacity * 2 : Needed_Capacity)
	
	, Bin_D .= _Function_Name "_Get(_What)`r`n"
	, Bin_D .= "{`r`n"
	, Bin_D .= A_Tab "Static Size = " FileSize ", Name = """ F_Name """, Extension = """ F_Extension """, Directory = """ F_Directory """`r`n"
	, Bin_D .= A_Tab ", Options = ""Size,Name,Extension,Directory""`r`n"
	, Bin_D .= A_Tab ";This function returns the size(in bytes), name, filename, extension or directory of the file stored depending on what you ask for.`r`n"
	, Bin_D .= A_Tab "If (InStr("","" Options "","", "","" _What "",""))`r`n"
	, Bin_D .= A_Tab A_Tab "Return %_What%`r`n}`r`n"
	, Bin_D .= "`r`n"
	, Bin_D .= "Extract_" _Function_Name "(_Filename, _DumpData = 0)`r`n"
	, Bin_D .= "{`r`n"
	
	, H := DllCall("CreateFile", Ptr, &_From_File, "UInt", 0x80000000, "UInt", 3, "UInt", 0, "UInt", 3, "UInt", 0, "UInt", 0)
	, VarSetCapacity(InData, FileSize, 0)
	, DllCall("ReadFile", Ptr, H, Ptr, &InData, "UInt", FileSize, "UInt*", 0, "UInt", 0)
	, DllCall("Crypt32.dll\CryptBinaryToString" (A_IsUnicode ? "W" : "A"), Ptr, &InData, UInt, FileSize, UInt, 1, UInt, 0, UIntP, Bytes, "CDECL Int")
	, VarSetCapacity(OutData, Bytes *= (A_IsUnicode ? 2 : 1))
	, DllCall("Crypt32.dll\CryptBinaryToString" (A_IsUnicode ? "W" : "A"), Ptr, &InData, UInt, FileSize, UInt, 1, Str, OutData, UIntP, Bytes, "CDECL Int")
	, ET1 := A_TickCount
	, NumPut(0, OutData, VarSetCapacity(OutData) - (A_IsUnicode ? 6 : 4), (A_IsUnicode ? "UShort" : "UChar")) ;Removes the final "`r`n" that gets auto added to the string
	, VarSetCapacity(InData, FileSize, 0)
	, VarSetCapacity(InData, 0)
	
	, Bin_D .= A_Tab ";This function ""extracts"" the file to the location+name you pass to it.`r`n"
	, Bin_D .= A_Tab "Static HasData = 1, Out_Data, Ptr`r`n"
	, N := 1, I := 0
	, Bin_D .= A_Tab "Static " N "`r`n"
	, Bin_D .= A_Tab N ++ " := """
	
	Loop, Parse, OutData, `n, `r
		If (I + 64 > _SplitLength)
			Bin_D .= """`r`n	Static " N "`r`n " A_Tab N ++ " := """, I := 0
			, Bin_D .= A_LoopField, I += 64
		Else
			Bin_D .= A_LoopField, I += 64
	
	If (I != 0)
		Bin_D .= """`r`n"
	If (N != 1)
		N --
	
	Bin_D .= A_Tab "`r`n"
	, Bin_D .= A_Tab "If (!HasData)`r`n"
	, Bin_D .= A_Tab A_Tab "Return -1`r`n"
	, Bin_D .= A_Tab "`r`n"
	, Bin_D .= A_Tab "If (!Out_Data){`r`n"
	, Bin_D .= A_Tab A_Tab "Ptr := A_IsUnicode ? ""Ptr"" : ""UInt""`r`n"
	, Bin_D .= A_Tab A_Tab ", VarSetCapacity(TD, " Ceil(FileSize * 1.37) " * (A_IsUnicode ? 2 : 1))`r`n"
	, Bin_D .= A_Tab A_Tab "`r`n"
	, Bin_D .= A_Tab A_Tab "Loop, " N "`r`n"
	, Bin_D .= A_Tab A_Tab A_Tab "TD .= %A_Index%, "
	If (_SplitLength < 4096)
		Bin_D .= "VarSetCapacity(%A_Index%, 0)`r`n"
	Else
		Bin_D .= "%A_Index% := """"`r`n"
	, Bin_D .= A_Tab A_Tab "`r`n"
	, Bin_D .= A_Tab A_Tab "VarSetCapacity(Out_Data, Bytes := " FileSize ", 0)`r`n"
	, Bin_D .= A_Tab A_Tab ", DllCall(""Crypt32.dll\CryptStringToBinary"" (A_IsUnicode ? ""W"" : ""A""), Ptr, &TD, ""UInt"", 0, ""UInt"", 1, Ptr, &Out_Data, A_IsUnicode ? ""UIntP"" : ""UInt*"", Bytes, ""Int"", 0, ""Int"", 0, ""CDECL Int"")`r`n"
	, Bin_D .= A_Tab A_Tab ", TD := """"`r`n"
	, Bin_D .= A_Tab "}`r`n"
	, Bin_D .= A_Tab "`r`n"
	, Bin_D .= A_Tab "IfExist, %_Filename%`r`n"
	, Bin_D .= A_Tab A_Tab "FileDelete, %_Filename%`r`n"
	, Bin_D .= A_Tab "`r`n"
	, Bin_D .= A_Tab "h := DllCall(""CreateFile"", Ptr, &_Filename, ""Uint"", 0x40000000, ""Uint"", 0, ""UInt"", 0, ""UInt"", 4, ""Uint"", 0, ""UInt"", 0)`r`n"
	, Bin_D .= A_Tab ", DllCall(""WriteFile"", Ptr, h, Ptr, &Out_Data, ""UInt"", " FileSize ", ""UInt"", 0, ""UInt"", 0)`r`n"
	, Bin_D .= A_Tab ", DllCall(""CloseHandle"", Ptr, h)`r`n"
	, Bin_D .= A_Tab "`r`n"
	, Bin_D .= A_Tab "If (_DumpData)`r`n"
	, Bin_D .= A_Tab A_Tab "VarSetCapacity(Out_Data, " FileSize ", 0)`r`n"
	, Bin_D .= A_Tab A_Tab ", VarSetCapacity(Out_Data, 0)`r`n"
	, Bin_D .= A_Tab A_Tab ", HasData := 0`r`n"
	, Bin_D .= "}`r`n"
	, ET2 := A_TickCount
	
	MsgBox, 0x4, Conversion Finished, % "Conversion Finished.`n`nTook " Round((ET1 - ST1)/1000, 3) " seconds to convert the file and " Round((ET2 - ET1)/1000, 3) " seconds to format the functions.`n`nWould you like to save the functions as " Function_Name ".ahk in the scripts current directory?"
	IfMsgBox, Yes
	{
		IfExist, %A_ScriptDir%\%_Function_Name%.ahk
		{
			FileExists := 1
			Msgbox, 0x4, File Already Exists,Error! %A_ScriptDir%\%_Function_Name%.ahk`n`nFile already exists. Do you want to overwrite it?
			IfMsgBox, Yes
			{
				FileDelete, %A_ScriptDir%\%_Function_Name%.ahk
				FileExists := 0
			}
		}
		
		If (!FileExists)
		{
			If A_IsUnicode
				FileAppend, %Bin_D%, *%A_ScriptDir%\%_Function_Name%.ahk, UTF-8
			Else
				FileAppend, %Bin_D%, *%A_ScriptDir%\%_Function_Name%.ahk
		}
	}
	MsgBox, 0x4, Conversion Finished, % "Conversion Finished.`n`nTook " Round((ET1 - ST1)/1000, 3) " seconds to convert the file and " Round((ET2 - ET1)/1000, 3) " seconds to format the function.`n`nWould you like to copy the functions to the clipboard?"
	IfMsgBox, Yes
		Clipboard := Bin_D
}

[quote name="Confucius ]And remember, no matter where you go, there you are.[/quote]

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010

Updated to 2.6

 

Fixed: extracting binary data twice in the same script from the same function



edik76
  • Members
  • 8 posts
  • Last active: Nov 04 2015 08:37 PM
  • Joined: 16 Jul 2012

Hi Bob,

 

Version 2.6 is working fine with AHK U32, but it doesn't work with AHK ANSI.

 

Best regards,

 

Ed



Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010

Hi Bob,

 

Version 2.6 is working fine with AHK U32, but it doesn't work with AHK ANSI.

 

Best regards,

 

Ed

 

Can you elaborate? I tested creating the .ahk and extracting the stored files (twice in the same script) with AHK Basic, AHK ANSI, AHK Unicode x32 and AHK Unicode x64. In every instance any file created with any version worked fine when used in any other version.



MontagesNmore
  • Members
  • 13 posts
  • Last active: Apr 22 2016 02:25 AM
  • Joined: 13 Nov 2013

I use the code as provided in the preivous page (code is below). However, when it extracts itself, I cannot open the file because it becomes corrupted. I also noticed I have to adjust the size of the file. The file that I am extracting is 22kb in size. I adjusted the byte size to 22000. The file that extracted itself, is provided in my script as well. (Example FileInstall, qar.exe, %A_Temp%\qar.exe, 0). Is there a work around where I can leave the Static Size default so it doesn't alter the size of the file I am extracting? Thanks!

#Persistent
#NoEnv 
#NoTrayIcon
SendMode Input 
SetWorkingDir %A_ScriptDir% 
#SingleInstance Force
;installation files
FileInstall, qar.exe, %A_Temp%\qar.exe, 0
;
Gui, Show, Center w462 h362,Extraction
Gui, Add, Button, x22 y146 w133 h93, Extract Program
; Button Actions Below 
; 
ButtonExtractProgram:
Extract_test(A_ScriptDir "\qar.exe")
 
 
 
test_Get(_What)
{
Static Size = 22000, Name = "qar.exe", Extension = "exe", Directory = "\"
, Options = "Size,Name,Extension,Directory"
;This function returns the size(in bytes), name, filename, extension or directory of the file stored depending on what you ask for.
If (InStr("," Options ",", "," _What ","))
Return %_What%
}
 
Extract_test(_Filename, _DumpData = 0)
{
;This function "extracts" the file to the location+name you pass to it.
Static HasData = 1, Out_Data, Ptr
Static 1 
1 := "AAAAAAAAAAAAAPA/AAAAAAEAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJAAAACQAAAAkAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAABAAAAAAAAAAAAgD8CAAAAAQAAAAEAAAABAAAAAQAAABdERV9NUBpJX0gXFkkFT1MgVAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAADIQgAAyEIAAMhCAADIQgVUYQAAAAAAAAAAAQAAAAAAAAAAAIA/AgAAAAEAAAABAAAAAQAAAAEAAAAZSU8USR1IAAAAAAAAAAAAAAA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AAAAAAAQAAAAAAAAAAAIA/AgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMhCAADIQgAAyEIAAMhC"
 
If (!HasData)
Return -1
 
If (!Out_Data){
Ptr := A_IsUnicode ? "Ptr" : "UInt"
, VarSetCapacity(TD, 8685 * (A_IsUnicode ? 2 : 1))
 
Loop, 1
TD .= %A_Index%, %A_Index% := ""
 
VarSetCapacity(Out_Data, Bytes := 22000, 0)
, DllCall("Crypt32.dll\CryptStringToBinary" (A_IsUnicode ? "W" : "A"), Ptr, &TD, "UInt", 0, "UInt", 1, Ptr, &Out_Data, A_IsUnicode ? "UIntP" : "UInt*", Bytes, "Int", 0, "Int", 0, "CDECL Int")
, TD := ""
}
 
IfExist, %_Filename%
FileDelete, %_Filename%
 
h := DllCall("CreateFile", Ptr, &_Filename, "Uint", 0x40000000, "Uint", 0, "UInt", 0, "UInt", 4, "Uint", 0, "UInt", 0)
, DllCall("WriteFile", Ptr, h, Ptr, &Out_Data, "UInt", 22000, "UInt", 0, "UInt", 0)
, DllCall("CloseHandle", Ptr, h)
 
If (_DumpData)
VarSetCapacity(Out_Data, 22000, 0)
, VarSetCapacity(Out_Data, 0)
, HasData := 0
}
return

 

UPDATE: I figured it out! I had to use the "Include File In Gui.ahk" THANK YOU VERY MUCH!!!! 



SuperSam
  • Members
  • 5 posts
  • Last active: Feb 05 2015 12:06 PM
  • Joined: 03 Feb 2015

Hiii

tell me image supported formts of this .ahk please



Skrell
  • Members
  • 384 posts
  • Last active: Jul 07 2016 05:03 PM
  • Joined: 23 Aug 2011

I'm probably missing something basic...but i'm trying to use this script to include wav files in my exe and when i follow these directions, NOTHING happens when i follow step #2.  I would have figured some dialog would come up asking which file i want to include?   What am i missing?:

 

1. Download and save the .ahk to a directory of your choosing.
2. Run the script
3. Select a file you want to include with your script(s)
4. Enter a name for the function you call to recreate the file (valid function names only)
5. Wait for it to do its stuff
6. Answer the questions on how you want to save the script
7. Simply include the code via #include or pasting it into your script
8. Call the function with Extract_*name* and the path/name of the file you want it to save as and it will recreate the file



dcraig91
  • Members
  • 3 posts
  • Last active: Feb 19 2015 02:31 PM
  • Joined: 08 Feb 2015

Hello i download .ahk, compile and when execute nothing

 

help me plz?



Skrell
  • Members
  • 384 posts
  • Last active: Jul 07 2016 05:03 PM
  • Joined: 23 Aug 2011

dcraig91,

Same here.  When i look inside the script i dont even see any code that would generate a popup window GUI so i'm at a loss here for how this is supposed to work.  I'm wondering if the link in the OP is to the wrong code?  There is nothing in the code that says it's version 2.6 and the 1st line reads:

Ptr := A_PtrSize ? "Ptr" : "UInt"

Which i'm not sure the meaning of?  Can anyone help us?
 



Sam.
  • Members
  • 107 posts
  • Last active: Jul 15 2017 04:06 PM
  • Joined: 14 Nov 2008

I'm wondering if the link in the OP is to the wrong code?

I would agree. Try this link instead.