line endings?

master
JoYo 2016-07-11 22:56:22 -04:00
parent e41802ec85
commit 5dba23d673
3 changed files with 124 additions and 79 deletions

View File

@ -1,63 +1,90 @@
--- ---
Language: Cpp Language: Cpp
# BasedOnStyle: LLVM # BasedOnStyle: Google
AccessModifierOffset: -2 AccessModifierOffset: -1
AlignAfterOpenBracket: true AlignAfterOpenBracket: Align
AlignEscapedNewlinesLeft: false AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true AlignOperands: true
AlignTrailingComments: true AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All AllowShortFunctionsOnASingleLine: All
AlwaysBreakAfterDefinitionReturnType: false AllowShortIfStatementsOnASingleLine: true
AlwaysBreakTemplateDeclarations: false AllowShortLoopsOnASingleLine: true
AlwaysBreakBeforeMultilineStrings: false AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: true BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false BreakConstructorInitializersBeforeComma: false
BinPackParameters: true ColumnLimit: 80
BinPackArguments: true CommentPragmas: '^ IWYU pragma:'
ColumnLimit: 120 ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4 ConstructorInitializerIndentWidth: 4
DerivePointerAlignment: false ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: false ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IndentCaseLabels: true
IndentWidth: 4
IndentWrappedFunctionNames: false IndentWrappedFunctionNames: false
IndentFunctionDeclarationAfterType: false KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1 MaxEmptyLinesToKeep: 1
KeepEmptyLinesAtTheStartOfBlocks: true
NamespaceIndentation: None NamespaceIndentation: None
ObjCBlockIndentWidth: 2 ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 19 PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300 PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120 PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000 PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60 PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Right PointerAlignment: Left
SpacesBeforeTrailingComments: 1 ReflowComments: true
Cpp11BracedListStyle: true SortIncludes: true
Standard: Cpp11 SpaceAfterCStyleCast: false
IndentWidth: 4 SpaceBeforeAssignmentOperators: true
TabWidth: 4 SpaceBeforeParens: ControlStatements
UseTab: Never SpaceInEmptyParentheses: false
BreakBeforeBraces: Allman SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false SpacesInParentheses: false
SpacesInSquareBrackets: false SpacesInSquareBrackets: false
SpacesInAngles: false Standard: Auto
SpaceInEmptyParentheses: false TabWidth: 4
SpacesInCStyleCastParentheses: false UseTab: Never
SpaceAfterCStyleCast: false ...
SpacesInContainerLiterals: true
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 4
CommentPragmas: '^ IWYU pragma:'
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
SpaceBeforeParens: ControlStatements
DisableFormat: false

42
sins.c
View File

@ -16,12 +16,14 @@
int generation(char *seed_path); int generation(char *seed_path);
int reproduce(void *pic_address, size_t pic_size); int reproduce(void *pic_address, size_t pic_size);
char seed_path[SHA_SUM_LENGTH];
FILE *seed_handle = NULL;
void *pic_buffer = NULL;
int generation(char *seed_path) int generation(char *seed_path)
{ {
int return_value = 0; int return_value = 0;
FILE *seed_handle = NULL;
struct stat pic_statistics; struct stat pic_statistics;
void *pic_buffer = NULL;
seed_handle = fopen(seed_path, "rb"); seed_handle = fopen(seed_path, "rb");
if (NULL == seed_handle) if (NULL == seed_handle)
@ -64,7 +66,6 @@ int generation(char* seed_path)
pic_function(pic_buffer, pic_statistics.st_size, reproduce_function); pic_function(pic_buffer, pic_statistics.st_size, reproduce_function);
return_value = 1; return_value = 1;
GEN_CLEANUP: GEN_CLEANUP:
if (NULL != pic_buffer) if (NULL != pic_buffer)
@ -83,29 +84,30 @@ GEN_CLEANUP:
int reproduce(void *pic_address, size_t pic_size) int reproduce(void *pic_address, size_t pic_size)
{ {
int return_value = 0; int return_value = 0;
char checksum[SHA_SUM_LENGTH];
unsigned char digest[SHA_DIGEST_LENGTH]; unsigned char digest[SHA_DIGEST_LENGTH];
struct drand48_data drand_data; struct drand48_data drand_data;
long int mutation_value; long int mutation_value;
unsigned int mutation_offset = 0; unsigned int mutation_offset = 0;
unsigned char pic_mutated = 0; unsigned char pic_mutated = 0;
struct stat pic_statistics;
srand48_r(time(NULL), &drand_data); srand48_r(time(NULL), &drand_data);
lrand48_r(&drand_data, &mutation_value); lrand48_r(&drand_data, &mutation_value);
mutation_offset = (mutation_value % (pic_size + 1)); mutation_offset = (mutation_value % (pic_size + 1));
pic_mutated = ((unsigned char *)pic_address)[mutation_offset] & (mutation_value % 2); pic_mutated =
((unsigned char *)pic_address)[mutation_offset] & (mutation_value % 2);
((char *)pic_address)[mutation_offset] = pic_mutated; ((char *)pic_address)[mutation_offset] = pic_mutated;
memset(checksum, 0, SHA_SUM_LENGTH); memset(seed_path, 0, SHA_SUM_LENGTH);
SHA1((const unsigned char *)pic_address, pic_size, digest); SHA1((const unsigned char *)pic_address, pic_size, 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(&seed_path[iter * 2], "%02x", digest[iter]);
} }
FILE *survived_store = fopen(checksum, "w+"); FILE *survived_store = fopen(seed_path, "w+");
if (NULL == survived_store) if (NULL == survived_store)
{ {
return_value = errno; return_value = errno;
@ -125,22 +127,38 @@ CLONE_CLEANUP:
{ {
fclose(survived_store); fclose(survived_store);
} }
fstat(fileno(seed_handle), &pic_statistics);
if (NULL != pic_buffer)
{
munmap(pic_buffer, pic_statistics.st_size);
}
if (NULL != seed_handle)
{
fclose(seed_handle);
seed_handle = NULL;
}
return generation(checksum); return generation(seed_path);
} }
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
int return_value = 1; int return_value = 1;
char seed_path[SHA_SUM_LENGTH];
pid_t scrap_process_id; pid_t scrap_process_id;
strncpy(seed_path, argv[1], SHA_SUM_LENGTH); strncpy(seed_path, argv[1], SHA_SUM_LENGTH);
scrap_process_id = fork();
while (return_value) while (return_value)
{ {
scrap_process_id = fork();
if (scrap_process_id < 0)
{
break;
}
printf("child\t%d\n", scrap_process_id);
if (scrap_process_id == 0) if (scrap_process_id == 0)
{ {
return_value = generation(seed_path); return_value = generation(seed_path);