lurumdare
2019-09-12 41915d810cbc678cdec5ef2b248dd84dbb905cee
formatting and type cast

2个文件已修改
54 ■■■■■ 已修改文件
src/library/os/os-win.c 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/os/os.c 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/os/os-win.c
@@ -1,9 +1,10 @@
#ifdef _MSC_VER
#include <Windows.h>
#endif
#include <iphlpapi.h>
#include "../base/logger.h"
#include "os.h"
#include <iphlpapi.h>
#include <stdio.h>
#pragma comment(lib, "IPHLPAPI.lib")
unsigned char* unbase64(const char* ascii, int len, int *flen);
@@ -16,9 +17,9 @@
    FUNCTION_RETURN result = FUNC_RET_ERROR;
    char buffer[MAX_COMPUTERNAME_LENGTH + 1];
    int bufsize = MAX_COMPUTERNAME_LENGTH + 1;
    const BOOL cmpName = GetComputerName(buffer, &bufsize);
    const BOOL cmpName = GetComputerName(buffer, (unsigned long*)&bufsize);
    if (cmpName) {
        strncpy(identifier, buffer, 6);
        strncpy((char*)identifier, buffer, 6);
        result = FUNC_RET_OK;
    }
    return result;
@@ -40,11 +41,9 @@
    int ndrives = 0;
    DWORD FileFlags;
    char volName[_MAX_FNAME], FileSysName[_MAX_FNAME];
    char* szSingleDrive;
    DWORD volSerial = 0;
    BOOL success;
    UINT driveType;
    const DWORD dwSize = MAX_PATH;
    char szLogicalDrives[MAX_PATH] = { 0 };
    unsigned char buf[8] = "";
@@ -53,13 +52,13 @@
    if (dwResult > 0 && dwResult <= MAX_PATH) {
        return_value = FUNC_RET_OK;
        szSingleDrive = szLogicalDrives;
        char* szSingleDrive = szLogicalDrives;
        while (*szSingleDrive && ndrives < MAX_UNITS) {
            // get the next drive
            driveType = GetDriveType(szSingleDrive);
            UINT driveType = GetDriveType(szSingleDrive);
            if (driveType == DRIVE_FIXED) {
                success = GetVolumeInformation(szSingleDrive, volName, MAX_PATH,
                BOOL success = GetVolumeInformation(szSingleDrive, volName, MAX_PATH,
                        &volSerial, &FileMaxLen, &FileFlags, FileSysName,
                        MAX_PATH);
                if (success) {
@@ -69,7 +68,7 @@
                    LOG_DEBUG("Max file length : %d", FileMaxLen); 
                    LOG_DEBUG("Filesystem      : %s", FileSysName);
                    if (diskInfos != NULL) {
                        if (ndrives < *disk_info_size) {
                        if (ndrives < (int)*disk_info_size) {
                            diskInfos[ndrives].id = ndrives;
                            strncpy(diskInfos[ndrives].device, volName, MAX_PATH);
                            strncpy(diskInfos[ndrives].label, FileSysName, MAX_PATH);
@@ -105,11 +104,9 @@
}
static int translate(char ipStringIn[16], unsigned char ipv4[4]) {
    char *str2;
    size_t index = 0;
    str2 = ipStringIn; /* save the pointer */
    char* str2 = ipStringIn; /* save the pointer */
    while (*str2) {
        if (isdigit((unsigned char) *str2)) {
            ipv4[index] *= 10;
@@ -127,13 +124,11 @@
FUNCTION_RETURN getAdapterInfos(OsAdapterInfo * adapterInfos,
        size_t * adapter_info_size) {
    DWORD dwStatus;
    unsigned int i = 0;
    FUNCTION_RETURN result;
    PIP_ADAPTER_INFO pAdapterInfo, pAdapter = NULL;
    PIP_ADAPTER_INFO pAdapterInfo;
    //IP_ADAPTER_INFO AdapterInfo[20];              // Allocate information for up to 16 NICs
    DWORD dwBufLen = sizeof(IP_ADAPTER_INFO); //10 * sizeof(IP_ADAPTER_INFO);  // Save the memory size of buffer
    i = 3;
    unsigned int i = 3;
    do {
        pAdapterInfo = (PIP_ADAPTER_INFO) malloc(dwBufLen);
        dwStatus = GetAdaptersInfo(               // Call GetAdapterInfo
@@ -160,9 +155,9 @@
  *adapter_info_size = dwBufLen / sizeof(IP_ADAPTER_INFO);
    memset(adapterInfos, 0, dwBufLen);
    pAdapter = pAdapterInfo;
    PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
    i = 0;
    result = FUNC_RET_OK;
    FUNCTION_RETURN result = FUNC_RET_OK;
    while (pAdapter) {
        strncpy(adapterInfos[i].description, pAdapter->Description,
                min(sizeof(adapterInfos->description),
@@ -191,19 +186,17 @@
    return result;
}
// TODO: remove unused
static void printHash(HCRYPTHASH* hHash) {
    BYTE *pbHash;
    DWORD dwHashLen;
    DWORD dwHashLenSize = sizeof(DWORD);
    char* hashStr;
    unsigned int i;
    if (CryptGetHashParam(*hHash, HP_HASHSIZE, (BYTE *) &dwHashLen,
            &dwHashLenSize, 0)) {
        pbHash = (BYTE*) malloc(dwHashLen);
        hashStr = (char*) malloc(dwHashLen * 2 + 1);
        BYTE* pbHash = (BYTE*)malloc(dwHashLen);
        char* hashStr = (char*)malloc(dwHashLen * 2 + 1);
        if (CryptGetHashParam(*hHash, HP_HASHVAL, pbHash, &dwHashLen, 0)) {
            for (i = 0; i < dwHashLen; i++) {
            for (unsigned int i = 0; i < dwHashLen; i++) {
                sprintf(&hashStr[i * 2], "%02x", pbHash[i]);
            } LOG_DEBUG("Hash to verify: %s", hashStr);
        }
src/library/os/os.c
@@ -1,8 +1,7 @@
//#include <stdlib.h>
#include <stdio.h>
#include "../base/logger.h"
#include "os.h"
#include "../base/logger.h"
#include "public-key.h"
#include <stdio.h>
#ifndef _MSC_VER
@@ -140,7 +139,7 @@
        // container by specifying a container name and setting the 
        // CRYPT_NEWKEYSET flag.
        LOG_INFO("Error in AcquireContext 0x%08x \n", GetLastError());
        if (NTE_BAD_KEYSET == GetLastError()) {
        if (NTE_BAD_KEYSET == (long)GetLastError()) {
            if (!CryptAcquireContext(&hProv, "license++verify",
                    MS_ENHANCED_PROV, PROV_RSA_FULL,
                    CRYPT_NEWKEYSET | CRYPT_VERIFYCONTEXT)) {
@@ -170,7 +169,7 @@
        return FUNC_RET_ERROR;
    }
    if (!CryptHashData(hHash, stringToVerify, (DWORD) strlen(stringToVerify), 0)) {
    if (!CryptHashData(hHash, (const BYTE*)stringToVerify, (DWORD) strlen(stringToVerify), 0)) {
        LOG_ERROR("Error in hashing data 0x%08x ", GetLastError());
        CryptDestroyHash(hHash);
        CryptReleaseContext(hProv, 0);
@@ -180,7 +179,7 @@
    LOG_DEBUG("Lenght %d, hashed Data: [%s]", strlen(stringToVerify), stringToVerify);
    printHash(&hHash);
#endif
    sigBlob = unbase64(signatureB64, (int) strlen(signatureB64), &dwSigLen);
    sigBlob = unbase64(signatureB64, (int) strlen(signatureB64), (int*)&dwSigLen);
    LOG_DEBUG("raw signature lenght %d", dwSigLen);
    if (!CryptVerifySignature(hHash, sigBlob, dwSigLen, hKey, NULL, 0)) {
        LOG_ERROR("Signature not validated!  0x%08x ", GetLastError());