-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ammon Smith
committed
Apr 12, 2017
1 parent
8626565
commit ff7532e
Showing
6 changed files
with
102 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
oppai | ||
# Binaries | ||
build/ | ||
/oppai | ||
obj | ||
*.o | ||
*.[oad] | ||
|
||
# Artifacts | ||
*.tar.gz | ||
tags | ||
|
||
# Project settings | ||
.ycm_extra_conf.py* | ||
|
||
# Misc | ||
*.swp | ||
*~ | ||
tags | ||
build/ | ||
*.bak | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <openssl/md5.h> | ||
#include <unistd.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#define mkdir(x) mkdir(x, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) | ||
|
||
internalfn | ||
size_t get_exe_path(char* buf, size_t bufsize) | ||
{ | ||
ssize_t res; | ||
|
||
res = readlink("/proc/self/exe", buf, bufsize); | ||
if (res >= 0) { | ||
return (size_t)res; | ||
} | ||
|
||
res = readlink("/proc/curproc/file", buf, bufsize); | ||
if (res >= 0) { | ||
return (size_t)res; | ||
} | ||
|
||
res = readlink("/proc/self/path/a.out", buf, bufsize); | ||
if (res >= 0) { | ||
return (size_t)res; | ||
} | ||
|
||
perror("readlink"); | ||
strcpy(buf, "."); | ||
|
||
return 1; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <Windows.h> | ||
#include <direct.h> | ||
#include <Wincrypt.h> | ||
#define mkdir _mkdir | ||
|
||
internalfn | ||
size_t get_exe_path(char* buf, size_t bufsize) { | ||
return GetModuleFileNameA(0, buf, (u32)bufsize); | ||
} | ||
|
||
#define MD5_DIGEST_LENGTH 16 | ||
|
||
internalfn | ||
void MD5(u8 const* buf, size_t buflen, u8* digest) | ||
{ | ||
HCRYPTPROV prov; | ||
|
||
if (!CryptAcquireContext(&prov, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) | ||
{ | ||
fprintf(stderr, "CryptAcquireContext 0x%08X\n", GetLastError()); | ||
return; | ||
} | ||
|
||
HCRYPTHASH hash; | ||
|
||
if (!CryptCreateHash(prov, CALG_MD5, 0, 0, &hash)) | ||
{ | ||
fprintf(stderr, "CryptCreateHash 0x%08X\n", GetLastError()); | ||
goto cleanup; | ||
} | ||
|
||
if (!CryptHashData(hash, buf, (DWORD)buflen, 0)) | ||
{ | ||
fprintf(stderr, "CryptHashData 0x%08X\n", GetLastError()); | ||
goto cleanup2; | ||
} | ||
|
||
DWORD hashlen = MD5_DIGEST_LENGTH; | ||
|
||
if (!CryptGetHashParam(hash, HP_HASHVAL, digest, &hashlen, 0)) | ||
{ | ||
fprintf(stderr, "CryptGetHashParam 0x%08X\n", GetLastError()); | ||
} | ||
|
||
cleanup2: | ||
CryptDestroyHash(hash); | ||
|
||
cleanup: | ||
CryptReleaseContext(prov, 0); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters