月度归档:2020年04月

CSAPP-Lab:Bomb Lab

实验内容下载地址:http://csapp.cs.cmu.edu/3e/labs.html


目录:

  1. Data Lab
  2. Bomb Lab
  3. Attack Lab
  4. Buffer Lab (IA32)
  5. Architecture Lab
  6. Architecture Lab (Y86)
  7. Cache Lab
  8. Performance Lab
  9. Shell Lab
  10. Malloc Lab
  11. Proxy Lab

描述:

  • A “binary bomb” is a program provided to students as an object code file. When run, it prompts the user to type in 6 different strings. If any of these is incorrect, the bomb “explodes,” printing an error message and logging the event on a grading server. Students must “defuse” their own unique bomb by disassembling and reverse engineering the program to determine what the 6 strings should be. The lab teaches students to understand assembly language, and also forces them to learn how to use a debugger. It’s also great fun. A legendary lab among the CMU undergrads.Here’s a Linux/x86-64 binary bomb that you can try out for yourself. The feature that notifies the grading server has been disabled, so feel free to explode this bomb with impunity. If you’re an instructor with a CS:APP account, then you can download the solution.

    实验提供了一个二进制文件bomb,当它运行的时候,他会提示用户输入六个不同的字符串,如果任意一个错误,它就会bomb。学生必须查看他的反汇编代码,然后逆向出6个字符串分别是什么,这个实验教会学生理解汇编语言,也促使他们学习如何使用调试器。

 

2020-4-16 English Reading.

阅读打卡 Reading Record。

第一篇阅读:大概就是美国的小公司过得非常困难,天天申请某个特殊计划的贷款,贷款的太多了,现在国会还没批下来

The Small Business Administration said Monday that it reached the $349 billion lending limit for the program. Thousands of small business owners whose loans have not yet been processed must now wait for Congress to approve a Trump administration request for another $250 billion for the program.

source:https://time.com/5822511/paycheck-protection-program-hold/

 

第二篇阅读:

数码圈的新闻Apple 发布了新手机 新版 iPhone se

Apple’s New iPhone SE Offers Most of the Features at a Fraction of the Price

Most of the Features at a Fraction of the price 很低的价格  大多数的Feature

原文:https://time.com/5821625/apple-se-low-cost-smartphone/

2020-4-14 English Reading

Reading record. source:https://time.com/5819878/smithfield-pork-plant-closes-coronavirus/


The world’s biggest pork producer is shuttering a major U.S. plant indefinitely after a coronavirus outbreak among employees, with the company warning that closures across the country are taking American meat supplies “perilously close to the edge” of shortfalls.

继续阅读

2020-4-13 English Reading.

Reading record.source:https://time.com/5819795/opec-barrel-cut-coronavirus/


DUBAI, United Arab Emirates — OPEC, Russia and other oil-producing nations on Sunday finalized an unprecedented production cut of nearly 10 million barrels, or a tenth of global supply, in hopes of boosting crashing prices amid the coronavirus pandemic and a price war, officials said.

继续阅读

2020-4-12 English Reading.

Reading Record. source:https://time.com/5819074/federal-reserve-fed-coronavirus-lending/


The Federal Reserve may not be done with its all-out blitz to help the U.S. economy survive a coronavirus-induced shutdown, even after launching an unprecedented $2.3 trillion in lending programs.

The central bank used up only about 40% of the as much as $454 billion in seed capital that Congress provided it in extending help to small and mid-sized businesses, state and local governments and some risky corners of the financial markets on Thursday. 继续阅读

2020-4-11 English Reading.

Reading Record.

srocue:https://time.com/5819080/unemployment-coronavirus/

Economists expect the U.S. to suffer its largest-ever contraction this quarter and the unemployment rate to soar to a post-Depression record, followed by a recovery that will be moderate and drawn out.

Gross domestic product will plummet an annualized 25% from April through June after a smaller setback in the first quarter and the jobless rate will hit 12.6%, the highest since the 1940s, according to the median forecasts in Bloomberg’s monthly survey of 69 economists.

继续阅读

2020-4-9 English Reading.

Reading Record

source:https://time.com/5817083/jack-dorsey-pledges-1-billion-coronavirus-relief/

Jack Dorsey is devoting $1 billion of his stake in Square Inc., the payments firm he co-founded, to help fund the coronavirus relief effort.

“After we disarm this pandemic, the focus will shift to girl’s health and education, and UBI,” Dorsey said Tuesday in a tweet, referring to universal basic income. The pledge represents about 28% of his wealth, he said.

继续阅读

CSAPP-Lab:Data Lab

今天开坑写一个系列,记录自己做11个CSAPP配套Lab的过程。

本帖为第一个实验,Data Lab。

实验内容下载地址:http://csapp.cs.cmu.edu/3e/labs.html


目录:

  1. Data Lab
  2. Bomb Lab
  3. Attack Lab
  4. Buffer Lab (IA32)
  5. Architecture Lab
  6. Architecture Lab (Y86)
  7. Cache Lab
  8. Performance Lab
  9. Shell Lab
  10. Malloc Lab
  11. Proxy Lab

1.实验文件

实验文件解压后 有一个datalab-handout文件夹,里面有很多c文件,我们只需要在 bits.c里面编写程序,然后运行评测程序即可。

2.使用方法

bits.c文件里面有许多空函数,我们的工作就是根据函数的描述把空函数补充完整。
补充完整后,进行编译,使用make命令即可,make编译无错误后,运行btest程序./btest即可进行评测。

只测试单个函数:
./btest -f [函数名]

指定参数
./btest -f [函数名] -1 [参数1] -2 [参数2] -3……

输出调试
可以直接在bits.c文件里面调用printf方法输出调试信息,不需要包含stdio.h头文件。

3.实验内容:

//1
/* 
 * bitXor - x^y using only ~ and & 
 *   Example: bitXor(4, 5) = 1
 *   Legal ops: ~ &
 *   Max ops: 14
 *   Rating: 1
* bit异或
* 要求只用~和&完成异或操作
* 思路:第一题比较简单,任何逻辑操作都可以用~和&表达,异或也是,
* 去查一下亦或的等价表达式,用摩根公式简化一下即可 */ int bitXor(int x, int y) { int a = ~(~x & y); int b = ~( x & ~y); int c = ~( a & b); return c; } /* * tmin - return minimum two's complement integer * Legal ops: ! ~ & ^ | + << >> * Max ops: 4 * Rating: 1
* 返回补码表达的最小值
* 根据补码的知识,补码的最小值就是1000000……000B */ int tmin(void) { return 1<<31; } //2 /* * isTmax - returns 1 if x is the maximum, two's complement number, * and 0 otherwise * Legal ops: ! ~ & ^ | + * Max ops: 10 * Rating: 1
* 检验参数x是否是补码最大值
* 思路,补码最大值是0111……1111 用~(1<<31))得到0111……111 然后和x进行一下亦或操作即可,如果完全一直则得0,取反为1 */ int isTmax(int x) { return !(x^(~(1<<31))); } /* * allOddBits - return 1 if all odd-numbered bits in word set to 1 * where bits are numbered from 0 (least significant) to 31 (most significant) * Examples allOddBits(0xFFFFFFFD) = 0, allOddBits(0xAAAAAAAA) = 1 * Legal ops: ! ~ & ^ | + << >> * Max ops: 12 * Rating: 2 */ int allOddBits(int x) { int nX = ~x; return !( (nX&0xAA) | (nX&(0xAA<<8)) | (nX&(0xAA<<16)) | (nX&(0xAA<<24))); } /* * negate - return -x * Example: negate(1) = -1. * Legal ops: ! ~ & ^ | + << >> * Max ops: 5 * Rating: 2 */ int negate(int x) { return (~x)+1; } //3 /* * isAsciiDigit - return 1 if 0x30 <= x <= 0x39 (ASCII codes for characters '0' to '9') * Example: isAsciiDigit(0x35) = 1. * isAsciiDigit(0x3a) = 0. * isAsciiDigit(0x05) = 0. * Legal ops: ! ~ & ^ | + << >> * Max ops: 15 * Rating: 3 */ int isAsciiDigit(int x) { int a = !(!(x>>8));//验证高24位是否全为0(符合要求), int b = !(!(0x30^(x&0xF0))); int c1 = (0x08&x)>>3; int c2 = (0x04&x)>>2; int c3 = (0x02&x)>>1; int c = (c1 & c2) | (c1 & c3);//如果是0表示 低四位符合要求 // printf("x:0x%x a:0x%x b:0x%x c:0x%x c1:0x%x c2:0x%x c3:0x%x\n",x,a,b,c,c1,c2,c3); return !(a | b | c); } /* * conditional - same as x ? y : z * Example: conditional(2,4,5) = 4 * Legal ops: ! ~ & ^ | + << >> * Max ops: 16 * Rating: 3 */ int conditional(int x, int y, int z) { int a = ((!(!x))<<31)>>31; return (y&a) | (z&~a); } /* * isLessOrEqual - if x <= y then return 1, else return 0 * Example: isLessOrEqual(4,5) = 1. * Legal ops: ! ~ & ^ | + << >> * Max ops: 24 * Rating: 3 */ int isLessOrEqual(int x, int y) { int x_sign = x>>31&1; int y_sign = y>>31&1; int a = x_sign & (!y_sign); int b = !(x_sign^y_sign); int c = b & ((x+~y)>>31 & 1); return a | c; } //4 /* * logicalNeg - implement the ! operator, using all of * the legal operators except ! * Examples: logicalNeg(3) = 0, logicalNeg(0) = 1 * Legal ops: ~ & ^ | + << >> * Max ops: 12 * Rating: 4 */ int logicalNeg(int x) { int x_sign = (x>>31) & 1; int myx = x&(~(1<<31)); int a = (myx+~0)>>31; return (a & ((~x_sign)&1)); } /* howManyBits - return the minimum number of bits required to represent x in * two's complement * Examples: howManyBits(12) = 5 * howManyBits(298) = 10 * howManyBits(-5) = 4 * howManyBits(0) = 1 * howManyBits(-1) = 1 * howManyBits(0x80000000) = 32 * Legal ops: ! ~ & ^ | + << >> * Max ops: 90 * Rating: 4 */ int howManyBits(int x) { int b16,b8,b4,b2,b1,b0; int sign=x>>31; x = (sign&~x)|(~sign&x);//如果x为正则不变,否则按位取反(这样好找最高位为1的,原来是最高位为0的,这样也将符号位去掉了) // 不断缩小范围 b16 = !!(x>>16)<<4;//高十六位是否有1 x = x>>b16;//如果有(至少需要16位),则将原数右移16位 b8 = !!(x>>8)<<3;//剩余位高8位是否有1 x = x>>b8;//如果有(至少需要16+8=24位),则右移8位 b4 = !!(x>>4)<<2;//同理 x = x>>b4; b2 = !!(x>>2)<<1; x = x>>b2; b1 = !!(x>>1); x = x>>b1; b0 = x; return b16+b8+b4+b2+b1+b0+1;//+1表示加上符号位 }

2020-4-6 English Reading.

Price Gouging

Though Trump didn’t detail his concerns with 3M, White House trade adviser Peter Navarro said at a Thursday news conference that the administration has had concerns about whether the company’s production around the world is being delivered to the U.S.

Dallas Mavericks owner Mark Cuban said he has been in touch with the White House about supposed price gouging by resellers of 3M masks and accused the company of not doing enough to ensure they end up in the hands of medical professionals.

3M has previously said it hasn’t changed the prices it charges and can’t control the prices dealers or retailers charge for their products.

The president is facing mounting pressure from governors and congressional Democrats to use the Korean War-era defense law that gives him sweeping powers to force companies to produce personal protective equipment and ventilators that are in short supply. More than 236,000 people in the U.S. have contracted the virus and more than 5,600 have died, according to Johns Hopkins University.

Health-care officials and governors have said that in some localities, people may die because there won’t be enough ventilators for the growing number of patients who need them.

New York Governor Andrew Cuomo on Thursday said the state would run out of ventilators in six days at the current rate. “If a person comes in and needs a ventilator and you don’t have a ventilator, the person dies,” Cuomo told reporters.

Ventilator Shortage

Trump said at the White House later on Thursday that “thousands” of ventilators are in production. But he faulted states for failing to stockpile them, deflecting criticism of his administration.

“We’re not an ordering clerk, we’re a backup,” Trump said. “The states have to stock up. It’s like one of those things, they waited.”

He has expressed reluctance to use the defense law, comparing it to nationalizing industries. He has said he prefers to use threats to invoke the act as leverage to force companies to comply with demands to manufacture equipment.

The president, however, ordered General Motors Co. last Friday to make ventilators by directing the U.S. health secretary, under the defense law, to require the automaker to do so.

—With assistance from Ellen Proper.

source:

https://time.com/5815155/3m-face-masks-trump/