mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
ADD: string functions (@merlokk)
This commit is contained in:
parent
e574e89553
commit
79dd43dbd2
2 changed files with 35 additions and 1 deletions
|
@ -118,7 +118,7 @@ void FillFileNameByUID(char *fileName, uint8_t *uid, char *ext, int byteCount) {
|
||||||
// printing and converting functions
|
// printing and converting functions
|
||||||
void print_hex(const uint8_t * data, const size_t len) {
|
void print_hex(const uint8_t * data, const size_t len) {
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i=0; i < len; ++i)
|
for (i=0; i < len; i++)
|
||||||
printf("%02x ", data[i]);
|
printf("%02x ", data[i]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
@ -681,4 +681,35 @@ extern int num_CPUs(void) {
|
||||||
extern void str_lower(char *s ){
|
extern void str_lower(char *s ){
|
||||||
for(int i=0; i < strlen(s); i++)
|
for(int i=0; i < strlen(s); i++)
|
||||||
s[i] = tolower( s[i] );
|
s[i] = tolower( s[i] );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace unprintable characters with a dot in char buffer
|
||||||
|
extern void clean_ascii(unsigned char *buf, size_t len) {
|
||||||
|
for (size_t i = 0; i < len; i++) {
|
||||||
|
if (!isprint(buf[i]))
|
||||||
|
buf[i] = '.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// replace \r \n to \0
|
||||||
|
extern void strcleanrn(char *buf, size_t len) {
|
||||||
|
strcreplace(buf, len, '\n', '\0');
|
||||||
|
strcreplace(buf, len, '\r', '\0');
|
||||||
|
}
|
||||||
|
|
||||||
|
// replace char in buffer
|
||||||
|
extern void strcreplace(char *buf, size_t len, char from, char to) {
|
||||||
|
for (size_t i = 0; i < len; i++) {
|
||||||
|
if (buf[i] == from)
|
||||||
|
buf[i] = to;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern char *strmcopy(char *buf) {
|
||||||
|
char * str = NULL;
|
||||||
|
if ((str = (char*) malloc(strlen(buf) + 1)) != NULL) {
|
||||||
|
memset(str, 0, strlen(buf) + 1);
|
||||||
|
strcpy(str, buf);
|
||||||
|
}
|
||||||
|
return str;
|
||||||
}
|
}
|
|
@ -144,4 +144,7 @@ extern uint64_t HornerScheme(uint64_t num, uint64_t divider, uint64_t factor);
|
||||||
extern int num_CPUs(void); // number of logical CPUs
|
extern int num_CPUs(void); // number of logical CPUs
|
||||||
|
|
||||||
extern void str_lower(char* s); // converts string to lower case
|
extern void str_lower(char* s); // converts string to lower case
|
||||||
|
extern void strcleanrn(char *buf, size_t len);
|
||||||
|
extern void strcreplace(char *buf, size_t len, char from, char to);
|
||||||
|
extern char *strmcopy(char *buf);
|
||||||
#endif
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue