SlideShare a Scribd company logo
C++ and Assembly: Debugging
and Reverse Engineering
Mike Gelfand
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
About me
• Mike Gelfand
• Principal developer at SolarWinds MSP
• Used a handful of programming languages in the past 10+ years
• Love cats
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Agenda
• What is the assembly language and how does it compare to C++?
• How do we leverage assembly knowledge in everyday life?
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Assembly Language,
whatever that is
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Typical use in modern age
•Operating systems (bootloaders,
hardware setup)
•Compilers (intermediate language, inline
assembler)
•Performance-critical code (encryption,
graphics, scientific simulations)
•Reverse engineering
•Debugging
leal -12(%ecx, %eax, 8), %edi
movzbl %ah, %ebp
fsub %st, %st(3)
(AT&T)
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Just how bad could it be?
CAN I HAZ
CLARITY?!
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Just how bad could it be?
leal -12(%ecx, %eax, 8), %edi
movzbl %ah, %ebp
fsub %st, %st(3)
(AT&T)
lea edi, [ecx + eax * 8 - 12]
movzx ebp, ah
fsub st(3), st
(Intel)
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Switching between Intel and AT&T flavors
Switch to Intel:
(gdb) set disassembly-flavor intel
(lldb) settings set target.x86-disassembly-flavor intel
Switch to AT&T (but why?):
(gdb) set disassembly-flavor att
(lldb) settings set target.x86-disassembly-flavor att
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
x86 registers overview © Wikipedia
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
General-purpose registers in the wild
Register Name Meaning [Extra] Use
RAX, EAX, AX Accumulator Result of multiplication or division
RBX, EBX, BX Base index Array index
RCX, ECX, CX Counter Number of iterations left in the loop or string operation
RDX, EDX, DX Data Multiplication result or dividend upper bits
RSP, ESP, SP Stack pointer Address of the top of the stack
RBP, EBP, BP Stack base pointer Address of the current stack frame
RSI, ESI, SI Source index Address of the current source operand of string operations
RDI, EDI, DI Destination index Address of the current destination operand of string operations
RIP, EIP Instruction pointer Address of the current instruction being executed
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
C++ vs. Assembly: Basic stuff
C++
int a = 5;
a += 7;
int b = a - 4;
a |= b;
bool c = a & 7;
a *= b;
b = *(int*)(a + b);
Assembly (AT&T)
mov $5, %eax
add $7, %eax
lea -4(%eax), %ebx
or %ebx, %eax
test $7, %eax
imul %ebx
mov (%eax, %ebx), %ebx
Assembly (Intel)
mov eax, 5
add eax, 7
lea ebx, [eax - 4]
or eax, ebx
test eax, 7
imul ebx
mov ebx, [eax + ebx]
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Flags register
Flag Meaning Category Use
CF Carry Status Carry or borrow indication (addition, subtraction, shift)
PF Parity Status Floating-point C2 flag check (e.g. FUCOM with NaN value)
AF Adjust Status Same as CF but just for the lower nibble (think BCD)
ZF Zero Status Result is zero/non-zero
SF Sign Status Result is negative/positive
OF Overflow Status Sign bit changed when adding two numbers of same sign, or subtracting two numbers of
different signs
DF Direction Control Specifies string processing direction
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
C++ vs. Assembly: Branching
C++
int a = 10;
while (a > 0)
{
if (a % 2 == 0)
a -= 3;
else
a /= 2;
}
Assembly (compiler)
[0x1f73] <+3>: mov ecx, 10
[0x1f76] <+6>: test ecx, ecx
[0x1f78] <+8>: jle 0x1f93 ; <+35>
[0x1f7a] <+10>: nop word ptr [eax + eax]
[0x1f80] <+16>: lea edx, [ecx - 0x3]
[0x1f83] <+19>: mov eax, ecx
[0x1f85] <+21>: shr eax
[0x1f87] <+23>: test cl, 0x1
[0x1f8a] <+26>: cmove eax, edx
[0x1f8d] <+29>: test eax, eax
[0x1f8f] <+31>: mov ecx, eax
[0x1f91] <+33>: jg 0x1f80 ; <+16>
[0x1f93] <+35>:
Assembly (human)
mov eax, 10
loop_start:
cmp eax, 0
jle finish
test eax, 1
jnz divide
sub eax, 3
jmp loop_start
divide:
sar eax, 1
jmp loop_start
finish:
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Calling conventions
• Where parameters and results reside
• In which order parameters are passed
• Who cleans up after the call
• What registers are preserved and who does it
• etc.
Currently in wide use:
• x86: cdecl, stdcall
• x64: MS, System V
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
C++ vs. Assembly: Calling functions (non-virtual, cdecl)
int f(int a, int b)
{
return a + b;
}
int g()
{
return f(2, 3) + 4;
}
f(int, int):
mov eax, DWORD PTR [esp + 0x8]
add eax, DWORD PTR [esp + 0x4]
ret
g():
push 0x3
push 0x2
call 0x8048520 <f(int, int)>
pop edx
add eax, 0x4
pop ecx
ret
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
C++ vs. Assembly: Calling functions (virtual, cdecl)
struct I
{
virtual int f(int a, int b) = 0;
};
struct A : public I
{
int f(int a, int b) override
{
return a + b;
}
};
int g(I& x)
{
return x.f(2, 3) + 4;
}
A::f(int, int):
mov eax, DWORD PTR [esp + 0xc]
add eax, DWORD PTR [esp + 0x8]
ret
g(I&):
sub esp, 0x10
mov eax, DWORD PTR [esp + 0x14]
mov edx, DWORD PTR [eax]
push 0x3
push 0x2
push eax
call DWORD PTR [edx]
add esp, 0x1c
add eax, 0x4
ret
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Assembly & Disassember
The Rescue Rangers
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Example #1: Waiting in kernel mode
// In a header far, far away
ULONG const TimeoutMs = 30000;
// Waiting up to 30 seconds for event to happen
LARGE_INTEGER timeout;
timeout.QuadPart = -1 * TimeoutMs * 10 * 1000;
NTSTATUS const waitResult =
KeWaitForSingleObject(&event, Executive,
KernelMode, FALSE, &timeout);
mov eax, dword ptr [TimeoutMs]
lea rcx, [rsp + 0x48] ; 1st arg
imul eax, eax, 0xFFFFD8F0
xor r9d, r9d ; 4th arg
xor r8d, r8d ; 3rd arg
xor edx, edx ; 2nd arg
mov qword ptr [rsp + 0x40], rax
lea rax, [rsp + 0x40]
mov qword ptr [rsp + 0x20], rax ; 5th arg
call qword ptr [_imp_KeWaitForSingleObject]
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Example #1: Waiting in kernel mode
// In a header far, far away
LONG const TimeoutMs = 30000;
// Waiting up to 30 seconds for event to happen
LARGE_INTEGER timeout;
timeout.QuadPart = -1 * TimeoutMs * 10 * 1000;
NTSTATUS const waitResult =
KeWaitForSingleObject(&event, Executive,
KernelMode, FALSE, &timeout);
mov eax, dword ptr [TimeoutMs]
lea rcx, [rsp + 0x48] ; 1st arg
imul eax, eax, 0xFFFFD8F0
xor r9d, r9d ; 4th arg
xor r8d, r8d ; 3rd arg
xor edx, edx ; 2nd arg
cdqe
mov qword ptr [rsp + 0x40], rax
lea rax, [rsp + 0x40]
mov qword ptr [rsp + 0x20], rax ; 5th arg
call qword ptr [_imp_KeWaitForSingleObject]
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Example #2: Magic statics
struct Data
{
int x;
Data() : x(123) {}
};
Data& GetData()
{
static Data data;
return data;
}
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Example #2: Magic statics
GCC 4.2.1 (released 10 years ago)
0x08048560 <_Z7GetDatav+0>: push ebp
0x08048561 <_Z7GetDatav+1>: mov ebp,esp
0x08048563 <_Z7GetDatav+3>: sub esp,0x8
0x08048566 <_Z7GetDatav+6>: cmp BYTE PTR ds:0x8049790,0x0
0x0804856d <_Z7GetDatav+13>: je 0x8048576 <_Z7GetDatav+22>
0x0804856f <_Z7GetDatav+15>: leave
0x08048570 <_Z7GetDatav+16>: mov eax,0x8049798
0x08048575 <_Z7GetDatav+21>: ret
0x08048576 <_Z7GetDatav+22>: mov DWORD PTR [esp],0x8049790
0x0804857d <_Z7GetDatav+29>: call 0x80483e4 <__cxa_guard_acquire@plt>
0x08048582 <_Z7GetDatav+34>: test eax,eax
0x08048584 <_Z7GetDatav+36>: je 0x804856f <_Z7GetDatav+15>
0x08048586 <_Z7GetDatav+38>: mov DWORD PTR [esp],0x8049798
0x0804858d <_Z7GetDatav+45>: call 0x80485e0 <Data>
0x08048592 <_Z7GetDatav+50>: mov DWORD PTR [esp],0x8049790
0x08048599 <_Z7GetDatav+57>: call 0x8048414 <__cxa_guard_release@plt>
0x0804859e <_Z7GetDatav+62>: mov eax,0x8049798
0x080485a3 <_Z7GetDatav+67>: leave
0x080485a4 <_Z7GetDatav+68>: ret
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Example #2: Magic statics
MSVC 12 (Visual Studio 2013)
example!GetData [example.cpp @ 14]:
14 00e61040 a14485e800 mov eax,dword ptr [example!$S1 (00e88544)]
15 00e61045 a801 test al,1
15 00e61047 7512 jne example!GetData+0x1b (00e6105b)
example!GetData+0x9 [example.cpp @ 15]:
15 00e61049 83c801 or eax,1
15 00e6104c b94085e800 mov ecx,offset example!data (00e88540)
15 00e61051 a34485e800 mov dword ptr [example!$S1 (00e88544)],eax
15 00e61056 e8aaffffff call example!ILT+0(??0DataQAEXZ) (00e61005)
example!GetData+0x1b [example.cpp @ 16]:
16 00e6105b b84085e800 mov eax,offset example!data (00e88540)
17 00e61060 c3 ret
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Example #2: Magic statics
MSVC 15 (Visual Studio 2017)
example!GetData [example.cpp @ 14]:
14 010765a0 64a12c000000 mov eax,dword ptr fs:[0000002Ch]
15 010765a6 8b0d80fc0c01 mov ecx,dword ptr [example!_tls_index (010cfc80)]
15 010765ac 8b0c88 mov ecx,dword ptr [eax+ecx*4]
15 010765af a14cfc0c01 mov eax,dword ptr [example!type_info `RTTI Type Descriptor'+0x128 (010cfc4c)]
15 010765b4 3b8104010000 cmp eax,dword ptr [ecx+104h]
15 010765ba 7f06 jg example!GetData+0x22 (010765c2)
example!GetData+0x1c [example.cpp @ 16]:
16 010765bc b848fc0c01 mov eax,offset example!data (010cfc48)
17 010765c1 c3 ret
example!GetData+0x22 [example.cpp @ 15]:
15 010765c2 684cfc0c01 push offset example!type_info `RTTI Type Descriptor'+0x128 (010cfc4c)
15 010765c7 e8d9afffff call example!ILT+1440(__Init_thread_header) (010715a5)
15 010765cc 83c404 add esp,4
15 010765cf 833d4cfc0c01ff cmp dword ptr [example!type_info `RTTI Type Descriptor'+0x128 (010cfc4c)],0FFFFFFFFh
15 010765d6 75e4 jne example!GetData+0x1c (010765bc)
example!GetData+0x38 [example.cpp @ 15]:
15 010765d8 b948fc0c01 mov ecx,offset example!data (010cfc48)
15 010765dd e857c1ffff call example!ILT+5940(??0DataQAEXZ) (01072739)
15 010765e2 684cfc0c01 push offset example!type_info `RTTI Type Descriptor'+0x128 (010cfc4c)
15 010765e7 e89eb6ffff call example!ILT+3205(__Init_thread_footer) (01071c8a)
15 010765ec 83c404 add esp,4
15 010765ef ebcb jmp example!GetData+0x1c (010765bc)
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Example #3: Code obfuscation
push edx
push 0x4920
mov dword ptr [esp], ecx
mov dword ptr [esp], edi
mov edi, 0x16BC2A97
push eax
mov eax, 0x7C4B60CD
add dword ptr [esp + 8], eax
mov eax, dword ptr [esp]
add esp, 4
add dword ptr [esp + 4], edi
sub dword ptr [esp + 4], 0x7C4B60CD
pop edi
push dword ptr [esp]
pop eax
push esi
mov esi, esp
add esi, 4
add esi, 4
xchg dword ptr [esp], esi
pop esp
push ebp
mov ebp, 0x16BC2A97
sub eax, ebp
pop ebp
mov edx, dword ptr [esp]
add esp, 4
void f(x86_regs32_t& regs, std::vector<std::uint32_t>& stack)
{
stack.push_back(regs.edx);
stack.push_back(0x4920);
stack[stack.size() - 1 - 0] = regs.ecx;
stack[stack.size() - 1 - 0] = regs.edi;
regs.edi = 0x16BC2A97;
stack.push_back(regs.eax);
regs.eax = 0x7C4B60CD;
stack[stack.size() - 1 - 2] += regs.eax;
regs.eax = stack[stack.size() - 1 - 0];
stack.pop_back();
stack[stack.size() - 1 - 1] += regs.edi;
stack[stack.size() - 1 - 1] -= 0x7C4B60CD;
regs.edi = stack[stack.size() - 1 - 0]; stack.pop_back();
stack.push_back(stack[stack.size() - 1 - 0]);
regs.eax = stack[stack.size() - 1 - 0]; stack.pop_back();
stack.push_back(regs.esi);
regs.esi = 0;
regs.esi += 1;
regs.esi += 1;
std::swap(stack[stack.size() - 1 - 0], regs.esi);
stack.resize(stack.size() - stack[stack.size() - 1 - 0] + 1);
stack.push_back(regs.ebp);
regs.ebp = 0x16BC2A97;
regs.eax -= regs.ebp;
regs.ebp = stack[stack.size() - 1 - 0]; stack.pop_back();
regs.edx = stack[stack.size() - 1 - 0];
stack.pop_back();
}
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Example #3: Code obfuscation
mov eax, edx
add edx, 0x16BC2A97
void f(std::uint32_t& eax, std::uint32_t& edx)
{
regs.eax = regs.edx;
regs.edx += 0x16BC2A97;
}
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
The Stuff
in case you’re interested
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Want to learn assembly and contribute at the same time?
• FASM — modern and fast assembler written in assembly
http://flatassembler.net/
• Menuet OS, Kolibri OS, BareMetal, and whole lot more
http://wiki.osdev.org/Projects
• KOL & MCK by Vladimir Kladov (achtung: Delphi)
http://kolmck.ru/
© 2017 SolarWinds MSP UK Ltd. All rights reserved.
Questions?
mike.gelfand@solarwinds.com
mikedld@mikedld.com
The SolarWinds and SolarWinds MSP trademarks are the
exclusive property of SolarWinds MSP UK Ltd. or its affiliates
and may be registered or pending registration with the U.S.
Patent and Trademark Office and in other countries. All other
SolarWinds MSP UK and SolarWinds trademarks, service
marks, and logos may be common law marks or are registered
or pending registration. All other trademarks mentioned
herein are used for identification purposes only and are
trademarks (and may be registered trademarks) of their
respective companies.

More Related Content

What's hot (20)

PDF
The Ring programming language version 1.5.4 book - Part 25 of 185
Mahmoud Samir Fayed
 
PPTX
General Purpose Computing using Graphics Hardware
Daniel Blezek
 
PDF
Use C++ to Manipulate mozSettings in Gecko
Chih-Hsuan Kuo
 
PDF
Adam Sitnik "State of the .NET Performance"
Yulia Tsisyk
 
PDF
IoT to the Database: Soldering, Python and a little PL/SQL
Blaine Carter
 
PPTX
AA-sort with SSE4.1
MITSUNARI Shigeo
 
PDF
Pandas+postgre sql 實作 with code
Tim Hong
 
PPTX
A comparison of apache spark supervised machine learning algorithms for dna s...
Valerio Morfino
 
PDF
The elements of a functional mindset
Eric Normand
 
PDF
Cosmological Perturbations and Numerical Simulations
Ian Huston
 
PDF
【論文紹介】Relay: A New IR for Machine Learning Frameworks
Takeo Imai
 
PDF
PyTorch 튜토리얼 (Touch to PyTorch)
Hansol Kang
 
DOCX
Network security
Rakesh chaudhary
 
PDF
Scala for Java programmers
輝 子安
 
PDF
Evaluation of X32 ABI for Virtualization and Cloud
The Linux Foundation
 
PDF
Fast Wavelet Tree Construction in Practice
Rakuten Group, Inc.
 
PDF
quantum chemistry on quantum computer handson by Q# (2019/8/4@MDR Hongo, Tokyo)
Maho Nakata
 
PDF
A compact bytecode format for JavaScriptCore
Tadeu Zagallo
 
PDF
Verification of Concurrent and Distributed Systems
Mykola Novik
 
The Ring programming language version 1.5.4 book - Part 25 of 185
Mahmoud Samir Fayed
 
General Purpose Computing using Graphics Hardware
Daniel Blezek
 
Use C++ to Manipulate mozSettings in Gecko
Chih-Hsuan Kuo
 
Adam Sitnik "State of the .NET Performance"
Yulia Tsisyk
 
IoT to the Database: Soldering, Python and a little PL/SQL
Blaine Carter
 
AA-sort with SSE4.1
MITSUNARI Shigeo
 
Pandas+postgre sql 實作 with code
Tim Hong
 
A comparison of apache spark supervised machine learning algorithms for dna s...
Valerio Morfino
 
The elements of a functional mindset
Eric Normand
 
Cosmological Perturbations and Numerical Simulations
Ian Huston
 
【論文紹介】Relay: A New IR for Machine Learning Frameworks
Takeo Imai
 
PyTorch 튜토리얼 (Touch to PyTorch)
Hansol Kang
 
Network security
Rakesh chaudhary
 
Scala for Java programmers
輝 子安
 
Evaluation of X32 ABI for Virtualization and Cloud
The Linux Foundation
 
Fast Wavelet Tree Construction in Practice
Rakuten Group, Inc.
 
quantum chemistry on quantum computer handson by Q# (2019/8/4@MDR Hongo, Tokyo)
Maho Nakata
 
A compact bytecode format for JavaScriptCore
Tadeu Zagallo
 
Verification of Concurrent and Distributed Systems
Mykola Novik
 

Viewers also liked (20)

PDF
C++Now Trip Report
corehard_by
 
PPTX
Ускоряем сборку С++ проектов. Практика использования unity-сборок
corehard_by
 
PPTX
Analysis and interpretation of monitoring data
corehard_by
 
PDF
Restinio - header-only http and websocket server
corehard_by
 
PDF
(Не)чёткий поиск
corehard_by
 
PPTX
C++ в играх, больших и не очень
corehard_by
 
PDF
MxxRu::externals: Repositoryless Dependency Manager
corehard_by
 
PPTX
Benchmark it
corehard_by
 
PDF
Actors for fun and profit
corehard_by
 
PDF
The beast is becoming functional
corehard_by
 
PDF
Обработка потока данных на примере deep packet inspection: внутренняя архитек...
corehard_by
 
PPTX
C++ in kernel mode
corehard_by
 
PPTX
Субъекторная модель
corehard_by
 
PPTX
Abseil - let the savior come?
corehard_by
 
PPTX
Поиск уязвимостей с использованием статического анализа кода
corehard_by
 
PPTX
Battle: BDD vs notBDD
COMAQA.BY
 
PPTX
Mixing C++ & Python II: Pybind11
corehard_by
 
PPTX
Слои тестового фрамеворка. Что? Где? Когда?
COMAQA.BY
 
PDF
Метаданные для кластера: гонка key-value-героев / Руслан Рагимов, Светлана Ла...
Ontico
 
PDF
Честное перформанс-тестирование / Дмитрий Пивоваров (ZeroTurnaround)
Ontico
 
C++Now Trip Report
corehard_by
 
Ускоряем сборку С++ проектов. Практика использования unity-сборок
corehard_by
 
Analysis and interpretation of monitoring data
corehard_by
 
Restinio - header-only http and websocket server
corehard_by
 
(Не)чёткий поиск
corehard_by
 
C++ в играх, больших и не очень
corehard_by
 
MxxRu::externals: Repositoryless Dependency Manager
corehard_by
 
Benchmark it
corehard_by
 
Actors for fun and profit
corehard_by
 
The beast is becoming functional
corehard_by
 
Обработка потока данных на примере deep packet inspection: внутренняя архитек...
corehard_by
 
C++ in kernel mode
corehard_by
 
Субъекторная модель
corehard_by
 
Abseil - let the savior come?
corehard_by
 
Поиск уязвимостей с использованием статического анализа кода
corehard_by
 
Battle: BDD vs notBDD
COMAQA.BY
 
Mixing C++ & Python II: Pybind11
corehard_by
 
Слои тестового фрамеворка. Что? Где? Когда?
COMAQA.BY
 
Метаданные для кластера: гонка key-value-героев / Руслан Рагимов, Светлана Ла...
Ontico
 
Честное перформанс-тестирование / Дмитрий Пивоваров (ZeroTurnaround)
Ontico
 
Ad

Similar to C++ and Assembly: Debugging and Reverse Engineering (20)

PDF
hashdays 2011: Ange Albertini - Such a weird processor - messing with x86 opc...
Area41
 
PPTX
Basic ASM by @binaryheadache
camsec
 
PPTX
Reversing malware analysis training part4 assembly programming basics
Cysinfo Cyber Security Community
 
PPTX
Intro to reverse engineering owasp
Tsvetelin Choranov
 
PDF
CNIT 127 Ch 1: Before you Begin
Sam Bowne
 
PDF
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
Willem van Ketwich
 
PPT
Assembly language
Piyush Jain
 
PDF
CNIT 127 Ch Ch 1: Before you Begin
Sam Bowne
 
PDF
The walking 0xDEAD
Carlos Garcia Prado
 
PDF
Hacker Thursdays: An introduction to binary exploitation
OWASP Hacker Thursday
 
PDF
Stale pointers are the new black
Vincenzo Iozzo
 
PDF
Reversing & malware analysis training part 4 assembly programming basics
Abdulrahman Bassam
 
PPTX
17
dano2osu
 
ODP
x86 & PE
Ange Albertini
 
PDF
Reverse Engineering Dojo: Enhancing Assembly Reading Skills
Asuka Nakajima
 
PPT
class04_x86assembly.ppt hy there u need be
mnewg218
 
PPTX
x86
Wei-Bo Chen
 
PDF
X86 assembly & GDB
Jian-Yu Li
 
PPT
Windows debugging sisimon
Sisimon Soman
 
PPTX
Introduction to Linux Exploit Development
johndegruyter
 
hashdays 2011: Ange Albertini - Such a weird processor - messing with x86 opc...
Area41
 
Basic ASM by @binaryheadache
camsec
 
Reversing malware analysis training part4 assembly programming basics
Cysinfo Cyber Security Community
 
Intro to reverse engineering owasp
Tsvetelin Choranov
 
CNIT 127 Ch 1: Before you Begin
Sam Bowne
 
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
Willem van Ketwich
 
Assembly language
Piyush Jain
 
CNIT 127 Ch Ch 1: Before you Begin
Sam Bowne
 
The walking 0xDEAD
Carlos Garcia Prado
 
Hacker Thursdays: An introduction to binary exploitation
OWASP Hacker Thursday
 
Stale pointers are the new black
Vincenzo Iozzo
 
Reversing & malware analysis training part 4 assembly programming basics
Abdulrahman Bassam
 
x86 & PE
Ange Albertini
 
Reverse Engineering Dojo: Enhancing Assembly Reading Skills
Asuka Nakajima
 
class04_x86assembly.ppt hy there u need be
mnewg218
 
X86 assembly & GDB
Jian-Yu Li
 
Windows debugging sisimon
Sisimon Soman
 
Introduction to Linux Exploit Development
johndegruyter
 
Ad

More from corehard_by (20)

PPTX
C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...
corehard_by
 
PPTX
C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...
corehard_by
 
PDF
C++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений Охотников
corehard_by
 
PPTX
C++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр Титов
corehard_by
 
PPTX
C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...
corehard_by
 
PPTX
C++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья Шишков
corehard_by
 
PPTX
C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...
corehard_by
 
PPTX
C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...
corehard_by
 
PPTX
C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...
corehard_by
 
PPTX
C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...
corehard_by
 
PDF
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
corehard_by
 
PPTX
C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...
corehard_by
 
PPTX
C++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел Филонов
corehard_by
 
PDF
C++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan Čukić
corehard_by
 
PDF
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
corehard_by
 
PDF
C++ CoreHard Autumn 2018. Полезный constexpr - Антон Полухин
corehard_by
 
PDF
C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...
corehard_by
 
PPTX
Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019
corehard_by
 
PDF
Как помочь и как помешать компилятору. Андрей Олейников ➠ CoreHard Autumn 2019
corehard_by
 
PDF
Автоматизируй это. Кирилл Тихонов ➠ CoreHard Autumn 2019
corehard_by
 
C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...
corehard_by
 
C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...
corehard_by
 
C++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений Охотников
corehard_by
 
C++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр Титов
corehard_by
 
C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...
corehard_by
 
C++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья Шишков
corehard_by
 
C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...
corehard_by
 
C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...
corehard_by
 
C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...
corehard_by
 
C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...
corehard_by
 
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
corehard_by
 
C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...
corehard_by
 
C++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел Филонов
corehard_by
 
C++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan Čukić
corehard_by
 
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
corehard_by
 
C++ CoreHard Autumn 2018. Полезный constexpr - Антон Полухин
corehard_by
 
C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...
corehard_by
 
Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019
corehard_by
 
Как помочь и как помешать компилятору. Андрей Олейников ➠ CoreHard Autumn 2019
corehard_by
 
Автоматизируй это. Кирилл Тихонов ➠ CoreHard Autumn 2019
corehard_by
 

Recently uploaded (20)

PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Python basic programing language for automation
DanialHabibi2
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
July Patch Tuesday
Ivanti
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 

C++ and Assembly: Debugging and Reverse Engineering

  • 1. C++ and Assembly: Debugging and Reverse Engineering Mike Gelfand
  • 2. © 2017 SolarWinds MSP UK Ltd. All rights reserved. About me • Mike Gelfand • Principal developer at SolarWinds MSP • Used a handful of programming languages in the past 10+ years • Love cats
  • 3. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Agenda • What is the assembly language and how does it compare to C++? • How do we leverage assembly knowledge in everyday life?
  • 4. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Assembly Language, whatever that is
  • 5. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Typical use in modern age •Operating systems (bootloaders, hardware setup) •Compilers (intermediate language, inline assembler) •Performance-critical code (encryption, graphics, scientific simulations) •Reverse engineering •Debugging
  • 6. leal -12(%ecx, %eax, 8), %edi movzbl %ah, %ebp fsub %st, %st(3) (AT&T) © 2017 SolarWinds MSP UK Ltd. All rights reserved. Just how bad could it be? CAN I HAZ CLARITY?!
  • 7. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Just how bad could it be? leal -12(%ecx, %eax, 8), %edi movzbl %ah, %ebp fsub %st, %st(3) (AT&T) lea edi, [ecx + eax * 8 - 12] movzx ebp, ah fsub st(3), st (Intel)
  • 8. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Switching between Intel and AT&T flavors Switch to Intel: (gdb) set disassembly-flavor intel (lldb) settings set target.x86-disassembly-flavor intel Switch to AT&T (but why?): (gdb) set disassembly-flavor att (lldb) settings set target.x86-disassembly-flavor att
  • 9. © 2017 SolarWinds MSP UK Ltd. All rights reserved. x86 registers overview © Wikipedia
  • 10. © 2017 SolarWinds MSP UK Ltd. All rights reserved. General-purpose registers in the wild Register Name Meaning [Extra] Use RAX, EAX, AX Accumulator Result of multiplication or division RBX, EBX, BX Base index Array index RCX, ECX, CX Counter Number of iterations left in the loop or string operation RDX, EDX, DX Data Multiplication result or dividend upper bits RSP, ESP, SP Stack pointer Address of the top of the stack RBP, EBP, BP Stack base pointer Address of the current stack frame RSI, ESI, SI Source index Address of the current source operand of string operations RDI, EDI, DI Destination index Address of the current destination operand of string operations RIP, EIP Instruction pointer Address of the current instruction being executed
  • 11. © 2017 SolarWinds MSP UK Ltd. All rights reserved. C++ vs. Assembly: Basic stuff C++ int a = 5; a += 7; int b = a - 4; a |= b; bool c = a & 7; a *= b; b = *(int*)(a + b); Assembly (AT&T) mov $5, %eax add $7, %eax lea -4(%eax), %ebx or %ebx, %eax test $7, %eax imul %ebx mov (%eax, %ebx), %ebx Assembly (Intel) mov eax, 5 add eax, 7 lea ebx, [eax - 4] or eax, ebx test eax, 7 imul ebx mov ebx, [eax + ebx]
  • 12. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Flags register Flag Meaning Category Use CF Carry Status Carry or borrow indication (addition, subtraction, shift) PF Parity Status Floating-point C2 flag check (e.g. FUCOM with NaN value) AF Adjust Status Same as CF but just for the lower nibble (think BCD) ZF Zero Status Result is zero/non-zero SF Sign Status Result is negative/positive OF Overflow Status Sign bit changed when adding two numbers of same sign, or subtracting two numbers of different signs DF Direction Control Specifies string processing direction
  • 13. © 2017 SolarWinds MSP UK Ltd. All rights reserved. C++ vs. Assembly: Branching C++ int a = 10; while (a > 0) { if (a % 2 == 0) a -= 3; else a /= 2; } Assembly (compiler) [0x1f73] <+3>: mov ecx, 10 [0x1f76] <+6>: test ecx, ecx [0x1f78] <+8>: jle 0x1f93 ; <+35> [0x1f7a] <+10>: nop word ptr [eax + eax] [0x1f80] <+16>: lea edx, [ecx - 0x3] [0x1f83] <+19>: mov eax, ecx [0x1f85] <+21>: shr eax [0x1f87] <+23>: test cl, 0x1 [0x1f8a] <+26>: cmove eax, edx [0x1f8d] <+29>: test eax, eax [0x1f8f] <+31>: mov ecx, eax [0x1f91] <+33>: jg 0x1f80 ; <+16> [0x1f93] <+35>: Assembly (human) mov eax, 10 loop_start: cmp eax, 0 jle finish test eax, 1 jnz divide sub eax, 3 jmp loop_start divide: sar eax, 1 jmp loop_start finish:
  • 14. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Calling conventions • Where parameters and results reside • In which order parameters are passed • Who cleans up after the call • What registers are preserved and who does it • etc. Currently in wide use: • x86: cdecl, stdcall • x64: MS, System V
  • 15. © 2017 SolarWinds MSP UK Ltd. All rights reserved. C++ vs. Assembly: Calling functions (non-virtual, cdecl) int f(int a, int b) { return a + b; } int g() { return f(2, 3) + 4; } f(int, int): mov eax, DWORD PTR [esp + 0x8] add eax, DWORD PTR [esp + 0x4] ret g(): push 0x3 push 0x2 call 0x8048520 <f(int, int)> pop edx add eax, 0x4 pop ecx ret
  • 16. © 2017 SolarWinds MSP UK Ltd. All rights reserved. C++ vs. Assembly: Calling functions (virtual, cdecl) struct I { virtual int f(int a, int b) = 0; }; struct A : public I { int f(int a, int b) override { return a + b; } }; int g(I& x) { return x.f(2, 3) + 4; } A::f(int, int): mov eax, DWORD PTR [esp + 0xc] add eax, DWORD PTR [esp + 0x8] ret g(I&): sub esp, 0x10 mov eax, DWORD PTR [esp + 0x14] mov edx, DWORD PTR [eax] push 0x3 push 0x2 push eax call DWORD PTR [edx] add esp, 0x1c add eax, 0x4 ret
  • 17. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Assembly & Disassember The Rescue Rangers
  • 18. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Example #1: Waiting in kernel mode // In a header far, far away ULONG const TimeoutMs = 30000; // Waiting up to 30 seconds for event to happen LARGE_INTEGER timeout; timeout.QuadPart = -1 * TimeoutMs * 10 * 1000; NTSTATUS const waitResult = KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, &timeout); mov eax, dword ptr [TimeoutMs] lea rcx, [rsp + 0x48] ; 1st arg imul eax, eax, 0xFFFFD8F0 xor r9d, r9d ; 4th arg xor r8d, r8d ; 3rd arg xor edx, edx ; 2nd arg mov qword ptr [rsp + 0x40], rax lea rax, [rsp + 0x40] mov qword ptr [rsp + 0x20], rax ; 5th arg call qword ptr [_imp_KeWaitForSingleObject]
  • 19. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Example #1: Waiting in kernel mode // In a header far, far away LONG const TimeoutMs = 30000; // Waiting up to 30 seconds for event to happen LARGE_INTEGER timeout; timeout.QuadPart = -1 * TimeoutMs * 10 * 1000; NTSTATUS const waitResult = KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, &timeout); mov eax, dword ptr [TimeoutMs] lea rcx, [rsp + 0x48] ; 1st arg imul eax, eax, 0xFFFFD8F0 xor r9d, r9d ; 4th arg xor r8d, r8d ; 3rd arg xor edx, edx ; 2nd arg cdqe mov qword ptr [rsp + 0x40], rax lea rax, [rsp + 0x40] mov qword ptr [rsp + 0x20], rax ; 5th arg call qword ptr [_imp_KeWaitForSingleObject]
  • 20. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Example #2: Magic statics struct Data { int x; Data() : x(123) {} }; Data& GetData() { static Data data; return data; }
  • 21. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Example #2: Magic statics GCC 4.2.1 (released 10 years ago) 0x08048560 <_Z7GetDatav+0>: push ebp 0x08048561 <_Z7GetDatav+1>: mov ebp,esp 0x08048563 <_Z7GetDatav+3>: sub esp,0x8 0x08048566 <_Z7GetDatav+6>: cmp BYTE PTR ds:0x8049790,0x0 0x0804856d <_Z7GetDatav+13>: je 0x8048576 <_Z7GetDatav+22> 0x0804856f <_Z7GetDatav+15>: leave 0x08048570 <_Z7GetDatav+16>: mov eax,0x8049798 0x08048575 <_Z7GetDatav+21>: ret 0x08048576 <_Z7GetDatav+22>: mov DWORD PTR [esp],0x8049790 0x0804857d <_Z7GetDatav+29>: call 0x80483e4 <__cxa_guard_acquire@plt> 0x08048582 <_Z7GetDatav+34>: test eax,eax 0x08048584 <_Z7GetDatav+36>: je 0x804856f <_Z7GetDatav+15> 0x08048586 <_Z7GetDatav+38>: mov DWORD PTR [esp],0x8049798 0x0804858d <_Z7GetDatav+45>: call 0x80485e0 <Data> 0x08048592 <_Z7GetDatav+50>: mov DWORD PTR [esp],0x8049790 0x08048599 <_Z7GetDatav+57>: call 0x8048414 <__cxa_guard_release@plt> 0x0804859e <_Z7GetDatav+62>: mov eax,0x8049798 0x080485a3 <_Z7GetDatav+67>: leave 0x080485a4 <_Z7GetDatav+68>: ret
  • 22. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Example #2: Magic statics MSVC 12 (Visual Studio 2013) example!GetData [example.cpp @ 14]: 14 00e61040 a14485e800 mov eax,dword ptr [example!$S1 (00e88544)] 15 00e61045 a801 test al,1 15 00e61047 7512 jne example!GetData+0x1b (00e6105b) example!GetData+0x9 [example.cpp @ 15]: 15 00e61049 83c801 or eax,1 15 00e6104c b94085e800 mov ecx,offset example!data (00e88540) 15 00e61051 a34485e800 mov dword ptr [example!$S1 (00e88544)],eax 15 00e61056 e8aaffffff call example!ILT+0(??0DataQAEXZ) (00e61005) example!GetData+0x1b [example.cpp @ 16]: 16 00e6105b b84085e800 mov eax,offset example!data (00e88540) 17 00e61060 c3 ret
  • 23. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Example #2: Magic statics MSVC 15 (Visual Studio 2017) example!GetData [example.cpp @ 14]: 14 010765a0 64a12c000000 mov eax,dword ptr fs:[0000002Ch] 15 010765a6 8b0d80fc0c01 mov ecx,dword ptr [example!_tls_index (010cfc80)] 15 010765ac 8b0c88 mov ecx,dword ptr [eax+ecx*4] 15 010765af a14cfc0c01 mov eax,dword ptr [example!type_info `RTTI Type Descriptor'+0x128 (010cfc4c)] 15 010765b4 3b8104010000 cmp eax,dword ptr [ecx+104h] 15 010765ba 7f06 jg example!GetData+0x22 (010765c2) example!GetData+0x1c [example.cpp @ 16]: 16 010765bc b848fc0c01 mov eax,offset example!data (010cfc48) 17 010765c1 c3 ret example!GetData+0x22 [example.cpp @ 15]: 15 010765c2 684cfc0c01 push offset example!type_info `RTTI Type Descriptor'+0x128 (010cfc4c) 15 010765c7 e8d9afffff call example!ILT+1440(__Init_thread_header) (010715a5) 15 010765cc 83c404 add esp,4 15 010765cf 833d4cfc0c01ff cmp dword ptr [example!type_info `RTTI Type Descriptor'+0x128 (010cfc4c)],0FFFFFFFFh 15 010765d6 75e4 jne example!GetData+0x1c (010765bc) example!GetData+0x38 [example.cpp @ 15]: 15 010765d8 b948fc0c01 mov ecx,offset example!data (010cfc48) 15 010765dd e857c1ffff call example!ILT+5940(??0DataQAEXZ) (01072739) 15 010765e2 684cfc0c01 push offset example!type_info `RTTI Type Descriptor'+0x128 (010cfc4c) 15 010765e7 e89eb6ffff call example!ILT+3205(__Init_thread_footer) (01071c8a) 15 010765ec 83c404 add esp,4 15 010765ef ebcb jmp example!GetData+0x1c (010765bc)
  • 24. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Example #3: Code obfuscation push edx push 0x4920 mov dword ptr [esp], ecx mov dword ptr [esp], edi mov edi, 0x16BC2A97 push eax mov eax, 0x7C4B60CD add dword ptr [esp + 8], eax mov eax, dword ptr [esp] add esp, 4 add dword ptr [esp + 4], edi sub dword ptr [esp + 4], 0x7C4B60CD pop edi push dword ptr [esp] pop eax push esi mov esi, esp add esi, 4 add esi, 4 xchg dword ptr [esp], esi pop esp push ebp mov ebp, 0x16BC2A97 sub eax, ebp pop ebp mov edx, dword ptr [esp] add esp, 4 void f(x86_regs32_t& regs, std::vector<std::uint32_t>& stack) { stack.push_back(regs.edx); stack.push_back(0x4920); stack[stack.size() - 1 - 0] = regs.ecx; stack[stack.size() - 1 - 0] = regs.edi; regs.edi = 0x16BC2A97; stack.push_back(regs.eax); regs.eax = 0x7C4B60CD; stack[stack.size() - 1 - 2] += regs.eax; regs.eax = stack[stack.size() - 1 - 0]; stack.pop_back(); stack[stack.size() - 1 - 1] += regs.edi; stack[stack.size() - 1 - 1] -= 0x7C4B60CD; regs.edi = stack[stack.size() - 1 - 0]; stack.pop_back(); stack.push_back(stack[stack.size() - 1 - 0]); regs.eax = stack[stack.size() - 1 - 0]; stack.pop_back(); stack.push_back(regs.esi); regs.esi = 0; regs.esi += 1; regs.esi += 1; std::swap(stack[stack.size() - 1 - 0], regs.esi); stack.resize(stack.size() - stack[stack.size() - 1 - 0] + 1); stack.push_back(regs.ebp); regs.ebp = 0x16BC2A97; regs.eax -= regs.ebp; regs.ebp = stack[stack.size() - 1 - 0]; stack.pop_back(); regs.edx = stack[stack.size() - 1 - 0]; stack.pop_back(); }
  • 25. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Example #3: Code obfuscation mov eax, edx add edx, 0x16BC2A97 void f(std::uint32_t& eax, std::uint32_t& edx) { regs.eax = regs.edx; regs.edx += 0x16BC2A97; }
  • 26. © 2017 SolarWinds MSP UK Ltd. All rights reserved. The Stuff in case you’re interested
  • 27. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Want to learn assembly and contribute at the same time? • FASM — modern and fast assembler written in assembly http://flatassembler.net/ • Menuet OS, Kolibri OS, BareMetal, and whole lot more http://wiki.osdev.org/Projects • KOL & MCK by Vladimir Kladov (achtung: Delphi) http://kolmck.ru/
  • 28. © 2017 SolarWinds MSP UK Ltd. All rights reserved. Questions? [email protected] [email protected]
  • 29. The SolarWinds and SolarWinds MSP trademarks are the exclusive property of SolarWinds MSP UK Ltd. or its affiliates and may be registered or pending registration with the U.S. Patent and Trademark Office and in other countries. All other SolarWinds MSP UK and SolarWinds trademarks, service marks, and logos may be common law marks or are registered or pending registration. All other trademarks mentioned herein are used for identification purposes only and are trademarks (and may be registered trademarks) of their respective companies.