Advertisement
imk0tter

Untitled

Jul 11th, 2011
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <windows.h>
  5. class TestClass {
  6.       private:
  7.           char * name;
  8.           char * dataString;
  9.           BYTE * data;
  10.           int dataSize;
  11.           void formatDataString();
  12.       public:
  13.           TestClass(char * name, BYTE * data, int size);
  14.           ~TestClass();
  15.           char * getName();
  16.           BYTE * getData();
  17.           int    getDataSize();
  18.           char * getDataString();
  19.           // Display Functions
  20.          
  21. };
  22. // Constructors
  23. TestClass::TestClass(char * name, BYTE * data, int size) {
  24.     this->name =       (char*)malloc(sizeof(char) * strlen(name));
  25.     this->data =       (BYTE*)malloc(sizeof(BYTE) * size);
  26.     this->dataString = (char*)malloc(sizeof(char) * size * 5);
  27.     this->dataSize =   size;
  28.     memcpy((VOID*)this->name,(VOID*)name,strlen(name));
  29.     memcpy((VOID*)this->data,(VOID*)data,size);
  30.     formatDataString();
  31. }
  32. // Private Methods
  33. void TestClass::formatDataString() {
  34.      char temp[5];
  35.      for (int i = 0; i < dataSize; ++i) {
  36.          sprintf(temp,"%#.2X ",data[i]);
  37.          memcpy((VOID*)(dataString + i*5),(VOID*)temp,5);
  38.      }
  39. }
  40. // Public Methods
  41. TestClass::~TestClass() {
  42.     delete this->name;
  43.     delete this->data;
  44.     delete this->dataString;
  45. }
  46.  
  47. char * TestClass::getName() {
  48.      return name;
  49. }
  50. BYTE * TestClass::getData() {
  51.      return data;
  52. }
  53. int  TestClass::getDataSize() {
  54.      return dataSize;    
  55. }
  56. char * TestClass::getDataString() {
  57.      return dataString;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement