flat assembler
Message board for the users of flat assembler.
Index
> Windows > Addition x64 |
Author |
|
revolution 08 May 2015, 14:24
Your offset into that stack are wrong. Each 64-bit push is 8 bytes.
|
|||
08 May 2015, 14:24 |
|
yq8 08 May 2015, 22:32
revolution wrote: Your offset into that stack are wrong. Each 64-bit push is 8 bytes. Code: push rbp mov rbp, rsp xor rax, rax xor rcx, rcx mov rax, qword[rbp+0x10] mov rcx, qword[rbp+0x18] add rax, rcx pop rbp ret 0x10 Thanks for the hint, I now corrected the offsets, but still its returning completly wrong results. 100 + 5 = 485219888 it says ? Whats wrong, I can't see the problem. |
|||
08 May 2015, 22:32 |
|
revolution 09 May 2015, 00:11
How are you calling it?
Show more of your code. |
|||
09 May 2015, 00:11 |
|
yq8 09 May 2015, 00:32
I call this code as byte[] from C#.
The x86 code works fine, the x64 doesn't. What could be the issue? |
|||
09 May 2015, 00:32 |
|
revolution 09 May 2015, 00:37
What is the 64-bit call convention used by C#? fastcall?
|
|||
09 May 2015, 00:37 |
|
yq8 09 May 2015, 18:34
As I said I execute by a byte[] like so:
Code: private delegate int DelAddNative(int a, int b); private static Int32 AddNative(int a, int b) { Int32 OutRes = 0; // Allocate a Handle GCHandle PinnedArray = GCHandle.Alloc(x64Addition, GCHandleType.Pinned); // Get handle for shellcode // Get address of Object IntPtr ShellcodePointer = PinnedArray.AddrOfPinnedObject(); // Convert function-pointer to Delegate DelAddNative AddDelegate = (DelAddNative)Marshal.GetDelegateForFunctionPointer(ShellcodePointer, typeof(DelAddNative)); uint flOldProtect; // Make shellcode executable VirtualProtect(ShellcodePointer, (UIntPtr)x64Addition.Length, PAGE_EXECUTE_READWRITE, out flOldProtect); // Execute shellcode OutRes = AddDelegate(a, b); // Restore old flag VirtualProtect(ShellcodePointer, (UIntPtr)x64Addition.Length, flOldProtect, out flOldProtect); // Release handle PinnedArray.Free(); return OutRes; } Not sure how I can use the fastcall convention here since I am not importing any dll. The strange thing is, the x64 code looks alright, tho, I get an exception when executing it, not so with the x86 code. Any more ideas? |
|||
09 May 2015, 18:34 |
|
revolution 09 May 2015, 23:19
If it is using fastcall (which is not stated in your code above so I don't know what it is) then all you need for addition is this:
Code: x64Addition: mov rax,rcx ;parameter 1 add rax,rdx ;parameter 2 ret |
|||
09 May 2015, 23:19 |
|
yq8 10 May 2015, 06:11
@revolution : Nice man, that works
Thanks a bunch ^^ |
|||
10 May 2015, 06:11 |
|
revolution 10 May 2015, 06:52
For something slightly less clear it can be reduced to a single instruction:
Code: x64Addition: lea rax,[rcx+rdx] ret |
|||
10 May 2015, 06:52 |
|
sinsi 10 May 2015, 07:18
With ADD you can check the carry flag though...
|
|||
10 May 2015, 07:18 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.