Skip to content
⌘ NSIS Forum Archive

PHP and ReadCustomerData

10 posts

xliner78#

PHP and ReadCustomerData

Hi to everyone,

I want to pass a variable to the exe using ReadCustomerData.
I searched online and i found something but not seems to working.

http://superuser.com/questions/90515...nsis-installer
<?php
echo "mydata:testvariable">>setup.exe;
?>
I want the user when access the page downloads the exe and the variable have passed in the installer.
Any help is appreciated
Thanks
xliner78#
Hi Anders,
Thanks for the reply.
I don't know how to pass the parameter to exe with php and download it.
LoRd_MuldeR#
xliner78, not quite sure what you want 😱

PHP script is something that runs on a server. NSIS installer runs on the local computer.

But if you actually want to invoke a PHP script on the server, from your local NSIS installer, then you have to send a HTTP request to the server and store/evaluate the corresponding HTTP response. Parameters may be passed in the "query string" part of the URL.

Look into the Inetc plug-in!


[EDIT]

If you actually want the installer EXE to have the "customer data" built-in, it would be a pretty bad idea to just append this extra data to the finished EXE file. Instead, pass it to MakeNSIS via /D switch when you compile the installer! For example, if you pass /DFoo=Bar to MakeNSIS when compiling the installer, then you can get the passed value ("Bar") by using ${Foo} placeholder inside the installer script.
xliner78#
Anders is not actually a php question.
Because i also don't know how to pass the parameter testvariable inside the script.
I read the documentation but i still cannot make it working?
Anders#
Originally Posted by xliner78 View Post
Anders is not actually a php question.
Because i also don't know how to pass the parameter testvariable inside the script.
I read the documentation but i still cannot make it working?
If it is not a PHP question, why did you include PHP in the thread title?

I'll ask again, when you download the .exe from the server, is your data appended to the file or not? Check with a hex editor. We cannot continue until you answer this question...
xliner78#
Hi Anders,
Now i understand.
When the file downloaded there is nothing appended.My problem is how to append it.
How to append the data manually on my computer?
I already tried to open the exe with notepad (with SetCompress off)
I added in the end of file mydata:testvariable and the installed destroyed
Thanks for you helping me Anders
Anders#
You cannot edit .exe files in notepad, use a hex editor. If you just want to append a string you can start cmd.exe and type "echo Hello World >> MySetup.exe".
xliner78#
Hi Anders.
Thanks for the help .
I finally found how to also edit it with php on the fly without changing the installer.exe every time.
Here is the full solution
Here is the php code you will need
<?php
$txt ="mydata:testvariable";
$filename = "installer.exe";
$outputfilename = "exportedexename.exe";

header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"" . basename($outputfilename) . "\";" );
header("Content-Transfer-Encoding: binary");
readfile("$filename");
readfile($txt.PHP_EOL);
?>
Add this function to your script
Function ReadCustomerData
; arguments
Exch $R1 ; customer data magic value
; locals
Push $1 ; file name or (later) file handle
Push $2 ; current trial offset
Push $3 ; current trial string (which will match $R1 when customer data is found)
Push $4 ; length of $R1

FileOpen $1 $EXEPATH r

; change 1024 here to, e.g., 2048 to scan the last 2Kb of EXE file
IntOp $2 0 - 1024
StrLen $4 $R1

loop:
FileSeek $1 $2 END
FileRead $1 $3 $4
StrCmp $3 $R1 found
IntOp $2 $2 + 1
IntCmp $2 0 loop loop

StrCpy $R1 ""
goto fin

found:
IntOp $2 $2 + $4
FileSeek $1 $2 END
FileRead $1 $3
StrCpy $R1 $3

fin:
Pop $4
Pop $3
Pop $2
Pop $1
Exch $R1
FunctionEnd

And to get the appended data use this
Push "mydata:"
Call ReadCustomerData
Pop $R1
StrCmp $R1 "" 0 +3
Where $R1 is your appended data.