Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Commit

Permalink
Set fw_bcmdhd.bin permissions to 644 instead of 755, add 'log' option…
Browse files Browse the repository at this point in the history
… to Shell objects to log every executed command in logcat
  • Loading branch information
chrisk44 committed Feb 22, 2020
1 parent 488f31e commit c59f3a4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
Binary file modified .idea/caches/gradle_models.ser
Binary file not shown.
8 changes: 6 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 22 additions & 12 deletions app/src/main/java/com/hijacker/InstallFirmwareDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import static com.hijacker.MainActivity.findFirmwarePath;
import static com.hijacker.MainActivity.firm_backup_file;
import static com.hijacker.MainActivity.background;
import static com.hijacker.MainActivity.iface;
import static com.hijacker.MainActivity.path;
import static com.hijacker.MainActivity.stop;

Expand Down Expand Up @@ -139,7 +140,7 @@ public void show(FragmentManager fragmentManager, String tag){
void attemptInstall(){
String firm_location = firmwareView.getText().toString();

if(debug) Log.d("HIJACKER/InstFirm", "Installing firmware in " + firm_location + " and utility in " + selectedUtilPath);
if(debug) Log.d(TAG, "Installing firmware in " + firm_location + " and utility in " + selectedUtilPath);
install(firm_location, selectedUtilPath);
}
void attemptRestore(){
Expand Down Expand Up @@ -239,8 +240,6 @@ void install(String firm_location, String util_location){
stop(PROCESS_AIRODUMP);
}

WifiManager wifiManager = (WifiManager) getActivity().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if(wifiManager!=null) wifiManager.setWifiEnabled(false);
if(backup_cb.isChecked()){
if(new File(firm_backup_file).exists()){
Toast.makeText(getActivity(), R.string.backup_exists, Toast.LENGTH_SHORT).show();
Expand Down Expand Up @@ -273,21 +272,32 @@ void install(String firm_location, String util_location){

Log.d(TAG, fs + " has been remounted as rw successfully");

// Extract the files
if(!extract(fw_filename, firm_location)){
// Extract the files in 'path'
if(!extract(fw_filename, path)){
Log.e(TAG, "Error extracting fw file in " + firm_location);
Snackbar.make(dialogView, R.string.error_extracting_firmware, Snackbar.LENGTH_LONG).show();
}
if(!extract("nexutil", util_location + "/nexutil")){
if(!extract("nexutil", path)){
Log.e(TAG, "Error extracting nexutil in " + util_location);
Snackbar.make(dialogView, R.string.error_extracting_utility, Snackbar.LENGTH_LONG).show();
}

// Move the extracted files to their locations
shell.run("mv " + path + '/' + fw_filename + " " + firm_location);
shell.run("mv " + path + "/nexutil " + util_location + "/nexutil");

// chmod the firmware and nexutil
shell.run(busybox + " chmod 644 " + firm_location);
shell.run(busybox + " chmod 755 " + util_location + "/nexutil");

// Remount fs as ro
shell.run(busybox + " mount -o ro,remount " + fs);

// Reset WiFi
shell.run(busybox + " ifconfig " + iface + " down");
shell.run(busybox + " ifconfig " + iface + " up");

Toast.makeText(getActivity(), R.string.installed_firm_util, Toast.LENGTH_SHORT).show();
if(wifiManager!=null) wifiManager.setWifiEnabled(true);

if(start_airodump) Airodump.startClean();

Expand All @@ -307,8 +317,9 @@ void restore(String firm_location){
// Verify that fs has been remounted successfully
if(!verifyRW()) return;

// Replace the firmware with the backup file
// Replace the firmware with the backup file and chmod to 644
shell.run("cp " + firm_backup_file + " " + firm_location);
shell.run(busybox + " chmod 644 " + firm_location);

// Remount fs as ro
shell.run(busybox + " mount -o ro,remount " + fs);
Expand All @@ -319,8 +330,8 @@ void restore(String firm_location){
dismissAllowingStateLoss();
}

boolean extract(String filename, String dest){
File f = new File(path, filename); //no permissions to write at dest so extract at local directory and then move to target
boolean extract(String filename, String dir){
File f = new File(dir, filename);
if(!f.exists()){
try{
InputStream in = getResources().getAssets().open(filename);
Expand All @@ -332,8 +343,6 @@ boolean extract(String filename, String dest){
}
in.close();
out.close();
shell.run("mv " + path + '/' + filename + " " + dest);
shell.run("chmod 755 " + dest);
}catch(IOException e){
Log.e("HIJACKER/InstFirm", "Exception copying from assets", e);
return false;
Expand All @@ -354,6 +363,7 @@ protected void onPreExecute() {
@Override
protected Void doInBackground(Void... voids){
shell = Shell.getFreeShell();
shell.setLog(true);

//Find firmware path
firmwarePath = findFirmwarePath(shell);
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/com/hijacker/Shell.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Shell{
private BufferedReader shell_out;
private static final List<Shell> free = new ArrayList<>();
private static int total=0;
private boolean valid = true;
private boolean valid = true, log = false;
Shell(){
total++;
try{
Expand All @@ -72,26 +72,30 @@ void run(String cmd){
}
this.shell_in.print(cmd + '\n');
this.shell_in.flush();

if(log) Log.d("HIJACKER/ShellLog", cmd);
}
boolean isValid(){ return this.valid; }
void done(){
if(!valid){
throw new IllegalStateException("Shell has already been registered as free");
}
clearOutput();
setLog(false);
synchronized(free){
if(!free.contains(this)) free.add(this);
valid = false;
}
}
void clearOutput(){
// Print a unique string
String term_str = "ENDOFCLEAR" + System.currentTimeMillis() + "-" + new Random().nextInt();
String term_str = "SHELL_OUTPUT_CLEAR-" + System.currentTimeMillis() + "-" + new Random().nextInt();
run("echo; echo " + term_str);

// Read up to the last known line
MainActivity.getLastLine(shell_out, term_str);
}
void setLog(boolean log){ this.log = log; }
static synchronized Shell getFreeShell(){
if(free.isEmpty()) return new Shell();
else{
Expand Down

1 comment on commit c59f3a4

@1v3k
Copy link

@1v3k 1v3k commented on c59f3a4 Jun 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you

Please sign in to comment.