Skip to content

Commit

Permalink
Implemented readline in IDevice::Shell.
Browse files Browse the repository at this point in the history
  • Loading branch information
GreySyntax committed Oct 23, 2010
1 parent b79e16f commit 9cd62c7
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 7 deletions.
Binary file added backup/22-10-10_17.46.zip
Binary file not shown.
3 changes: 3 additions & 0 deletions include/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@
#include <string.h>
#include <stdlib.h>

#include <readline/readline.h>
#include <readline/history.h>

#endif /* COMMON_H_ */
25 changes: 25 additions & 0 deletions include/Hooks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/***
* iRecovery++ libusb based usb interface for iBoot and iBSS
* Copyright (C) 2010 GreySyntax
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef HOOKS_H_

#define HOOKS_H_

int set_deftext();

#endif /* HOOKS_H_ */
4 changes: 3 additions & 1 deletion include/IDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

#include "LazyUSB.h"
#include "Common.h"
///#include "Hooks.h"

#define IDEVICE_H_
#define APPLE_VENDOR_ID 0x05AC
#define APPLE_VENDOR_ID 0x05AC
#define LOG_FILE ".irecovery_history"

class IDevice {

Expand Down
39 changes: 39 additions & 0 deletions src/Hooks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/***
* iRecovery++ libusb based usb interface for iBoot and iBSS
* Copyright (C) 2010 GreySyntax
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "Common.h"
#include "Hooks.h"

char *deftext;

int set_deftext() {

if (deftext) {

rl_insert_text(deftext);
deftext = (char *) NULL;
rl_startup_hook = (rl_hook_func_t *)NULL;
}

return 0;
}

void set_deftext(char *txt) {

deftext = txt;
}
55 changes: 52 additions & 3 deletions src/IDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

#include "IDevice.h"

#define APPLE_VENDOR_ID 0x05AC

using namespace std;

enum {
Expand All @@ -30,9 +28,23 @@ enum {
kBufferSize = 0x10000,
kCommandMaxLen = 0x200,
kCommandTimeout = 500,
kUploadTimeout = 1000
kUploadTimeout = 1000,
};

static char *deftext;

static int set_deftext() {

if (deftext) {

rl_insert_text(deftext);
deftext = (char *) NULL;
rl_startup_hook = (rl_hook_func_t *)NULL;
}

return 0;
}

IDevice::IDevice() {

//Stub
Expand Down Expand Up @@ -137,6 +149,8 @@ bool IDevice::SendCommand(const char* argv) {
return false;
}

//add_history(LOG_FILE);

char* action = strtok(strdup(argv), " ");

if (! strcmp(action, "getenv")) {
Expand All @@ -155,6 +169,11 @@ bool IDevice::SendBuffer(char* data, int length, int* actual_length) {
Connect();
}

if (! USB.IsConnected() || ! USB.Configure(1) || ! USB.ClaimAltInterface(1, 1)) {

return false;
}

if (USB.Write(0x04, data, length, actual_length, kUploadTimeout) != 0) {

return false;
Expand Down Expand Up @@ -185,6 +204,17 @@ void IDevice::Shell() {

bool runShell = true;
int available = 0, pos = 0;
char *prompt, *temp;

deftext = (char *)0;
//prompt = "IDevice$: ";

if (deftext && *deftext) {

rl_startup_hook = set_deftext;
}

read_history(LOG_FILE);

while (runShell) {

Expand All @@ -203,6 +233,25 @@ void IDevice::Shell() {
free(buffer);
buffer = (char*)malloc(kBufferSize);
}

temp = readline("IDevice$ ");

if (temp != 0 && temp && *temp) {

//TODO Log

if (temp[0] == '/' && strlen(temp) > 1 && temp[1] != ' ') {

//TODO Handle command

} else {

SendCommand(temp);
}

//Ciao bitch!
free(temp);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/LazyUSB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ bool LazyUSB::ClaimInterface(int interface) {
#else

libusb_init(NULL);
//libusb_set_debug(NULL, 2);

if ((handle = libusb_open_device_with_vid_pid(NULL, vendorID, productID)) == NULL) {
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CXXFLAGS = -O2 -g -Wall -fmessage-length=0 -I./include
CXXALL = -lreadline
CXXCSS = -I"../include" -I"/usr/local/include" -I"/opt/local/include" -L"/usr/local/lib" -L"/opt/local/lib"
CXXCSS = -I"../include" -I"/usr/local/include" -L"/usr/local/lib"
CXXWIN = -lusb -I"C:\MinGW\include" -L"C:\MinGW\lib"
CXXNIX = -lusb-1.0
CXXOSX = -lusb-1.0 -framework CoreFoundation -framework IOKit
Expand Down Expand Up @@ -33,7 +33,7 @@ win: start $(SOURCE)
@mkdir ../bin;
$(CXX) -o $(TARGET) $(SOURCE) $(CXXALL) $(CXXWIN)

backup:
@if [ ! -e ../backup ]; then mkdir ../backup; fi;
backup: $(SOURCE) $(HEADERS) $(EXTRA_FILES)
@if [ ! -e ../backup ]; then; mkdir ../backup; fi;
@zip ../backup/`date +%d-%m-%y_%H.%M`.zip $(SOURCE) $(HEADERS) $(EXTRA_FILES)

1 change: 1 addition & 0 deletions src/Program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ int main(int argc, char *argv[]) {
if (Device.Connect()) {

Device.Shell();
//Device.Upload("../crap");
Device.Disconnect();
}

Expand Down

0 comments on commit 9cd62c7

Please sign in to comment.