Go Back   CodeCall Programming Forum > Software Development > Assembly
Register Blogs Search Today's Posts Mark Forums Read

Assembly A machine oriented language in which mnemonics are used to represent each machine language instruction.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-19-2009, 10:59 PM
Programmer
 
Join Date: Apr 2008
Posts: 142
RobotGymnast is on a distinguished road
Mutating Code? (ASM w/ C++)

I tried to write a very simple mutating program the other day, but it keeps failing. Because my program uses addresses that are hardcoded in (I know, bad practice), you compiling the code would likely result in runtime errors anyway.

Therefore, my question is: does anybody have an example of an extremely simple self-modifying ASM program? I'd also like to know if there's a way that doesn't involve hardcoded addresses.

My program was basically:

Code:
unsigned int testvar = 0;
__asm
{
write code that made testvar=0xFFFFFFFF;
execute code;
}
cout << testvar << endl;
I keep getting "read error of memory [0xFFFFFFFF]" when I try writing to the code segment (this is in OllyDBG)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-20-2009, 09:02 AM
WingedPanther's Avatar
Super Moderator
 
Join Date: Jul 2006
Age: 36
Posts: 11,435
WingedPanther has much to be proud ofWingedPanther has much to be proud ofWingedPanther has much to be proud ofWingedPanther has much to be proud ofWingedPanther has much to be proud ofWingedPanther has much to be proud ofWingedPanther has much to be proud ofWingedPanther has much to be proud ofWingedPanther has much to be proud of
Re: Mutating Code? (ASM w/ C++)

If your goal is to do this in C++, you may want to check out Boost Lambda. You could also try having a scripting language interpreter.

I haven't played with self-modifying code, however.
__________________
CodeCall Blog | CodeCall Wiki | Shareware
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-20-2009, 01:31 PM
Programmer
 
Join Date: Apr 2008
Posts: 142
RobotGymnast is on a distinguished road
Re: Mutating Code? (ASM w/ C++)

My goal isn't to write self-modifying C++ code. Any code that modifies itself and runs will be in ASM. However, surrounding code might be in C++.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-21-2009, 08:57 PM
dargueta's Avatar
Code Warrior
 
Join Date: Oct 2007
Age: 19
Posts: 2,602
dargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud of
Re: Mutating Code? (ASM w/ C++)

You can get the current address and then use offsets to write code into a buffer, then jump to the buffer.

Code:
call    next
next:
pop    eax
;address now in EAX. for 64-bit code, pop RAX.
__________________
Cannot delete '002pgin': There is not enough free disk space.
Delete one or more files to free disk space, and then try again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-21-2009, 09:02 PM
Programmer
 
Join Date: Apr 2008
Posts: 142
RobotGymnast is on a distinguished road
Re: Mutating Code? (ASM w/ C++)

Yes, that gives me my current address. But now, how do I write anything? Writing to the code segment results in a read error of address 0xFFFFFFFF
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 06-21-2009, 09:05 PM
dargueta's Avatar
Code Warrior
 
Join Date: Oct 2007
Age: 19
Posts: 2,602
dargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud of
Re: Mutating Code? (ASM w/ C++)

Then try writing to a data segment. Try using malloc or something. Operating systems typically block this sort of behavior for security reasons, by the way.
__________________
Cannot delete '002pgin': There is not enough free disk space.
Delete one or more files to free disk space, and then try again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 06-21-2009, 09:12 PM
Programmer
 
Join Date: Apr 2008
Posts: 142
RobotGymnast is on a distinguished road
Re: Mutating Code? (ASM w/ C++)

yeah, writing to the data segment worked fine. Then how do programs create and use code caves?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 06-21-2009, 09:19 PM
dargueta's Avatar
Code Warrior
 
Join Date: Oct 2007
Age: 19
Posts: 2,602
dargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud ofdargueta has much to be proud of
Re: Mutating Code? (ASM w/ C++)

Um...no idea.
__________________
Cannot delete '002pgin': There is not enough free disk space.
Delete one or more files to free disk space, and then try again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Evolutionary Design and Acyclic componentization Kernel News 0 02-22-2009 11:40 AM
Functional Programming Unit Testing - Part 4 Kernel News 0 12-21-2008 07:20 PM


All times are GMT -5. The time now is 06:54 AM.


vBulletin v3.8.0 ©2010, Jelsoft Enterprises Ltd.


no new posts

LinkBacks Enabled by vBSEO 3.1.0