Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Failing Arduino Mega 2560 Sketch

By: a guest on Feb 5th, 2014  |  syntax: C++  |  size: 16.34 KB  |  views: 58  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. #include <avr/pgmspace.h>
  3.  
  4. const byte JAVA_PROGRAM[] PROGMEM = {
  5. 0xca, 0xfe, 0xba, 0xbe, 0x0, 0x0, 0x0, 0x32, 0x0, 0x31,
  6. 0xa, 0x0, 0xa, 0x0, 0x20, 0x8, 0x0, 0x21, 0xa, 0x0,
  7. 0x22, 0x0, 0x23, 0xa, 0x0, 0x22, 0x0, 0x24, 0xa, 0x0,
  8. 0x9, 0x0, 0x25, 0xa, 0x0, 0x22, 0x0, 0x26, 0x8, 0x0,
  9. 0x27, 0x9, 0x0, 0x9, 0x0, 0x28, 0x7, 0x0, 0x29, 0x7,
  10. 0x0, 0x2a, 0x1, 0x0, 0x7, 0x6d, 0x79, 0x56, 0x61, 0x6c,
  11. 0x75, 0x65, 0x1, 0x0, 0x1, 0x49, 0x1, 0x0, 0x6, 0x3c,
  12. 0x69, 0x6e, 0x69, 0x74, 0x3e, 0x1, 0x0, 0x3, 0x28, 0x29,
  13. 0x56, 0x1, 0x0, 0x4, 0x43, 0x6f, 0x64, 0x65, 0x1, 0x0,
  14. 0xf, 0x4c, 0x69, 0x6e, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65,
  15. 0x72, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x1, 0x0, 0x12, 0x4c,
  16. 0x6f, 0x63, 0x61, 0x6c, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62,
  17. 0x6c, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x1, 0x0, 0x4,
  18. 0x74, 0x68, 0x69, 0x73, 0x1, 0x0, 0x21, 0x4c, 0x64, 0x75,
  19. 0x6f, 0x76, 0x65, 0x6e, 0x74, 0x69, 0x70, 0x72, 0x6f, 0x67,
  20. 0x72, 0x61, 0x6d, 0x2f, 0x44, 0x55, 0x4f, 0x56, 0x65, 0x6e,
  21. 0x74, 0x69, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x3b,
  22. 0x1, 0x0, 0x4, 0x6d, 0x61, 0x69, 0x6e, 0x1, 0x0, 0x16,
  23. 0x28, 0x5b, 0x4c, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, 0x61,
  24. 0x6e, 0x67, 0x2f, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x3b,
  25. 0x29, 0x56, 0x1, 0x0, 0x4, 0x61, 0x72, 0x67, 0x73, 0x1,
  26. 0x0, 0x13, 0x5b, 0x4c, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c,
  27. 0x61, 0x6e, 0x67, 0x2f, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67,
  28. 0x3b, 0x1, 0x0, 0x8, 0x6d, 0x79, 0x4e, 0x75, 0x6d, 0x62,
  29. 0x65, 0x72, 0x1, 0x0, 0x8, 0x6d, 0x79, 0x52, 0x65, 0x73,
  30. 0x75, 0x6c, 0x74, 0x1, 0x0, 0x8, 0x6d, 0x79, 0x4d, 0x65,
  31. 0x74, 0x68, 0x6f, 0x64, 0x1, 0x0, 0x4, 0x28, 0x49, 0x29,
  32. 0x49, 0x1, 0x0, 0x6, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72,
  33. 0x1, 0x0, 0x8, 0x3c, 0x63, 0x6c, 0x69, 0x6e, 0x69, 0x74,
  34. 0x3e, 0x1, 0x0, 0xa, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65,
  35. 0x46, 0x69, 0x6c, 0x65, 0x1, 0x0, 0x14, 0x44, 0x55, 0x4f,
  36. 0x56, 0x65, 0x6e, 0x74, 0x69, 0x50, 0x72, 0x6f, 0x67, 0x72,
  37. 0x61, 0x6d, 0x2e, 0x6a, 0x61, 0x76, 0x61, 0xc, 0x0, 0xd,
  38. 0x0, 0xe, 0x1, 0x0, 0x17, 0x50, 0x6c, 0x65, 0x61, 0x73,
  39. 0x65, 0x20, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x20, 0x61, 0x20,
  40. 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x2e, 0xa, 0x7, 0x0,
  41. 0x2b, 0xc, 0x0, 0x2c, 0x0, 0x2d, 0xc, 0x0, 0x2e, 0x0,
  42. 0x2f, 0xc, 0x0, 0x1a, 0x0, 0x1b, 0xc, 0x0, 0x2c, 0x0,
  43. 0x30, 0x1, 0x0, 0x10, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68,
  44. 0x65, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0xa,
  45. 0xc, 0x0, 0xb, 0x0, 0xc, 0x1, 0x0, 0x1f, 0x64, 0x75,
  46. 0x6f, 0x76, 0x65, 0x6e, 0x74, 0x69, 0x70, 0x72, 0x6f, 0x67,
  47. 0x72, 0x61, 0x6d, 0x2f, 0x44, 0x55, 0x4f, 0x56, 0x65, 0x6e,
  48. 0x74, 0x69, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x1,
  49. 0x0, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, 0x61, 0x6e,
  50. 0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x1, 0x0,
  51. 0x18, 0x64, 0x75, 0x6f, 0x76, 0x65, 0x6e, 0x74, 0x69, 0x70,
  52. 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x2f, 0x45, 0x78, 0x63,
  53. 0x68, 0x61, 0x6e, 0x67, 0x65, 0x1, 0x0, 0x5, 0x70, 0x72,
  54. 0x69, 0x6e, 0x74, 0x1, 0x0, 0x15, 0x28, 0x4c, 0x6a, 0x61,
  55. 0x76, 0x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x1e, 0x0, 0x0, 0x0, 0x2, 0x0,
  93. 0x1f
  94. };
  95.  
  96. const byte ATTRIBUTE_NAME1[] PROGMEM = "Code";
  97.  
  98. const byte METHOD_NAME1[] PROGMEM = "<clinit>";
  99. const byte METHOD_NAME2[] PROGMEM = "<init>";
  100. const byte METHOD_NAME3[] PROGMEM = "main";
  101.  
  102. const byte ERROR_MESSAGE1[] PROGMEM = "Invalid class file.\n";
  103. const byte ERROR_MESSAGE2[] PROGMEM = "Invalid constant.\n";
  104. const byte ERROR_MESSAGE3[] PROGMEM = "Interfaces are not supported.\n";
  105.  
  106. byte equalText(byte *buffer1, byte *buffer2)
  107. {
  108.         long index = 0;
  109.         while (index < 512)
  110.         {
  111.                 byte tempValue1 = *buffer1;
  112.                 byte tempValue2 = *buffer2;
  113.                 if (tempValue1 != tempValue2)
  114.                 {
  115.                         return false;
  116.                 }
  117.                 if (tempValue1 == 0)
  118.                 {
  119.                         break;
  120.                 }
  121.                 buffer1 += 1;
  122.                 buffer2 += 1;
  123.                 index += 1;
  124.         }
  125.         return true;
  126. }
  127.  
  128. byte equalData(long amount, byte *buffer1, byte *buffer2)
  129. {
  130.         while (amount > 0)
  131.         {
  132.                 byte tempValue1 = *buffer1;
  133.                 byte tempValue2 = *buffer2;
  134.                 if (tempValue1 != tempValue2)
  135.                 {
  136.                         return false;
  137.                 }
  138.                 buffer1 += 1;
  139.                 buffer2 += 1;
  140.                 amount -= 1;
  141.         }
  142.         return true;
  143. }
  144.  
  145. void copyTextFromProgMemToBuffer(byte *destination, const byte *sequence)
  146. {
  147.         byte count = 0;
  148.         while (count < 250)
  149.         {
  150.                 byte tempData = pgm_read_byte(sequence);
  151.                 *destination = tempData;
  152.                 if (tempData == 0)
  153.                 {
  154.                         break;
  155.                 }
  156.                 sequence += 1;
  157.                 destination += 1;
  158.                 count += 1;
  159.         }
  160. }
  161.  
  162. void copyDataFromProgMemToBuffer(byte *destination, long amount, const byte *sequence)
  163. {
  164.         long index = 0;
  165.         while (index < amount)
  166.         {
  167.                 byte tempData = pgm_read_byte(sequence + index);
  168.                 *(destination + index) = tempData;
  169.                 index += 1;
  170.         }
  171. }
  172.  
  173. byte equalTextToTextFromProgMem(byte *buffer1, const byte *buffer2)
  174. {
  175.   byte tempBuffer[250];
  176.   copyTextFromProgMemToBuffer(tempBuffer, buffer2);
  177.   return equalText(buffer1, tempBuffer);
  178. }
  179.  
  180. void printFromProgMem(const byte *sequence)
  181. {
  182.   byte tempBuffer[250];
  183.   copyTextFromProgMemToBuffer(tempBuffer, sequence);
  184.   Serial.print((char *)tempBuffer);
  185. }
  186.  
  187. void readSequenceFromJavaProgram(long amount, byte *buffer, long address)
  188. {
  189.   copyDataFromProgMemToBuffer(buffer, amount, JAVA_PROGRAM + address);
  190. }
  191.  
  192. byte readByteFromJavaProgram(long address)
  193. {
  194.   byte tempBuffer[1];
  195.   readSequenceFromJavaProgram(1, tempBuffer, address);
  196.   return tempBuffer[0];
  197. }
  198.  
  199. unsigned int readUnsignedShortFromJavaProgram(long address)
  200. {
  201.   byte tempBuffer[2];
  202.   readSequenceFromJavaProgram(2, tempBuffer, address);
  203.   return ((unsigned int)tempBuffer[0] << (unsigned int)8) + (unsigned int)tempBuffer[1];
  204. }
  205.  
  206. unsigned long readUnsignedIntFromJavaProgram(long address)
  207. {
  208.   byte tempBuffer[4];
  209.   readSequenceFromJavaProgram(4, tempBuffer, address);
  210.   long output = (unsigned long)tempBuffer[0] << (unsigned long)24;
  211.   output += (unsigned long)tempBuffer[1] << (unsigned long)16;
  212.   output += ((unsigned long)tempBuffer[2] << (unsigned long)8) + (unsigned long)tempBuffer[3];
  213.   return output;
  214. }
  215.  
  216. long constantAddressList[100];
  217. unsigned int thisJavaClass;
  218. long fieldAddressList[25];
  219. byte fieldAmount;
  220. byte fieldIndexList[25];
  221. byte fieldData[100];
  222. long methodAddressList[25];
  223. byte methodAmount;
  224. long methodCodeAttributeAddressList[25];
  225. int staticMethodIndex;
  226. int constructorMethodIndex;
  227. int mainMethodIndex;
  228. byte operandStack[100];
  229. unsigned int operandStackLevel;
  230. byte variableStack[200];
  231. unsigned int variableStackLevel;
  232. byte tempBuffer[400];
  233.  
  234. void readJavaProgramStringConstant(byte *destination, unsigned int index)
  235. {
  236.   long tempAddress = constantAddressList[index - 1];
  237.   tempAddress += 1;
  238.   unsigned int tempAmount = readUnsignedShortFromJavaProgram(tempAddress);
  239.   tempAddress += 2;
  240.   readSequenceFromJavaProgram(tempAmount, destination, tempAddress);
  241.   *(destination + tempAmount) = 0;
  242. }
  243.  
  244. byte getDescriptorSize(byte *destination, byte *buffer)
  245. {
  246.   byte tempCharacter = *buffer;
  247.   if (tempCharacter == 'B' || tempCharacter == 'C' || tempCharacter == 'F' || tempCharacter == 'I' || tempCharacter == 'S' || tempCharacter == 'Z')
  248.   {
  249.     *destination = 4;
  250.     return 1;
  251.   }
  252.   if (tempCharacter == 'D' || tempCharacter == 'J')
  253.   {
  254.     *destination = 8;
  255.     return 1;
  256.   }
  257.   if (tempCharacter == 'L')
  258.   {
  259.     *destination = 4;
  260.     buffer += 1;
  261.     byte output = 2;
  262.     while (*buffer != ';' && output < 250)
  263.     {
  264.       buffer += 1;
  265.       output += 1;
  266.     }
  267.     return output;
  268.   }
  269.   if (tempCharacter == '[')
  270.   {
  271.     *destination = 4;
  272.     byte tempNumber;
  273.     return 1 + getDescriptorSize(&tempNumber, buffer + 1);
  274.   }
  275. }
  276.  
  277. void pushOperandIntOntoStack(long operand)
  278. {
  279.   *((long *)(operandStack + operandStackLevel)) = operand;
  280.   operandStackLevel += 4;
  281. }
  282.  
  283. long popOperandIntFromStack()
  284. {
  285.   operandStackLevel -= 4;
  286.   return *((long *)(operandStack + operandStackLevel));
  287. }
  288.  
  289. void initializeJavaProgram(long address)
  290. {
  291.   unsigned long tempValue = readUnsignedIntFromJavaProgram(address);
  292.   address += 4;
  293.   if (tempValue != 0xCAFEBABE)
  294.   {
  295.     printFromProgMem(ERROR_MESSAGE1);
  296.     return;
  297.   }
  298.   // The version numbers could be read here.
  299.   address += 4;
  300.   unsigned int tempCount = readUnsignedShortFromJavaProgram(address);
  301.   address += 2;
  302.   unsigned int index = 1;
  303.   while (index < tempCount)
  304.   {
  305.     constantAddressList[index - 1] = address;
  306.     byte tempType = readByteFromJavaProgram(address);
  307.     address += 1;
  308.     if (tempType == 1)
  309.     {
  310.       unsigned int tempAmount = readUnsignedShortFromJavaProgram(address);
  311.       address += 2;
  312.       address += tempAmount;
  313.       //readJavaProgramStringConstant(tempBuffer, index);
  314.       //Serial.println((char *)tempBuffer);
  315.     }
  316.     if (tempType == 3 || tempType == 4 || tempType > 8)
  317.     {
  318.       address += 4;
  319.     }
  320.     if (tempType == 5 || tempType == 6)
  321.     {
  322.       address += 8;
  323.     }
  324.     if (tempType == 7 || tempType == 8)
  325.     {
  326.       address += 2;
  327.     }
  328.     if (tempType > 12)
  329.     {
  330.       printFromProgMem(ERROR_MESSAGE2);
  331.       return;
  332.     }
  333.     index += 1;
  334.   }
  335.   // Access flags here.
  336.   address += 2;
  337.   thisJavaClass = readUnsignedShortFromJavaProgram(address);
  338.   address += 2;
  339.   // Superclass here.
  340.   address += 2;
  341.   tempCount = readUnsignedShortFromJavaProgram(address);
  342.   address += 2;
  343.   if (tempCount > 0)
  344.   {
  345.     printFromProgMem(ERROR_MESSAGE3);
  346.   }
  347.   // Interfaces here.
  348.   fieldAmount = 0;
  349.   tempCount = readUnsignedShortFromJavaProgram(address);
  350.   address += 2;
  351.   index = 0;
  352.   while (tempCount > 0)
  353.   {
  354.     fieldAddressList[index] = address;
  355.     index += 1;
  356.     // Access flags here.
  357.     address += 2;
  358.     // Name index here.
  359.     address += 2;
  360.     // Descriptor index here.
  361.     address += 2;
  362.     unsigned int tempAmount = readUnsignedShortFromJavaProgram(address);
  363.     address += 2;
  364.     unsigned int tempIndex = 0;
  365.     while (tempIndex < tempAmount)
  366.     {
  367.       // Attribute name index here.
  368.       address += 2;
  369.       unsigned long tempAmount2 = readUnsignedIntFromJavaProgram(address);
  370.       address += 4;
  371.       // Info here.
  372.       address += tempAmount2;
  373.       tempIndex += 1;
  374.     }
  375.     fieldAmount += 1;
  376.     tempCount -= 1;
  377.   }
  378.   methodAmount = 0;
  379.   tempCount = readUnsignedShortFromJavaProgram(address);
  380.   address += 2;
  381.   index = 0;
  382.   while (tempCount > 0)
  383.   {
  384.     methodAddressList[index] = address;
  385.     index += 1;
  386.     // Access flags here.
  387.     address += 2;
  388.     // Name index here.
  389.     unsigned int tempIndex2 = readUnsignedShortFromJavaProgram(address);
  390.     readJavaProgramStringConstant(tempBuffer, tempIndex2);
  391.     Serial.println((char *)tempBuffer);
  392.     address += 2;
  393.     // Descriptor index here.
  394.     address += 2;
  395.     unsigned int tempAmount = readUnsignedShortFromJavaProgram(address);
  396.     address += 2;
  397.     unsigned int tempIndex = 0;
  398.     while (tempIndex < tempAmount)
  399.     {
  400.       unsigned int tempIndex2 = readUnsignedShortFromJavaProgram(address);
  401.       readJavaProgramStringConstant(tempBuffer, tempIndex2);
  402.       Serial.println((char *)tempBuffer);
  403.       if (equalTextToTextFromProgMem(tempBuffer, ATTRIBUTE_NAME1))
  404.       {
  405.         methodCodeAttributeAddressList[index] = address;
  406.       }
  407.       address += 2;
  408.       unsigned long tempAmount2 = readUnsignedIntFromJavaProgram(address);
  409.       address += 4;
  410.       // Info here.
  411.       address += tempAmount2;
  412.       tempIndex += 1;
  413.     }
  414.     methodAmount += 1;
  415.     tempCount -= 1;
  416.   }
  417.   byte tempFieldIndex = 0;
  418.   index = 0;
  419.   while (index < fieldAmount)
  420.   {
  421.     fieldIndexList[index] = tempFieldIndex;
  422.     long tempAddress = fieldAddressList[index];
  423.     unsigned int tempIndex = readUnsignedShortFromJavaProgram(tempAddress + 4);
  424.     readJavaProgramStringConstant(tempBuffer, tempIndex);
  425.     byte tempSize;
  426.     getDescriptorSize(&tempSize, tempBuffer);
  427.     tempFieldIndex += tempSize;
  428.     index += 1;
  429.   }
  430.   staticMethodIndex = -1;
  431.   constructorMethodIndex = -1;
  432.   mainMethodIndex = -1;
  433.   index = 0;
  434.   while (index < methodAmount)
  435.   {
  436.     long tempAddress = methodAddressList[index];
  437.     unsigned int tempIndex = readUnsignedShortFromJavaProgram(tempAddress + 2);
  438.     readJavaProgramStringConstant(tempBuffer, tempIndex);
  439.     if (equalTextToTextFromProgMem(tempBuffer, METHOD_NAME1))
  440.     {
  441.       staticMethodIndex = index;
  442.     }
  443.     if (equalTextToTextFromProgMem(tempBuffer, METHOD_NAME2))
  444.     {
  445.       constructorMethodIndex = index;
  446.     }
  447.     if (equalTextToTextFromProgMem(tempBuffer, METHOD_NAME3))
  448.     {
  449.       mainMethodIndex = index;
  450.     }
  451.     index += 1;
  452.   }
  453.   operandStackLevel = 0;
  454.   variableStackLevel = 0;
  455. }
  456.  
  457. int findJavaProgramMethod(unsigned int index)
  458. {
  459.   long tempAddress = constantAddressList[index];
  460.   unsigned int nameAndDescriptorIndex = readUnsignedShortFromJavaProgram(tempAddress + 3);
  461.   tempAddress = constantAddressList[nameAndDescriptorIndex];
  462.   unsigned int nameIndex = readUnsignedShortFromJavaProgram(tempAddress + 1);
  463.   unsigned int descriptorIndex = readUnsignedShortFromJavaProgram(tempAddress + 3);
  464.   unsigned int tempIndex = 0;
  465.   while (tempIndex < methodAmount)
  466.   {
  467.     long tempAddress = methodAddressList[tempIndex];
  468.     unsigned int tempIndex2 = readUnsignedShortFromJavaProgram(tempAddress + 2);
  469.     unsigned int tempIndex3 = readUnsignedShortFromJavaProgram(tempAddress + 4);
  470.     if (tempIndex2 == nameIndex && tempIndex3 == descriptorIndex)
  471.     {
  472.       return tempIndex;
  473.     }
  474.     tempIndex += 1;
  475.   }
  476.   return -1;
  477. }
  478.  
  479. void runJavaProgramMethodByIndex(unsigned int index)
  480. {
  481.   unsigned int tempVariableStackLevel = variableStackLevel;
  482.   long tempAddress = methodAddressList[index];
  483.   unsigned int tempIndex = readUnsignedShortFromJavaProgram(tempAddress + 4);
  484.   readJavaProgramStringConstant(tempBuffer, tempIndex);
  485.   unsigned int tempSize = 0;
  486.   tempIndex = 1;
  487.   while (*(tempBuffer + tempIndex) != ')' && tempIndex < 400)
  488.   {
  489.     byte tempSize2;
  490.     tempIndex += getDescriptorSize(&tempSize2, tempBuffer + tempIndex);
  491.     tempSize += tempSize2;
  492.   }
  493.   tempAddress = methodCodeAttributeAddressList[index];
  494.   variableStackLevel += 4 * readUnsignedShortFromJavaProgram(tempAddress + 8);
  495.  
  496.   variableStackLevel = tempVariableStackLevel;
  497. }
  498.  
  499. void runJavaProgramMethod(unsigned int index)
  500. {
  501.   int tempIndex = findJavaProgramMethod(index);
  502.   if (tempIndex == -1)
  503.   {
  504.     return;
  505.   }
  506.   runJavaProgramMethodByIndex(tempIndex);
  507. }
  508.  
  509. void runJavaProgram(long address)
  510. {
  511.   initializeJavaProgram(address);
  512.   runJavaProgramMethodByIndex(staticMethodIndex);
  513.   runJavaProgramMethodByIndex(constructorMethodIndex);
  514.   runJavaProgramMethodByIndex(mainMethodIndex);
  515. }
  516.  
  517. void setup()
  518. {
  519.   Serial.begin(9600);
  520.   Serial.println("Hello world!");
  521.   runJavaProgram(0);
  522. }
  523.  
  524. void loop()
  525. {
  526.  
  527. }