суббота, 3 декабря 2016 г.

Very simple programm for reverse

http://wormholetravel.net/
Here we try to analysis the very simple programm for reverse.
So we have got a appli which draw the figure.




Firstly we see it in Ollydbg






In IDA we have


Here we can see the compiler


The IDA pseudocode 






int sub_411880() { int v0; // edx@9 int v1; // ST04_4@9 int v2; // ecx@9 char v4; // [sp+0h] [bp-FCh]@1 char v5; // [sp+Ch] [bp-F0h]@1 int v6; // [sp+D0h] [bp-2Ch]@1 int v7; // [sp+DCh] [bp-20h]@1 int i; // [sp+E8h] [bp-14h]@3 int v9; // [sp+F4h] [bp-8h]@1 int savedregs; // [sp+FCh] [bp+0h]@9 memset(&v5, 0xCCu, 0xF0u); v6 = 0; sub_411325("Enter the number of rows: \n", v4); sub_41122B("%d", (unsigned int)&v7); v9 = 1; while ( v9 <= v7 ) { for ( i = 1; i <= v7 - v9; ++i ) sub_411325(" ", v4); while ( v6 != 2 * v9 - 1 ) { sub_411325("* ", v4); ++v6; } sub_411325("\n", v4); ++v9; v6 = 0; } getchar(); ((void (*)(void))sub_411113)(); getchar(); ((void (*)(void))sub_411113)(); v1 = v0; sub_41125D(&savedregs, &dword_411988); return sub_411113(v2, v1); }

Now we rewtire this code in C
#include <stdio.h>
int main(void)
{
int i, space, rows;
int k = 0;
printf("Enter the number of rows: \n");

/*get the entered data from user*/
scanf("%d", &rows);
for (i=1; i <= rows; ++i, k = 0)
{
for (space = 1; space <= rows-i; ++space)
{
printf(" ");
}
while (k != 2*i-1)
{
printf("* ");
++k;
}
printf("\n");
}
getchar();
getchar();

return 0;
}

Комментариев нет:

Отправить комментарий