<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Self Modifying Code on Programmer's Insight</title><link>https://blog.ganapathy.xyz/tags/self-modifying-code/</link><description>Recent content in Self Modifying Code on Programmer's Insight</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Wed, 17 Apr 2013 21:25:59 -0700</lastBuildDate><atom:link href="https://blog.ganapathy.xyz/tags/self-modifying-code/index.xml" rel="self" type="application/rss+xml"/><item><title>Self Modifying Code</title><link>https://blog.ganapathy.xyz/2013/04/self-modifying-code.html</link><pubDate>Wed, 17 Apr 2013 19:52:00 -0700</pubDate><guid>https://blog.ganapathy.xyz/2013/04/self-modifying-code.html</guid><description>&lt;div&gt;&#10;Sorry guys. It's been a while. I'm near the end of Spring Semester with hectic things ahead.&lt;br&gt;&#10;In the mean time, I thought I would post something for us to chew.&lt;br&gt;&#10;&lt;br&gt;&#10;Okay this post is about Self Modifying Code which I came across recently in my course work&lt;br&gt;&#10;where there was a line "The issues with Binary Translation (VMM) is Self Modifying Code".&lt;br&gt;&#10;&lt;br&gt;&#10;&amp;nbsp;Lets not look into VMM aspects, rather I shall restrict myself to the later.&lt;br&gt;&#10;&lt;br&gt;&#10;What is Self Modifying Code?&lt;br&gt;&#10;&lt;br&gt;&#10;Program that purposely alters its own instructions while executing.&lt;br&gt;&#10;Something like a chameleon :-)&lt;br&gt;&#10;&lt;br&gt;&#10;If we write a code that improperly manipulates a buffer then its a self modifying code :-) leading to crash.&lt;br&gt;&#10;&lt;br&gt;&#10;Questions arise as to why we need this kind of code for which I would suggest to read the &lt;a href="http://en.wikipedia.org/wiki/Self-modifying_code" rel="noopener noreferrer"&gt;wikipedia&lt;/a&gt; article for its usages.&lt;br&gt;&#10;&lt;br&gt;&#10;Of-course one can use this to create viruses ! making life difficult for anti-virus programs / honeypots.&lt;br&gt;&#10;&lt;br&gt;&#10;It is not the code that gets changed [ Of course it needs to :-) ] but the executable that needs to change while its running. This restricts us to OS specific.&lt;br&gt;&#10;&lt;br&gt;&#10;Say suppose we have a program emitting some output. Now lets open the executable using &lt;br&gt;&#10;hex editor, modify the executable to emit a different one.&lt;br&gt;&#10;&lt;br&gt;&#10;If we see windows updates, its evident that program which is in execution is closed, re-written and started again. Can't this be done while the program is in execution?&lt;br&gt;&#10;&lt;br&gt;&#10;Consider a huge deployment where there is a small bug with respect to your component.&lt;br&gt;&#10;The fix is just adding a check or changing some macro.&lt;br&gt;&#10;&lt;br&gt;&#10;Instead of rebuilding the entire component,&amp;nbsp; is it possible to write a small piece of code ( a function ) which could tweak into image of running file and fixes the bug by altering it.&lt;br&gt;&#10;This would be of great help. isn't it ? :-)&lt;br&gt;&#10;&lt;br&gt;&#10;So how do we do it?&amp;nbsp; I'm also trying it.&lt;br&gt;&#10;In the mean time, you guys too can try.&lt;br&gt;&#10;&lt;br&gt;&#10;Lets state our objective&lt;br&gt;&#10;&lt;br&gt;&#10;a) We know the operating system where our "*.so || *.exe || *.sl" is running.&lt;br&gt;&#10;b) Our objective is to tweak this executable for a minor fix that was found in site deployment.&lt;br&gt;&#10;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Note : we are not supposed to restart the process]&lt;br&gt;&#10;&lt;br&gt;&#10;Have fun while trying :)&lt;br&gt;&#10;&lt;br&gt;&lt;/div&gt;</description></item></channel></rss>