Complete list of paste operation constraints? - copy-paste

I've programmed for quite a long time - yet I never knew, until today - that folders can't be pasted into themselves.
I found this out in a rather unpleasant way - in my application (we're working on a file browsing app), when I pasted the folder into itself - it caused a segmentation fault (infinite recursion).
02-22 04:01:35.186: A/libc(786): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 786 (explorermanager)
My question is: are there any other paste constraints I should be aware of and are also appliable to most platforms?

On Win32 you can indeed copy a directory into itself. However if it is not put within a sub-directory it will simply overwrite existing files.
NOTE: For large directories this solution WILL take a little time.
// Make sure to link default lib "Shell32.lib"
#include <Windows.h>
#include <Shellapi.h>
int main() {
SHFILEOPSTRUCT hFileS = { 0 };
hFileS.hwnd = NULL;
hFileS.wFunc = FO_COPY;
hFileS.fFlags = FOF_SILENT;
hFileS.pTo = "C:\\DevkitPro\\TEST\0"; // Put into sub-dir TEST
hFileS.pFrom = "C:\\DevkitPro\\*\0";
SHFileOperation(&hFileS);
return 0;
}
Hopefully this helps (if you are using Windows)...
On MSDN:
http://msdn2.microsoft.com/en-us/library/ms647743.aspx

Related

Program compiles but doesn't do anything

I've recently started exploring and reading about Microchip's PIC32 MCUs, most specifically for motor control. I had some job done over the years but was a long while and haven't used the IDE with evaluation board since university years. Been using Arduino-compatible boards since or boards, compatible with the Arduino IDE.
So I'm running MPLAB X IDE v6.05 with the latest XC32 Compiler.
My Development board is DT100113 Curiosity Pro board, utilizing PIC32MK0512MCJ064 MCU and an on-board PicKit4 (PKoB4) for programming/debugging/serial connection purposes.
What I try to do is light up the two user LEDs on pins RA10 and RE13 respectively.
As I begin with creating new project, select my device, my program/debug tool and give my project a name, next step is to create a new main.c file.
I create the file and write the following:
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
int main(int argc, char** argv) {
//Define corresponding port bits as outputs (0 = output, 1 = input).
TRISAbits.TRISA10 = 0;
TRISEbits.TRISE13 = 0;
//Latch the outputs to HIGH (1) and hold.
while(1)
{
LATAbits.LATA10 = 1;
LATEbits.LATE13 = 1;
}
return (EXIT_SUCCESS);
}
When I build and run it - nothing happens. Build is successful, connected to programmer, erase/flash device OK, but nothing with the LEDs.
I think I'm missing the #pragma directives (read about that it must be defined first prior anything else), but am unaware on how to set configuration bits (used peripherals, internal clock speed, etc.).
Any pointers to how-to articles, posts, etc. will be highly appreciated. I was not able to find step-by-step tutorial for my development board so far :((
Thank you in advance!
Cheers,
Iliyan
I tried creating a new project, it compiled and ran, but the LEDs were not lit.
Obviously was missing some vital parts in the code.
Application software examples and driver libraries are included as part of the MPLAB Harmony V3 Framework. Add Harmony to 'Embedded' under the 'Tools' tab of the MPLAB IDE.

Finding frameworks being linked to a project in Xcode

I saw this question: How can I programatically get the list of frameworks and libraries included in an ios project? here, which tries to answer similar question. However, I've two questions on this
The answer in above link (or see code below) - does it provide all frameworks or "only" frameworks that are linked to the project.
for (NSBundle *framework in [NSBundle allFrameworks])
NSLog(#"%#",framework.bundlePath.lastPathComponent);
if I see a framework appearing in above code, how can I find its usage in my code. I see many frameworks being referred to in above code, but I'm not able to figure out where exactly are they used. As per my knowledge, few of them are not used - is there a proper way to find this out.
Update 1:
I made a simple new app with absolutely no code in it. Then, I executed the for loop above and found that, it also presented me with all the frameworks - which means, the code above simply prints all the frameworks and not the one that I am essentially be using in my app. But, does it mean that all frameworks that are printed are linked to the app?
The dynamic loader dyld(3) provides this information. This code will print all loaded frameworks and shared libraries as well:
#include <stdio.h>
#include <dlfcn.h>
#include <mach-o/dyld.h>
int main() {
uint32_t c = _dyld_image_count();
for(uint32_t i = 0; i < c; ++i) {
printf("%d: %s\n", i, _dyld_get_image_name(i));
}
return 0;
}
EDIT: allFrameworks lists only frameworks which are linked to your app, and which contain at least one Objective-C class (see https://developer.apple.com/documentation/foundation/nsbundle/1408056-allframeworks).
Searching for referrers is should be very difficult in general. If you are just looking for a single function, you can add a static implementation of the function and call the loaded variant from it. This technique is used for overwriting __cxa_throw for instance, but it should also work for other functions:
static cxa_throw_t sCxa_throw = 0;
extern "C" void __cxa_throw(void *inException, void *inPvtinfo, void (*inDestination)(void *)) {
if (sCxa_throw == NULL) {
sCxa_throw = (cxa_throw_t)dlsym(RTLD_NEXT, "__cxa_throw");
}
sCxa_throw(inException, inPvtinfo, inDestination);
}
The variable sCXA_throw contains the reference to the dynamic version of this function while the loader uses the static version. Inside of this function you can determine the callers with unwinding the stack with libunwind.

How to trace back #pragma pack?

I've been wrestling with an issue in iOS causing improper allocation, getting less memory back from malloc than I should have for a CPP object. I recently discovered it was due to two translation units including the same header, one of which along its include chain had a few occurrences of #pragma pack.
Now, I'm not sure how to properly trace back to whichever file is using it and ensure that it fixes it. I've added a bunch of #pragma pack(show) and have nailed down the offending file from the top (the offending file being the file that causes others files to have the same pack setting of 1). I've opened that file in Xcode and run preprocess on it.
In most cases, it looks like code is setting pack back to default (8 on arm64). Are there any tools that can help verify which is the offender along the chain?
The only tip that I have (a case of a pack 1, which is what the pack was being set to), is a header from the iOS SDK. But even it looks to be ok.
# 54 "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/usr/include/sys/kauth.h" 2 3 4
#pragma pack(1)
typedef struct {
u_int8_t sid_kind;
u_int8_t sid_authcount;
u_int8_t sid_authority[6];
u_int32_t sid_authorities[16];
} ntsid_t;
#pragma pack()
As I mentioned, when searching through the preprocessed source file, I wasn't able to find any instance of #pragma pack that wasn't undoing its setting shortly after. However, I wasn't aware that there was another way to set packing, via #pragma options align=(packed|reset). It turns out that it wasn't being undone, but I was looking for #pragma pack.

Simple method call in Xcode 5 and passed value won't change

I'm a noob to Xcode and am reading the Big Nerd Ranch book and its asking me to do example programs in simple C to get me familiar with the language, however its asked me to create a program that calls a method from main and passes an int and does a square calculation and the printf to defog screen. Here is the program:-
#include <stdio.h>
void doTheMath(int numberToSquare)
{
int numberSquared = numberToSquare * numberToSquare;
printf("%d squared is %d\n",numberToSquare,numberSquared);
}
int main(int argc, const char * argv[])
{
doTheMath(5);
return 0;
}
As you can see I am passing the value 5 to the method and it prints 25 on screen when i run the code. IF I then change 5 to 15 to get it to write out a different value, it doesn't. It still writes out 5 squared, not 25 squared.
In debug and step through the value is wrong and isn't changed.
I've closed the project and Xcode and still it doesn't work all of the time and then sometimes it does reflect the changed value.
The project Type is an OSX application / command-line tool. The project is stored on my NAS.
Your code is correct and when I test it in Xcode and change the 5 to 15 and run it, I get the correct answer returned. Make sure you save your file after you make the change, and you could also try to clean your project (Product > Clean).
Sometimes Xcode just does strange things . . .

dyld API on iPhone - strange output

I have three question for you, all related to dyld :)
I have been using this dyld man page as a basis. I have compiled the following code and successfully executed the binary on my jailbroken device.
#include <stdio.h>
#include <mach-o/dyld.h>
int main(int argc, const char* argv[]) {
uint32_t image_count, i;
image_count = _dyld_image_count();
for (i = 0; i < image_count; i++) {
printf("%s\n", _dyld_get_image_name(i));
}
return 0;
}
I thought that these functions let me find all the shared libraries that are loaded in my program's address-space. On my mac, the output is pretty straightforward: It shows the paths to all the libraries that are currently loaded in memory. On my iPhone the output is nearly the same - i also get filepaths - but there are no files at the specified location. (On my mac on the other hand, i can locate the files!)
This is a sample line from the output:
/usr/lib/system/libdyld.dylib
According to ls, iFile and all the other tools i've used, this directory (/usr/lib/system/) is empty. Why? Where are those files?
Another thing i'd like to know is: Is it possible to locate a library in memory? From what offset to what offset the library is mapped into memory? I think i know how to find the beginning but i have no idea how to find the end of the library. To find the beginning, i'd use the address returned by _dyld_get_image_header - Is that correct?
Last question: I wanted to load a dynamic lib system-wide so i assumed i could use DYLD_INSERT_LIBRARIES to do just that. However, every binary i try to execute after inserting my lib crashes and produces a bus error! Did i forget something or is it the dynamic library that causes the crash?
the libraries are located at :
/System/Library/Caches/com.apple.dyld/dyld_shared_cache_armv6 (_armv7)
This is a big file were all the single libraries have been joined into one large one.
See http://iphonedevwiki.net/index.php/MobileSubstrate for hooking on jailbroken device
Yes one can determine the position of a dylib in memory, even on non jailbroken devices.
parse the LC_SEGMENT(_TEXT)-Section Header(_text) of the library then you can get the base address of the library and the size of the TEXT __text segment. Then query for the vmslide. Add this to the base address of the TEXT __text.
A detailed description of the mach-o file format can be found here:
https://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/MachORuntime/Reference/reference.html. Pay special attention to "segment_command"-structure.

Resources