sizeof

Size of classes with virtual functions GCC/Xcode

只愿长相守 提交于 2019-12-06 14:21:28
问题 Can anyone explain to me what is going on here? First off, I think most programmers know that a class with a virtual function has a vtbl and thus has 4 extra bytes on the top of it. As far as I know, that's fairly standard. I've tested this and taken advantage of this fact before to do load in place from a binary file with patched vtbls. For the last 6 months, I've been working in Xcode and just recently came across the need to do some load in place stuff, so I was looking into patching vtbls

stack smashing detected解决过程

旧城冷巷雨未停 提交于 2019-12-06 14:09:57
在执行程序结束return 0 之后出现上图问题。主要原因是在程序中存在数组越界。 解决方法: 1. 查看定义的结构体内buffer大小,为4096字节 typedef struct { UINT32 len; BYTE buf[4096]; } ctrust_tpm2_combuf_t 2. 查看要存储的结构体TPMS_CONTEXT大小为5208字节      sizeof(TPMS_CONTEXT) 3. 在memcpy拷贝时,要添加字节大小限制条件 if (sizeof(TPMS_CONTEXT) > 4096) { sub_context->len = 4096; } else { sub_context->len = sizeof(TPMS_CONTEXT); }   memcpy(&sub_context->buf, (BYTE *)&context, sub_context->len); 来源: https://www.cnblogs.com/wenkyme/p/11988620.html

C语言数字图像处理学习笔记2

我的未来我决定 提交于 2019-12-06 13:09:44
2019.12.4 1. fread() 函数可以直接按照结构体的格式进行文件的读取,并根据结构体中的字节数自动匹配。 注意 ,若是多个结构体,且没有明显格式的情况下,注意在结构体前加上 #pragma pack(1) 设定结构体对齐字符为1,即不会自动补充多余的字符。确保对齐,不然读取的时候会出错。 若 #pragma pack(4) ,则会自动补齐4个字符,也是 默认情况 。即 char 类型在读取计算大小的时候也会算成4,即使 sizeof 依旧为1。 最后可以使用 #pragma pack () 取消指定对齐。也可以使用 #pragma pack(pop) 。 2. fseek(fp, 0, SEEK_SET); 函数控制文件指针的位置移动。参数1: 文件指针。参数2: 指针偏移距离。参数3: 指针起始位置(文件起始位置) 3.如果你只是想将一个文件的内容读入到一个字符串中,用 file_get_contents() ,它的性能比上面的代码好得多。 4.bmp文件完美解析 https://blog.csdn.net/lanbing510/article/details/8176231 bmp文件分析 https://blog.csdn.net/qq_37887537/article/details/88576820 5.各位数编译器的不同类型的取值范围。 https:/

让Libevent 在window下 支持 IOCP

一笑奈何 提交于 2019-12-06 12:54:14
Libevent 的强大就不说了,但由于在window下使用的是 select 机制 ,除了效率低下意外还有一个讨厌的"FD_SETSIZE"限制,所以一直 希望能支持IOCP,可是现在已经到2.0还是没能够支持。 无意中在网上发现了个支持IOCP的libevent版本,是1.4.7版的。不过没关系,把其中的一个关键文件"win32iocp.c"拷贝到最新的1.4.14b版本中,并在"event.c" 中修改: ..... #ifdef HAVE_POLL extern const struct eventop pollops; #endif #ifdef HAVE_EPOLL extern const struct eventop epollops; #endif #ifdef HAVE_WORKING_KQUEUE extern const struct eventop kqops; #endif #ifdef HAVE_DEVPOLL extern const struct eventop devpollops; #endif #ifdef WIN32 #ifndef _EVENT_NOIOCP extern const struct eventop win32iocpops; #endif extern const struct eventop win32ops;

sizeof a pointer

流过昼夜 提交于 2019-12-06 12:48:58
int i=0; int *p = &i; std::cout<<sizeof(i)<<" vs "<<sizeof(p)<<"\n"; char c='0'; char*pc = &c; std::cout<<sizeof(c)<<" vs "<<sizeof(pc)<<"\n"; double d=0.123456789; double *pd = &d; std::cout<<sizeof(d)<<" vs "<<sizeof(pd)<<"\n"; Why is the size of a pointer always equal to that of an integer which is 4? Because that is how much memory a pointer takes: 4 bytes. If this was a 64-bit application, it would return 8. Pointers don't contain the data they point to. Pointers just point to the data they point to. sizeof( double* ) is the size of the data used to describe where a double is located.

UNIX编程 TCP基础读写笔记

让人想犯罪 __ 提交于 2019-12-06 12:20:34
基本TCP客户端与服务器 Server #include <cstdio> #include <cstring> #include <string> #include <vector> #include <unistd.h> #include <arpa/inet.h> #include <sys/errno.h> #include <sys/socket.h> #include <netinet/in.h> #include <string> using namespace std; const int BUF_SIZE = 1024; string addr_to_string(const sockaddr_in *addr) { char addr_str[INET_ADDRSTRLEN]; const char *addr_str_ptr = inet_ntop(AF_INET, &addr->sin_addr, addr_str, sizeof(addr_str)); if (addr_str_ptr == NULL) { fprintf(stderr, "inet_ntop failed\n"); return ""; } return string(addr_str_ptr) + ":" + to_string(ntohs(addr->sin_port)); }

What arguments does the sizeof operator take in C?

戏子无情 提交于 2019-12-06 10:00:34
[ Original title referred to 'sizeof function'. ] I tried these and they all worked: char *p; printf("Size of *p is %d\n",sizeof(*p)); //result =1 printf("Size of p is %d\n",sizeof( p)); //result =4 printf("Size of p is %d\n",sizeof(&p)); //result =4 I wonder why the first printf is 1, the 2nd and 3rd is 4? So what arguments can sizeof can actually take? It takes a type. sizeof(char) is always one. The variable p itself is a pointer, and on your platform that has a size of 4. Then you do &p , or a pointer to a pointer, which also has a size of 4. On most modern desktop systems, a 32-bit

解密 char转换为json

浪子不回头ぞ 提交于 2019-12-06 09:53:31
1 typedef struct CRYPT_BLOCK { 2   DWORD dwSize; // Data的 3   DWORD dwKey; // 密钥 循环使用DWORD的每个字节来进行加密 详情见XorEncrypt 4   char chData[1]; // 加密后的数据 5 } CRYPT_BLOCK, *PCRYPT_BLOCK; 6 7 typedef boost::shared_ptr<Json::Value> JsonSharedPtr; 一个数异或另一个数两次后,该数保持不变。 即: c = a^b; c = c^b; c == a; 这一规律就是使用异或运算对数据及文件进行加密处理的基本原理。 1 bool XorEncrypt(const char* pKey, DWORD dwCbKey, const char* pIn, DWORD dwCbSize, char* pOut) 2 { 3   if (pIn == NULL || pOut == NULL || pKey == NULL) { 4     return false; 5   } 6 7   for (DWORD i = 0; i < dwCbSize; ++i) { 8     pOut[i] = pIn[i] ^ pKey[i % dwCbKey]; 9   } 10 11  

What determines the size of integer in C? [duplicate]

 ̄綄美尐妖づ 提交于 2019-12-06 08:44:37
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: size of int, long, etc Does the size of an int depend on the compiler and/or processor? I'm not sure if similar questions have been asked before on SO (Atleast, I couldn't find any while searching, so thought of asking myself). What determines the size of int (and other datatypes) in C . I've read it depends on the machine/operating system/compiler, but haven't come across a clear/detailed enough explanation on

全局数组

可紊 提交于 2019-12-06 08:43:16
全局数组初始化为零,靠,这特么我还真不知道,怪不得看的代码不用给它赋值 如果是全局数组,就自动会初始化为0 但如果是在函数中定义,那么必须要先初始化 int result[10]; memset(result,0,sizeof(result)); // 注意是sizeof(result) = 40 不是 10 哦 来源: https://www.cnblogs.com/chenxiansen/p/11973228.html