Solved

how To edit exe to insert a serial no wich can be usd by runing exe

Posted on 2003-10-22
4
240 Views
Last Modified: 2013-12-26
At time of installation I have to open the resource. and i have to insert a string serial number in the exe.
please provide me code to edit the exe (in solaris) to insert a serial number which can be used by exe at run time. please help

0
Comment
Question by:ssahu
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 225 total points
ID: 9612225
/* serialnum.c
 *
 * Rewrite serial number in a file.  This should be called as such:
 *   strings -o filename | grep serialnumberflag | serialnum filename serialnumber
 *
 * the serialnumberflag is a string embedded in the file at the position where the serial number
 * will be written.  serialnumberflag must be at least as long a the eventual serial number.
 * serialnumberflag must not contain whitespace.
 *
 * For instance the executable file "exefile" could have the following line in its source code:
 *    char serialnum[] = "The_serial_number_will_go_here";
 *
 * then the patch would occur as follows:
 *   strings -o exefile | grep "The_serial_number_will_go_here"| serialnum exefile "1456 FJCH 0013 ABCD"
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

int main (int argc, char ** argv)
{
  unsigned len;
  int fd = -1;
  long offset = -1L;
  long roffset = -1L;
  char serialtag[1024];

  if (argc < 3) {
    printf("usage: %s filename serialnum\n", argv[0]);
    return (-1);
  }

  /* open the executable file to modify */
  if ((fd = open(argv[1], O_RDWR)) == -1) {
    perror("could not open executable file");
    return (-2);
  }

  /* read the serialnumber tag string and is offset as output of strings -o */
  if (scanf("%ld %1000s", &offset, serialtag) < 2) {
    printf("could not parse serialtag offset\n");
    return (-3);
  }
  printf("offset = %ld    tag = %s\n", offset, serialtag);

  /* make sure the serialnumber tag in the file is large enough to hold the serial number */
  if ((len = strlen(argv[2])) > strlen(serialtag)) {
    printf("serial number too long for reserved space in file.\n");
    return (-4);
  }

  /* seek to the appropriate location in the file and write out the serial number string */
  if ((roffset = lseek(fd, offset, SEEK_SET)) != offset) {
    printf("seek into execuable file failed - %ld", roffset);
    return (-5);
  }

  /* write out the new serial number string */
  if (write(fd, argv[2], len+1) < (int)(len+1)) {
    perror("failed to write serial number into execuable file");
    return (-6);
  }

  if (close(fd)) {
    perror("failed to close executable file");
    return (-7);
  }

  return (0);
}

0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 9612236
You can remove the line (for debugging):
 printf("offset = %ld    tag = %s\n", offset, serialtag);

0
 
LVL 18

Expert Comment

by:liddler
ID: 10191536
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by  brettmjohnson

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

liddler
EE Cleanup Volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now