Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean-up, Modernize, and Add New "Card Beep" Feature #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*bin
*bin
Source Code/esprfidtool/build/
4 changes: 2 additions & 2 deletions Source Code/esprfidtool/WiegandNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ bool WiegandNG::available() {
return ret;
}

void WiegandNG::ReadD0 () {
ICACHE_RAM_ATTR void WiegandNG::ReadD0 () {
_bitCounted++; // increment bit count for Interrupt connected to D0
shift_left(_buffer,_bufferSize,1); // shift 0 into buffer
_lastPulseTime = millis(); // keep track of time last wiegand bit received
}

void WiegandNG::ReadD1() {
ICACHE_RAM_ATTR void WiegandNG::ReadD1() {
_bitCounted++; // increment bit count for Interrupt connected to D1
if (_bitCounted > (_bufferSize * 8)) {
_bitCounted=0; // overflowed,
Expand Down
3 changes: 0 additions & 3 deletions Source Code/esprfidtool/aba2str.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
String aba2str (String magstripe, int magStart, int magEnd, String swipeDirection) {
//f.println(String()+"Start pos:"+magStart);
//f.println(String()+"Start pos:"+magEnd);
String ABA="";
String aba2str="";
int magCount=abs(magEnd-magStart);
//f.println(String()+"magCount:"+magCount);
aba2str=(String()+"\"Cleaned\" Binary:"+magstripe.substring(magStart,magEnd)+"\n");
aba2str+=(String()+" * Possible "+swipeDirection+" Card Data\(ASCII\):");
while (magCount>0) {
Expand Down
59 changes: 31 additions & 28 deletions Source Code/esprfidtool/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,28 @@ void apiinfo(int prettify) {
freespace=fs_info.totalBytes-fs_info.usedBytes;

const size_t bufferSize = JSON_ARRAY_SIZE(5) + JSON_OBJECT_SIZE(3);
DynamicJsonBuffer jsonAPIbuffer(bufferSize);
JsonObject& apilog = jsonAPIbuffer.createObject();
DynamicJsonDocument apilog(bufferSize);

apilog["Device"] = "ESP-RFID-Tool";
apilog["Firmware"] = version;
apilog["API"] = APIversion;
JsonObject& apifs = apilog.createNestedObject("File System");
JsonObject apifs = apilog.createNestedObject("File System");
apifs["Total Space"]=total;
apifs["Used Space"]=used;
apifs["Free Space"]=freespace;
apilog["Free Memory"] = String(ESP.getFreeHeap(),DEC);

String API_Response="";
if (prettify==1) {
apilog.prettyPrintTo(API_Response);
serializeJsonPretty(apilog, API_Response);
}
else {
apilog.printTo(API_Response);
serializeJson(apilog, API_Response);
}
server.send(200, "application/json", API_Response);
delay(50);
jsonAPIbuffer.clear();
apifs.clear();
apilog.clear();
}

void apilistlogs(int prettify) {
Expand All @@ -72,15 +72,14 @@ void apilistlogs(int prettify) {
while (dir.next()) {
File f = dir.openFile("r");
String FileName = dir.fileName();
if((!FileName.startsWith("/payloads/"))&&(!FileName.startsWith("/esploit.json"))&&(!FileName.startsWith("/esportal.json"))&&(!FileName.startsWith("/esprfidtool.json"))&&(!FileName.startsWith("/config.json"))) {
if((!FileName.startsWith("/esprfidtool.json"))&&(!FileName.startsWith("/config.json"))) {
logcount++;
}
f.close();
}

const size_t bufferSize = JSON_ARRAY_SIZE(5) + JSON_OBJECT_SIZE(1);
DynamicJsonBuffer jsonAPIbuffer(bufferSize);
JsonObject& apilog = jsonAPIbuffer.createObject();
DynamicJsonDocument apilog(bufferSize);

apilog["Device"] = "ESP-RFID-Tool";
apilog["Firmware"] = version;
Expand All @@ -92,25 +91,25 @@ void apilistlogs(int prettify) {
while (dir2ndrun.next()) {
File f = dir2ndrun.openFile("r");
String FileName = dir2ndrun.fileName();
if ((!FileName.startsWith("/payloads/"))&&(!FileName.startsWith("/esploit.json"))&&(!FileName.startsWith("/esportal.json"))&&(!FileName.startsWith("/esprfidtool.json"))&&(!FileName.startsWith("/config.json"))) {
if ((!FileName.startsWith("/esprfidtool.json"))&&(!FileName.startsWith("/config.json"))) {
currentlog++;
FileName.remove(0,1);
JsonObject& apilistlogs = apilog.createNestedObject(String(currentlog));
JsonObject apilistlogs = apilog.createNestedObject(String(currentlog));
apilistlogs["File Name"]=FileName;
}
f.close();
}

String API_Response="";
if (prettify==1) {
apilog.prettyPrintTo(API_Response);
serializeJsonPretty(apilog, API_Response);
}
else {
apilog.printTo(API_Response);
serializeJson(apilog, API_Response);;
}
server.send(200, "application/json", API_Response);
delay(50);
jsonAPIbuffer.clear();
apilog.clear();
}

void apilog(String logfile,int prettify) {
Expand All @@ -131,33 +130,35 @@ void apilog(String logfile,int prettify) {
}
}
f.close();
const size_t bufferSize = JSON_ARRAY_SIZE(6) + JSON_OBJECT_SIZE(4);
DynamicJsonBuffer jsonAPIbuffer(bufferSize);
JsonObject& apilog = jsonAPIbuffer.createObject();
DynamicJsonDocument apilog(2048);

apilog["Device"] = "ESP-RFID-Tool";
apilog["Firmware"] = version;
apilog["API"] = APIversion;
apilog["Log File"] = logfile;
apilog["Captures"] = apiCAPTUREcount;
apilog["CaptureCount"] = apiCAPTUREcount;

JsonArray captures = apilog.createNestedArray("Captures");

int apiCURRENTcapture=0;
File f = SPIFFS.open(String()+"/"+logfile, "r");
DynamicJsonDocument apiCURRENTcaptureOBJECT(1024);

while(f.available()) {
String line = f.readStringUntil('\n');

if(line.indexOf(",Binary:") > 0) {
int firstIndex = line.indexOf(",Binary:");

if(firstIndex > -1) {
apiCURRENTcapture++;
int firstIndex = line.indexOf(",Binary:");
int secondIndex = line.indexOf(",", firstIndex + 1);
String binaryCaptureLINE=line.substring(firstIndex+8, secondIndex);
if ( binaryCaptureLINE.indexOf(" ") > 0 ) {
binaryCaptureLINE=binaryCaptureLINE.substring(binaryCaptureLINE.indexOf(" ")+1);
}
binaryCaptureLINE.replace("\r","");
JsonObject& apiCURRENTcaptureOBJECT = apilog.createNestedObject(String(apiCURRENTcapture));
apiCURRENTcaptureOBJECT["Bit Count"]=binaryCaptureLINE.length();
apiCURRENTcaptureOBJECT["Binary"]=binaryCaptureLINE;
apiCURRENTcaptureOBJECT["Bit Count"] = binaryCaptureLINE.length();
apiCURRENTcaptureOBJECT["Binary"] = binaryCaptureLINE;
if(line.indexOf(",HEX:") > 0) {
int hfirstIndex = line.indexOf(",HEX:");
int hsecondIndex = line.indexOf(",", hfirstIndex + 1);
Expand All @@ -168,22 +169,24 @@ void apilog(String logfile,int prettify) {
if(line.indexOf(",Keypad Code:") > 0) {
int kfirstIndex = line.indexOf(",Keypad Code:");
int ksecondIndex = line.indexOf(",", kfirstIndex + 1);
String pinCURRENT=line.substring(kfirstIndex+13, ksecondIndex);
String pinCURRENT = line.substring(kfirstIndex + 13, ksecondIndex);
pinCURRENT.replace("\r","");
apiCURRENTcaptureOBJECT["Keypad Press"]=pinCURRENT;
apiCURRENTcaptureOBJECT["Keypad Press"] = pinCURRENT;
}

captures.add(apiCURRENTcaptureOBJECT);
}
}
f.close();
String API_Response="";
if (prettify==1) {
apilog.prettyPrintTo(API_Response);
serializeJsonPretty(apilog, API_Response);
}
else {
apilog.printTo(API_Response);
serializeJson(apilog, API_Response);;
}
server.send(200, "application/json", API_Response);
delay(50);
jsonAPIbuffer.clear();
apilog.clear();
}
}
12 changes: 6 additions & 6 deletions Source Code/esprfidtool/api_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ server.on("/api/tx/bin", [](){
}

const size_t bufferSize = JSON_ARRAY_SIZE(4) + JSON_OBJECT_SIZE(5);
DynamicJsonBuffer jsonAPIbuffer(bufferSize);
JsonObject& apitxbin = jsonAPIbuffer.createObject();
DynamicJsonDocument apitxbin(bufferSize);

apitxbin["Device"] = "ESP-RFID-Tool";
apitxbin["Firmware"] = version;
apitxbin["API"] = APIversion;

JsonObject& apitxbinary = apitxbin.createNestedObject("Transmission");
JsonObject apitxbinary = apitxbin.createNestedObject("Transmission");
int commacount=0;
for (int commalook=0; commalook<=api_binary.length(); commalook++) {
if (api_binary.charAt(commalook)==',') {
Expand All @@ -52,14 +51,15 @@ server.on("/api/tx/bin", [](){
else {
String API_Response="";
if (prettify==1) {
apitxbin.prettyPrintTo(API_Response);
serializeJsonPretty(apitxbin, API_Response);
}
else {
apitxbin.printTo(API_Response);
serializeJson(apitxbin, API_Response);
}
server.send(200, "application/json", API_Response);
delay(50);
jsonAPIbuffer.clear();
apitxbinary.clear();
apitxbin.clear();
apiTX(api_binary,api_pulsewidth,api_datainterval,api_wait);
}
});
Expand Down
Loading