某牛人解包器"as-util.h" 逆向代码

说明下,有一天在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 {
	WORD	bfType;
	DWORD	bfSize;
	WORD	bfReserved1;
	WORD	bfReserved2;
	DWORD	bfOffBits;
} BITMAPFILEHEADER,*LPBITMAPFILEHEADER,*PBITMAPFILEHEADER;

typedef struct tagBITMAPINFOHEADER{
	DWORD	biSize;
	LONG	biWidth;
	LONG	biHeight;
	WORD	biPlanes;
	WORD	biBitCount;
	DWORD	biCompression;
	DWORD	biSizeImage;
	LONG	biXPelsPerMeter;
	LONG	biYPelsPerMeter;
	DWORD	biClrUsed;
	DWORD	biClrImportant;
} 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);
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值