In: Computer Science
You will be traversing structures as part of the project. However, as practice, we will traverse some structures, for which the source code is already known to us, to remove some of the ambiguity inherent in dealing with undocumented or under-documented Windows structures. Here we know the structures and what their members are.
The task for this assignment is to “fill in the blanks” in the in-line Assembly, so that the requested data is populated with the appropriate information. To do this, you must engage in experimentation with traversing structures to discover the correct values.
#include <stdio.h>
#include <windows.h>
struct address {
char street1[20]; // +0
char zip[20]; // +0x14
char state[20]; // +0x28
};
struct college {
int id; // +0
char name[40]; // +0x4
struct address address_info; // + 0x2C
};
struct personal {
int id;
char nickname[20];
int age;
char gender[4];
};
struct student {
int id; // +0x0
char fname[20]; // +0x4
char lname[20]; // +0x18
struct college college_info;// +0x2C
struct personal personal_info; // +0x?? What is the size of the COLLEGE struct?
};
int main(int argc, char argv[], char envp[]) {
char*var = NULL;
struct student student1 = { 1, "Howareyou", "you", 1101, "System Eng", "111 Ave", "55442", "IO", 1,"Howareyou", 40,'m'};
printf("[*] Student Name: %s\n", student1.personal_info.gender);
_asm {
lea eax, student1
lea eax, [eax + 0x30]
mov var, eax
}
printf("[*] School name: %s\n", var);
_asm {
lea eax, student1
lea eax, [eax + 0x0]
mov var, eax
}
printf("[*] Street: %s\n", var);
_asm {
lea eax, student1
lea eax, [eax + 0x0]
mov var, eax
}
printf("[*] State: %s\n", var);
_asm {
lea eax, student1
lea eax, [eax + 0x0]
mov var, eax
}
printf("[*] Nickname: %s\n", var);
}
Note: Done accordingly. Please comment for any problem. Please Uprate. Thanks.
#include <stdio.h>
#include <windows.h>
struct address {
char street1[20]; // +0
char zip[20]; // +0x14
char state[20]; // +0x28
};//size = 0x3C
struct college {
int id; // +0
char name[40]; // +0x4
struct address address_info; // + 0x2C
};//size=0x68
struct personal {
int id; // +0
char nickname[20];// +0x04
int age; //+0x18
char gender[4]; //+0x1C
};//size=0x20
struct student {
int id; // +0x0
char fname[20]; // +0x4
char lname[20]; // +0x18
struct college college_info;// +0x2C
struct personal personal_info; // +0x94 What is the size of the COLLEGE struct?
};//size=B4
int main(int argc, char argv[], char envp[]) {
char*var = NULL;
struct student student1 = { 1, "Howareyou", "you", 1101, "System Eng", "111 Ave", "55442", "IO", 1,"Howareyou", 40,'m'};
printf("[*] Student Name: %s %s\n", student1.fname,student1.lname);
_asm {
lea eax, student1
lea eax, [eax + 0x30]
mov var, eax
}
printf("[*] School name: %s\n", var);
_asm {
lea eax, student1
lea eax, [eax + 0x58]
mov var, eax
}
printf("[*] Street: %s\n", var);
_asm {
lea eax, student1
lea eax, [eax + 0x80]
mov var, eax
}
printf("[*] State: %s\n", var);
_asm {
lea eax, student1
lea eax, [eax + 0x98]
mov var, eax
}
printf("[*] Nickname: %s\n", var);
system("pause");
}
Output: