Old 20th October 2015, 19:03   #1
xliner78
Junior Member
 
Join Date: Jun 2011
Posts: 7
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
code:
<?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 is offline   Reply With Quote
Old 20th October 2015, 22:07   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,914
So, does setup.exe have the data embedded when you download it or is this a server issue?

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 20th October 2015, 22:17   #3
xliner78
Junior Member
 
Join Date: Jun 2011
Posts: 7
Hi Anders,
Thanks for the reply.
I don't know how to pass the parameter to exe with php and download it.
xliner78 is offline   Reply With Quote
Old 20th October 2015, 23:03   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,914
If this is a PHP question then this is not the right place to ask questions...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 20th October 2015, 23:06   #5
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
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.

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 21st October 2015, 12:54   #6
xliner78
Junior Member
 
Join Date: Jun 2011
Posts: 7
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?
xliner78 is offline   Reply With Quote
Old 21st October 2015, 13:26   #7
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,914
Quote:
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...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 21st October 2015, 13:30   #8
xliner78
Junior Member
 
Join Date: Jun 2011
Posts: 7
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
xliner78 is offline   Reply With Quote
Old 21st October 2015, 16:06   #9
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,914
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".

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 21st October 2015, 16:19   #10
xliner78
Junior Member
 
Join Date: Jun 2011
Posts: 7
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
code:
<?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
code:
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
code:
Push "mydata:"
Call ReadCustomerData
Pop $R1
StrCmp $R1 "" 0 +3


Where $R1 is your appended data.
xliner78 is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Tags
nsis, php, variable

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump