Enable syntax highlighting for TR1 headers in VS2008 SP1

Unfortunately, VS2008 SP1 doesn’t recognize C++ tr1 headers. That means there are no syntax highlighting and no intellisense for these files. This is a bug, but you can fix it by yourself. The trick is in the registry. VS maintains a list of extensionless files, and will treat them as cpp files. It is under:…

3

VC extensions list

MSDN has a page describing various VC extensions. But it is far from complete.  I’ve collected a list of nonstandard extensions provided by VC, some of them are evil. If you want to write standard conformant C++ code, you’d better be aware of these extensions which are on by default. Some commonly (mis-)used extensions are in bold. W4001: nonstandard extension ‘single line…

2

Contiguousness of STL containers and string

In C++, it is well-known that the data in the vector is contiguous. To be more specific, here is the quotation from the standard (C++03, 23.2.4/1) The elements of a vector are stored contiguously, meaning that if v is a vector<T, Allocator> where T is some type other than bool, then it obeys the identity…

1

Protected or Private?

As the designer of base class, you may hesitate whether to use private or protect access control. Then, let’s try the following examples: 1. Call protected member function#include <cstdio>class A{protected:    void b() {printf(“Oops!\n”);}};void f(A* a){    class A_hack:public A    {        friend void f(A*);    };    static_cast<A_hack *>(a)->b();}class B{public:    void f(A* a)    {        class A_hack:public A        {            friend B;        };        static_cast<A_hack *>(a)->b();    }};int main(){    f(NULL);    B().f(NULL);} Although the result of the cast is undefined as stated in the standard, if no this pointer adjustment happens and the layout of A is the same…

1

IDA Pro 5.3 Demo is released

IDA Pro is the world-class disassembler. It’s a very useful reverse engineering tool. Now the demo of the newest version 5.3 is available: IDA Pro 5.3 demo download You can also try the freeware version (a little out of date): IDA Pro 4.9 Freeware

1

Minimize the size of your program – low level

NOTICE: The following is not intended for real-world application. It is just an intellectual exercise to minimize the size of the program. The generated PE file may or may not be valid as it depends on behavior of specific architecture, OS and toolset. The previous post: Minimize the size of your program – high level…

1

Minimize the size of your program – assembly source

; based on tiny.asm, modified by xiangfan ;e_cblp 2b;tbl 1b;hexstr 1b;LoaderFlags 4b BITS 32 ;; MZ header;; The only two fields that matter are e_magic and e_lfanew mzhdr:    dw “MZ”       ; e_magic    dw 0          ; e_cblp UNUSED ;; PE signature; pesig:    dd “PE”       ; e_cp UNUSED          ; PE signature                  ; e_crlc UNUSED ;; PE header;…

1

Minimize the size of your program – high level

NOTICE: The following is not intended for real-world application. It is just an intellectual exercise to minimize the size of the program. The generated PE file may or may not be valid as it depends on behavior of specific architecture, OS and toolset. Nowadays, the size of the program is no longer a big issue….

1

Obfuscate your code

Obfuscation is widely used to protect your code from reverse engineering.Here is one example which takes advantage of indirected call and opcode overlap in X86: __declspec(naked)void Fun1(){     __asm {         //obfuscation chunk         call LABEL1LABEL1:         pop eax         add eax, 6         jmp eax          //real function body         ret     }} __declspec(naked)void Fun2(){     __asm {         //obfuscation chunk         call LABEL1LABEL1:         pop eax         add…

1

Play with the C++ compiler – compile nightmare

Playing with the compiler is interesting. One challenge for the compiler writer is compilation performance. There’re many kinds of C++ code which are the nightmare for the compiler. Now let’s go! 1. Preprocess a. Self Inclusion (GCC only)Normally, the compiler will limit the nest level of inclusion. In order to challenge the compiler, you have…

1