I am Attempting to download a binary file(exe) from a php script. Been stuck for hours.
PHP Script:
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 1048);
echo $buffer;
}
C:
char update[1024] = {0};
FILE *fileo;
fileo = fopen("test.exe", "wb");
instruction = recv(s, update, 1024, 0);
int result =returnBody();//Removes headers
fwrite(body, sizeof(body),1,fileo);
memset(update, 0, 1024);
while ((instruction = recv(s, update, 1024, 0)) > 0)
{
fwrite(update, sizeof(update),1,fileo);
memset(update, 0, 1024);
}
fclose(fileo);
returnbody function:
int returnBody(){
for(int x = 0; x < strlen(message); x++)
{
if(message[x] == '\r')
{
if(message[x + 1] == '\n')
{
if(message[x + 2] == '\r')
{
if(message[x + 3] == '\n')
{
int y = x + 4;
body = (char *)realloc(body, ((strlen(message) - y) * sizeof(char)));
memset(body, 0, sizeof(body));
for(int b = 0; y < strlen(message); y++, b++){
body[b] = message[y];
}
return 1;
}
}
}
}
}
return 0;
}
I succeed in writing the file but it doesn't run. Gets an error, unsupported 16 bit application.
My Question is do I need to parse it as binary before I write it to the file?