本帖最后由 jixun66 于 2018-3-2 12:10 编辑
对每个字节的高低4位进行交换。
起因:歌者盟视频加密
Swap4Bit.7z
(97.19 KB, 下载次数: 19)
用法:解压,拖放文件到程序上,或自行查阅说明。
#include <fstream>
#include <string>
#include <algorithm>
#define BUFFER_SIZE (4 * 1024)
unsigned char g_buffer[BUFFER_SIZE];
void TransformBuffer(unsigned char* buffer, const int size)
{
for(int i = 0; i < size; i++)
{
const unsigned char c = buffer[i];
buffer[i] = (c >> 4) | (c << 4);
}
}
void ProcessFile(std::wstring path)
{
printf("Processing %ls...\n", path.c_str());
std::fstream in_stream;
std::fstream out_stream;
in_stream.open(path, std::fstream::in | std::fstream::binary);
in_stream.seekg(0, in_stream.end);
int length = static_cast<int>(in_stream.tellg());
in_stream.seekg(0, in_stream.beg);
const std::string::size_type ext_pos = path.find_last_of(L'.');
std::wstring output_path;
if (ext_pos == std::string::npos)
{
output_path = path + L".swap";
} else
{
output_path = path.substr(0, ext_pos) + L".swap" + path.substr(ext_pos);
}
out_stream.open(output_path, std::fstream::out | std::fstream::binary);
char* signed_buffer_ptr = reinterpret_cast<char*>(g_buffer);
while(length > 0)
{
const int transform_size = std::min(BUFFER_SIZE, length);
in_stream.read(signed_buffer_ptr, transform_size);
TransformBuffer(g_buffer, transform_size);
out_stream.write(signed_buffer_ptr, transform_size);
length -= transform_size;
}
}
int wmain(int argc, wchar_t *argv[], wchar_t *envp[])
{
printf("4 bit swapper by jixun66@52pojie\n");
if (argc == 1)
{
printf("Usage: <swap4bit> <file1> [file2 [file3] ...]\n\n");
} else for(int i = 1; i < argc; i++)
{
ProcessFile(argv[i]);
}
return 0;
}
|