Why do we have Rust and Go???
Languages like C/C++ are general purpouse programming languages used widely for competative programming. Whereas Languages like rust and go are development oriented language or a procedural programming language. The language Go was developed by Google and launched in 2009. The language was developed to solve large scale problems faced by google as an open source programming language.
The language is platform independant like Java and hence can be compiled on any platform and is incredibly easy to learn as it is a lot like python in terms of syntax. These languages are Scripting languages are extremely great for writing services.
Speaking of GoLang
- A high performance language , providing great efficiency like C/C++.
- Provides high concurrency as in Java.
- Concurrency is the efficiency of the programme to utilize the untapped capabilities of the OS and the machine hardware. Eg. threading to enable faster execution of the programme.
- Easy to learn and fun to code like python : ) !!
Summing it up if you’re looking for scalability and efficiency in a programming language you should probably consider Go!
Go is a win win for the user as well as the processor in terms of efficiency and understandability for the developers !!
| GoLang | C++ |
| It does not use header files instead of header file go use packages. | It contain header file and does not contain package. |
| It does not support implicit type conversion. | It support implicit type conversion. |
| Go use panic and recover for resolving error. | C++ use try, catch, and throw for resolving error. |
| It does not have while or do-while statements. | It have while or do-while statements. |
| It is more strong typed as comparison to C++ language. | It is less strong typed as compare to Go language. |
| Go contains goroutines and channel. | C++ does not contain goroutines and channel. |
| It does not support inheritance. | It supports Inheritance |
Basics of GoLang
Go is pretty much a combo of C/C++ and python in terms of syntax.
Example 1:
“Hello, World” in Go!!
To compile:
$ go build <file name> -o <outfile>
$ ./outfile
Example 2:
Just to Familiarise with the datatypes I tried this example and you can see its quite similar to python.
The output is as follows:
Data types in Go:
As far as reversing a Go binary is concerned as you may have noticed in example 2, the initialisation of variables is not done as it is done in python where the data type need not be mentioned and therefore everytime a variable is initialised it is checked with all the available types in this structure below to determine the type.
- Bool
- String
- Int 8 ,16 ,32 ,64
- Uint8 , uint16, uint32 , uint64
- Complex32, complex64
- To name a few…
So that’s all you need to know about go language for now !
Let’s get started with reversing
Here for analysing the binary , I am using IDA pro .
Our simple hello World programme has been compiled to ~1800 functions which is not very ideal for reversing. And hence , figuring out our main function is Important.z
Structure of a Go binary
The main of a Go binary is called the “ main.main ”
On further digging we figure out the actual main function that we have written resides in the main.main.
And in the main we can see the call being made to the function Println().
Now lets move on to solving a simple custom challenge.
Challenge Description: make the binary print 1 . : )
Now, since we know what to do first, lets get straight to the main.main function and see the decompilation on IDA!
So our required input is : thebadcat
Now moving onto Rust.
Rust is a more innovative system-level language. Creators produced this language with safety in mind. Notably, they aimed to beat C++ by offering safer memory management while keeping their speed advantage. Rust will lead to the production of fast software.The language frequently supports projects aimed at high-security and high-concurrency .
Rust is also largely known as a memory safe Language
Advantages and Disadvantages :
| Pros | Cons |
| Highly safe[memory safe language] | Not very friendly in terms of syntax |
| High speed of execution, almost as much as C/C++ | You can’t develop code as ‘fast’ as scripting languages like Python or Ruby |
| High Concurrency | The binaries produced by rust compiler are larger compared to C/C++ |
| High level of abstraction |
Now let’s analyse the binary:
When you run the binary on IDA, first you see the main and on looking at the graph it is sort of like the libc_start function on C binaries which call the main. And similarly here you can see the highlighted function being called is our actual main function that we wrote.This is what we’ll be analysing next.
So this is the decompilation of our main which clearly shows what the entire programme does , ie , initialises the count , add 1, and prints the value of count till the value of count hits 20,
Now let’s talk about the stack frames in Rust and Go.
The normal C stack frame:
The normal stack frame -Segmented Stack Frame
The stack frame implemented by C binaries where the stack grows from the top, as each new function gets called a new stack frame is created where the local variables are allocated space on the top of the stack -Segmented Stack frames
Stack Frames in Rust and GoLang:
Go provides a light and smart goroutines management. Light because the goroutine stack starts at 2Kb only, and smart since goroutines can grow / shrink automatically according to our needs.
This default stack size is sometimes not enough to run our program. This is when Go automatically adjusts the size of the stack
Function calls in Go binaries
In Go binaries , when a function gets called ,it actually accepts any amount of data and leaves it to the compiler to check the type and length etc of the arguments passed.
And on analysing , the return value wasn’t on any of the registers , instead the stack held the return value
So here ;
Split Stack and Stack Copying:
So this programme simply calls the functions a,b,c and prints a line…
Stack copying is a lot like , multiple segmented stacks. The Go routine is running along using the stack space and when it runs out, it hits the stack overflow check and gets copied to a bigger stack space.
However, instead of having a link back to the previous segment, it creates the new segment with double the size and copies the old segment into it. This means that when the stack shrinks back to its old size, the runtime doesn’t have to do anything. Shrinking is now a free operation. Additionally, when the stack grows again, the runtime doesn’t have to do anything. We just reuse the space that we allocated earlier.
Thank You 🙂









