Skip to content

Commit 1368d13

Browse files
committed
Fix write permission checks on SD card, pass correct path to exec_payload to dialog with manual.
1 parent 8ab3e7c commit 1368d13

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

app/src/main/java/org/leyfer/thesis/touchlogger_dirty/activity/MainActivity.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.support.v7.app.AlertDialog;
1515
import android.support.v7.app.AppCompatActivity;
1616
import android.util.Log;
17+
import android.view.LayoutInflater;
1718
import android.view.View;
1819
import android.widget.Button;
1920
import android.widget.TextView;
@@ -81,7 +82,12 @@ public void run() {
8182
mHandler.post(new Runnable() {
8283
@Override
8384
public void run() {
84-
notifyManualInstallationRequired();
85+
File externalStorageDirectory =
86+
Environment.getExternalStorageDirectory();
87+
File targetFile = new File(externalStorageDirectory,
88+
EXEC_PAYLOAD_NAME);
89+
notifyManualInstallationRequired(
90+
targetFile.getAbsolutePath());
8591
}
8692
});
8793
} catch (final ManualInstallationException e) {
@@ -109,9 +115,16 @@ private String getStackTraceString(Exception e) {
109115
return result.toString();
110116
}
111117

112-
private void notifyManualInstallationRequired() {
118+
private void notifyManualInstallationRequired(String fileExternalStorageDirLocation) {
119+
LayoutInflater inflater = LayoutInflater.from(this);
120+
View manualInstallationView = inflater.inflate
121+
(R.layout.dialog_manual_payload_installation, null);
122+
TextView copyCommandTextView = manualInstallationView.findViewById(R.id.copy_command);
123+
copyCommandTextView.setText(
124+
getString(R.string.copy_command_text, fileExternalStorageDirLocation));
125+
113126
new AlertDialog.Builder(this)
114-
.setView(R.layout.dialog_manual_payload_installation)
127+
.setView(manualInstallationView)
115128
.setTitle(R.string.alert_title)
116129
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
117130
@Override
@@ -125,12 +138,13 @@ public void onClick(DialogInterface dialogInterface, int i) {
125138
private void prepareManualInstallation() throws ManualInstallationException {
126139
File execPayloadFile = new File(getFilesDir(), EXEC_PAYLOAD_NAME);
127140
if (execPayloadFile.exists()) {
128-
File targetFile = new File(Environment.getExternalStorageDirectory().getPath(),
129-
EXEC_PAYLOAD_NAME);
130-
if (!targetFile.canWrite()) {
141+
File externalStorageDirectory = Environment.getExternalStorageDirectory();
142+
if (!externalStorageDirectory.canWrite()) {
131143
throw new ManualInstallationException(
132144
"Unable to create file on SD card, check SD card permissions!");
133145
}
146+
147+
File targetFile = new File(externalStorageDirectory, EXEC_PAYLOAD_NAME);
134148
try {
135149
FileUtils.copyFile(execPayloadFile, targetFile);
136150
} catch (IOException e) {

app/src/main/res/layout/dialog_manual_payload_installation.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
android:text="@string/manual_3"/>
2626

2727
<TextView
28+
android:id="@+id/copy_command"
2829
android:layout_width="match_parent"
2930
android:layout_height="wrap_content"
3031
android:layout_marginLeft="32dp"
3132
android:layout_marginStart="32dp"
3233
android:layout_marginTop="8dp"
33-
android:text="@string/manual_3_1"
34+
android:text="@string/copy_command_text"
3435
app:fontFamily="monospace"/>
3536

3637
<TextView

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
<string name="payload_install_error">Touchlogger was unable to complete payload installation!</string>
2626
<string name="manual_1">To install touchlogger payload manually, please follow these steps:</string>
2727
<string name="manual_2">1. Connect to your device using ADB shell</string>
28-
<string name="manual_3">2. Copy /sdcard/exec_payload to /data/local/tmp/exec_payload:</string>
28+
<string name="manual_3">2. Copy exec_payload from SD card to /data/local/tmp/exec_payload:</string>
2929
<string name="manual_4">3. Set exec_payload to executable:</string>
30-
<string name="manual_3_1">cp /sdcard/exec_payload /data/local/tmp/exec_payload</string>
30+
<string name="copy_command_text">cp %1$s /data/local/tmp/exec_payload</string>
3131
<string name="manual_5">cd /data/local/tmp</string>
3232
<string name="manual_5_1">chmod 755 exec_payload</string>
3333
<string name="manual_6">4. Start exec_payload:</string>

0 commit comments

Comments
 (0)