Extracting self-extracting exe archive via php - php

I have a problem. I have the service which is giving me .exe file which they claim is in fact zip archive. A self-extracting archive.
Problem is that I am downloading that with my app (php) to server and need to extract it there witout downloading to local computer.
I have tried download .exe file to local computer - it is self extracting on windows to /temp dir and than self launching FLASH player.
$zip = zip_open($myfile); gives in print_r($zip): 1
zip->open gives no results either.
change .exe to .zip doesn't let winzip or other kind of un-packer on windows to open it - .exe cannot be opened by winzip too.
Now I have no idea how to deal with it. If anybody can advise please.

Try to execute the program as an executable with the system command

Executing files from an external source you don't trust 100% is never a good idea.
The info-zip version of zip allows you to remove the SFX stub from a self-extracting zip file (with the -J flag) converting it back into a normal zip file.
Source code is freely available.
Making a self-extracting zip file is a matter of prepending a zip file with the SFX binary code, then appending the size of the binary stub to the resulting file - but I'm not sure how the data is represented - but a bit of reverse-engineering the available code should make this clear.

Well... if your PHP server is Windows you shouldn't have a problem doing it as a system command. Otherwise, it's a little more tricky. I hear that the unzip system command will unzip self-extracting zip files, but I don't have access to a Linux box at the moment to try it out.
If you're on shared hosting, chances are you can't do it.

Well if you think after executing the exe file, it will extract its content, then you can use exec function to run the .exe files like the one below:
exec("d:\\example\\php\_exe\\1436.exe");
and also you can use system function to run external programs as well.
And also if you wonder what's the difference:
PHP - exec() vs system() vs passthru()

Related

How to validate a .tar.gz archive in PHP?

The user uploads a .tar.gz archive and I need to validate if the archive contains a certain file (I just need to check the filename, nothing else).
I know I can open the file using \PharData however it seems that it loads the entire archive into memory. Since the archive is a backup and can easily be bigger than memory_limit, I can't use this.
How can I do the validation without loading the whole file to memory? In case it is impossible to do in PHP (as I suspect), how can I do it in bash? Again without loading the entire file to memory at once and also without actually unpacking the archive.
you just can use bash command for that:
tar -t - show list of files

Batch script to download and save XLS file to directory

I am trying to write some batch script to download and save an XLS file from a URL. I am able to down load the file by using
#ECHO OFF
start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE url link
exit
I would now like to save these files to a folder or directory.
Any help anyone could provide here would be greatly appreciated.
There are at least two ways to do it.
Like Buddy suggested, use a command-line downloader, for example wget.
Under Linux, you can run PHP directly (even without a webserver). See PHP: Command Line PHP on Microsoft Windows in PHP manual.
Don't run a browser, or - even worse - IE, just to run a PHP script.

determine if PDF file is openable and not corrupt

I am wandering if anybody has a reliable way of determine whether a PDF document is actually a PDF document, and that it isn't corrupted.
I generate reports on my system and I want to be certain that the data returned by another system contains an openable PDF document (and that the data is not corrupt).
At the moment, I am basically looking at string length (the PDF gets stored into a variable, not a physical file).
Any recommendations to do this in PHP would be great.
If you just want to make sure the file is a PDF file, without checking that it is a completely intact pdf file with no issues, you can read the first 5 bytes of the file and for a PDF file they will be exactly equal to the string "%PDF-"
This is how the file program in linux identifies PDF files.
But if you want to make absolutely sure there are no errors anywhere in the file, you can run a program that processes the entire file, and see if that program returns success.
In linux you can use ghostscript ("gs") to render the PDF document to any format.
Or you can install acrobat reader, and run acroread as a command line program to convert it to postscript:
acroread -print -toPostScript [your_file.pdf]
To do either of these you will need to use the system PHP function. To check of the program ran successfully, you need to pass a variable in the second parameter to system that will receive the return status.
You can use pdfinfo, centos installation command:
yum install poppler-utils
... and use pdfinfo command. The PHP code is as follows:
if(!exec("pdfinfo test.pdf")){
echo "file is corrupted"
}

Creating selfextracting zips in php on the fly

I'm working on a php script packaging some files (a setup.exe and a licence.txt which is created direct in php for the user). We don't want that the user has to unzip it and start setup.exe.
On the computer we solved that by using selfextracting zips with:
zip is called setup.exe
zip has icon of the application
destination of extraction is temporary folder
extracting process is hidden
So if the user click on setup.exe he don't know that this setup.exe is a zip at the end.
But is that also possible on the server in the php script?
i tried the normal ziparchive object and pclzip and i can create the zip with these libraries. But i cannot change the parameters above...
Can anyone tell me if there's a solution for this?
Use PHP:exec to run an external application that compress and compile your exec file, with your stuff inside as you need.
PHP don't have built-in function to compress and compile and executable file.

compressing a folder into different formats in php

hey guys , im dealing with a script that it should compress and folder and make it ready in 3 versions :
7z
zip
tar.gz
surely i did found a way on how to make a zip file out of a folder in php by using a zip compression class
http://www.phpclasses.org/package/2322-PHP-Create-ZIP-file-archives-and-serve-for-download.html
but for 7z and tar.gz format no idea on how to do the compression
is there any way to make an 7z or tar.gz compressed file !?
specially 7z format
I suggest you install the relevant programs on the server, and call them from php via exec() to compress your files for you. Why bother rewriting the compression code when it's already been written?
Assuming Linux and having these (basic) tools already available:
exec("zip -r archive_name.zip directory_to_compress");
exec("tar -zcvf archive_name.tar.gz directory_to_compress");
For 7zip, you can check out this project on SourceForge.

Categories