X86 Source Share

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

HalfWayToHell333

Jr.Coder
Silenced
Full Member
Nobleman
Jun 23, 2014
80
783
3
Hey there,

while learning to write proper X86 and later (maybe much later:D) X64 Assembly,
i have written some Source for try and error i would like to share.

I´ll only Post full working Sources.

This Function takes a Val and print´s out it´s oct , hex and dec equivalent´s.
The ASM-Function calls printf from internal ,
which means you have Argument passing and function calls from and to ASM

Maybe you want to have a look at it.
Uselfull hints , comments or suggestions are welcome.

Main.cpp
C++:
#include <iostream>

#define rcast(type,val) reinterpret_cast<type>(val) 

extern "C" void _cdecl ohdPrint(void* val);//no function overload possible (for my knowledge) -> so must cast to Type

void main(void){

	int val = 16;
	long val2 = LONG_MAX;
	char byte = 'A';//A == 65 (ASCII TABLE)
	
	ohdPrint(rcast(int*,val));
	std::cout << std::endl;
	
	ohdPrint(rcast(long*, val2));
	std::cout << std::endl;

	ohdPrint(rcast(char*, byte));
	std::cout << std::endl;

	std::cin.get();
}

.486
.Model c , flat
.data

octformat DB "oct : %o",10,0 ; for printf first Argument (format)
hexformat DB "hex : 0x%xh",10,0 ; for printf first Argument (format)
decformat DB "dec : %u",10,0 ; for printf first Argument (format)

.code

ohdPrint proc c ;

extrn printf : proc ; for printf

push EBP ; save basePointer
mov EBP,ESP ; save the stack
mov edx , [esp+8] ; mov arg to edx

push ecx ; save ecx (1)
push ebx ; save ebx (2)
push edx ; save edx (3)
; 1 to 3 must be saved before calling a function

push offset octformat ; push format to print on stack
call printf ; call function
add esp , 4 ; cleanup for offset octformat

pop edx ; restore edx (4)
pop ebx ; restore ebx (5)
pop ecx ; restore ecx (6)
; 4 to 6 must be restored after function call
; and yes , Step´s 1 to 6 must be done over and over again

push ecx
push ebx
push edx

push offset hexformat
call printf
add esp , 4

pop edx
pop ebx
pop ecx

push ecx
push ebx
push edx

push edx
push offset decformat
call printf
add esp , 4

pop edx
pop ebx
pop ecx

mov ESP,EBP ; restore the stack
pop EBP ; resore basePointer
ret

ohdPrint endp
end
 

Syntax Error

Coder
Silenced
Meme Tier VIP
Nov 6, 2014
239
2,928
6
pop edx ; restore edx (4)
pop ebx ; restore ebx (5)
pop ecx ; restore ecx (6)
; 4 to 6 must be restored after function call
; and yes , Step´s 1 to 6 must be done over and over again

push ecx
push ebx
push edx

[/SPOILER]
I understand why you first push those registers onto the stack. So printf won't destroy whatever values you may have in there but you're only using edx why push them all on? That's not what I'm confused about. Why do you then pop them off the stack only to immediately push them back on? Couldn't you just leave them on there?

All in all thank you for sharing. :)
 

HalfWayToHell333

Jr.Coder
Silenced
Full Member
Nobleman
Jun 23, 2014
80
783
3
I understand why you first push those registers onto the stack. So printf won't destroy whatever values you may have in there but you're only using edx why push them all on? That's not what I'm confused about. Why do you then pop them off the stack only to immediately push them back on? Couldn't you just leave them on there?

All in all thank you for sharing. :)
:facepalm:
Yep you were absolutely right on this , my bad.
That's the proof , reading != understanding :fail:

I corrected the Source so it makes more Sense.

.486
.Model c , flat
.data
octformat DB "oct : %o",10,0 ; for printf first Argument (format)
hexformat DB "hex : 0x%xh",10,0 ; for printf first Argument (format)
decformat DB "dec : %u",10,0 ; for printf first Argument (format)
.code

ohdPrint proc c ;

extrn printf : proc ; for printf

push EBP ; save basePointer
mov EBP,ESP ; save the stack
push [esp+8] ; save Val
push offset octformat ; push format to print on stack
call printf ; call function
add esp , 4 ; cleanup for offset octformat

push offset hexformat
call printf
add esp , 4

push offset decformat
call printf
add esp , 4

mov ESP,EBP ; restore the stack
pop EBP ; resore basePointer
ret

ohdPrint endp
end
 
Last edited:

HalfWayToHell333

Jr.Coder
Silenced
Full Member
Nobleman
Jun 23, 2014
80
783
3
This is based on the ASMX64 Youtube Video Tutorial 52 from Whatsacreel >accessing structs<
It should be self explaining.
And it is in X86 of course.
#include <iostream>

struct Foo{
int val=0;
int val2 = 0;
};

//takes 2 structs , adds the amount of val to every variable in the structs and returns the Sum
extern "C" unsigned int sumVals(Foo* first,Foo* second,int val=0);

void main(void){
using namespace std;

int add = 100;
Foo first;
Foo sec;

first.val = 10;
first.val2 = 200;
sec.val = 3000;
sec.val2 = 40000;

cout << "before calcVals\n" << endl;
cout << "first.val : " << first.val << endl << "first.val2 : " << first.val2 << endl;
cout << "sec.val : " << sec.val << endl << "sec.val2 : " << sec.val2 << endl;

cout << "\nresult : " << sumVals(&first, &sec, add) << endl;

cout << "\nfirst.val : " << first.val << endl << "first.val2 : " << first.val2 << endl;
cout << "sec.val : " << sec.val << endl << "sec.val2 : " << sec.val2 << endl;

cout << "\nhit enter", cin.get();
}

.model flat
.data

Foo struct ; delcare struct alignment
val DWORD 0
val2 DWORD 0
Foo ends

TempResult DWORD 0

.code
sumVals proc c

push EBP ; save basePointer
mov EBP,ESP ; save the stack

;----------------------------------------------------------

mov ebx , [esp+8] ; mov Foo1
mov ecx , [esp+12] ; mov Foo2
mov edx , [esp+16] ; move increment

;----------------------------------------------------------

mov eax , [ebx].Foo.val ; Foo1.val
add eax , edx ; Foo1.val += increment
mov [ebx].Foo.val , eax ; new Foo1.val
mov TempResult , eax ; sum==Foo1.val + increment

;----------------------------------------------------------

mov eax , [ecx].Foo.val
add eax , edx
mov [ecx].Foo.val , eax
add TempResult , eax ;sum+=Foo2.val + increment

;----------------------------------------------------------

mov eax , [ebx].Foo.val2 ; Foo1.val2
add eax , edx ; Foo1.val2 += increment
mov [ebx].Foo.val2 , eax ; new Foo1.val2
add TempResult , eax ; sum+=Foo1.val2 + increment

;----------------------------------------------------------

mov eax , [ecx].Foo.val2
add eax , edx
mov [ecx].Foo.val2 , eax
add TempResult , eax ; sum+=Foo2.val2 + increment

;----------------------------------------------------------

xchg eax,TempResult ; Result to eax

mov ESP,EBP ; restore the stack
pop EBP ; resore basePointer
ret
sumVals endp
end

Anything that could be done more efficient or better? , please comment.
 
Last edited:
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods