Created
January 6, 2020 16:47
-
-
Save jotaki/bec5cb1808f077ef42eb6228e4c18ce5 to your computer and use it in GitHub Desktop.
get password into memory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <ctype.h> | |
#include <termios.h> | |
int main(void) | |
{ | |
char buf[BUFSIZ]; | |
register int input, len = 0; | |
struct termios t_orig, t_new; | |
int i; | |
tcgetattr(STDIN_FILENO, &t_orig); | |
t_new = t_orig; | |
t_new.c_lflag &= ~ECHO; | |
t_new.c_lflag &= ~ICANON; | |
tcsetattr(STDIN_FILENO, TCSAFLUSH, &t_new); | |
printf("Enter password: "); | |
fflush(stdout); | |
while((input = fgetc(stdin)) != '\n') { | |
buf[len++] = (input ^ 42); | |
if(len >= sizeof(buf)-1) | |
break; | |
} | |
printf("\n"); | |
fflush(stdout); | |
buf[len] = '\0'; | |
tcsetattr(STDIN_FILENO, TCSAFLUSH, &t_orig); | |
for(i=0;i<len;++i) { | |
printf("0x%02x (%c)", buf[i], isprint(buf[i]) ? buf[i] : '.'); | |
} | |
printf("\n"); | |
for(i=0;i<len;++i) { | |
printf("%c", buf[i] ^ 42); | |
} | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and read() can't use registers directly. (uses pointer to store buffer, which can't be a register)