mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
added a C sample of grabbing output
This commit is contained in:
parent
449eacdee5
commit
6e1cf6c0de
3 changed files with 71 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
gcc -o test test.c -I../../include -lpm3rrg_rdv4 -L../build -lpthread
|
gcc -o test test.c -I../../include -lpm3rrg_rdv4 -L../build -lpthread
|
||||||
|
gcc -o test_grab test_grab.c -I../../include -lpm3rrg_rdv4 -L../build -lpthread
|
||||||
|
|
3
client/experimental_lib/example_c/02run_test_grab.sh
Executable file
3
client/experimental_lib/example_c/02run_test_grab.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
LD_LIBRARY_PATH=../build ./test_grab
|
67
client/experimental_lib/example_c/test_grab.c
Normal file
67
client/experimental_lib/example_c/test_grab.c
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
#include "pm3.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
int pipefd[2];
|
||||||
|
char buf[8196 + 1];
|
||||||
|
size_t n;
|
||||||
|
|
||||||
|
if (pipe(pipefd) == -1) {
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int pid = fork();
|
||||||
|
if (pid == -1) {
|
||||||
|
perror("fork");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// child
|
||||||
|
if (pid == 0) {
|
||||||
|
printf("[INFO] inside child\n");
|
||||||
|
|
||||||
|
// Redirect stdout to the write end of the pipe
|
||||||
|
dup2(pipefd[1], STDOUT_FILENO);
|
||||||
|
|
||||||
|
close(pipefd[0]); // Child: close read end of the pipe
|
||||||
|
close(pipefd[1]); // Close original write end
|
||||||
|
|
||||||
|
pm3 *p;
|
||||||
|
p = pm3_open("/dev/ttyS9");
|
||||||
|
//printf("Device: %s\n", pm3_name_get(p));
|
||||||
|
|
||||||
|
// Execute the command
|
||||||
|
pm3_console(p, "hw status");
|
||||||
|
pm3_close(p);
|
||||||
|
_exit(-1);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
printf("[INFO] inside parent\n");
|
||||||
|
// Parent: close write end of the pipe
|
||||||
|
close(pipefd[1]);
|
||||||
|
|
||||||
|
// Read from the pipe
|
||||||
|
while (1) {
|
||||||
|
n = read(pipefd[0], buf, sizeof(buf));
|
||||||
|
if (n == -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (n == 0) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
// null termination
|
||||||
|
buf[n] = 0;
|
||||||
|
if (strstr(buf, "Unique ID") != NULL) {
|
||||||
|
printf("%s", buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close read end
|
||||||
|
close(pipefd[0]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue