eh, moving out of cloud9
							parent
							
								
									8ccbadf94b
								
							
						
					
					
						commit
						50533d793e
					
				| 
						 | 
					@ -20,7 +20,7 @@ BreakBeforeTernaryOperators: true
 | 
				
			||||||
BreakConstructorInitializersBeforeComma: false
 | 
					BreakConstructorInitializersBeforeComma: false
 | 
				
			||||||
BinPackParameters: true
 | 
					BinPackParameters: true
 | 
				
			||||||
BinPackArguments: true
 | 
					BinPackArguments: true
 | 
				
			||||||
ColumnLimit:     80
 | 
					ColumnLimit:     120
 | 
				
			||||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
 | 
					ConstructorInitializerAllOnOneLineOrOnePerLine: false
 | 
				
			||||||
ConstructorInitializerIndentWidth: 4
 | 
					ConstructorInitializerIndentWidth: 4
 | 
				
			||||||
DerivePointerAlignment: false
 | 
					DerivePointerAlignment: false
 | 
				
			||||||
| 
						 | 
					@ -31,7 +31,7 @@ IndentFunctionDeclarationAfterType: false
 | 
				
			||||||
MaxEmptyLinesToKeep: 1
 | 
					MaxEmptyLinesToKeep: 1
 | 
				
			||||||
KeepEmptyLinesAtTheStartOfBlocks: true
 | 
					KeepEmptyLinesAtTheStartOfBlocks: true
 | 
				
			||||||
NamespaceIndentation: None
 | 
					NamespaceIndentation: None
 | 
				
			||||||
ObjCBlockIndentWidth: 4
 | 
					ObjCBlockIndentWidth: 2
 | 
				
			||||||
ObjCSpaceAfterProperty: false
 | 
					ObjCSpaceAfterProperty: false
 | 
				
			||||||
ObjCSpaceBeforeProtocolList: true
 | 
					ObjCSpaceBeforeProtocolList: true
 | 
				
			||||||
PenaltyBreakBeforeFirstCallParameter: 19
 | 
					PenaltyBreakBeforeFirstCallParameter: 19
 | 
				
			||||||
| 
						 | 
					@ -45,7 +45,7 @@ SpacesBeforeTrailingComments: 1
 | 
				
			||||||
Cpp11BracedListStyle: true
 | 
					Cpp11BracedListStyle: true
 | 
				
			||||||
Standard:        Cpp11
 | 
					Standard:        Cpp11
 | 
				
			||||||
IndentWidth:     4
 | 
					IndentWidth:     4
 | 
				
			||||||
TabWidth:        8
 | 
					TabWidth:        4
 | 
				
			||||||
UseTab:          Never
 | 
					UseTab:          Never
 | 
				
			||||||
BreakBeforeBraces: Allman
 | 
					BreakBeforeBraces: Allman
 | 
				
			||||||
SpacesInParentheses: false
 | 
					SpacesInParentheses: false
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										202
									
								
								sins.cpp
								
								
								
								
							
							
						
						
									
										202
									
								
								sins.cpp
								
								
								
								
							| 
						 | 
					@ -16,113 +16,129 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define SHA_SUM_LENGTH (SHA_DIGEST_LENGTH + SHA_DIGEST_LENGTH + 1)
 | 
					#define SHA_SUM_LENGTH (SHA_DIGEST_LENGTH + SHA_DIGEST_LENGTH + 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void picProto(void *picAddr, size_t picSize, void *clonePtr) {
 | 
					void picProto(void *picAddr, size_t picSize, void *clonePtr)
 | 
				
			||||||
  void (*cloneFunc)(void *, size_t, char *) = clonePtr;
 | 
					{
 | 
				
			||||||
  cloneFunc(picAddr, picSize);
 | 
					    void (*cloneFunc)(void *, size_t) = clonePtr;
 | 
				
			||||||
  return;
 | 
					    cloneFunc(picAddr, picSize);
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void clone(void *picAddr, size_t picSize, char *checksum) {
 | 
					void clone(void *picAddr, size_t picSize)
 | 
				
			||||||
  auto retVal = EX_SOFTWARE;
 | 
					{
 | 
				
			||||||
 | 
					    auto retVal = EX_SOFTWARE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  struct drand48_data drand_data;
 | 
					    struct drand48_data drand_data;
 | 
				
			||||||
  srand48_r(time(NULL), &drand_data);
 | 
					    srand48_r(time(NULL), &drand_data);
 | 
				
			||||||
  long int randVal;
 | 
					    long int randVal;
 | 
				
			||||||
  lrand48_r(&drand_data, &randVal);
 | 
					    lrand48_r(&drand_data, &randVal);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  unsigned int picOffset = (randVal % (picSize + 1));
 | 
					    unsigned int picOffset = (randVal % (picSize + 1));
 | 
				
			||||||
  unsigned char picFlip = ((char *)picAddr)[picOffset] & (randVal % 2);
 | 
					    unsigned char picFlip = ((char *)picAddr)[picOffset] & (randVal % 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  printf("%x\t%x\n", picOffset, picFlip);
 | 
					    printf("%x\t%x\n", picOffset, picFlip);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ((char *)picAddr)[picOffset] = picFlip;
 | 
					    ((char *)picAddr)[picOffset] = picFlip;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  unsigned char digest[SHA_DIGEST_LENGTH];
 | 
					    unsigned char digest[SHA_DIGEST_LENGTH];
 | 
				
			||||||
  SHA1(picAddr, picSize, digest);
 | 
					    SHA1(picAddr, picSize, digest);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  for (int iter = 0; iter < SHA_DIGEST_LENGTH; iter++) {
 | 
					    for (int iter = 0; iter < SHA_DIGEST_LENGTH; iter++)
 | 
				
			||||||
    sprintf(&checksum[iter * 2], "%02x", digest[iter]);
 | 
					    {
 | 
				
			||||||
  }
 | 
					        sprintf(&checksum[iter * 2], "%02x", digest[iter]);
 | 
				
			||||||
 | 
					 | 
				
			||||||
  FILE *fileOutHandle = fopen(checksum, "w+");
 | 
					 | 
				
			||||||
  if (NULL == fileOutHandle) {
 | 
					 | 
				
			||||||
    retVal = errno;
 | 
					 | 
				
			||||||
    goto CLONE_CLEANUP;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  retVal = fwrite(picAddr, 1, picSize, fileOutHandle);
 | 
					 | 
				
			||||||
  if (retVal != picSize) {
 | 
					 | 
				
			||||||
    retVal = errno;
 | 
					 | 
				
			||||||
    goto CLONE_CLEANUP;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  retVal = EX_OK;
 | 
					 | 
				
			||||||
CLONE_CLEANUP:
 | 
					 | 
				
			||||||
  if (fileOutHandle) {
 | 
					 | 
				
			||||||
    fclose(fileOutHandle);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  return;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int main(int argc, const char **argv) {
 | 
					 | 
				
			||||||
  auto retVal = EX_SOFTWARE;
 | 
					 | 
				
			||||||
  char fileInPath[SHA_SUM_LENGTH];
 | 
					 | 
				
			||||||
  char checksum[SHA_SUM_LENGTH];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  strncpy(fileInPath, argv[1], SHA_SUM_LENGTH);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  while (1) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    FILE *fileInHandle = fopen(fileInPath, "rb");
 | 
					 | 
				
			||||||
    if (NULL == fileInHandle) {
 | 
					 | 
				
			||||||
      retVal = errno;
 | 
					 | 
				
			||||||
      goto MAIN_CLEANUP;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    struct stat picStat;
 | 
					    FILE *fileOutHandle = fopen(checksum, "w+");
 | 
				
			||||||
    retVal = fstat(fileno(fileInHandle), &picStat);
 | 
					    if (NULL == fileOutHandle)
 | 
				
			||||||
    if (-1 == retVal) {
 | 
					    {
 | 
				
			||||||
      retVal = errno;
 | 
					        retVal = errno;
 | 
				
			||||||
      goto MAIN_CLEANUP;
 | 
					        goto CLONE_CLEANUP;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void *picBuffer = mmap(NULL, picStat.st_size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
 | 
					    retVal = fwrite(picAddr, 1, picSize, fileOutHandle);
 | 
				
			||||||
    if (MAP_FAILED == picBuffer) {
 | 
					    if (retVal != picSize)
 | 
				
			||||||
      retVal = errno;
 | 
					    {
 | 
				
			||||||
      goto MAIN_CLEANUP;
 | 
					        retVal = errno;
 | 
				
			||||||
 | 
					        goto CLONE_CLEANUP;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    retVal = fread(picBuffer, 1, picStat.st_size, fileInHandle);
 | 
					 | 
				
			||||||
    if (retVal != picStat.st_size) {
 | 
					 | 
				
			||||||
      retVal = errno;
 | 
					 | 
				
			||||||
      goto MAIN_CLEANUP;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (NULL != fileInHandle) {
 | 
					 | 
				
			||||||
      fclose(fileInHandle);
 | 
					 | 
				
			||||||
      fileInHandle = NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    memset(checksum, 0, SHA_SUM_LENGTH);
 | 
					 | 
				
			||||||
    void (*cloneFunc)(void *, size_t, char *) = clone;
 | 
					 | 
				
			||||||
    void (*picFunc)(void *, size_t, void *, char *) = picBuffer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    signal(SIGSEGV, magic_handler);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    picFunc(picBuffer, picStat.st_size, cloneFunc, checksum);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    strncpy(fileInPath, checksum, SHA_SUM_LENGTH);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    retVal = EX_OK;
 | 
					    retVal = EX_OK;
 | 
				
			||||||
  MAIN_CLEANUP:
 | 
					CLONE_CLEANUP:
 | 
				
			||||||
    if (NULL != picBuffer) {
 | 
					    if (fileOutHandle)
 | 
				
			||||||
      munmap(picBuffer, picStat.st_size);
 | 
					    {
 | 
				
			||||||
 | 
					        fclose(fileOutHandle);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (NULL != fileInHandle) {
 | 
					    return;
 | 
				
			||||||
      fclose(fileInHandle);
 | 
					}
 | 
				
			||||||
      fileInHandle = NULL;
 | 
					
 | 
				
			||||||
    }
 | 
					int main(int argc, const char **argv)
 | 
				
			||||||
  }
 | 
					{
 | 
				
			||||||
 | 
					    auto retVal = EX_SOFTWARE;
 | 
				
			||||||
  return retVal;
 | 
					    char fileInPath[SHA_SUM_LENGTH];
 | 
				
			||||||
 | 
					    char checksum[SHA_SUM_LENGTH];
 | 
				
			||||||
 | 
					    FILE *fileInHandle = NULL;
 | 
				
			||||||
 | 
					    struct stat picStat;
 | 
				
			||||||
 | 
					    void *picBuffer = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    strncpy(fileInPath, argv[1], SHA_SUM_LENGTH);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    while (1)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        fileInHandle = fopen(fileInPath, "rb");
 | 
				
			||||||
 | 
					        if (NULL == fileInHandle)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            retVal = errno;
 | 
				
			||||||
 | 
					            goto MAIN_CLEANUP;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        retVal = fstat(fileno(fileInHandle), &picStat);
 | 
				
			||||||
 | 
					        if (-1 == retVal)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            retVal = errno;
 | 
				
			||||||
 | 
					            goto MAIN_CLEANUP;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        auto mmapFlags = (PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE);
 | 
				
			||||||
 | 
					        picBuffer = mmap(NULL, picStat.st_size, mmapFlags, -1, 0);
 | 
				
			||||||
 | 
					        if (MAP_FAILED == picBuffer)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            retVal = errno;
 | 
				
			||||||
 | 
					            goto MAIN_CLEANUP;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        retVal = fread(picBuffer, 1, picStat.st_size, fileInHandle);
 | 
				
			||||||
 | 
					        if (retVal != picStat.st_size)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            retVal = errno;
 | 
				
			||||||
 | 
					            goto MAIN_CLEANUP;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (NULL != fileInHandle)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            fclose(fileInHandle);
 | 
				
			||||||
 | 
					            fileInHandle = NULL;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        memset(checksum, 0, SHA_SUM_LENGTH);
 | 
				
			||||||
 | 
					        void (*cloneFunc)(void *, size_t) = clone;
 | 
				
			||||||
 | 
					        void (*picFunc)(void *, size_t, void *) = picBuffer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        picFunc(picBuffer, picStat.st_size, cloneFunc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        strncpy(fileInPath, checksum, SHA_SUM_LENGTH);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    retVal = EX_OK;
 | 
				
			||||||
 | 
					MAIN_CLEANUP:
 | 
				
			||||||
 | 
					    if (NULL != picBuffer)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        munmap(picBuffer, picStat.st_size);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (NULL != fileInHandle)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        fclose(fileInHandle);
 | 
				
			||||||
 | 
					        fileInHandle = NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return retVal;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										7
									
								
								wscript
								
								
								
								
							
							
						
						
									
										7
									
								
								wscript
								
								
								
								
							| 
						 | 
					@ -3,13 +3,12 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def options(opt):
 | 
					def options(opt):
 | 
				
			||||||
    opt.load('nasm')
 | 
					    opt.load('nasm')
 | 
				
			||||||
    opt.load('compiler_c')
 | 
					    opt.load('compiler_cxx')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def configure(conf):
 | 
					def configure(conf):
 | 
				
			||||||
    conf.load('nasm')
 | 
					    conf.load('nasm')
 | 
				
			||||||
    conf.load('compiler_c')
 | 
					    conf.load('compiler_cxx')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def build(bld):
 | 
					def build(bld):
 | 
				
			||||||
    bld.program(source='pic-linux.c', target='pic-linux', cflags='-g')
 | 
					    bld.program(source='sins.cpp', target='sins', cflags='-g')
 | 
				
			||||||
    bld.program(source='sins.c', target='sins', cflags='-g')
 | 
					 | 
				
			||||||
    bld(features='asm', source='scrap.asm', target='scrap')
 | 
					    bld(features='asm', source='scrap.asm', target='scrap')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue