Обновить label_pointer.c

main
serr 2025-01-09 18:57:04 +03:00
parent 39fbd56042
commit 09e42eb53c
1 changed files with 36 additions and 35 deletions

View File

@ -1,36 +1,37 @@
#include <stdio.h> #include <stdio.h>
#include <intrin.h> #include <intrin.h>
#pragma intrinsic(_ReturnAddress) #pragma intrinsic(_ReturnAddress)
char* next_instruction_address(void) { return (char*)_ReturnAddress(); } char* next_instruction_address(void) { return (char*)_ReturnAddress(); }
int test( int test(
char* (*_next_instruction_address) (void) char* (*_next_instruction_address) (void)
) { ) {
char* p_begin = _next_instruction_address() + 13; char* p_begin = _next_instruction_address() + 13;
begin:; begin:;
int a = 2; int a = 2;
int b = 2; int b = 2;
char* p_end = _next_instruction_address() + 13; char* p_end = _next_instruction_address() + 13;
end:; end:;
char* save_p_end = p_end; char* save_p_end = p_end;
char* save_p_begin = p_begin; char* save_p_begin = p_begin;
__asm { __asm {
lea eax, begin lea eax, begin
mov p_begin, eax mov p_begin, eax
lea eax, end lea eax, end
mov p_end, eax mov p_end, eax
} }
printf("%lu=%lu\n%lu=%lu\n", // Сравнение адресов, полученных без вставки и с ней
(size_t)save_p_end, (size_t)p_end, printf("%lu=%lu\n%lu=%lu\n",
(size_t)save_p_begin, (size_t)p_begin); (size_t)save_p_end, (size_t)p_end,
(size_t)save_p_begin, (size_t)p_begin);
return a + b;
} return a + b;
}
int main(void) {
test(next_instruction_address); int main(void) {
return 0; test(next_instruction_address);
return 0;
} }