资讯详情

资讯详情

Win_PE文件节表根据对齐计算分配空间大小

/* * description * * getShiftOperandByAlignment: 根据对齐方式获取移位操作数 * * 参数: * alignment_size: 内存对齐大小; 值: 512, 1024(1k), 4096(4K), 8196(8K) * * 返回值: * 失败返回-1, 成功返回操作数 */ int32_t getShiftOperandByAlignment(uint32_t alignment_size); /* * description * * getAllcoationSizeByAlignment: 获取对齐的整数倍 * * 参数: * value: 要计算的值 * alignment_size: 对齐大小: 512, 1024(1K), 2048(2K), 4096(4K), 8192(8K) * * 返回值: * 失败返回0, 成功返回对齐后的大小 */ int32_t getAllcoationSizeByAlignment(int32_t value, int32_t alignment_size); void test() { //1. 66560 / 1024 65; 输出result: 67584; 67584 / 1024 66 //2. 58903 / 1024 57.5224609375; 输出result: 59392; 59392 / 1024 58 //3. 58903 / 4096 14.380615234375; 输出result: 61440; 61440 / 4096 15 int result getAllcoationSizeByAlignment(58903, 4096); printf(result: %d\n, result); } int main(int argc, char* argv[]) { test(); printf(\n); return 0; } int32_t getAllcoationSizeByAlignment(int32_t value, int32_t alignment_size) { ERROR_CHECK(value 0, 0, 参数: value 小于零.\n); int32_t result getShiftOperandByAlignment(alignment_size); ERROR_CHECK(result -1, 0, 对齐大小不符合.\n); if (value alignment_size) { return alignment_size; } int32_t integer_multiple (value result) 1; return alignment_size * integer_multiple; } int32_t getShiftOperandByAlignment(int32_t alignment_size) { //移位操作数 int32_t shift_operand[5] { 9, 10, 11, 12, 13 }; int32_t result; switch (alignment_size) { case 512: result shift_operand[0]; break; case 1024: return shift_operand[1]; //break; case 2048: result shift_operand[2]; break; case 4096: result shift_operand[3]; break; case 8192: result shift_operand[4]; break; default: result -1; break; } return result; }_
觉得有用,分享给同行:

为您的企业打造数字门面

稳重轻奢商务风格,端正雅致视觉,长效耐看不易过时。

立即咨询 →