title: Automatic insertion of checksum guards
body: <p>As part of my project, I have to insert portions of code(called checksum guards) to protect some function. This process has to be automated i.e. I need to write a script to insert these guards in an assembly. I do have the guard template with me, I am not sure how to proceed. </p>
  
  <p>How do I write a shell script to insert code in the assembly file generated from a source file in C?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>This is the paper which I am trying to implement.
  cerias.purdue.edu/assets/pdf/bibtex_archive/2001-49.pdf
  The authors have mentioned that they have modified the binary to insert the guards but that seemed tough. So, I thought of modifying the assembly code.</p>
  
  <p>Here is a guard template:</p>
  
  <pre><code>guard:
        add ebp, -checksum
        mov eax, client_addr
  
  for:
        cmp eax, client_end
        jg end
        mov ebx, dword[eax]
        add ebp, ebx
        add eax, 4
        jmp for
  end:
  </code></pre>
  
  <p>where client_addr and client_end mark the beginning and ending of the code to protect respectively.</p>
  
  <p>I realize that my understanding of the paper is not complete and I am still unclear about various issues, but I am trying to figure it out.</p>
  
  <p>How do I give the various functions(to protect) as an input to the shellscript?</p>
  
  <ol>
  <li>I can give the name of the functions as a string.</li>
  <li>I can give the starting and ending address of the functions( found using gdb).</li>
  </ol>
  
  <p>But after inserting the checksum guard, the addresses would change so I think giving the name would be a better idea.
  Is it so?</p>
  
  <p>I am new to SO, and therefore still need to learn a lot about the correct ways to post a question. 
  But Thank you for helping and guiding me.</p>