x86-64

Get type of binary on filesystem via C# running in 64 bit

和自甴很熟 提交于 2021-02-20 03:49:37
问题 I have a C# application, compiled in Visual Studio 2017 on the 'Any CPU' target, with the 'Prefer 32-bit' option disabled. In this application, I am trying to pinvoke kernel32!GetBinaryType(). When running with 'Prefer 32-bit' enabled, it works fine. When running in either 32 or 64-bit mode from a C++ executable, it works fine. I am not sure what I am doing wrong with the 64-bit C# application. This is my pinvoke signature: [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError =

Get type of binary on filesystem via C# running in 64 bit

拈花ヽ惹草 提交于 2021-02-20 03:47:04
问题 I have a C# application, compiled in Visual Studio 2017 on the 'Any CPU' target, with the 'Prefer 32-bit' option disabled. In this application, I am trying to pinvoke kernel32!GetBinaryType(). When running with 'Prefer 32-bit' enabled, it works fine. When running in either 32 or 64-bit mode from a C++ executable, it works fine. I am not sure what I am doing wrong with the 64-bit C# application. This is my pinvoke signature: [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError =

How to use the fixups attribute on a section?

主宰稳场 提交于 2021-02-20 01:36:28
问题 What exactly does "fixups" do when applied on a section? In a fasm sample i found the following section delcaration and i'm really not sure what the fixups attribute does, i couldn't find much information on that in the fasm documentation. section '.reloc' fixups data readable discardable if $=$$ dd 0,8 ; if there are no fixups, generate dummy entry end if 回答1: This appears to be a workaround for a bug in how FASM generates PECOFF DLLs. The .reloc section only applies to PECOFF images (EXEs

Avoiding page faults in IDT hooking

故事扮演 提交于 2021-02-18 22:12:37
问题 Note: I'm running on FreeBSD, but I've also included Linux as a tag since the problem is somewhat general and Linux-specific solutions are of interest to me. Edit : just to confirm that the issue was not FreeBSD specific, I ported the module to Linux, and indeed got the exact same behavior. The code for the Linux version of the module is given below; it is essentially exactly the same, the only major difference being that the IDT is evidently given read-only protection in Linux, and so I had

Check if a number is even

我只是一个虾纸丫 提交于 2021-02-17 05:56:19
问题 I'm working my way through low level bit hacks, and would like to write an assembly program for each. Here is what I have for checking if a number is even or not: is_even: # check if an integer is even. # This is the same as seeing if its a multiple of two, i.e., & 1<<n - 1 # rdi stores the number xor %eax, %eax test $0b1, %rdi setz %al ret _start: mov $5, %rdi call is_even Are there any ways to improve the above or make it more readable? Is it possible to do the is_even check with 2

how do i rotate a value in assembly

一世执手 提交于 2021-02-16 20:40:38
问题 I am implementing a function in assembly x86 64 bits, which I am unable to alter: unsigned long rotate(unsigned long val, unsigned long num, unsigned long direction); direction- 1 is left and 0 is right. This is my code to shift left but its not working the last bit is off. Can someone help me please. rotate: push rbp push rdi push rsi push rdx mov rbp, rsp sub rsp, 16 cmp rdx, 1 je shift_left shift_left: mov rax, rdi shl rax, cl mov rax, rax mov rcx, rdi sub cl, 64 shl rcx, cl or rax rdx mov

how do i rotate a value in assembly

旧巷老猫 提交于 2021-02-16 20:40:28
问题 I am implementing a function in assembly x86 64 bits, which I am unable to alter: unsigned long rotate(unsigned long val, unsigned long num, unsigned long direction); direction- 1 is left and 0 is right. This is my code to shift left but its not working the last bit is off. Can someone help me please. rotate: push rbp push rdi push rsi push rdx mov rbp, rsp sub rsp, 16 cmp rdx, 1 je shift_left shift_left: mov rax, rdi shl rax, cl mov rax, rax mov rcx, rdi sub cl, 64 shl rcx, cl or rax rdx mov

Should %rsp be aligned to 16-byte boundary before calling a function in NASM?

社会主义新天地 提交于 2021-02-16 20:20:22
问题 I saw the following rules from NASM's document: The stack pointer %rsp must be aligned to a 16-byte boundary before making a call. Fine, but the process of making a call pushes the return address (8 bytes) on the stack, so when a function gets control, %rsp is not aligned. You have to make that extra space yourself, by pushing something or subtracting 8 from %rsp. And I have a snippet of NASM assembly code as below: The %rsp should be at the boundary of 8-bytes before I call the function "inc

x86_64 Opcode encoding formats in the intel manual

試著忘記壹切 提交于 2021-02-16 14:04:29
问题 What are the "Op/En" formats listed in the Intel x86_64 reference manual? For example in the Add opcode I can take a guess at some such as "I" = Immediate, but is there a comprehensive list for these? 回答1: The intro sections of Intel's vol.2 manual explain how to read each entry: Section 3.1.1.4 Operand Encoding Column in the Instruction Summary Table The “operand encoding” column is abbreviated as Op/En in the Instruction Summary table heading. Instruction operand encoding information is

Cpp uint32_fast_t resolves to uint64_t but is slower for nearly all operations than a uint32_t (x86_64). Why does it resolve to uint64_t?

久未见 提交于 2021-02-16 13:58:29
问题 Ran a benchmark and uint32_fast_t is 8 byte but slower than 4 byte uint32_t for nearly all operations. If this is the case why does uint32_fast_t not stay as 4 bytes? OS info: 5.3.0-62-generic #56~18.04.1-Ubuntu SMP Wed Jun 24 16:17:03 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux Cpu info: cat /sys/devices/cpu/caps/pmu_name skylake model name : Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz Benchmark I used for testing: #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <cstdint>