Solved

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

Posted on 2003-10-22
4
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

705 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