EDN Admin
Well-known member
I have following code.<br/>
I got it from https://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=3810&lngWId=3<br/>
I modified it in following code.<br/>
<br/>
To lock exe it write 0xcd and 0x20 at first two byte.<br/>
First two bytes are for what?<br/>
What are the valid values for that?
<pre class="prettyprint void Lock(wchar_t * fn)
{
char * fname = wcharToChar(fn);
FILE *fd;
unsigned char buffer[3];
_chmod(fname, _S_IWRITE);
fd=fopen(fname,"rb+");
if(fd==NULL)
{
printf("nCannt open %sn",fname);
system("pause");
exit(2);
}
fseek(fd,0,SEEK_SET);
fread(buffer,2,1,fd);
if(buffer[0] == 0xcd && buffer[1] == 0x20)
{
fclose(fd);
printf("n%s already protected...n",fname);
system("pause");
exit(2);
}
fseek(fd,0,SEEK_END);
fwrite(buffer,2,1,fd);
fseek(fd,0,SEEK_SET);
buffer[0] = 0xcd;
buffer[1] = 0x20;
fwrite(buffer,2,1,fd);
fclose(fd);
}[/code]
<br/>
View the full article
I got it from https://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=3810&lngWId=3<br/>
I modified it in following code.<br/>
<br/>
To lock exe it write 0xcd and 0x20 at first two byte.<br/>
First two bytes are for what?<br/>
What are the valid values for that?
<pre class="prettyprint void Lock(wchar_t * fn)
{
char * fname = wcharToChar(fn);
FILE *fd;
unsigned char buffer[3];
_chmod(fname, _S_IWRITE);
fd=fopen(fname,"rb+");
if(fd==NULL)
{
printf("nCannt open %sn",fname);
system("pause");
exit(2);
}
fseek(fd,0,SEEK_SET);
fread(buffer,2,1,fd);
if(buffer[0] == 0xcd && buffer[1] == 0x20)
{
fclose(fd);
printf("n%s already protected...n",fname);
system("pause");
exit(2);
}
fseek(fd,0,SEEK_END);
fwrite(buffer,2,1,fd);
fseek(fd,0,SEEK_SET);
buffer[0] = 0xcd;
buffer[1] = 0x20;
fwrite(buffer,2,1,fd);
fclose(fd);
}[/code]
<br/>
View the full article