Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: "db" a string constant in assembler?


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Mar 5, 2016 6:47 AM Last Post By: Rudy Velthuis (...
Arthur Hoornweg

Posts: 414
Registered: 6/2/98
"db" a string constant in assembler?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 21, 2016 3:19 AM
Hello all,

I'd like to use a Delphi string constant inside an assembler block as a "db" statement, is that possible at all? The following won't compile:

CONST myconstant='Just a string';
 
Procedure test;
Begin
  asm
    jmp @skipovertext
@copyofstring: db myconstant,0
@skipovertext:
  end;
End;

Kind regards,
Arthur Hoornweg

Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: "db" a string constant in assembler?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 26, 2016 6:01 PM   in response to: Arthur Hoornweg in response to: Arthur Hoornweg
Arthur Hoornweg wrote:

Hello all,

I'd like to use a Delphi string constant inside an assembler block as
a "db" statement, is that possible at all? The following won't
compile:

CONST myconstant='Just a string';
 
Procedure test;
Begin
  asm
    jmp @skipovertext
@copyofstring: db myconstant,0
@skipovertext:
  end;
End;

Apparently not. This surprises me a bit. But note that the string is
stored in the executable already, so there is no need to repeat it.

--
Rudy Velthuis http://www.rvelthuis.de

"Devlin's First Law - Buyer beware: in the hands of a charlatan,
mathematics can be used to make a vacuous argument look
impressive.
Devlin's Second Law - So can PowerPoint." -- Keith Devlin
Arthur Hoornweg

Posts: 414
Registered: 6/2/98
Re: "db" a string constant in assembler?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 22, 2016 4:57 AM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) wrote:

Apparently not. This surprises me a bit. But note that the string is
stored in the executable already, so there is no need to repeat it.

The string is part of a tamper-protection scheme. I need the exact same string to be inside an assembler function and also to be accessible (read access) in a separate Delphi function. So it would be nice if I could store it only once as a CONST instead of having to repeat it.

Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: "db" a string constant in assembler?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 22, 2016 5:14 AM   in response to: Arthur Hoornweg in response to: Arthur Hoornweg
Arthur Hoornweg wrote:

Rudy Velthuis (TeamB) wrote:

Apparently not. This surprises me a bit. But note that the string is
stored in the executable already, so there is no need to repeat it.

The string is part of a tamper-protection scheme. I need the exact
same string to be inside an assembler function and also to be
accessible (read access) in a separate Delphi function. So it would
be nice if I could store it only once as a CONST instead of having to
repeat it.


You can store the string as a const, but not as DB. But there is no
need for the latter anyway.

--
Rudy Velthuis http://www.rvelthuis.de

Weiler's Law: Nothing is impossible for the man who doesn't have
to do the work.
Arthur Hoornweg

Posts: 414
Registered: 6/2/98
Re: "db" a string constant in assembler?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 22, 2016 7:04 AM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) wrote:

You can store the string as a const, but not as DB. But there is no
need for the latter anyway.

There is. It is part of a tamper protection scheme. The string inside the ASM section is a marker. A helper program scans the freshly compiled executable on disk for this marker and writes a hash of the executable (minus the marker) into the executable, into a record which is located at a certain offset after this marker. After performing the hash, I use signtool to sign and timestamp the code twice (first with SHA1 then with SHA2). At runtime, the program can do a very fast integrity check and knows if it has been tampered with or not.

The silly thing is that I have to hardwire the marker string in the helper program as well as in the tamper decoding logic. It would be much more elegant if both programs could just share it as a CONST.
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: "db" a string constant in assembler?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 5, 2016 6:47 AM   in response to: Arthur Hoornweg in response to: Arthur Hoornweg
Arthur Hoornweg wrote:

Rudy Velthuis (TeamB) wrote:

You can store the string as a const, but not as DB. But there is no
need for the latter anyway.

There is. It is part of a tamper protection scheme. The string inside
the ASM section is a marker. A helper program scans the freshly
compiled executable on disk for this marker and writes a hash of the
executable (minus the marker) into the executable, into a record
which is located at a certain offset after this marker.

Make it a (const) record. Do not use a DB for this. The constant string
will be in the executable too.

--
Rudy Velthuis http://www.rvelthuis.de

"... Somehow we find it hard to sell our values, namely that
the rich should plunder the poor."
-- John Foster Dulles
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02