Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1]   Go Down

Author Topic: Grabing resources off a program  (Read 1733 times)

thirdbanana

  • 8 MB
  • **
  • Posts: 14
Grabing resources off a program
« on: October 10, 2024, 07:49:11 PM »

Long time ago, I wrote a program in Think C (hence my question in another thread), which I recently found, or at least some fragments. And a compiled version of the code. If I want to compile the code again, I will need the graphics and sound resources; can I fetch them off the executable file (i.e. program) using resedit or something like that?
Logged

Knezzen

  • Staff Member
  • 1024 MB
  • ******
  • Posts: 1261
  • Pro Tools Addict!
    • Macintosh Garden
Re: Grabing resources off a program
« Reply #1 on: October 10, 2024, 10:30:59 PM »

Yeah, that works for sure.
Logged
Pro Tools addict and staff member at Mac OS 9 Lives!, System 7 Today and Macintosh Garden.

Bolkonskij

  • Staff Member
  • 256 MB
  • *****
  • Posts: 297
    • Cornica.org
Re: Grabing resources off a program
« Reply #2 on: October 11, 2024, 05:39:18 AM »

If you added them via ResEdit before, you should be able to open up your resource file and get them out again. Also, while I don't remember any name, there's little applications that do that for you as well. You may want to check the Macintosh Garden for them, they're definitely there.
Logged

thirdbanana

  • 8 MB
  • **
  • Posts: 14
Re: Grabing resources off a program
« Reply #3 on: October 11, 2024, 10:15:01 AM »

If you added them via ResEdit before, you should be able to open up your resource file and get them out again. Also, while I don't remember any name, there's little applications that do that for you as well. You may want to check the Macintosh Garden for them, they're definitely there.

I am not sure; I know I used Think C 5.0 (I actually wrote in the code when I bought it, as it required some changes). I do not remember how the resources were fed: I want to say they were in a separate file which was then added into the binary somehow. Being able to save the resources will help a lot: while I have the original image file (before the different bits were cropped and added as individual components), the floppy I found was not the one I used to build it, so it has some missing files namely the resource and the header file. There is also a programname.mac file which I have no idea of what it is supposed to do.

My plan now is to get it such that it will successfully compile in Think C 5 (which I hope runs in OS9). Then I can decide if I want to switch to codewarrior or whatever, and clean the code some.  :-[
Logged

Bolkonskij

  • Staff Member
  • 256 MB
  • *****
  • Posts: 297
    • Cornica.org
Re: Grabing resources off a program
« Reply #4 on: October 12, 2024, 01:16:26 AM »

Traditionally, when programming the Mac, you would have created an empty resource file and then manually added your resources (pictures, sounds, windows, menu bars, constants etc.) to it which you'd later reference in code. So, in theory, you just need to fire up ResEdit and open the resource file located somewhere in the source folder. From there, you should be able to copy + paste stuff to where you need it. (provided the resource file actually IS in the sources folder)

As for other options, I've run into this application here on Garden:

http://macintoshgarden.org/apps/37thresex

It might do the trick for you, but I have no experience using it myself!
« Last Edit: October 12, 2024, 03:08:05 AM by Bolkonskij »
Logged

ssp3

  • 512 MB
  • *****
  • Posts: 925
Re: Grabing resources off a program
« Reply #5 on: October 12, 2024, 08:14:43 AM »

As for other options, I've run into this application here on Garden:

http://macintoshgarden.org/apps/37thresex

It might do the trick for you, but I have no experience using it myself!

Kagi and serial numbers. Eek!
Nothing comes close to the ResEdit.
Logged
If you're not part of the solution, you're part of the problem.

joevt

  • 64 MB
  • ****
  • Posts: 105
  • New Member
Re: Grabing resources off a program
« Reply #6 on: October 12, 2024, 11:56:09 AM »

Nothing comes close to the ResEdit.
I think Resorcerer has better templates and editors than ResEdit.
It has other features such as being able to look at the ROM resources.
Logged

robespierre

  • 128 MB
  • ****
  • Posts: 156
  • malfrat des logiciels
Re: Grabing resources off a program
« Reply #7 on: October 12, 2024, 12:43:17 PM »

When using MPW to do traditional Mac development, the tools called "Rez" and "DeRez" were used in a build script to add resources to an application. The source for the resources were in files with names ending with ".r", which were regular text files.

Lightspeed/THINK C usually used a file ending in ".rsrc" instead, which got merged with the application during the build phase. In this case you would use ResEdit or Resorcerer to create the resources using their templates.
Logged

ssp3

  • 512 MB
  • *****
  • Posts: 925
Re: Grabing resources off a program
« Reply #8 on: October 12, 2024, 01:32:39 PM »

I think Resorcerer has better templates and editors than ResEdit.
It has other features such as being able to look at the ROM resources.

Of course it does, but it wasn't free, like ResEdit. (I know, I know  ;) )
Logged
If you're not part of the solution, you're part of the problem.

thirdbanana

  • 8 MB
  • **
  • Posts: 14
Re: Grabing resources off a program
« Reply #9 on: October 16, 2024, 02:40:44 AM »

Lightspeed/THINK C usually used a file ending in ".rsrc" instead, which got merged with the application during the build phase. In this case you would use ResEdit or Resorcerer to create the resources using their templates.

Is the ".rsrc" file just the file created in ResEdit with the resources needed by the program? And shouldn't it be added to the project file? I found at the Macintosh Garden the book "Macintosh_C_Programming_Primer_1992.pdf," which is the one I bought (found it in a box but the pdf is more convenient right now), but had not reached the section on building a proper Mac program yet.

Funny you mentioned Lightspeed C; I did have it (v 2.somehing?) before I bought Think C 5.
Logged

sentient06

  • 8 MB
  • **
  • Posts: 11
Re: Grabing resources off a program
« Reply #10 on: December 04, 2024, 03:58:21 AM »

I would try DeRez.

Steps:

1. Install MPW. (I put mine on the Applications folder;)
2. Open the MPW Shell;
3. Delete everything and type this:

Code: [Select]
DeRez -i "Macintosh:Applications:MPW-GM:Interfaces & Libraries:Interfaces:RIncludes:" "Macintosh:Desktop Folder:MyApp" Carbon.r -s CODE -s DATA -s RELA > "Macintosh:Desktop Folder:MyApp.txt"

Make sure it's a single line, then position the cursor at the end and hit ⌘+Return.

Now, you can see a file will be created on your desktop. It's a text file with a creator type set to MPW. You can modify that with the FileType app or even MPW itself, or just drag into SimpleText.

Notice how we're skipping the resource types for "CODE", "DATA" and "RELA". They export a bunch of encoded stuff you probably don't care about. If you do, just don't exclude it. Removing the stuff after, and including the ">" sign will output the stuff to the shell.

You can put the new resource code into a file with the ".r" extension. If you use an IDE like CodeWarrior, there should be an option to run server tools there, and you can use it to re-encode this into an .rsrc file to be used by your project. Then you can manually change stuff on ResEdit.

Is the ".rsrc" file just the file created in ResEdit with the resources needed by the program? And shouldn't it be added to the project file?

Yes, the ".rsrc" is a file made by ResEdit. When programming with the help of resources, we make a file like that and set a bunch of data we replicate in the code. Stuff like window IDs. You can add a bunch of windows and id them with numbers like 128, 129, 130, etc, then declare those numbers as constants in your code. When your compiler links all the files, it picks up the ".rsrc" file and merges into the final executable.

But using graphical interface apps like ResEdit is not very good for versioning code, so Apple invented this C-like syntax to describe the resources instead. We use these tools Rez and DeRez to transform the stuff from code to ".rsrc" and back again. Rez compiles the code into ".rsrc" and DeRez decompiles it.

MPW is the toolset that Apple provided for developers that contains these tools. They can be used by other IDEs via a thing called a Tool Server. On CodeWarrior, for example, you need to link a folder from MPW inside CodeWarrior's folder, so it can find these tools. Then, in your project, you drop the ".r" file with the resource code, and spin up the server. Then you can select Rez and it shows you a GUI with options, so you don't have to poke about with a shell like we did on MPW in my above example. It then creates the ".rsrc" for you by encoding it with Rez.

The step-by-step I provided above is for using MPW to manually extract the resources code that would be in an ".r" file. It's an easy way of copying the resources from any file.
« Last Edit: December 05, 2024, 06:55:05 AM by sentient06 »
Logged

IIO

  • Staff Member
  • 4096 MB
  • *******
  • Posts: 4671
  • just a number
Re: Grabing resources off a program
« Reply #11 on: December 04, 2024, 02:41:09 PM »

37thresex
canopener
...

of course none of them can explode all resource types at once, writing them into files... while preserving the type and ID in some way...
Logged
insert arbitrary signature here

joevt

  • 64 MB
  • ****
  • Posts: 105
  • New Member
Re: Grabing resources off a program
« Reply #12 on: December 05, 2024, 12:06:51 AM »

I would try DeRez.
Code: [Select]
DeRez -1 "Macintosh:Applications:MPW-GM:Interfaces & Libraries:Interfaces:RIncludes:" "Macintosh:Desktop Folder:MyApp" Carbon.r -s CODE -s DATA -s RELA > "Macintosh:Desktop Folder:MyApp.txt"
I think the -1 should be -i

If there are resources that have a definition in RIncludes but are not included by Carbon.r, then you'll want to add those other .r files. You may want to create your own .r file for custom resource types.

Rez and DeRez also exist in modern macOS as standalone commands so you don't need MPW at all (except for the RIncludes folder). I think it's an Xcode command line tool?
Code: [Select]
command -v DeRez
/usr/bin/DeRez

MPW commands can be executed in modern macOS. It uses emulation so it's not as fast as the native standalone commands.
 https://github.com/ksherlock/mpw

DeRez uses MacRoman encoding. The copyright character (ASCII 0xA9) for your app's version string should appear as ©. MPW's DeRez may show ASCII 0x09 as ∆ and ASCII 0x0D as ¬ in the hex dumps but Mac OS X's DeRez command shows them as period (.)

The emulated mpw and the Mac OS X DeRez will output unix line feeds (ASCII 0x10).
Classic MPW will output carriage returns (ASCII 0x0D).
Logged

ssp3

  • 512 MB
  • *****
  • Posts: 925
Re: Grabing resources off a program
« Reply #13 on: December 05, 2024, 01:31:15 AM »

Rez and DeRez also exist in modern macOS as standalone commands so you don't need MPW at all (except for the RIncludes folder). I think it's an Xcode command line tool?

Yep. This is on 10.10.5
Code: [Select]
### /Library/Developer/CommandLineTools/usr/bin/Rez - Usage: /Library/Developer/CommandLineTools/usr/bin/Rez [-a] [-al word | longword] [-arch arch] [-c creator] [-d name[=value]] [-i path] [-isysroot path] [-F framework] [-m] [-noResolve [output | include]] [-o file] [-ov] [-p] [-rd] [-ro] [-s path] [-sc script] [-t type] [-u name] [-useDF] [file...].
Code: [Select]
### /Library/Developer/CommandLineTools/usr/bin/DeRez - No filename to de-compile was specified.
### /Library/Developer/CommandLineTools/usr/bin/DeRez - Usage: /Library/Developer/CommandLineTools/usr/bin/DeRez resourceFile [-c] [-d name[=value]] [-e] [-i path] [-isysroot path] [-m n] [-noResolve [output | include]] [-only type[(id[:id])]] [-p] [-rd] [-s type[(id[:id])]] [-sc script] [-u name] [-useDF] [file...].
Logged
If you're not part of the solution, you're part of the problem.

sentient06

  • 8 MB
  • **
  • Posts: 11
Re: Grabing resources off a program
« Reply #14 on: December 05, 2024, 05:00:09 AM »

I think the -1 should be -i

You are correct. I copied from the emulator via screenshot and Preview messed up the character. I fixed the original text. Good spot!

If there are resources that have a definition in RIncludes but are not included by Carbon.r, then you'll want to add those other .r files. You may want to create your own .r file for custom resource types.

Yes. But, you know, it's best to start somewhere. Maybe the main resources are enough? I don't know.

MPW commands can be executed in modern macOS. It uses emulation so it's not as fast as the native standalone commands.

Correct again. DeRez is available in macOS 15. But you need to point to some SDK files, and I suspect that the latest versions don't contain the same content they did in previous versions of modern Mac OS. In 10.6 or so one would do something like this...

Code: [Select]
DeRez -isysroot `xcrun --sdk macosx --show-sdk-path` file.rsrc Carbon.r

... to correctly parse the .r bits. I couldn't do it on macOS 15. But then, I didn't try too hard, maybe there's a way. (Maybe if one downloads an older SDK and uses that in the command line?)

But, I think that, if you can DeRez a file into .r even on a modern Mac OS and even without the parsing - i.e. it looks like a lot of hexadecimals and encoded content - it would still be possible to grab that file, toss into Mac OS 9 and re-encode into an .rsrc stand-alone file. I haven't tried it, but I reckon it's doable.

Oh, modern apps like Sublime Text can save a file with different line endings, including classic Mac OS.
« Last Edit: December 05, 2024, 07:11:22 AM by sentient06 »
Logged

joevt

  • 64 MB
  • ****
  • Posts: 105
  • New Member
Re: Grabing resources off a program
« Reply #15 on: December 05, 2024, 05:17:54 PM »

Mac OS X SDKs do contain .r files in some of the frameworks. It might not have all the .r files that MPW Universal Interfaces has. I haven't compared the set of .r files in each.
Code: [Select]
find -L $(xcrun --sdk macosx --show-sdk-path) -name '*.r'

Setting -isysroot to the SDK does seem to work as you described (tested in Monterey, should work in Sequoia).

The real sysroot "/" contains frameworks without .r files (/System/Library/Frameworks).

I use $( ) in Mac OS X instead of ` ` because it can be more easily nested.
Logged
Pages: [1]   Go Up

Recent Topics