Patching doesn't work?

Technical Discussions not Related Directly to MHS. For Example, Coding, Hex Editing, General Hacking, Etc.

Moderators: g3nuin3, SpeedWing, WhiteHat

Patching doesn't work?

Postby bvkim » Wed Aug 05, 2009 8:03 pm

Hi there

I'm currently doing practices under Linux w/ blah crackmes:
Link: crackmes.de

This is the dump result:

Code: Select all
blah:     file format elf32-i386


Disassembly of section .text:

08048094 <.text>:
8048094:   31 c0                   xor    %eax,%eax
8048096:   b8 2f 00 00 00          mov    $0x2f,%eax
804809b:   cd 80                   int    $0x80
804809d:   3d ad de 00 00          cmp    $0xdead,%eax
80480a2:   75 16                   jne    0x80480ba <-- I want to NOP this line
80480a4:   b8 04 00 00 00          mov    $0x4,%eax
80480a9:   bb 01 00 00 00          mov    $0x1,%ebx
80480ae:   b9 c4 90 04 08          mov    $0x80490c4,%ecx
80480b3:   ba 06 00 00 00          mov    $0x6,%edx
80480b8:   cd 80                   int    $0x80
80480ba:   31 c0                   xor    %eax,%eax
80480bc:   40                      inc    %eax
80480bd:   31 db                   xor    %ebx,%ebx
80480bf:   cd 80                   int    $0x80



As I comment above, I want to patch that line by 2 - NOP bytes.
I wrote this code:

Code: Select all
#include <stdio.h>

int
main( int argc, char *argv[] )
{
   int offset[2] = { 0x75, 0x16 }; /* origin */
   char patch[2] = { 0x90, 0x90 }; /* nop */
   FILE *file;
   int i;
   
   file = fopen( "blah", "rb+" );
   if( file != NULL ) {
      for( i = 0; i < 2; ++i ) {
         fseek( file, offset[i], SEEK_SET ); /* search */
         fprintf( file, "%c", patch[i] ); /* patch */         
      }
      printf("Patched Done.\n");
   } else {
      printf("[Error]: file not found. \n");
   }      
   fclose( file );
   return 0;
}


However, I don't know why it doesn't work???
[Note: if I change different offsets, source works; only the above offset occurs error]
May some1 help me this?
bvkim
I Have A Few Questions
 
Posts: 3
Joined: Sat Aug 01, 2009 12:14 pm

Postby bvkim » Wed Aug 05, 2009 8:33 pm

Problem found! ^^!
bvkim
I Have A Few Questions
 
Posts: 3
Joined: Sat Aug 01, 2009 12:14 pm

Postby [Psych] » Thu Aug 06, 2009 6:58 pm

I see you posted this on about 3 forums only to find the problem straight after :P
[Psych]
Hacker Smacker
 
Posts: 41
Joined: Thu Jul 16, 2009 4:15 pm


Return to Technical Unrelated

Who is online

Users browsing this forum: No registered users and 0 guests