TEST(VersionInfo, getVersion) {
  VersionInfo version;
  jsonxx::Object versionJson = version.getVersion();
  
  ASSERT_EQ(1, versionJson.size());
  ASSERT_EQ(VERSION, versionJson.get<string>("version"));
}
Пример #2
0
bool SHMProcess::Private::validate(vector <VersionInfo *> & known_versions)
{
    // try to identify the DF version
    IMAGE_NT_HEADERS32 pe_header;
    IMAGE_SECTION_HEADER sections[16];
    HMODULE hmod = NULL;
    DWORD junk;
    HANDLE hProcess;
    bool found = false;
    identified = false;
    // open process, we only need the process open
    hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, process_ID );
    if (NULL == hProcess)
        return false;

    // try getting the first module of the process
    if(EnumProcessModules(hProcess, &hmod, 1 * sizeof(HMODULE), &junk) == 0)
    {
        CloseHandle(hProcess);
        // cout << "EnumProcessModules fail'd" << endl;
        return false;
    }
    // got base ;)
    uint32_t base = (uint32_t)hmod;

    // read from this process
    uint32_t pe_offset = self->readDWord(base+0x3C);
    self->read(base + pe_offset                   , sizeof(pe_header), (uint8_t *)&pe_header);
    self->read(base + pe_offset+ sizeof(pe_header), sizeof(sections) , (uint8_t *)&sections );

    // iterate over the list of memory locations
    vector<VersionInfo *>::iterator it;
    for ( it=known_versions.begin() ; it < known_versions.end(); it++ )
    {
        uint32_t pe_timestamp;
        try
        {
            pe_timestamp = (*it)->getPE();
        }
        catch(Error::MissingMemoryDefinition&)
        {
            continue;
        }
        if (pe_timestamp == pe_header.FileHeader.TimeDateStamp)
        {
            VersionInfo *m = new VersionInfo(**it);
            m->RebaseAll(base);
            memdescriptor = m;
            m->setParentProcess(self);
            identified = true;
            cerr << "identified " << m->getVersion() << endl;
            CloseHandle(hProcess);
            return true;
        }
    }
    return false;
}
int main(int argc, char **argv) {

  Gtk::Main kit(argc, argv);

  InputParser parser(cin);
  _log("Parsing input...");
  Object json = parser.readBody();

  if (json.has<string>("lang")) {
    l10nLabels.setLanguage(json.get<string>("lang"));
  }

  string response;

  if (json.get<string>("protocol") != "https:") {
    ExtensionDialog dialog;
    response = dialog.error(ONLY_HTTPS_ALLOWED).json();
  } else {
    string type = json.get<string>("type");

    if (type == "SIGN") {
      string hashFromStdIn = json.get<String>("hash");
      string certId = json.get<String>("id");
      _log("signing hash: %s, with certId: %s", hashFromStdIn.c_str(), certId.c_str());
      Signer signer(hashFromStdIn, certId);
      response = signer.sign().json();
    } else if (type == "CERT") {
      CertificateSelection cert;
      response = cert.getCert().json();
    } else if (type == "VERSION") {
      VersionInfo version;
      response = version.getVersion().json();
    }
  }
  int responseLength = response.size();
  unsigned char *responseLengthAsBytes = intToBytesLittleEndian(responseLength);
  cout.write((char *) responseLengthAsBytes, 4);
  _log("Response(%i) %s ", responseLength, response.c_str());
  cout << response << endl;
  free(responseLengthAsBytes);
  return EXIT_SUCCESS;
}