-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f04d26c
Showing
9 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> | ||
<classpathentry kind="src" path="gen"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bin | ||
gen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>NativeExe</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.ApkBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="net.gimite.nativeexe" | ||
android:versionCode="1" | ||
android:versionName="1.0.0"> | ||
<application android:icon="@drawable/icon" android:label="@string/app_name"> | ||
<activity android:name=".MainActivity" | ||
android:label="@string/app_name"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
<uses-permission android:name="android.permission.INTERNET"></uses-permission> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This file is automatically generated by Android Tools. | ||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED! | ||
# | ||
# This file must be checked in Version Control Systems. | ||
# | ||
# To customize properties used by the Ant build system use, | ||
# "build.properties", and override values to adapt the script to your | ||
# project structure. | ||
|
||
# Project target. | ||
target=android-4 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
> | ||
|
||
<TextView | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/localPathLabel" android:text="Local exe path:"/> | ||
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> | ||
<EditText android:id="@+id/localPathEdit" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1" android:text="/system/bin/ls"></EditText> | ||
<Button android:id="@+id/localRunButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Run"></Button> | ||
</LinearLayout> | ||
|
||
<TextView | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/urlLabel" android:text="URL to remote exe:"/> | ||
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> | ||
<EditText android:id="@+id/urlEdit" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1" android:text="http://shimadzu.dip.jp/~gimite/arm-hello"/> | ||
<Button android:id="@+id/remoteRunButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Run"></Button> | ||
</LinearLayout> | ||
|
||
<TextView android:id="@+id/outputView" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="hello">Hello World, MainActivity</string> | ||
<string name="app_name">Run Native Exe</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package net.gimite.nativeexe; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.net.HttpURLConnection; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
import net.gimite.nativeexe.R; | ||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.view.View; | ||
import android.view.View.OnClickListener; | ||
import android.widget.*; | ||
|
||
public class MainActivity extends Activity { | ||
|
||
private TextView outputView; | ||
private Button localRunButton; | ||
private EditText localPathEdit; | ||
private Handler handler = new Handler(); | ||
private EditText urlEdit; | ||
private Button remoteRunButton; | ||
|
||
/** Called when the activity is first created. */ | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.main); | ||
|
||
outputView = (TextView)findViewById(R.id.outputView); | ||
localPathEdit = (EditText)findViewById(R.id.localPathEdit); | ||
localRunButton = (Button)findViewById(R.id.localRunButton); | ||
localRunButton.setOnClickListener(onLocalRunButtonClick); | ||
urlEdit = (EditText)findViewById(R.id.urlEdit); | ||
remoteRunButton = (Button)findViewById(R.id.remoteRunButton); | ||
remoteRunButton.setOnClickListener(onRemoteRunButtonClick); | ||
} | ||
|
||
private OnClickListener onLocalRunButtonClick = new OnClickListener() { | ||
public void onClick(View v) { | ||
String output = exec(localPathEdit.getText().toString()); | ||
output(output); | ||
} | ||
}; | ||
|
||
private OnClickListener onRemoteRunButtonClick = new OnClickListener() { | ||
public void onClick(View v) { | ||
final String url = urlEdit.getText().toString(); | ||
final String localPath = "/data/data/net.gimite.nativeexe/a.out"; | ||
output("Downloading..."); | ||
Thread thread = new Thread(new Runnable() { | ||
public void run() { | ||
download(url, localPath); | ||
exec("/system/bin/chmod 744 " + localPath); | ||
output("Executing..."); | ||
String output = exec(localPath); | ||
output(output); | ||
} | ||
}); | ||
thread.start(); | ||
} | ||
}; | ||
|
||
// Executes UNIX command. | ||
private String exec(String command) { | ||
try { | ||
Process process = Runtime.getRuntime().exec(command); | ||
BufferedReader reader = new BufferedReader( | ||
new InputStreamReader(process.getInputStream())); | ||
int read; | ||
char[] buffer = new char[4096]; | ||
StringBuffer output = new StringBuffer(); | ||
while ((read = reader.read(buffer)) > 0) { | ||
output.append(buffer, 0, read); | ||
} | ||
reader.close(); | ||
process.waitFor(); | ||
return output.toString(); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private void download(String urlStr, String localPath) { | ||
try { | ||
URL url = new URL(urlStr); | ||
HttpURLConnection urlconn = (HttpURLConnection)url.openConnection(); | ||
urlconn.setRequestMethod("GET"); | ||
urlconn.setInstanceFollowRedirects(true); | ||
urlconn.connect(); | ||
InputStream in = urlconn.getInputStream(); | ||
FileOutputStream out = new FileOutputStream(localPath); | ||
int read; | ||
byte[] buffer = new byte[4096]; | ||
while ((read = in.read(buffer)) > 0) { | ||
out.write(buffer, 0, read); | ||
} | ||
out.close(); | ||
in.close(); | ||
urlconn.disconnect(); | ||
} catch (MalformedURLException e) { | ||
throw new RuntimeException(e); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private void output(final String str) { | ||
Runnable proc = new Runnable() { | ||
public void run() { | ||
outputView.setText(str); | ||
} | ||
}; | ||
handler.post(proc); | ||
} | ||
|
||
} |