IDA简易教程(10)

2019-08-28 23:47

// and we sell computer softwares

struct software_info_t { // a structure containing various bitfields

unsigned int plateform : 2; // 2 bits reserved for the plateform - plateforms can be combined (0x03) #define PC 0x1 // 0x01 #define MAC 0x2 // 0x02

unsigned int os : 3; // 3 bits reserved for the OS - OS can be combined (0x1C) #define WINDOWS 0x1 // 0x04 #define DOS 0x2 // 0x08 #define OS_X 0x4 // 0x10

unsigned int category : 2; // 2 bits reserved for the category - categories can't be combined (0x60)

#define DISASSEMBLY 0x1 // 0x20 #define RECOVERY 0x2 // 0x40 #define CRYPTOGRAPHY 0x3 // 0x60 };

struct software_t { software_info_t info; char name[32]; };

struct softwares_t { // a variable length structure to memorize our softwares long count; software_t softs[]; };

// generic products we're selling

enum product_category_t { // an enumerated type BOOK,

SOFTWARE,

HARDWARE // we actually don't sell hardware };

union product_u { // an union to contain product information depending on its category book_t book; software_t software;

// struct hardware_t hardware; // we actually don't sell hardware };

struct product_t { // a structure containing another structure long id;

product_category_t category; product_u p; };

// our data // ======== // our customers

customer_t customers[] = { // an initialized array to memorize our customers { 1, \ { 2, \ { 3, \ { 0 } };

// our products

book_t ida_book = { \

softwares_t softwares = // an initialized variable length structure { 3, {

{ { PC, WINDOWS|DOS, DISASSEMBLY }, \ { { PC|MAC, WINDOWS|OS_X, RECOVERY }, \ { { PC, WINDOWS, CRYPTOGRAPHY }, \ } };

#define PRODUCTS_COUNT 4

// our functions // =============

// check software information

int check_software(software_info_t software_info) {

bool valid = true;

if (software_info.plateform & PC) {

if (! (software_info.plateform & MAC) && (software_info.os & OS_X)) valid = false; // OS-X isn't yet available on PC ;) }

else if (software_info.plateform & MAC) {

if (! (software_info.plateform & PC) && ((software_info.os & WINDOWS) || (software_info.os & DOS)))

valid = false; // Windows & DOS aren't available on Mac... } else

valid = false; return valid; }

// check product category

int check_product(product_category_t product_category) {

bool valid = true;

if (product_category == HARDWARE) {

valid = false;

printf(\ }

return valid; }

// print customer information

void print_customer(customer_t *customer) {

printf(\customer->id, customer->name, customer->sex); }

// print book information

void print_book(book_t *book) {

printf(\book->title); }

// print software information

void print_software(software_t *software) {

printf(\software->name); // plateform

// we use 'if', as plateforms can be combined if (software->info.plateform & PC) printf(\

if (software->info.plateform & MAC) printf(\ printf(\ // OS

// we use 'if', as os can be combined if (software->info.os & WINDOWS) printf(\ if (software->info.os & DOS) printf(\

if (software->info.os & OS_X) printf(\ printf(\ // category


IDA简易教程(10).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:九九乘法口诀练习题(A4打印版)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: