-
Content Count
309 -
Joined
-
Last visited
-
Days Won
18
Files posted by 墨香年少
-
Updated
-
Submitted
-
Submitted
-
Submitted
-
Submitted
-
Submitted
-
Updated
-
Updated
-
Updated
-
Updated
-
Submitted
-
c++制作的二维码生成器
QrToPng.h:
// // Created by remy on 07-06-20. // #ifndef QR_TO_PNG_H #define QR_TO_PNG_H #include "QrCode.hpp" #include "TinyPngOut.hpp" #include <fstream> #include <iostream> #include <memory> #include <string> #include <stdio.h> #include <io.h> class QrToPng { public: /** * Gives an object containing all the data to create the QR code. When @writeToPNG() is called, * the actual file is constructed and written. * The image is scaled to fit in the given size as much as possible relative to the QR code * size. * @param fileName relative or absolute filename to write image to. Relative will be in CWD. * @param imgSize The height and width of the image. Image is square, so will be width and height. * @param minModulePixelSize How many pixels big should a qr module be (a white or black dot)? * @param text The text to encode in the QR code. * @param overwriteExistingFile Overwrite if a file with @fileName already exists? * @param ecc error correction (low,mid,high). */ QrToPng(std::string fileName, int imgSize, int minModulePixelSize, std::string text, bool overwriteExistingFile, qrcodegen::QrCode::Ecc ecc); /** Writes a QrToPng object to a png file at @_fileName. * @return true if file could be written, false if file could not be written */ bool writeToPNG(); private: std::string _fileName; int _size; int _minModulePixelSize; std::string _text; bool _overwriteExistingFile; qrcodegen::QrCode::Ecc _ecc; bool _writeToPNG(const qrcodegen::QrCode &qrData) const; uint32_t _imgSize(const qrcodegen::QrCode &qrData) const; uint32_t _imgSizeWithBorder(const qrcodegen::QrCode &qrData) const; bool file_exists(std::string file_name) const; }; #endif //QR_TO_PNG_H QrToPng.cpp:
// // Created by remy on 02-06-20. // #include "QrToPng.h" QrToPng::QrToPng(std::string fileName, int imgSize, int minModulePixelSize, std::string text, bool overwriteExistingFile, qrcodegen::QrCode::Ecc ecc) : _fileName(std::move(fileName)), _size(imgSize), _minModulePixelSize(minModulePixelSize), _text(std::move(text)), _overwriteExistingFile(overwriteExistingFile), _ecc(ecc) { } bool QrToPng::writeToPNG() { /* text is required */ if (_text.empty()) return false; if (!_overwriteExistingFile and file_exists(_fileName)) return false; auto _qr = qrcodegen::QrCode::encodeText("", _ecc); try { _qr = qrcodegen::QrCode::encodeText(_text.c_str(), _ecc); } catch (const std::length_error &e) { std::cerr << "Failed to generate QR code, too much data. Decrease _ecc, enlarge size or give less text." << std::endl; std::cerr << "e.what(): " << e.what() << std::endl; return false; } if (_overwriteExistingFile and file_exists(_fileName)) { /*if (!fs::copy_file(_fileName, _fileName + ".tmp", fs::copy_options::overwrite_existing)) { return false; }*/ } auto result = _writeToPNG(_qr); if (result) { std::string tmp_file(_fileName + ".tmp"); remove(tmp_file.c_str()); } return result; } bool QrToPng::_writeToPNG(const qrcodegen::QrCode &qrData) const { std::ofstream out(_fileName.c_str(), std::ios::binary); int pngWH = _imgSizeWithBorder(qrData); TinyPngOut pngout(pngWH, pngWH, out); auto qrSize = qrData.getSize(); auto qrSizeWithBorder = qrData.getSize() + 2; if (qrSizeWithBorder > _size) return false; // qrcode doesn't fit int qrSizeFitsInMaxImgSizeTimes = _size / qrSizeWithBorder; int pixelsWHPerModule = qrSizeFitsInMaxImgSizeTimes; if (qrSizeFitsInMaxImgSizeTimes < _minModulePixelSize) return false; // image would be to small to scan std::vector<uint8_t> tmpData; const uint8_t blackPixel = 0x00; const uint8_t whitePixel = 0xFF; /* The below loop converts the qrData to RGB8.8.8 pixels and writes it with * the tinyPNGoutput library. since we probably have requested a larger * qr module pixel size we must transform the qrData modules to be larger * pixels (than just 1x1). */ // border above for (int i = 0; i < pngWH; i++) // row for (int j = 0; j < pixelsWHPerModule; j++) // module pixel (height) tmpData.insert(tmpData.end(), {whitePixel, whitePixel, whitePixel}); pngout.write(tmpData.data(), static_cast<size_t>(tmpData.size() / 3)); tmpData.clear(); for (int qrModuleAtY = 0; qrModuleAtY < qrSize; qrModuleAtY++) { for (int col = 0; col < pixelsWHPerModule; col++) { // border left for (int i = 0; i < qrSizeFitsInMaxImgSizeTimes; ++i) tmpData.insert(tmpData.end(), {whitePixel, whitePixel, whitePixel}); // qr module to pixel for (int qrModuleAtX = 0; qrModuleAtX < (qrSize); qrModuleAtX++) { for (int row = 0; row < qrSizeFitsInMaxImgSizeTimes; ++row) { if (qrData.getModule(qrModuleAtX, qrModuleAtY)) { // insert saves us a for loop or 3 times the same line. tmpData.insert(tmpData.end(), {blackPixel, blackPixel, blackPixel}); } else { tmpData.insert(tmpData.end(), {whitePixel, whitePixel, whitePixel}); } } } // border right for (int i = 0; i < qrSizeFitsInMaxImgSizeTimes; ++i) tmpData.insert(tmpData.end(), {whitePixel, whitePixel, whitePixel}); // write the entire row pngout.write(tmpData.data(), static_cast<size_t>(tmpData.size() / 3)); tmpData.clear(); } } // border below for (int i = 0; i < pngWH; i++) // row for (int j = 0; j < pixelsWHPerModule; j++) // module pixel (height) tmpData.insert(tmpData.end(), {whitePixel, whitePixel, whitePixel}); pngout.write(tmpData.data(), static_cast<size_t>(tmpData.size() / 3)); tmpData.clear(); return file_exists(_fileName); } uint32_t QrToPng::_imgSize(const qrcodegen::QrCode &qrData) const { return (_size / qrData.getSize()) * qrData.getSize(); } uint32_t QrToPng::_imgSizeWithBorder(const qrcodegen::QrCode &qrData) const { return (_size / (qrData.getSize() + 2)) * (qrData.getSize() + 2); } bool QrToPng::file_exists(std::string file_name) const { if ((_access(file_name.c_str(), 0) == 0) > 0) { return true; } return false; } TinyPngOut.hpp:
/* * Tiny PNG Output (C++) * * Copyright (c) 2018 Project Nayuki * https://www.nayuki.io/page/tiny-png-output * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program (see COPYING.txt and COPYING.LESSER.txt). * If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <cstddef> #include <cstdint> #include <ostream> /* * Takes image pixel data in raw RGB8.8.8 format and writes a PNG file to a byte output stream. */ class TinyPngOut final { /*---- Fields ----*/ // Immutable configuration private: std::uint32_t width; // Measured in pixels private: std::uint32_t height; // Measured in pixels private: std::uint32_t lineSize; // Measured in bytes, equal to (width * 3 + 1) // Running state private: std::ostream &output; private: std::uint32_t positionX; // Next byte index in current line private: std::uint32_t positionY; // Line index of next byte private: std::uint32_t uncompRemain; // Number of uncompressed bytes remaining private: std::uint16_t deflateFilled; // Bytes filled in the current block (0 <= n < DEFLATE_MAX_BLOCK_SIZE) private: std::uint32_t crc; // Primarily for IDAT chunk private: std::uint32_t adler; // For DEFLATE data within IDAT /*---- Public constructor and method ----*/ /* * Creates a PNG writer with the given width and height (both non-zero) and byte output stream. * TinyPngOut will leave the output stream still open once it finishes writing the PNG file data. * Throws an exception if the dimensions exceed certain limits (e.g. w * h > 700 million). */ public: explicit TinyPngOut(std::uint32_t w, std::uint32_t h, std::ostream &out); /* * Writes 'count' pixels from the given array to the output stream. This reads count*3 * bytes from the array. Pixels are presented from top to bottom, left to right, and with * subpixels in RGB order. This object keeps track of how many pixels were written and * various position variables. It is an error to write more pixels in total than width*height. * Once exactly width*height pixels have been written with this TinyPngOut object, * there are no more valid operations on the object and it should be discarded. */ public: void write(const std::uint8_t pixels[], size_t count); /*---- Private checksum methods ----*/ // Reads the 'crc' field and updates its value based on the given array of new data. private: void crc32(const std::uint8_t data[], size_t len); // Reads the 'adler' field and updates its value based on the given array of new data. private: void adler32(const std::uint8_t data[], size_t len); /*---- Private utility members ----*/ private: template <std::size_t N> void write(const std::uint8_t(&data)[N]) { output.write(reinterpret_cast<const char*>(data), sizeof(data)); } private: static void putBigUint32(std::uint32_t val, std::uint8_t array[4]); private: static constexpr std::uint16_t DEFLATE_MAX_BLOCK_SIZE = 65535; }; TinyPngOut.cpp:
/* * Tiny PNG Output (C++) * * Copyright (c) 2018 Project Nayuki * https://www.nayuki.io/page/tiny-png-output * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program (see COPYING.txt and COPYING.LESSER.txt). * If not, see <http://www.gnu.org/licenses/>. */ #include <algorithm> #include <cassert> #include <limits> #include <stdexcept> #include "TinyPngOut.hpp" using std::uint8_t; using std::uint16_t; using std::uint32_t; using std::uint64_t; using std::size_t; TinyPngOut::TinyPngOut(uint32_t w, uint32_t h, std::ostream &out) : // Set most of the fields width(w), height(h), output(out), positionX(0), positionY(0), deflateFilled(0), adler(1) { // Check arguments if (width == 0 || height == 0) throw std::domain_error("Zero width or height"); // Compute and check data siezs uint64_t lineSz = static_cast<uint64_t>(width) * 3 + 1; if (lineSz > UINT32_MAX) throw std::length_error("Image too large"); lineSize = static_cast<uint32_t>(lineSz); uint64_t uncompRm = lineSize * height; if (uncompRm > UINT32_MAX) throw std::length_error("Image too large"); uncompRemain = static_cast<uint32_t>(uncompRm); uint32_t numBlocks = uncompRemain / DEFLATE_MAX_BLOCK_SIZE; if (uncompRemain % DEFLATE_MAX_BLOCK_SIZE != 0) numBlocks++; // Round up // 5 bytes per DEFLATE uncompressed block header, 2 bytes for zlib header, 4 bytes for zlib Adler-32 footer uint64_t idatSize = static_cast<uint64_t>(numBlocks) * 5 + 6; idatSize += uncompRemain; if (idatSize > static_cast<uint32_t>(INT32_MAX)) throw std::length_error("Image too large"); // Write header (not a pure header, but a couple of things concatenated together) uint8_t header[] = { // 43 bytes long // PNG header 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, // IHDR chunk 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, 0, 0, 0, 0, // 'width' placeholder 0, 0, 0, 0, // 'height' placeholder 0x08, 0x02, 0x00, 0x00, 0x00, 0, 0, 0, 0, // IHDR CRC-32 placeholder // IDAT chunk 0, 0, 0, 0, // 'idatSize' placeholder 0x49, 0x44, 0x41, 0x54, // DEFLATE data 0x08, 0x1D, }; putBigUint32(width, &header[16]); putBigUint32(height, &header[20]); putBigUint32(idatSize, &header[33]); crc = 0; crc32(&header[12], 17); putBigUint32(crc, &header[29]); write(header); crc = 0; crc32(&header[37], 6); // 0xD7245B6B } void TinyPngOut::write(const uint8_t pixels[], size_t count) { if (count > SIZE_MAX / 3) throw std::length_error("Invalid argument"); count *= 3; // Convert pixel count to byte count while (count > 0) { if (pixels == nullptr) throw std::invalid_argument("Null pointer"); if (positionY >= height) throw std::logic_error("All image pixels already written"); if (deflateFilled == 0) { // Start DEFLATE block uint16_t size = DEFLATE_MAX_BLOCK_SIZE; if (uncompRemain < size) size =7 downloads
Updated
-
数字金额大写转换工具
basic_form.h:
#pragma once class BasicForm : public ui::WindowImplBase { public: BasicForm(); ~BasicForm(); virtual std::wstring GetSkinFolder() override; virtual std::wstring GetSkinFile() override; virtual std::wstring GetWindowClassName() const override; bool OnClicked(ui::EventArgs* msg); virtual void InitWindow() override; virtual LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); static const std::wstring kClassName; ui::RichEdit* num; ui::RichEdit* zh_num; std::wstring string2wstring(std::string str); std::string wstring2string(std::wstring wstr); std::string ChineseCapitalMoney(double Num); }; basic_form.cpp:
#include "framework.h" #include "basic_form.h" #include <string> #include <cstdlib> #include <atlstr.h> const std::wstring BasicForm::kClassName = L"Basic"; BasicForm::BasicForm() { } BasicForm::~BasicForm() { } std::wstring BasicForm::GetSkinFolder() { return L"basic"; } std::wstring BasicForm::GetSkinFile() { return L"basic.xml"; } std::wstring BasicForm::GetWindowClassName() const { return kClassName; } void BasicForm::InitWindow() { num = (ui::RichEdit*)FindControl(L"num"); zh_num = (ui::RichEdit*)FindControl(L"zh_num"); m_pRoot->AttachBubbledEvent(ui::kEventClick, nbase::Bind(&BasicForm::OnClicked, this, std::placeholders::_1)); } bool BasicForm::OnClicked(ui::EventArgs* msg) { std::wstring name = msg->pSender->GetName(); if (name == L"do_transe") { std::string _num = wstring2string(num->GetText()); double double_num = atof(_num.c_str()); std::string _cn_num = ChineseCapitalMoney(double_num); zh_num->SetText(string2wstring(_cn_num)); } else { } return true; } LRESULT BasicForm::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { PostQuitMessage(0L); return __super::OnClose(uMsg, wParam, lParam, bHandled); } std::wstring BasicForm::string2wstring(std::string str) { std::wstring result; int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), NULL, 0); TCHAR* buffer = new TCHAR[len + 1]; MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), buffer, len); buffer[len] = '\0'; result.append(buffer); delete[] buffer; return result; } std::string BasicForm::wstring2string(std::wstring wstr) { std::string result; int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), NULL, 0, NULL, NULL); char* buffer = new char[len + 1]; WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), buffer, len, NULL, NULL); buffer[len] = '\0'; result.append(buffer); delete[] buffer; return result; } std::string BasicForm::ChineseCapitalMoney(double Num) { std::string szChMoney; CString szNum; int iLen, iNum, iAddZero = 0; const char* hzUnit[18] = { "分","角","元","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟","万","拾","佰","仟" }; const char* hzNum[10] = { "零","壹","贰","叁","肆","伍","陆","柒","捌","玖" }; szNum.Format(_T("%18.0f"), Num * 100); //只是到分 szNum.TrimLeft(); iLen = szNum.GetLength(); if (iLen > 15 || iLen == 0 || Num < 0)return ""; //数据错误返回 for (int i = 0; i < iLen; i++) { iNum = _ttoi((LPCTSTR)szNum.Mid(i, 1)); if (iNum == 0)//如果为0 iAddZero++; else { if (iAddZero > 0) szChMoney += "零"; szChMoney += hzNum[iNum];//转换为相应的数字 iAddZero = 0; } if (iNum != 0 || iLen - i == 3 || iLen - i == 11 || ((iLen - i + 1) % 8 == 0 && iAddZero < 4)) szChMoney += hzUnit[iLen - i - 1];//添加相应的汉字 } if (szNum.Right(2) == _T("00")) //没有角和分 szChMoney += "整"; return szChMoney; }
1 download
Submitted
-
忘记winscp密码找回
/* Copyright (c) 2011, Aurelien Aptel <aurelien.aptel@gmail.com> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <string> #include <fstream> #include <iostream> #include <cstdlib> #include <vector> using namespace std; typedef unsigned char uchar; #define PW_MAGIC 0xA3 #define PW_MAXLEN 50 #define PW_FLAG 0xFF string decrypt(string pwd, string key); #ifdef WIN #include <windows.h> #define REG_MAXLEN_KEY 255 #define REG_MAXLEN_VAL 16383 const string session_path = TEXT("SOFTWARE\\Martin Prikryl\\WinSCP 2\\Sessions"); // mostly from MSDN bool reg_get_list (string key, vector<string>& keylist, vector<string>& vallist) { HKEY hKey; TCHAR achKey[REG_MAXLEN_KEY]; // buffer for subkey name DWORD cbName; // size of name string TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name DWORD cchClassName = MAX_PATH; // size of class string DWORD cSubKeys=0; // number of subkeys DWORD cbMaxSubKey; // longest subkey size DWORD cchMaxClass; // longest class string DWORD cValues; // number of values for key DWORD cchMaxValue; // longest value name DWORD cbMaxValueData; // longest value data DWORD cbSecurityDescriptor; // size of security descriptor FILETIME ftLastWriteTime; // last write time DWORD i, retCode; TCHAR achValue[REG_MAXLEN_VAL]; DWORD cchValue = REG_MAXLEN_VAL; retCode = RegOpenKeyExA(HKEY_CURRENT_USER, key.c_str(), 0, KEY_READ, &hKey); if(retCode != ERROR_SUCCESS) { cout << "bark\n"; return false; } // Get the class name and the value count. retCode = RegQueryInfoKey( hKey, // key handle achClass, // buffer for class name &cchClassName, // size of class string NULL, // reserved &cSubKeys, // number of subkeys &cbMaxSubKey, // longest subkey size &cchMaxClass, // longest class string &cValues, // number of values for this key &cchMaxValue, // longest value name &cbMaxValueData, // longest value data &cbSecurityDescriptor, // security descriptor &ftLastWriteTime); // last write time if (cSubKeys) { // printf( "\nNumber of subkeys: %lu\n", cSubKeys); for (i=0; i<cSubKeys; i++) { cbName = REG_MAXLEN_KEY; retCode = RegEnumKeyEx(hKey, i, achKey, &cbName, NULL, NULL, NULL, &ftLastWriteTime); if (retCode == ERROR_SUCCESS) { // printf("(%lu) %s\n", i+1, achKey); keylist.push_back(achKey); } } } if (cValues) { // printf( "\nNumber of values: %lu\n", cValues); for (i=0, retCode=ERROR_SUCCESS; i<cValues; i++) { cchValue = REG_MAXLEN_VAL; achValue[0] = '\0'; retCode = RegEnumValue(hKey, i, achValue, &cchValue, NULL, NULL, NULL, NULL); if(retCode == ERROR_SUCCESS) { // printf("(%lu) %s\n", i+1, achValue); vallist.push_back(achValue); } } } RegCloseKey(hKey); return true; } bool reg_get_key (string location, string name, string& val) { HKEY key; TCHAR value[1024]; DWORD bufLen = 1024*sizeof(TCHAR); long ret; ret = RegOpenKeyExA(HKEY_CURRENT_USER, location.c_str(), 0, KEY_QUERY_VALUE, &key); if(ret != ERROR_SUCCESS) { return false; } ret = RegQueryValueExA(key, name.c_str(), 0, 0, (LPBYTE) value, &bufLen); RegCloseKey(key); if ( (ret != ERROR_SUCCESS) || (bufLen > 1024*sizeof(TCHAR)) ){ return false; } string stringValue = string(value, (size_t)bufLen - 1); size_t i = stringValue.length(); while( i > 0 && stringValue[i-1] == '\0' ){ --i; } val = stringValue; return true; } void decrypt_registry_session (string session) { const string kuser = TEXT("UserName"), khost = TEXT("HostName"), kpw = TEXT("Password"), ktunuser = TEXT("TunnelUserName"), ktunhost = TEXT("TunnelHostName"), ktunpw = TEXT("TunnelPassword"); bool r = true; string user, host, pw; string path = session_path + TEXT("\\") + session; // normal session r = r && reg_get_key(path, kuser, user); r = r && reg_get_key(path, khost, host); r = r && reg_get_key(path, kpw, pw); if(r) cout << user << "@" << host << "\t" << decrypt(pw, user+host) << "\n"; // tunnel session r = r && reg_get_key(path, ktunuser, user); r = r && reg_get_key(path, ktunhost, host); r = r && reg_get_key(path, ktunpw, pw); if(r) cout << user << "@" << host << "\t" << decrypt(pw, user+host) << "\n"; } void read_registry () { vector<string> keylist, vallist; bool r; r = reg_get_list(session_path, keylist, vallist); for(int i = 0; i < keylist.size(); i++) decrypt_registry_session(keylist[i]); } #endif int dec_next_char(string &s) { if(s.length() <= 0) return 0; const string base = "0123456789ABCDEF"; int a = base.find(s[0]); int b = base.find(s[1]); uchar r = (uchar) ~((a << 4) + (b << 0) ^ PW_MAGIC); s.erase(0, 2); return r; } string decrypt(string pwd, string key) { string clearpwd; uchar length, flag; flag = dec_next_char(pwd); if(flag == PW_FLAG) { dec_next_char(pwd); length = dec_next_char(pwd); } else length = flag; pwd.erase(0, (dec_next_char(pwd))*2); for(int i = 0; i < length; i++) clearpwd += (char)dec_next_char(pwd); if(flag == PW_FLAG) { if(clearpwd.substr(0, key.length()) != key) clearpwd = ""; else clearpwd.erase(0, key.length()); } return clearpwd; } string clean (string s) { int len = s.length(); if(len && s[len-1] == '\r') s.erase(len-1, 1); return s; } void parse_wscp_conf (char* path) { string l; string host, user, pwd; string tunnel_host, tunnel_user, tunnel_pwd; ifstream f(path); if(!f.is_open()) { cerr << "Cannot open " << path << "\n"; exit(1); } cerr << "reading " << path << "\n"; while(f.good()) { getline(f, l); if(l.substr(0, 9) == "UserName=") { user = clean(l.substr(9)); } else if(l.substr(0, 15) == "TunnelUserName=") { tunnel_user = clean(l.substr(15)); } else if(l.substr(0, 9) == "HostName=") { host = clean(l.substr(9)); } else if(l.substr(0, 15) == "TunnelHostName=") { tunnel_host = clean(l.substr(15)); } else if(l.substr(0, 9) == "Password=" || l.substr(0,15) == "TunnelPassword=") { int password_start = l.find_first_of('=') + 1; bool is_tunnel = password_start == 9; pwd = clean(l.substr(password_start)); if(is_tunnel && !user.empty() && !host.empty() && !pwd.empty()) { cout << user << "@" << host << "\t" << decrypt(pwd, user+host) << "\n"; } else if(!is_tunnel && !tunnel_user.empty() && !tunnel_host.empty()) { cout << tunnel_user << "@" << tunnel_host << "\t" << decrypt(pwd, tunnel_user+tunnel_host) << "\n"; } user = host = pwd = ""; } } f.close(); } int main (int argc, char** argv) { string user, host, pwd; switch(argc-1) { #ifdef WIN case 0: read_registry(); break; #endif case 1: if(string("-h") == argv[1] || string("/?") == argv[1]) goto help; parse_wscp_conf(argv[1]); break; case 3: user = argv[1]; host = argv[2]; pwd = argv[3]; cout << user << "@" << host << "\t" << decrypt(pwd, user+host); break; help: default: cerr << "Restore stored password from WinSCP.\n" << "Usage:\n\t" << argv[0] << " [user host cryptedpwd | path/to/winscp.ini | -h | /? ]\n" << "On Windows, no options means look up in the registry.\n" << "\nExamples:\n" << "\t" << argv[0] << " foo example.com A35C4E4502235B7335F65E12961302012888799B78BAF39F5A632CA6073A333339243D312C3039723F33313F3D3739B012F6\n" << "\t" << argv[0] << " /tmp/winscp.ini\n"; break; } return 0; }
22 downloads
Updated
-
Submitted
-
Submitted
-
Submitted