News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Self incrementing Counter info

Started by skywalker, March 02, 2006, 12:43:49 AM

Previous topic - Next topic

skywalker

Is it possible to have a self-incrementing counter inside a program? (Would store a value each time prog is run.)

Is that what code injection is that I have seen ?

Thanks.

hutch--

Andy,

The problem is storing the data somewhere. In the old days of DOS you wrote the result back to the exe file but under win32 this cannot be done. Most go for a registry setting or writing the data to a file somewhere but neither are secure.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

asmfan

i've just come an idea: using for storing counter resources. Imagine each time U execute the program it updates its resources from itself (BeginUpdateResource, UpdateResource...)
tell me what do you think about it.
Russia is a weird place

PBrennick

I would just use a .ini file, you can use ReadProfileString and WriteProfileString to do this in win.ini, create your own section and do it there.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

skywalker

Quote from: PBrennick on March 04, 2006, 08:02:13 PM
I would just use a .ini file, you can use ReadProfileString and WriteProfileString to do this in win.ini, create your own section and do it there.

Paul

So could you put your own section in the middle somewhere?

I can't find either function iin the APIs.


donkey

GetProfileString and WriteProfileString, Microsoft has some bizzare naming conventions could have been Get/Set or Read/Write but they choose Get/Write ??? You should know that if you're running NT/2K/XP it just gets mapped to the registry anyway so it isn't really hiding it too well.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

PBrennick

Donkey,
Ah, why are we bothering to hide a use counter.  Maybe I just don't get it but this is no big deal.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

donkey

I guess I should also suggest SHSetValue and SHGetValue, two great little APIs from SHLWAPI.DLL, when you're only dealing with one simple value they are great for storing and reading from the registry. If I was doing this type of thing I would write an encrypted key the registry with the current count, that way it's harder to change, they could just delete it though but if you're sneaky about naming it they might never find it. Say...

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.zxr\

Not many people even know what those keys are for. If you'd like to know about them I use them in WinExplorer, they hold the openswith information for each extension. Since .zxr is not like to exist it's not a problem  :)
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

donkey

Quote from: PBrennick on March 05, 2006, 02:35:14 AM
Donkey,
Ah, why are we bothering to hide a use counter.  Maybe I just don't get it but this is no big deal.

Paul


There is no other reason I can see to have a run counter other than for software expiry, other than that I haven't the foggiest idea why it could possibly be useful. I guess I just assumed that's what he was trying to do, re-reading the posts I think I might be mistaken.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

PBrennick

Donkey,
Maybe not, your thoughts are logical.  Expiry did not even occur to me.  I bet you are right.  This type of thing CAN be done in the file but share must be running on the target and that is just to easy to defeat.  If the user closes share.exe and removes it from the system  then UnlockRegion will not work (I don't think).

Paul
The GeneSys Project is available from:
The Repository or My crappy website

rags

Quote from: donkey on March 05, 2006, 02:26:27 AM
You should know that if you're running NT/2K/XP it just gets mapped to the registry anyway so it isn't really hiding it too well.
Donkey,
Maybe I'm reading the SDK wrong, but I read it as saying if the specified ini file doesn't have a subkey in-
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping
Then all reading and writing would be to the disk, and not the registry.
Am I correct in my understanding of get/write profie string?

God made Man, but the monkey applied the glue -DEVO

donkey

Quote from: rags on March 05, 2006, 03:44:00 AM
Donkey,
Maybe I'm reading the SDK wrong, but I read it as saying if the specified ini file doesn't have a subkey in-
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping
Then all reading and writing would be to the disk, and not the registry.
Am I correct in my understanding of get/write profie string?

I was going by this...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/writeprofilestring.asp

QuoteIf the section name specified by lpAppName does not exist as a named value or as a subkey, then there will be an unnamed value (shown as <No Name>) that specifies the default location in the registry where you will find the keys for the section.

Don't really use INI files at all any more, the registry is just too convenient and easy to use, also I like customizable toolbars so I have to create a subkey anyway. Never really liked INI files though they have their place I guess, I think I used one for the favourites menu in a RadASM add-in I wrote.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

PBrennick

I think the fact that Windows, itself, still uses INI files speaks for itself.  Remember that the registry, as a file can be compared to as a very large INI file.  Also, the registry is the most frequently written to file on the system.  It is a shared file that gets simultaneous writes on a constant basis and as such, it is the least stable file on the system.  I think that is why Windows still uses INI files in some situations.  I also use the registry frequently but some tasks, to me, just make more sense in an INI file and expiry is at the top of the list here because to defeat it if the registry is used all a user has to do is set a restore point.  Remember that and think about it and in general realize what the purpose of restore points is.  Windows will use this method to recover from registry crashes (caused by the share situation).  At times, a lot of times it just falls over and dies and it happens SO often that restore points technology had to be created.  I know that restore points are also useful for testing software, also, but expiry is the issue here, remember what I said and do not use the registry for this purpose.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

skywalker

Quote from: donkey on March 05, 2006, 02:26:27 AM
GetProfileString and WriteProfileString, Microsoft has some bizzare naming conventions could have been Get/Set or Read/Write but they choose Get/Write ??? You should know that if you're running NT/2K/XP it just gets mapped to the registry anyway so it isn't really hiding it too well.

Can you help us ? If you don't feel confortable showing how to adding a section to win.ini, how about making a new ini file ?

Thanks.




zcoder

If you just need some kind of a file to
use only for your program, then why use
GetProfileString and WriteProfileString?

just make a Structure

MY_DATA STRUCT
mydata1     DWORD
mydata2     DWORD
mystring    MAX_PATH dup()
MY_DATA ENDS

Then fill in the items and sore the STRUCTURE as a file
this way when you read the file back into the structure
you don't have to convert any shit or invoke other API's
just to get to some info you need.


Just a sugestion.


Zcoder....
Back in 1979, My computer ran so fine.
And there was no such thing,
As a Microsoft Crashed Machine.
http://zcoder.110mb.com
http://www.dietzel.com/partner/idevaffiliate.php?id=345_6  Free Domain Names