nasm - cross-platform self-modifying code (Intel/AMD only) -


i have searched considerably answer without success. in debugger, 1 may write instructions , execute them. requires special permissions in executable image. seek perform function without debugger.

please show me asm "hello world" program has self-modifying code (perhaps replacing series of 090h code uppercase 'h' in hello) , commands necessary enable execution. next 2 lines before , after machine code h->h replacement.

90 90 90 90 90 90 90 90 90 90 90 ; 11 nops 8a 26 50 00 80 e4 df 88 26 50 00 ; mov ah,[bx]; , ah,0dfh; mov [bx],ah; 

i have complete competence , confidence constructing iapx86 machine code. problem convincing linux, darwin/yosemite, , windows allow execution. in end, want able construct , modify executable on-the-fly new language writing. architecture of new language has no parallels in modern practice.

i expect criticism flying in face of convention, proceed plans notwithstanding.

thank taking question seriously. code works! turned out far simpler thought; without special compiler flags, or elf or macho specialization. in iapx86 machine code, c3 near ret without return value. have few improvements make, listed after code, question, asked, answered satisfaction.

working code

#include <cstdio> #include <cstdlib> #include <iostream> #include <string>  using namespace std;  typedef void (*fptr)();  int main(int argc, char **argv) {   try {     fptr p = (fptr)"\xc3";     p();     cout << "hello world" << endl;   }   catch (const int     e) { cout << "int     exception: " << e << endl; }   catch (const char    e) { cout << "char    exception: " << e << endl; }   catch (const string &e) { cout << "string  exception: " << e << endl; }   catch (...)             { cout << "default exception"        << endl; }   exit(0); } 

todo

  • bracket opcode strings safety code.
  • prevent opcodes appearing in strings.
  • catch signals exceptions.

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -