4 Replies - 300 Views - Last Post: 18 May 2013 - 01:28 PM Rate Topic: -----

#1 theshowtekfan  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 27-September 11

is there a way to add RC_DATA resource to a file with php ? :)

Posted 17 May 2013 - 06:28 PM

hi there, i am working on a file protector webpage wich will protect .net files and i am trying to add the bytes of the .net program to the rc_data resources of another file, to do this i would either need access to the win32 api functions or i would need some other way to edit rc_data ;)

please help me out here, i tried googling but did not find anything else than the outdated and not working php_win32.dll

Is This A Good Question/Topic? 0
  • +

Replies To: is there a way to add RC_DATA resource to a file with php ? :)

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3712
  • View blog
  • Posts: 5,964
  • Joined: 08-June 10

Re: is there a way to add RC_DATA resource to a file with php ? :)

Posted 17 May 2013 - 07:04 PM

PHP has a number of Windows Extensions, but the Win32 extension is apparently considered dead, like you say. Not sure of a .NET or COM extension is of any use in this?

If not, you could always write a .NET or C++ program to do this, and then execute it through PHP. That way you won't have to be using PHP - which is hardly built for this kind of work - to do the task itself, and can use more "native" methods in a language that fully supports the APIs needed.
Was This Post Helpful? 0
  • +
  • -

#3 theshowtekfan  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 27-September 11

Re: is there a way to add RC_DATA resource to a file with php ? :)

Posted 17 May 2013 - 07:23 PM

well i thought about a backend C++ server, as that i my main language but idk how to make a front end php and backend C++ :/
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3712
  • View blog
  • Posts: 5,964
  • Joined: 08-June 10

Re: is there a way to add RC_DATA resource to a file with php ? :)

Posted 17 May 2013 - 08:03 PM

Well, PHP is never on the front-end. In the context of web development (which it is, 99.9% of the time), PHP is exclusively a server-side language.

I'm not suggesting that you build a PHP-like, server-side web app in C++. Just that you create a C++ program that does whatever it is you want to do with these Windows APIs, and then execute that program from PHP when needed. PHP can still take care of everything relating to creating the website, just using your C++ program as a way to take care of this RC_DATA stuff.

For example, imagine if you created a EXE file in C++ or .NET that did some modifications to a file and saved it as a new file. That you could execute this program in a CMD window like so:
> C:\path\to\my\app\convert.exe "C:\files\input.file" "C:\files\output.file"


You could have PHP do just that, using the exec methods, and then use the result of this EXE. Consider if you allowed your users to upload the input file for this program through PHP, this code would run it through this EXE and feed the modified file back to the user:
<?php
if (isset($_FILES["theFile"]) && $_FILES["theFile"]["error"] == 0) {
	// Define a path where the converted file should be put,
	// and get the location of the temporary file created by PHP
	// for the file upload.
	$outputFile = "C:\\modified_files\\" . $_FILES["theFile"]["name"];
	$inputFile = $_FILES["theFile"]["tmpName"];

	// Create a shell command that executes an external program
	// and passes both file paths to it as parameters.
	$command = "C:\\path\\to\\my\\app\\convert.exe \"{$inputFile}\" \"{$outputFile}\"";

	// Execute the command. PHP will pause at this point, waiting for the
	// process to finish.
	exec($command, $output, $result);
	
	// The result will be whatever result the EXE returns.
	if ($result == 0) {
		// Since it was successful, feed the modified file back
		// to the user.
		header("Content-type: " . $_FILES["theFile"]["type"]);
		header("Content-Disposition: attachment; filename='{$_FILES["theFile"]["name"]}'");
		header("Conent-Length: " . filesize($outputFile));
		readfile($outputFile);
		exit;
	}
	else {
		echo "Failed to convert your file.";
	}
}
else {
	echo "Upload a file, genius.";
}


Of course, I've done very little input validation here, so this is not exactly a safe script, but you get what I mean. PHP doesn't have to do all the actual work itself, it can rely on programs written in other language to do things it lacks the APIs to do itself.
Was This Post Helpful? 0
  • +
  • -

#5 theshowtekfan  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 27-September 11

Re: is there a way to add RC_DATA resource to a file with php ? :)

Posted 18 May 2013 - 01:28 PM

View PostAtli, on 17 May 2013 - 08:03 PM, said:

Well, PHP is never on the front-end. In the context of web development (which it is, 99.9% of the time), PHP is exclusively a server-side language.

I'm not suggesting that you build a PHP-like, server-side web app in C++. Just that you create a C++ program that does whatever it is you want to do with these Windows APIs, and then execute that program from PHP when needed. PHP can still take care of everything relating to creating the website, just using your C++ program as a way to take care of this RC_DATA stuff.

For example, imagine if you created a EXE file in C++ or .NET that did some modifications to a file and saved it as a new file. That you could execute this program in a CMD window like so:
> C:\path\to\my\app\convert.exe "C:\files\input.file" "C:\files\output.file"


You could have PHP do just that, using the exec methods, and then use the result of this EXE. Consider if you allowed your users to upload the input file for this program through PHP, this code would run it through this EXE and feed the modified file back to the user:
<?php
if (isset($_FILES["theFile"]) && $_FILES["theFile"]["error"] == 0) {
	// Define a path where the converted file should be put,
	// and get the location of the temporary file created by PHP
	// for the file upload.
	$outputFile = "C:\\modified_files\\" . $_FILES["theFile"]["name"];
	$inputFile = $_FILES["theFile"]["tmpName"];

	// Create a shell command that executes an external program
	// and passes both file paths to it as parameters.
	$command = "C:\\path\\to\\my\\app\\convert.exe \"{$inputFile}\" \"{$outputFile}\"";

	// Execute the command. PHP will pause at this point, waiting for the
	// process to finish.
	exec($command, $output, $result);
	
	// The result will be whatever result the EXE returns.
	if ($result == 0) {
		// Since it was successful, feed the modified file back
		// to the user.
		header("Content-type: " . $_FILES["theFile"]["type"]);
		header("Content-Disposition: attachment; filename='{$_FILES["theFile"]["name"]}'");
		header("Conent-Length: " . filesize($outputFile));
		readfile($outputFile);
		exit;
	}
	else {
		echo "Failed to convert your file.";
	}
}
else {
	echo "Upload a file, genius.";
}


Of course, I've done very little input validation here, so this is not exactly a safe script, but you get what I mean. PHP doesn't have to do all the actual work itself, it can rely on programs written in other language to do things it lacks the APIs to do itself.


i did as u said and i have the php execute the program with an arguement that tells it the file path, the problem now is that the exec() command and all the commands does not allow me to launch a .exe file for some reason, and only cmd commands :/ is there any other way to run my .exe through php ??? i would really appreciate answers to this :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1