@byxiaoxie3 年前

09/9
18:11
Home

C++ 查询内存页属性

std::string QueryMemInfo(LPVOID address)
{
	MEMORY_BASIC_INFORMATION meminfo;
	VirtualQueryEx(GameHandle, address, &meminfo, sizeof(meminfo));  //查询内存页属性保存到[meminfo]

	PVOID base_address = meminfo.BaseAddress;
	PVOID alloc_base = meminfo.AllocationBase;
	DWORD alloc_protect = meminfo.AllocationProtect;
	DWORD region_size = meminfo.RegionSize;
	DWORD state = meminfo.State;
	DWORD protect = meminfo.Protect;
	DWORD type = meminfo.Type;

	std::string s_alloc_protect;
	if (alloc_protect & PAGE_NOACCESS)                // 0x0001
		s_alloc_protect = "NoAccess";
	if (alloc_protect & PAGE_READONLY)                // 0x0002
		s_alloc_protect = "Readonly";
	else if (alloc_protect & PAGE_READWRITE)          // 0x0004
		s_alloc_protect = "ReadWrite";
	else if (alloc_protect & PAGE_WRITECOPY)          // 0x0008
		s_alloc_protect = "WriteCopy";
	else if (alloc_protect & PAGE_EXECUTE)            // 0x0010
		s_alloc_protect = "Execute";
	else if (alloc_protect & PAGE_EXECUTE_READ)       // 0x0020
		s_alloc_protect = "Execute_Read";
	else if (alloc_protect & PAGE_EXECUTE_READWRITE)  // 0x0040
		s_alloc_protect = "Execute_ReadWrite";
	else if (alloc_protect & PAGE_EXECUTE_WRITECOPY)  // 0x0080
		s_alloc_protect = "Execute_WriteCopy";
	if (alloc_protect & PAGE_GUARD)                   // 0x0100
		s_alloc_protect += "+Guard";
	if (alloc_protect & PAGE_NOCACHE)                 // 0x0200
		s_alloc_protect += "+NoCache";

	std::string s_state;
	if (state == MEM_COMMIT)
		s_state = "Commit ";
	else if (state == MEM_FREE)
		s_state = "Free   ";
	else if (state == MEM_RESERVE)
		s_state = "Reserve";
	else
		s_state = "Damned ";

	std::string s_protect;
	if (protect & PAGE_NOACCESS)
		s_protect = "NoAccess";
	if (protect & PAGE_READONLY)
		s_protect = "Readonly";
	else if (protect & PAGE_READWRITE)
		s_protect = "ReadWrite";
	else if (protect & PAGE_WRITECOPY)
		s_protect = "WriteCopy";
	else if (protect & PAGE_EXECUTE)
		s_protect = "Execute";
	else if (protect & PAGE_EXECUTE_READ)
		s_protect = "Execute_Read";
	else if (protect & PAGE_EXECUTE_READWRITE)
		s_protect = "Execute_ReadWrite";
	else if (protect & PAGE_EXECUTE_WRITECOPY)
		s_protect = "Execute_WriteCopy";
	if (protect & PAGE_GUARD)
		s_protect += "+Guard";
	if (protect & PAGE_NOCACHE)
		s_protect += "+NoCache";

	std::string s_type;
	if (type == MEM_IMAGE)
		s_type = "Image  ";
	else if (type == MEM_MAPPED)
		s_type = "Free   ";
	else if (type == MEM_PRIVATE)
		s_type = "Private";
	else
		s_type = "-      ";

	char buf[128] = { '/0' };
	sprintf(buf, "%8X %8X %25s %7s %25s %7s %8X", base_address, alloc_base,s_alloc_protect.c_str(), s_state.c_str(), s_protect.c_str(), s_type.c_str(), region_size);

	return std::string(buf);
}

int main(){
	HANDLE GameHandle = 0x0; //游戏句柄
	LPVOID BaseAddress = NULL; //游戏模块
	QueryMemInfo(GetBaseAddress + OFFSET_Role);  //调用方法
}

不提供完整的C++代码,仅查询内存页属性代码

C++ 查询内存页属性

@byxiaoxie6 年前

03/12
23:41
Home

C# 查IP国家/地区

引用:using System.Net;
/// <summary>
/// 查IP国家/地区
/// </summary>
/// <param name="strIP"></param>
/// <returns></returns>
public static string GetIPCitys(string strIP)
{
    string Url = null;
    string Text = null;
    string c = null;
    try
    {
        Url = "http://opendata.baidu.com/api.php?query=" + strIP + "&co=&resource_id=6006&t=1412300361645&ie=utf8&oe=gbk&cb=op_aladdin_callback&format=json&tn=baidu&cb=jQuery1102026811896078288555_1412299994977&_=1412299994981";
	WebRequest wReq = System.Net.WebRequest.Create(Url);
        wReq.Timeout = 2000;
        WebResponse wResp = wReq.GetResponse();
        Stream respStream = wResp.GetResponseStream();
        StreamReader reader = new StreamReader(respStream, Encoding.GetEncoding("gb2312"));
        Text = reader.ReadToEnd();
		
	//取文本内容中间文字 - 开始
        int i = Text.IndexOf("location\":\"") + 11;
        int j = Text.IndexOf("titlecont")-5;
        c = Text.Substring(i, j - i + 2);
	//取文本内容中间文字 - 结束
		
        if (c != "")
        {
            return c;
        }
        else
        {
            c = "未知";
        }
    }
    catch
    {
        c = "错误";
    }
    return c;
}

 

C# 查IP国家/地区

@byxiaoxie6 年前

08/30
23:26
Home

C# ini配置文件读写

ini.cs 源代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace ini_config
{
    /// <summary>
    /// ini文件类
    /// </summary>
    public class IniFile
    {
        private string m_FileName;

        public string FileName
        {
            get { return m_FileName; }
            set { m_FileName = value; }
        }

        [DllImport("kernel32.dll")]
        private static extern int GetPrivateProfileInt(
            string lpAppName,
            string lpKeyName,
            int nDefault,
            string lpFileName
            );

        [DllImport("kernel32.dll")]
        private static extern int GetPrivateProfileString(
            string lpAppName,
            string lpKeyName,
            string lpDefault,
            StringBuilder lpReturnedString,
            int nSize,
            string lpFileName
            );

        [DllImport("kernel32.dll")]
        private static extern int WritePrivateProfileString(
            string lpAppName,
            string lpKeyName,
            string lpString,
            string lpFileName
            );

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="aFileName">Ini文件路径</param>
        public IniFile(string aFileName)
        {
            this.m_FileName = aFileName;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public IniFile()
        { }

        /// <summary>
        /// [扩展]读Int数值
        /// </summary>
        /// <param name="section">节</param>
        /// <param name="name">键</param>
        /// <param name="def">默认值</param>
        /// <returns></returns>
        public int ReadInt(string section, string name, int def)
        {
            return GetPrivateProfileInt(section, name, def, this.m_FileName);
        }

        /// <summary>
        /// [扩展]读取string字符串
        /// </summary>
        /// <param name="section">节</param>
        /// <param name="name">键</param>
        /// <param name="def">默认值</param>
        /// <returns></returns>
        public string ReadString(string section, string name, string def)
        {
            StringBuilder vRetSb = new StringBuilder(2048);
            GetPrivateProfileString(section, name, def, vRetSb, 2048, this.m_FileName);
            return vRetSb.ToString();
        }

        /// <summary>
        /// [扩展]写入Int数值,如果不存在 节-键,则会自动创建
        /// </summary>
        /// <param name="section">节</param>
        /// <param name="name">键</param>
        /// <param name="Ival">写入值</param>
        public void WriteInt(string section, string name, int Ival)
        {

            WritePrivateProfileString(section, name, Ival.ToString(), this.m_FileName);
        }

        /// <summary>
        /// [扩展]写入String字符串,如果不存在 节-键,则会自动创建
        /// </summary>
        /// <param name="section">节</param>
        /// <param name="name">键</param>
        /// <param name="strVal">写入值</param>
        public void WriteString(string section, string name, string strVal)
        {
            WritePrivateProfileString(section, name, strVal, this.m_FileName);
        }

        /// <summary>
        /// 删除指定的 节
        /// </summary>
        /// <param name="section"></param>
        public void DeleteSection(string section)
        {
            WritePrivateProfileString(section, null, null, this.m_FileName);
        }

        /// <summary>
        /// 删除全部 节
        /// </summary>
        public void DeleteAllSection()
        {
            WritePrivateProfileString(null, null, null, this.m_FileName);
        }

        /// <summary>
        /// 读取指定 节-键 的值
        /// </summary>
        /// <param name="section"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public string IniReadValue(string section, string name)
        {
            StringBuilder strSb = new StringBuilder(256);
            GetPrivateProfileString(section, name, "", strSb, 256, this.m_FileName);
            return strSb.ToString();
        }

        /// <summary>
        /// 写入指定值,如果不存在 节-键,则会自动创建
        /// </summary>
        /// <param name="section"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        public void IniWriteValue(string section, string name, string value)
        {
            WritePrivateProfileString(section, name, value, this.m_FileName);
        }
    }
}

阅读全文 →

C# ini配置文件读写

@byxiaoxie7 年前

03/14
10:03
Home

C语言学习(弃坑)

变量类型与输出类型:

int d = 10; //整数型
long ld = 10; //长整型
unsigned ud = 65535 //无符号整型
float f = 1.0; //单精度浮点型
double lf = 1E2; //双精度浮点型
char p = 'C language'; //字符串
char *p = "C language"; //指针字符串

printf("%s\n",p); //字符串输出
printf("%d\n",p); //整数型输出
printf("%f\n",p); //单精度浮点输出
printf("%o\n",p); //八进制输出
printf("%x\n",p); //十六进制输出
printf("%ld\n",p); //长整型输出
printf("%lf\n",p); //双精度浮点输出 
printf("%c\n",p); //字符型输出 
//中文输出
const char text[] = "测试"; 
printf("\n",printf(text));

阅读全文 →

C语言学习(弃坑)

加载中……