說明下,有一天在Ck還是什麼地方有人求某牛人解包器"as-util.h"
的原始碼
由於作者沒有提供此檔案原始碼,我在分析解包器時候順帶分析了一下
如果沒有你用道的函數,只能說抱歉了
可以作為C語言愛好者學習使用 這個類
//"common.h"//This code is write without author's permission.//Reverse by 大師♂羅莊(luozhuang)//http://blog.csdn.net/luozhuang// Generic utilities in "as-util.h"//*****************************************************************************//-----------------------------------------------------------------------------// open_or_die//-----------------------------------------------------------------------------int open_or_die(const std::string& filename, int flags, int mode = 0);int write_file(const std::string& filename, const void* buff, unsigned int len);int write_bmp(const std::string& filename, unsigned char* buff, unsigned long len, unsigned long width, unsigned long height, unsigned short depth_bytes);//-----------------------------------------------------------------------------// get_file_size//-----------------------------------------------------------------------------unsigned long get_file_size(int fd);//-----------------------------------------------------------------------------// get_file_prefix//-----------------------------------------------------------------------------std::string get_file_prefix(const std::string& filename);//-----------------------------------------------------------------------------// get_file_extension//-----------------------------------------------------------------------------std::string get_file_extension(const std::string& filename);//-----------------------------------------------------------------------------// flip_endian//-----------------------------------------------------------------------------unsigned long flip_endian(unsigned long x);
非windows系統編譯需要下面內容:
//This code is write without author's permission.//Reverse by 大師♂羅莊(luozhuang)//http://blog.csdn.net/luozhuang#ifndef _WINGDI_typedef unsigned char BYTE;typedef int WINBOOL,*PWINBOOL,*LPWINBOOL;typedef WINBOOL BOOL;typedef BOOL *PBOOL,*LPBOOL;typedef unsigned short WORD;typedef float FLOAT;typedef unsigned long DWORD;typedef char CHAR;typedef short SHORT;typedef long LONG;typedef struct tagBITMAPFILEHEADER {WORDbfType;DWORDbfSize;WORDbfReserved1;WORDbfReserved2;DWORDbfOffBits;} BITMAPFILEHEADER,*LPBITMAPFILEHEADER,*PBITMAPFILEHEADER;typedef struct tagBITMAPINFOHEADER{DWORDbiSize;LONGbiWidth;LONGbiHeight;WORDbiPlanes;WORDbiBitCount;DWORDbiCompression;DWORDbiSizeImage;LONGbiXPelsPerMeter;LONGbiYPelsPerMeter;DWORDbiClrUsed;DWORDbiClrImportant;} BITMAPINFOHEADER,*LPBITMAPINFOHEADER,*PBITMAPINFOHEADER;#endif#endif /* __ARC4COMMON_H__ */
源檔案:
//This code is not write in author's permission.//Reverse by 大師♂羅莊(luozhuang)//http://blog.csdn.net/luozhuang// This is a set of common functionality in "as-util.h"#include "common.h"#include <cmath>using std::string;using namespace std;//*****************************************************************************// Generic utilities//*****************************************************************************//-----------------------------------------------------------------------------// open_or_die//-----------------------------------------------------------------------------int open_or_die(const string& filename, int flags, int mode) { int fd = open(filename.c_str(), flags, mode); if (fd == -1) { fprintf(stderr, "Could not open %s (%s)\n", filename.c_str(), strerror(errno)); exit(-1); } return fd;}int write_file(const string& filename, const void* buff, unsigned int len){ int v3; v3 = open_or_die(filename, 33537, 384); write(v3, buff, len); return close(v3);}int write_bmp(const string& filename, unsigned char* buff, unsigned long len, unsigned long width, unsigned long height, unsigned short depth_bytes){ BITMAPFILEHEADER bmf; BITMAPINFOHEADER bmi; memset(&bmf, 0, sizeof(bmf)); memset(&bmi, 0, sizeof(bmi)); bmf.bfType = 0x4D42; bmf.bfSize = sizeof(bmf) + sizeof(bmi) + len; bmf.bfOffBits = sizeof(bmf) + sizeof(bmi); bmi.biSize = sizeof(bmi); bmi.biWidth = width; bmi.biHeight = height; bmi.biPlanes = 1; bmi.biBitCount = depth_bytes * 8; int fd = open_or_die(filename + ".bmp", O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, S_IREAD | S_IWRITE); write(fd, &bmf, sizeof(bmf)); write(fd, &bmi, sizeof(bmi)); write(fd, buff, len); return close(fd);}//-----------------------------------------------------------------------------// get_file_size//-----------------------------------------------------------------------------unsigned long get_file_size(int fd) { struct stat file_stat; fstat(fd, &file_stat); return file_stat.st_size;}//-----------------------------------------------------------------------------// get_file_prefix//-----------------------------------------------------------------------------string get_file_prefix(const std::string& filename) { string temp(filename); string::size_type pos = temp.find_last_of("."); if (pos != string::npos) { temp = temp.substr(0, pos); } return temp;}//-----------------------------------------------------------------------------// get_file_prefix//-----------------------------------------------------------------------------string get_file_extension(const std::string& filename) { string temp; string::size_type pos = filename.find_last_of("."); if (pos != string::npos) { temp = filename.substr(pos + 1); } return temp;}//-----------------------------------------------------------------------------// flip_endian//-----------------------------------------------------------------------------unsigned long flip_endian(unsigned long x) { return (x >> 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x << 24);}