Foundations of ARM64 Linux Debugging, Disassembling, and Reversing: Analyze Code, Understand Stack Memory Usage, and Reconstruct Original C/C++ Code with ARM64 1st Edition Dmitry Vostokov - Download the full set of chapters carefully compiled
Foundations of ARM64 Linux Debugging, Disassembling, and Reversing: Analyze Code, Understand Stack Memory Usage, and Reconstruct Original C/C++ Code with ARM64 1st Edition Dmitry Vostokov - Download the full set of chapters carefully compiled
https://ebookmass.com/product/foundations-of-arm64-linux-debugging-
disassembling-and-reversing-dmitry-vostokov/
https://ebookmass.com/product/international-swimming-pool-and-spa-
code-2021-1st-edition-international-code-council/
https://ebookmass.com/product/international-fire-code-international-
code-council-series-2021-1st-edition-international-code-council/
Foundations of ARM64
Linux Debugging,
Disassembling, and
Reversing
Analyze Code, Understand Stack
Memory Usage, and Reconstruct
Original C/C++ Code with ARM64
—
Dmitry Vostokov
Foundations of
ARM64 Linux
Debugging,
Disassembling, and
Reversing
Analyze Code, Understand
Stack Memory Usage,
and Reconstruct Original C/C++
Code with ARM64
Dmitry Vostokov
Foundations of ARM64 Linux Debugging, Disassembling, and Reversing:
Analyze Code, Understand Stack Memory Usage, and Reconstruct Original
C/C++ Code with ARM64
Dmitry Vostokov
Dublin, Ireland
Preface����������������������������������������������������������������������������������������������xiii
iii
Table of Contents
Chapter 4: Pointers�����������������������������������������������������������������������������35
A Definition���������������������������������������������������������������������������������������������������������35
“Pointers” Project: Memory Layout and Registers����������������������������������������������36
“Pointers” Project: Calculations��������������������������������������������������������������������������38
Using Pointers to Assign Numbers to Memory Cells�������������������������������������������39
Adding Numbers Using Pointers�������������������������������������������������������������������������46
Incrementing Numbers Using Pointers���������������������������������������������������������������51
Multiplying Numbers Using Pointers�������������������������������������������������������������������54
Summary������������������������������������������������������������������������������������������������������������58
iv
Table of Contents
v
Table of Contents
vi
Table of Contents
vii
Table of Contents
Index�������������������������������������������������������������������������������������������������167
viii
About the Author
Dmitry Vostokov is an internationally
recognized expert, speaker, educator, scientist,
and author. He is the founder of the pattern-
oriented software diagnostics, forensics,
and prognostics discipline and Software
Diagnostics Institute (DA+TA: DumpAnalysis.
org + TraceAnalysis.org). Vostokov has also
authored more than 50 books on software
diagnostics, anomaly detection and analysis,
software and memory forensics, root cause analysis and problem solving,
memory dump analysis, debugging, software trace and log analysis,
reverse engineering, and malware analysis. He has more than 25 years
of experience in software architecture, design, development, and
maintenance in various industries, including leadership, technical, and
people management roles. Dmitry also founded Syndromatix, Anolog.
io, BriteTrace, DiaThings, Logtellect, OpenTask Iterative and Incremental
Publishing (OpenTask.com), Software Diagnostics Technology and
Services (former Memory Dump Analysis Services; PatternDiagnostics.
com), and Software Prognostics. In his spare time, he presents various
topics on Debugging TV and explores Software Narratology, its further
development as Narratology of Things and Diagnostics of Things (DoT),
Software Pathology, and Quantum Software Diagnostics. His current
areas of interest are theoretical software diagnostics and its mathematical
and computer science foundations, application of formal logic, artificial
intelligence, machine learning and data mining to diagnostics and anomaly
detection, software diagnostics engineering and diagnostics-driven
ix
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
About the Author
x
About the Technical Reviewer
Sundar Pandian has more than three
years of experience in embedded software
development, including development of device
drivers, middleware software, and application
services for the infotainment system on the
Android platform. He’s also developed CAN
protocol drivers for the automotive braking
system on the Autosar platform.
He’s developed software with C, C++,
and Java and worked in the automotive,
semiconductor, and telecom industries. He has
a bachelor’s in electronics and communication engineering. Currently, he
serves as a firmware/middleware engineer for audio DSPs.
xi
Preface
The book covers topics ranging from ARM64 assembly language
instructions and writing programs in assembly language to pointers, live
debugging, and static binary analysis of compiled C and C++ code.
Diagnostics of core memory dumps, live and postmortem debugging
of Linux applications, services, and systems, memory forensics, malware,
and vulnerability analysis require an understanding of ARM64 assembly
language and how C and C++ compilers generate code, including
memory layout and pointers. This book is about background knowledge
and practical foundations that are needed to understand internal Linux
program structure and behavior, start working with the GDB debugger, and
use it for disassembly and reversing. It consists of practical step-by-step
exercises of increasing complexity with explanations and many diagrams,
including some necessary background topics.
By the end of the book, you will have a solid understanding of how
Linux C and C++ compilers generate binary code. In addition, you will be
able to analyze such code confidently, understand stack memory usage,
and reconstruct original C/C++ code.
The book will be useful for
• Software testers
xiii
Preface
This book can also be used as an ARM64 assembly language and Linux
debugging supplement for relevant undergraduate-level courses.
Source Code
All source code used in this book can be downloaded from github.com/
apress/arm64-linux-debugging-disassembling-reversing.
xiv
CHAPTER 1
Memory, Registers,
and Simple Arithmetic
emory and Registers Inside an
M
Idealized Computer
Computer memory consists of a sequence of memory cells, and each cell
has a unique address (location). Every cell contains a “number.” We refer
to these “numbers” as contents at addresses (locations). Because memory
access is slower than arithmetic instructions, there are so-called registers
to speed up complex operations that require memory to store temporary
results. We can also think about them as stand-alone memory cells. The
name of a register is its address. Figure 1-1 illustrates this.
2
Chapter 1 Memory, Registers, and Simple Arithmetic
3
Chapter 1 Memory, Registers, and Simple Arithmetic
static int a, b;
4
Chapter 1 Memory, Registers, and Simple Arithmetic
5
Chapter 1 Memory, Registers, and Simple Arithmetic
If we use the C or C++ language, “a” is called “the variable a,” and we
write the assignment as
a = 1;
adr x0, a
mov w1, #1
str w1, [x0]
adrp x0, 0x4b2000
add x0, x0, #0xb00
mov w1, #0x1
str w1, [x0]
adrp x0, 0x4b2000, and subsequent add x0, x0, #0xb00 is how the
compiler generates code to calculate the address “a” instead of specifying it
directly. Such code is required for addressing large regions of memory, and
6
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
Other documents randomly have
different content
He looked straight at her now as if she were his strength, his
refuge. His eyes were haggard, strained. “Go on, what is it?” he
said.
As if in reward for his docility she closed her hand again on his
where it rested on the rock. It seemed to give him strength—
strength to follow, to obey.
“Listen, Tom; are you listening? An indictment—you know what an
indictment is, don’t you?” she said kindly. “It’s an accusation—by the
state. You and I are part of the state; do you see? It’s our
accusation—no, no no, please don’t be angry, Tom—I just mean that
it isn’t a question between you and Mr. Whalen and the state, see?
Because we’re a part of the state—you and I.”
It cheered and consoled him to hear her couple their two names
in this way. It made them seem like—like partners.
“That indictment stands, Tom; it stands until it’s answered.
Running away and hiding somewhere else doesn’t answer it. Don’t
you see? And it is not for you and me to set ourselves up as judges.
It’s just a question of good citizenship, Tom, that’s all. I wish now
you had read the book I asked you to read.
“You have to go to Kingston and tell them, the authorities;
because there’s a stigma on you till you do. You have to think of
your highest duty and that is your duty as a citizen. Then when they
—when the case comes to trial you have a right to help him all you
can. And you will try to, I know you will. I just thought that if you
took the two thousand dollars you could hire a lawyer with it maybe
—because I know he’s poor.”
“Poor,” Tom whispered in pitiful, broken tones; “Yop.”
“You can be a good citizen if you will, and then a good friend if
he’ll let you. Please don’t, Tom—oh please—no, no, listen, Tom. I
just want you to do your duty. Listen,” she pled. “I will have the
money that Niel pays me for helping him—about three hundred
dollars—and you can have that too. We’ll chip in to help him, Tom.
And then—maybe—he’ll be freed—he’ll have his freedom in the right
way. Free just like you and me. Don’t you see, Tom?”
He nodded his head in reluctant assent.
“You must go and tell them, Tom, you must tell them that he is
here. If we disrespect the law we can’t expect the law to protect us.
Do you know what an indictment says, Tom? How it begins? It says,
‘We the people.’ Tom—poor Tom—I’m sorry, oh, so sorry. But you’ll
do what’s brave and right, won’t you? Yes, you will. You came to ask
me and I have to tell you. It’s just like—I know—it’s just like going to
war and shooting mothers’ sons, Tom. But you were a soldier and a
scout and that means you’re a citizen. Aren’t you, Tom? And you’ll
do your plain duty, won’t you? You asked me, Tom, and I’m telling
you—you’ll—I knew you would....”
Yes, she knew he would because he hung his head, then of a
sudden clasped his hands before his face. It was only for just a
moment....
CHAPTER XXX
THE DEPARTURE
TIME
ALONE
GOODFELLOW
And now a quick exhilaration seized Tom; the tempest was over. It
was a pity that Audry Ferris could not be there to feel the full force
of his breezy air of emancipation. To see him come swaggering up
out of the valley of the shadow. To take note of that careless,
independent whistling of a song, which seemed to proclaim to the
world, “I should worry.” But these things would keep. His spirit
seemed likely to last a day or two—oh, goodness, yes.
He was just going to celebrate his emancipation by getting up and
throwing those boisterous tin cans overboard when the boat lurched
enough to cause him to keep his seat. Just in that moment his
exhilaration was chilled by a blighting thought. If he did not tell,
perhaps Audry would. The secret was between these two.
Presently something happened which startled him. Simultaneously
with a lurch of the boat came a sound from within the cabin, a
sound as of someone falling. Then the sliding-door rolled slowly
open. A can rolled across the deck, making a clanking sound as it
struck an iron cable cleat.
In the dim light within the cabin, Tom could see a hand; it seemed
very white in the gathering darkness. It was on the floor and the
arm extended past the opening, so that all Tom could see was just
this hand and arm. It seemed to him as if the hand belonged to one
crouching, and who had cautiously rolled the door open for him to
enter.
He went in, then paused aghast at what he saw. If the hand had
started the door, then it had been hospitably opened by a dead man.
In the lurching of the boat the figure, apparently, had rolled out of
the starboard bunk. It was in a sunken, half-sitting posture against
the bunk. The head hung sideways, the glazed eyes leering at Tom
as in ghastly welcome. He could not get it out of his startled senses
that this thing had gotten out of the bunk, pushed the door open,
and sat there on the floor in an affected attitude of subservient
greeting. It seemed to say, “Here I am at your feet; walk in, won’t
you?”
Tom was startled, agitated. But he was not panic-stricken. He laid
the body decently upon the floor, crossways so it would not roll with
the rocking of the boat. It was the body of a man under middle age,
partly clothed. He had been for many days unshaven, and was in a
pitiful state of emaciation. Tom thought he had been dead for only a
day or two. He pulled some shreds of awning from across the port-
holes, threw open the heavy brass-bound glass disks, and let in the
fresh evening air and such light as the late twilight afforded.
He was too perturbed to see or think of anything outside the
tragic circumstance of death, but a hasty glance about the cabin
showed all too plainly that the boat had been the lonely refuge of
this wretched, gaunt creature for many days. Whether anybody
knew of his refuge Tom could not conjecture. He supposed that the
owner was still abroad. No doubt the dead man had been fully
cognizant of the measure of safety he enjoyed. Tom thought he
might have died of consumption; he could not bear the thought that
he had died of starvation.
The walls of the cabin were very much besmeared with soot from
a smelly, filthy oil stove. There were a very few odds and ends of
food. Fishing tackle lay about and an old crab net. It was the lonely
tenant of the Goodfellow, and not boys, who had fished, probably in
the shelter of the darkness.
On the little table a few papers were in a pasteboard box. An
empty soup-can had been fastened to the slab by a tack driven
through the bottom. In this stood a fountain pen. A bottle of ink had
slid off on the floor. Among the papers was a queer pasteboard
device, with a disk that turned; it was some kind of an elaborate
weather chart. There were many clippings about the weather stuck
on a nail in the bulkhead.
An unfinished manuscript of yellow paper was hanging in a large
fish-hook also fastened to the bulkhead. Tom glanced at this, read a
few lines, took it out into the better light of the cockpit and read
more. When it was too dark to see he tiptoed into the chamber of
death and sought amid the squalid disorder of alien paraphernalia
for a lantern, but could find none. Nor could he find any matches.
He thought these might be in the dead man’s pocket. He did not
search for them. He folded the loose pages, put them in his pocket,
and tiptoed out into the cockpit again. The moon was coming up full
and glinting the water which still rippled, sometimes into whitecaps,
in the fresh breeze. The threat of storm had passed. The night was
clear and cool.
He rolled the little cabin door shut and fastened it. He picked up
the cans which were rolling and clanking about the deck and cast
them in the water. It was very still then. He could not remain here.
Even the sound of his own footfalls on the deck startled him. He
tiptoed to the rail, climbed over and into the little waiting, bobbing
skiff, and rowed for the shore. Once away from the boat he was glad
for the companionable clanking of the oar-locks; it was a good
wholesome, cheery sound.
Tom rowed for the shore after finding the man’s
body.
LAST WORDS
HOMEWARD BOUND
Tom’s sensational discovery seemed to take the edge off his new
resolve in the matter of his duty. Kind fate had taken the matter out
of his hands. But he had made his resolve before that discovery. And
right or wrong he gloried in his independent decision. He thought of
Audry with a kind of bravado.
But all thoughts now were subservient to his new and urgent duty.
Hurrying to the local headquarters of police, he told hurriedly of his
harrowing discovery, laying the manuscript before the official on
duty.
For a few terrible minutes he thought they were going to hold
him. But they seemed in the end to be impressed with the
straightforwardness of his narrative and let him go after taking his
name and address. One of them recognized him as assistant at
Temple Camp and doubtless that fact saved him the exasperation of
being detained. He said nothing about Whalen for he saw no reason
to do so. He would bring Whalen into the light, but in his own way.
He wished to manage that end of it. His brain was seething with
plans.
Now that he had gotten the burden of his discovery and its
startling revelation off his mind and into the proper hands, his one
thought was to reach the mountain before the countryside was
ringing with the news. The officials had darkly warned him that they
might want him any time.
He caught a train down to Kingston, had a bite to eat there, then
started for the mountain on foot. It is a long walk over the fine
highway from Kingston to West Hurley, but he was accustomed to
long hikes, and his excitement gave him an elastic energy. He
recalled that Billy the sailor had tramped all the way from
Poughkeepsie. His tumultuous thoughts beguiled the journey like a
circus. He seemed to be on springs. Twin lights came rapidly along
from both directions, now and then a horn honked its warning, once
he called asking for a lift but got no answer; he did not care.
“They, the powers that be,” he panted, “know where the culprit—
the real culprit—is, and I’ll take care of my end of it—all right, all
right.” In his exhilaration it never occurred to him that he had
revealed the whereabouts of the murderer of Henry Merrick and
might, technically, be entitled to the reward. He was, at least, the
means of exposing the ultimate sequel of that old crime.
But he did think of the—thing out there on the river, lying face
upward. And he could not repress a certain measure of pity when he
thought of those days of wistful waiting; waiting for the drought to
bring the ghost of old West Hurley once again to light.
But these were not pleasant thoughts for a lonely wayfarer at
night. So he thought of Mr. Fairgreaves, the courtly, the magnificent
Mr. Fairgreaves. Well, he would see them all in the morning....
It was midnight when he reached West Hurley and he was not yet
tired. He realized how futile was his steady, rapid stride. He could
not sleep when he reached the cottage. And he could not see any
one before morning. Why hurry? He conquered his nerves and
resolved not to hurry.
While West Hurley slept, Tom walked down to the shore of the
reservoir. The moon shone upon it and the shimmering area of the
vast storage lake looked like a golden island. Not a sound was there.
If the water was low, he could see no sign of it on the near shore.
Somewhere under that water, in old ruined masonry, was a box
with valuable papers. It seemed preposterously romantic—like buried
treasure. And a poor stricken wretch with the stigma of old crime
upon him had waited and waited for the stubborn water to subside—
and had died waiting.
Three deaths so far—and sorrow and homelessness. And folks
away off in the great city of New York turning on their faucets, and
watering their lawns, and putting out their fires with this same
water, and never thinking, never knowing....
CHAPTER XXXVII
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookmass.com