Antidebugging during the process attach >>

Categorias: Reversing, Code, English

Today was a great day for reverse engineering and protection analysis. I've found two great programs to to these things: a API call monitor and a COM call monitor. Besides that, in the first program site - from a enthusiastic of the good for all Win32 Assembly - I've found the source code for one more antidebugging technique, what bring us back to our series of antidebugging techniques.

Antidebugging using the DebugPort >>

Categorias: Reversing, Code, English

When a debugger starts a process to be debugged or, the article case, connects to a already created process, the communication between these processes is made through an internal resource inside Windows called LPC (Local Procedure Call). The system creates a "magic" communication port for debugging and the debugging events pass throw it.

Antidebugging using exceptions (part two) >>

Categorias: Reversing, Code, English

In the first article we saw how it's possible to spoof the debugger through exceptions and let the attacker lose some considerable time trying to unbind the program from the fake breakpoints. However, we saw also that this is a difficult solution to keep in the source code, besides its main weakness to be easily bypassed if discovered. Now it's time to put things easier to support and at the same time to guarantee tough times even if the attacker discover what is going on.

The upgrade showed here still uses the exception throwing intrinsically, but now it doesn't depends on the code division in minifunctions and minicalls. Instead, we just need to get code traces and put them inside a miraculous macro that will do everything we want. This, of course, after some "hammer work" that will be explained here.

Antidebugging using exceptions (part one) >>

Categorias: Reversing, Code, English

A debugger puts breakpoints to stop for a moment the debuggee execution. In order to do this it makes use of a well known instruction: int 3. This instruction throws an exception - the breakpoint exception - that is caught by the operating system and bypassed to the handling code for this exception. For debuggee processes this code is inside the debugger. For free processes this code normally doesn't exist and the application simply crashs.

The main idea in this protection is to take care these exceptions during the application execution. Doing this, we can make use of this fact and, in the handling code, run the protected code. The solution here looks like a script interpreter. It consists basically of two threads: The first one read an instructions sequence and tells the second thread to run it step to step. In order to do this the second thread uses a small functions set with well defined code blocks. Here's the example in pseudocode:

How to run anything as a service >>

Categorias: English

The biggest advantage running an application as a service, interactive or not, is to allow its start before a logon be performed. An example that happens to me is the need of debugging a GINA. In order to do this, I need the Visual Studio remote debugger be started before logon. The easiest and fastest solution is to run Msvcmon, the server part of debugging, as a service.

Today I've figured out a pretty interesting shortcut to achieve it.

Funky do-while >>

Categorias: C++, English

It's a known habit to use do-while constructions when there's a need to define a macro that has more than one command instead of using the { simple multicommand brackets }. What was never clear is why this is so.

Silly regex trick: finding the project who failed inside a big VS solution >>

Categorias: Nothing, English

I know what you going to think about this one: "silly trick". That's why I just put it in the title. Anyway, that is something I use everyday, so I thought it might be useful to who cares about productivity.

MouseTool >>

Categorias: Code, English

Well, as most of you already know, I really don't like mice. Nevertheless I respect the users who use it and like it. That is the reason why I am writing a little more about it. This time, I going to show a program I use every day: MouseTool, for the users who does not use the mouse and like it.

Why is my DLL locked? >>

Categorias: OperatingSystem, English

There is a document from Microsoft alerting about the hazards in putting your code inside a DllMain function. what is more comprehensive and easier to read than the MSDN observations. It is worth reading, even because the explanations about the loader lock and its side effects can do very good for your code health.

C and C++ Operators Precedence Table >>

Categorias: C++, English
Wanderley,your explanation about why a program compiles in C++ and not in C seems to me logic and correct, but gave me some doubts, because I always learned that the C and C++ operator precedence are the same thing.I checked out the Appendix A in the "C ++ - How To Program" (sixth edition) and the book table is equal to the C operators precedence table and it is different from the C++ precedence table presented by you in the article.I went to the internet and found out in two websites the table and both are equal to the book table.http://en.wikipedia.org/wiki/Operators_in_C_and_C
http://www.cppreference.com/operator_precedence.html
From where did you get the presented C++ table?[]s,Márcio Andrey Oliveira

What happens inside the sizeof operator >>

Categorias: C++, English

The question: how to get the size of a struct member without declaring it as a variable in memory? In pseudocode:

static const size_t FIELD_SIZE_MSGID = 15;
 
struct FEEDER_RECORD_HEADER
{
   char MessageID[FIELD_SIZE_MSGID];
   char MessageIndex[10];
};
 
// error C2143: syntax error : missing ')' before '.'
char MessageIndexBuffer[sizeof(FEEDER_RECORD_HEADER.MessageIndex) + 1];
 
// error C2070: '': illegal sizeof operand
char MessageIndexBuffer[sizeof(FEEDER_RECORD_HEADER::MessageIndex) + 1];

In this first try (even being a nice one) we can clearly see by instinct that the construction is not supposed to work. The compiler error is not even clear. The member access operator (the point sign) needs to have as its left some variable or constant of the same type of the struct. Since the operand is the type itself, there is no deal.

Precedence difference >>

Categorias: C++, English

Once upon a time my old friend Kabloc wrote this little and "harmless" function in order to print the multiplication table:

#include <stdio.h>
 
int main()
{
	int f1,f2,s=0;
	   for(f1=1;(f1==11&&s!=5)?s=5,f1=0,putchar(10):(f1<=10)?f1=f1:f1=12,f1<=11;f1++)
			for(f2=1+s;f2<=5+s;f2++)printf("%dx%d=%d%c",f2,f1,f1*f2,(f2==5+s)?10:9);
	return 0;
}

Despite the fact the result is a strong candidate to "The International Obfuscated C Code Contest", the linux guys told him the code was not successful on GCC, and somewhere inside those four lines there was a non-standard piece of code.

Google shortcuts >>

Categorias: Tools, English

I do love shortcuts. Since my very first years using computers, shortcuts had become my obsession. I research them through the time, collecting them, using them. For a long time I avoid myself from touching the mouse, trainning to remember all keystroke sequences I know.

Disassembling the array operator >>

Categorias: C++, English

Arrays are fascinating in C language because they are so simple and so powerful at the same time. When we start to really understand them and realize all its power we are very close to understand another awesome feature of the language: pointers.

When I was reading the K&R book (again) I was enjoying the language specification details in the Appendix A. It was specially odd the description as an array must be accessed: