Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Login function
- inline asm {
- push r11
- push r4
- mov sp, r4
- add #0x4, r4
- add #0xffd8, sp
- mov.b #0x0, -0x6(r4)
- mov.b #0x8, -0x19(r4)
- mov.b #0x10, -0x18(r4)
- }
- puts("Authentication now requires a username and password.");
- /* Technically this could probably be expanded to include the str being put into memory
- *
- * (char *)0x4484 = "Authentication now requires a username and password."
- * puts((char *)0x4484)
- *
- */
- puts("Remember: both are between 8 and 16 characters.");
- puts("Please enter your username:");
- // get input from the user, up to 0x63 (dec 99) characters, and store it in adr 0x2404
- getsn((char *)0x2404, 0x63)
- // print the user's input
- puts(char *)0x2404);
- // copy that input to 0xffd6 using strcpy
- strcpy((char *)0xffd6, (char* )0x2404);
- puts("Please enter your password:");
- // get input from the user, up to 0x63 (dec 99) characters, and store it in adr 0x2404
- getsn(char *)0x2404, 0x63);
- // print the user's input
- puts((char *)0x2404);
- // copy that input to 0xffe9 using strcpy
- // just a note: ffe9 - ffd6 = 0x13 or dec 19 -> that's the length between where the
- // username and password are stored
- strcpy((char *)0xffe9, (char* )0x2404);
- inline asm {
- mov r11, r15
- mov r4, r14
- add #0xffe8, r14 // r14 = 43b4
- }
- // basically what I'm trying to show here is if the value at the first byte at the
- // address in r14 isn't null, increase the address by one and move onto the next character and
- // check if that's null
- void* register14 = 0x43b4; // this is just a placeholder variable for r14, just to visualize
- label1:
- if ((char *)register14 != 0x00) {
- register14++;
- goto label1;
- }
- inline asm {
- mov r14, r11 // r11 = r14, so r11 = the address of the null byte at the
- // end of the username string
- sub r15, r11 // r11 = r11 - r15 -> the difference between the addresses
- // which gets stored in r11
- mov.b -0x18(r4), r15 // move the value at r4 - 0x18 into r15
- // I looked up the MSP430 instruction set, and sxt is "Sign extend 8 bits to 16"
- // does that make more space available to be stored in r15..?
- // Seems like this is for the username
- sxt r15
- cmp r15, r11 // r11 - r15 -> if r15 < r11 then set the carry
- // cmp in msp430 = arg2 - arg1
- // carry can be set when the result is negative,
- // as I found on stackoverflow -- ask me for link
- // if needed
- jnc #0x45fa <login+0xaa> // branch off and continue code like normal
- // if the carry flag was set, stop the program
- mov &0x2400, r15
- call #0x4728 <puts>
- br #0x4440 <__stop_progExec__>
- mov.b -0x19(r4), r15
- // Same thing above, but for the password
- sxt r15
- cmp r15, r11 // maybe if the password is smaller than the username,
- // continue like normal?
- jc #0x4610 <login+0xc0> // jump if carry flag was set, and continue like normal
- // if the carry flag wasn't set, stop the program
- mov &0x2402, r15
- call #0x4728 <puts>
- br #0x4440 <__stop_progExec__>
- mov.b #0x0, -0x2c(r4) // move a null byte into the address of r4 - 0x2c
- mov #0xffd4, r15 // set r15 to 0xffd4, which is by the username
- add r4, r15 // add the value inside r4 to r15..?
- push r15 // push the username string onto the stack
- mov r4, r15
- add #0xffe9, r15 // set r15 a little further in memory, where the password is stored
- push r15 // push the password string onto the stack
- add #0xffed, r15 // move further into memory for the next string?
- push r15 // push the value in r15 to the stack
- push #0x7d
- call #0x46c4 <INT> // INT call to test if password is correct
- // Takes two arguments, which in this case is probably
- // the most recent `push r15`, which is the username? and 0x7d, or
- // the first two things on top of the stack, which is
- // the username? and the password
- add #0x8, sp // move the stack pointer by 0x8
- }
- // next up is some sorta pseudocode, but it's the best way I can illustrate it in C
- // (this starts at 4634 in the microcorruption disassembly)
- char *str;
- if ((r4 - 0x2c) == 0x00) {
- str = "That password is not correct.";
- } else {
- str = "Access Granted";
- unlock_door();
- }
- puts(str);
- if ((r4 - 0x6) != 0) {
- puts((char *)0x2400); // print the password
- inline asm {
- br #0x4440 <__stop_progExec__> // quit the program
- }
- } else {
- inline asm {
- add #0x28, sp // add 0x28 to the stack pointer
- pop r4 // pop out values in r4 and r11
- pop r11
- }
- }
- return; // Done!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement