IDA Pro: How to change the virtual segment register T in a script - ida

If I press option/alt-G, IDA shows a dialog which allows me to change the value of the T segment register to 1 to indicate that the following bytes should be interpreted a Thumb code.
I would like to be able to change the value of T in a script.
What script function can I use?

Try
SetRegEx(addr,"T",val,SR_user);
I found this by doing it manually, then clicking File | Produce file | Dump Database to IDC file.. and reading the commands used at the manual process location above.
Then read your idc.idc files to for the syntax of the above command.

Related

WinDbg scripting - how to delete a file?

I'm working with an existing framework of WinDbg scripts that go through a series of test scripts Test1.txt, Test2.txt, etc., which are generated by C++ code and which output results.
For example a chunk of one of the test scripts would be,
.if (($spat(#"${var}","18300.000000")==1))
{
.logappend C:\Tests\TestResults.txt
.printf "TestNumber=\t1\tExpected=\t18300.000000\tActual=\t%.6f\t******PASSED******\n",poi(poi(#$t2+#$t6)+0x10)
.logclose
}
I'm trying to add functionality that will create a file whose name displays the current # of the test being run, so that users can see their progress without needing to open a file.
My thought process was that I would set up the script generator, so that at the start of Test #N, it would add a line to the script to create a file 'currentlyRunningTestN.txt', and at the end of Test #N, it would add a line to the script to delete that file. However, I don't see any delete function in the WinDbg meta command glossary: https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/meta-commands, or in the list of supported C functions like printf. Am I just missing something, or is deleting files not supported by WinDbg (or equivalently renaming files, which would also serve my purpose?) If deleting/renaming don't work, is there another way to achieve the functionality I'm looking for?
With the .shell command, you can execute any DOS-like command. Although I never tried deleting a file, it should be possible.
As you may have noticed, WinDbg scripting does not always work on first attempt, please make sure your scripting will not result in a big data loss on your customer's PC whilst deleting files.

How to access previously run commands in MATLAB

I saved my command line by first clicking on it and pressing ctrl+s and MATLAB saves a .mat file.
Now I want to open it in a text form in order to remember what I did in my command line the other day.
Is there a way to do that?
Saving a .mat file from the command window saves all of the variables that currently exist within your workspace within a binary .mat file. There is no information about the commands that were used to generate these variables in this file format therefore it cannot be automatically extracted from another program.
If you need to get information about what commands were run, you can look at your command history to see this. If you need to programmatically access this file you can look in MATLAB's preference directory for the file named history.m or history.xml on newer versions.
type(fullfile(prefdir, 'history.m'))
If you need to keep track of what commands you run in the future, you can use diary at the top of your script or beginning of your session to log all commands and associated command line output to a plain-text log file which would then be accessible to other programs.
diary('mylogfile.txt')

How to send a command line command multiple times

I have been working on a project that uses a program called TeraTerm to send commands to a TV via a serial port. I have discovered that when I open the program manually after a reboot, I have to open the correct port and then send the .dat command file several times before it actually takes (Turns off the TV).
The commands I am using are from this page.
Anyway, I ran the command
TTERMPRO /C=7 /DS /FD=C:\Commands\TurnOffTest3.dat /FD=C:\Commands\TurnOffTest3.dat /FD=C:\Commands\TurnOffTest3.dat
hoping that it would allow me to send the file multiple times. The TeraTerm window did open as usual, but the file was either not sent or had no effect.
There is a very high likelyhood that I am sending the commands incorrectly, as I am very new to the command prompt itself. Is there a way that I can call the command to send a file multiple times? If I am not interpreting the interface given on the website correctly or even if the way I am using the commands is just flat out wrong, any and all advice is welcome.
Side note: yes, I am sure that the command file that I am sending is the correct one because when I send the file manually (i. e. use the GUI) the TV turns off as expected.
EDIT: I have tried sending the file with and without quotes in its name.
for /L %G in (1,1,3) do TTERMPRO …
Read more in FOR command:
If you are using the FOR command at the command line rather than
in a batch program, use just one percent sign: %G instead of
%%G.
Noticed in help information about system commands for /? as well: To use the FOR command in a batch program, specify %%variable instead of %variable. Variable names are case sensitive, so %i is different from %I.
==> for /?
Runs a specified command for each file in a set of files.
FOR %variable IN (set) DO command [command-parameters]
%variable Specifies a single letter replaceable parameter.
(set) Specifies a set of one or more files. Wildcards may be used.
command Specifies the command to carry out for each file.
command-parameters
Specifies parameters or switches for the specified command.
To use the FOR command in a batch program, specify %%variable instead
of %variable. Variable names are case sensitive, so %i is different
from %I.
…
Further reading in Syntax: Escape Characters, Delimiters and Quotes

ipython rolling log

I want to have last 500Mb worth of ipython input and output saved to a file
The saving described above should be able to get around instances when I have to kill ipython. For example, saving based on a timer
I want to have this file reloaded (not re-executed) at startup. The file then gets updated in a rolling fashion
How can I achieve this?
IPython already logs your input - it's stored in history.sqlite in your profile folder (run ipython locate profile to see where that is). To turn on output logging as well, edit ipython_config.py and search for 'db_log_output'. This captures output resulting from the displayhook (with the Out [n]: prompt), not printed output.
To look at history from a previous session, you can use %hist ~1/1-10 (lines 1-10 of the session before the current one). It also works with magic commands like %rerun, %recall and %save.
If you want it recorded to a text file, have a look at the %logstart magic.

Doxygen command line - error handling

I use Doxygen in command line mode(via a batch file scheduled to run at certain time) for generating code documentation.
I supply it with a Doxyfile that has all the settings.
And it overwrites the previously generated documentation for same code.
My problem is, the input location name may change at some time.
So, in the log, doxygen shows that it cannot find ONE of the input locations.
What my aim is that the documentation should be generated/overwritten ONLY IF there is NO ERROR.
There are three possible solutions in my mind(in the order of decreasing convenience):
Interrupt docs generation in case of ANY error.
If its not possible to interrupt the docs generation, I can generate docs in some other place and then replace older ones using simple move command in batch file IF Doxygen has not thrown any errors. For this, I will somehow have to get hold of Doxygen errors in batch file runtime.
Save docs to different folder, save log to txt, scan txt in batch for errors(This, I can do but prefer avoiding)
So, is there any way I can get hold of this error while running Doxygen via batch file?