We’re rewarding the question askers & reputations are being recalculated! Read more.

Hot answers tagged

20

It's the wrong question, really. AH is the exception. Now the real question is, why is AH such an exception? It's an old register, from the 8086 era. It exists to facilitate moving over code from the 8080. The 8080 has different registers from the 8086, so you can't move over code directly. In particular, it didn't have an AL,AH or AX register. It did ...


17

Is it possible to access the higher part of the 32-bit and 64-bit registers? If so, which ones? It is impossible to access the higher parts of the EAX and RAX registers, or of any other 32 and 64-bit registers, directly. You'll have to use indirect instruction sequences if you're interested in doing that. This is because there are no encodings to access ...


7

The shr rax, 3 is an unsigned divide by 8 with truncation towards zero. The inclusion of the adc rax, 0 makes the division round to nearest instead. (Though 0.5 will always be rounded up) So this operation sets RAX to 1 if RAX is in the range of [4-11] (8*1 ±4) 2 if RAX is in the range of [12-20] (8*2 ±4) 3 if RAX is in the range of [20-27] (8*3 ±4) You ...


7

I believe the best tool for rewriting assembly to C is IDA Graph View, which is toggled with space. It let you see the function as Basic Blocks, connected by control flow instructions. In this specific function, I cannot spot any jumps so you will see one long block. The first thing you usually see in a function is the function prologue which sets up the ...


5

Update: Thanks to Nirlzr, I see I missed the emphasized point at the bottom of the post. This answer, though not what OP is looking for, may serve useful for anyone down the road who is looking for a way to access those bits. Apologies for missing OPs full intention! I actually wrote an in-depth article on this topic a couple of years ago: Accessing and ...


4

This function computes (in a recursive manner) the sum of the n first integers: 400700: sub rsp,0x18 ; Align the stack 400704: mov QWORD PTR [rsp+0x8],rdi ; Store first argument on stack 400709: cmp QWORD PTR [rsp+0x8],0x0 ; test (n == 0) +--40070f: jne 400718 <bar+0x18> ; jump to 400718 if (n != 0) | ...


3

If you use -dr instead of plain -d, objdump will list relocation info next to the instructions. E.g. here's a random sample I just compiled 00000000 <main>: 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 e4 f0 and $0xfffffff0,%esp 6: 83 ec 20 sub $0x20,%...


3

Since you mentioned ELF in the tag. WinMain, DllMain, etc should not be a concern for you. They're name conventions for Windows. The main function is the first function executed for a C/C++ program. However, it doesn't mean this is the real first function / code executed. You will usually find some initialization code before this function is called. my ...


3

I believe the discrepancy between 40 and actual sum of 48 is mostly an error, however there are many other registers used for handling hardware, memory management, and control of different features of the CPU. The answer you linked to covers all the commonly used registers in the following image (taken from there): There are, however plenty of less ...


3

Wikipedia has a page about the x86 architecture and all its known registers. Here is a small picture gathering all what we know about it. In fact, not all these registers are officially documented. But, all the registers we know (and we know how to use) are listed in the picture. And, it makes much more than 40. And, I do not know what are these 'hardware' ...


2

These two symbols aren't exported in the usual way (i.e. via the export table). Instead, they are public symbols inside the run-time library itself. The startup code that runs before _main() performs the command-line resolution, assigning parameters into the __wargv array, and storing the count in __argc. The relative addresses are fixed for the file, but ...


2

Actually, there is no lea edx, [0x80490c8] for 64-bits addressing modes. Since, afaik, in all 64-bits addressing modes lea is a register relative opcode. LEA - Load Effective Address Computes the effective address of the second operand (the source operand) and stores it in the first operand (destination operand). The source operand is a memory ...


2

Windows loader does not care about section names, so the name does not really matter, but usually this section contains the pointer to the indirect call guard check (___guard_check_icall_fptr). The pointer to it is stored in the GuardCFCheckFunctionPointer field of the load configuration directory. I guess in the newer files it may contain some additional ...


2

The most useful reference I've seen about this section is in this Adobe source comment: // // Allocate xyz in the .00cfg so that it is implicitly merged into the // import section of the binary (which is read-only). // Indirect calls using this pointer do not have the guard check function, // and so will not fail the CFG check. // The code appears to add ...


2

Mainly, this is because the program did enough pop previously to get rsp just in front the saved rip. Then, a simple push will overwrite the saved rip. As you can notice on the first picture, your saved rip is at 0x5561dca8 and, your rsp as well. Therefore, a push operation will store the address of the touch3 function as return address of the stack-frame. ...


2

It seems to be %rip (the address of the ud2): #include <signal.h> #include <stdio.h> #include <ucontext.h> void handler(int signo, siginfo_t *info, void *context) { ucontext_t *uc = (ucontext_t*)context; printf("%llx\n", uc->uc_mcontext.gregs[REG_RIP]); } compiles to: handler(int, siginfo_t*, void*): movq 168(%rdx),...


2

You have several options here, but I like this one. Since the code is already inside the executable, so you have to patch the entrypoint to jump to a new function. To do so, I suggest to use a shared object (.so). In this module you will both: the new function and a 'patcher function'. The latter function must be defined with __attribute__((constructor)), ...


2

For this case, here I compile the MS Docs example in 64 bit PE binary with gcc -ggdb command (or use gcc -S for the assembly file). Here is the assembly section of SetCommState function in Intel syntax: mov dword ptr [rbp-44], 57600 ; dcb.BaudRate = CBR_57600 mov byte ptr [rbp-30], 8 ; dcb.ByteSize = 8 mov byte ptr [rbp-29], 0 ...


2

Just a quick note in case you would not be aware of this: $ cat tiny.c #include <unistd.h> void _start() { _exit(42); } on x86-64, here is what I get (you need a static libc: libc.a): $ gcc -static -ffreestanding -nostartfiles -s -o tiny tiny.c $ ./tiny || echo $? 42 Pay attention that: $ file tiny tiny: ELF 64-bit LSB executable, x86-64, ...


2

It is possible to do what you want. There are some difficulties you may encounter though. I'll show you a short instruction how it can be done in several different cases. Have a look at ELF specification to know how every file in that format looks like, which sections it consists of and how they are located in the process image at the runtime. Even when ...


2

Pretty much, they will all eventually read the PEPROCESS object directory. Maybe not, depends on what you're trying to hide from. If it's just some basic usermode process iteration then you're probably fine. There's quite a few ways to iterate the process object directory though, such as ZwGetNextProcess. Your best bet would probably be ObRegisterCallbacks ...


2

When does the PE loader fill in the IAT? The IAT is updated at load time by the PE Loader [1], this is called Load-time dynamic linking, as opposed to Run-time dynamic linking, where LoadLibrary/GetProcAddress are necessary. Hooking an API not included in Import Address Table There are several ways to do that actually, and Export Address Table hooking is ...


2

I've found out how this works. I had the right idea, but I had made the mistake of assuming it was n bytes ahead, failing to factor in the size of the actual value at hand. Since the specific type of v1 was a single, this means I had to multiply the 1818 by 4 bytes. Looking at the corresponding ASM, movss dword ptr [rdi+1C68h], xmm1, I can see that rdi+...


2

Details of such low-level registers are often disclosed only to Intel's trusted partners under NDA since they're not intended to be accessed by the general application programmer but only by writers of BIOS or other system-level code. That said, sometimes you can find info in unexpected places... #define MSR_POWER_CTL 0x1FC #define ...


1

Welcome to the wonderful world of AT&T assembly! The 9 in 9(%rax, %rdx) is commonly called displacement or sometimes base, and you should indeed just add all three values: 9+rax+rdx = 9+0x100+0x3 = 0x10C This address is then dereferenced so the value 0x11 is loaded from the address 0x10C. I would recommend reading the Solaris x86 Assembly Language ...


1

the Apis like Sleep are documented a header file is provided in the sdk a library to link against is provided by sdk (windows.h ,kernel32.lib) api s like Zwxxx are internal or advanced user apis they or either undocumented or semidocumented or documented for usage in a kernel mode these apis are not to be taken for granted to be either forward ...


1

It seems you're looking at a Wow64 syscall stubs in 32-bit ntdll.dll. WOW64 can use a special value in the high part of the syscall number for so-called Turbo thunks. From WoW64 internals by "wbenny": typedef struct _WOW64_SYSTEM_SERVICE { ULONG SystemCallNumber : 12; ULONG ServiceTableIndex : 4; ULONG TurboThunkNumber : 5; // Can hold ...


1

I would like to extend the .text section and insert [code]. If there's a better method of inserting new functionality into an ELF I'm all ears. Techniques for adding arbitrary code to ELF files were pioneered by Linux virus writers beginning all the way back in the 1990s. In comparison with the methods they developed, as well as with more modern techniques,...


1

execve specification says: Both argv and envp must be terminated by a NULL pointer. but from your question it seems, that you forgot about it; you want to call it like this: execve("/bin/cat", ["/bin/cat","/test/file", NULL], NULL) If it still doesn't work, here is the working code in C. You can then follow @user3629249's suggestion and use gcc -S ...


1

Comment out or simply remove lines ehdr->e_shoff += PAGE_SIZE; if (text_found) { phdr[i].p_offset += PAGE_SIZE; continue; } and change shdr->sh_offset's to shdr[i].sh_offset's. Explanation: You may run readelf -a hello for more details. It will output following problems: readelf: Error: Reading 1856 bytes extends past end of file for ...


Only top voted, non community-wiki answers of a minimum length are eligible