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
Solved

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

Posted on 2003-10-22
4
242 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 67
Looking for a specific application/software 2 114
zeroMAx challenge 20 111
Problem to event 3 102
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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