Polymorphic engines in C or C++ [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I stumbled across polymorphic engines and I don't know anything about them. However, I am curious about how they are written. Every example that I've looked up writes them in assembly, my assembly is not good at all; I know just a few instructions here and there but not that well. On the other hand, I am good in C and C++.
I am familiar with the concept of polymorphism in C++ but after reading about polymorphic engines, I am assuming that they are different from the polymorphism in C++.
How can techniques such as using virtual keyword in C++ be used to obfuscate or encrypt the code in an application?

If a program has to be modified you can go either modifying the source code or modifying the compiled executable.
The first approach is awful (in my opinion) because:
A source file is subject to a lot of optimizations in the compilation processes. So two source files slightly different from each other could produce the same object code.
If you need your program to be self modifying you will have to carry with all the tools needed to build it. (Something like carrying a candy factory with you just for the case you want a candy of a different flavor in your trip)
...
Notice that I'm talking here about compiled languages as the use of C or C++ in your question suggests. For interpreted languages the first approach is the obvious one.
In your case, the second makes more sense but it is strictly related to the machine code of the target machine.
So my point is: if you want to implement a program or routine that is able to produce a modified version of other program or a modified version of itself you can implement it in Assembly, C, C++ or any other language but in all cases you have to be proficient in your target machine's assembly language and machine code.
I recommend you to research more. This topic is broad. In the case you decide to go on, I can say that Assembly won't be the biggest dragon to beat.

Related

Why Rust is faster than Ocaml in Performance, Even though first Rust compiler was implemented in Ocaml [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I found that the initial compiler for Rust language was written in Ocaml. So what i thought was that Rust would be similar to Ocaml performance wise. But when I look at benchmarks Ocaml vs C++ and Rust vs C++ and compare Ocaml with Rust. It gives me what...?, but how...?
How can Rust be more faster in performance compared to Ocaml even though it derived from Ocaml?
and then it gives rise to an another question ???
Can a compiler based language derived from C be faster than C itself performance wise?
The compiler simply generates the (machine) code that is going to be run. The resulting program doesn't run on top of the language its compiler was written in. Hence, there is no correlation between performance of a particular implementation and the language it was implemented in.
The language the compiler is written on just affects the speed of the compiler and thus the compile time. It has no effect on the speed of the compiled program, since that depends only on the generated machine code.
In principle you can write a C++ compiler with brainfuck, run the compiler in some really slow brainfuck interpreter and have the output be the most sophisticated and efficient machine code ever. And thus your final program will be lightning fast.
I suggest you read up on compiler bootstrapping, it's a fascinating topic:
en.wikipedia.org/wiki/Bootstrapping_(compilers)
https://stackoverflow.com/questions/193560/writing-a-compiler-in-its-own-language

Is there a C++ dialect without "standard bugs"? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Today I was listening to a number of talks about dark sides of C++. One them was held by a man who was participating in the creation of the new C++ standard (Nikolai Jossutis). I'm fascinated by the many things in language, which make it easier to misuse. And for me personally it seems that C++ is actually fine if there wasn't backward comparability, which didn't allow to fix "bugs in the standard".
Hypotethically let's say I want an language dialect of C++ that is not backward compatible with the standard C++. It removes components considered dangerous, it doesn't compile something which is almost always results in UB.
I don't want to give any concrete examples, but I'm fine with everyhing which will make code safer. I already treat warnings as errors in the strictiest provided by the compiler way and use static analysis, along with ASan, etc..
UPD: I'm speaking about something very similar to C++ and it's characteristics. If I think about Java, it isn't suitable for me, because of VM. I'm asking about dialect of C++, not very different language, like Java or Rust. Rust is fine, because it compiles to native code, but I'm asking about dialect, not new language.
you could try D https://dlang.org/...
Or have a look at the Misra C++ rules https://www.perforce.com/resources/qac/misra-c-cpp, there are also code checkers available

How is visual programming using nodes and links converted into code? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
as title says, i want to know what is logic behind visual programming and how is it being converted into code?
Use for example unreal engine 4 blueprints, how it all works behind scenes?
I somehow think everything is made using linked structures with pointers... For example:" if " statement needs link of statement and to output links, wether that statement is true or false... But if we do all like that, programming every keyword seperatly, i think it would take too much time.
I hope you understand what im thinking.
I would from the point of view of c++ explaination if possible..
Usually data flow graphs are not converted into C, C++ or similar before being compiled. A visual representation of a data flow graph is much closer to an Abstract Syntax Tree (AST) than written programming language code.
In fact, for most programming language compilers among the first steps carried out is the translation of a the written code into an AST, and it's a trivial task to feed such a AST into a program like graphviz to generate a call graph or similar from it.
So in a sense, that data flow graph of Unreal, or LabVIEW or similar programming environments is already one step closer to the executable code. Hence regarding your questions it's better suited to reformulate it as "how is written programming language parsed and translated into a data flow graph – like you can draw in Unreal engine – or an AST?".
Unfortunately the answer to this would go vastly beyond the scope of StackOverflow, and I'll simply refer you to the standard literature on compiler development.

Different compilers, different syntax [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How to compensate the differences between the syntax of different compilers of the same programming language? How could I know which one is standard and used worldwide to make projects?
For example: I worked 4 months on Borland C++ compiler to learn C++ but now I saw the syntax of Borland, Visual C++ and Developer C++ is different. I am confused, need some guidance...
The first solution is to not use parts which are specific to one compiler or another. Before you use a feature of the language, check on the internet to see if it's specific to any one compiler. If it is, then don't use it.
Other than that, actually making a C/C++ program which is compilable by different compilers is a task which takes effort. It doesn't "just happen", because the compilers each have their own quirks, their own level of support of the standard etc. Even writing compliant C99/C++11 code you might still see issues. So one solution is to actually compile the program with different compilers on a regular basis (say, as part of testing before pushing code to the central repository) and make sure that all of them can compile the code, and the resulting software can run.
As for "standard" compilers, on Linux and Mac gcc and clang can be considered "gold". On Windows, the compilers by Microsoft are standard.

How can I make C++ in C? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Well, i was learning, again, a little bit of c and was with a little curious about how did the C++ inventor made it. And some facts lead me to the information, that he created it using pure C(obviously), so i was thinking if there is any source or anything that could help me to do things in C, that i can do in C++, like templates, namespace, class, reference and others it doesn't matter how difficult it is, i want to at least have more notion, so if anyone know a reliable source and well written i would be glad.
Yes, many, many years back, the first C++ compiler, by Bjarne Stroustrup was a "frontend for a C compiler".
Today, it certainly isn't anywhere like that. Modern C++ compilers generate code directly from C++ constructs in intermediate form for the backend to process into machine code for the target. This allows the compiler to do a more direct job, and not rely on the C compiler "understanding" what is going on.
This page contains some reference material on the cfront:
http://www.softwarepreservation.org/projects/c_plus_plus/index.html#cfront
That page also has links for the 3.0.3 archived sources as unpacked and compressed form.
Note however that this release is 21.5 years old, and would thus, if it was a person be able to order alcohol in a US Bar after showing ID. This is NOT the modern standard C++ by any measure (and it may or may not generate code that is suitable for a modern C compiler, I have no idea)
With this quote to go with the 3.0 release from 1991:
Bjarne Stroustrup notes, "A warning that Cfront 3 is pre-standard and
emphatically not recommended for use or further development might be
in place."
Edit:
I did download the code in the (compressed) link above. It certainly doesn't compile on Linux without effort. More effort than I am willing to spend, really. One of the problems is that it's pre-ANSI C, so the compile complains about various functions not being declared (for example strcpy, strcat, etc), and there are OS choices, none of which is Linux.
I also don't think it is necessarily the best place to start learning compiler techniques.