Bingxin knowledge of the source, in the matter less stagnant. — “Xin Xing Yuan Repair water Tank”
The only way to understand a system is to read the source code
The only way to fully understand a system is to read the system’s source code implementation! The same principle applies to an iOS programmer. Luckily we are now in a open source code to the good old days (here thanks to Richard Matthew stallman and the GNU project), many excellent library are presented in the form of the source code for everyone, even the iOS this closed systems are also under some pressure to open the partial source code (although the opening part is not necessarily the same) and real, That’s enough to give us a lot of enthusiasm for peeping into some of the implementation mechanisms. At present, there are a lot of articles on the network based on Apple’s open source to introduce the OC2.0 Runtime principle, runloop implementation mechanism and class +load method execution timing, etc.
When we wish to go farther, we find a mountain blocking our way. Because of the closed source nature of the system, we cannot read all the source code and core implementation. So should we just stop there?
The answer is NO!
Source code comes in both high-level and low-level forms. While we are blocked by higher-form source code, lower-form source code is still open for us to find the key and unlock it. What is the low-level source code? The answer is machine instructions!!
We know that any application source code that meets the rules of an operating system’S ABI will eventually be compiled and linked to a particular format of machine instructions and executed on the CPU. If a program’s high-level language implementation is its source code to a programmer, a program’s sequence of machine instructions is its source code to the CPU. It’s just that machine language is incredibly difficult to understand for many people.
One of the good things is that although machine language is obscure, our forefathers invented a mnemonic language called assembly language
Each command in assembly language corresponds to almost every machine instruction, but it increases the readability of programs so that we are not faced with a string of dry binary numbers. Don’t you see the assembly language scenario in many decompiler tools and even in XCODE? It is the advent of assembly language that makes reading and analyzing source code a big step forward!
When you are proficient in assembly language! All the code you see will be source code!
Some say that assembly language is still more obscure than high-level languages, but this is not always true. Qiu Bojun and Lei Jun, who remember the first generation of Programmers in China, first came into contact with assembly language, and they were all programmed in assembly language. Assembly language is so close to machine language that everyone feels intimidated. It is true that these low-level languages do not conform to natural semantics and syntactic rules as much as the higher-level languages we use, but they have the advantage of being very straightforward and simple. Assembly isn’t that complicated when you dig into it. In a program’s machine instructions, most of the instruction code does nothing but calculate and move data between registers and between registers and memory. In high level languages we can define very personalized variables and unlimited variables, whereas in low level languages we can only use a limited number of registers as temporary variables and access memory addresses like arrays.
The following diagram shows the difference between machine language and assembly and high-level languages that implement a snippet of accumulative functionality:
If you look at the code above, you may know what it means in high-level language. If you look at the code in assembly language, you may know what it means a few times. If you look at the code in machine language, you may not know what it means.
Having said that, some might ask what assembly language has to do with my desire to get to the bottom of iOS!
Good question! The answer is the closed nature of iOS system, which makes it impossible for us to pry out the underlying implementation of many systems. When we are troubled by a certain problem or an implementation principle but can not solve it, we can decompile the system and get assembly language to understand and read its implementation principle. When we are faced with a sudden runtime crash, we can read the assembly language to understand its cause. When there is no context for our crash, we can use assembly language to locate and solve the problem. When we want to solve a problem and want to do dynamic patch we can also use assembly language to complete; When we want to hook some applications on a jailbroken machine, we can do it through assembly language. When we want to maximize the performance of our systems and certain critical parts of the code we can use assembly language; When we want to be a hacker we can use assembly language… There are so many things we can do with assembly language. Today’s application programming languages are more and more advanced language development, and appear to be simple, intelligent, resulting in a lower and lower threshold of entry. The more advanced the language is, the more encapsulation it is away from the underlying implementation, the less you can pry, so the low-level language is still very much alive and necessary. IOS runtime source code for objc_msgSend is written in assembly language! The goal is to maximize the performance of the function.
Therefore, mastering and understanding assembly language knowledge is not only a key to the bottom of iOS system but also to the bottom of all systems. When you master or understand some basic assembly language knowledge and skills, you will open the door to everything is source code. It is worth mentioning that I am not going to introduce everything about assembly in detail, in fact, as long as we understand some basic assembly knowledge can be very convenient to help us solve a lot of things.
Stay tuned for the next post:An introduction to the underlying instruction set of iOS
According to the author
Always wanted to write some knowledge points about the bottom of the system, and brewing for a long time. And then talking to other people, why don’t you do a series? You don’t have to write everything at once before publishing it. I heard that and thought it made a lot of sense, so I thought I’d share a series of articles about the underlying iOS system. This is the beginning of the first introduction, although their level is also very general, but think about their own or some accumulation, even if there is a problem or there is a mistake can also be published for everyone to comment and blame it. The ultimate goal is common progress, as long as this point is achieved I will be satisfied. In the following days, I will try to make a series of weekly expansions of the underlying iOS system in this series. First, I will give a general outline. Of course, there may be changes in the future:
directory
- Go deep into the assembly language of iOS
- An introduction to the underlying instruction set of iOS
- In-depth introduction to iOS XCODE support for assembly
- Deep into the CPU register of the iOS system
- Deep into the iOS system of machine instruction introduction
- Deep into the iOS system of the bottom of the assignment instruction
- An introduction to function calls at the bottom of iOS
- In-depth introduction of other common commands in the iOS system
- An introduction to the underlying function stack of iOS
- Deep into the bottom of the iOS system function stack (2) introduction
- In-depth introduction to the implementation principle of the iOS system
- The introduction of assembly language embedded in the high-level language of iOS system
- In-depth introduction to common assembly code snippets of the iOS system
- In-depth introduction to the implementation of various attributes and modifications in OC of iOS system
- An introduction to the ABI at the bottom of iOS
- An introduction to the process of compiling links at the bottom of iOS
- An introduction to the executable structure at the bottom of iOS
- In – depth introduction to iOS mach-O file format
- An in-depth introduction to the iOS image file manipulation API
- An in-depth introduction to the well-known load Command structure of iOS
- An introduction to the application loading process at the bottom of iOS
- In-depth static library introduction of iOS system
- In-depth introduction of dynamic library of iOS system
- In-depth introduction to the underlying framework of iOS system
- In-depth introduction to the base of the iOS system
- An introduction to module function calls at the bottom of iOS
- An introduction to intermodule function calls at the bottom of iOS
- In-depth introduction to the dynamic construction of iOS machine instructions
- Deep into the bottom of iOS crash problem solution
- Deep into the bottom of the iOS system crash solution without context
- In-depth introduction to the implementation principles of common iOS tools and commands
- An introduction to the real OC class memory structure in iOS
Welcome to visit myMaking the addressandJane’s address book