M
M
mr-ZA2018-11-22 01:23:37
C++ / C#
mr-ZA, 2018-11-22 01:23:37

Explain in C++?

Hello everyone, I have a question regarding the notorious C++ jap. In short, I studied the base according to Datalam and Schildt, now the question is - how to apply C / C ++ in practice, how to go beyond writing theoretical programs? I opened other people's projects on Github, a lot is not clear. Especially with regards to system programming, writing various serious programs under Windows, does it turn out that you need to study the entire WinAPI? I would also like to combine knowledge of C ++ and, through debugging, for example, on IDAPro, learn how to debug programs and understand their structure in Assembler. But no such material was found. Thanks in advance for your guidance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Sorokin, 2018-11-22
@mr-ZA

1. Nobody writes in pure WinAPI. And even more so, there is no need to study it, you just need to have an idea of ​​​​how it works, and some specific solutions are described in the documentation - when you need it, then you will learn it.
2. To create applications, you will need to familiarize yourself with some kind of framework, whether it be cross-platform Qt or something more native for Windows.
3. If you do not touch the windows, then in order to go beyond the theoretical programs, you need to start writing such a non-theoretical program.
4. In order to understand the structure of programs in assembler, it would be nice, in addition to C ++, to study the assembler itself a little more, the principles of processor architecture, the principles of application architecture for a specific OS.
5. Debugging with IDAPro in the 21st century is extreme. If you debug your application in C ++, then you have its source codes, there are a lot of debuggers for specific languages ​​​​that are perfectly able to debug from source codes.

M
magdest, 2018-11-22
@magdest

Install MS VisualStudio, write C++ code, select any line of your code and press F9 (a red breakpoint will appear), run the F5 program, the program will stop at this breakpoint, then right-click on the line and select (To disassembled code) the assembler code of your program will appear.
Here, study.
The assembler manipulates processor registers, like reserved variable names, of a certain size (you can find them in Google...))).
VisualStudio X64 does not support assembly rates.
For x86, the code is as follows:
//========================================== ================================================= =====
namespace kodno {//namespace for unmanaged code.
//#pragma unmanaged //beginning of unmanaged code.
#pragma managed(push, off)//beginning of unmanaged code.
//function with parameters by reference through the & sign, allows you to return values ​​in each variable.
inline unsigned int func_asm(unsigned int &i1, unsigned int &i2)//inline copies the function to the place of its call, thereby making it local.
{
unsigned int i3;//variable for the result.
//------------------------------------------------ -------------------------------------------------- -------------------
//this is how the disassembler works: (this way you can calculate how the compiler passes values ​​by reference to variables):
// unsigned int i4 = i1;// for unmanaged code, reference variables should always be assigned to regular ones.
// unsigned int i5 = i2;//₽
/*
unsigned int i4 = i1;//for unmanaged code, reference variables should always be assigned to regular ones.
00B91477 mov eax, dword ptr[i1]
00B9147A mov ecx, dword ptr[eax]
00B9147C mov dword ptr[i4], ecx
unsigned int i5 = i2;//₽
00B9147F mov edx, dword ptr[i2]
00B91482 mov eax, dword ptr[edx]
00B91484 mov dword ptr[i5], eax
*/
//--------------------------------- -------------------------------------------------- ----------------------------------
_asm // x86 assembler start (32-bit registers)
{//before writing code in assembler, you need to save the processor registers, and restore them before exiting.
push eax // save the register (the first one entered, the last one should exit, the stack box is arranged like this.)
push ebx
push ecx
// get the value by reference:
push [i1] // in brackets [address] , so the value is taken at the address.
pop ecx //restore value from push [i1] to ecx register.
push [ecx] //since the link is a double pointer like double brackets[address[address]], I take it again.
pop eax//restore the value from push [ecx] to the eax register, thereby getting the real value passed by reference to the function..
push [i2]
pop ecx
push[ecx]
pop ebx
//or so, getting value by reference:
/*mov ecx, dword ptr[i1]
mov eax, dword ptr[ecx]
mov ecx, dword ptr[i2]
mov ebx, dword ptr[ecx] */
add eax, ebx //equivalent to EAX=EAX + EBX.
mov i3, eax //return value to variable.
//
pop ecx
pop ebx
pop eax//restore register (first in - last out)
}
i1 = i3;//return values ​​by reference.
i2 = i3;
return i3;//I return the value through the function.
}
//#pragma managed //beginning of managed code /CLR.
#pragma managed(pop)//end of non-managed code.
}
//---------------------------------------------- -------------------------------------------------- ----------------------------------------
unsigned int b3 = kodno::func_asm(b1 , b2);//function call from native code.
//=============================================== =================================================
/ CLR is a NET Framework machine, it has its own machine code called MANAGED, it has its own assembler called IL-Assembler.
And, pure code runs hardware on the computer, this code is called UNMANAGED.
VisualStudio C++/CLR allows you to write both UN_managed and Managed code in your program.
In order to use the X64 assembly code in Visual Studio, you need to tie it up as a separate module, but first practice with asm inserts (There is such an environment called Lazarus - so it accepts both x32 and x64 assembler inserts, as well as different assembly language syntaxes, but there is Pascal, which is also interesting in principle. You can do this: start with lazarus, then go to PascalABC.NET, then go to C #. Oh, in general, watch YouTube at high speed - you will develop lightning-fast thinking, everything is there for beginners, watch everything, the more you watch, the more associations, at first do not delve into, observe, understanding will come by the second viewing of the second author of the lectures - there will be something to compare with.))) exactly like that, otherwise your brain will have nothing to react with.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question