21
Windows questions / Re: Computing number of Pages to alloc usin VirtualAlloc
« Last post by TimoVJL on November 14, 2024, 03:23:37 PM »test:
from podump
Code: [Select]
#include <stdio.h>
int __cdecl main(void)
{
unsigned long _dwSize, __dwSize;
__dwSize = 3456;
_dwSize = ((__dwSize + 4095) >> 12) << 12 ;
printf("%d\n", _dwSize);
return 0;
}
returns 4096from podump
Code: [Select]
1: #include <stdio.h>
2:
3: int __cdecl main(void)
_main:
[00000000] 55 push ebp
[00000001] 89E5 mov ebp,esp
[00000003] 83EC08 sub esp,8
4: {
5: unsigned long _dwSize, __dwSize;
6: __dwSize = 3456;
[00000006] C745F8800D0000 mov dword ptr [ebp-8],D80
7: _dwSize = ((__dwSize + 4095) >> 12) << 12 ;
[0000000D] 8B45F8 mov eax,dword ptr [ebp-8]
[00000010] 8D80FF0F0000 lea eax,[eax+FFF]
[00000016] C1E80C shr eax,C
[00000019] C1E00C shl eax,C
[0000001C] 8945FC mov dword ptr [ebp-4],eax
8: printf("%d\n", _dwSize);
[0000001F] FF75FC push dword ptr [ebp-4]
[00000022] 6800000000 push @9
[00000027] E800000000 call _printf
[0000002C] 83C408 add esp,8
9: return 0;
[0000002F] B800000000 mov eax,0
[00000034] 89EC mov esp,ebp
[00000036] 5D pop ebp
[00000037] C3 ret
Code: [Select]
1: #include <stdio.h>
2:
3: int __cdecl main(void)
main:
[0000000000000000] 4883EC28 sub rsp,28
4: {
5: unsigned long _dwSize, __dwSize;
6: __dwSize = 3456;
[0000000000000004] C7442420800D0000 mov dword ptr [rsp+20],D80
7: _dwSize = ((__dwSize + 4095) >> 12) << 12 ;
[000000000000000C] 8B442420 mov eax,dword ptr [rsp+20]
[0000000000000010] 678D80FF0F0000 lea eax,[eax+FFF]
[0000000000000017] C1E80C shr eax,C
[000000000000001A] C1E00C shl eax,C
[000000000000001D] 89442424 mov dword ptr [rsp+24],eax
8: printf("%d\n", _dwSize);
[0000000000000021] 488D0D00000000 lea rcx,[@9]
[0000000000000028] 8B542424 mov edx,dword ptr [rsp+24]
[000000000000002C] E800000000 call printf
9: return 0;
[0000000000000031] B800000000 mov eax,0
[0000000000000036] 4883C428 add rsp,28
[000000000000003A] C3 ret