-
Notifications
You must be signed in to change notification settings - Fork 462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move random_int() to util.cpp #5555
base: master
Are you sure you want to change the base?
Changes from 3 commits
39a8e8e
f290892
ce7ab83
ff5e878
d60cab9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -542,3 +542,36 @@ bool process_exists(int pid) { | |||||
} | ||||||
|
||||||
#endif | ||||||
|
||||||
int random_int(unsigned int &n) { | ||||||
#if defined(_WIN32) | ||||||
#if defined(__CYGWIN32__) | ||||||
HMODULE hLib=LoadLibrary((const char *)"ADVAPI32.DLL"); | ||||||
#else | ||||||
HMODULE hLib=LoadLibraryA("ADVAPI32.DLL"); | ||||||
#endif | ||||||
if (!hLib) { | ||||||
return 1; | ||||||
} | ||||||
BOOLEAN (APIENTRY *pfn)(void*, ULONG) = | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the library was not loaded correctly two lines above - this will fail with an exception |
||||||
(BOOLEAN (APIENTRY *)(void*,ULONG))GetProcAddress(hLib,"SystemFunction036"); | ||||||
if (pfn) { | ||||||
char buff[32]; | ||||||
ULONG ulCbBuff = sizeof(buff); | ||||||
if(pfn(buff,ulCbBuff)) { | ||||||
// use buff full of random goop | ||||||
memcpy(&n,buff,sizeof(n)); | ||||||
} | ||||||
} | ||||||
FreeLibrary(hLib); | ||||||
#else | ||||||
FILE* f = fopen("/dev/random", "r"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if (!f) { | ||||||
return 2; | ||||||
} | ||||||
if (1 != fread(&n, sizeof(n), 1, f)) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return 3; | ||||||
} | ||||||
fclose(f); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
#endif | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run locally this command to remove trailing spaces:
python3 ci_tools/trailing_whitespaces_check.py . --fix